Code Duplication    Length = 161-161 lines in 2 locations

public/js/tinymce/themes/mobile/theme.js 1 location

@@ 5615-5775 (lines=161) @@
5612
      getHeight: getHeight
5613
    };
5614
5615
    var promise = function () {
5616
      var Promise = function (fn) {
5617
        if (typeof this !== 'object')
5618
          throw new TypeError('Promises must be constructed via new');
5619
        if (typeof fn !== 'function')
5620
          throw new TypeError('not a function');
5621
        this._state = null;
5622
        this._value = null;
5623
        this._deferreds = [];
5624
        doResolve(fn, bind(resolve, this), bind(reject, this));
5625
      };
5626
      var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
5627
        setTimeout(fn, 1);
5628
      };
5629
      function bind(fn, thisArg) {
5630
        return function () {
5631
          fn.apply(thisArg, arguments);
5632
        };
5633
      }
5634
      var isArray = Array.isArray || function (value) {
5635
        return Object.prototype.toString.call(value) === '[object Array]';
5636
      };
5637
      function handle(deferred) {
5638
        var me = this;
5639
        if (this._state === null) {
5640
          this._deferreds.push(deferred);
5641
          return;
5642
        }
5643
        asap(function () {
5644
          var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
5645
          if (cb === null) {
5646
            (me._state ? deferred.resolve : deferred.reject)(me._value);
5647
            return;
5648
          }
5649
          var ret;
5650
          try {
5651
            ret = cb(me._value);
5652
          } catch (e) {
5653
            deferred.reject(e);
5654
            return;
5655
          }
5656
          deferred.resolve(ret);
5657
        });
5658
      }
5659
      function resolve(newValue) {
5660
        try {
5661
          if (newValue === this)
5662
            throw new TypeError('A promise cannot be resolved with itself.');
5663
          if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
5664
            var then = newValue.then;
5665
            if (typeof then === 'function') {
5666
              doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
5667
              return;
5668
            }
5669
          }
5670
          this._state = true;
5671
          this._value = newValue;
5672
          finale.call(this);
5673
        } catch (e) {
5674
          reject.call(this, e);
5675
        }
5676
      }
5677
      function reject(newValue) {
5678
        this._state = false;
5679
        this._value = newValue;
5680
        finale.call(this);
5681
      }
5682
      function finale() {
5683
        for (var i = 0, len = this._deferreds.length; i < len; i++) {
5684
          handle.call(this, this._deferreds[i]);
5685
        }
5686
        this._deferreds = null;
5687
      }
5688
      function Handler(onFulfilled, onRejected, resolve, reject) {
5689
        this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
5690
        this.onRejected = typeof onRejected === 'function' ? onRejected : null;
5691
        this.resolve = resolve;
5692
        this.reject = reject;
5693
      }
5694
      function doResolve(fn, onFulfilled, onRejected) {
5695
        var done = false;
5696
        try {
5697
          fn(function (value) {
5698
            if (done)
5699
              return;
5700
            done = true;
5701
            onFulfilled(value);
5702
          }, function (reason) {
5703
            if (done)
5704
              return;
5705
            done = true;
5706
            onRejected(reason);
5707
          });
5708
        } catch (ex) {
5709
          if (done)
5710
            return;
5711
          done = true;
5712
          onRejected(ex);
5713
        }
5714
      }
5715
      Promise.prototype['catch'] = function (onRejected) {
5716
        return this.then(null, onRejected);
5717
      };
5718
      Promise.prototype.then = function (onFulfilled, onRejected) {
5719
        var me = this;
5720
        return new Promise(function (resolve, reject) {
5721
          handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
5722
        });
5723
      };
5724
      Promise.all = function () {
5725
        var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
5726
        return new Promise(function (resolve, reject) {
5727
          if (args.length === 0)
5728
            return resolve([]);
5729
          var remaining = args.length;
5730
          function res(i, val) {
5731
            try {
5732
              if (val && (typeof val === 'object' || typeof val === 'function')) {
5733
                var then = val.then;
5734
                if (typeof then === 'function') {
5735
                  then.call(val, function (val) {
5736
                    res(i, val);
5737
                  }, reject);
5738
                  return;
5739
                }
5740
              }
5741
              args[i] = val;
5742
              if (--remaining === 0) {
5743
                resolve(args);
5744
              }
5745
            } catch (ex) {
5746
              reject(ex);
5747
            }
5748
          }
5749
          for (var i = 0; i < args.length; i++) {
5750
            res(i, args[i]);
5751
          }
5752
        });
5753
      };
5754
      Promise.resolve = function (value) {
5755
        if (value && typeof value === 'object' && value.constructor === Promise) {
5756
          return value;
5757
        }
5758
        return new Promise(function (resolve) {
5759
          resolve(value);
5760
        });
5761
      };
5762
      Promise.reject = function (value) {
5763
        return new Promise(function (resolve, reject) {
5764
          reject(value);
5765
        });
5766
      };
5767
      Promise.race = function (values) {
5768
        return new Promise(function (resolve, reject) {
5769
          for (var i = 0, len = values.length; i < len; i++) {
5770
            values[i].then(resolve, reject);
5771
          }
5772
        });
5773
      };
5774
      return Promise;
5775
    };
5776
    var Promise = window.Promise ? window.Promise : promise();
5777
5778
    function Blob (parts, properties) {

public/js/tinymce/plugins/imagetools/plugin.js 1 location

@@ 75-235 (lines=161) @@
72
      getHeight: getHeight
73
    };
74
75
    var promise = function () {
76
      var Promise = function (fn) {
77
        if (typeof this !== 'object')
78
          throw new TypeError('Promises must be constructed via new');
79
        if (typeof fn !== 'function')
80
          throw new TypeError('not a function');
81
        this._state = null;
82
        this._value = null;
83
        this._deferreds = [];
84
        doResolve(fn, bind(resolve, this), bind(reject, this));
85
      };
86
      var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
87
        setTimeout(fn, 1);
88
      };
89
      function bind(fn, thisArg) {
90
        return function () {
91
          fn.apply(thisArg, arguments);
92
        };
93
      }
94
      var isArray = Array.isArray || function (value) {
95
        return Object.prototype.toString.call(value) === '[object Array]';
96
      };
97
      function handle(deferred) {
98
        var me = this;
99
        if (this._state === null) {
100
          this._deferreds.push(deferred);
101
          return;
102
        }
103
        asap(function () {
104
          var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
105
          if (cb === null) {
106
            (me._state ? deferred.resolve : deferred.reject)(me._value);
107
            return;
108
          }
109
          var ret;
110
          try {
111
            ret = cb(me._value);
112
          } catch (e) {
113
            deferred.reject(e);
114
            return;
115
          }
116
          deferred.resolve(ret);
117
        });
118
      }
119
      function resolve(newValue) {
120
        try {
121
          if (newValue === this)
122
            throw new TypeError('A promise cannot be resolved with itself.');
123
          if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
124
            var then = newValue.then;
125
            if (typeof then === 'function') {
126
              doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
127
              return;
128
            }
129
          }
130
          this._state = true;
131
          this._value = newValue;
132
          finale.call(this);
133
        } catch (e) {
134
          reject.call(this, e);
135
        }
136
      }
137
      function reject(newValue) {
138
        this._state = false;
139
        this._value = newValue;
140
        finale.call(this);
141
      }
142
      function finale() {
143
        for (var i = 0, len = this._deferreds.length; i < len; i++) {
144
          handle.call(this, this._deferreds[i]);
145
        }
146
        this._deferreds = null;
147
      }
148
      function Handler(onFulfilled, onRejected, resolve, reject) {
149
        this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
150
        this.onRejected = typeof onRejected === 'function' ? onRejected : null;
151
        this.resolve = resolve;
152
        this.reject = reject;
153
      }
154
      function doResolve(fn, onFulfilled, onRejected) {
155
        var done = false;
156
        try {
157
          fn(function (value) {
158
            if (done)
159
              return;
160
            done = true;
161
            onFulfilled(value);
162
          }, function (reason) {
163
            if (done)
164
              return;
165
            done = true;
166
            onRejected(reason);
167
          });
168
        } catch (ex) {
169
          if (done)
170
            return;
171
          done = true;
172
          onRejected(ex);
173
        }
174
      }
175
      Promise.prototype['catch'] = function (onRejected) {
176
        return this.then(null, onRejected);
177
      };
178
      Promise.prototype.then = function (onFulfilled, onRejected) {
179
        var me = this;
180
        return new Promise(function (resolve, reject) {
181
          handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
182
        });
183
      };
184
      Promise.all = function () {
185
        var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
186
        return new Promise(function (resolve, reject) {
187
          if (args.length === 0)
188
            return resolve([]);
189
          var remaining = args.length;
190
          function res(i, val) {
191
            try {
192
              if (val && (typeof val === 'object' || typeof val === 'function')) {
193
                var then = val.then;
194
                if (typeof then === 'function') {
195
                  then.call(val, function (val) {
196
                    res(i, val);
197
                  }, reject);
198
                  return;
199
                }
200
              }
201
              args[i] = val;
202
              if (--remaining === 0) {
203
                resolve(args);
204
              }
205
            } catch (ex) {
206
              reject(ex);
207
            }
208
          }
209
          for (var i = 0; i < args.length; i++) {
210
            res(i, args[i]);
211
          }
212
        });
213
      };
214
      Promise.resolve = function (value) {
215
        if (value && typeof value === 'object' && value.constructor === Promise) {
216
          return value;
217
        }
218
        return new Promise(function (resolve) {
219
          resolve(value);
220
        });
221
      };
222
      Promise.reject = function (value) {
223
        return new Promise(function (resolve, reject) {
224
          reject(value);
225
        });
226
      };
227
      Promise.race = function (values) {
228
        return new Promise(function (resolve, reject) {
229
          for (var i = 0, len = values.length; i < len; i++) {
230
            values[i].then(resolve, reject);
231
          }
232
        });
233
      };
234
      return Promise;
235
    };
236
    var Promise = window.Promise ? window.Promise : promise();
237
238
    var constant = function (value) {