Code Duplication    Length = 161-161 lines in 2 locations

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) {

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

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