/** * tinymce.js * * Copyright 2009, Moxiecode Systems AB * Released under LGPL License. * * License: http://tinymce.moxiecode.com/license * Contributing: http://tinymce.moxiecode.com/contributing */ (function(win) { var whiteSpaceRe = /^\s*|\s*$/g, undefined, isRegExpBroken = 'B'.replace(/A(.)|B/, '$1') === '$1'; /** * Core namespace with core functionality for the TinyMCE API all sub classes will be added to this namespace/object. * * @static * @class tinymce * @example * // Using each method * tinymce.each([1, 2, 3], function(v, i) { * console.log(i + '=' + v); * }); * * // Checking for a specific browser * if (tinymce.isIE) * console.log("IE"); */ var tinymce = { /** * Major version of TinyMCE build. * * @property majorVersion * @type String */ majorVersion : '@@tinymce_major_version@@', /** * Major version of TinyMCE build. * * @property minorVersion * @type String */ minorVersion : '@@tinymce_minor_version@@', /** * Release date of TinyMCE build. * * @property releaseDate * @type String */ releaseDate : '@@tinymce_release_date@@', /** * Initializes the TinyMCE global namespace this will setup browser detection and figure out where TinyMCE is running from. */ _init : function() { var t = this, d = document, na = navigator, ua = na.userAgent, i, nl, n, base, p, v; /** * Constant that is true if the browser is Opera. * * @property isOpera * @type Boolean * @final */ t.isOpera = win.opera && opera.buildNumber; /** * Constant that is true if the browser is WebKit (Safari/Chrome). * * @property isWebKit * @type Boolean * @final */ t.isWebKit = /WebKit/.test(ua); /** * Constant that is true if the browser is IE. * * @property isIE * @type Boolean * @final */ t.isIE = !t.isWebKit && !t.isOpera && (/MSIE/gi).test(ua) && (/Explorer/gi).test(na.appName); /** * Constant that is true if the browser is IE 6 or older. * * @property isIE6 * @type Boolean * @final */ t.isIE6 = t.isIE && /MSIE [56]/.test(ua); /** * Constant that is true if the browser is IE 7. * * @property isIE7 * @type Boolean * @final */ t.isIE7 = t.isIE && /MSIE [7]/.test(ua); /** * Constant that is true if the browser is IE 8. * * @property isIE8 * @type Boolean * @final */ t.isIE8 = t.isIE && /MSIE [8]/.test(ua); /** * Constant that is true if the browser is IE 9. * * @property isIE9 * @type Boolean * @final */ t.isIE9 = t.isIE && /MSIE [9]/.test(ua); /** * Constant that is true if the browser is Gecko. * * @property isGecko * @type Boolean * @final */ t.isGecko = !t.isWebKit && /Gecko/.test(ua); /** * Constant that is true if the os is Mac OS. * * @property isMac * @type Boolean * @final */ t.isMac = ua.indexOf('Mac') != -1; /** * Constant that is true if the runtime is Adobe Air. * * @property isAir * @type Boolean * @final */ t.isAir = /adobeair/i.test(ua); /** * Constant that tells if the current browser is an iPhone or iPad. * * @property isIDevice * @type Boolean * @final */ t.isIDevice = /(iPad|iPhone)/.test(ua); /** * Constant that is true if the current browser is running on iOS 5 or greater. * * @property isIOS5 * @type Boolean * @final */ t.isIOS5 = t.isIDevice && ua.match(/AppleWebKit\/(\d*)/)[1]>=534; // TinyMCE .NET webcontrol might be setting the values for TinyMCE if (win.tinyMCEPreInit) { t.suffix = tinyMCEPreInit.suffix; t.baseURL = tinyMCEPreInit.base; t.query = tinyMCEPreInit.query; return; } // Get suffix and base t.suffix = ''; // If base element found, add that infront of baseURL nl = d.getElementsByTagName('base'); for (i=0; i 3;}); */ grep : function(a, f) { var o = []; tinymce.each(a, function(v) { if (!f || f(v)) o.push(v); }); return o; }, /** * Returns the index of a value in an array, this method will return -1 if the item wasn't found. * * @method inArray * @param {Array} a Array/Object to search for value in. * @param {Object} v Value to check for inside the array. * @return {Number/String} Index of item inside the array inside an object. Or -1 if it wasn't found. * @example * // Get index of value in array this will alert 1 since 2 is at that index * alert(tinymce.inArray([1,2,3], 2)); */ inArray : function(a, v) { var i, l; if (a) { for (i = 0, l = a.length; i < l; i++) { if (a[i] === v) return i; } } return -1; }, /** * Extends an object with the specified other object(s). * * @method extend * @param {Object} o Object to extend with new items. * @param {Object} e..n Object(s) to extend the specified object with. * @return {Object} o New extended object, same reference as the input object. * @example * // Extends obj1 with two new fields * var obj = tinymce.extend(obj1, { * somefield1 : 'a', * somefield2 : 'a' * }); * * // Extends obj with obj2 and obj3 * tinymce.extend(obj, obj2, obj3); */ extend : function(o, e) { var i, l, a = arguments; for (i = 1, l = a.length; i < l; i++) { e = a[i]; tinymce.each(e, function(v, n) { if (v !== undefined) o[n] = v; }); } return o; }, // #endif /** * 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. */ trim : function(s) { return (s ? '' + s : '').replace(whiteSpaceRe, ''); }, /** * 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, inheritage 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 * } * }); */ create : function(s, p, root) { var t = this, sp, ns, cn, scn, c, de = 0; // Parse : : s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s); cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name // Create namespace for new class ns = t.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]; t.extend(ns[cn].prototype, p); // Extend if (s[5]) { sp = t.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 t.each(sp, function(f, n) { ns[cn].prototype[n] = sp[n]; }); // Add overridden methods t.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 t.each(p['static'], function(f, n) { ns[cn][n] = f; }); if (this.onCreate) this.onCreate(s[2], s[3], ns[cn].prototype); }, /** * 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. */ walk : function(o, f, n, s) { s = s || this; if (o) { if (n) o = o[n]; tinymce.each(o, function(o, i) { if (f.call(s, o, i, n) === false) return false; tinymce.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 * } * }; */ createNS : function(n, o) { var i, v; o = o || win; n = n.split('.'); for (i=0; i