first commit
This commit is contained in:
153
js/tinymce/classes/util/Arr.js
Normal file
153
js/tinymce/classes/util/Arr.js
Normal file
@@ -0,0 +1,153 @@
|
||||
/**
|
||||
* Arr.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Array utility class.
|
||||
*
|
||||
* @private
|
||||
* @class tinymce.util.Arr
|
||||
*/
|
||||
define("tinymce/util/Arr", [], function() {
|
||||
var isArray = Array.isArray || function(obj) {
|
||||
return Object.prototype.toString.call(obj) === "[object Array]";
|
||||
};
|
||||
|
||||
function toArray(obj) {
|
||||
var array = obj, i, l;
|
||||
|
||||
if (!isArray(obj)) {
|
||||
array = [];
|
||||
for (i = 0, l = obj.length; i < l; i++) {
|
||||
array[i] = obj[i];
|
||||
}
|
||||
}
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
function each(o, cb, s) {
|
||||
var n, l;
|
||||
|
||||
if (!o) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
s = s || o;
|
||||
|
||||
if (o.length !== undefined) {
|
||||
// Indexed arrays, needed for Safari
|
||||
for (n = 0, l = o.length; n < l; n++) {
|
||||
if (cb.call(s, o[n], n, o) === false) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Hashtables
|
||||
for (n in o) {
|
||||
if (o.hasOwnProperty(n)) {
|
||||
if (cb.call(s, o[n], n, o) === false) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
function map(array, callback) {
|
||||
var out = [];
|
||||
|
||||
each(array, function(item, index) {
|
||||
out.push(callback(item, index, array));
|
||||
});
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
function filter(a, f) {
|
||||
var o = [];
|
||||
|
||||
each(a, function(v, index) {
|
||||
if (!f || f(v, index, a)) {
|
||||
o.push(v);
|
||||
}
|
||||
});
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
function indexOf(a, v) {
|
||||
var i, l;
|
||||
|
||||
if (a) {
|
||||
for (i = 0, l = a.length; i < l; i++) {
|
||||
if (a[i] === v) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function reduce(collection, iteratee, accumulator, thisArg) {
|
||||
var i = 0;
|
||||
|
||||
if (arguments.length < 3) {
|
||||
accumulator = collection[0];
|
||||
}
|
||||
|
||||
for (; i < collection.length; i++) {
|
||||
accumulator = iteratee.call(thisArg, accumulator, collection[i], i);
|
||||
}
|
||||
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
function findIndex(array, predicate, thisArg) {
|
||||
var i, l;
|
||||
|
||||
for (i = 0, l = array.length; i < l; i++) {
|
||||
if (predicate.call(thisArg, array[i], i, array)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
function find(array, predicate, thisArg) {
|
||||
var idx = findIndex(array, predicate, thisArg);
|
||||
|
||||
if (idx !== -1) {
|
||||
return array[idx];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function last(collection) {
|
||||
return collection[collection.length - 1];
|
||||
}
|
||||
|
||||
return {
|
||||
isArray: isArray,
|
||||
toArray: toArray,
|
||||
each: each,
|
||||
map: map,
|
||||
filter: filter,
|
||||
indexOf: indexOf,
|
||||
reduce: reduce,
|
||||
findIndex: findIndex,
|
||||
find: find,
|
||||
last: last
|
||||
};
|
||||
});
|
||||
169
js/tinymce/classes/util/Class.js
Normal file
169
js/tinymce/classes/util/Class.js
Normal file
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* Class.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This utilitiy class is used for easier inheritance.
|
||||
*
|
||||
* Features:
|
||||
* * Exposed super functions: this._super();
|
||||
* * Mixins
|
||||
* * Dummy functions
|
||||
* * Property functions: var value = object.value(); and object.value(newValue);
|
||||
* * Static functions
|
||||
* * Defaults settings
|
||||
*/
|
||||
define("tinymce/util/Class", [
|
||||
"tinymce/util/Tools"
|
||||
], function(Tools) {
|
||||
var each = Tools.each, extend = Tools.extend;
|
||||
|
||||
var extendClass, initializing;
|
||||
|
||||
function Class() {
|
||||
}
|
||||
|
||||
// Provides classical inheritance, based on code made by John Resig
|
||||
Class.extend = extendClass = function(prop) {
|
||||
var self = this, _super = self.prototype, prototype, name, member;
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
var i, mixins, mixin, self = this;
|
||||
|
||||
// All construction is actually done in the init method
|
||||
if (!initializing) {
|
||||
// Run class constuctor
|
||||
if (self.init) {
|
||||
self.init.apply(self, arguments);
|
||||
}
|
||||
|
||||
// Run mixin constructors
|
||||
mixins = self.Mixins;
|
||||
if (mixins) {
|
||||
i = mixins.length;
|
||||
while (i--) {
|
||||
mixin = mixins[i];
|
||||
if (mixin.init) {
|
||||
mixin.init.apply(self, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dummy function, needs to be extended in order to provide functionality
|
||||
function dummy() {
|
||||
return this;
|
||||
}
|
||||
|
||||
// Creates a overloaded method for the class
|
||||
// this enables you to use this._super(); to call the super function
|
||||
function createMethod(name, fn) {
|
||||
return function() {
|
||||
var self = this, tmp = self._super, ret;
|
||||
|
||||
self._super = _super[name];
|
||||
ret = fn.apply(self, arguments);
|
||||
self._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
}
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
|
||||
/*eslint new-cap:0 */
|
||||
prototype = new self();
|
||||
initializing = false;
|
||||
|
||||
// Add mixins
|
||||
if (prop.Mixins) {
|
||||
each(prop.Mixins, function(mixin) {
|
||||
mixin = mixin;
|
||||
|
||||
for (var name in mixin) {
|
||||
if (name !== "init") {
|
||||
prop[name] = mixin[name];
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (_super.Mixins) {
|
||||
prop.Mixins = _super.Mixins.concat(prop.Mixins);
|
||||
}
|
||||
}
|
||||
|
||||
// Generate dummy methods
|
||||
if (prop.Methods) {
|
||||
each(prop.Methods.split(','), function(name) {
|
||||
prop[name] = dummy;
|
||||
});
|
||||
}
|
||||
|
||||
// Generate property methods
|
||||
if (prop.Properties) {
|
||||
each(prop.Properties.split(','), function(name) {
|
||||
var fieldName = '_' + name;
|
||||
|
||||
prop[name] = function(value) {
|
||||
var self = this, undef;
|
||||
|
||||
// Set value
|
||||
if (value !== undef) {
|
||||
self[fieldName] = value;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
// Get value
|
||||
return self[fieldName];
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// Static functions
|
||||
if (prop.Statics) {
|
||||
each(prop.Statics, function(func, name) {
|
||||
Class[name] = func;
|
||||
});
|
||||
}
|
||||
|
||||
// Default settings
|
||||
if (prop.Defaults && _super.Defaults) {
|
||||
prop.Defaults = extend({}, _super.Defaults, prop.Defaults);
|
||||
}
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (name in prop) {
|
||||
member = prop[name];
|
||||
|
||||
if (typeof member == "function" && _super[name]) {
|
||||
prototype[name] = createMethod(name, member);
|
||||
} else {
|
||||
prototype[name] = member;
|
||||
}
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.constructor = Class;
|
||||
|
||||
// And make this class extendible
|
||||
Class.extend = extendClass;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
return Class;
|
||||
});
|
||||
235
js/tinymce/classes/util/Color.js
Normal file
235
js/tinymce/classes/util/Color.js
Normal file
@@ -0,0 +1,235 @@
|
||||
/**
|
||||
* Color.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class lets you parse/serialize colors and convert rgb/hsb.
|
||||
*
|
||||
* @class tinymce.util.Color
|
||||
* @example
|
||||
* var white = new tinymce.util.Color({r: 255, g: 255, b: 255});
|
||||
* var red = new tinymce.util.Color('#FF0000');
|
||||
*
|
||||
* console.log(white.toHex(), red.toHsv());
|
||||
*/
|
||||
define("tinymce/util/Color", [], function() {
|
||||
var min = Math.min, max = Math.max, round = Math.round;
|
||||
|
||||
/**
|
||||
* Constructs a new color instance.
|
||||
*
|
||||
* @constructor
|
||||
* @method Color
|
||||
* @param {String} value Optional initial value to parse.
|
||||
*/
|
||||
function Color(value) {
|
||||
var self = this, r = 0, g = 0, b = 0;
|
||||
|
||||
function rgb2hsv(r, g, b) {
|
||||
var h, s, v, d, minRGB, maxRGB;
|
||||
|
||||
h = 0;
|
||||
s = 0;
|
||||
v = 0;
|
||||
r = r / 255;
|
||||
g = g / 255;
|
||||
b = b / 255;
|
||||
|
||||
minRGB = min(r, min(g, b));
|
||||
maxRGB = max(r, max(g, b));
|
||||
|
||||
if (minRGB == maxRGB) {
|
||||
v = minRGB;
|
||||
|
||||
return {
|
||||
h: 0,
|
||||
s: 0,
|
||||
v: v * 100
|
||||
};
|
||||
}
|
||||
|
||||
/*eslint no-nested-ternary:0 */
|
||||
d = (r == minRGB) ? g - b : ((b == minRGB) ? r - g : b - r);
|
||||
h = (r == minRGB) ? 3 : ((b == minRGB) ? 1 : 5);
|
||||
h = 60 * (h - d / (maxRGB - minRGB));
|
||||
s = (maxRGB - minRGB) / maxRGB;
|
||||
v = maxRGB;
|
||||
|
||||
return {
|
||||
h: round(h),
|
||||
s: round(s * 100),
|
||||
v: round(v * 100)
|
||||
};
|
||||
}
|
||||
|
||||
function hsvToRgb(hue, saturation, brightness) {
|
||||
var side, chroma, x, match;
|
||||
|
||||
hue = (parseInt(hue, 10) || 0) % 360;
|
||||
saturation = parseInt(saturation, 10) / 100;
|
||||
brightness = parseInt(brightness, 10) / 100;
|
||||
saturation = max(0, min(saturation, 1));
|
||||
brightness = max(0, min(brightness, 1));
|
||||
|
||||
if (saturation === 0) {
|
||||
r = g = b = round(255 * brightness);
|
||||
return;
|
||||
}
|
||||
|
||||
side = hue / 60;
|
||||
chroma = brightness * saturation;
|
||||
x = chroma * (1 - Math.abs(side % 2 - 1));
|
||||
match = brightness - chroma;
|
||||
|
||||
switch (Math.floor(side)) {
|
||||
case 0:
|
||||
r = chroma;
|
||||
g = x;
|
||||
b = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
r = x;
|
||||
g = chroma;
|
||||
b = 0;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
r = 0;
|
||||
g = chroma;
|
||||
b = x;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
r = 0;
|
||||
g = x;
|
||||
b = chroma;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
r = x;
|
||||
g = 0;
|
||||
b = chroma;
|
||||
break;
|
||||
|
||||
case 5:
|
||||
r = chroma;
|
||||
g = 0;
|
||||
b = x;
|
||||
break;
|
||||
|
||||
default:
|
||||
r = g = b = 0;
|
||||
}
|
||||
|
||||
r = round(255 * (r + match));
|
||||
g = round(255 * (g + match));
|
||||
b = round(255 * (b + match));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the hex string of the current color. For example: #ff00ff
|
||||
*
|
||||
* @method toHex
|
||||
* @return {String} Hex string of current color.
|
||||
*/
|
||||
function toHex() {
|
||||
function hex(val) {
|
||||
val = parseInt(val, 10).toString(16);
|
||||
|
||||
return val.length > 1 ? val : '0' + val;
|
||||
}
|
||||
|
||||
return '#' + hex(r) + hex(g) + hex(b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the r, g, b values of the color. Each channel has a range from 0-255.
|
||||
*
|
||||
* @method toRgb
|
||||
* @return {Object} Object with r, g, b fields.
|
||||
*/
|
||||
function toRgb() {
|
||||
return {
|
||||
r: r,
|
||||
g: g,
|
||||
b: b
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the h, s, v values of the color. Ranges: h=0-360, s=0-100, v=0-100.
|
||||
*
|
||||
* @method toHsv
|
||||
* @return {Object} Object with h, s, v fields.
|
||||
*/
|
||||
function toHsv() {
|
||||
return rgb2hsv(r, g, b);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the specified value and populates the color instance.
|
||||
*
|
||||
* Supported format examples:
|
||||
* * rbg(255,0,0)
|
||||
* * #ff0000
|
||||
* * #fff
|
||||
* * {r: 255, g: 0, b: 0}
|
||||
* * {h: 360, s: 100, v: 100}
|
||||
*
|
||||
* @method parse
|
||||
* @param {Object/String} value Color value to parse.
|
||||
* @return {tinymce.util.Color} Current color instance.
|
||||
*/
|
||||
function parse(value) {
|
||||
var matches;
|
||||
|
||||
if (typeof value == 'object') {
|
||||
if ("r" in value) {
|
||||
r = value.r;
|
||||
g = value.g;
|
||||
b = value.b;
|
||||
} else if ("v" in value) {
|
||||
hsvToRgb(value.h, value.s, value.v);
|
||||
}
|
||||
} else {
|
||||
if ((matches = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(value))) {
|
||||
r = parseInt(matches[1], 10);
|
||||
g = parseInt(matches[2], 10);
|
||||
b = parseInt(matches[3], 10);
|
||||
} else if ((matches = /#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(value))) {
|
||||
r = parseInt(matches[1], 16);
|
||||
g = parseInt(matches[2], 16);
|
||||
b = parseInt(matches[3], 16);
|
||||
} else if ((matches = /#([0-F])([0-F])([0-F])/gi.exec(value))) {
|
||||
r = parseInt(matches[1] + matches[1], 16);
|
||||
g = parseInt(matches[2] + matches[2], 16);
|
||||
b = parseInt(matches[3] + matches[3], 16);
|
||||
}
|
||||
}
|
||||
|
||||
r = r < 0 ? 0 : (r > 255 ? 255 : r);
|
||||
g = g < 0 ? 0 : (g > 255 ? 255 : g);
|
||||
b = b < 0 ? 0 : (b > 255 ? 255 : b);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
if (value) {
|
||||
parse(value);
|
||||
}
|
||||
|
||||
self.toRgb = toRgb;
|
||||
self.toHsv = toHsv;
|
||||
self.toHex = toHex;
|
||||
self.parse = parse;
|
||||
}
|
||||
|
||||
return Color;
|
||||
});
|
||||
191
js/tinymce/classes/util/Delay.js
Normal file
191
js/tinymce/classes/util/Delay.js
Normal file
@@ -0,0 +1,191 @@
|
||||
/**
|
||||
* Delay.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Utility class for working with delayed actions like setTimeout.
|
||||
*
|
||||
* @class tinymce.util.Delay
|
||||
*/
|
||||
define("tinymce/util/Delay", [
|
||||
"tinymce/util/Promise"
|
||||
], function(Promise) {
|
||||
var requestAnimationFramePromise;
|
||||
|
||||
function requestAnimationFrame(callback, element) {
|
||||
var i, requestAnimationFrameFunc = window.requestAnimationFrame, vendors = ['ms', 'moz', 'webkit'];
|
||||
|
||||
function featurefill(callback) {
|
||||
window.setTimeout(callback, 0);
|
||||
}
|
||||
|
||||
for (i = 0; i < vendors.length && !requestAnimationFrameFunc; i++) {
|
||||
requestAnimationFrameFunc = window[vendors[i] + 'RequestAnimationFrame'];
|
||||
}
|
||||
|
||||
if (!requestAnimationFrameFunc) {
|
||||
requestAnimationFrameFunc = featurefill;
|
||||
}
|
||||
|
||||
requestAnimationFrameFunc(callback, element);
|
||||
}
|
||||
|
||||
function wrappedSetTimeout(callback, time) {
|
||||
if (typeof time != 'number') {
|
||||
time = 0;
|
||||
}
|
||||
|
||||
return setTimeout(callback, time);
|
||||
}
|
||||
|
||||
function wrappedSetInterval(callback, time) {
|
||||
if (typeof time != 'number') {
|
||||
time = 0;
|
||||
}
|
||||
|
||||
return setInterval(callback, time);
|
||||
}
|
||||
|
||||
function wrappedClearTimeout(id) {
|
||||
return clearTimeout(id);
|
||||
}
|
||||
|
||||
function wrappedClearInterval(id) {
|
||||
return clearInterval(id);
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Requests an animation frame and fallbacks to a timeout on older browsers.
|
||||
*
|
||||
* @method requestAnimationFrame
|
||||
* @param {function} callback Callback to execute when a new frame is available.
|
||||
* @param {DOMElement} element Optional element to scope it to.
|
||||
*/
|
||||
requestAnimationFrame: function(callback, element) {
|
||||
if (requestAnimationFramePromise) {
|
||||
requestAnimationFramePromise.then(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
requestAnimationFramePromise = new Promise(function(resolve) {
|
||||
if (!element) {
|
||||
element = document.body;
|
||||
}
|
||||
|
||||
requestAnimationFrame(resolve, element);
|
||||
}).then(callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a timer in ms and executes the specified callback when the timer runs out.
|
||||
*
|
||||
* @method setTimeout
|
||||
* @param {function} callback Callback to execute when timer runs out.
|
||||
* @param {Number} time Optional time to wait before the callback is executed, defaults to 0.
|
||||
* @return {Number} Timeout id number.
|
||||
*/
|
||||
setTimeout: wrappedSetTimeout,
|
||||
|
||||
/**
|
||||
* Sets an interval timer in ms and executes the specified callback at every interval of that time.
|
||||
*
|
||||
* @method setInterval
|
||||
* @param {function} callback Callback to execute when interval time runs out.
|
||||
* @param {Number} time Optional time to wait before the callback is executed, defaults to 0.
|
||||
* @return {Number} Timeout id number.
|
||||
*/
|
||||
setInterval: wrappedSetInterval,
|
||||
|
||||
/**
|
||||
* Sets an editor timeout it's similar to setTimeout except that it checks if the editor instance is
|
||||
* still alive when the callback gets executed.
|
||||
*
|
||||
* @method setEditorTimeout
|
||||
* @param {tinymce.Editor} editor Editor instance to check the removed state on.
|
||||
* @param {function} callback Callback to execute when timer runs out.
|
||||
* @param {Number} time Optional time to wait before the callback is executed, defaults to 0.
|
||||
* @return {Number} Timeout id number.
|
||||
*/
|
||||
setEditorTimeout: function(editor, callback, time) {
|
||||
return wrappedSetTimeout(function() {
|
||||
if (!editor.removed) {
|
||||
callback();
|
||||
}
|
||||
}, time);
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets an interval timer it's similar to setInterval except that it checks if the editor instance is
|
||||
* still alive when the callback gets executed.
|
||||
*
|
||||
* @method setEditorInterval
|
||||
* @param {function} callback Callback to execute when interval time runs out.
|
||||
* @param {Number} time Optional time to wait before the callback is executed, defaults to 0.
|
||||
* @return {Number} Timeout id number.
|
||||
*/
|
||||
setEditorInterval: function(editor, callback, time) {
|
||||
var timer;
|
||||
|
||||
timer = wrappedSetInterval(function() {
|
||||
if (!editor.removed) {
|
||||
callback();
|
||||
} else {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, time);
|
||||
|
||||
return timer;
|
||||
},
|
||||
|
||||
/**
|
||||
* Creates throttled callback function that only gets executed once within the specified time.
|
||||
*
|
||||
* @method throttle
|
||||
* @param {function} callback Callback to execute when timer finishes.
|
||||
* @param {Number} time Optional time to wait before the callback is executed, defaults to 0.
|
||||
* @return {Function} Throttled function callback.
|
||||
*/
|
||||
throttle: function(callback, time) {
|
||||
var timer, func;
|
||||
|
||||
func = function() {
|
||||
var args = arguments;
|
||||
|
||||
clearTimeout(timer);
|
||||
|
||||
timer = wrappedSetTimeout(function() {
|
||||
callback.apply(this, args);
|
||||
}, time);
|
||||
};
|
||||
|
||||
func.stop = function() {
|
||||
clearTimeout(timer);
|
||||
};
|
||||
|
||||
return func;
|
||||
},
|
||||
|
||||
/**
|
||||
* Clears an interval timer so it won't execute.
|
||||
*
|
||||
* @method clearInterval
|
||||
* @param {Number} Interval timer id number.
|
||||
*/
|
||||
clearInterval: wrappedClearInterval,
|
||||
|
||||
/**
|
||||
* Clears an timeout timer so it won't execute.
|
||||
*
|
||||
* @method clearTimeout
|
||||
* @param {Number} Timeout timer id number.
|
||||
*/
|
||||
clearTimeout: wrappedClearTimeout
|
||||
};
|
||||
});
|
||||
294
js/tinymce/classes/util/EventDispatcher.js
Normal file
294
js/tinymce/classes/util/EventDispatcher.js
Normal file
@@ -0,0 +1,294 @@
|
||||
/**
|
||||
* EventDispatcher.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class lets you add/remove and fire events by name on the specified scope. This makes
|
||||
* it easy to add event listener logic to any class.
|
||||
*
|
||||
* @class tinymce.util.EventDispatcher
|
||||
* @example
|
||||
* var eventDispatcher = new EventDispatcher();
|
||||
*
|
||||
* eventDispatcher.on('click', function() {console.log('data');});
|
||||
* eventDispatcher.fire('click', {data: 123});
|
||||
*/
|
||||
define("tinymce/util/EventDispatcher", [
|
||||
"tinymce/util/Tools"
|
||||
], function(Tools) {
|
||||
var nativeEvents = Tools.makeMap(
|
||||
"focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange " +
|
||||
"mouseout mouseenter mouseleave wheel keydown keypress keyup input contextmenu dragstart dragend dragover " +
|
||||
"draggesture dragdrop drop drag submit " +
|
||||
"compositionstart compositionend compositionupdate touchstart touchend",
|
||||
' '
|
||||
);
|
||||
|
||||
function Dispatcher(settings) {
|
||||
var self = this, scope, bindings = {}, toggleEvent;
|
||||
|
||||
function returnFalse() {
|
||||
return false;
|
||||
}
|
||||
|
||||
function returnTrue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
settings = settings || {};
|
||||
scope = settings.scope || self;
|
||||
toggleEvent = settings.toggleEvent || returnFalse;
|
||||
|
||||
/**
|
||||
* Fires the specified event by name.
|
||||
*
|
||||
* @method fire
|
||||
* @param {String} name Name of the event to fire.
|
||||
* @param {Object?} args Event arguments.
|
||||
* @return {Object} Event args instance passed in.
|
||||
* @example
|
||||
* instance.fire('event', {...});
|
||||
*/
|
||||
function fire(name, args) {
|
||||
var handlers, i, l, callback;
|
||||
|
||||
name = name.toLowerCase();
|
||||
args = args || {};
|
||||
args.type = name;
|
||||
|
||||
// Setup target is there isn't one
|
||||
if (!args.target) {
|
||||
args.target = scope;
|
||||
}
|
||||
|
||||
// Add event delegation methods if they are missing
|
||||
if (!args.preventDefault) {
|
||||
// Add preventDefault method
|
||||
args.preventDefault = function() {
|
||||
args.isDefaultPrevented = returnTrue;
|
||||
};
|
||||
|
||||
// Add stopPropagation
|
||||
args.stopPropagation = function() {
|
||||
args.isPropagationStopped = returnTrue;
|
||||
};
|
||||
|
||||
// Add stopImmediatePropagation
|
||||
args.stopImmediatePropagation = function() {
|
||||
args.isImmediatePropagationStopped = returnTrue;
|
||||
};
|
||||
|
||||
// Add event delegation states
|
||||
args.isDefaultPrevented = returnFalse;
|
||||
args.isPropagationStopped = returnFalse;
|
||||
args.isImmediatePropagationStopped = returnFalse;
|
||||
}
|
||||
|
||||
if (settings.beforeFire) {
|
||||
settings.beforeFire(args);
|
||||
}
|
||||
|
||||
handlers = bindings[name];
|
||||
if (handlers) {
|
||||
for (i = 0, l = handlers.length; i < l; i++) {
|
||||
callback = handlers[i];
|
||||
|
||||
// Unbind handlers marked with "once"
|
||||
if (callback.once) {
|
||||
off(name, callback.func);
|
||||
}
|
||||
|
||||
// Stop immediate propagation if needed
|
||||
if (args.isImmediatePropagationStopped()) {
|
||||
args.stopPropagation();
|
||||
return args;
|
||||
}
|
||||
|
||||
// If callback returns false then prevent default and stop all propagation
|
||||
if (callback.func.call(scope, args) === false) {
|
||||
args.preventDefault();
|
||||
return args;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds an event listener to a specific event by name.
|
||||
*
|
||||
* @method on
|
||||
* @param {String} name Event name or space separated list of events to bind.
|
||||
* @param {callback} callback Callback to be executed when the event occurs.
|
||||
* @param {Boolean} first Optional flag if the event should be prepended. Use this with care.
|
||||
* @return {Object} Current class instance.
|
||||
* @example
|
||||
* instance.on('event', function(e) {
|
||||
* // Callback logic
|
||||
* });
|
||||
*/
|
||||
function on(name, callback, prepend, extra) {
|
||||
var handlers, names, i;
|
||||
|
||||
if (callback === false) {
|
||||
callback = returnFalse;
|
||||
}
|
||||
|
||||
if (callback) {
|
||||
callback = {
|
||||
func: callback
|
||||
};
|
||||
|
||||
if (extra) {
|
||||
Tools.extend(callback, extra);
|
||||
}
|
||||
|
||||
names = name.toLowerCase().split(' ');
|
||||
i = names.length;
|
||||
while (i--) {
|
||||
name = names[i];
|
||||
handlers = bindings[name];
|
||||
if (!handlers) {
|
||||
handlers = bindings[name] = [];
|
||||
toggleEvent(name, true);
|
||||
}
|
||||
|
||||
if (prepend) {
|
||||
handlers.unshift(callback);
|
||||
} else {
|
||||
handlers.push(callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unbinds an event listener to a specific event by name.
|
||||
*
|
||||
* @method off
|
||||
* @param {String?} name Name of the event to unbind.
|
||||
* @param {callback?} callback Callback to unbind.
|
||||
* @return {Object} Current class instance.
|
||||
* @example
|
||||
* // Unbind specific callback
|
||||
* instance.off('event', handler);
|
||||
*
|
||||
* // Unbind all listeners by name
|
||||
* instance.off('event');
|
||||
*
|
||||
* // Unbind all events
|
||||
* instance.off();
|
||||
*/
|
||||
function off(name, callback) {
|
||||
var i, handlers, bindingName, names, hi;
|
||||
|
||||
if (name) {
|
||||
names = name.toLowerCase().split(' ');
|
||||
i = names.length;
|
||||
while (i--) {
|
||||
name = names[i];
|
||||
handlers = bindings[name];
|
||||
|
||||
// Unbind all handlers
|
||||
if (!name) {
|
||||
for (bindingName in bindings) {
|
||||
toggleEvent(bindingName, false);
|
||||
delete bindings[bindingName];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
if (handlers) {
|
||||
// Unbind all by name
|
||||
if (!callback) {
|
||||
handlers.length = 0;
|
||||
} else {
|
||||
// Unbind specific ones
|
||||
hi = handlers.length;
|
||||
while (hi--) {
|
||||
if (handlers[hi].func === callback) {
|
||||
handlers = handlers.slice(0, hi).concat(handlers.slice(hi + 1));
|
||||
bindings[name] = handlers;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!handlers.length) {
|
||||
toggleEvent(name, false);
|
||||
delete bindings[name];
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (name in bindings) {
|
||||
toggleEvent(name, false);
|
||||
}
|
||||
|
||||
bindings = {};
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds an event listener to a specific event by name
|
||||
* and automatically unbind the event once the callback fires.
|
||||
*
|
||||
* @method once
|
||||
* @param {String} name Event name or space separated list of events to bind.
|
||||
* @param {callback} callback Callback to be executed when the event occurs.
|
||||
* @param {Boolean} first Optional flag if the event should be prepended. Use this with care.
|
||||
* @return {Object} Current class instance.
|
||||
* @example
|
||||
* instance.once('event', function(e) {
|
||||
* // Callback logic
|
||||
* });
|
||||
*/
|
||||
function once(name, callback, prepend) {
|
||||
return on(name, callback, prepend, {once: true});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true/false if the dispatcher has a event of the specified name.
|
||||
*
|
||||
* @method has
|
||||
* @param {String} name Name of the event to check for.
|
||||
* @return {Boolean} true/false if the event exists or not.
|
||||
*/
|
||||
function has(name) {
|
||||
name = name.toLowerCase();
|
||||
return !(!bindings[name] || bindings[name].length === 0);
|
||||
}
|
||||
|
||||
// Expose
|
||||
self.fire = fire;
|
||||
self.on = on;
|
||||
self.off = off;
|
||||
self.once = once;
|
||||
self.has = has;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true/false if the specified event name is a native browser event or not.
|
||||
*
|
||||
* @method isNative
|
||||
* @param {String} name Name to check if it's native.
|
||||
* @return {Boolean} true/false if the event is native or not.
|
||||
* @static
|
||||
*/
|
||||
Dispatcher.isNative = function(name) {
|
||||
return !!nativeEvents[name.toLowerCase()];
|
||||
};
|
||||
|
||||
return Dispatcher;
|
||||
});
|
||||
87
js/tinymce/classes/util/Fun.js
Normal file
87
js/tinymce/classes/util/Fun.js
Normal file
@@ -0,0 +1,87 @@
|
||||
/**
|
||||
* Fun.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* Functional utility class.
|
||||
*
|
||||
* @private
|
||||
* @class tinymce.util.Fun
|
||||
*/
|
||||
define("tinymce/util/Fun", [], function() {
|
||||
var slice = [].slice;
|
||||
|
||||
function constant(value) {
|
||||
return function() {
|
||||
return value;
|
||||
};
|
||||
}
|
||||
|
||||
function negate(predicate) {
|
||||
return function(x) {
|
||||
return !predicate(x);
|
||||
};
|
||||
}
|
||||
|
||||
function compose(f, g) {
|
||||
return function(x) {
|
||||
return f(g(x));
|
||||
};
|
||||
}
|
||||
|
||||
function or() {
|
||||
var args = slice.call(arguments);
|
||||
|
||||
return function(x) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (args[i](x)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
function and() {
|
||||
var args = slice.call(arguments);
|
||||
|
||||
return function(x) {
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
if (!args[i](x)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
function curry(fn) {
|
||||
var args = slice.call(arguments);
|
||||
|
||||
if (args.length - 1 >= fn.length) {
|
||||
return fn.apply(this, args.slice(1));
|
||||
}
|
||||
|
||||
return function() {
|
||||
var tempArgs = args.concat([].slice.call(arguments));
|
||||
return curry.apply(this, tempArgs);
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
constant: constant,
|
||||
negate: negate,
|
||||
and: and,
|
||||
or: or,
|
||||
curry: curry,
|
||||
compose: compose
|
||||
};
|
||||
});
|
||||
116
js/tinymce/classes/util/I18n.js
Normal file
116
js/tinymce/classes/util/I18n.js
Normal file
@@ -0,0 +1,116 @@
|
||||
/**
|
||||
* I18n.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* I18n class that handles translation of TinyMCE UI.
|
||||
* Uses po style with csharp style parameters.
|
||||
*
|
||||
* @class tinymce.util.I18n
|
||||
*/
|
||||
define("tinymce/util/I18n", [], function() {
|
||||
"use strict";
|
||||
|
||||
var data = {}, code = "en";
|
||||
|
||||
return {
|
||||
/**
|
||||
* Sets the current language code.
|
||||
*
|
||||
* @method setCode
|
||||
* @param {String} newCode Current language code.
|
||||
*/
|
||||
setCode: function(newCode) {
|
||||
if (newCode) {
|
||||
code = newCode;
|
||||
this.rtl = this.data[newCode] ? this.data[newCode]._dir === 'rtl' : false;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the current language code.
|
||||
*
|
||||
* @method getCode
|
||||
* @return {String} Current language code.
|
||||
*/
|
||||
getCode: function() {
|
||||
return code;
|
||||
},
|
||||
|
||||
/**
|
||||
* Property gets set to true if a RTL language pack was loaded.
|
||||
*
|
||||
* @property rtl
|
||||
* @type Boolean
|
||||
*/
|
||||
rtl: false,
|
||||
|
||||
/**
|
||||
* Adds translations for a specific language code.
|
||||
*
|
||||
* @method add
|
||||
* @param {String} code Language code like sv_SE.
|
||||
* @param {Array} items Name/value array with English en_US to sv_SE.
|
||||
*/
|
||||
add: function(code, items) {
|
||||
var langData = data[code];
|
||||
|
||||
if (!langData) {
|
||||
data[code] = langData = {};
|
||||
}
|
||||
|
||||
for (var name in items) {
|
||||
langData[name] = items[name];
|
||||
}
|
||||
|
||||
this.setCode(code);
|
||||
},
|
||||
|
||||
/**
|
||||
* Translates the specified text.
|
||||
*
|
||||
* It has a few formats:
|
||||
* I18n.translate("Text");
|
||||
* I18n.translate(["Text {0}/{1}", 0, 1]);
|
||||
* I18n.translate({raw: "Raw string"});
|
||||
*
|
||||
* @method translate
|
||||
* @param {String/Object/Array} text Text to translate.
|
||||
* @return {String} String that got translated.
|
||||
*/
|
||||
translate: function(text) {
|
||||
var langData;
|
||||
|
||||
langData = data[code];
|
||||
if (!langData) {
|
||||
langData = {};
|
||||
}
|
||||
|
||||
if (typeof text == "undefined") {
|
||||
return text;
|
||||
}
|
||||
|
||||
if (typeof text != "string" && text.raw) {
|
||||
return text.raw;
|
||||
}
|
||||
|
||||
if (text.push) {
|
||||
var values = text.slice(1);
|
||||
|
||||
text = (langData[text[0]] || text[0]).replace(/\{([0-9]+)\}/g, function(match1, match2) {
|
||||
return values[match2];
|
||||
});
|
||||
}
|
||||
|
||||
return (langData[text] || text).replace(/{context:\w+}$/, '');
|
||||
},
|
||||
|
||||
data: data
|
||||
};
|
||||
});
|
||||
109
js/tinymce/classes/util/JSON.js
Normal file
109
js/tinymce/classes/util/JSON.js
Normal file
@@ -0,0 +1,109 @@
|
||||
/**
|
||||
* JSON.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* JSON parser and serializer class.
|
||||
*
|
||||
* @class tinymce.util.JSON
|
||||
* @static
|
||||
* @example
|
||||
* // JSON parse a string into an object
|
||||
* var obj = tinymce.util.JSON.parse(somestring);
|
||||
*
|
||||
* // JSON serialize a object into an string
|
||||
* var str = tinymce.util.JSON.serialize(obj);
|
||||
*/
|
||||
define("tinymce/util/JSON", [], function() {
|
||||
function serialize(o, quote) {
|
||||
var i, v, t, name;
|
||||
|
||||
quote = quote || '"';
|
||||
|
||||
if (o === null) {
|
||||
return 'null';
|
||||
}
|
||||
|
||||
t = typeof o;
|
||||
|
||||
if (t == 'string') {
|
||||
v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
|
||||
|
||||
return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
|
||||
// Make sure single quotes never get encoded inside double quotes for JSON compatibility
|
||||
if (quote === '"' && a === "'") {
|
||||
return a;
|
||||
}
|
||||
|
||||
i = v.indexOf(b);
|
||||
|
||||
if (i + 1) {
|
||||
return '\\' + v.charAt(i + 1);
|
||||
}
|
||||
|
||||
a = b.charCodeAt().toString(16);
|
||||
|
||||
return '\\u' + '0000'.substring(a.length) + a;
|
||||
}) + quote;
|
||||
}
|
||||
|
||||
if (t == 'object') {
|
||||
if (o.hasOwnProperty && Object.prototype.toString.call(o) === '[object Array]') {
|
||||
for (i = 0, v = '['; i < o.length; i++) {
|
||||
v += (i > 0 ? ',' : '') + serialize(o[i], quote);
|
||||
}
|
||||
|
||||
return v + ']';
|
||||
}
|
||||
|
||||
v = '{';
|
||||
|
||||
for (name in o) {
|
||||
if (o.hasOwnProperty(name)) {
|
||||
v += typeof o[name] != 'function' ? (v.length > 1 ? ',' + quote : quote) + name +
|
||||
quote + ':' + serialize(o[name], quote) : '';
|
||||
}
|
||||
}
|
||||
|
||||
return v + '}';
|
||||
}
|
||||
|
||||
return '' + o;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Serializes the specified object as a JSON string.
|
||||
*
|
||||
* @method serialize
|
||||
* @param {Object} obj Object to serialize as a JSON string.
|
||||
* @param {String} quote Optional quote string defaults to ".
|
||||
* @return {string} JSON string serialized from input.
|
||||
*/
|
||||
serialize: serialize,
|
||||
|
||||
/**
|
||||
* Unserializes/parses the specified JSON string into a object.
|
||||
*
|
||||
* @method parse
|
||||
* @param {string} s JSON String to parse into a JavaScript object.
|
||||
* @return {Object} Object from input JSON string or undefined if it failed.
|
||||
*/
|
||||
parse: function(text) {
|
||||
try {
|
||||
// Trick uglify JS
|
||||
return window[String.fromCharCode(101) + 'val']('(' + text + ')');
|
||||
} catch (ex) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
|
||||
/**#@-*/
|
||||
};
|
||||
});
|
||||
38
js/tinymce/classes/util/JSONP.js
Normal file
38
js/tinymce/classes/util/JSONP.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* JSONP.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
define("tinymce/util/JSONP", [
|
||||
"tinymce/dom/DOMUtils"
|
||||
], function(DOMUtils) {
|
||||
return {
|
||||
callbacks: {},
|
||||
count: 0,
|
||||
|
||||
send: function(settings) {
|
||||
var self = this, dom = DOMUtils.DOM, count = settings.count !== undefined ? settings.count : self.count;
|
||||
var id = 'tinymce_jsonp_' + count;
|
||||
|
||||
self.callbacks[count] = function(json) {
|
||||
dom.remove(id);
|
||||
delete self.callbacks[count];
|
||||
|
||||
settings.callback(json);
|
||||
};
|
||||
|
||||
dom.add(dom.doc.body, 'script', {
|
||||
id: id,
|
||||
src: settings.url,
|
||||
type: 'text/javascript'
|
||||
});
|
||||
|
||||
self.count++;
|
||||
}
|
||||
};
|
||||
});
|
||||
110
js/tinymce/classes/util/JSONRequest.js
Normal file
110
js/tinymce/classes/util/JSONRequest.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* JSONRequest.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class enables you to use JSON-RPC to call backend methods.
|
||||
*
|
||||
* @class tinymce.util.JSONRequest
|
||||
* @example
|
||||
* var json = new tinymce.util.JSONRequest({
|
||||
* url: 'somebackend.php'
|
||||
* });
|
||||
*
|
||||
* // Send RPC call 1
|
||||
* json.send({
|
||||
* method: 'someMethod1',
|
||||
* params: ['a', 'b'],
|
||||
* success: function(result) {
|
||||
* console.dir(result);
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* // Send RPC call 2
|
||||
* json.send({
|
||||
* method: 'someMethod2',
|
||||
* params: ['a', 'b'],
|
||||
* success: function(result) {
|
||||
* console.dir(result);
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
define("tinymce/util/JSONRequest", [
|
||||
"tinymce/util/JSON",
|
||||
"tinymce/util/XHR",
|
||||
"tinymce/util/Tools"
|
||||
], function(JSON, XHR, Tools) {
|
||||
var extend = Tools.extend;
|
||||
|
||||
function JSONRequest(settings) {
|
||||
this.settings = extend({}, settings);
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple helper function to send a JSON-RPC request without the need to initialize an object.
|
||||
* Consult the Wiki API documentation for more details on what you can pass to this function.
|
||||
*
|
||||
* @method sendRPC
|
||||
* @static
|
||||
* @param {Object} o Call object where there are three field id, method and params this object should also contain callbacks etc.
|
||||
*/
|
||||
JSONRequest.sendRPC = function(o) {
|
||||
return new JSONRequest().send(o);
|
||||
};
|
||||
|
||||
JSONRequest.prototype = {
|
||||
/**
|
||||
* Sends a JSON-RPC call. Consult the Wiki API documentation for more details on what you can pass to this function.
|
||||
*
|
||||
* @method send
|
||||
* @param {Object} args Call object where there are three field id, method and params this object should also contain callbacks etc.
|
||||
*/
|
||||
send: function(args) {
|
||||
var ecb = args.error, scb = args.success;
|
||||
|
||||
args = extend(this.settings, args);
|
||||
|
||||
args.success = function(c, x) {
|
||||
c = JSON.parse(c);
|
||||
|
||||
if (typeof c == 'undefined') {
|
||||
c = {
|
||||
error: 'JSON Parse error.'
|
||||
};
|
||||
}
|
||||
|
||||
if (c.error) {
|
||||
ecb.call(args.error_scope || args.scope, c.error, x);
|
||||
} else {
|
||||
scb.call(args.success_scope || args.scope, c.result);
|
||||
}
|
||||
};
|
||||
|
||||
args.error = function(ty, x) {
|
||||
if (ecb) {
|
||||
ecb.call(args.error_scope || args.scope, ty, x);
|
||||
}
|
||||
};
|
||||
|
||||
args.data = JSON.serialize({
|
||||
id: args.id || 'c' + (this.count++),
|
||||
method: args.method,
|
||||
params: args.params
|
||||
});
|
||||
|
||||
// JSON content type for Ruby on rails. Bug: #1883287
|
||||
args.content_type = 'application/json';
|
||||
|
||||
XHR.send(args);
|
||||
}
|
||||
};
|
||||
|
||||
return JSONRequest;
|
||||
});
|
||||
213
js/tinymce/classes/util/LocalStorage.js
Normal file
213
js/tinymce/classes/util/LocalStorage.js
Normal file
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
* LocalStorage.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class will simulate LocalStorage on IE 7 and return the native version on modern browsers.
|
||||
* Storage is done using userData on IE 7 and a special serialization format. The format is designed
|
||||
* to be as small as possible by making sure that the keys and values doesn't need to be encoded. This
|
||||
* makes it possible to store for example HTML data.
|
||||
*
|
||||
* Storage format for userData:
|
||||
* <base 32 key length>,<key string>,<base 32 value length>,<value>,...
|
||||
*
|
||||
* For example this data key1=value1,key2=value2 would be:
|
||||
* 4,key1,6,value1,4,key2,6,value2
|
||||
*
|
||||
* @class tinymce.util.LocalStorage
|
||||
* @static
|
||||
* @version 4.0
|
||||
* @example
|
||||
* tinymce.util.LocalStorage.setItem('key', 'value');
|
||||
* var value = tinymce.util.LocalStorage.getItem('key');
|
||||
*/
|
||||
define("tinymce/util/LocalStorage", [], function() {
|
||||
var LocalStorage, storageElm, items, keys, userDataKey, hasOldIEDataSupport;
|
||||
|
||||
// Check for native support
|
||||
try {
|
||||
if (window.localStorage) {
|
||||
return localStorage;
|
||||
}
|
||||
} catch (ex) {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
userDataKey = "tinymce";
|
||||
storageElm = document.documentElement;
|
||||
hasOldIEDataSupport = !!storageElm.addBehavior;
|
||||
|
||||
if (hasOldIEDataSupport) {
|
||||
storageElm.addBehavior('#default#userData');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the keys names and updates LocalStorage.length property. Since IE7 doesn't have any getters/setters.
|
||||
*/
|
||||
function updateKeys() {
|
||||
keys = [];
|
||||
|
||||
for (var key in items) {
|
||||
keys.push(key);
|
||||
}
|
||||
|
||||
LocalStorage.length = keys.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the userData string and parses it into the items structure.
|
||||
*/
|
||||
function load() {
|
||||
var key, data, value, pos = 0;
|
||||
|
||||
items = {};
|
||||
|
||||
// localStorage can be disabled on WebKit/Gecko so make a dummy storage
|
||||
if (!hasOldIEDataSupport) {
|
||||
return;
|
||||
}
|
||||
|
||||
function next(end) {
|
||||
var value, nextPos;
|
||||
|
||||
nextPos = end !== undefined ? pos + end : data.indexOf(',', pos);
|
||||
if (nextPos === -1 || nextPos > data.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
value = data.substring(pos, nextPos);
|
||||
pos = nextPos + 1;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
storageElm.load(userDataKey);
|
||||
data = storageElm.getAttribute(userDataKey) || '';
|
||||
|
||||
do {
|
||||
var offset = next();
|
||||
if (offset === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
key = next(parseInt(offset, 32) || 0);
|
||||
if (key !== null) {
|
||||
offset = next();
|
||||
if (offset === null) {
|
||||
break;
|
||||
}
|
||||
|
||||
value = next(parseInt(offset, 32) || 0);
|
||||
|
||||
if (key) {
|
||||
items[key] = value;
|
||||
}
|
||||
}
|
||||
} while (key !== null);
|
||||
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the items structure into a the userData format.
|
||||
*/
|
||||
function save() {
|
||||
var value, data = '';
|
||||
|
||||
// localStorage can be disabled on WebKit/Gecko so make a dummy storage
|
||||
if (!hasOldIEDataSupport) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (var key in items) {
|
||||
value = items[key];
|
||||
data += (data ? ',' : '') + key.length.toString(32) + ',' + key + ',' + value.length.toString(32) + ',' + value;
|
||||
}
|
||||
|
||||
storageElm.setAttribute(userDataKey, data);
|
||||
|
||||
try {
|
||||
storageElm.save(userDataKey);
|
||||
} catch (ex) {
|
||||
// Ignore disk full
|
||||
}
|
||||
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
LocalStorage = {
|
||||
/**
|
||||
* Length of the number of items in storage.
|
||||
*
|
||||
* @property length
|
||||
* @type Number
|
||||
* @return {Number} Number of items in storage.
|
||||
*/
|
||||
//length:0,
|
||||
|
||||
/**
|
||||
* Returns the key name by index.
|
||||
*
|
||||
* @method key
|
||||
* @param {Number} index Index of key to return.
|
||||
* @return {String} Key value or null if it wasn't found.
|
||||
*/
|
||||
key: function(index) {
|
||||
return keys[index];
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the value if the specified key or null if it wasn't found.
|
||||
*
|
||||
* @method getItem
|
||||
* @param {String} key Key of item to retrive.
|
||||
* @return {String} Value of the specified item or null if it wasn't found.
|
||||
*/
|
||||
getItem: function(key) {
|
||||
return key in items ? items[key] : null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets the value of the specified item by it's key.
|
||||
*
|
||||
* @method setItem
|
||||
* @param {String} key Key of the item to set.
|
||||
* @param {String} value Value of the item to set.
|
||||
*/
|
||||
setItem: function(key, value) {
|
||||
items[key] = "" + value;
|
||||
save();
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the specified item by key.
|
||||
*
|
||||
* @method removeItem
|
||||
* @param {String} key Key of item to remove.
|
||||
*/
|
||||
removeItem: function(key) {
|
||||
delete items[key];
|
||||
save();
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes all items.
|
||||
*
|
||||
* @method clear
|
||||
*/
|
||||
clear: function() {
|
||||
items = {};
|
||||
save();
|
||||
}
|
||||
};
|
||||
|
||||
load();
|
||||
|
||||
return LocalStorage;
|
||||
});
|
||||
129
js/tinymce/classes/util/Observable.js
Normal file
129
js/tinymce/classes/util/Observable.js
Normal file
@@ -0,0 +1,129 @@
|
||||
/**
|
||||
* Observable.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This mixin will add event binding logic to classes.
|
||||
*
|
||||
* @mixin tinymce.util.Observable
|
||||
*/
|
||||
define("tinymce/util/Observable", [
|
||||
"tinymce/util/EventDispatcher"
|
||||
], function(EventDispatcher) {
|
||||
function getEventDispatcher(obj) {
|
||||
if (!obj._eventDispatcher) {
|
||||
obj._eventDispatcher = new EventDispatcher({
|
||||
scope: obj,
|
||||
toggleEvent: function(name, state) {
|
||||
if (EventDispatcher.isNative(name) && obj.toggleNativeEvent) {
|
||||
obj.toggleNativeEvent(name, state);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return obj._eventDispatcher;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Fires the specified event by name.
|
||||
*
|
||||
* @method fire
|
||||
* @param {String} name Name of the event to fire.
|
||||
* @param {Object?} args Event arguments.
|
||||
* @param {Boolean?} bubble True/false if the event is to be bubbled.
|
||||
* @return {Object} Event args instance passed in.
|
||||
* @example
|
||||
* instance.fire('event', {...});
|
||||
*/
|
||||
fire: function(name, args, bubble) {
|
||||
var self = this;
|
||||
|
||||
// Prevent all events except the remove event after the instance has been removed
|
||||
if (self.removed && name !== "remove") {
|
||||
return args;
|
||||
}
|
||||
|
||||
args = getEventDispatcher(self).fire(name, args, bubble);
|
||||
|
||||
// Bubble event up to parents
|
||||
if (bubble !== false && self.parent) {
|
||||
var parent = self.parent();
|
||||
while (parent && !args.isPropagationStopped()) {
|
||||
parent.fire(name, args, false);
|
||||
parent = parent.parent();
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
},
|
||||
|
||||
/**
|
||||
* Binds an event listener to a specific event by name.
|
||||
*
|
||||
* @method on
|
||||
* @param {String} name Event name or space separated list of events to bind.
|
||||
* @param {callback} callback Callback to be executed when the event occurs.
|
||||
* @param {Boolean} first Optional flag if the event should be prepended. Use this with care.
|
||||
* @return {Object} Current class instance.
|
||||
* @example
|
||||
* instance.on('event', function(e) {
|
||||
* // Callback logic
|
||||
* });
|
||||
*/
|
||||
on: function(name, callback, prepend) {
|
||||
return getEventDispatcher(this).on(name, callback, prepend);
|
||||
},
|
||||
|
||||
/**
|
||||
* Unbinds an event listener to a specific event by name.
|
||||
*
|
||||
* @method off
|
||||
* @param {String?} name Name of the event to unbind.
|
||||
* @param {callback?} callback Callback to unbind.
|
||||
* @return {Object} Current class instance.
|
||||
* @example
|
||||
* // Unbind specific callback
|
||||
* instance.off('event', handler);
|
||||
*
|
||||
* // Unbind all listeners by name
|
||||
* instance.off('event');
|
||||
*
|
||||
* // Unbind all events
|
||||
* instance.off();
|
||||
*/
|
||||
off: function(name, callback) {
|
||||
return getEventDispatcher(this).off(name, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Bind the event callback and once it fires the callback is removed.
|
||||
*
|
||||
* @method once
|
||||
* @param {String} name Name of the event to bind.
|
||||
* @param {callback} callback Callback to bind only once.
|
||||
* @return {Object} Current class instance.
|
||||
*/
|
||||
once: function(name, callback) {
|
||||
return getEventDispatcher(this).once(name, callback);
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns true/false if the object has a event of the specified name.
|
||||
*
|
||||
* @method hasEventListeners
|
||||
* @param {String} name Name of the event to check for.
|
||||
* @return {Boolean} true/false if the event exists or not.
|
||||
*/
|
||||
hasEventListeners: function(name) {
|
||||
return getEventDispatcher(this).has(name);
|
||||
}
|
||||
};
|
||||
});
|
||||
200
js/tinymce/classes/util/Promise.js
Normal file
200
js/tinymce/classes/util/Promise.js
Normal file
@@ -0,0 +1,200 @@
|
||||
/**
|
||||
* Promise.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* Promise polyfill under MIT license: https://github.com/taylorhakes/promise-polyfill
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/* eslint-disable */
|
||||
/* jshint ignore:start */
|
||||
|
||||
/**
|
||||
* Modifed to be a feature fill and wrapped as tinymce module.
|
||||
*/
|
||||
define("tinymce/util/Promise", [], function() {
|
||||
if (window.Promise) {
|
||||
return window.Promise;
|
||||
}
|
||||
|
||||
// Use polyfill for setImmediate for performance gains
|
||||
var asap = Promise.immediateFn || (typeof setImmediate === 'function' && setImmediate) ||
|
||||
function(fn) { setTimeout(fn, 1); };
|
||||
|
||||
// Polyfill for Function.prototype.bind
|
||||
function bind(fn, thisArg) {
|
||||
return function() {
|
||||
fn.apply(thisArg, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
var isArray = Array.isArray || function(value) { return Object.prototype.toString.call(value) === "[object Array]"; };
|
||||
|
||||
function Promise(fn) {
|
||||
if (typeof this !== 'object') throw new TypeError('Promises must be constructed via new');
|
||||
if (typeof fn !== 'function') throw new TypeError('not a function');
|
||||
this._state = null;
|
||||
this._value = null;
|
||||
this._deferreds = [];
|
||||
|
||||
doResolve(fn, bind(resolve, this), bind(reject, this));
|
||||
}
|
||||
|
||||
function handle(deferred) {
|
||||
var me = this;
|
||||
if (this._state === null) {
|
||||
this._deferreds.push(deferred);
|
||||
return;
|
||||
}
|
||||
asap(function() {
|
||||
var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
|
||||
if (cb === null) {
|
||||
(me._state ? deferred.resolve : deferred.reject)(me._value);
|
||||
return;
|
||||
}
|
||||
var ret;
|
||||
try {
|
||||
ret = cb(me._value);
|
||||
}
|
||||
catch (e) {
|
||||
deferred.reject(e);
|
||||
return;
|
||||
}
|
||||
deferred.resolve(ret);
|
||||
});
|
||||
}
|
||||
|
||||
function resolve(newValue) {
|
||||
try { //Promise Resolution Procedure: https://github.com/promises-aplus/promises-spec#the-promise-resolution-procedure
|
||||
if (newValue === this) throw new TypeError('A promise cannot be resolved with itself.');
|
||||
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
||||
var then = newValue.then;
|
||||
if (typeof then === 'function') {
|
||||
doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
|
||||
return;
|
||||
}
|
||||
}
|
||||
this._state = true;
|
||||
this._value = newValue;
|
||||
finale.call(this);
|
||||
} catch (e) { reject.call(this, e); }
|
||||
}
|
||||
|
||||
function reject(newValue) {
|
||||
this._state = false;
|
||||
this._value = newValue;
|
||||
finale.call(this);
|
||||
}
|
||||
|
||||
function finale() {
|
||||
for (var i = 0, len = this._deferreds.length; i < len; i++) {
|
||||
handle.call(this, this._deferreds[i]);
|
||||
}
|
||||
this._deferreds = null;
|
||||
}
|
||||
|
||||
function Handler(onFulfilled, onRejected, resolve, reject){
|
||||
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
||||
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
||||
this.resolve = resolve;
|
||||
this.reject = reject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Take a potentially misbehaving resolver function and make sure
|
||||
* onFulfilled and onRejected are only called once.
|
||||
*
|
||||
* Makes no guarantees about asynchrony.
|
||||
*/
|
||||
function doResolve(fn, onFulfilled, onRejected) {
|
||||
var done = false;
|
||||
try {
|
||||
fn(function (value) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
onFulfilled(value);
|
||||
}, function (reason) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
onRejected(reason);
|
||||
});
|
||||
} catch (ex) {
|
||||
if (done) return;
|
||||
done = true;
|
||||
onRejected(ex);
|
||||
}
|
||||
}
|
||||
|
||||
Promise.prototype['catch'] = function (onRejected) {
|
||||
return this.then(null, onRejected);
|
||||
};
|
||||
|
||||
Promise.prototype.then = function(onFulfilled, onRejected) {
|
||||
var me = this;
|
||||
return new Promise(function(resolve, reject) {
|
||||
handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
|
||||
});
|
||||
};
|
||||
|
||||
Promise.all = function () {
|
||||
var args = Array.prototype.slice.call(arguments.length === 1 && isArray(arguments[0]) ? arguments[0] : arguments);
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (args.length === 0) return resolve([]);
|
||||
var remaining = args.length;
|
||||
function res(i, val) {
|
||||
try {
|
||||
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
||||
var then = val.then;
|
||||
if (typeof then === 'function') {
|
||||
then.call(val, function (val) { res(i, val); }, reject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
args[i] = val;
|
||||
if (--remaining === 0) {
|
||||
resolve(args);
|
||||
}
|
||||
} catch (ex) {
|
||||
reject(ex);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
res(i, args[i]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Promise.resolve = function (value) {
|
||||
if (value && typeof value === 'object' && value.constructor === Promise) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
resolve(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.reject = function (value) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
reject(value);
|
||||
});
|
||||
};
|
||||
|
||||
Promise.race = function (values) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
for(var i = 0, len = values.length; i < len; i++) {
|
||||
values[i].then(resolve, reject);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return Promise;
|
||||
});
|
||||
|
||||
/* jshint ignore:end */
|
||||
/* eslint-enable */
|
||||
1701
js/tinymce/classes/util/Quirks.js
Normal file
1701
js/tinymce/classes/util/Quirks.js
Normal file
File diff suppressed because it is too large
Load Diff
442
js/tinymce/classes/util/Tools.js
Normal file
442
js/tinymce/classes/util/Tools.js
Normal file
@@ -0,0 +1,442 @@
|
||||
/**
|
||||
* Tools.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class contains various utlity functions. These are also exposed
|
||||
* directly on the tinymce namespace.
|
||||
*
|
||||
* @class tinymce.util.Tools
|
||||
*/
|
||||
define("tinymce/util/Tools", [
|
||||
"tinymce/Env",
|
||||
"tinymce/util/Arr"
|
||||
], function(Env, Arr) {
|
||||
/**
|
||||
* Removes whitespace from the beginning and end of a string.
|
||||
*
|
||||
* @method trim
|
||||
* @param {String} s String to remove whitespace from.
|
||||
* @return {String} New string with removed whitespace.
|
||||
*/
|
||||
var whiteSpaceRegExp = /^\s*|\s*$/g;
|
||||
|
||||
function trim(str) {
|
||||
return (str === null || str === undefined) ? '' : ("" + str).replace(whiteSpaceRegExp, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a object is of a specific type for example an array.
|
||||
*
|
||||
* @method is
|
||||
* @param {Object} obj Object to check type of.
|
||||
* @param {string} type Optional type to check for.
|
||||
* @return {Boolean} true/false if the object is of the specified type.
|
||||
*/
|
||||
function is(obj, type) {
|
||||
if (!type) {
|
||||
return obj !== undefined;
|
||||
}
|
||||
|
||||
if (type == 'array' && Arr.isArray(obj)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return typeof obj == type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a name/object map out of an array with names.
|
||||
*
|
||||
* @method makeMap
|
||||
* @param {Array/String} items Items to make map out of.
|
||||
* @param {String} delim Optional delimiter to split string by.
|
||||
* @param {Object} map Optional map to add items to.
|
||||
* @return {Object} Name/value map of items.
|
||||
*/
|
||||
function makeMap(items, delim, map) {
|
||||
var i;
|
||||
|
||||
items = items || [];
|
||||
delim = delim || ',';
|
||||
|
||||
if (typeof items == "string") {
|
||||
items = items.split(delim);
|
||||
}
|
||||
|
||||
map = map || {};
|
||||
|
||||
i = items.length;
|
||||
while (i--) {
|
||||
map[items[i]] = {};
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a class, subclass or static singleton.
|
||||
* More details on this method can be found in the Wiki.
|
||||
*
|
||||
* @method create
|
||||
* @param {String} s Class name, inheritance and prefix.
|
||||
* @param {Object} p Collection of methods to add to the class.
|
||||
* @param {Object} root Optional root object defaults to the global window object.
|
||||
* @example
|
||||
* // Creates a basic class
|
||||
* tinymce.create('tinymce.somepackage.SomeClass', {
|
||||
* SomeClass: function() {
|
||||
* // Class constructor
|
||||
* },
|
||||
*
|
||||
* method: function() {
|
||||
* // Some method
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* // Creates a basic subclass class
|
||||
* tinymce.create('tinymce.somepackage.SomeSubClass:tinymce.somepackage.SomeClass', {
|
||||
* SomeSubClass: function() {
|
||||
* // Class constructor
|
||||
* this.parent(); // Call parent constructor
|
||||
* },
|
||||
*
|
||||
* method: function() {
|
||||
* // Some method
|
||||
* this.parent(); // Call parent method
|
||||
* },
|
||||
*
|
||||
* 'static': {
|
||||
* staticMethod: function() {
|
||||
* // Static method
|
||||
* }
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* // Creates a singleton/static class
|
||||
* tinymce.create('static tinymce.somepackage.SomeSingletonClass', {
|
||||
* method: function() {
|
||||
* // Some method
|
||||
* }
|
||||
* });
|
||||
*/
|
||||
function create(s, p, root) {
|
||||
var self = this, sp, ns, cn, scn, c, de = 0;
|
||||
|
||||
// Parse : <prefix> <class>:<super class>
|
||||
s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
|
||||
cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
|
||||
|
||||
// Create namespace for new class
|
||||
ns = self.createNS(s[3].replace(/\.\w+$/, ''), root);
|
||||
|
||||
// Class already exists
|
||||
if (ns[cn]) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Make pure static class
|
||||
if (s[2] == 'static') {
|
||||
ns[cn] = p;
|
||||
|
||||
if (this.onCreate) {
|
||||
this.onCreate(s[2], s[3], ns[cn]);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Create default constructor
|
||||
if (!p[cn]) {
|
||||
p[cn] = function() {};
|
||||
de = 1;
|
||||
}
|
||||
|
||||
// Add constructor and methods
|
||||
ns[cn] = p[cn];
|
||||
self.extend(ns[cn].prototype, p);
|
||||
|
||||
// Extend
|
||||
if (s[5]) {
|
||||
sp = self.resolve(s[5]).prototype;
|
||||
scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
|
||||
|
||||
// Extend constructor
|
||||
c = ns[cn];
|
||||
if (de) {
|
||||
// Add passthrough constructor
|
||||
ns[cn] = function() {
|
||||
return sp[scn].apply(this, arguments);
|
||||
};
|
||||
} else {
|
||||
// Add inherit constructor
|
||||
ns[cn] = function() {
|
||||
this.parent = sp[scn];
|
||||
return c.apply(this, arguments);
|
||||
};
|
||||
}
|
||||
ns[cn].prototype[cn] = ns[cn];
|
||||
|
||||
// Add super methods
|
||||
self.each(sp, function(f, n) {
|
||||
ns[cn].prototype[n] = sp[n];
|
||||
});
|
||||
|
||||
// Add overridden methods
|
||||
self.each(p, function(f, n) {
|
||||
// Extend methods if needed
|
||||
if (sp[n]) {
|
||||
ns[cn].prototype[n] = function() {
|
||||
this.parent = sp[n];
|
||||
return f.apply(this, arguments);
|
||||
};
|
||||
} else {
|
||||
if (n != cn) {
|
||||
ns[cn].prototype[n] = f;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Add static methods
|
||||
/*jshint sub:true*/
|
||||
/*eslint dot-notation:0*/
|
||||
self.each(p['static'], function(f, n) {
|
||||
ns[cn][n] = f;
|
||||
});
|
||||
}
|
||||
|
||||
function extend(obj, ext) {
|
||||
var i, l, name, args = arguments, value;
|
||||
|
||||
for (i = 1, l = args.length; i < l; i++) {
|
||||
ext = args[i];
|
||||
for (name in ext) {
|
||||
if (ext.hasOwnProperty(name)) {
|
||||
value = ext[name];
|
||||
|
||||
if (value !== undefined) {
|
||||
obj[name] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executed the specified function for each item in a object tree.
|
||||
*
|
||||
* @method walk
|
||||
* @param {Object} o Object tree to walk though.
|
||||
* @param {function} f Function to call for each item.
|
||||
* @param {String} n Optional name of collection inside the objects to walk for example childNodes.
|
||||
* @param {String} s Optional scope to execute the function in.
|
||||
*/
|
||||
function walk(o, f, n, s) {
|
||||
s = s || this;
|
||||
|
||||
if (o) {
|
||||
if (n) {
|
||||
o = o[n];
|
||||
}
|
||||
|
||||
Arr.each(o, function(o, i) {
|
||||
if (f.call(s, o, i, n) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
walk(o, f, n, s);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a namespace on a specific object.
|
||||
*
|
||||
* @method createNS
|
||||
* @param {String} n Namespace to create for example a.b.c.d.
|
||||
* @param {Object} o Optional object to add namespace to, defaults to window.
|
||||
* @return {Object} New namespace object the last item in path.
|
||||
* @example
|
||||
* // Create some namespace
|
||||
* tinymce.createNS('tinymce.somepackage.subpackage');
|
||||
*
|
||||
* // Add a singleton
|
||||
* var tinymce.somepackage.subpackage.SomeSingleton = {
|
||||
* method: function() {
|
||||
* // Some method
|
||||
* }
|
||||
* };
|
||||
*/
|
||||
function createNS(n, o) {
|
||||
var i, v;
|
||||
|
||||
o = o || window;
|
||||
|
||||
n = n.split('.');
|
||||
for (i = 0; i < n.length; i++) {
|
||||
v = n[i];
|
||||
|
||||
if (!o[v]) {
|
||||
o[v] = {};
|
||||
}
|
||||
|
||||
o = o[v];
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves a string and returns the object from a specific structure.
|
||||
*
|
||||
* @method resolve
|
||||
* @param {String} n Path to resolve for example a.b.c.d.
|
||||
* @param {Object} o Optional object to search though, defaults to window.
|
||||
* @return {Object} Last object in path or null if it couldn't be resolved.
|
||||
* @example
|
||||
* // Resolve a path into an object reference
|
||||
* var obj = tinymce.resolve('a.b.c.d');
|
||||
*/
|
||||
function resolve(n, o) {
|
||||
var i, l;
|
||||
|
||||
o = o || window;
|
||||
|
||||
n = n.split('.');
|
||||
for (i = 0, l = n.length; i < l; i++) {
|
||||
o = o[n[i]];
|
||||
|
||||
if (!o) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string but removes the whitespace before and after each value.
|
||||
*
|
||||
* @method explode
|
||||
* @param {string} s String to split.
|
||||
* @param {string} d Delimiter to split by.
|
||||
* @example
|
||||
* // Split a string into an array with a,b,c
|
||||
* var arr = tinymce.explode('a, b, c');
|
||||
*/
|
||||
function explode(s, d) {
|
||||
if (!s || is(s, 'array')) {
|
||||
return s;
|
||||
}
|
||||
|
||||
return Arr.map(s.split(d || ','), trim);
|
||||
}
|
||||
|
||||
function _addCacheSuffix(url) {
|
||||
var cacheSuffix = Env.cacheSuffix;
|
||||
|
||||
if (cacheSuffix) {
|
||||
url += (url.indexOf('?') === -1 ? '?' : '&') + cacheSuffix;
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
return {
|
||||
trim: trim,
|
||||
|
||||
/**
|
||||
* Returns true/false if the object is an array or not.
|
||||
*
|
||||
* @method isArray
|
||||
* @param {Object} obj Object to check.
|
||||
* @return {boolean} true/false state if the object is an array or not.
|
||||
*/
|
||||
isArray: Arr.isArray,
|
||||
|
||||
is: is,
|
||||
|
||||
/**
|
||||
* Converts the specified object into a real JavaScript array.
|
||||
*
|
||||
* @method toArray
|
||||
* @param {Object} obj Object to convert into array.
|
||||
* @return {Array} Array object based in input.
|
||||
*/
|
||||
toArray: Arr.toArray,
|
||||
makeMap: makeMap,
|
||||
|
||||
/**
|
||||
* Performs an iteration of all items in a collection such as an object or array. This method will execure the
|
||||
* callback function for each item in the collection, if the callback returns false the iteration will terminate.
|
||||
* The callback has the following format: cb(value, key_or_index).
|
||||
*
|
||||
* @method each
|
||||
* @param {Object} o Collection to iterate.
|
||||
* @param {function} cb Callback function to execute for each item.
|
||||
* @param {Object} s Optional scope to execute the callback in.
|
||||
* @example
|
||||
* // Iterate an array
|
||||
* tinymce.each([1,2,3], function(v, i) {
|
||||
* console.debug("Value: " + v + ", Index: " + i);
|
||||
* });
|
||||
*
|
||||
* // Iterate an object
|
||||
* tinymce.each({a: 1, b: 2, c: 3], function(v, k) {
|
||||
* console.debug("Value: " + v + ", Key: " + k);
|
||||
* });
|
||||
*/
|
||||
each: Arr.each,
|
||||
|
||||
/**
|
||||
* Creates a new array by the return value of each iteration function call. This enables you to convert
|
||||
* one array list into another.
|
||||
*
|
||||
* @method map
|
||||
* @param {Array} array Array of items to iterate.
|
||||
* @param {function} callback Function to call for each item. It's return value will be the new value.
|
||||
* @return {Array} Array with new values based on function return values.
|
||||
*/
|
||||
map: Arr.map,
|
||||
|
||||
/**
|
||||
* Filters out items from the input array by calling the specified function for each item.
|
||||
* If the function returns false the item will be excluded if it returns true it will be included.
|
||||
*
|
||||
* @method grep
|
||||
* @param {Array} a Array of items to loop though.
|
||||
* @param {function} f Function to call for each item. Include/exclude depends on it's return value.
|
||||
* @return {Array} New array with values imported and filtered based in input.
|
||||
* @example
|
||||
* // Filter out some items, this will return an array with 4 and 5
|
||||
* var items = tinymce.grep([1,2,3,4,5], function(v) {return v > 3;});
|
||||
*/
|
||||
grep: Arr.filter,
|
||||
|
||||
/**
|
||||
* Returns true/false if the object is an array or not.
|
||||
*
|
||||
* @method isArray
|
||||
* @param {Object} obj Object to check.
|
||||
* @return {boolean} true/false state if the object is an array or not.
|
||||
*/
|
||||
inArray: Arr.indexOf,
|
||||
|
||||
extend: extend,
|
||||
create: create,
|
||||
walk: walk,
|
||||
createNS: createNS,
|
||||
resolve: resolve,
|
||||
explode: explode,
|
||||
_addCacheSuffix: _addCacheSuffix
|
||||
};
|
||||
});
|
||||
411
js/tinymce/classes/util/URI.js
Normal file
411
js/tinymce/classes/util/URI.js
Normal file
@@ -0,0 +1,411 @@
|
||||
/**
|
||||
* URI.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class handles parsing, modification and serialization of URI/URL strings.
|
||||
* @class tinymce.util.URI
|
||||
*/
|
||||
define("tinymce/util/URI", [
|
||||
"tinymce/util/Tools"
|
||||
], function(Tools) {
|
||||
var each = Tools.each, trim = Tools.trim;
|
||||
var queryParts = "source protocol authority userInfo user password host port relative path directory file query anchor".split(' ');
|
||||
var DEFAULT_PORTS = {
|
||||
'ftp': 21,
|
||||
'http': 80,
|
||||
'https': 443,
|
||||
'mailto': 25
|
||||
};
|
||||
|
||||
/**
|
||||
* Constructs a new URI instance.
|
||||
*
|
||||
* @constructor
|
||||
* @method URI
|
||||
* @param {String} url URI string to parse.
|
||||
* @param {Object} settings Optional settings object.
|
||||
*/
|
||||
function URI(url, settings) {
|
||||
var self = this, baseUri, base_url;
|
||||
|
||||
url = trim(url);
|
||||
settings = self.settings = settings || {};
|
||||
baseUri = settings.base_uri;
|
||||
|
||||
// Strange app protocol that isn't http/https or local anchor
|
||||
// For example: mailto,skype,tel etc.
|
||||
if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
|
||||
self.source = url;
|
||||
return;
|
||||
}
|
||||
|
||||
var isProtocolRelative = url.indexOf('//') === 0;
|
||||
|
||||
// Absolute path with no host, fake host and protocol
|
||||
if (url.indexOf('/') === 0 && !isProtocolRelative) {
|
||||
url = (baseUri ? baseUri.protocol || 'http' : 'http') + '://mce_host' + url;
|
||||
}
|
||||
|
||||
// Relative path http:// or protocol relative //path
|
||||
if (!/^[\w\-]*:?\/\//.test(url)) {
|
||||
base_url = settings.base_uri ? settings.base_uri.path : new URI(location.href).directory;
|
||||
if (settings.base_uri.protocol === "") {
|
||||
url = '//mce_host' + self.toAbsPath(base_url, url);
|
||||
} else {
|
||||
url = /([^#?]*)([#?]?.*)/.exec(url);
|
||||
url = ((baseUri && baseUri.protocol) || 'http') + '://mce_host' + self.toAbsPath(base_url, url[1]) + url[2];
|
||||
}
|
||||
}
|
||||
|
||||
// Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
|
||||
url = url.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
|
||||
|
||||
/*jshint maxlen: 255 */
|
||||
/*eslint max-len: 0 */
|
||||
url = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
|
||||
|
||||
each(queryParts, function(v, i) {
|
||||
var part = url[i];
|
||||
|
||||
// Zope 3 workaround, they use @@something
|
||||
if (part) {
|
||||
part = part.replace(/\(mce_at\)/g, '@@');
|
||||
}
|
||||
|
||||
self[v] = part;
|
||||
});
|
||||
|
||||
if (baseUri) {
|
||||
if (!self.protocol) {
|
||||
self.protocol = baseUri.protocol;
|
||||
}
|
||||
|
||||
if (!self.userInfo) {
|
||||
self.userInfo = baseUri.userInfo;
|
||||
}
|
||||
|
||||
if (!self.port && self.host === 'mce_host') {
|
||||
self.port = baseUri.port;
|
||||
}
|
||||
|
||||
if (!self.host || self.host === 'mce_host') {
|
||||
self.host = baseUri.host;
|
||||
}
|
||||
|
||||
self.source = '';
|
||||
}
|
||||
|
||||
if (isProtocolRelative) {
|
||||
self.protocol = '';
|
||||
}
|
||||
|
||||
//t.path = t.path || '/';
|
||||
}
|
||||
|
||||
URI.prototype = {
|
||||
/**
|
||||
* Sets the internal path part of the URI.
|
||||
*
|
||||
* @method setPath
|
||||
* @param {string} path Path string to set.
|
||||
*/
|
||||
setPath: function(path) {
|
||||
var self = this;
|
||||
|
||||
path = /^(.*?)\/?(\w+)?$/.exec(path);
|
||||
|
||||
// Update path parts
|
||||
self.path = path[0];
|
||||
self.directory = path[1];
|
||||
self.file = path[2];
|
||||
|
||||
// Rebuild source
|
||||
self.source = '';
|
||||
self.getURI();
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the specified URI into a relative URI based on the current URI instance location.
|
||||
*
|
||||
* @method toRelative
|
||||
* @param {String} uri URI to convert into a relative path/URI.
|
||||
* @return {String} Relative URI from the point specified in the current URI instance.
|
||||
* @example
|
||||
* // Converts an absolute URL to an relative URL url will be somedir/somefile.htm
|
||||
* var url = new tinymce.util.URI('http://www.site.com/dir/').toRelative('http://www.site.com/dir/somedir/somefile.htm');
|
||||
*/
|
||||
toRelative: function(uri) {
|
||||
var self = this, output;
|
||||
|
||||
if (uri === "./") {
|
||||
return uri;
|
||||
}
|
||||
|
||||
uri = new URI(uri, {base_uri: self});
|
||||
|
||||
// Not on same domain/port or protocol
|
||||
if ((uri.host != 'mce_host' && self.host != uri.host && uri.host) || self.port != uri.port ||
|
||||
(self.protocol != uri.protocol && uri.protocol !== "")) {
|
||||
return uri.getURI();
|
||||
}
|
||||
|
||||
var tu = self.getURI(), uu = uri.getURI();
|
||||
|
||||
// Allow usage of the base_uri when relative_urls = true
|
||||
if (tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu)) {
|
||||
return tu;
|
||||
}
|
||||
|
||||
output = self.toRelPath(self.path, uri.path);
|
||||
|
||||
// Add query
|
||||
if (uri.query) {
|
||||
output += '?' + uri.query;
|
||||
}
|
||||
|
||||
// Add anchor
|
||||
if (uri.anchor) {
|
||||
output += '#' + uri.anchor;
|
||||
}
|
||||
|
||||
return output;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts the specified URI into a absolute URI based on the current URI instance location.
|
||||
*
|
||||
* @method toAbsolute
|
||||
* @param {String} uri URI to convert into a relative path/URI.
|
||||
* @param {Boolean} noHost No host and protocol prefix.
|
||||
* @return {String} Absolute URI from the point specified in the current URI instance.
|
||||
* @example
|
||||
* // Converts an relative URL to an absolute URL url will be http://www.site.com/dir/somedir/somefile.htm
|
||||
* var url = new tinymce.util.URI('http://www.site.com/dir/').toAbsolute('somedir/somefile.htm');
|
||||
*/
|
||||
toAbsolute: function(uri, noHost) {
|
||||
uri = new URI(uri, {base_uri: this});
|
||||
|
||||
return uri.getURI(noHost && this.isSameOrigin(uri));
|
||||
},
|
||||
|
||||
/**
|
||||
* Determine whether the given URI has the same origin as this URI. Based on RFC-6454.
|
||||
* Supports default ports for protocols listed in DEFAULT_PORTS. Unsupported protocols will fail safe: they
|
||||
* won't match, if the port specifications differ.
|
||||
*
|
||||
* @method isSameOrigin
|
||||
* @param {tinymce.util.URI} uri Uri instance to compare.
|
||||
* @returns {Boolean} True if the origins are the same.
|
||||
*/
|
||||
isSameOrigin: function(uri) {
|
||||
if (this.host == uri.host && this.protocol == uri.protocol) {
|
||||
if (this.port == uri.port) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var defaultPort = DEFAULT_PORTS[this.protocol];
|
||||
if (defaultPort && ((this.port || defaultPort) == (uri.port || defaultPort))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a absolute path into a relative path.
|
||||
*
|
||||
* @method toRelPath
|
||||
* @param {String} base Base point to convert the path from.
|
||||
* @param {String} path Absolute path to convert into a relative path.
|
||||
*/
|
||||
toRelPath: function(base, path) {
|
||||
var items, breakPoint = 0, out = '', i, l;
|
||||
|
||||
// Split the paths
|
||||
base = base.substring(0, base.lastIndexOf('/'));
|
||||
base = base.split('/');
|
||||
items = path.split('/');
|
||||
|
||||
if (base.length >= items.length) {
|
||||
for (i = 0, l = base.length; i < l; i++) {
|
||||
if (i >= items.length || base[i] != items[i]) {
|
||||
breakPoint = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (base.length < items.length) {
|
||||
for (i = 0, l = items.length; i < l; i++) {
|
||||
if (i >= base.length || base[i] != items[i]) {
|
||||
breakPoint = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (breakPoint === 1) {
|
||||
return path;
|
||||
}
|
||||
|
||||
for (i = 0, l = base.length - (breakPoint - 1); i < l; i++) {
|
||||
out += "../";
|
||||
}
|
||||
|
||||
for (i = breakPoint - 1, l = items.length; i < l; i++) {
|
||||
if (i != breakPoint - 1) {
|
||||
out += "/" + items[i];
|
||||
} else {
|
||||
out += items[i];
|
||||
}
|
||||
}
|
||||
|
||||
return out;
|
||||
},
|
||||
|
||||
/**
|
||||
* Converts a relative path into a absolute path.
|
||||
*
|
||||
* @method toAbsPath
|
||||
* @param {String} base Base point to convert the path from.
|
||||
* @param {String} path Relative path to convert into an absolute path.
|
||||
*/
|
||||
toAbsPath: function(base, path) {
|
||||
var i, nb = 0, o = [], tr, outPath;
|
||||
|
||||
// Split paths
|
||||
tr = /\/$/.test(path) ? '/' : '';
|
||||
base = base.split('/');
|
||||
path = path.split('/');
|
||||
|
||||
// Remove empty chunks
|
||||
each(base, function(k) {
|
||||
if (k) {
|
||||
o.push(k);
|
||||
}
|
||||
});
|
||||
|
||||
base = o;
|
||||
|
||||
// Merge relURLParts chunks
|
||||
for (i = path.length - 1, o = []; i >= 0; i--) {
|
||||
// Ignore empty or .
|
||||
if (path[i].length === 0 || path[i] === ".") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Is parent
|
||||
if (path[i] === '..') {
|
||||
nb++;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Move up
|
||||
if (nb > 0) {
|
||||
nb--;
|
||||
continue;
|
||||
}
|
||||
|
||||
o.push(path[i]);
|
||||
}
|
||||
|
||||
i = base.length - nb;
|
||||
|
||||
// If /a/b/c or /
|
||||
if (i <= 0) {
|
||||
outPath = o.reverse().join('/');
|
||||
} else {
|
||||
outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
|
||||
}
|
||||
|
||||
// Add front / if it's needed
|
||||
if (outPath.indexOf('/') !== 0) {
|
||||
outPath = '/' + outPath;
|
||||
}
|
||||
|
||||
// Add traling / if it's needed
|
||||
if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
|
||||
outPath += tr;
|
||||
}
|
||||
|
||||
return outPath;
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the full URI of the internal structure.
|
||||
*
|
||||
* @method getURI
|
||||
* @param {Boolean} noProtoHost Optional no host and protocol part. Defaults to false.
|
||||
*/
|
||||
getURI: function(noProtoHost) {
|
||||
var s, self = this;
|
||||
|
||||
// Rebuild source
|
||||
if (!self.source || noProtoHost) {
|
||||
s = '';
|
||||
|
||||
if (!noProtoHost) {
|
||||
if (self.protocol) {
|
||||
s += self.protocol + '://';
|
||||
} else {
|
||||
s += '//';
|
||||
}
|
||||
|
||||
if (self.userInfo) {
|
||||
s += self.userInfo + '@';
|
||||
}
|
||||
|
||||
if (self.host) {
|
||||
s += self.host;
|
||||
}
|
||||
|
||||
if (self.port) {
|
||||
s += ':' + self.port;
|
||||
}
|
||||
}
|
||||
|
||||
if (self.path) {
|
||||
s += self.path;
|
||||
}
|
||||
|
||||
if (self.query) {
|
||||
s += '?' + self.query;
|
||||
}
|
||||
|
||||
if (self.anchor) {
|
||||
s += '#' + self.anchor;
|
||||
}
|
||||
|
||||
self.source = s;
|
||||
}
|
||||
|
||||
return self.source;
|
||||
}
|
||||
};
|
||||
|
||||
URI.parseDataUri = function(uri) {
|
||||
var type, matches;
|
||||
|
||||
uri = decodeURIComponent(uri).split(',');
|
||||
|
||||
matches = /data:([^;]+)/.exec(uri[0]);
|
||||
if (matches) {
|
||||
type = matches[1];
|
||||
}
|
||||
|
||||
return {
|
||||
type: type,
|
||||
data: uri[1]
|
||||
};
|
||||
};
|
||||
|
||||
return URI;
|
||||
});
|
||||
37
js/tinymce/classes/util/VK.js
Normal file
37
js/tinymce/classes/util/VK.js
Normal file
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* VK.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This file exposes a set of the common KeyCodes for use. Please grow it as needed.
|
||||
*/
|
||||
define("tinymce/util/VK", [
|
||||
"tinymce/Env"
|
||||
], function(Env) {
|
||||
return {
|
||||
BACKSPACE: 8,
|
||||
DELETE: 46,
|
||||
DOWN: 40,
|
||||
ENTER: 13,
|
||||
LEFT: 37,
|
||||
RIGHT: 39,
|
||||
SPACEBAR: 32,
|
||||
TAB: 9,
|
||||
UP: 38,
|
||||
|
||||
modifierPressed: function(e) {
|
||||
return e.shiftKey || e.ctrlKey || e.altKey || this.metaKeyPressed(e);
|
||||
},
|
||||
|
||||
metaKeyPressed: function(e) {
|
||||
// Check if ctrl or meta key is pressed. Edge case for AltGr on Windows where it produces ctrlKey+altKey states
|
||||
return (Env.mac ? e.metaKey : e.ctrlKey && !e.altKey);
|
||||
}
|
||||
};
|
||||
});
|
||||
110
js/tinymce/classes/util/XHR.js
Normal file
110
js/tinymce/classes/util/XHR.js
Normal file
@@ -0,0 +1,110 @@
|
||||
/**
|
||||
* XHR.js
|
||||
*
|
||||
* Released under LGPL License.
|
||||
* Copyright (c) 1999-2015 Ephox Corp. All rights reserved
|
||||
*
|
||||
* License: http://www.tinymce.com/license
|
||||
* Contributing: http://www.tinymce.com/contributing
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class enables you to send XMLHTTPRequests cross browser.
|
||||
* @class tinymce.util.XHR
|
||||
* @mixes tinymce.util.Observable
|
||||
* @static
|
||||
* @example
|
||||
* // Sends a low level Ajax request
|
||||
* tinymce.util.XHR.send({
|
||||
* url: 'someurl',
|
||||
* success: function(text) {
|
||||
* console.debug(text);
|
||||
* }
|
||||
* });
|
||||
*
|
||||
* // Add custom header to XHR request
|
||||
* tinymce.util.XHR.on('beforeSend', function(e) {
|
||||
* e.xhr.setRequestHeader('X-Requested-With', 'Something');
|
||||
* });
|
||||
*/
|
||||
define("tinymce/util/XHR", [
|
||||
"tinymce/util/Observable",
|
||||
"tinymce/util/Tools"
|
||||
], function(Observable, Tools) {
|
||||
var XHR = {
|
||||
/**
|
||||
* Sends a XMLHTTPRequest.
|
||||
* Consult the Wiki for details on what settings this method takes.
|
||||
*
|
||||
* @method send
|
||||
* @param {Object} settings Object will target URL, callbacks and other info needed to make the request.
|
||||
*/
|
||||
send: function(settings) {
|
||||
var xhr, count = 0;
|
||||
|
||||
function ready() {
|
||||
if (!settings.async || xhr.readyState == 4 || count++ > 10000) {
|
||||
if (settings.success && count < 10000 && xhr.status == 200) {
|
||||
settings.success.call(settings.success_scope, '' + xhr.responseText, xhr, settings);
|
||||
} else if (settings.error) {
|
||||
settings.error.call(settings.error_scope, count > 10000 ? 'TIMED_OUT' : 'GENERAL', xhr, settings);
|
||||
}
|
||||
|
||||
xhr = null;
|
||||
} else {
|
||||
setTimeout(ready, 10);
|
||||
}
|
||||
}
|
||||
|
||||
// Default settings
|
||||
settings.scope = settings.scope || this;
|
||||
settings.success_scope = settings.success_scope || settings.scope;
|
||||
settings.error_scope = settings.error_scope || settings.scope;
|
||||
settings.async = settings.async === false ? false : true;
|
||||
settings.data = settings.data || '';
|
||||
|
||||
XHR.fire('beforeInitialize', {settings: settings});
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
|
||||
if (xhr) {
|
||||
if (xhr.overrideMimeType) {
|
||||
xhr.overrideMimeType(settings.content_type);
|
||||
}
|
||||
|
||||
xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async);
|
||||
|
||||
if (settings.crossDomain) {
|
||||
xhr.withCredentials = true;
|
||||
}
|
||||
|
||||
if (settings.content_type) {
|
||||
xhr.setRequestHeader('Content-Type', settings.content_type);
|
||||
}
|
||||
|
||||
if (settings.requestheaders) {
|
||||
Tools.each(settings.requestheaders, function(header) {
|
||||
xhr.setRequestHeader(header.key, header.value);
|
||||
});
|
||||
}
|
||||
|
||||
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||
|
||||
xhr = XHR.fire('beforeSend', {xhr: xhr, settings: settings}).xhr;
|
||||
xhr.send(settings.data);
|
||||
|
||||
// Syncronous request
|
||||
if (!settings.async) {
|
||||
return ready();
|
||||
}
|
||||
|
||||
// Wait for response, onReadyStateChange can not be used since it leaks memory in IE
|
||||
setTimeout(ready, 10);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tools.extend(XHR, Observable);
|
||||
|
||||
return XHR;
|
||||
});
|
||||
Reference in New Issue
Block a user