4 * Compiled inline version. (Library mode)
7 /*jshint smarttabs:true, undef:true, latedef:true, curly:true, bitwise:true, camelcase:true */
10 (function(exports, undefined) {
15 function require(ids, callback) {
16 var module, defs = [];
18 for (var i = 0; i < ids.length; ++i) {
19 module = modules[ids[i]] || resolve(ids[i]);
21 throw 'module definition dependecy not found: ' + ids[i];
27 callback.apply(null, defs);
30 function define(id, dependencies, definition) {
31 if (typeof id !== 'string') {
32 throw 'invalid module definition, module id must be defined and be a string';
35 if (dependencies === undefined) {
36 throw 'invalid module definition, dependencies must be specified';
39 if (definition === undefined) {
40 throw 'invalid module definition, definition function must be specified';
43 require(dependencies, function() {
44 modules[id] = definition.apply(null, arguments);
48 function defined(id) {
52 function resolve(id) {
54 var fragments = id.split(/[.\/]/);
56 for (var fi = 0; fi < fragments.length; ++fi) {
57 if (!target[fragments[fi]]) {
61 target = target[fragments[fi]];
67 function expose(ids) {
68 for (var i = 0; i < ids.length; i++) {
71 var fragments = id.split(/[.\/]/);
73 for (var fi = 0; fi < fragments.length - 1; ++fi) {
74 if (target[fragments[fi]] === undefined) {
75 target[fragments[fi]] = {};
78 target = target[fragments[fi]];
81 target[fragments[fragments.length - 1]] = modules[id];
85 // Included from: js/tinymce/classes/dom/Sizzle.jQuery.js
90 * Copyright, Moxiecode Systems AB
91 * Released under LGPL License.
93 * License: http://www.tinymce.com/license
94 * Contributing: http://www.tinymce.com/contributing
97 /*global jQuery:true */
100 * Fake Sizzle using jQuery.
102 define("tinymce/dom/Sizzle", [], function() {
103 // Detect if jQuery is loaded
104 if (!window.jQuery) {
105 throw new Error("Load jQuery first");
110 function Sizzle(selector, context, results, seed) {
111 return $.find(selector, context, results, seed);
114 Sizzle.matches = function(expr, elements) {
115 return $(elements).is(expr) ? elements : [];
121 // Included from: js/tinymce/classes/html/Styles.js
126 * Copyright, Moxiecode Systems AB
127 * Released under LGPL License.
129 * License: http://www.tinymce.com/license
130 * Contributing: http://www.tinymce.com/contributing
134 * This class is used to parse CSS styles it also compresses styles to reduce the output size.
137 * var Styles = new tinymce.html.Styles({
138 * url_converter: function(url) {
143 * styles = Styles.parse('border: 1px solid red');
144 * styles.color = 'red';
146 * console.log(new tinymce.html.StyleSerializer().serialize(styles));
148 * @class tinymce.html.Styles
151 define("tinymce/html/Styles", [], function() {
152 return function(settings, schema) {
153 /*jshint maxlen:255 */
154 var rgbRegExp = /rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,
155 urlOrStrRegExp = /(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,
156 styleRegExp = /\s*([^:]+):\s*([^;]+);?/g,
157 trimRightRegExp = /\s+$/,
158 undef, i, encodingLookup = {}, encodingItems, invisibleChar = '\uFEFF';
160 settings = settings || {};
162 encodingItems = ('\\" \\\' \\; \\: ; : ' + invisibleChar).split(' ');
163 for (i = 0; i < encodingItems.length; i++) {
164 encodingLookup[encodingItems[i]] = invisibleChar + i;
165 encodingLookup[invisibleChar + i] = encodingItems[i];
168 function toHex(match, r, g, b) {
170 val = parseInt(val, 10).toString(16);
172 return val.length > 1 ? val : '0' + val; // 0 -> 00
175 return '#' + hex(r) + hex(g) + hex(b);
180 * Parses the specified RGB color value and returns a hex version of that color.
183 * @param {String} color RGB string value like rgb(1,2,3)
184 * @return {String} Hex version of that RGB value like #FF00FF.
186 toHex: function(color) {
187 return color.replace(rgbRegExp, toHex);
191 * Parses the specified style value into an object collection. This parser will also
192 * merge and remove any redundant items that browsers might have added. It will also convert non hex
193 * colors to hex values. Urls inside the styles will also be converted to absolute/relative based on settings.
196 * @param {String} css Style value to parse for example: border:1px solid red;.
197 * @return {Object} Object representation of that style like {border: '1px solid red'}
199 parse: function(css) {
200 var styles = {}, matches, name, value, isEncoded, urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope || this;
202 function compress(prefix, suffix) {
203 var top, right, bottom, left;
205 // Get values and check it it needs compressing
206 top = styles[prefix + '-top' + suffix];
211 right = styles[prefix + '-right' + suffix];
216 bottom = styles[prefix + '-bottom' + suffix];
217 if (right != bottom) {
221 left = styles[prefix + '-left' + suffix];
222 if (bottom != left) {
227 styles[prefix + suffix] = left;
228 delete styles[prefix + '-top' + suffix];
229 delete styles[prefix + '-right' + suffix];
230 delete styles[prefix + '-bottom' + suffix];
231 delete styles[prefix + '-left' + suffix];
235 * Checks if the specific style can be compressed in other words if all border-width are equal.
237 function canCompress(key) {
238 var value = styles[key], i;
240 if (!value || value.indexOf(' ') < 0) {
244 value = value.split(' ');
247 if (value[i] !== value[0]) {
252 styles[key] = value[0];
258 * Compresses multiple styles into one style.
260 function compress2(target, a, b, c) {
261 if (!canCompress(a)) {
265 if (!canCompress(b)) {
269 if (!canCompress(c)) {
274 styles[target] = styles[a] + ' ' + styles[b] + ' ' + styles[c];
280 // Encodes the specified string by replacing all \" \' ; : with _<num>
281 function encode(str) {
284 return encodingLookup[str];
287 // Decodes the specified string by replacing all _<num> with it's original value \" \' etc
288 // It will also decode the \" \' if keep_slashes is set to fale or omitted
289 function decode(str, keep_slashes) {
291 str = str.replace(/\uFEFF[0-9]/g, function(str) {
292 return encodingLookup[str];
297 str = str.replace(/\\([\'\";:])/g, "$1");
303 function processUrl(match, url, url2, url3, str, str2) {
309 // Force strings into single quote format
310 return "'" + str.replace(/\'/g, "\\'") + "'";
313 url = decode(url || url2 || url3);
315 // Convert the URL to relative/absolute depending on config
317 url = urlConverter.call(urlConverterScope, url, 'style');
320 // Output new URL format
321 return "url('" + url.replace(/\'/g, "\\'") + "')";
325 // Encode \" \' % and ; and : inside strings so they don't interfere with the style parsing
326 css = css.replace(/\\[\"\';:\uFEFF]/g, encode).replace(/\"[^\"]+\"|\'[^\']+\'/g, function(str) {
327 return str.replace(/[;:]/g, encode);
331 while ((matches = styleRegExp.exec(css))) {
332 name = matches[1].replace(trimRightRegExp, '').toLowerCase();
333 value = matches[2].replace(trimRightRegExp, '');
335 if (name && value.length > 0) {
336 // Opera will produce 700 instead of bold in their style values
337 if (name === 'font-weight' && value === '700') {
339 } else if (name === 'color' || name === 'background-color') { // Lowercase colors like RED
340 value = value.toLowerCase();
343 // Convert RGB colors to HEX
344 value = value.replace(rgbRegExp, toHex);
346 // Convert URLs and force them into url('value') format
347 value = value.replace(urlOrStrRegExp, processUrl);
348 styles[name] = isEncoded ? decode(value, true) : value;
351 styleRegExp.lastIndex = matches.index + matches[0].length;
354 // Compress the styles to reduce it's size for example IE will expand styles
355 compress("border", "");
356 compress("border", "-width");
357 compress("border", "-color");
358 compress("border", "-style");
359 compress("padding", "");
360 compress("margin", "");
361 compress2('border', 'border-width', 'border-style', 'border-color');
363 // Remove pointless border, IE produces these
364 if (styles.border === 'medium none') {
365 delete styles.border;
373 * Serializes the specified style object into a string.
376 * @param {Object} styles Object to serialize as string for example: {border: '1px solid red'}
377 * @param {String} element_name Optional element name, if specified only the styles that matches the schema will be serialized.
378 * @return {String} String representation of the style object for example: border: 1px solid red.
380 serialize: function(styles, element_name) {
381 var css = '', name, value;
383 function serializeStyles(name) {
384 var styleList, i, l, value;
386 styleList = schema.styles[name];
388 for (i = 0, l = styleList.length; i < l; i++) {
390 value = styles[name];
392 if (value !== undef && value.length > 0) {
393 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
399 // Serialize styles according to schema
400 if (element_name && schema && schema.styles) {
401 // Serialize global styles and element specific styles
402 serializeStyles('*');
403 serializeStyles(element_name);
405 // Output the styles in the order they are inside the object
406 for (name in styles) {
407 value = styles[name];
409 if (value !== undef && value.length > 0) {
410 css += (css.length > 0 ? ' ' : '') + name + ': ' + value + ';';
421 // Included from: js/tinymce/classes/dom/EventUtils.js
426 * Copyright, Moxiecode Systems AB
427 * Released under LGPL License.
429 * License: http://www.tinymce.com/license
430 * Contributing: http://www.tinymce.com/contributing
433 /*jshint loopfunc:true*/
435 define("tinymce/dom/EventUtils", [], function() {
438 var eventExpandoPrefix = "mce-data-";
439 var mouseEventRe = /^(?:mouse|contextmenu)|click/;
440 var deprecated = {keyLocation: 1, layerX: 1, layerY: 1};
443 * Binds a native event to a callback on the speified target.
445 function addEvent(target, name, callback, capture) {
446 if (target.addEventListener) {
447 target.addEventListener(name, callback, capture || false);
448 } else if (target.attachEvent) {
449 target.attachEvent('on' + name, callback);
454 * Unbinds a native event callback on the specified target.
456 function removeEvent(target, name, callback, capture) {
457 if (target.removeEventListener) {
458 target.removeEventListener(name, callback, capture || false);
459 } else if (target.detachEvent) {
460 target.detachEvent('on' + name, callback);
465 * Normalizes a native event object or just adds the event specific methods on a custom event.
467 function fix(originalEvent, data) {
468 var name, event = data || {}, undef;
470 // Dummy function that gets replaced on the delegation state functions
471 function returnFalse() {
475 // Dummy function that gets replaced on the delegation state functions
476 function returnTrue() {
480 // Copy all properties from the original event
481 for (name in originalEvent) {
482 // layerX/layerY is deprecated in Chrome and produces a warning
483 if (!deprecated[name]) {
484 event[name] = originalEvent[name];
488 // Normalize target IE uses srcElement
490 event.target = event.srcElement || document;
493 // Calculate pageX/Y if missing and clientX/Y available
494 if (originalEvent && mouseEventRe.test(originalEvent.type) && originalEvent.pageX === undef && originalEvent.clientX !== undef) {
495 var eventDoc = event.target.ownerDocument || document;
496 var doc = eventDoc.documentElement;
497 var body = eventDoc.body;
499 event.pageX = originalEvent.clientX + (doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
500 ( doc && doc.clientLeft || body && body.clientLeft || 0);
502 event.pageY = originalEvent.clientY + (doc && doc.scrollTop || body && body.scrollTop || 0 ) -
503 ( doc && doc.clientTop || body && body.clientTop || 0);
506 // Add preventDefault method
507 event.preventDefault = function() {
508 event.isDefaultPrevented = returnTrue;
510 // Execute preventDefault on the original event object
512 if (originalEvent.preventDefault) {
513 originalEvent.preventDefault();
515 originalEvent.returnValue = false; // IE
520 // Add stopPropagation
521 event.stopPropagation = function() {
522 event.isPropagationStopped = returnTrue;
524 // Execute stopPropagation on the original event object
526 if (originalEvent.stopPropagation) {
527 originalEvent.stopPropagation();
529 originalEvent.cancelBubble = true; // IE
534 // Add stopImmediatePropagation
535 event.stopImmediatePropagation = function() {
536 event.isImmediatePropagationStopped = returnTrue;
537 event.stopPropagation();
540 // Add event delegation states
541 if (!event.isDefaultPrevented) {
542 event.isDefaultPrevented = returnFalse;
543 event.isPropagationStopped = returnFalse;
544 event.isImmediatePropagationStopped = returnFalse;
551 * Bind a DOMContentLoaded event across browsers and executes the callback once the page DOM is initialized.
552 * It will also set/check the domLoaded state of the event_utils instance so ready isn't called multiple times.
554 function bindOnReady(win, callback, eventUtils) {
555 var doc = win.document, event = {type: 'ready'};
557 if (eventUtils.domLoaded) {
562 // Gets called when the DOM is ready
563 function readyHandler() {
564 if (!eventUtils.domLoaded) {
565 eventUtils.domLoaded = true;
570 function waitForDomLoaded() {
571 if (doc.readyState === "complete") {
572 removeEvent(doc, "readystatechange", waitForDomLoaded);
577 function tryScroll() {
579 // If IE is used, use the trick by Diego Perini licensed under MIT by request to the author.
580 // http://javascript.nwbox.com/IEContentLoaded/
581 doc.documentElement.doScroll("left");
583 setTimeout(tryScroll, 0);
591 if (doc.addEventListener) {
592 addEvent(win, 'DOMContentLoaded', readyHandler);
595 addEvent(doc, "readystatechange", waitForDomLoaded);
597 // Wait until we can scroll, when we can the DOM is initialized
598 if (doc.documentElement.doScroll && win === win.top) {
603 // Fallback if any of the above methods should fail for some odd reason
604 addEvent(win, 'load', readyHandler);
608 * This class enables you to bind/unbind native events to elements and normalize it's behavior across browsers.
610 function EventUtils() {
611 var self = this, events = {}, count, expando, hasFocusIn, hasMouseEnterLeave, mouseEnterLeave;
613 expando = eventExpandoPrefix + (+new Date()).toString(32);
614 hasMouseEnterLeave = "onmouseenter" in document.documentElement;
615 hasFocusIn = "onfocusin" in document.documentElement;
616 mouseEnterLeave = {mouseenter: 'mouseover', mouseleave: 'mouseout'};
619 // State if the DOMContentLoaded was executed or not
620 self.domLoaded = false;
621 self.events = events;
624 * Executes all event handler callbacks for a specific event.
627 * @param {Event} evt Event object.
628 * @param {String} id Expando id value to look for.
630 function executeHandlers(evt, id) {
631 var callbackList, i, l, callback;
633 callbackList = events[id][evt.type];
635 for (i = 0, l = callbackList.length; i < l; i++) {
636 callback = callbackList[i];
638 // Check if callback exists might be removed if a unbind is called inside the callback
639 if (callback && callback.func.call(callback.scope, evt) === false) {
640 evt.preventDefault();
643 // Should we stop propagation to immediate listeners
644 if (evt.isImmediatePropagationStopped()) {
652 * Binds a callback to an event on the specified target.
655 * @param {Object} target Target node/window or custom object.
656 * @param {String} names Name of the event to bind.
657 * @param {function} callback Callback function to execute when the event occurs.
658 * @param {Object} scope Scope to call the callback function on, defaults to target.
659 * @return {function} Callback function that got bound.
661 self.bind = function(target, names, callback, scope) {
662 var id, callbackList, i, name, fakeName, nativeHandler, capture, win = window;
664 // Native event handler function patches the event and executes the callbacks for the expando
665 function defaultNativeHandler(evt) {
666 executeHandlers(fix(evt || win.event), id);
669 // Don't bind to text nodes or comments
670 if (!target || target.nodeType === 3 || target.nodeType === 8) {
674 // Create or get events id for the target
675 if (!target[expando]) {
677 target[expando] = id;
680 id = target[expando];
683 // Setup the specified scope or use the target as a default
684 scope = scope || target;
686 // Split names and bind each event, enables you to bind multiple events with one call
687 names = names.split(' ');
691 nativeHandler = defaultNativeHandler;
692 fakeName = capture = false;
694 // Use ready instead of DOMContentLoaded
695 if (name === "DOMContentLoaded") {
699 // DOM is already ready
700 if (self.domLoaded && name === "ready" && target.readyState == 'complete') {
701 callback.call(scope, fix({type: name}));
705 // Handle mouseenter/mouseleaver
706 if (!hasMouseEnterLeave) {
707 fakeName = mouseEnterLeave[name];
710 nativeHandler = function(evt) {
711 var current, related;
713 current = evt.currentTarget;
714 related = evt.relatedTarget;
716 // Check if related is inside the current target if it's not then the event should
717 // be ignored since it's a mouseover/mouseout inside the element
718 if (related && current.contains) {
719 // Use contains for performance
720 related = current.contains(related);
722 while (related && related !== current) {
723 related = related.parentNode;
729 evt = fix(evt || win.event);
730 evt.type = evt.type === 'mouseout' ? 'mouseleave' : 'mouseenter';
731 evt.target = current;
732 executeHandlers(evt, id);
738 // Fake bubbeling of focusin/focusout
739 if (!hasFocusIn && (name === "focusin" || name === "focusout")) {
741 fakeName = name === "focusin" ? "focus" : "blur";
742 nativeHandler = function(evt) {
743 evt = fix(evt || win.event);
744 evt.type = evt.type === 'focus' ? 'focusin' : 'focusout';
745 executeHandlers(evt, id);
749 // Setup callback list and bind native event
750 callbackList = events[id][name];
752 events[id][name] = callbackList = [{func: callback, scope: scope}];
753 callbackList.fakeName = fakeName;
754 callbackList.capture = capture;
756 // Add the nativeHandler to the callback list so that we can later unbind it
757 callbackList.nativeHandler = nativeHandler;
759 // Check if the target has native events support
761 if (name === "ready") {
762 bindOnReady(target, nativeHandler, self);
764 addEvent(target, fakeName || name, nativeHandler, capture);
767 if (name === "ready" && self.domLoaded) {
768 callback({type: name});
770 // If it already has an native handler then just push the callback
771 callbackList.push({func: callback, scope: scope});
776 target = callbackList = 0; // Clean memory for IE
782 * Unbinds the specified event by name, name and callback or all events on the target.
785 * @param {Object} target Target node/window or custom object.
786 * @param {String} names Optional event name to unbind.
787 * @param {function} callback Optional callback function to unbind.
788 * @return {EventUtils} Event utils instance.
790 self.unbind = function(target, names, callback) {
791 var id, callbackList, i, ci, name, eventMap;
793 // Don't bind to text nodes or comments
794 if (!target || target.nodeType === 3 || target.nodeType === 8) {
798 // Unbind event or events if the target has the expando
799 id = target[expando];
801 eventMap = events[id];
805 names = names.split(' ');
809 callbackList = eventMap[name];
811 // Unbind the event if it exists in the map
813 // Remove specified callback
815 ci = callbackList.length;
817 if (callbackList[ci].func === callback) {
818 callbackList.splice(ci, 1);
823 // Remove all callbacks if there isn't a specified callback or there is no callbacks left
824 if (!callback || callbackList.length === 0) {
825 delete eventMap[name];
826 removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
831 // All events for a specific element
832 for (name in eventMap) {
833 callbackList = eventMap[name];
834 removeEvent(target, callbackList.fakeName || name, callbackList.nativeHandler, callbackList.capture);
840 // Check if object is empty, if it isn't then we won't remove the expando map
841 for (name in eventMap) {
845 // Delete event object
848 // Remove expando from target
850 // IE will fail here since it can't delete properties from window
851 delete target[expando];
853 // IE will set it to null
854 target[expando] = null;
862 * Fires the specified event on the specified target.
865 * @param {Object} target Target node/window or custom object.
866 * @param {String} name Event name to fire.
867 * @param {Object} args Optional arguments to send to the observers.
868 * @return {EventUtils} Event utils instance.
870 self.fire = function(target, name, args) {
873 // Don't bind to text nodes or comments
874 if (!target || target.nodeType === 3 || target.nodeType === 8) {
878 // Build event object by patching the args
879 args = fix(null, args);
881 args.target = target;
884 // Found an expando that means there is listeners to execute
885 id = target[expando];
887 executeHandlers(args, id);
891 target = target.parentNode || target.ownerDocument || target.defaultView || target.parentWindow;
892 } while (target && !args.isPropagationStopped());
898 * Removes all bound event listeners for the specified target. This will also remove any bound
899 * listeners to child nodes within that target.
902 * @param {Object} target Target node/window object.
903 * @return {EventUtils} Event utils instance.
905 self.clean = function(target) {
906 var i, children, unbind = self.unbind;
908 // Don't bind to text nodes or comments
909 if (!target || target.nodeType === 3 || target.nodeType === 8) {
913 // Unbind any element on the specificed target
914 if (target[expando]) {
918 // Target doesn't have getElementsByTagName it's probably a window object then use it's document to find the children
919 if (!target.getElementsByTagName) {
920 target = target.document;
923 // Remove events from each child element
924 if (target && target.getElementsByTagName) {
927 children = target.getElementsByTagName('*');
930 target = children[i];
932 if (target[expando]) {
942 * Destroys the event object. Call this on IE to remove memory leaks.
944 self.destroy = function() {
948 // Legacy function for canceling events
949 self.cancel = function(e) {
952 e.stopImmediatePropagation();
959 EventUtils.Event = new EventUtils();
960 EventUtils.Event.bind(window, 'ready', function() {});
965 // Included from: js/tinymce/classes/dom/TreeWalker.js
970 * Copyright, Moxiecode Systems AB
971 * Released under LGPL License.
973 * License: http://www.tinymce.com/license
974 * Contributing: http://www.tinymce.com/contributing
978 * TreeWalker class enables you to walk the DOM in a linear manner.
980 * @class tinymce.dom.TreeWalker
982 define("tinymce/dom/TreeWalker", [], function() {
983 return function(start_node, root_node) {
984 var node = start_node;
986 function findSibling(node, start_name, sibling_name, shallow) {
990 // Walk into nodes if it has a start
991 if (!shallow && node[start_name]) {
992 return node[start_name];
995 // Return the sibling if it has one
996 if (node != root_node) {
997 sibling = node[sibling_name];
1002 // Walk up the parents to look for siblings
1003 for (parent = node.parentNode; parent && parent != root_node; parent = parent.parentNode) {
1004 sibling = parent[sibling_name];
1014 * Returns the current node.
1017 * @return {Node} Current node where the walker is.
1019 this.current = function() {
1024 * Walks to the next node in tree.
1027 * @return {Node} Current node where the walker is after moving to the next node.
1029 this.next = function(shallow) {
1030 node = findSibling(node, 'firstChild', 'nextSibling', shallow);
1035 * Walks to the previous node in tree.
1038 * @return {Node} Current node where the walker is after moving to the previous node.
1040 this.prev = function(shallow) {
1041 node = findSibling(node, 'lastChild', 'previousSibling', shallow);
1047 // Included from: js/tinymce/classes/util/Tools.js
1052 * Copyright, Moxiecode Systems AB
1053 * Released under LGPL License.
1055 * License: http://www.tinymce.com/license
1056 * Contributing: http://www.tinymce.com/contributing
1060 * This class contains various utlity functions. These are also exposed
1061 * directly on the tinymce namespace.
1063 * @class tinymce.util.Tools
1065 define("tinymce/util/Tools", [], function() {
1067 * Removes whitespace from the beginning and end of a string.
1070 * @param {String} s String to remove whitespace from.
1071 * @return {String} New string with removed whitespace.
1073 var whiteSpaceRegExp = /^\s*|\s*$/g;
1074 var trim = function(str) {
1075 return (str === null || str === undefined) ? '' : ("" + str).replace(whiteSpaceRegExp, '');
1079 * Returns true/false if the object is an array or not.
1082 * @param {Object} obj Object to check.
1083 * @return {boolean} true/false state if the object is an array or not.
1085 var isArray = Array.isArray || function(obj) {
1086 return Object.prototype.toString.call(obj) === "[object Array]";
1090 * Checks if a object is of a specific type for example an array.
1093 * @param {Object} o Object to check type of.
1094 * @param {string} t Optional type to check for.
1095 * @return {Boolean} true/false if the object is of the specified type.
1099 return o !== undefined;
1102 if (t == 'array' && isArray(o)) {
1106 return typeof(o) == t;
1110 * Converts the specified object into a real JavaScript array.
1113 * @param {Object} obj Object to convert into array.
1114 * @return {Array} Array object based in input.
1116 function toArray(obj) {
1117 var array = [], i, l;
1119 for (i = 0, l = obj.length; i < l; i++) {
1127 * Makes a name/object map out of an array with names.
1130 * @param {Array/String} items Items to make map out of.
1131 * @param {String} delim Optional delimiter to split string by.
1132 * @param {Object} map Optional map to add items to.
1133 * @return {Object} Name/value map of items.
1135 function makeMap(items, delim, map) {
1138 items = items || [];
1139 delim = delim || ',';
1141 if (typeof(items) == "string") {
1142 items = items.split(delim);
1156 * Performs an iteration of all items in a collection such as an object or array. This method will execure the
1157 * callback function for each item in the collection, if the callback returns false the iteration will terminate.
1158 * The callback has the following format: cb(value, key_or_index).
1161 * @param {Object} o Collection to iterate.
1162 * @param {function} cb Callback function to execute for each item.
1163 * @param {Object} s Optional scope to execute the callback in.
1165 * // Iterate an array
1166 * tinymce.each([1,2,3], function(v, i) {
1167 * console.debug("Value: " + v + ", Index: " + i);
1170 * // Iterate an object
1171 * tinymce.each({a: 1, b: 2, c: 3], function(v, k) {
1172 * console.debug("Value: " + v + ", Key: " + k);
1175 function each(o, cb, s) {
1184 if (o.length !== undefined) {
1185 // Indexed arrays, needed for Safari
1186 for (n=0, l = o.length; n < l; n++) {
1187 if (cb.call(s, o[n], n, o) === false) {
1194 if (o.hasOwnProperty(n)) {
1195 if (cb.call(s, o[n], n, o) === false) {
1206 * Creates a new array by the return value of each iteration function call. This enables you to convert
1207 * one array list into another.
1210 * @param {Array} a Array of items to iterate.
1211 * @param {function} f Function to call for each item. It's return value will be the new value.
1212 * @return {Array} Array with new values based on function return values.
1214 function map(a, f) {
1217 each(a, function(v) {
1225 * Filters out items from the input array by calling the specified function for each item.
1226 * If the function returns false the item will be excluded if it returns true it will be included.
1229 * @param {Array} a Array of items to loop though.
1230 * @param {function} f Function to call for each item. Include/exclude depends on it's return value.
1231 * @return {Array} New array with values imported and filtered based in input.
1233 * // Filter out some items, this will return an array with 4 and 5
1234 * var items = tinymce.grep([1,2,3,4,5], function(v) {return v > 3;});
1236 function grep(a, f) {
1239 each(a, function(v) {
1249 * Creates a class, subclass or static singleton.
1250 * More details on this method can be found in the Wiki.
1253 * @param {String} s Class name, inheritage and prefix.
1254 * @param {Object} p Collection of methods to add to the class.
1255 * @param {Object} root Optional root object defaults to the global window object.
1257 * // Creates a basic class
1258 * tinymce.create('tinymce.somepackage.SomeClass', {
1259 * SomeClass: function() {
1260 * // Class constructor
1263 * method: function() {
1268 * // Creates a basic subclass class
1269 * tinymce.create('tinymce.somepackage.SomeSubClass:tinymce.somepackage.SomeClass', {
1270 * SomeSubClass: function() {
1271 * // Class constructor
1272 * this.parent(); // Call parent constructor
1275 * method: function() {
1277 * this.parent(); // Call parent method
1281 * staticMethod: function() {
1287 * // Creates a singleton/static class
1288 * tinymce.create('static tinymce.somepackage.SomeSingletonClass', {
1289 * method: function() {
1294 function create(s, p, root) {
1295 var t = this, sp, ns, cn, scn, c, de = 0;
1297 // Parse : <prefix> <class>:<super class>
1298 s = /^((static) )?([\w.]+)(:([\w.]+))?/.exec(s);
1299 cn = s[3].match(/(^|\.)(\w+)$/i)[2]; // Class name
1301 // Create namespace for new class
1302 ns = t.createNS(s[3].replace(/\.\w+$/, ''), root);
1304 // Class already exists
1309 // Make pure static class
1310 if (s[2] == 'static') {
1313 if (this.onCreate) {
1314 this.onCreate(s[2], s[3], ns[cn]);
1320 // Create default constructor
1322 p[cn] = function() {};
1326 // Add constructor and methods
1328 t.extend(ns[cn].prototype, p);
1332 sp = t.resolve(s[5]).prototype;
1333 scn = s[5].match(/\.(\w+)$/i)[1]; // Class name
1335 // Extend constructor
1338 // Add passthrough constructor
1339 ns[cn] = function() {
1340 return sp[scn].apply(this, arguments);
1343 // Add inherit constructor
1344 ns[cn] = function() {
1345 this.parent = sp[scn];
1346 return c.apply(this, arguments);
1349 ns[cn].prototype[cn] = ns[cn];
1351 // Add super methods
1352 t.each(sp, function(f, n) {
1353 ns[cn].prototype[n] = sp[n];
1356 // Add overridden methods
1357 t.each(p, function(f, n) {
1358 // Extend methods if needed
1360 ns[cn].prototype[n] = function() {
1361 this.parent = sp[n];
1362 return f.apply(this, arguments);
1366 ns[cn].prototype[n] = f;
1372 // Add static methods
1374 t.each(p['static'], function(f, n) {
1380 * Returns the index of a value in an array, this method will return -1 if the item wasn't found.
1383 * @param {Array} a Array/Object to search for value in.
1384 * @param {Object} v Value to check for inside the array.
1385 * @return {Number/String} Index of item inside the array inside an object. Or -1 if it wasn't found.
1387 * // Get index of value in array this will alert 1 since 2 is at that index
1388 * alert(tinymce.inArray([1,2,3], 2));
1390 function inArray(a, v) {
1394 for (i = 0, l = a.length; i < l; i++) {
1404 function extend(obj, ext) {
1405 var i, l, name, args = arguments, value;
1407 for (i = 1, l = args.length; i < l; i++) {
1410 if (ext.hasOwnProperty(name)) {
1413 if (value !== undefined) {
1424 * Executed the specified function for each item in a object tree.
1427 * @param {Object} o Object tree to walk though.
1428 * @param {function} f Function to call for each item.
1429 * @param {String} n Optional name of collection inside the objects to walk for example childNodes.
1430 * @param {String} s Optional scope to execute the function in.
1432 function walk(o, f, n, s) {
1440 each(o, function(o, i) {
1441 if (f.call(s, o, i, n) === false) {
1451 * Creates a namespace on a specific object.
1454 * @param {String} n Namespace to create for example a.b.c.d.
1455 * @param {Object} o Optional object to add namespace to, defaults to window.
1456 * @return {Object} New namespace object the last item in path.
1458 * // Create some namespace
1459 * tinymce.createNS('tinymce.somepackage.subpackage');
1461 * // Add a singleton
1462 * var tinymce.somepackage.subpackage.SomeSingleton = {
1463 * method: function() {
1468 function createNS(n, o) {
1474 for (i=0; i<n.length; i++) {
1488 * Resolves a string and returns the object from a specific structure.
1491 * @param {String} n Path to resolve for example a.b.c.d.
1492 * @param {Object} o Optional object to search though, defaults to window.
1493 * @return {Object} Last object in path or null if it couldn't be resolved.
1495 * // Resolve a path into an object reference
1496 * var obj = tinymce.resolve('a.b.c.d');
1498 function resolve(n, o) {
1504 for (i = 0, l = n.length; i < l; i++) {
1516 * Splits a string but removes the whitespace before and after each value.
1519 * @param {string} s String to split.
1520 * @param {string} d Delimiter to split by.
1522 * // Split a string into an array with a,b,c
1523 * var arr = tinymce.explode('a, b, c');
1525 function explode(s, d) {
1526 if (!s || is(s, 'array')) {
1530 return map(s.split(d || ','), trim);
1552 // Included from: js/tinymce/classes/dom/Range.js
1557 * Copyright, Moxiecode Systems AB
1558 * Released under LGPL License.
1560 * License: http://www.tinymce.com/license
1561 * Contributing: http://www.tinymce.com/contributing
1564 define("tinymce/dom/Range", [
1565 "tinymce/util/Tools"
1566 ], function(Tools) {
1567 // Range constructor
1568 function Range(dom) {
1576 START_OFFSET = 'startOffset',
1577 START_CONTAINER = 'startContainer',
1578 END_CONTAINER = 'endContainer',
1579 END_OFFSET = 'endOffset',
1580 extend = Tools.extend,
1581 nodeIndex = dom.nodeIndex;
1583 function createDocumentFragment() {
1584 return doc.createDocumentFragment();
1587 function setStart(n, o) {
1588 _setEndPoint(TRUE, n, o);
1591 function setEnd(n, o) {
1592 _setEndPoint(FALSE, n, o);
1595 function setStartBefore(n) {
1596 setStart(n.parentNode, nodeIndex(n));
1599 function setStartAfter(n) {
1600 setStart(n.parentNode, nodeIndex(n) + 1);
1603 function setEndBefore(n) {
1604 setEnd(n.parentNode, nodeIndex(n));
1607 function setEndAfter(n) {
1608 setEnd(n.parentNode, nodeIndex(n) + 1);
1611 function collapse(ts) {
1613 t[END_CONTAINER] = t[START_CONTAINER];
1614 t[END_OFFSET] = t[START_OFFSET];
1616 t[START_CONTAINER] = t[END_CONTAINER];
1617 t[START_OFFSET] = t[END_OFFSET];
1623 function selectNode(n) {
1628 function selectNodeContents(n) {
1630 setEnd(n, n.nodeType === 1 ? n.childNodes.length : n.nodeValue.length);
1633 function compareBoundaryPoints(h, r) {
1634 var sc = t[START_CONTAINER], so = t[START_OFFSET], ec = t[END_CONTAINER], eo = t[END_OFFSET],
1635 rsc = r.startContainer, rso = r.startOffset, rec = r.endContainer, reo = r.endOffset;
1637 // Check START_TO_START
1639 return _compareBoundaryPoints(sc, so, rsc, rso);
1642 // Check START_TO_END
1644 return _compareBoundaryPoints(ec, eo, rsc, rso);
1649 return _compareBoundaryPoints(ec, eo, rec, reo);
1652 // Check END_TO_START
1654 return _compareBoundaryPoints(sc, so, rec, reo);
1658 function deleteContents() {
1662 function extractContents() {
1663 return _traverse(EXTRACT);
1666 function cloneContents() {
1667 return _traverse(CLONE);
1670 function insertNode(n) {
1671 var startContainer = this[START_CONTAINER],
1672 startOffset = this[START_OFFSET], nn, o;
1674 // Node is TEXT_NODE or CDATA
1675 if ((startContainer.nodeType === 3 || startContainer.nodeType === 4) && startContainer.nodeValue) {
1677 // At the start of text
1678 startContainer.parentNode.insertBefore(n, startContainer);
1679 } else if (startOffset >= startContainer.nodeValue.length) {
1680 // At the end of text
1681 dom.insertAfter(n, startContainer);
1683 // Middle, need to split
1684 nn = startContainer.splitText(startOffset);
1685 startContainer.parentNode.insertBefore(n, nn);
1688 // Insert element node
1689 if (startContainer.childNodes.length > 0) {
1690 o = startContainer.childNodes[startOffset];
1694 startContainer.insertBefore(n, o);
1696 startContainer.appendChild(n);
1701 function surroundContents(n) {
1702 var f = t.extractContents();
1709 function cloneRange() {
1710 return extend(new Range(dom), {
1711 startContainer: t[START_CONTAINER],
1712 startOffset: t[START_OFFSET],
1713 endContainer: t[END_CONTAINER],
1714 endOffset: t[END_OFFSET],
1715 collapsed: t.collapsed,
1716 commonAncestorContainer: t.commonAncestorContainer
1722 function _getSelectedNode(container, offset) {
1725 if (container.nodeType == 3 /* TEXT_NODE */) {
1733 child = container.firstChild;
1734 while (child && offset > 0) {
1736 child = child.nextSibling;
1746 function _isCollapsed() {
1747 return (t[START_CONTAINER] == t[END_CONTAINER] && t[START_OFFSET] == t[END_OFFSET]);
1750 function _compareBoundaryPoints(containerA, offsetA, containerB, offsetB) {
1751 var c, offsetC, n, cmnRoot, childA, childB;
1753 // In the first case the boundary-points have the same container. A is before B
1754 // if its offset is less than the offset of B, A is equal to B if its offset is
1755 // equal to the offset of B, and A is after B if its offset is greater than the
1757 if (containerA == containerB) {
1758 if (offsetA == offsetB) {
1762 if (offsetA < offsetB) {
1763 return -1; // before
1769 // In the second case a child node C of the container of A is an ancestor
1770 // container of B. In this case, A is before B if the offset of A is less than or
1771 // equal to the index of the child node C and A is after B otherwise.
1773 while (c && c.parentNode != containerA) {
1779 n = containerA.firstChild;
1781 while (n != c && offsetC < offsetA) {
1786 if (offsetA <= offsetC) {
1787 return -1; // before
1793 // In the third case a child node C of the container of B is an ancestor container
1794 // of A. In this case, A is before B if the index of the child node C is less than
1795 // the offset of B and A is after B otherwise.
1797 while (c && c.parentNode != containerB) {
1803 n = containerB.firstChild;
1805 while (n != c && offsetC < offsetB) {
1810 if (offsetC < offsetB) {
1811 return -1; // before
1817 // In the fourth case, none of three other cases hold: the containers of A and B
1818 // are siblings or descendants of sibling nodes. In this case, A is before B if
1819 // the container of A is before the container of B in a pre-order traversal of the
1820 // Ranges' context tree and A is after B otherwise.
1821 cmnRoot = dom.findCommonAncestor(containerA, containerB);
1822 childA = containerA;
1824 while (childA && childA.parentNode != cmnRoot) {
1825 childA = childA.parentNode;
1832 childB = containerB;
1833 while (childB && childB.parentNode != cmnRoot) {
1834 childB = childB.parentNode;
1841 if (childA == childB) {
1845 n = cmnRoot.firstChild;
1848 return -1; // before
1859 function _setEndPoint(st, n, o) {
1863 t[START_CONTAINER] = n;
1864 t[START_OFFSET] = o;
1866 t[END_CONTAINER] = n;
1870 // If one boundary-point of a Range is set to have a root container
1871 // other than the current one for the Range, the Range is collapsed to
1872 // the new position. This enforces the restriction that both boundary-
1873 // points of a Range must have the same root container.
1874 ec = t[END_CONTAINER];
1875 while (ec.parentNode) {
1879 sc = t[START_CONTAINER];
1880 while (sc.parentNode) {
1885 // The start position of a Range is guaranteed to never be after the
1886 // end position. To enforce this restriction, if the start is set to
1887 // be at a position after the end, the Range is collapsed to that
1889 if (_compareBoundaryPoints(t[START_CONTAINER], t[START_OFFSET], t[END_CONTAINER], t[END_OFFSET]) > 0) {
1896 t.collapsed = _isCollapsed();
1897 t.commonAncestorContainer = dom.findCommonAncestor(t[START_CONTAINER], t[END_CONTAINER]);
1900 function _traverse(how) {
1901 var c, endContainerDepth = 0, startContainerDepth = 0, p, depthDiff, startNode, endNode, sp, ep;
1903 if (t[START_CONTAINER] == t[END_CONTAINER]) {
1904 return _traverseSameContainer(how);
1907 for (c = t[END_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
1908 if (p == t[START_CONTAINER]) {
1909 return _traverseCommonStartContainer(c, how);
1912 ++endContainerDepth;
1915 for (c = t[START_CONTAINER], p = c.parentNode; p; c = p, p = p.parentNode) {
1916 if (p == t[END_CONTAINER]) {
1917 return _traverseCommonEndContainer(c, how);
1920 ++startContainerDepth;
1923 depthDiff = startContainerDepth - endContainerDepth;
1925 startNode = t[START_CONTAINER];
1926 while (depthDiff > 0) {
1927 startNode = startNode.parentNode;
1931 endNode = t[END_CONTAINER];
1932 while (depthDiff < 0) {
1933 endNode = endNode.parentNode;
1937 // ascend the ancestor hierarchy until we have a common parent.
1938 for (sp = startNode.parentNode, ep = endNode.parentNode; sp != ep; sp = sp.parentNode, ep = ep.parentNode) {
1943 return _traverseCommonAncestors(startNode, endNode, how);
1946 function _traverseSameContainer(how) {
1947 var frag, s, sub, n, cnt, sibling, xferNode, start, len;
1949 if (how != DELETE) {
1950 frag = createDocumentFragment();
1953 // If selection is empty, just return the fragment
1954 if (t[START_OFFSET] == t[END_OFFSET]) {
1958 // Text node needs special case handling
1959 if (t[START_CONTAINER].nodeType == 3 /* TEXT_NODE */) {
1960 // get the substring
1961 s = t[START_CONTAINER].nodeValue;
1962 sub = s.substring(t[START_OFFSET], t[END_OFFSET]);
1964 // set the original text node to its new value
1966 n = t[START_CONTAINER];
1967 start = t[START_OFFSET];
1968 len = t[END_OFFSET] - t[START_OFFSET];
1970 if (start === 0 && len >= n.nodeValue.length - 1) {
1971 n.parentNode.removeChild(n);
1973 n.deleteData(start, len);
1976 // Nothing is partially selected, so collapse to start point
1980 if (how == DELETE) {
1984 if (sub.length > 0) {
1985 frag.appendChild(doc.createTextNode(sub));
1991 // Copy nodes between the start/end offsets.
1992 n = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]);
1993 cnt = t[END_OFFSET] - t[START_OFFSET];
1995 while (n && cnt > 0) {
1996 sibling = n.nextSibling;
1997 xferNode = _traverseFullySelected(n, how);
2000 frag.appendChild(xferNode);
2007 // Nothing is partially selected, so collapse to start point
2015 function _traverseCommonStartContainer(endAncestor, how) {
2016 var frag, n, endIdx, cnt, sibling, xferNode;
2018 if (how != DELETE) {
2019 frag = createDocumentFragment();
2022 n = _traverseRightBoundary(endAncestor, how);
2025 frag.appendChild(n);
2028 endIdx = nodeIndex(endAncestor);
2029 cnt = endIdx - t[START_OFFSET];
2032 // Collapse to just before the endAncestor, which
2033 // is partially selected.
2035 t.setEndBefore(endAncestor);
2042 n = endAncestor.previousSibling;
2044 sibling = n.previousSibling;
2045 xferNode = _traverseFullySelected(n, how);
2048 frag.insertBefore(xferNode, frag.firstChild);
2055 // Collapse to just before the endAncestor, which
2056 // is partially selected.
2058 t.setEndBefore(endAncestor);
2065 function _traverseCommonEndContainer(startAncestor, how) {
2066 var frag, startIdx, n, cnt, sibling, xferNode;
2068 if (how != DELETE) {
2069 frag = createDocumentFragment();
2072 n = _traverseLeftBoundary(startAncestor, how);
2074 frag.appendChild(n);
2077 startIdx = nodeIndex(startAncestor);
2078 ++startIdx; // Because we already traversed it
2080 cnt = t[END_OFFSET] - startIdx;
2081 n = startAncestor.nextSibling;
2082 while (n && cnt > 0) {
2083 sibling = n.nextSibling;
2084 xferNode = _traverseFullySelected(n, how);
2087 frag.appendChild(xferNode);
2095 t.setStartAfter(startAncestor);
2102 function _traverseCommonAncestors(startAncestor, endAncestor, how) {
2103 var n, frag, commonParent, startOffset, endOffset, cnt, sibling, nextSibling;
2105 if (how != DELETE) {
2106 frag = createDocumentFragment();
2109 n = _traverseLeftBoundary(startAncestor, how);
2111 frag.appendChild(n);
2114 commonParent = startAncestor.parentNode;
2115 startOffset = nodeIndex(startAncestor);
2116 endOffset = nodeIndex(endAncestor);
2119 cnt = endOffset - startOffset;
2120 sibling = startAncestor.nextSibling;
2123 nextSibling = sibling.nextSibling;
2124 n = _traverseFullySelected(sibling, how);
2127 frag.appendChild(n);
2130 sibling = nextSibling;
2134 n = _traverseRightBoundary(endAncestor, how);
2137 frag.appendChild(n);
2141 t.setStartAfter(startAncestor);
2148 function _traverseRightBoundary(root, how) {
2149 var next = _getSelectedNode(t[END_CONTAINER], t[END_OFFSET] - 1), parent, clonedParent;
2150 var prevSibling, clonedChild, clonedGrandParent, isFullySelected = next != t[END_CONTAINER];
2153 return _traverseNode(next, isFullySelected, FALSE, how);
2156 parent = next.parentNode;
2157 clonedParent = _traverseNode(parent, FALSE, FALSE, how);
2161 prevSibling = next.previousSibling;
2162 clonedChild = _traverseNode(next, isFullySelected, FALSE, how);
2164 if (how != DELETE) {
2165 clonedParent.insertBefore(clonedChild, clonedParent.firstChild);
2168 isFullySelected = TRUE;
2172 if (parent == root) {
2173 return clonedParent;
2176 next = parent.previousSibling;
2177 parent = parent.parentNode;
2179 clonedGrandParent = _traverseNode(parent, FALSE, FALSE, how);
2181 if (how != DELETE) {
2182 clonedGrandParent.appendChild(clonedParent);
2185 clonedParent = clonedGrandParent;
2189 function _traverseLeftBoundary(root, how) {
2190 var next = _getSelectedNode(t[START_CONTAINER], t[START_OFFSET]), isFullySelected = next != t[START_CONTAINER];
2191 var parent, clonedParent, nextSibling, clonedChild, clonedGrandParent;
2194 return _traverseNode(next, isFullySelected, TRUE, how);
2197 parent = next.parentNode;
2198 clonedParent = _traverseNode(parent, FALSE, TRUE, how);
2202 nextSibling = next.nextSibling;
2203 clonedChild = _traverseNode(next, isFullySelected, TRUE, how);
2205 if (how != DELETE) {
2206 clonedParent.appendChild(clonedChild);
2209 isFullySelected = TRUE;
2213 if (parent == root) {
2214 return clonedParent;
2217 next = parent.nextSibling;
2218 parent = parent.parentNode;
2220 clonedGrandParent = _traverseNode(parent, FALSE, TRUE, how);
2222 if (how != DELETE) {
2223 clonedGrandParent.appendChild(clonedParent);
2226 clonedParent = clonedGrandParent;
2230 function _traverseNode(n, isFullySelected, isLeft, how) {
2231 var txtValue, newNodeValue, oldNodeValue, offset, newNode;
2233 if (isFullySelected) {
2234 return _traverseFullySelected(n, how);
2237 if (n.nodeType == 3 /* TEXT_NODE */) {
2238 txtValue = n.nodeValue;
2241 offset = t[START_OFFSET];
2242 newNodeValue = txtValue.substring(offset);
2243 oldNodeValue = txtValue.substring(0, offset);
2245 offset = t[END_OFFSET];
2246 newNodeValue = txtValue.substring(0, offset);
2247 oldNodeValue = txtValue.substring(offset);
2251 n.nodeValue = oldNodeValue;
2254 if (how == DELETE) {
2258 newNode = dom.clone(n, FALSE);
2259 newNode.nodeValue = newNodeValue;
2264 if (how == DELETE) {
2268 return dom.clone(n, FALSE);
2271 function _traverseFullySelected(n, how) {
2272 if (how != DELETE) {
2273 return how == CLONE ? dom.clone(n, TRUE) : n;
2276 n.parentNode.removeChild(n);
2279 function toStringIE() {
2280 return dom.create('body', null, cloneContents()).outerText;
2285 startContainer: doc,
2290 commonAncestorContainer: doc,
2301 setStartBefore: setStartBefore,
2302 setStartAfter: setStartAfter,
2303 setEndBefore: setEndBefore,
2304 setEndAfter: setEndAfter,
2306 selectNode: selectNode,
2307 selectNodeContents: selectNodeContents,
2308 compareBoundaryPoints: compareBoundaryPoints,
2309 deleteContents: deleteContents,
2310 extractContents: extractContents,
2311 cloneContents: cloneContents,
2312 insertNode: insertNode,
2313 surroundContents: surroundContents,
2314 cloneRange: cloneRange,
2315 toStringIE: toStringIE
2321 // Older IE versions doesn't let you override toString by it's constructor so we have to stick it in the prototype
2322 Range.prototype.toString = function() {
2323 return this.toStringIE();
2329 // Included from: js/tinymce/classes/html/Entities.js
2334 * Copyright, Moxiecode Systems AB
2335 * Released under LGPL License.
2337 * License: http://www.tinymce.com/license
2338 * Contributing: http://www.tinymce.com/contributing
2341 /*jshint bitwise:false */
2344 * Entity encoder class.
2346 * @class tinymce.html.Entities
2350 define("tinymce/html/Entities", [
2351 "tinymce/util/Tools"
2352 ], function(Tools) {
2353 var makeMap = Tools.makeMap;
2355 var namedEntities, baseEntities, reverseEntities,
2356 attrsCharsRegExp = /[&<>\"\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
2357 textCharsRegExp = /[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,
2358 rawCharsRegExp = /[<>&\"\']/g,
2359 entityRegExp = /&(#x|#)?([\w]+);/g,
2361 128: "\u20AC", 130: "\u201A", 131: "\u0192", 132: "\u201E", 133: "\u2026", 134: "\u2020",
2362 135: "\u2021", 136: "\u02C6", 137: "\u2030", 138: "\u0160", 139: "\u2039", 140: "\u0152",
2363 142: "\u017D", 145: "\u2018", 146: "\u2019", 147: "\u201C", 148: "\u201D", 149: "\u2022",
2364 150: "\u2013", 151: "\u2014", 152: "\u02DC", 153: "\u2122", 154: "\u0161", 155: "\u203A",
2365 156: "\u0153", 158: "\u017E", 159: "\u0178"
2370 '\"': '"', // Needs to be escaped since the YUI compressor would otherwise break the code
2377 // Reverse lookup table for raw entities
2386 // Decodes text by using the browser
2387 function nativeDecode(text) {
2390 elm = document.createElement("div");
2391 elm.innerHTML = text;
2393 return elm.textContent || elm.innerText || text;
2396 // Build a two way lookup table for the entities
2397 function buildEntitiesLookup(items, radix) {
2398 var i, chr, entity, lookup = {};
2401 items = items.split(',');
2402 radix = radix || 10;
2404 // Build entities lookup table
2405 for (i = 0; i < items.length; i += 2) {
2406 chr = String.fromCharCode(parseInt(items[i], radix));
2408 // Only add non base entities
2409 if (!baseEntities[chr]) {
2410 entity = '&' + items[i + 1] + ';';
2411 lookup[chr] = entity;
2412 lookup[entity] = chr;
2420 // Unpack entities lookup where the numbers are in radix 32 to reduce the size
2421 namedEntities = buildEntitiesLookup(
2422 '50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,' +
2423 '5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,' +
2424 '5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,' +
2425 '5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,' +
2426 '68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,' +
2427 '6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,' +
2428 '6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,' +
2429 '75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,' +
2430 '7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,' +
2431 '7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,' +
2432 'sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,' +
2433 'st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,' +
2434 't9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,' +
2435 'tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,' +
2436 'u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,' +
2437 '81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,' +
2438 '8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,' +
2439 '8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,' +
2440 '8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,' +
2441 '8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,' +
2442 'nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,' +
2443 'rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,' +
2444 'Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,' +
2445 '80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,' +
2446 '811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro', 32);
2450 * Encodes the specified string using raw entities. This means only the required XML base entities will be endoded.
2453 * @param {String} text Text to encode.
2454 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
2455 * @return {String} Entity encoded text.
2457 encodeRaw: function(text, attr) {
2458 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
2459 return baseEntities[chr] || chr;
2464 * Encoded the specified text with both the attributes and text entities. This function will produce larger text contents
2465 * since it doesn't know if the context is within a attribute or text node. This was added for compatibility
2466 * and is exposed as the DOMUtils.encode function.
2468 * @method encodeAllRaw
2469 * @param {String} text Text to encode.
2470 * @return {String} Entity encoded text.
2472 encodeAllRaw: function(text) {
2473 return ('' + text).replace(rawCharsRegExp, function(chr) {
2474 return baseEntities[chr] || chr;
2479 * Encodes the specified string using numeric entities. The core entities will be
2480 * encoded as named ones but all non lower ascii characters will be encoded into numeric entities.
2482 * @method encodeNumeric
2483 * @param {String} text Text to encode.
2484 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
2485 * @return {String} Entity encoded text.
2487 encodeNumeric: function(text, attr) {
2488 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
2489 // Multi byte sequence convert it to a single entity
2490 if (chr.length > 1) {
2491 return '&#' + (((chr.charCodeAt(0) - 0xD800) * 0x400) + (chr.charCodeAt(1) - 0xDC00) + 0x10000) + ';';
2494 return baseEntities[chr] || '&#' + chr.charCodeAt(0) + ';';
2499 * Encodes the specified string using named entities. The core entities will be encoded
2500 * as named ones but all non lower ascii characters will be encoded into named entities.
2502 * @method encodeNamed
2503 * @param {String} text Text to encode.
2504 * @param {Boolean} attr Optional flag to specify if the text is attribute contents.
2505 * @param {Object} entities Optional parameter with entities to use.
2506 * @return {String} Entity encoded text.
2508 encodeNamed: function(text, attr, entities) {
2509 entities = entities || namedEntities;
2511 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
2512 return baseEntities[chr] || entities[chr] || chr;
2517 * Returns an encode function based on the name(s) and it's optional entities.
2519 * @method getEncodeFunc
2520 * @param {String} name Comma separated list of encoders for example named,numeric.
2521 * @param {String} entities Optional parameter with entities to use instead of the built in set.
2522 * @return {function} Encode function to be used.
2524 getEncodeFunc: function(name, entities) {
2525 entities = buildEntitiesLookup(entities) || namedEntities;
2527 function encodeNamedAndNumeric(text, attr) {
2528 return text.replace(attr ? attrsCharsRegExp : textCharsRegExp, function(chr) {
2529 return baseEntities[chr] || entities[chr] || '&#' + chr.charCodeAt(0) + ';' || chr;
2533 function encodeCustomNamed(text, attr) {
2534 return Entities.encodeNamed(text, attr, entities);
2537 // Replace + with , to be compatible with previous TinyMCE versions
2538 name = makeMap(name.replace(/\+/g, ','));
2540 // Named and numeric encoder
2541 if (name.named && name.numeric) {
2542 return encodeNamedAndNumeric;
2549 return encodeCustomNamed;
2552 return Entities.encodeNamed;
2557 return Entities.encodeNumeric;
2561 return Entities.encodeRaw;
2565 * Decodes the specified string, this will replace entities with raw UTF characters.
2568 * @param {String} text Text to entity decode.
2569 * @return {String} Entity decoded string.
2571 decode: function(text) {
2572 return text.replace(entityRegExp, function(all, numeric, value) {
2574 value = parseInt(value, numeric.length === 2 ? 16 : 10);
2576 // Support upper UTF
2577 if (value > 0xFFFF) {
2580 return String.fromCharCode(0xD800 + (value >> 10), 0xDC00 + (value & 0x3FF));
2582 return asciiMap[value] || String.fromCharCode(value);
2586 return reverseEntities[all] || namedEntities[all] || nativeDecode(all);
2594 // Included from: js/tinymce/classes/Env.js
2599 * Copyright, Moxiecode Systems AB
2600 * Released under LGPL License.
2602 * License: http://www.tinymce.com/license
2603 * Contributing: http://www.tinymce.com/contributing
2607 * This class contains various environment constrants like browser versions etc.
2608 * Normally you don't want to sniff specific browser versions but sometimes you have
2609 * to when it's impossible to feature detect. So use this with care.
2611 * @class tinymce.Env
2614 define("tinymce/Env", [], function() {
2615 var nav = navigator, userAgent = nav.userAgent;
2616 var opera, webkit, ie, ie11, gecko, mac, iDevice;
2618 opera = window.opera && window.opera.buildNumber;
2619 webkit = /WebKit/.test(userAgent);
2620 ie = !webkit && !opera && (/MSIE/gi).test(userAgent) && (/Explorer/gi).test(nav.appName);
2621 ie = ie && /MSIE (\w+)\./.exec(userAgent)[1];
2622 ie11 = userAgent.indexOf('Trident') != -1 ? 11 : false;
2624 gecko = !webkit && /Gecko/.test(userAgent);
2625 mac = userAgent.indexOf('Mac') != -1;
2626 iDevice = /(iPad|iPhone)/.test(userAgent);
2628 // Is a iPad/iPhone and not on iOS5 sniff the WebKit version since older iOS WebKit versions
2629 // says it has contentEditable support but there is no visible caret.
2630 var contentEditable = !iDevice || userAgent.match(/AppleWebKit\/(\d*)/)[1] >= 534;
2634 * Constant that is true if the browser is Opera.
2643 * Constant that is true if the browser is WebKit (Safari/Chrome).
2652 * Constant that is more than zero if the browser is IE.
2661 * Constant that is true if the browser is Gecko.
2670 * Constant that is true if the os is Mac OS.
2679 * Constant that is true if the os is iOS.
2688 * Constant that is true if the browser supports editing.
2690 * @property contentEditable
2694 contentEditable: contentEditable,
2697 * Transparent image data url.
2699 * @property transparentSrc
2703 transparentSrc: "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",
2706 * Returns true/false if the browser can or can't place the caret after a inline block like an image.
2708 * @property noCaretAfter
2712 caretAfter: ie != 8,
2715 * Constant that is true if the browser supports native DOM Ranges. IE 9+.
2720 range: window.getSelection && "Range" in window,
2723 * Returns the IE document mode for non IE browsers this will fake IE 10.
2725 * @property documentMode
2728 documentMode: ie ? (document.documentMode || 7) : 10
2732 // Included from: js/tinymce/classes/dom/DOMUtils.js
2737 * Copyright, Moxiecode Systems AB
2738 * Released under LGPL License.
2740 * License: http://www.tinymce.com/license
2741 * Contributing: http://www.tinymce.com/contributing
2745 * Utility class for various DOM manipulation and retrieval functions.
2747 * @class tinymce.dom.DOMUtils
2749 * // Add a class to an element by id in the page
2750 * tinymce.DOM.addClass('someid', 'someclass');
2752 * // Add a class to an element by id inside the editor
2753 * tinymce.activeEditor.dom.addClass('someid', 'someclass');
2755 define("tinymce/dom/DOMUtils", [
2756 "tinymce/dom/Sizzle",
2757 "tinymce/html/Styles",
2758 "tinymce/dom/EventUtils",
2759 "tinymce/dom/TreeWalker",
2760 "tinymce/dom/Range",
2761 "tinymce/html/Entities",
2763 "tinymce/util/Tools"
2764 ], function(Sizzle, Styles, EventUtils, TreeWalker, Range, Entities, Env, Tools) {
2766 var each = Tools.each, is = Tools.is, grep = Tools.grep, trim = Tools.trim, extend = Tools.extend;
2767 var isWebKit = Env.webkit, isIE = Env.ie;
2768 var simpleSelectorRe = /^([a-z0-9],?)+$/i;
2769 var whiteSpaceRegExp = /^[ \t\r\n]*$/;
2770 var numericCssMap = Tools.makeMap('fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom', ' ');
2773 * Constructs a new DOMUtils instance. Consult the Wiki for more details on settings etc for this class.
2777 * @param {Document} d Document reference to bind the utility class to.
2778 * @param {settings} s Optional settings collection.
2780 function DOMUtils(doc, settings) {
2781 var self = this, blockElementsMap;
2787 self.stdMode = !isIE || doc.documentMode >= 8;
2788 self.boxModel = !isIE || doc.compatMode == "CSS1Compat" || self.stdMode;
2789 self.hasOuterHTML = "outerHTML" in doc.createElement("a");
2791 self.settings = settings = extend({
2796 self.schema = settings.schema;
2797 self.styles = new Styles({
2798 url_converter: settings.url_converter,
2799 url_converter_scope: settings.url_converter_scope
2800 }, settings.schema);
2803 self.events = settings.ownEvents ? new EventUtils(settings.proxy) : EventUtils.Event;
2804 blockElementsMap = settings.schema ? settings.schema.getBlockElements() : {};
2807 * Returns true/false if the specified element is a block element or not.
2810 * @param {Node/String} node Element/Node to check.
2811 * @return {Boolean} True/False state if the node is a block element or not.
2813 self.isBlock = function(node) {
2819 // This function is called in module pattern style since it might be executed with the wrong this scope
2820 var type = node.nodeType;
2822 // If it's a node then check the type and use the nodeName
2824 return !!(type === 1 && blockElementsMap[node.nodeName]);
2827 return !!blockElementsMap[node];
2831 DOMUtils.prototype = {
2835 "class": "className",
2836 className: "className",
2838 disabled: "disabled",
2839 maxlength: "maxLength",
2840 readonly: "readOnly",
2841 selected: "selected",
2848 fixDoc: function(doc) {
2849 var settings = this.settings, name;
2851 if (isIE && settings.schema) {
2852 // Add missing HTML 4/5 elements to IE
2853 ('abbr article aside audio canvas ' +
2854 'details figcaption figure footer ' +
2855 'header hgroup mark menu meter nav ' +
2856 'output progress section summary ' +
2857 'time video').replace(/\w+/g, function(name) {
2858 doc.createElement(name);
2861 // Create all custom elements
2862 for (name in settings.schema.getCustomElements()) {
2863 doc.createElement(name);
2868 clone: function(node, deep) {
2869 var self = this, clone, doc;
2871 // TODO: Add feature detection here in the future
2872 if (!isIE || node.nodeType !== 1 || deep) {
2873 return node.cloneNode(deep);
2878 // Make a HTML5 safe shallow copy
2880 clone = doc.createElement(node.nodeName);
2883 each(self.getAttribs(node), function(attr) {
2884 self.setAttrib(clone, attr.nodeName, self.getAttrib(node, attr.nodeName));
2890 // Setup HTML5 patched document fragment
2892 self.frag = doc.createDocumentFragment();
2893 self.fixDoc(self.frag);
2896 // Make a deep copy by adding it to the document fragment then removing it this removed the :section
2897 clone = doc.createElement('div');
2898 self.frag.appendChild(clone);
2899 clone.innerHTML = node.outerHTML;
2900 self.frag.removeChild(clone);
2902 return clone.firstChild;
2906 * Returns the root node of the document. This is normally the body but might be a DIV. Parents like getParent will not
2907 * go above the point of this root node.
2910 * @return {Element} Root element for the utility class.
2912 getRoot: function() {
2915 return self.get(self.settings.root_element) || self.doc.body;
2919 * Returns the viewport of the window.
2921 * @method getViewPort
2922 * @param {Window} win Optional window to get viewport of.
2923 * @return {Object} Viewport object with fields x, y, w and h.
2925 getViewPort: function(win) {
2928 win = !win ? this.win : win;
2930 rootElm = this.boxModel ? doc.documentElement : doc.body;
2932 // Returns viewport size excluding scrollbars
2934 x: win.pageXOffset || rootElm.scrollLeft,
2935 y: win.pageYOffset || rootElm.scrollTop,
2936 w: win.innerWidth || rootElm.clientWidth,
2937 h: win.innerHeight || rootElm.clientHeight
2942 * Returns the rectangle for a specific element.
2945 * @param {Element/String} elm Element object or element ID to get rectangle from.
2946 * @return {object} Rectangle for specified element object with x, y, w, h fields.
2948 getRect: function(elm) {
2949 var self = this, pos, size;
2951 elm = self.get(elm);
2952 pos = self.getPos(elm);
2953 size = self.getSize(elm);
2957 w: size.w, h: size.h
2962 * Returns the size dimensions of the specified element.
2965 * @param {Element/String} elm Element object or element ID to get rectangle from.
2966 * @return {object} Rectangle for specified element object with w, h fields.
2968 getSize: function(elm) {
2969 var self = this, w, h;
2971 elm = self.get(elm);
2972 w = self.getStyle(elm, 'width');
2973 h = self.getStyle(elm, 'height');
2975 // Non pixel value, then force offset/clientWidth
2976 if (w.indexOf('px') === -1) {
2980 // Non pixel value, then force offset/clientWidth
2981 if (h.indexOf('px') === -1) {
2986 w: parseInt(w, 10) || elm.offsetWidth || elm.clientWidth,
2987 h: parseInt(h, 10) || elm.offsetHeight || elm.clientHeight
2992 * Returns a node by the specified selector function. This function will
2993 * loop through all parent nodes and call the specified function for each node.
2994 * If the function then returns true indicating that it has found what it was looking for, the loop execution will then end
2995 * and the node it found will be returned.
2998 * @param {Node/String} node DOM node to search parents on or ID string.
2999 * @param {function} selector Selection function or CSS selector to execute on each node.
3000 * @param {Node} root Optional root element, never go below this point.
3001 * @return {Node} DOM Node or null if it wasn't found.
3003 getParent: function(node, selector, root) {
3004 return this.getParents(node, selector, root, false);
3008 * Returns a node list of all parents matching the specified selector function or pattern.
3009 * If the function then returns true indicating that it has found what it was looking for and that node will be collected.
3011 * @method getParents
3012 * @param {Node/String} node DOM node to search parents on or ID string.
3013 * @param {function} selector Selection function to execute on each node or CSS pattern.
3014 * @param {Node} root Optional root element, never go below this point.
3015 * @return {Array} Array of nodes or null if it wasn't found.
3017 getParents: function(node, selector, root, collect) {
3018 var self = this, selectorVal, result = [];
3020 node = self.get(node);
3021 collect = collect === undefined;
3023 // Default root on inline mode
3024 root = root || (self.getRoot().nodeName != 'BODY' ? self.getRoot().parentNode : null);
3026 // Wrap node name as func
3027 if (is(selector, 'string')) {
3028 selectorVal = selector;
3030 if (selector === '*') {
3031 selector = function(node) {return node.nodeType == 1;};
3033 selector = function(node) {
3034 return self.is(node, selectorVal);
3040 if (node == root || !node.nodeType || node.nodeType === 9) {
3044 if (!selector || selector(node)) {
3052 node = node.parentNode;
3055 return collect ? result : null;
3059 * Returns the specified element by ID or the input element if it isn't a string.
3062 * @param {String/Element} n Element id to look for or element to just pass though.
3063 * @return {Element} Element matching the specified id or null if it wasn't found.
3065 get: function(elm) {
3068 if (elm && this.doc && typeof(elm) == 'string') {
3070 elm = this.doc.getElementById(elm);
3072 // IE and Opera returns meta elements when they match the specified input ID, but getElementsByName seems to do the trick
3073 if (elm && elm.id !== name) {
3074 return this.doc.getElementsByName(name)[1];
3082 * Returns the next node that matches selector or function
3085 * @param {Node} node Node to find siblings from.
3086 * @param {String/function} selector Selector CSS expression or function.
3087 * @return {Node} Next node item matching the selector or null if it wasn't found.
3089 getNext: function(node, selector) {
3090 return this._findSib(node, selector, 'nextSibling');
3094 * Returns the previous node that matches selector or function
3097 * @param {Node} node Node to find siblings from.
3098 * @param {String/function} selector Selector CSS expression or function.
3099 * @return {Node} Previous node item matching the selector or null if it wasn't found.
3101 getPrev: function(node, selector) {
3102 return this._findSib(node, selector, 'previousSibling');
3108 * Selects specific elements by a CSS level 3 pattern. For example "div#a1 p.test".
3109 * This function is optimized for the most common patterns needed in TinyMCE but it also performs well enough
3110 * on more complex patterns.
3113 * @param {String} selector CSS level 3 pattern to select/find elements by.
3114 * @param {Object} scope Optional root element/scope element to search in.
3115 * @return {Array} Array with all matched elements.
3117 * // Adds a class to all paragraphs in the currently active editor
3118 * tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'someclass');
3120 * // Adds a class to all spans that have the test class in the currently active editor
3121 * tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('span.test'), 'someclass')
3123 select: function(selector, scope) {
3126 //Sizzle.selectors.cacheLength = 0;
3127 return Sizzle(selector, self.get(scope) || self.get(self.settings.root_element) || self.doc, []);
3131 * Returns true/false if the specified element matches the specified css pattern.
3134 * @param {Node/NodeList} elm DOM node to match or an array of nodes to match.
3135 * @param {String} selector CSS pattern to match the element against.
3137 is: function(elm, selector) {
3140 // If it isn't an array then try to do some simple selectors instead of Sizzle for to boost performance
3141 if (elm.length === undefined) {
3142 // Simple all selector
3143 if (selector === '*') {
3144 return elm.nodeType == 1;
3147 // Simple selector just elements
3148 if (simpleSelectorRe.test(selector)) {
3149 selector = selector.toLowerCase().split(/,/);
3150 elm = elm.nodeName.toLowerCase();
3152 for (i = selector.length - 1; i >= 0; i--) {
3153 if (selector[i] == elm) {
3163 if (elm.nodeType && elm.nodeType != 1) {
3167 return Sizzle.matches(selector, elm.nodeType ? [elm] : elm).length > 0;
3173 * Adds the specified element to another element or elements.
3176 * @param {String/Element/Array} parentElm Element id string, DOM node element or array of ids or elements to add to.
3177 * @param {String/Element} name Name of new element to add or existing element to add.
3178 * @param {Object} attrs Optional object collection with arguments to add to the new element(s).
3179 * @param {String} html Optional inner HTML contents to add for each element.
3180 * @return {Element/Array} Element that got created, or an array of created elements if multiple input elements
3183 * // Adds a new paragraph to the end of the active editor
3184 * tinymce.activeEditor.dom.add(tinymce.activeEditor.getBody(), 'p', {title: 'my title'}, 'Some content');
3186 add: function(parentElm, name, attrs, html, create) {
3189 return this.run(parentElm, function(parentElm) {
3192 newElm = is(name, 'string') ? self.doc.createElement(name) : name;
3193 self.setAttribs(newElm, attrs);
3196 if (html.nodeType) {
3197 newElm.appendChild(html);
3199 self.setHTML(newElm, html);
3203 return !create ? parentElm.appendChild(newElm) : newElm;
3208 * Creates a new element.
3211 * @param {String} name Name of new element.
3212 * @param {Object} attrs Optional object name/value collection with element attributes.
3213 * @param {String} html Optional HTML string to set as inner HTML of the element.
3214 * @return {Element} HTML DOM node element that got created.
3216 * // Adds an element where the caret/selection is in the active editor
3217 * var el = tinymce.activeEditor.dom.create('div', {id: 'test', 'class': 'myclass'}, 'some content');
3218 * tinymce.activeEditor.selection.setNode(el);
3220 create: function(name, attrs, html) {
3221 return this.add(this.doc.createElement(name), name, attrs, html, 1);
3225 * Creates HTML string for element. The element will be closed unless an empty inner HTML string is passed in.
3227 * @method createHTML
3228 * @param {String} name Name of new element.
3229 * @param {Object} attrs Optional object name/value collection with element attributes.
3230 * @param {String} html Optional HTML string to set as inner HTML of the element.
3231 * @return {String} String with new HTML element, for example: <a href="#">test</a>.
3233 * // Creates a html chunk and inserts it at the current selection/caret location
3234 * tinymce.activeEditor.selection.setContent(tinymce.activeEditor.dom.createHTML('a', {href: 'test.html'}, 'some line'));
3236 createHTML: function(name, attrs, html) {
3237 var outHtml = '', key;
3239 outHtml += '<' + name;
3241 for (key in attrs) {
3242 if (attrs.hasOwnProperty(key) && attrs[key] !== null) {
3243 outHtml += ' ' + key + '="' + this.encode(attrs[key]) + '"';
3247 // A call to tinymce.is doesn't work for some odd reason on IE9 possible bug inside their JS runtime
3248 if (typeof(html) != "undefined") {
3249 return outHtml + '>' + html + '</' + name + '>';
3252 return outHtml + ' />';
3256 * Creates a document fragment out of the specified HTML string.
3258 * @method createFragment
3259 * @param {String} html Html string to create fragment from.
3260 * @return {DocumentFragment} Document fragment node.
3262 createFragment: function(html) {
3263 var frag, node, doc = this.doc, container;
3265 container = doc.createElement("div");
3266 frag = doc.createDocumentFragment();
3269 container.innerHTML = html;
3272 while ((node = container.firstChild)) {
3273 frag.appendChild(node);
3280 * Removes/deletes the specified element(s) from the DOM.
3283 * @param {String/Element/Array} node ID of element or DOM element object or array containing multiple elements/ids.
3284 * @param {Boolean} keep_children Optional state to keep children or not. If set to true all children will be
3285 * placed at the location of the removed element.
3286 * @return {Element/Array} HTML DOM element that got removed, or an array of removed elements if multiple input elements
3289 * // Removes all paragraphs in the active editor
3290 * tinymce.activeEditor.dom.remove(tinymce.activeEditor.dom.select('p'));
3292 * // Removes an element by id in the document
3293 * tinymce.DOM.remove('mydiv');
3295 remove: function(node, keep_children) {
3296 return this.run(node, function(node) {
3297 var child, parent = node.parentNode;
3303 if (keep_children) {
3304 while ((child = node.firstChild)) {
3305 // IE 8 will crash if you don't remove completely empty text nodes
3306 if (!isIE || child.nodeType !== 3 || child.nodeValue) {
3307 parent.insertBefore(child, node);
3309 node.removeChild(child);
3314 return parent.removeChild(node);
3319 * Sets the CSS style value on a HTML element. The name can be a camelcase string
3320 * or the CSS style name like background-color.
3323 * @param {String/Element/Array} n HTML element/Element ID or Array of elements/ids to set CSS style value on.
3324 * @param {String} na Name of the style value to set.
3325 * @param {String} v Value to set on the style.
3327 * // Sets a style value on all paragraphs in the currently active editor
3328 * tinymce.activeEditor.dom.setStyle(tinymce.activeEditor.dom.select('p'), 'background-color', 'red');
3330 * // Sets a style value to an element by id in the current document
3331 * tinymce.DOM.setStyle('mydiv', 'background-color', 'red');
3333 setStyle: function(elm, name, value) {
3334 return this.run(elm, function(elm) {
3335 var self = this, style, key;
3338 if (typeof(name) === 'string') {
3341 // Camelcase it, if needed
3342 name = name.replace(/-(\D)/g, function(a, b) {
3343 return b.toUpperCase();
3346 // Default px suffix on these
3347 if (typeof(value) === 'number' && !numericCssMap[name]) {
3351 // IE specific opacity
3352 if (name === "opacity" && elm.runtimeStyle && typeof(elm.runtimeStyle.opacity) === "undefined") {
3353 style.filter = value === '' ? '' : "alpha(opacity=" + (value * 100) + ")";
3356 if (name == "float") {
3357 // Old IE vs modern browsers
3358 name = "cssFloat" in elm.style ? "cssFloat" : "styleFloat";
3362 style[name] = value;
3367 // Force update of the style data
3368 if (self.settings.update_styles) {
3369 elm.removeAttribute('data-mce-style');
3373 self.setStyle(elm, key, name[key]);
3381 * Returns the current style or runtime/computed value of an element.
3384 * @param {String/Element} elm HTML element or element id string to get style from.
3385 * @param {String} name Style name to return.
3386 * @param {Boolean} computed Computed style.
3387 * @return {String} Current style or computed style value of an element.
3389 getStyle: function(elm, name, computed) {
3390 elm = this.get(elm);
3397 if (this.doc.defaultView && computed) {
3399 name = name.replace(/[A-Z]/g, function(a){
3404 return this.doc.defaultView.getComputedStyle(elm, null).getPropertyValue(name);
3406 // Old safari might fail
3411 // Camelcase it, if needed
3412 name = name.replace(/-(\D)/g, function(a, b) {
3413 return b.toUpperCase();
3416 if (name == 'float') {
3417 name = isIE ? 'styleFloat' : 'cssFloat';
3421 if (elm.currentStyle && computed) {
3422 return elm.currentStyle[name];
3425 return elm.style ? elm.style[name] : undefined;
3429 * Sets multiple styles on the specified element(s).
3432 * @param {Element/String/Array} e DOM element, element id string or array of elements/ids to set styles on.
3433 * @param {Object} o Name/Value collection of style items to add to the element(s).
3435 * // Sets styles on all paragraphs in the currently active editor
3436 * tinymce.activeEditor.dom.setStyles(tinymce.activeEditor.dom.select('p'), {'background-color': 'red', 'color': 'green'});
3438 * // Sets styles to an element by id in the current document
3439 * tinymce.DOM.setStyles('mydiv', {'background-color': 'red', 'color': 'green'});
3441 setStyles: function(elm, styles) {
3442 this.setStyle(elm, styles);
3445 css: function(elm, name, value) {
3446 this.setStyle(elm, name, value);
3450 * Removes all attributes from an element or elements.
3452 * @method removeAllAttribs
3453 * @param {Element/String/Array} e DOM element, element id string or array of elements/ids to remove attributes from.
3455 removeAllAttribs: function(e) {
3456 return this.run(e, function(e) {
3457 var i, attrs = e.attributes;
3458 for (i = attrs.length - 1; i >= 0; i--) {
3459 e.removeAttributeNode(attrs.item(i));
3465 * Sets the specified attribute of an element or elements.
3468 * @param {Element/String/Array} e DOM element, element id string or array of elements/ids to set attribute on.
3469 * @param {String} n Name of attribute to set.
3470 * @param {String} v Value to set on the attribute - if this value is falsy like null, 0 or '' it will remove the attribute instead.
3472 * // Sets class attribute on all paragraphs in the active editor
3473 * tinymce.activeEditor.dom.setAttrib(tinymce.activeEditor.dom.select('p'), 'class', 'myclass');
3475 * // Sets class attribute on a specific element in the current page
3476 * tinymce.dom.setAttrib('mydiv', 'class', 'myclass');
3478 setAttrib: function(e, n, v) {
3486 return this.run(e, function(e) {
3488 var originalValue = e.getAttribute(n);
3492 if (!is(v, 'string')) {
3493 each(v, function(v, n) {
3494 t.setStyle(e, n, v);
3500 // No mce_style for elements with these since they might get resized by the user
3501 if (s.keep_values) {
3503 e.setAttribute('data-mce-style', v, 2);
3505 e.removeAttribute('data-mce-style', 2);
3509 e.style.cssText = v;
3513 e.className = v || ''; // Fix IE null bug
3518 if (s.keep_values) {
3519 if (s.url_converter) {
3520 v = s.url_converter.call(s.url_converter_scope || t, v, n, e);
3523 t.setAttrib(e, 'data-mce-' + n, v, 2);
3529 e.setAttribute('data-mce-style', v);
3533 if (is(v) && v !== null && v.length !== 0) {
3534 e.setAttribute(n, '' + v, 2);
3536 e.removeAttribute(n, 2);
3539 // fire onChangeAttrib event for attributes that have changed
3540 if (originalValue != v && s.onSetAttrib) {
3541 s.onSetAttrib({attrElm: e, attrName: n, attrValue: v});
3547 * Sets two or more specified attributes of an element or elements.
3549 * @method setAttribs
3550 * @param {Element/String/Array} elm DOM element, element id string or array of elements/ids to set attributes on.
3551 * @param {Object} attrs Name/Value collection of attribute items to add to the element(s).
3553 * // Sets class and title attributes on all paragraphs in the active editor
3554 * tinymce.activeEditor.dom.setAttribs(tinymce.activeEditor.dom.select('p'), {'class': 'myclass', title: 'some title'});
3556 * // Sets class and title attributes on a specific element in the current page
3557 * tinymce.DOM.setAttribs('mydiv', {'class': 'myclass', title: 'some title'});
3559 setAttribs: function(elm, attrs) {
3562 return this.run(elm, function(elm) {
3563 each(attrs, function(value, name) {
3564 self.setAttrib(elm, name, value);
3570 * Returns the specified attribute by name.
3573 * @param {String/Element} elm Element string id or DOM element to get attribute from.
3574 * @param {String} name Name of attribute to get.
3575 * @param {String} defaultVal Optional default value to return if the attribute didn't exist.
3576 * @return {String} Attribute value string, default value or null if the attribute wasn't found.
3578 getAttrib: function(elm, name, defaultVal) {
3579 var value, self = this, undef;
3581 elm = self.get(elm);
3583 if (!elm || elm.nodeType !== 1) {
3584 return defaultVal === undef ? false : defaultVal;
3587 if (!is(defaultVal)) {
3591 // Try the mce variant for these
3592 if (/^(src|href|style|coords|shape)$/.test(name)) {
3593 value = elm.getAttribute("data-mce-" + name);
3600 if (isIE && self.props[name]) {
3601 value = elm[self.props[name]];
3602 value = value && value.nodeValue ? value.nodeValue : value;
3606 value = elm.getAttribute(name, 2);
3609 // Check boolean attribs
3610 if (/^(checked|compact|declare|defer|disabled|ismap|multiple|nohref|noshade|nowrap|readonly|selected)$/.test(name)) {
3611 if (elm[self.props[name]] === true && value === '') {
3615 return value ? name : '';
3618 // Inner input elements will override attributes on form elements
3619 if (elm.nodeName === "FORM" && elm.getAttributeNode(name)) {
3620 return elm.getAttributeNode(name).nodeValue;
3623 if (name === 'style') {
3624 value = value || elm.style.cssText;
3627 value = self.serializeStyle(self.parseStyle(value), elm.nodeName);
3629 if (self.settings.keep_values) {
3630 elm.setAttribute('data-mce-style', value);
3635 // Remove Apple and WebKit stuff
3636 if (isWebKit && name === "class" && value) {
3637 value = value.replace(/(apple|webkit)\-[a-z\-]+/gi, '');
3645 // IE returns 1 as default value
3653 // IE returns +0 as default value for size
3654 if (value === '+0' || value === 20 || value === 0) {
3673 // IE returns -1 as default value
3682 // IE returns default value
3683 if (value === 32768 || value === 2147483647 || value === '32768') {
3693 if (value === 65535) {
3700 value = value.toLowerCase();
3704 // IE has odd anonymous function for event attributes
3705 if (name.indexOf('on') === 0 && value) {
3706 value = ('' + value).replace(/^function\s+\w+\(\)\s+\{\s+(.*)\s+\}$/, '$1');
3711 return (value !== undef && value !== null && value !== '') ? '' + value : defaultVal;
3715 * Returns the absolute x, y position of a node. The position will be returned in an object with x, y fields.
3718 * @param {Element/String} n HTML element or element id to get x, y position from.
3719 * @param {Element} ro Optional root element to stop calculations at.
3720 * @return {object} Absolute position of the specified element object with x, y fields.
3722 getPos: function(elm, rootElm) {
3723 var self = this, x = 0, y = 0, offsetParent, doc = self.doc, pos;
3725 elm = self.get(elm);
3726 rootElm = rootElm || doc.body;
3729 // Use getBoundingClientRect if it exists since it's faster than looping offset nodes
3730 if (rootElm === doc.body && elm.getBoundingClientRect) {
3731 pos = elm.getBoundingClientRect();
3732 rootElm = self.boxModel ? doc.documentElement : doc.body;
3734 // Add scroll offsets from documentElement or body since IE with the wrong box model will use d.body and so do WebKit
3735 // Also remove the body/documentelement clientTop/clientLeft on IE 6, 7 since they offset the position
3736 x = pos.left + (doc.documentElement.scrollLeft || doc.body.scrollLeft) - rootElm.clientTop;
3737 y = pos.top + (doc.documentElement.scrollTop || doc.body.scrollTop) - rootElm.clientLeft;
3739 return {x: x, y: y};
3743 while (offsetParent && offsetParent != rootElm && offsetParent.nodeType) {
3744 x += offsetParent.offsetLeft || 0;
3745 y += offsetParent.offsetTop || 0;
3746 offsetParent = offsetParent.offsetParent;
3749 offsetParent = elm.parentNode;
3750 while (offsetParent && offsetParent != rootElm && offsetParent.nodeType) {
3751 x -= offsetParent.scrollLeft || 0;
3752 y -= offsetParent.scrollTop || 0;
3753 offsetParent = offsetParent.parentNode;
3757 return {x: x, y: y};
3761 * Parses the specified style value into an object collection. This parser will also
3762 * merge and remove any redundant items that browsers might have added. It will also convert non-hex
3763 * colors to hex values. Urls inside the styles will also be converted to absolute/relative based on settings.
3765 * @method parseStyle
3766 * @param {String} cssText Style value to parse, for example: border:1px solid red;.
3767 * @return {Object} Object representation of that style, for example: {border: '1px solid red'}
3769 parseStyle: function(cssText) {
3770 return this.styles.parse(cssText);
3774 * Serializes the specified style object into a string.
3776 * @method serializeStyle
3777 * @param {Object} styles Object to serialize as string, for example: {border: '1px solid red'}
3778 * @param {String} name Optional element name.
3779 * @return {String} String representation of the style object, for example: border: 1px solid red.
3781 serializeStyle: function(styles, name) {
3782 return this.styles.serialize(styles, name);
3786 * Adds a style element at the top of the document with the specified cssText content.
3789 * @param {String} cssText CSS Text style to add to top of head of document.
3791 addStyle: function(cssText) {
3792 var self = this, doc = self.doc, head, styleElm;
3794 // Prevent inline from loading the same styles twice
3795 if (self !== DOMUtils.DOM && doc === document) {
3796 var addedStyles = DOMUtils.DOM.addedStyles;
3798 addedStyles = addedStyles || [];
3799 if (addedStyles[cssText]) {
3803 addedStyles[cssText] = true;
3804 DOMUtils.DOM.addedStyles = addedStyles;
3807 // Create style element if needed
3808 styleElm = doc.getElementById('mceDefaultStyles');
3810 styleElm = doc.createElement('style');
3811 styleElm.id = 'mceDefaultStyles';
3812 styleElm.type = 'text/css';
3814 head = doc.getElementsByTagName('head')[0];
3815 if (head.firstChild) {
3816 head.insertBefore(styleElm, head.firstChild);
3818 head.appendChild(styleElm);
3822 // Append style data to old or new style element
3823 if (styleElm.styleSheet) {
3824 styleElm.styleSheet.cssText += cssText;
3826 styleElm.appendChild(doc.createTextNode(cssText));
3831 * Imports/loads the specified CSS file into the document bound to the class.
3834 * @param {String} u URL to CSS file to load.
3836 * // Loads a CSS file dynamically into the current document
3837 * tinymce.DOM.loadCSS('somepath/some.css');
3839 * // Loads a CSS file into the currently active editor instance
3840 * tinymce.activeEditor.dom.loadCSS('somepath/some.css');
3842 * // Loads a CSS file into an editor instance by id
3843 * tinymce.get('someid').dom.loadCSS('somepath/some.css');
3845 * // Loads multiple CSS files into the current document
3846 * tinymce.DOM.loadCSS('somepath/some.css,somepath/someother.css');
3848 loadCSS: function(url) {
3849 var self = this, doc = self.doc, head;
3851 // Prevent inline from loading the same CSS file twice
3852 if (self !== DOMUtils.DOM && doc === document) {
3853 DOMUtils.DOM.loadCSS(url);
3861 head = doc.getElementsByTagName('head')[0];
3863 each(url.split(','), function(url) {
3866 if (self.files[url]) {
3870 self.files[url] = true;
3871 link = self.create('link', {rel: 'stylesheet', href: url});
3873 // IE 8 has a bug where dynamically loading stylesheets would produce a 1 item remaining bug
3874 // This fix seems to resolve that issue by recalcing the document once a stylesheet finishes loading
3875 // It's ugly but it seems to work fine.
3876 if (isIE && doc.documentMode && doc.recalc) {
3877 link.onload = function() {
3886 head.appendChild(link);
3891 * Adds a class to the specified element or elements.
3894 * @param {String/Element/Array} elm Element ID string or DOM element or array with elements or IDs.
3895 * @param {String} cls Class name to add to each element.
3896 * @return {String/Array} String with new class value or array with new class values for all elements.
3898 * // Adds a class to all paragraphs in the active editor
3899 * tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'myclass');
3901 * // Adds a class to a specific element in the current page
3902 * tinymce.DOM.addClass('mydiv', 'myclass');
3904 addClass: function(elm, cls) {
3905 return this.run(elm, function(elm) {
3912 if (this.hasClass(elm, cls)) {
3913 return elm.className;
3916 clsVal = this.removeClass(elm, cls);
3917 elm.className = clsVal = (clsVal !== '' ? (clsVal + ' ') : '') + cls;
3924 * Removes a class from the specified element or elements.
3926 * @method removeClass
3927 * @param {String/Element/Array} elm Element ID string or DOM element or array with elements or IDs.
3928 * @param {String} cls Class name to remove from each element.
3929 * @return {String/Array} String of remaining class name(s), or an array of strings if multiple input elements
3932 * // Removes a class from all paragraphs in the active editor
3933 * tinymce.activeEditor.dom.removeClass(tinymce.activeEditor.dom.select('p'), 'myclass');
3935 * // Removes a class from a specific element in the current page
3936 * tinymce.DOM.removeClass('mydiv', 'myclass');
3938 removeClass: function(elm, cls) {
3939 var self = this, re;
3941 return self.run(elm, function(elm) {
3944 if (self.hasClass(elm, cls)) {
3946 re = new RegExp("(^|\\s+)" + cls + "(\\s+|$)", "g");
3949 val = elm.className.replace(re, ' ');
3950 val = trim(val != ' ' ? val : '');
3952 elm.className = val;
3956 elm.removeAttribute('class');
3957 elm.removeAttribute('className');
3963 return elm.className;
3968 * Returns true if the specified element has the specified class.
3971 * @param {String/Element} n HTML element or element id string to check CSS class on.
3972 * @param {String} c CSS class to check for.
3973 * @return {Boolean} true/false if the specified element has the specified class.
3975 hasClass: function(elm, cls) {
3976 elm = this.get(elm);
3982 return (' ' + elm.className + ' ').indexOf(' ' + cls + ' ') !== -1;
3986 * Toggles the specified class on/off.
3988 * @method toggleClass
3989 * @param {Element} elm Element to toggle class on.
3990 * @param {[type]} cls Class to toggle on/off.
3991 * @param {[type]} state Optional state to set.
3993 toggleClass: function(elm, cls, state) {
3994 state = state === undefined ? !this.hasClass(elm, cls) : state;
3996 if (this.hasClass(elm, cls) !== state) {
3998 this.addClass(elm, cls);
4000 this.removeClass(elm, cls);
4006 * Shows the specified element(s) by ID by setting the "display" style.
4009 * @param {String/Element/Array} elm ID of DOM element or DOM element or array with elements or IDs to show.
4011 show: function(elm) {
4012 return this.setStyle(elm, 'display', 'block');
4016 * Hides the specified element(s) by ID by setting the "display" style.
4019 * @param {String/Element/Array} e ID of DOM element or DOM element or array with elements or IDs to hide.
4021 * // Hides an element by id in the document
4022 * tinymce.DOM.hide('myid');
4024 hide: function(elm) {
4025 return this.setStyle(elm, 'display', 'none');
4029 * Returns true/false if the element is hidden or not by checking the "display" style.
4032 * @param {String/Element} e Id or element to check display state on.
4033 * @return {Boolean} true/false if the element is hidden or not.
4035 isHidden: function(elm) {
4036 elm = this.get(elm);
4038 return !elm || elm.style.display == 'none' || this.getStyle(elm, 'display') == 'none';
4042 * Returns a unique id. This can be useful when generating elements on the fly.
4043 * This method will not check if the element already exists.
4046 * @param {String} prefix Optional prefix to add in front of all ids - defaults to "mce_".
4047 * @return {String} Unique id.
4049 uniqueId: function(prefix) {
4050 return (!prefix ? 'mce_' : prefix) + (this.counter++);
4054 * Sets the specified HTML content inside the element or elements. The HTML will first be processed. This means
4055 * URLs will get converted, hex color values fixed etc. Check processHTML for details.
4058 * @param {Element/String/Array} e DOM element, element id string or array of elements/ids to set HTML inside of.
4059 * @param {String} h HTML content to set as inner HTML of the element.
4061 * // Sets the inner HTML of all paragraphs in the active editor
4062 * tinymce.activeEditor.dom.setHTML(tinymce.activeEditor.dom.select('p'), 'some inner html');
4064 * // Sets the inner HTML of an element by id in the document
4065 * tinymce.DOM.setHTML('mydiv', 'some inner html');
4067 setHTML: function(element, html) {
4070 return self.run(element, function(element) {
4072 // Remove all child nodes, IE keeps empty text nodes in DOM
4073 while (element.firstChild) {
4074 element.removeChild(element.firstChild);
4078 // IE will remove comments from the beginning
4079 // unless you padd the contents with something
4080 element.innerHTML = '<br />' + html;
4081 element.removeChild(element.firstChild);
4083 // IE sometimes produces an unknown runtime error on innerHTML if it's a block element
4084 // within a block element for example a div inside a p
4085 // This seems to fix this problem
4087 // Create new div with HTML contents and a BR in front to keep comments
4088 var newElement = self.create('div');
4089 newElement.innerHTML = '<br />' + html;
4091 // Add all children from div to target
4092 each (grep(newElement.childNodes), function(node, i) {
4094 if (i && element.canHaveHTML) {
4095 element.appendChild(node);
4100 element.innerHTML = html;
4108 * Returns the outer HTML of an element.
4110 * @method getOuterHTML
4111 * @param {String/Element} elm Element ID or element object to get outer HTML from.
4112 * @return {String} Outer HTML string.
4114 * tinymce.DOM.getOuterHTML(editorElement);
4115 * tinymce.activeEditor.getOuterHTML(tinymce.activeEditor.getBody());
4117 getOuterHTML: function(elm) {
4118 var doc, self = this;
4120 elm = self.get(elm);
4126 if (elm.nodeType === 1 && self.hasOuterHTML) {
4127 return elm.outerHTML;
4130 doc = (elm.ownerDocument || self.doc).createElement("body");
4131 doc.appendChild(elm.cloneNode(true));
4133 return doc.innerHTML;
4137 * Sets the specified outer HTML on an element or elements.
4139 * @method setOuterHTML
4140 * @param {Element/String/Array} elm DOM element, element id string or array of elements/ids to set outer HTML on.
4141 * @param {Object} html HTML code to set as outer value for the element.
4142 * @param {Document} doc Optional document scope to use in this process - defaults to the document of the DOM class.
4144 * // Sets the outer HTML of all paragraphs in the active editor
4145 * tinymce.activeEditor.dom.setOuterHTML(tinymce.activeEditor.dom.select('p'), '<div>some html</div>');
4147 * // Sets the outer HTML of an element by id in the document
4148 * tinymce.DOM.setOuterHTML('mydiv', '<div>some html</div>');
4150 setOuterHTML: function(elm, html, doc) {
4153 return self.run(elm, function(elm) {
4157 tempElm = doc.createElement("body");
4158 tempElm.innerHTML = html;
4160 node = tempElm.lastChild;
4162 self.insertAfter(node.cloneNode(true), elm);
4163 node = node.previousSibling;
4169 // Only set HTML on elements
4170 if (elm.nodeType == 1) {
4171 doc = doc || elm.ownerDocument || self.doc;
4175 // Try outerHTML for IE it sometimes produces an unknown runtime error
4176 if (elm.nodeType == 1 && self.hasOuterHTML) {
4177 elm.outerHTML = html;
4182 // Fix for unknown runtime error
4193 * Entity decodes a string. This method decodes any HTML entities, such as å.
4196 * @param {String} s String to decode entities on.
4197 * @return {String} Entity decoded string.
4199 decode: Entities.decode,
4202 * Entity encodes a string. This method encodes the most common entities, such as <>"&.
4205 * @param {String} text String to encode with entities.
4206 * @return {String} Entity encoded string.
4208 encode: Entities.encodeAllRaw,
4211 * Inserts an element after the reference element.
4213 * @method insertAfter
4214 * @param {Element} node Element to insert after the reference.
4215 * @param {Element/String/Array} reference_node Reference element, element id or array of elements to insert after.
4216 * @return {Element/Array} Element that got added or an array with elements.
4218 insertAfter: function(node, reference_node) {
4219 reference_node = this.get(reference_node);
4221 return this.run(node, function(node) {
4222 var parent, nextSibling;
4224 parent = reference_node.parentNode;
4225 nextSibling = reference_node.nextSibling;
4228 parent.insertBefore(node, nextSibling);
4230 parent.appendChild(node);
4238 * Replaces the specified element or elements with the new element specified. The new element will
4239 * be cloned if multiple input elements are passed in.
4242 * @param {Element} newElm New element to replace old ones with.
4243 * @param {Element/String/Array} oldELm Element DOM node, element id or array of elements or ids to replace.
4244 * @param {Boolean} k Optional keep children state, if set to true child nodes from the old object will be added to new ones.
4246 replace: function(newElm, oldElm, keepChildren) {
4249 return self.run(oldElm, function(oldElm) {
4250 if (is(oldElm, 'array')) {
4251 newElm = newElm.cloneNode(true);
4255 each(grep(oldElm.childNodes), function(node) {
4256 newElm.appendChild(node);
4260 return oldElm.parentNode.replaceChild(newElm, oldElm);
4265 * Renames the specified element and keeps its attributes and children.
4268 * @param {Element} elm Element to rename.
4269 * @param {String} name Name of the new element.
4270 * @return {Element} New element or the old element if it needed renaming.
4272 rename: function(elm, name) {
4273 var self = this, newElm;
4275 if (elm.nodeName != name.toUpperCase()) {
4276 // Rename block element
4277 newElm = self.create(name);
4279 // Copy attribs to new block
4280 each(self.getAttribs(elm), function(attr_node) {
4281 self.setAttrib(newElm, attr_node.nodeName, self.getAttrib(elm, attr_node.nodeName));
4285 self.replace(newElm, elm, 1);
4288 return newElm || elm;
4292 * Find the common ancestor of two elements. This is a shorter method than using the DOM Range logic.
4294 * @method findCommonAncestor
4295 * @param {Element} a Element to find common ancestor of.
4296 * @param {Element} b Element to find common ancestor of.
4297 * @return {Element} Common ancestor element of the two input elements.
4299 findCommonAncestor: function(a, b) {
4305 while (pe && ps != pe) {
4316 if (!ps && a.ownerDocument) {
4317 return a.ownerDocument.documentElement;
4324 * Parses the specified RGB color value and returns a hex version of that color.
4327 * @param {String} rgbVal RGB string value like rgb(1,2,3)
4328 * @return {String} Hex version of that RGB value like #FF00FF.
4330 toHex: function(rgbVal) {
4331 return this.styles.toHex(Tools.trim(rgbVal));
4335 * Executes the specified function on the element by id or dom element node or array of elements/id.
4338 * @param {String/Element/Array} Element ID or DOM element object or array with ids or elements.
4339 * @param {function} f Function to execute for each item.
4340 * @param {Object} s Optional scope to execute the function in.
4341 * @return {Object/Array} Single object, or an array of objects if multiple input elements were passed in.
4343 run: function(elm, func, scope) {
4344 var self = this, result;
4346 if (typeof(elm) === 'string') {
4347 elm = self.get(elm);
4354 scope = scope || this;
4355 if (!elm.nodeType && (elm.length || elm.length === 0)) {
4358 each(elm, function(elm, i) {
4360 if (typeof(elm) == 'string') {
4361 elm = self.get(elm);
4364 result.push(func.call(scope, elm, i));
4371 return func.call(scope, elm);
4375 * Returns a NodeList with attributes for the element.
4377 * @method getAttribs
4378 * @param {HTMLElement/string} elm Element node or string id to get attributes from.
4379 * @return {NodeList} NodeList with attributes.
4381 getAttribs: function(elm) {
4384 elm = this.get(elm);
4393 // Object will throw exception in IE
4394 if (elm.nodeName == 'OBJECT') {
4395 return elm.attributes;
4398 // IE doesn't keep the selected attribute if you clone option elements
4399 if (elm.nodeName === 'OPTION' && this.getAttrib(elm, 'selected')) {
4400 attrs.push({specified: 1, nodeName: 'selected'});
4403 // It's crazy that this is faster in IE but it's because it returns all attributes all the time
4404 var attrRegExp = /<\/?[\w:\-]+ ?|=[\"][^\"]+\"|=\'[^\']+\'|=[\w\-]+|>/gi;
4405 elm.cloneNode(false).outerHTML.replace(attrRegExp, '').replace(/[\w:\-]+/gi, function(a) {
4406 attrs.push({specified: 1, nodeName: a});
4412 return elm.attributes;
4416 * Returns true/false if the specified node is to be considered empty or not.
4419 * tinymce.DOM.isEmpty(node, {img: true});
4421 * @param {Object} elements Optional name/value object with elements that are automatically treated as non-empty elements.
4422 * @return {Boolean} true/false if the node is empty or not.
4424 isEmpty: function(node, elements) {
4425 var self = this, i, attributes, type, walker, name, brCount = 0;
4427 node = node.firstChild;
4429 walker = new TreeWalker(node, node.parentNode);
4430 elements = elements || self.schema ? self.schema.getNonEmptyElements() : null;
4433 type = node.nodeType;
4436 // Ignore bogus elements
4437 if (node.getAttribute('data-mce-bogus')) {
4441 // Keep empty elements like <img />
4442 name = node.nodeName.toLowerCase();
4443 if (elements && elements[name]) {
4444 // Ignore single BR elements in blocks like <p><br /></p> or <p><span><br /></span></p>
4445 if (name === 'br') {
4453 // Keep elements with data-bookmark attributes or name attribute like <a name="1"></a>
4454 attributes = self.getAttribs(node);
4455 i = node.attributes.length;
4457 name = node.attributes[i].nodeName;
4458 if (name === "name" || name === 'data-mce-bookmark') {
4464 // Keep comment nodes
4469 // Keep non whitespace text nodes
4470 if ((type === 3 && !whiteSpaceRegExp.test(node.nodeValue))) {
4473 } while ((node = walker.next()));
4476 return brCount <= 1;
4480 * Creates a new DOM Range object. This will use the native DOM Range API if it's
4481 * available. If it's not, it will fall back to the custom TinyMCE implementation.
4484 * @return {DOMRange} DOM Range object.
4486 * var rng = tinymce.DOM.createRng();
4487 * alert(rng.startContainer + "," + rng.startOffset);
4489 createRng: function() {
4492 return doc.createRange ? doc.createRange() : new Range(this);
4496 * Returns the index of the specified node within its parent.
4499 * @param {Node} node Node to look for.
4500 * @param {boolean} normalized Optional true/false state if the index is what it would be after a normalization.
4501 * @return {Number} Index of the specified node.
4503 nodeIndex: function(node, normalized) {
4504 var idx = 0, lastNodeType, lastNode, nodeType;
4507 for (lastNodeType = node.nodeType, node = node.previousSibling, lastNode = node; node; node = node.previousSibling) {
4508 nodeType = node.nodeType;
4510 // Normalize text nodes
4511 if (normalized && nodeType == 3) {
4512 if (nodeType == lastNodeType || !node.nodeValue.length) {
4517 lastNodeType = nodeType;
4525 * Splits an element into two new elements and places the specified split
4526 * element or elements between the new ones. For example splitting the paragraph at the bold element in
4527 * this example <p>abc<b>abc</b>123</p> would produce <p>abc</p><b>abc</b><p>123</p>.
4530 * @param {Element} parentElm Parent element to split.
4531 * @param {Element} splitElm Element to split at.
4532 * @param {Element} replacementElm Optional replacement element to replace the split element with.
4533 * @return {Element} Returns the split element or the replacement element if that is specified.
4535 split: function(parentElm, splitElm, replacementElm) {
4536 var self = this, r = self.createRng(), bef, aft, pa;
4538 // W3C valid browsers tend to leave empty nodes to the left/right side of the contents - this makes sense
4539 // but we don't want that in our code since it serves no purpose for the end user
4540 // For example splitting this html at the bold element:
4541 // <p>text 1<span><b>CHOP</b></span>text 2</p>
4543 // <p>text 1<span></span></p><b>CHOP</b><p><span></span>text 2</p>
4544 // this function will then trim off empty edges and produce:
4545 // <p>text 1</p><b>CHOP</b><p>text 2</p>
4546 function trimNode(node) {
4547 var i, children = node.childNodes, type = node.nodeType;
4549 function surroundedBySpans(node) {
4550 var previousIsSpan = node.previousSibling && node.previousSibling.nodeName == 'SPAN';
4551 var nextIsSpan = node.nextSibling && node.nextSibling.nodeName == 'SPAN';
4552 return previousIsSpan && nextIsSpan;
4555 if (type == 1 && node.getAttribute('data-mce-type') == 'bookmark') {
4559 for (i = children.length - 1; i >= 0; i--) {
4560 trimNode(children[i]);
4564 // Keep non whitespace text nodes
4565 if (type == 3 && node.nodeValue.length > 0) {
4566 // If parent element isn't a block or there isn't any useful contents for example "<p> </p>"
4567 // Also keep text nodes with only spaces if surrounded by spans.
4568 // eg. "<p><span>a</span> <span>b</span></p>" should keep space between a and b
4569 var trimmedLength = trim(node.nodeValue).length;
4570 if (!self.isBlock(node.parentNode) || trimmedLength > 0 || trimmedLength === 0 && surroundedBySpans(node)) {
4573 } else if (type == 1) {
4574 // If the only child is a bookmark then move it up
4575 children = node.childNodes;
4577 // TODO fix this complex if
4578 if (children.length == 1 && children[0] && children[0].nodeType == 1 &&
4579 children[0].getAttribute('data-mce-type') == 'bookmark') {
4580 node.parentNode.insertBefore(children[0], node);
4583 // Keep non empty elements or img, hr etc
4584 if (children.length || /^(br|hr|input|img)$/i.test(node.nodeName)) {
4595 if (parentElm && splitElm) {
4597 r.setStart(parentElm.parentNode, self.nodeIndex(parentElm));
4598 r.setEnd(splitElm.parentNode, self.nodeIndex(splitElm));
4599 bef = r.extractContents();
4602 r = self.createRng();
4603 r.setStart(splitElm.parentNode, self.nodeIndex(splitElm) + 1);
4604 r.setEnd(parentElm.parentNode, self.nodeIndex(parentElm) + 1);
4605 aft = r.extractContents();
4607 // Insert before chunk
4608 pa = parentElm.parentNode;
4609 pa.insertBefore(trimNode(bef), parentElm);
4611 // Insert middle chunk
4612 if (replacementElm) {
4613 pa.replaceChild(replacementElm, splitElm);
4615 pa.insertBefore(splitElm, parentElm);
4618 // Insert after chunk
4619 pa.insertBefore(trimNode(aft), parentElm);
4620 self.remove(parentElm);
4622 return replacementElm || splitElm;
4627 * Adds an event handler to the specified object.
4630 * @param {Element/Document/Window/Array/String} o Object or element id string to add event
4631 * handler to or an array of elements/ids/documents.
4632 * @param {String} n Name of event handler to add, for example: click.
4633 * @param {function} f Function to execute when the event occurs.
4634 * @param {Object} s Optional scope to execute the function in.
4635 * @return {function} Function callback handler the same as the one passed in.
4637 bind: function(target, name, func, scope) {
4638 return this.events.bind(target, name, func, scope || this);
4642 * Removes the specified event handler by name and function from an element or collection of elements.
4645 * @param {String/Element/Array} o Element ID string or HTML element or an array of elements or ids to remove handler from.
4646 * @param {String} n Event handler name, for example: "click"
4647 * @param {function} f Function to remove.
4648 * @return {bool/Array} Bool state of true if the handler was removed, or an array of states if multiple input elements
4651 unbind: function(target, name, func) {
4652 return this.events.unbind(target, name, func);
4656 * Fires the specified event name with object on target.
4659 * @param {Node/Document/Window} target Target element or object to fire event on.
4660 * @param {String} name Name of the event to fire.
4661 * @param {Object} evt Event object to send.
4662 * @return {Event} Event object.
4664 fire: function(target, name, evt) {
4665 return this.events.fire(target, name, evt);
4668 // Returns the content editable state of a node
4669 getContentEditable: function(node) {
4670 var contentEditable;
4673 if (node.nodeType != 1) {
4677 // Check for fake content editable
4678 contentEditable = node.getAttribute("data-mce-contenteditable");
4679 if (contentEditable && contentEditable !== "inherit") {
4680 return contentEditable;
4683 // Check for real content editable
4684 return node.contentEditable !== "inherit" ? node.contentEditable : null;
4688 * Destroys all internal references to the DOM to solve IE leak issues.
4692 destroy: function() {
4695 self.win = self.doc = self.root = self.events = self.frag = null;
4700 dumpRng: function(r) {
4702 'startContainer: ' + r.startContainer.nodeName +
4703 ', startOffset: ' + r.startOffset +
4704 ', endContainer: ' + r.endContainer.nodeName +
4705 ', endOffset: ' + r.endOffset
4711 _findSib: function(node, selector, name) {
4712 var self = this, func = selector;
4715 // If expression make a function of it using is
4716 if (typeof(func) == 'string') {
4717 func = function(node) {
4718 return self.is(node, selector);
4722 // Loop all siblings
4723 for (node = node[name]; node; node = node[name]) {
4735 * Instance of DOMUtils for the current document.
4739 * @type tinymce.dom.DOMUtils
4741 * // Example of how to add a class to some element by id
4742 * tinymce.DOM.addClass('someid', 'someclass');
4744 DOMUtils.DOM = new DOMUtils(document);
4749 // Included from: js/tinymce/classes/dom/ScriptLoader.js
4754 * Copyright, Moxiecode Systems AB
4755 * Released under LGPL License.
4757 * License: http://www.tinymce.com/license
4758 * Contributing: http://www.tinymce.com/contributing
4764 * This class handles asynchronous/synchronous loading of JavaScript files it will execute callbacks
4765 * when various items gets loaded. This class is useful to load external JavaScript files.
4767 * @class tinymce.dom.ScriptLoader
4769 * // Load a script from a specific URL using the global script loader
4770 * tinymce.ScriptLoader.load('somescript.js');
4772 * // Load a script using a unique instance of the script loader
4773 * var scriptLoader = new tinymce.dom.ScriptLoader();
4775 * scriptLoader.load('somescript.js');
4777 * // Load multiple scripts
4778 * var scriptLoader = new tinymce.dom.ScriptLoader();
4780 * scriptLoader.add('somescript1.js');
4781 * scriptLoader.add('somescript2.js');
4782 * scriptLoader.add('somescript3.js');
4784 * scriptLoader.loadQueue(function() {
4785 * alert('All scripts are now loaded.');
4788 define("tinymce/dom/ScriptLoader", [
4789 "tinymce/dom/DOMUtils",
4790 "tinymce/util/Tools"
4791 ], function(DOMUtils, Tools) {
4792 var DOM = DOMUtils.DOM;
4793 var each = Tools.each, grep = Tools.grep;
4795 function ScriptLoader() {
4801 scriptLoadedCallbacks = {},
4802 queueLoadedCallbacks = [],
4807 * Loads a specific script directly without adding it to the load queue.
4810 * @param {String} url Absolute URL to script to add.
4811 * @param {function} callback Optional callback function to execute ones this script gets loaded.
4812 * @param {Object} scope Optional scope to execute callback in.
4814 function loadScript(url, callback) {
4815 var dom = DOM, elm, id;
4817 // Execute callback when script is loaded
4822 elm.onreadystatechange = elm.onload = elm = null;
4829 // Report the error so it's easier for people to spot loading errors
4830 if (typeof(console) !== "undefined" && console.log) {
4831 console.log("Failed to load: " + url);
4834 // We can't mark it as done if there is a load error since
4835 // A) We don't want to produce 404 errors on the server and
4836 // B) the onerror event won't fire on all browsers.
4840 id = dom.uniqueId();
4842 // Create new script element
4843 elm = document.createElement('script');
4845 elm.type = 'text/javascript';
4848 // Seems that onreadystatechange works better on IE 10 onload seems to fire incorrectly
4849 if ("onreadystatechange" in elm) {
4850 elm.onreadystatechange = function() {
4851 if (/loaded|complete/.test(elm.readyState)) {
4859 // Add onerror event will get fired on some browsers but not all of them
4860 elm.onerror = error;
4862 // Add script to document
4863 (document.getElementsByTagName('head')[0] || document.body).appendChild(elm);
4867 * Returns true/false if a script has been loaded or not.
4870 * @param {String} url URL to check for.
4871 * @return {Boolean} true/false if the URL is loaded.
4873 this.isDone = function(url) {
4874 return states[url] == LOADED;
4878 * Marks a specific script to be loaded. This can be useful if a script got loaded outside
4879 * the script loader or to skip it from loading some script.
4882 * @param {string} u Absolute URL to the script to mark as loaded.
4884 this.markDone = function(url) {
4885 states[url] = LOADED;
4889 * Adds a specific script to the load queue of the script loader.
4892 * @param {String} url Absolute URL to script to add.
4893 * @param {function} callback Optional callback function to execute ones this script gets loaded.
4894 * @param {Object} scope Optional scope to execute callback in.
4896 this.add = this.load = function(url, callback, scope) {
4897 var state = states[url];
4899 // Add url to load queue
4900 if (state == undef) {
4902 states[url] = QUEUED;
4906 // Store away callback for later execution
4907 if (!scriptLoadedCallbacks[url]) {
4908 scriptLoadedCallbacks[url] = [];
4911 scriptLoadedCallbacks[url].push({
4913 scope: scope || this
4919 * Starts the loading of the queue.
4922 * @param {function} callback Optional callback to execute when all queued items are loaded.
4923 * @param {Object} scope Optional scope to execute the callback in.
4925 this.loadQueue = function(callback, scope) {
4926 this.loadScripts(queue, callback, scope);
4930 * Loads the specified queue of files and executes the callback ones they are loaded.
4931 * This method is generally not used outside this class but it might be useful in some scenarios.
4933 * @method loadScripts
4934 * @param {Array} scripts Array of queue items to load.
4935 * @param {function} callback Optional callback to execute ones all items are loaded.
4936 * @param {Object} scope Optional scope to execute callback in.
4938 this.loadScripts = function(scripts, callback, scope) {
4941 function execScriptLoadedCallbacks(url) {
4942 // Execute URL callback functions
4943 each(scriptLoadedCallbacks[url], function(callback) {
4944 callback.func.call(callback.scope);
4947 scriptLoadedCallbacks[url] = undef;
4950 queueLoadedCallbacks.push({
4952 scope: scope || this
4955 loadScripts = function() {
4956 var loadingScripts = grep(scripts);
4958 // Current scripts has been handled
4961 // Load scripts that needs to be loaded
4962 each(loadingScripts, function(url) {
4963 // Script is already loaded then execute script callbacks directly
4964 if (states[url] == LOADED) {
4965 execScriptLoadedCallbacks(url);
4969 // Is script not loading then start loading it
4970 if (states[url] != LOADING) {
4971 states[url] = LOADING;
4974 loadScript(url, function() {
4975 states[url] = LOADED;
4978 execScriptLoadedCallbacks(url);
4980 // Load more scripts if they where added by the recently loaded script
4986 // No scripts are currently loading then execute all pending queue loaded callbacks
4988 each(queueLoadedCallbacks, function(callback) {
4989 callback.func.call(callback.scope);
4992 queueLoadedCallbacks.length = 0;
5000 ScriptLoader.ScriptLoader = new ScriptLoader();
5002 return ScriptLoader;
5005 // Included from: js/tinymce/classes/AddOnManager.js
5010 * Copyright, Moxiecode Systems AB
5011 * Released under LGPL License.
5013 * License: http://www.tinymce.com/license
5014 * Contributing: http://www.tinymce.com/contributing
5018 * This class handles the loading of themes/plugins or other add-ons and their language packs.
5020 * @class tinymce.AddOnManager
5022 define("tinymce/AddOnManager", [
5023 "tinymce/dom/ScriptLoader",
5024 "tinymce/util/Tools"
5025 ], function(ScriptLoader, Tools) {
5026 var each = Tools.each;
5028 function AddOnManager() {
5036 AddOnManager.prototype = {
5038 * Returns the specified add on by the short name.
5041 * @param {String} name Add-on to look for.
5042 * @return {tinymce.Theme/tinymce.Plugin} Theme or plugin add-on instance or undefined.
5044 get: function(name) {
5045 if (this.lookup[name]) {
5046 return this.lookup[name].instance;
5052 dependencies: function(name) {
5055 if (this.lookup[name]) {
5056 result = this.lookup[name].dependencies;
5059 return result || [];
5063 * Loads a language pack for the specified add-on.
5065 * @method requireLangPack
5066 * @param {String} name Short name of the add-on.
5068 requireLangPack: function(name) {
5069 var settings = AddOnManager.settings;
5071 if (settings && settings.language && settings.language_load !== false) {
5072 ScriptLoader.ScriptLoader.add(this.urls[name] + '/langs/' + settings.language + '.js');
5077 * Adds a instance of the add-on by it's short name.
5080 * @param {String} id Short name/id for the add-on.
5081 * @param {tinymce.Theme/tinymce.Plugin} addOn Theme or plugin to add.
5082 * @return {tinymce.Theme/tinymce.Plugin} The same theme or plugin instance that got passed in.
5084 * // Create a simple plugin
5085 * tinymce.create('tinymce.plugins.TestPlugin', {
5086 * TestPlugin: function(ed, url) {
5087 * ed.on('click', function(e) {
5088 * ed.windowManager.alert('Hello World!');
5093 * // Register plugin using the add method
5094 * tinymce.PluginManager.add('test', tinymce.plugins.TestPlugin);
5096 * // Initialize TinyMCE
5099 * plugins: '-test' // Init the plugin but don't try to load it
5102 add: function(id, addOn, dependencies) {
5103 this.items.push(addOn);
5104 this.lookup[id] = {instance: addOn, dependencies: dependencies};
5109 createUrl: function(baseUrl, dep) {
5110 if (typeof dep === "object") {
5113 return {prefix: baseUrl.prefix, resource: dep, suffix: baseUrl.suffix};
5118 * Add a set of components that will make up the add-on. Using the url of the add-on name as the base url.
5119 * This should be used in development mode. A new compressor/javascript munger process will ensure that the
5120 * components are put together into the plugin.js file and compressed correctly.
5122 * @method addComponents
5123 * @param {String} pluginName name of the plugin to load scripts from (will be used to get the base url for the plugins).
5124 * @param {Array} scripts Array containing the names of the scripts to load.
5126 addComponents: function(pluginName, scripts) {
5127 var pluginUrl = this.urls[pluginName];
5129 each(scripts, function(script) {
5130 ScriptLoader.ScriptLoader.add(pluginUrl + "/" + script);
5135 * Loads an add-on from a specific url.
5138 * @param {String} n Short name of the add-on that gets loaded.
5139 * @param {String} u URL to the add-on that will get loaded.
5140 * @param {function} cb Optional callback to execute ones the add-on is loaded.
5141 * @param {Object} s Optional scope to execute the callback in.
5143 * // Loads a plugin from an external URL
5144 * tinymce.PluginManager.load('myplugin', '/some/dir/someplugin/plugin.js');
5146 * // Initialize TinyMCE
5149 * plugins: '-myplugin' // Don't try to load it again
5152 load: function(n, u, cb, s) {
5153 var t = this, url = u;
5155 function loadDependencies() {
5156 var dependencies = t.dependencies(n);
5158 each(dependencies, function(dep) {
5159 var newUrl = t.createUrl(u, dep);
5161 t.load(newUrl.resource, newUrl, undefined, undefined);
5168 cb.call(ScriptLoader);
5177 if (typeof u === "object") {
5178 url = u.prefix + u.resource + u.suffix;
5181 if (url.indexOf('/') !== 0 && url.indexOf('://') == -1) {
5182 url = AddOnManager.baseURL + '/' + url;
5185 t.urls[n] = url.substring(0, url.lastIndexOf('/'));
5190 ScriptLoader.ScriptLoader.add(url, loadDependencies, s);
5195 AddOnManager.PluginManager = new AddOnManager();
5196 AddOnManager.ThemeManager = new AddOnManager();
5198 return AddOnManager;
5202 * TinyMCE theme class.
5204 * @class tinymce.Theme
5208 * This method is responsible for rendering/generating the overall user interface with toolbars, buttons, iframe containers etc.
5211 * @param {Object} obj Object parameter containing the targetNode DOM node that will be replaced visually with an editor instance.
5212 * @return {Object} an object with items like iframeContainer, editorContainer, sizeContainer, deltaWidth, deltaHeight.
5216 * Plugin base class, this is a pseudo class that describes how a plugin is to be created for TinyMCE. The methods below are all optional.
5218 * @class tinymce.Plugin
5220 * tinymce.PluginManager.add('example', function(editor, url) {
5221 * // Add a button that opens a window
5222 * editor.addButton('example', {
5223 * text: 'My button',
5225 * onclick: function() {
5227 * editor.windowManager.open({
5228 * title: 'Example plugin',
5230 * {type: 'textbox', name: 'title', label: 'Title'}
5232 * onsubmit: function(e) {
5233 * // Insert content when the window form is submitted
5234 * editor.insertContent('Title: ' + e.data.title);
5240 * // Adds a menu item to the tools menu
5241 * editor.addMenuItem('example', {
5242 * text: 'Example plugin',
5244 * onclick: function() {
5245 * // Open window with a specific url
5246 * editor.windowManager.open({
5247 * title: 'TinyMCE site',
5248 * url: 'http://www.tinymce.com',
5261 // Included from: js/tinymce/classes/html/Node.js
5266 * Copyright, Moxiecode Systems AB
5267 * Released under LGPL License.
5269 * License: http://www.tinymce.com/license
5270 * Contributing: http://www.tinymce.com/contributing
5274 * This class is a minimalistic implementation of a DOM like node used by the DomParser class.
5277 * var node = new tinymce.html.Node('strong', 1);
5278 * someRoot.append(node);
5280 * @class tinymce.html.Node
5283 define("tinymce/html/Node", [], function() {
5284 var whiteSpaceRegExp = /^[ \t\r\n]*$/, typeLookup = {
5290 '#document-fragment': 11
5293 // Walks the tree left/right
5294 function walk(node, root_node, prev) {
5295 var sibling, parent, startName = prev ? 'lastChild' : 'firstChild', siblingName = prev ? 'prev' : 'next';
5297 // Walk into nodes if it has a start
5298 if (node[startName]) {
5299 return node[startName];
5302 // Return the sibling if it has one
5303 if (node !== root_node) {
5304 sibling = node[siblingName];
5310 // Walk up the parents to look for siblings
5311 for (parent = node.parent; parent && parent !== root_node; parent = parent.parent) {
5312 sibling = parent[siblingName];
5322 * Constructs a new Node instance.
5326 * @param {String} name Name of the node type.
5327 * @param {Number} type Numeric type representing the node.
5329 function Node(name, type) {
5334 this.attributes = [];
5335 this.attributes.map = {};
5341 * Replaces the current node with the specified one.
5344 * someNode.replace(someNewNode);
5347 * @param {tinymce.html.Node} node Node to replace the current node with.
5348 * @return {tinymce.html.Node} The old node that got replaced.
5350 replace: function(node) {
5357 self.insert(node, self);
5364 * Gets/sets or removes an attribute by name.
5367 * someNode.attr("name", "value"); // Sets an attribute
5368 * console.log(someNode.attr("name")); // Gets an attribute
5369 * someNode.attr("name", null); // Removes an attribute
5372 * @param {String} name Attribute name to set or get.
5373 * @param {String} value Optional value to set.
5374 * @return {String/tinymce.html.Node} String or undefined on a get operation or the current node on a set operation.
5376 attr: function(name, value) {
5377 var self = this, attrs, i, undef;
5379 if (typeof name !== "string") {
5381 self.attr(i, name[i]);
5387 if ((attrs = self.attributes)) {
5388 if (value !== undef) {
5390 if (value === null) {
5391 if (name in attrs.map) {
5392 delete attrs.map[name];
5396 if (attrs[i].name === name) {
5397 attrs = attrs.splice(i, 1);
5407 if (name in attrs.map) {
5411 if (attrs[i].name === name) {
5412 attrs[i].value = value;
5417 attrs.push({name: name, value: value});
5420 attrs.map[name] = value;
5424 return attrs.map[name];
5430 * Does a shallow clones the node into a new node. It will also exclude id attributes since
5431 * there should only be one id per document.
5434 * var clonedNode = node.clone();
5437 * @return {tinymce.html.Node} New copy of the original node.
5440 var self = this, clone = new Node(self.name, self.type), i, l, selfAttrs, selfAttr, cloneAttrs;
5442 // Clone element attributes
5443 if ((selfAttrs = self.attributes)) {
5445 cloneAttrs.map = {};
5447 for (i = 0, l = selfAttrs.length; i < l; i++) {
5448 selfAttr = selfAttrs[i];
5450 // Clone everything except id
5451 if (selfAttr.name !== 'id') {
5452 cloneAttrs[cloneAttrs.length] = {name: selfAttr.name, value: selfAttr.value};
5453 cloneAttrs.map[selfAttr.name] = selfAttr.value;
5457 clone.attributes = cloneAttrs;
5460 clone.value = self.value;
5461 clone.shortEnded = self.shortEnded;
5467 * Wraps the node in in another node.
5470 * node.wrap(wrapperNode);
5474 wrap: function(wrapper) {
5477 self.parent.insert(wrapper, self);
5478 wrapper.append(self);
5484 * Unwraps the node in other words it removes the node but keeps the children.
5491 unwrap: function() {
5492 var self = this, node, next;
5494 for (node = self.firstChild; node; ) {
5496 self.insert(node, self, true);
5504 * Removes the node from it's parent.
5510 * @return {tinymce.html.Node} Current node that got removed.
5512 remove: function() {
5513 var self = this, parent = self.parent, next = self.next, prev = self.prev;
5516 if (parent.firstChild === self) {
5517 parent.firstChild = next;
5526 if (parent.lastChild === self) {
5527 parent.lastChild = prev;
5536 self.parent = self.next = self.prev = null;
5543 * Appends a new node as a child of the current node.
5546 * node.append(someNode);
5549 * @param {tinymce.html.Node} node Node to append as a child of the current one.
5550 * @return {tinymce.html.Node} The node that got appended.
5552 append: function(node) {
5553 var self = this, last;
5559 last = self.lastChild;
5563 self.lastChild = node;
5565 self.lastChild = self.firstChild = node;
5574 * Inserts a node at a specific position as a child of the current node.
5577 * parentNode.insert(newChildNode, oldChildNode);
5580 * @param {tinymce.html.Node} node Node to insert as a child of the current node.
5581 * @param {tinymce.html.Node} ref_node Reference node to set node before/after.
5582 * @param {Boolean} before Optional state to insert the node before the reference node.
5583 * @return {tinymce.html.Node} The node that got inserted.
5585 insert: function(node, ref_node, before) {
5592 parent = ref_node.parent || this;
5595 if (ref_node === parent.firstChild) {
5596 parent.firstChild = node;
5598 ref_node.prev.next = node;
5601 node.prev = ref_node.prev;
5602 node.next = ref_node;
5603 ref_node.prev = node;
5605 if (ref_node === parent.lastChild) {
5606 parent.lastChild = node;
5608 ref_node.next.prev = node;
5611 node.next = ref_node.next;
5612 node.prev = ref_node;
5613 ref_node.next = node;
5616 node.parent = parent;
5622 * Get all children by name.
5625 * @param {String} name Name of the child nodes to collect.
5626 * @return {Array} Array with child nodes matchin the specified name.
5628 getAll: function(name) {
5629 var self = this, node, collection = [];
5631 for (node = self.firstChild; node; node = walk(node, self)) {
5632 if (node.name === name) {
5633 collection.push(node);
5641 * Removes all children of the current node.
5644 * @return {tinymce.html.Node} The current node that got cleared.
5647 var self = this, nodes, i, node;
5649 // Remove all children
5650 if (self.firstChild) {
5653 // Collect the children
5654 for (node = self.firstChild; node; node = walk(node, self)) {
5658 // Remove the children
5662 node.parent = node.firstChild = node.lastChild = node.next = node.prev = null;
5666 self.firstChild = self.lastChild = null;
5672 * Returns true/false if the node is to be considered empty or not.
5675 * node.isEmpty({img: true});
5677 * @param {Object} elements Name/value object with elements that are automatically treated as non empty elements.
5678 * @return {Boolean} true/false if the node is empty or not.
5680 isEmpty: function(elements) {
5681 var self = this, node = self.firstChild, i, name;
5685 if (node.type === 1) {
5686 // Ignore bogus elements
5687 if (node.attributes.map['data-mce-bogus']) {
5691 // Keep empty elements like <img />
5692 if (elements[node.name]) {
5696 // Keep elements with data attributes or name attribute like <a name="1"></a>
5697 i = node.attributes.length;
5699 name = node.attributes[i].name;
5700 if (name === "name" || name.indexOf('data-mce-') === 0) {
5707 if (node.type === 8) {
5711 // Keep non whitespace text nodes
5712 if ((node.type === 3 && !whiteSpaceRegExp.test(node.value))) {
5715 } while ((node = walk(node, self)));
5722 * Walks to the next or previous node and returns that node or null if it wasn't found.
5725 * @param {Boolean} prev Optional previous node state defaults to false.
5726 * @return {tinymce.html.Node} Node that is next to or previous of the current node.
5728 walk: function(prev) {
5729 return walk(this, null, prev);
5734 * Creates a node of a specific type.
5738 * @param {String} name Name of the node type to create for example "b" or "#text".
5739 * @param {Object} attrs Name/value collection of attributes that will be applied to elements.
5741 Node.create = function(name, attrs) {
5745 node = new Node(name, typeLookup[name] || 1);
5747 // Add attributes if needed
5749 for (attrName in attrs) {
5750 node.attr(attrName, attrs[attrName]);
5760 // Included from: js/tinymce/classes/html/Schema.js
5765 * Copyright, Moxiecode Systems AB
5766 * Released under LGPL License.
5768 * License: http://www.tinymce.com/license
5769 * Contributing: http://www.tinymce.com/contributing
5773 * Schema validator class.
5775 * @class tinymce.html.Schema
5777 * if (tinymce.activeEditor.schema.isValidChild('p', 'span'))
5778 * alert('span is valid child of p.');
5780 * if (tinymce.activeEditor.schema.getElementRule('p'))
5781 * alert('P is a valid element.');
5783 * @class tinymce.html.Schema
5786 define("tinymce/html/Schema", [
5787 "tinymce/util/Tools"
5788 ], function(Tools) {
5790 var makeMap = Tools.makeMap, each = Tools.each, extend = Tools.extend, explode = Tools.explode, inArray = Tools.inArray;
5792 function split(items, delim) {
5793 return items ? items.split(delim || ' ') : [];
5797 * Builds a schema lookup table
5800 * @param {String} type html4, html5 or html5-strict schema type.
5801 * @return {Object} Schema lookup table.
5803 function compileSchema(type) {
5804 var schema = {}, globalAttributes, eventAttributes, blockContent;
5805 var phrasingContent, flowContent, html4BlockContent, html4PhrasingContent;
5807 function add(name, attributes, children) {
5808 var ni, i, attributesOrder, args = arguments;
5810 function arrayToMap(array) {
5813 for (i = 0, l = array.length; i < l; i++) {
5820 children = children || [];
5821 attributes = attributes || "";
5823 if (typeof(children) === "string") {
5824 children = split(children);
5827 // Split string children
5828 for (i = 3; i < args.length; i++) {
5829 if (typeof(args[i]) === "string") {
5830 args[i] = split(args[i]);
5833 children.push.apply(children, args[i]);
5839 attributesOrder = [].concat(globalAttributes, split(attributes));
5840 schema[name[ni]] = {
5841 attributes: arrayToMap(attributesOrder),
5842 attributesOrder: attributesOrder,
5843 children: arrayToMap(children)
5848 function addAttrs(name, attributes) {
5849 var ni, schemaItem, i, l;
5853 attributes = split(attributes);
5855 schemaItem = schema[name[ni]];
5856 for (i = 0, l = attributes.length; i < l; i++) {
5857 schemaItem.attributes[attributes[i]] = {};
5858 schemaItem.attributesOrder.push(attributes[i]);
5863 // Use cached schema
5864 if (mapCache[type]) {
5865 return mapCache[type];
5868 // Attributes present on all elements
5869 globalAttributes = split("id accesskey class dir lang style tabindex title");
5871 // Event attributes can be opt-in/opt-out
5872 eventAttributes = split("onabort onblur oncancel oncanplay oncanplaythrough onchange onclick onclose oncontextmenu oncuechange " +
5873 "ondblclick ondrag ondragend ondragenter ondragleave ondragover ondragstart ondrop ondurationchange onemptied onended " +
5874 "onerror onfocus oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata onloadedmetadata onloadstart " +
5875 "onmousedown onmousemove onmouseout onmouseover onmouseup onmousewheel onpause onplay onplaying onprogress onratechange " +
5876 "onreset onscroll onseeked onseeking onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate onvolumechange " +
5880 // Block content elements
5881 blockContent = split(
5882 "address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul"
5885 // Phrasing content elements from the HTML5 spec (inline)
5886 phrasingContent = split(
5887 "a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd " +
5888 "label map noscript object q s samp script select small span strong sub sup " +
5889 "textarea u var #text #comment"
5892 // Add HTML5 items to globalAttributes, blockContent, phrasingContent
5893 if (type != "html4") {
5894 globalAttributes.push.apply(globalAttributes, split("contenteditable contextmenu draggable dropzone " +
5895 "hidden spellcheck translate"));
5896 blockContent.push.apply(blockContent, split("article aside details dialog figure header footer hgroup section nav"));
5897 phrasingContent.push.apply(phrasingContent, split("audio canvas command datalist mark meter output progress time wbr " +
5898 "video ruby bdi keygen"));
5901 // Add HTML4 elements unless it's html5-strict
5902 if (type != "html5-strict") {
5903 globalAttributes.push("xml:lang");
5905 html4PhrasingContent = split("acronym applet basefont big font strike tt");
5906 phrasingContent.push.apply(phrasingContent, html4PhrasingContent);
5908 each(html4PhrasingContent, function(name) {
5909 add(name, "", phrasingContent);
5912 html4BlockContent = split("center dir isindex noframes");
5913 blockContent.push.apply(blockContent, html4BlockContent);
5915 // Flow content elements from the HTML5 spec (block+inline)
5916 flowContent = [].concat(blockContent, phrasingContent);
5918 each(html4BlockContent, function(name) {
5919 add(name, "", flowContent);
5923 // Flow content elements from the HTML5 spec (block+inline)
5924 flowContent = flowContent || [].concat(blockContent, phrasingContent);
5926 // HTML4 base schema TODO: Move HTML5 specific attributes to HTML5 specific if statement
5927 // Schema items <element name>, <specific attributes>, <children ..>
5928 add("html", "manifest", "head body");
5929 add("head", "", "base command link meta noscript script style title");
5930 add("title hr noscript br");
5931 add("base", "href target");
5932 add("link", "href rel media hreflang type sizes hreflang");
5933 add("meta", "name http-equiv content charset");
5934 add("style", "media type scoped");
5935 add("script", "src async defer type charset");
5936 add("body", "onafterprint onbeforeprint onbeforeunload onblur onerror onfocus " +
5937 "onhashchange onload onmessage onoffline ononline onpagehide onpageshow " +
5938 "onpopstate onresize onscroll onstorage onunload", flowContent);
5939 add("address dt dd div caption", "", flowContent);
5940 add("h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn", "", phrasingContent);
5941 add("blockquote", "cite", flowContent);
5942 add("ol", "reversed start type", "li");
5943 add("ul", "", "li");
5944 add("li", "value", flowContent);
5945 add("dl", "", "dt dd");
5946 add("a", "href target rel media hreflang type", phrasingContent);
5947 add("q", "cite", phrasingContent);
5948 add("ins del", "cite datetime", flowContent);
5949 add("img", "src alt usemap ismap width height");
5950 add("iframe", "src name width height", flowContent);
5951 add("embed", "src type width height");
5952 add("object", "data type typemustmatch name usemap form width height", flowContent, "param");
5953 add("param", "name value");
5954 add("map", "name", flowContent, "area");
5955 add("area", "alt coords shape href target rel media hreflang type");
5956 add("table", "border", "caption colgroup thead tfoot tbody tr" + (type == "html4" ? " col" : ""));
5957 add("colgroup", "span", "col");
5959 add("tbody thead tfoot", "", "tr");
5960 add("tr", "", "td th");
5961 add("td", "colspan rowspan headers", flowContent);
5962 add("th", "colspan rowspan headers scope abbr", flowContent);
5963 add("form", "accept-charset action autocomplete enctype method name novalidate target", flowContent);
5964 add("fieldset", "disabled form name", flowContent, "legend");
5965 add("label", "form for", phrasingContent);
5966 add("input", "accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate " +
5967 "formtarget height list max maxlength min multiple name pattern readonly required size src step type value width"
5969 add("button", "disabled form formaction formenctype formmethod formnovalidate formtarget name type value",
5970 type == "html4" ? flowContent : phrasingContent);
5971 add("select", "disabled form multiple name required size", "option optgroup");
5972 add("optgroup", "disabled label", "option");
5973 add("option", "disabled label selected value");
5974 add("textarea", "cols dirname disabled form maxlength name readonly required rows wrap");
5975 add("menu", "type label", flowContent, "li");
5976 add("noscript", "", flowContent);
5978 // Extend with HTML5 elements
5979 if (type != "html4") {
5981 add("ruby", "", phrasingContent, "rt rp");
5982 add("figcaption", "", flowContent);
5983 add("mark rt rp summary bdi", "", phrasingContent);
5984 add("canvas", "width height", flowContent);
5985 add("video", "src crossorigin poster preload autoplay mediagroup loop " +
5986 "muted controls width height", flowContent, "track source");
5987 add("audio", "src crossorigin preload autoplay mediagroup loop muted controls", flowContent, "track source");
5988 add("source", "src type media");
5989 add("track", "kind src srclang label default");
5990 add("datalist", "", phrasingContent, "option");
5991 add("article section nav aside header footer", "", flowContent);
5992 add("hgroup", "", "h1 h2 h3 h4 h5 h6");
5993 add("figure", "", flowContent, "figcaption");
5994 add("time", "datetime", phrasingContent);
5995 add("dialog", "open", flowContent);
5996 add("command", "type label icon disabled checked radiogroup command");
5997 add("output", "for form name", phrasingContent);
5998 add("progress", "value max", phrasingContent);
5999 add("meter", "value min max low high optimum", phrasingContent);
6000 add("details", "open", flowContent, "summary");
6001 add("keygen", "autofocus challenge disabled form keytype name");
6004 // Extend with HTML4 attributes unless it's html5-strict
6005 if (type != "html5-strict") {
6006 addAttrs("script", "language xml:space");
6007 addAttrs("style", "xml:space");
6008 addAttrs("object", "declare classid codebase codetype archive standby align border hspace vspace");
6009 addAttrs("param", "valuetype type");
6010 addAttrs("a", "charset name rev shape coords");
6011 addAttrs("br", "clear");
6012 addAttrs("applet", "codebase archive code object alt name width height align hspace vspace");
6013 addAttrs("img", "name longdesc align border hspace vspace");
6014 addAttrs("iframe", "longdesc frameborder marginwidth marginheight scrolling align");
6015 addAttrs("font basefont", "size color face");
6016 addAttrs("input", "usemap align");
6017 addAttrs("select", "onchange");
6018 addAttrs("textarea");
6019 addAttrs("h1 h2 h3 h4 h5 h6 div p legend caption", "align");
6020 addAttrs("ul", "type compact");
6021 addAttrs("li", "type");
6022 addAttrs("ol dl menu dir", "compact");
6023 addAttrs("pre", "width xml:space");
6024 addAttrs("hr", "align noshade size width");
6025 addAttrs("isindex", "prompt");
6026 addAttrs("table", "summary width frame rules cellspacing cellpadding align bgcolor");
6027 addAttrs("col", "width align char charoff valign");
6028 addAttrs("colgroup", "width align char charoff valign");
6029 addAttrs("thead", "align char charoff valign");
6030 addAttrs("tr", "align char charoff valign bgcolor");
6031 addAttrs("th", "axis align char charoff valign nowrap bgcolor width height");
6032 addAttrs("form", "accept");
6033 addAttrs("td", "abbr axis scope align char charoff valign nowrap bgcolor width height");
6034 addAttrs("tfoot", "align char charoff valign");
6035 addAttrs("tbody", "align char charoff valign");
6036 addAttrs("area", "nohref");
6037 addAttrs("body", "background bgcolor text link vlink alink");
6040 // Extend with HTML5 attributes unless it's html4
6041 if (type != "html4") {
6042 addAttrs("input button select textarea", "autofocus");
6043 addAttrs("input textarea", "placeholder");
6044 addAttrs("a", "download");
6045 addAttrs("link script img", "crossorigin");
6046 addAttrs("iframe", "srcdoc sandbox seamless allowfullscreen");
6049 // Special: iframe, ruby, video, audio, label
6051 // Delete children of the same name from it's parent
6052 // For example: form can't have a child of the name form
6053 each(split('a form meter progress dfn'), function(name) {
6055 delete schema[name].children[name];
6059 // Delete header, footer, sectioning and heading content descendants
6060 /*each('dt th address', function(name) {
6061 delete schema[name].children[name];
6064 // Caption can't have tables
6065 delete schema.caption.children.table;
6067 // TODO: LI:s can only have value if parent is OL
6069 // TODO: Handle transparent elements
6070 // a ins del canvas map
6072 mapCache[type] = schema;
6078 * Constructs a new Schema instance.
6082 * @param {Object} settings Name/value settings object.
6084 return function(settings) {
6085 var self = this, elements = {}, children = {}, patternElements = [], validStyles, schemaItems;
6086 var whiteSpaceElementsMap, selfClosingElementsMap, shortEndedElementsMap, boolAttrMap;
6087 var blockElementsMap, nonEmptyElementsMap, textBlockElementsMap, customElementsMap = {}, specialElements = {};
6089 // Creates an lookup table map object for the specified option or the default value
6090 function createLookupTable(option, default_value, extendWith) {
6091 var value = settings[option];
6094 // Get cached default map or make it if needed
6095 value = mapCache[option];
6098 value = makeMap(default_value, ' ', makeMap(default_value.toUpperCase(), ' '));
6099 value = extend(value, extendWith);
6101 mapCache[option] = value;
6104 // Create custom map
6105 value = makeMap(value, ',', makeMap(value.toUpperCase(), ' '));
6111 settings = settings || {};
6112 schemaItems = compileSchema(settings.schema);
6114 // Allow all elements and attributes if verify_html is set to false
6115 if (settings.verify_html === false) {
6116 settings.valid_elements = '*[*]';
6119 // Build styles list
6120 if (settings.valid_styles) {
6123 // Convert styles into a rule list
6124 each(settings.valid_styles, function(value, key) {
6125 validStyles[key] = explode(value);
6129 // Setup map objects
6130 whiteSpaceElementsMap = createLookupTable('whitespace_elements', 'pre script noscript style textarea video audio iframe object');
6131 selfClosingElementsMap = createLookupTable('self_closing_elements', 'colgroup dd dt li option p td tfoot th thead tr');
6132 shortEndedElementsMap = createLookupTable('short_ended_elements', 'area base basefont br col frame hr img input isindex link ' +
6133 'meta param embed source wbr track');
6134 boolAttrMap = createLookupTable('boolean_attributes', 'checked compact declare defer disabled ismap multiple nohref noresize ' +
6135 'noshade nowrap readonly selected autoplay loop controls');
6136 nonEmptyElementsMap = createLookupTable('non_empty_elements', 'td th iframe video audio object', shortEndedElementsMap);
6137 textBlockElementsMap = createLookupTable('text_block_elements', 'h1 h2 h3 h4 h5 h6 p div address pre form ' +
6138 'blockquote center dir fieldset header footer article section hgroup aside nav figure');
6139 blockElementsMap = createLookupTable('block_elements', 'hr table tbody thead tfoot ' +
6140 'th tr td li ol ul caption dl dt dd noscript menu isindex samp option ' +
6141 'datalist select optgroup', textBlockElementsMap);
6143 each((settings.special || 'script noscript style textarea').split(' '), function(name) {
6144 specialElements[name] = new RegExp('<\/' + name + '[^>]*>','gi');
6147 // Converts a wildcard expression string to a regexp for example *a will become /.*a/.
6148 function patternToRegExp(str) {
6149 return new RegExp('^' + str.replace(/([?+*])/g, '.$1') + '$');
6152 // Parses the specified valid_elements string and adds to the current rules
6153 // This function is a bit hard to read since it's heavily optimized for speed
6154 function addValidElements(valid_elements) {
6155 var ei, el, ai, al, matches, element, attr, attrData, elementName, attrName, attrType, attributes, attributesOrder,
6156 prefix, outputName, globalAttributes, globalAttributesOrder, key, value,
6157 elementRuleRegExp = /^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)\])?$/,
6158 attrRuleRegExp = /^([!\-])?(\w+::\w+|[^=:<]+)?(?:([=:<])(.*))?$/,
6159 hasPatternsRegExp = /[*?+]/;
6161 if (valid_elements) {
6162 // Split valid elements into an array with rules
6163 valid_elements = split(valid_elements, ',');
6165 if (elements['@']) {
6166 globalAttributes = elements['@'].attributes;
6167 globalAttributesOrder = elements['@'].attributesOrder;
6171 for (ei = 0, el = valid_elements.length; ei < el; ei++) {
6172 // Parse element rule
6173 matches = elementRuleRegExp.exec(valid_elements[ei]);
6175 // Setup local names for matches
6176 prefix = matches[1];
6177 elementName = matches[2];
6178 outputName = matches[3];
6179 attrData = matches[5];
6181 // Create new attributes and attributesOrder
6183 attributesOrder = [];
6185 // Create the new element
6187 attributes: attributes,
6188 attributesOrder: attributesOrder
6191 // Padd empty elements prefix
6192 if (prefix === '#') {
6193 element.paddEmpty = true;
6196 // Remove empty elements prefix
6197 if (prefix === '-') {
6198 element.removeEmpty = true;
6201 if (matches[4] === '!') {
6202 element.removeEmptyAttrs = true;
6205 // Copy attributes from global rule into current rule
6206 if (globalAttributes) {
6207 for (key in globalAttributes) {
6208 attributes[key] = globalAttributes[key];
6211 attributesOrder.push.apply(attributesOrder, globalAttributesOrder);
6214 // Attributes defined
6216 attrData = split(attrData, '|');
6217 for (ai = 0, al = attrData.length; ai < al; ai++) {
6218 matches = attrRuleRegExp.exec(attrData[ai]);
6221 attrType = matches[1];
6222 attrName = matches[2].replace(/::/g, ':');
6223 prefix = matches[3];
6227 if (attrType === '!') {
6228 element.attributesRequired = element.attributesRequired || [];
6229 element.attributesRequired.push(attrName);
6230 attr.required = true;
6233 // Denied from global
6234 if (attrType === '-') {
6235 delete attributes[attrName];
6236 attributesOrder.splice(inArray(attributesOrder, attrName), 1);
6243 if (prefix === '=') {
6244 element.attributesDefault = element.attributesDefault || [];
6245 element.attributesDefault.push({name: attrName, value: value});
6246 attr.defaultValue = value;
6250 if (prefix === ':') {
6251 element.attributesForced = element.attributesForced || [];
6252 element.attributesForced.push({name: attrName, value: value});
6253 attr.forcedValue = value;
6257 if (prefix === '<') {
6258 attr.validValues = makeMap(value, '?');
6262 // Check for attribute patterns
6263 if (hasPatternsRegExp.test(attrName)) {
6264 element.attributePatterns = element.attributePatterns || [];
6265 attr.pattern = patternToRegExp(attrName);
6266 element.attributePatterns.push(attr);
6268 // Add attribute to order list if it doesn't already exist
6269 if (!attributes[attrName]) {
6270 attributesOrder.push(attrName);
6273 attributes[attrName] = attr;
6279 // Global rule, store away these for later usage
6280 if (!globalAttributes && elementName == '@') {
6281 globalAttributes = attributes;
6282 globalAttributesOrder = attributesOrder;
6285 // Handle substitute elements such as b/strong
6287 element.outputName = elementName;
6288 elements[outputName] = element;
6291 // Add pattern or exact element
6292 if (hasPatternsRegExp.test(elementName)) {
6293 element.pattern = patternToRegExp(elementName);
6294 patternElements.push(element);
6296 elements[elementName] = element;
6303 function setValidElements(valid_elements) {
6305 patternElements = [];
6307 addValidElements(valid_elements);
6309 each(schemaItems, function(element, name) {
6310 children[name] = element.children;
6314 // Adds custom non HTML elements to the schema
6315 function addCustomElements(custom_elements) {
6316 var customElementRegExp = /^(~)?(.+)$/;
6318 if (custom_elements) {
6319 each(split(custom_elements, ','), function(rule) {
6320 var matches = customElementRegExp.exec(rule),
6321 inline = matches[1] === '~',
6322 cloneName = inline ? 'span' : 'div',
6325 children[name] = children[cloneName];
6326 customElementsMap[name] = cloneName;
6328 // If it's not marked as inline then add it to valid block elements
6330 blockElementsMap[name.toUpperCase()] = {};
6331 blockElementsMap[name] = {};
6334 // Add elements clone if needed
6335 if (!elements[name]) {
6336 var customRule = elements[cloneName];
6338 customRule = extend({}, customRule);
6339 delete customRule.removeEmptyAttrs;
6340 delete customRule.removeEmpty;
6342 elements[name] = customRule;
6345 // Add custom elements at span/div positions
6346 each(children, function(element) {
6347 if (element[cloneName]) {
6348 element[name] = element[cloneName];
6355 // Adds valid children to the schema object
6356 function addValidChildren(valid_children) {
6357 var childRuleRegExp = /^([+\-]?)(\w+)\[([^\]]+)\]$/;
6359 if (valid_children) {
6360 each(split(valid_children, ','), function(rule) {
6361 var matches = childRuleRegExp.exec(rule), parent, prefix;
6364 prefix = matches[1];
6366 // Add/remove items from default
6368 parent = children[matches[2]];
6370 parent = children[matches[2]] = {'#comment': {}};
6373 parent = children[matches[2]];
6375 each(split(matches[3], '|'), function(child) {
6376 if (prefix === '-') {
6377 delete parent[child];
6387 function getElementRule(name) {
6388 var element = elements[name], i;
6390 // Exact match found
6395 // No exact match then try the patterns
6396 i = patternElements.length;
6398 element = patternElements[i];
6400 if (element.pattern.test(name)) {
6406 if (!settings.valid_elements) {
6407 // No valid elements defined then clone the elements from the schema spec
6408 each(schemaItems, function(element, name) {
6410 attributes: element.attributes,
6411 attributesOrder: element.attributesOrder
6414 children[name] = element.children;
6417 // Switch these on HTML4
6418 if (settings.schema != "html5") {
6419 each(split('strong/b em/i'), function(item) {
6420 item = split(item, '/');
6421 elements[item[1]].outputName = item[0];
6425 // Add default alt attribute for images
6426 elements.img.attributesDefault = [{name: 'alt', value: ''}];
6428 // Remove these if they are empty by default
6429 each(split('ol ul sub sup blockquote span font a table tbody tr strong em b i'), function(name) {
6430 if (elements[name]) {
6431 elements[name].removeEmpty = true;
6435 // Padd these by default
6436 each(split('p h1 h2 h3 h4 h5 h6 th td pre div address caption'), function(name) {
6437 elements[name].paddEmpty = true;
6440 // Remove these if they have no attributes
6441 each(split('span'), function(name) {
6442 elements[name].removeEmptyAttrs = true;
6445 setValidElements(settings.valid_elements);
6448 addCustomElements(settings.custom_elements);
6449 addValidChildren(settings.valid_children);
6450 addValidElements(settings.extended_valid_elements);
6452 // Todo: Remove this when we fix list handling to be valid
6453 addValidChildren('+ol[ul|ol],+ul[ul|ol]');
6455 // Delete invalid elements
6456 if (settings.invalid_elements) {
6457 each(explode(settings.invalid_elements), function(item) {
6458 if (elements[item]) {
6459 delete elements[item];
6464 // If the user didn't allow span only allow internal spans
6465 if (!getElementRule('span')) {
6466 addValidElements('span[!data-mce-type|*]');
6470 * Name/value map object with valid parents and children to those parents.
6479 self.children = children;
6482 * Name/value map object with valid styles for each element.
6487 self.styles = validStyles;
6490 * Returns a map with boolean attributes.
6492 * @method getBoolAttrs
6493 * @return {Object} Name/value lookup map for boolean attributes.
6495 self.getBoolAttrs = function() {
6500 * Returns a map with block elements.
6502 * @method getBlockElements
6503 * @return {Object} Name/value lookup map for block elements.
6505 self.getBlockElements = function() {
6506 return blockElementsMap;
6510 * Returns a map with text block elements. Such as: p,h1-h6,div,address
6512 * @method getTextBlockElements
6513 * @return {Object} Name/value lookup map for block elements.
6515 self.getTextBlockElements = function() {
6516 return textBlockElementsMap;
6520 * Returns a map with short ended elements such as BR or IMG.
6522 * @method getShortEndedElements
6523 * @return {Object} Name/value lookup map for short ended elements.
6525 self.getShortEndedElements = function() {
6526 return shortEndedElementsMap;
6530 * Returns a map with self closing tags such as <li>.
6532 * @method getSelfClosingElements
6533 * @return {Object} Name/value lookup map for self closing tags elements.
6535 self.getSelfClosingElements = function() {
6536 return selfClosingElementsMap;
6540 * Returns a map with elements that should be treated as contents regardless if it has text
6541 * content in them or not such as TD, VIDEO or IMG.
6543 * @method getNonEmptyElements
6544 * @return {Object} Name/value lookup map for non empty elements.
6546 self.getNonEmptyElements = function() {
6547 return nonEmptyElementsMap;
6551 * Returns a map with elements where white space is to be preserved like PRE or SCRIPT.
6553 * @method getWhiteSpaceElements
6554 * @return {Object} Name/value lookup map for white space elements.
6556 self.getWhiteSpaceElements = function() {
6557 return whiteSpaceElementsMap;
6561 * Returns a map with special elements. These are elements that needs to be parsed
6562 * in a special way such as script, style, textarea etc. The map object values
6563 * are regexps used to find the end of the element.
6565 * @method getSpecialElements
6566 * @return {Object} Name/value lookup map for special elements.
6568 self.getSpecialElements = function() {
6569 return specialElements;
6573 * Returns true/false if the specified element and it's child is valid or not
6574 * according to the schema.
6576 * @method isValidChild
6577 * @param {String} name Element name to check for.
6578 * @param {String} child Element child to verify.
6579 * @return {Boolean} True/false if the element is a valid child of the specified parent.
6581 self.isValidChild = function(name, child) {
6582 var parent = children[name];
6584 return !!(parent && parent[child]);
6588 * Returns true/false if the specified element name and optional attribute is
6589 * valid according to the schema.
6592 * @param {String} name Name of element to check.
6593 * @param {String} attr Optional attribute name to check for.
6594 * @return {Boolean} True/false if the element and attribute is valid.
6596 self.isValid = function(name, attr) {
6597 var attrPatterns, i, rule = getElementRule(name);
6599 // Check if it's a valid element
6602 // Check if attribute name exists
6603 if (rule.attributes[attr]) {
6607 // Check if attribute matches a regexp pattern
6608 attrPatterns = rule.attributePatterns;
6610 i = attrPatterns.length;
6612 if (attrPatterns[i].pattern.test(name)) {
6627 * Returns true/false if the specified element is valid or not
6628 * according to the schema.
6630 * @method getElementRule
6631 * @param {String} name Element name to check for.
6632 * @return {Object} Element object or undefined if the element isn't valid.
6634 self.getElementRule = getElementRule;
6637 * Returns an map object of all custom elements.
6639 * @method getCustomElements
6640 * @return {Object} Name/value map object of all custom elements.
6642 self.getCustomElements = function() {
6643 return customElementsMap;
6647 * Parses a valid elements string and adds it to the schema. The valid elements
6648 format is for example "element[attr=default|otherattr]".
6649 * Existing rules will be replaced with the ones specified, so this extends the schema.
6651 * @method addValidElements
6652 * @param {String} valid_elements String in the valid elements format to be parsed.
6654 self.addValidElements = addValidElements;
6657 * Parses a valid elements string and sets it to the schema. The valid elements
6658 * format is for example "element[attr=default|otherattr]".
6659 * Existing rules will be replaced with the ones specified, so this extends the schema.
6661 * @method setValidElements
6662 * @param {String} valid_elements String in the valid elements format to be parsed.
6664 self.setValidElements = setValidElements;
6667 * Adds custom non HTML elements to the schema.
6669 * @method addCustomElements
6670 * @param {String} custom_elements Comma separated list of custom elements to add.
6672 self.addCustomElements = addCustomElements;
6675 * Parses a valid children string and adds them to the schema structure. The valid children
6676 * format is for example: "element[child1|child2]".
6678 * @method addValidChildren
6679 * @param {String} valid_children Valid children elements string to parse
6681 self.addValidChildren = addValidChildren;
6683 self.elements = elements;
6687 // Included from: js/tinymce/classes/html/SaxParser.js
6692 * Copyright, Moxiecode Systems AB
6693 * Released under LGPL License.
6695 * License: http://www.tinymce.com/license
6696 * Contributing: http://www.tinymce.com/contributing
6700 * This class parses HTML code using pure JavaScript and executes various events for each item it finds. It will
6701 * always execute the events in the right order for tag soup code like <b><p></b></p>. It will also remove elements
6702 * and attributes that doesn't fit the schema if the validate setting is enabled.
6705 * var parser = new tinymce.html.SaxParser({
6708 * comment: function(text) {
6709 * console.log('Comment:', text);
6712 * cdata: function(text) {
6713 * console.log('CDATA:', text);
6716 * text: function(text, raw) {
6717 * console.log('Text:', text, 'Raw:', raw);
6720 * start: function(name, attrs, empty) {
6721 * console.log('Start:', name, attrs, empty);
6724 * end: function(name) {
6725 * console.log('End:', name);
6728 * pi: function(name, text) {
6729 * console.log('PI:', name, text);
6732 * doctype: function(text) {
6733 * console.log('DocType:', text);
6736 * @class tinymce.html.SaxParser
6739 define("tinymce/html/SaxParser", [
6740 "tinymce/html/Schema",
6741 "tinymce/html/Entities",
6742 "tinymce/util/Tools"
6743 ], function(Schema, Entities, Tools) {
6744 var each = Tools.each;
6747 * Constructs a new SaxParser instance.
6751 * @param {Object} settings Name/value collection of settings. comment, cdata, text, start and end are callbacks.
6752 * @param {tinymce.html.Schema} schema HTML Schema class to use when parsing.
6754 return function(settings, schema) {
6755 var self = this, noop = function() {};
6757 settings = settings || {};
6758 self.schema = schema = schema || new Schema();
6760 if (settings.fix_self_closing !== false) {
6761 settings.fix_self_closing = true;
6764 // Add handler functions from settings and setup default handlers
6765 each('comment cdata text start end pi doctype'.split(' '), function(name) {
6767 self[name] = settings[name] || noop;
6772 * Parses the specified HTML string and executes the callbacks for each item it finds.
6775 * new SaxParser({...}).parse('<b>text</b>');
6777 * @param {String} html Html string to sax parse.
6779 self.parse = function(html) {
6780 var self = this, matches, index = 0, value, endRegExp, stack = [], attrList, i, text, name;
6781 var isInternalElement, removeInternalElements, shortEndedElements, fillAttrsMap, isShortEnded;
6782 var validate, elementRule, isValidElement, attr, attribsValue, validAttributesMap, validAttributePatterns;
6783 var attributesRequired, attributesDefault, attributesForced;
6784 var anyAttributesRequired, selfClosing, tokenRegExp, attrRegExp, specialElements, attrValue, idCount = 0;
6785 var decode = Entities.decode, fixSelfClosing;
6787 function processEndTag(name) {
6790 // Find position of parent of the same type
6793 if (stack[pos].name === name) {
6800 // Close all the open elements
6801 for (i = stack.length - 1; i >= pos; i--) {
6805 self.end(name.name);
6809 // Remove the open elements from the stack
6814 function parseAttribute(match, name, value, val2, val3) {
6817 name = name.toLowerCase();
6818 value = name in fillAttrsMap ? name : decode(value || val2 || val3 || ''); // Handle boolean attribute than value attribute
6820 // Validate name and value pass through all data- attributes
6821 if (validate && !isInternalElement && name.indexOf('data-') !== 0) {
6822 attrRule = validAttributesMap[name];
6824 // Find rule by pattern matching
6825 if (!attrRule && validAttributePatterns) {
6826 i = validAttributePatterns.length;
6828 attrRule = validAttributePatterns[i];
6829 if (attrRule.pattern.test(name)) {
6840 // No attribute rule found
6846 if (attrRule.validValues && !(value in attrRule.validValues)) {
6851 // Add attribute to list and map
6852 attrList.map[name] = value;
6859 // Precompile RegExps and map objects
6860 tokenRegExp = new RegExp('<(?:' +
6861 '(?:!--([\\w\\W]*?)-->)|' + // Comment
6862 '(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|' + // CDATA
6863 '(?:!DOCTYPE([\\w\\W]*?)>)|' + // DOCTYPE
6864 '(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|' + // PI
6865 '(?:\\/([^>]+)>)|' + // End element
6866 '(?:([A-Za-z0-9\\-\\:\\.]+)((?:\\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\\/|\\s+)>)' + // Start element
6869 attrRegExp = /([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g;
6871 // Setup lookup tables for empty elements and boolean attributes
6872 shortEndedElements = schema.getShortEndedElements();
6873 selfClosing = settings.self_closing_elements || schema.getSelfClosingElements();
6874 fillAttrsMap = schema.getBoolAttrs();
6875 validate = settings.validate;
6876 removeInternalElements = settings.remove_internals;
6877 fixSelfClosing = settings.fix_self_closing;
6878 specialElements = schema.getSpecialElements();
6880 while ((matches = tokenRegExp.exec(html))) {
6882 if (index < matches.index) {
6883 self.text(decode(html.substr(index, matches.index - index)));
6886 if ((value = matches[6])) { // End element
6887 value = value.toLowerCase();
6889 // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
6890 if (value.charAt(0) === ':') {
6891 value = value.substr(1);
6894 processEndTag(value);
6895 } else if ((value = matches[7])) { // Start element
6896 value = value.toLowerCase();
6898 // IE will add a ":" in front of elements it doesn't understand like custom elements or HTML5 elements
6899 if (value.charAt(0) === ':') {
6900 value = value.substr(1);
6903 isShortEnded = value in shortEndedElements;
6905 // Is self closing tag for example an <li> after an open <li>
6906 if (fixSelfClosing && selfClosing[value] && stack.length > 0 && stack[stack.length - 1].name === value) {
6907 processEndTag(value);
6911 if (!validate || (elementRule = schema.getElementRule(value))) {
6912 isValidElement = true;
6914 // Grab attributes map and patters when validation is enabled
6916 validAttributesMap = elementRule.attributes;
6917 validAttributePatterns = elementRule.attributePatterns;
6921 if ((attribsValue = matches[8])) {
6922 isInternalElement = attribsValue.indexOf('data-mce-type') !== -1; // Check if the element is an internal element
6924 // If the element has internal attributes then remove it if we are told to do so
6925 if (isInternalElement && removeInternalElements) {
6926 isValidElement = false;
6932 attribsValue.replace(attrRegExp, parseAttribute);
6938 // Process attributes if validation is enabled
6939 if (validate && !isInternalElement) {
6940 attributesRequired = elementRule.attributesRequired;
6941 attributesDefault = elementRule.attributesDefault;
6942 attributesForced = elementRule.attributesForced;
6943 anyAttributesRequired = elementRule.removeEmptyAttrs;
6945 // Check if any attribute exists
6946 if (anyAttributesRequired && !attrList.length) {
6947 isValidElement = false;
6950 // Handle forced attributes
6951 if (attributesForced) {
6952 i = attributesForced.length;
6954 attr = attributesForced[i];
6956 attrValue = attr.value;
6958 if (attrValue === '{$uid}') {
6959 attrValue = 'mce_' + idCount++;
6962 attrList.map[name] = attrValue;
6963 attrList.push({name: name, value: attrValue});
6967 // Handle default attributes
6968 if (attributesDefault) {
6969 i = attributesDefault.length;
6971 attr = attributesDefault[i];
6974 if (!(name in attrList.map)) {
6975 attrValue = attr.value;
6977 if (attrValue === '{$uid}') {
6978 attrValue = 'mce_' + idCount++;
6981 attrList.map[name] = attrValue;
6982 attrList.push({name: name, value: attrValue});
6987 // Handle required attributes
6988 if (attributesRequired) {
6989 i = attributesRequired.length;
6991 if (attributesRequired[i] in attrList.map) {
6996 // None of the required attributes where found
6998 isValidElement = false;
7002 // Invalidate element if it's marked as bogus
7003 if (attrList.map['data-mce-bogus']) {
7004 isValidElement = false;
7008 if (isValidElement) {
7009 self.start(value, attrList, isShortEnded);
7012 isValidElement = false;
7015 // Treat script, noscript and style a bit different since they may include code that looks like elements
7016 if ((endRegExp = specialElements[value])) {
7017 endRegExp.lastIndex = index = matches.index + matches[0].length;
7019 if ((matches = endRegExp.exec(html))) {
7020 if (isValidElement) {
7021 text = html.substr(index, matches.index - index);
7024 index = matches.index + matches[0].length;
7026 text = html.substr(index);
7027 index = html.length;
7030 if (isValidElement) {
7031 if (text.length > 0) {
7032 self.text(text, true);
7038 tokenRegExp.lastIndex = index;
7042 // Push value on to stack
7043 if (!isShortEnded) {
7044 if (!attribsValue || attribsValue.indexOf('/') != attribsValue.length - 1) {
7045 stack.push({name: value, valid: isValidElement});
7046 } else if (isValidElement) {
7050 } else if ((value = matches[1])) { // Comment
7051 self.comment(value);
7052 } else if ((value = matches[2])) { // CDATA
7054 } else if ((value = matches[3])) { // DOCTYPE
7055 self.doctype(value);
7056 } else if ((value = matches[4])) { // PI
7057 self.pi(value, matches[5]);
7060 index = matches.index + matches[0].length;
7064 if (index < html.length) {
7065 self.text(decode(html.substr(index)));
7068 // Close any open elements
7069 for (i = stack.length - 1; i >= 0; i--) {
7073 self.end(value.name);
7080 // Included from: js/tinymce/classes/html/DomParser.js
7085 * Copyright, Moxiecode Systems AB
7086 * Released under LGPL License.
7088 * License: http://www.tinymce.com/license
7089 * Contributing: http://www.tinymce.com/contributing
7093 * This class parses HTML code into a DOM like structure of nodes it will remove redundant whitespace and make
7094 * sure that the node tree is valid according to the specified schema.
7095 * So for example: <p>a<p>b</p>c</p> will become <p>a</p><p>b</p><p>c</p>
7098 * var parser = new tinymce.html.DomParser({validate: true}, schema);
7099 * var rootNode = parser.parse('<h1>content</h1>');
7101 * @class tinymce.html.DomParser
7104 define("tinymce/html/DomParser", [
7105 "tinymce/html/Node",
7106 "tinymce/html/Schema",
7107 "tinymce/html/SaxParser",
7108 "tinymce/util/Tools"
7109 ], function(Node, Schema, SaxParser, Tools) {
7110 var makeMap = Tools.makeMap, each = Tools.each, explode = Tools.explode, extend = Tools.extend;
7113 * Constructs a new DomParser instance.
7117 * @param {Object} settings Name/value collection of settings. comment, cdata, text, start and end are callbacks.
7118 * @param {tinymce.html.Schema} schema HTML Schema class to use when parsing.
7120 return function(settings, schema) {
7121 var self = this, nodeFilters = {}, attributeFilters = [], matchedNodes = {}, matchedAttributes = {};
7123 settings = settings || {};
7124 settings.validate = "validate" in settings ? settings.validate : true;
7125 settings.root_name = settings.root_name || 'body';
7126 self.schema = schema = schema || new Schema();
7128 function fixInvalidChildren(nodes) {
7129 var ni, node, parent, parents, newParent, currentNode, tempNode, childNode, i;
7130 var nonEmptyElements, nonSplitableElements, textBlockElements, sibling, nextNode;
7132 nonSplitableElements = makeMap('tr,td,th,tbody,thead,tfoot,table');
7133 nonEmptyElements = schema.getNonEmptyElements();
7134 textBlockElements = schema.getTextBlockElements();
7136 for (ni = 0; ni < nodes.length; ni++) {
7139 // Already removed or fixed
7140 if (!node.parent || node.fixed) {
7144 // If the invalid element is a text block and the text block is within a parent LI element
7145 // Then unwrap the first text block and convert other sibling text blocks to LI elements similar to Word/Open Office
7146 if (textBlockElements[node.name] && node.parent.name == 'li') {
7147 // Move sibling text blocks after LI element
7148 sibling = node.next;
7150 if (textBlockElements[sibling.name]) {
7151 sibling.name = 'li';
7152 sibling.fixed = true;
7153 node.parent.insert(sibling, node.parent);
7158 sibling = sibling.next;
7161 // Unwrap current text block
7166 // Get list of all parent nodes until we find a valid parent to stick the child into
7168 for (parent = node.parent; parent && !schema.isValidChild(parent.name, node.name) &&
7169 !nonSplitableElements[parent.name]; parent = parent.parent) {
7170 parents.push(parent);
7173 // Found a suitable parent
7174 if (parent && parents.length > 1) {
7175 // Reverse the array since it makes looping easier
7178 // Clone the related parent and insert that after the moved node
7179 newParent = currentNode = self.filterNode(parents[0].clone());
7181 // Start cloning and moving children on the left side of the target node
7182 for (i = 0; i < parents.length - 1; i++) {
7183 if (schema.isValidChild(currentNode.name, parents[i].name)) {
7184 tempNode = self.filterNode(parents[i].clone());
7185 currentNode.append(tempNode);
7187 tempNode = currentNode;
7190 for (childNode = parents[i].firstChild; childNode && childNode != parents[i + 1]; ) {
7191 nextNode = childNode.next;
7192 tempNode.append(childNode);
7193 childNode = nextNode;
7196 currentNode = tempNode;
7199 if (!newParent.isEmpty(nonEmptyElements)) {
7200 parent.insert(newParent, parents[0], true);
7201 parent.insert(node, newParent);
7203 parent.insert(node, parents[0], true);
7206 // Check if the element is empty by looking through it's contents and special treatment for <p><br /></p>
7207 parent = parents[0];
7208 if (parent.isEmpty(nonEmptyElements) || parent.firstChild === parent.lastChild && parent.firstChild.name === 'br') {
7209 parent.empty().remove();
7211 } else if (node.parent) {
7212 // If it's an LI try to find a UL/OL for it or wrap it
7213 if (node.name === 'li') {
7214 sibling = node.prev;
7215 if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
7216 sibling.append(node);
7220 sibling = node.next;
7221 if (sibling && (sibling.name === 'ul' || sibling.name === 'ul')) {
7222 sibling.insert(node, sibling.firstChild, true);
7226 node.wrap(self.filterNode(new Node('ul', 1)));
7230 // Try wrapping the element in a DIV
7231 if (schema.isValidChild(node.parent.name, 'div') && schema.isValidChild('div', node.name)) {
7232 node.wrap(self.filterNode(new Node('div', 1)));
7234 // We failed wrapping it, then remove or unwrap it
7235 if (node.name === 'style' || node.name === 'script') {
7236 node.empty().remove();
7246 * Runs the specified node though the element and attributes filters.
7248 * @method filterNode
7249 * @param {tinymce.html.Node} Node the node to run filters on.
7250 * @return {tinymce.html.Node} The passed in node.
7252 self.filterNode = function(node) {
7255 // Run element filters
7256 if (name in nodeFilters) {
7257 list = matchedNodes[name];
7262 matchedNodes[name] = [node];
7266 // Run attribute filters
7267 i = attributeFilters.length;
7269 name = attributeFilters[i].name;
7271 if (name in node.attributes.map) {
7272 list = matchedAttributes[name];
7277 matchedAttributes[name] = [node];
7286 * Adds a node filter function to the parser, the parser will collect the specified nodes by name
7287 * and then execute the callback ones it has finished parsing the document.
7290 * parser.addNodeFilter('p,h1', function(nodes, name) {
7291 * for (var i = 0; i < nodes.length; i++) {
7292 * console.log(nodes[i].name);
7295 * @method addNodeFilter
7296 * @method {String} name Comma separated list of nodes to collect.
7297 * @param {function} callback Callback function to execute once it has collected nodes.
7299 self.addNodeFilter = function(name, callback) {
7300 each(explode(name), function(name) {
7301 var list = nodeFilters[name];
7304 nodeFilters[name] = list = [];
7307 list.push(callback);
7312 * Adds a attribute filter function to the parser, the parser will collect nodes that has the specified attributes
7313 * and then execute the callback ones it has finished parsing the document.
7316 * parser.addAttributeFilter('src,href', function(nodes, name) {
7317 * for (var i = 0; i < nodes.length; i++) {
7318 * console.log(nodes[i].name);
7321 * @method addAttributeFilter
7322 * @method {String} name Comma separated list of nodes to collect.
7323 * @param {function} callback Callback function to execute once it has collected nodes.
7325 self.addAttributeFilter = function(name, callback) {
7326 each(explode(name), function(name) {
7329 for (i = 0; i < attributeFilters.length; i++) {
7330 if (attributeFilters[i].name === name) {
7331 attributeFilters[i].callbacks.push(callback);
7336 attributeFilters.push({name: name, callbacks: [callback]});
7341 * Parses the specified HTML string into a DOM like node tree and returns the result.
7344 * var rootNode = new DomParser({...}).parse('<b>text</b>');
7346 * @param {String} html Html string to sax parse.
7347 * @param {Object} args Optional args object that gets passed to all filter functions.
7348 * @return {tinymce.html.Node} Root node containing the tree.
7350 self.parse = function(html, args) {
7351 var parser, rootNode, node, nodes, i, l, fi, fl, list, name, validate;
7352 var blockElements, startWhiteSpaceRegExp, invalidChildren = [], isInWhiteSpacePreservedElement;
7353 var endWhiteSpaceRegExp, allWhiteSpaceRegExp, isAllWhiteSpaceRegExp, whiteSpaceElements;
7354 var children, nonEmptyElements, rootBlockName;
7358 matchedAttributes = {};
7359 blockElements = extend(makeMap('script,style,head,html,body,title,meta,param'), schema.getBlockElements());
7360 nonEmptyElements = schema.getNonEmptyElements();
7361 children = schema.children;
7362 validate = settings.validate;
7363 rootBlockName = "forced_root_block" in args ? args.forced_root_block : settings.forced_root_block;
7365 whiteSpaceElements = schema.getWhiteSpaceElements();
7366 startWhiteSpaceRegExp = /^[ \t\r\n]+/;
7367 endWhiteSpaceRegExp = /[ \t\r\n]+$/;
7368 allWhiteSpaceRegExp = /[ \t\r\n]+/g;
7369 isAllWhiteSpaceRegExp = /^[ \t\r\n]+$/;
7371 function addRootBlocks() {
7372 var node = rootNode.firstChild, next, rootBlockNode;
7374 // Removes whitespace at beginning and end of block so:
7375 // <p> x </p> -> <p>x</p>
7376 function trim(rootBlockNode) {
7377 if (rootBlockNode) {
7378 node = rootBlockNode.firstChild;
7379 if (node && node.type == 3) {
7380 node.value = node.value.replace(startWhiteSpaceRegExp, '');
7383 node = rootBlockNode.lastChild;
7384 if (node && node.type == 3) {
7385 node.value = node.value.replace(endWhiteSpaceRegExp, '');
7390 // Check if rootBlock is valid within rootNode for example if P is valid in H1 if H1 is the contentEditabe root
7391 if (!schema.isValidChild(rootNode.name, rootBlockName.toLowerCase())) {
7398 if (node.type == 3 || (node.type == 1 && node.name !== 'p' &&
7399 !blockElements[node.name] && !node.attr('data-mce-type'))) {
7400 if (!rootBlockNode) {
7401 // Create a new root block element
7402 rootBlockNode = createNode(rootBlockName, 1);
7403 rootNode.insert(rootBlockNode, node);
7404 rootBlockNode.append(node);
7406 rootBlockNode.append(node);
7409 trim(rootBlockNode);
7410 rootBlockNode = null;
7416 trim(rootBlockNode);
7419 function createNode(name, type) {
7420 var node = new Node(name, type), list;
7422 if (name in nodeFilters) {
7423 list = matchedNodes[name];
7428 matchedNodes[name] = [node];
7435 function removeWhitespaceBefore(node) {
7436 var textNode, textVal, sibling;
7438 for (textNode = node.prev; textNode && textNode.type === 3; ) {
7439 textVal = textNode.value.replace(endWhiteSpaceRegExp, '');
7441 if (textVal.length > 0) {
7442 textNode.value = textVal;
7443 textNode = textNode.prev;
7445 sibling = textNode.prev;
7452 function cloneAndExcludeBlocks(input) {
7453 var name, output = {};
7455 for (name in input) {
7456 if (name !== 'li' && name != 'p') {
7457 output[name] = input[name];
7464 parser = new SaxParser({
7467 // Exclude P and LI from DOM parsing since it's treated better by the DOM parser
7468 self_closing_elements: cloneAndExcludeBlocks(schema.getSelfClosingElements()),
7470 cdata: function(text) {
7471 node.append(createNode('#cdata', 4)).value = text;
7474 text: function(text, raw) {
7477 // Trim all redundant whitespace on non white space elements
7478 if (!isInWhiteSpacePreservedElement) {
7479 text = text.replace(allWhiteSpaceRegExp, ' ');
7481 if (node.lastChild && blockElements[node.lastChild.name]) {
7482 text = text.replace(startWhiteSpaceRegExp, '');
7486 // Do we need to create the node
7487 if (text.length !== 0) {
7488 textNode = createNode('#text', 3);
7489 textNode.raw = !!raw;
7490 node.append(textNode).value = text;
7494 comment: function(text) {
7495 node.append(createNode('#comment', 8)).value = text;
7498 pi: function(name, text) {
7499 node.append(createNode(name, 7)).value = text;
7500 removeWhitespaceBefore(node);
7503 doctype: function(text) {
7506 newNode = node.append(createNode('#doctype', 10));
7507 newNode.value = text;
7508 removeWhitespaceBefore(node);
7511 start: function(name, attrs, empty) {
7512 var newNode, attrFiltersLen, elementRule, attrName, parent;
7514 elementRule = validate ? schema.getElementRule(name) : {};
7516 newNode = createNode(elementRule.outputName || name, 1);
7517 newNode.attributes = attrs;
7518 newNode.shortEnded = empty;
7520 node.append(newNode);
7522 // Check if node is valid child of the parent node is the child is
7523 // unknown we don't collect it since it's probably a custom element
7524 parent = children[node.name];
7525 if (parent && children[newNode.name] && !parent[newNode.name]) {
7526 invalidChildren.push(newNode);
7529 attrFiltersLen = attributeFilters.length;
7530 while (attrFiltersLen--) {
7531 attrName = attributeFilters[attrFiltersLen].name;
7533 if (attrName in attrs.map) {
7534 list = matchedAttributes[attrName];
7539 matchedAttributes[attrName] = [newNode];
7544 // Trim whitespace before block
7545 if (blockElements[name]) {
7546 removeWhitespaceBefore(newNode);
7549 // Change current node if the element wasn't empty i.e not <br /> or <img />
7554 // Check if we are inside a whitespace preserved element
7555 if (!isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
7556 isInWhiteSpacePreservedElement = true;
7561 end: function(name) {
7562 var textNode, elementRule, text, sibling, tempNode;
7564 elementRule = validate ? schema.getElementRule(name) : {};
7566 if (blockElements[name]) {
7567 if (!isInWhiteSpacePreservedElement) {
7568 // Trim whitespace of the first node in a block
7569 textNode = node.firstChild;
7570 if (textNode && textNode.type === 3) {
7571 text = textNode.value.replace(startWhiteSpaceRegExp, '');
7573 // Any characters left after trim or should we remove it
7574 if (text.length > 0) {
7575 textNode.value = text;
7576 textNode = textNode.next;
7578 sibling = textNode.next;
7582 // Remove any pure whitespace siblings
7583 while (textNode && textNode.type === 3) {
7584 text = textNode.value;
7585 sibling = textNode.next;
7587 if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
7597 // Trim whitespace of the last node in a block
7598 textNode = node.lastChild;
7599 if (textNode && textNode.type === 3) {
7600 text = textNode.value.replace(endWhiteSpaceRegExp, '');
7602 // Any characters left after trim or should we remove it
7603 if (text.length > 0) {
7604 textNode.value = text;
7605 textNode = textNode.prev;
7607 sibling = textNode.prev;
7611 // Remove any pure whitespace siblings
7612 while (textNode && textNode.type === 3) {
7613 text = textNode.value;
7614 sibling = textNode.prev;
7616 if (text.length === 0 || isAllWhiteSpaceRegExp.test(text)) {
7627 // Trim start white space
7628 // Removed due to: #5424
7629 /*textNode = node.prev;
7630 if (textNode && textNode.type === 3) {
7631 text = textNode.value.replace(startWhiteSpaceRegExp, '');
7633 if (text.length > 0)
7634 textNode.value = text;
7640 // Check if we exited a whitespace preserved element
7641 if (isInWhiteSpacePreservedElement && whiteSpaceElements[name]) {
7642 isInWhiteSpacePreservedElement = false;
7645 // Handle empty nodes
7646 if (elementRule.removeEmpty || elementRule.paddEmpty) {
7647 if (node.isEmpty(nonEmptyElements)) {
7648 if (elementRule.paddEmpty) {
7649 node.empty().append(new Node('#text', '3')).value = '\u00a0';
7651 // Leave nodes that have a name like <a name="name">
7652 if (!node.attributes.map.name && !node.attributes.map.id) {
7653 tempNode = node.parent;
7654 node.empty().remove();
7667 rootNode = node = new Node(args.context || settings.root_name, 11);
7671 // Fix invalid children or report invalid children in a contextual parsing
7672 if (validate && invalidChildren.length) {
7673 if (!args.context) {
7674 fixInvalidChildren(invalidChildren);
7676 args.invalid = true;
7680 // Wrap nodes in the root into block elements if the root is body
7681 if (rootBlockName && (rootNode.name == 'body' || args.isRootContent)) {
7685 // Run filters only when the contents is valid
7686 if (!args.invalid) {
7688 for (name in matchedNodes) {
7689 list = nodeFilters[name];
7690 nodes = matchedNodes[name];
7692 // Remove already removed children
7695 if (!nodes[fi].parent) {
7696 nodes.splice(fi, 1);
7700 for (i = 0, l = list.length; i < l; i++) {
7701 list[i](nodes, name, args);
7705 // Run attribute filters
7706 for (i = 0, l = attributeFilters.length; i < l; i++) {
7707 list = attributeFilters[i];
7709 if (list.name in matchedAttributes) {
7710 nodes = matchedAttributes[list.name];
7712 // Remove already removed children
7715 if (!nodes[fi].parent) {
7716 nodes.splice(fi, 1);
7720 for (fi = 0, fl = list.callbacks.length; fi < fl; fi++) {
7721 list.callbacks[fi](nodes, list.name, args);
7730 // Remove <br> at end of block elements Gecko and WebKit injects BR elements to
7731 // make it possible to place the caret inside empty blocks. This logic tries to remove
7732 // these elements and keep br elements that where intended to be there intact
7733 if (settings.remove_trailing_brs) {
7734 self.addNodeFilter('br', function(nodes) {
7735 var i, l = nodes.length, node, blockElements = extend({}, schema.getBlockElements());
7736 var nonEmptyElements = schema.getNonEmptyElements(), parent, lastParent, prev, prevName;
7737 var elementRule, textNode;
7739 // Remove brs from body element as well
7740 blockElements.body = 1;
7742 // Must loop forwards since it will otherwise remove all brs in <p>a<br><br><br></p>
7743 for (i = 0; i < l; i++) {
7745 parent = node.parent;
7747 if (blockElements[node.parent.name] && node === parent.lastChild) {
7748 // Loop all nodes to the left of the current node and check for other BR elements
7749 // excluding bookmarks since they are invisible
7752 prevName = prev.name;
7755 if (prevName !== "span" || prev.attr('data-mce-type') !== 'bookmark') {
7756 // Found a non BR element
7757 if (prevName !== "br") {
7761 // Found another br it's a <br><br> structure then don't remove anything
7762 if (prevName === 'br') {
7774 // Is the parent to be considered empty after we removed the BR
7775 if (parent.isEmpty(nonEmptyElements)) {
7776 elementRule = schema.getElementRule(parent.name);
7778 // Remove or padd the element depending on schema rule
7780 if (elementRule.removeEmpty) {
7782 } else if (elementRule.paddEmpty) {
7783 parent.empty().append(new Node('#text', 3)).value = '\u00a0';
7789 // Replaces BR elements inside inline elements like <p><b><i><br></i></b></p>
7790 // so they become <p><b><i> </i></b></p>
7792 while (parent && parent.firstChild === lastParent && parent.lastChild === lastParent) {
7793 lastParent = parent;
7795 if (blockElements[parent.name]) {
7799 parent = parent.parent;
7802 if (lastParent === parent) {
7803 textNode = new Node('#text', 3);
7804 textNode.value = '\u00a0';
7805 node.replace(textNode);
7812 // Force anchor names closed, unless the setting "allow_html_in_named_anchor" is explicitly included.
7813 if (!settings.allow_html_in_named_anchor) {
7814 self.addAttributeFilter('id,name', function(nodes) {
7815 var i = nodes.length, sibling, prevSibling, parent, node;
7819 if (node.name === 'a' && node.firstChild && !node.attr('href')) {
7820 parent = node.parent;
7822 // Move children after current node
7823 sibling = node.lastChild;
7825 prevSibling = sibling.prev;
7826 parent.insert(sibling, node);
7827 sibling = prevSibling;
7836 // Included from: js/tinymce/classes/html/Writer.js
7841 * Copyright, Moxiecode Systems AB
7842 * Released under LGPL License.
7844 * License: http://www.tinymce.com/license
7845 * Contributing: http://www.tinymce.com/contributing
7849 * This class is used to write HTML tags out it can be used with the Serializer or the SaxParser.
7851 * @class tinymce.html.Writer
7853 * var writer = new tinymce.html.Writer({indent: true});
7854 * var parser = new tinymce.html.SaxParser(writer).parse('<p><br></p>');
7855 * console.log(writer.getContent());
7857 * @class tinymce.html.Writer
7860 define("tinymce/html/Writer", [
7861 "tinymce/html/Entities",
7862 "tinymce/util/Tools"
7863 ], function(Entities, Tools) {
7864 var makeMap = Tools.makeMap;
7867 * Constructs a new Writer instance.
7871 * @param {Object} settings Name/value settings object.
7873 return function(settings) {
7874 var html = [], indent, indentBefore, indentAfter, encode, htmlOutput;
7876 settings = settings || {};
7877 indent = settings.indent;
7878 indentBefore = makeMap(settings.indent_before || '');
7879 indentAfter = makeMap(settings.indent_after || '');
7880 encode = Entities.getEncodeFunc(settings.entity_encoding || 'raw', settings.entities);
7881 htmlOutput = settings.element_format == "html";
7885 * Writes the a start element such as <p id="a">.
7888 * @param {String} name Name of the element.
7889 * @param {Array} attrs Optional attribute array or undefined if it hasn't any.
7890 * @param {Boolean} empty Optional empty state if the tag should end like <br />.
7892 start: function(name, attrs, empty) {
7893 var i, l, attr, value;
7895 if (indent && indentBefore[name] && html.length > 0) {
7896 value = html[html.length - 1];
7898 if (value.length > 0 && value !== '\n') {
7903 html.push('<', name);
7906 for (i = 0, l = attrs.length; i < l; i++) {
7908 html.push(' ', attr.name, '="', encode(attr.value, true), '"');
7912 if (!empty || htmlOutput) {
7913 html[html.length] = '>';
7915 html[html.length] = ' />';
7918 if (empty && indent && indentAfter[name] && html.length > 0) {
7919 value = html[html.length - 1];
7921 if (value.length > 0 && value !== '\n') {
7928 * Writes the a end element such as </p>.
7931 * @param {String} name Name of the element.
7933 end: function(name) {
7936 /*if (indent && indentBefore[name] && html.length > 0) {
7937 value = html[html.length - 1];
7939 if (value.length > 0 && value !== '\n')
7943 html.push('</', name, '>');
7945 if (indent && indentAfter[name] && html.length > 0) {
7946 value = html[html.length - 1];
7948 if (value.length > 0 && value !== '\n') {
7955 * Writes a text node.
7958 * @param {String} text String to write out.
7959 * @param {Boolean} raw Optional raw state if true the contents wont get encoded.
7961 text: function(text, raw) {
7962 if (text.length > 0) {
7963 html[html.length] = raw ? text : encode(text);
7968 * Writes a cdata node such as <![CDATA[data]]>.
7971 * @param {String} text String to write out inside the cdata.
7973 cdata: function(text) {
7974 html.push('<![CDATA[', text, ']]>');
7978 * Writes a comment node such as <!-- Comment -->.
7981 * @param {String} text String to write out inside the comment.
7983 comment: function(text) {
7984 html.push('<!--', text, '-->');
7988 * Writes a PI node such as <?xml attr="value" ?>.
7991 * @param {String} name Name of the pi.
7992 * @param {String} text String to write out inside the pi.
7994 pi: function(name, text) {
7996 html.push('<?', name, ' ', text, '?>');
7998 html.push('<?', name, '?>');
8007 * Writes a doctype node such as <!DOCTYPE data>.
8010 * @param {String} text String to write out inside the doctype.
8012 doctype: function(text) {
8013 html.push('<!DOCTYPE', text, '>', indent ? '\n' : '');
8017 * Resets the internal buffer if one wants to reuse the writer.
8026 * Returns the contents that got serialized.
8028 * @method getContent
8029 * @return {String} HTML contents that got written down.
8031 getContent: function() {
8032 return html.join('').replace(/\n$/, '');
8038 // Included from: js/tinymce/classes/html/Serializer.js
8043 * Copyright, Moxiecode Systems AB
8044 * Released under LGPL License.
8046 * License: http://www.tinymce.com/license
8047 * Contributing: http://www.tinymce.com/contributing
8051 * This class is used to serialize down the DOM tree into a string using a Writer instance.
8055 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
8056 * @class tinymce.html.Serializer
8059 define("tinymce/html/Serializer", [
8060 "tinymce/html/Writer",
8061 "tinymce/html/Schema"
8062 ], function(Writer, Schema) {
8064 * Constructs a new Serializer instance.
8067 * @method Serializer
8068 * @param {Object} settings Name/value settings object.
8069 * @param {tinymce.html.Schema} schema Schema instance to use.
8071 return function(settings, schema) {
8072 var self = this, writer = new Writer(settings);
8074 settings = settings || {};
8075 settings.validate = "validate" in settings ? settings.validate : true;
8077 self.schema = schema = schema || new Schema();
8078 self.writer = writer;
8081 * Serializes the specified node into a string.
8084 * new tinymce.html.Serializer().serialize(new tinymce.html.DomParser().parse('<p>text</p>'));
8086 * @param {tinymce.html.Node} node Node instance to serialize.
8087 * @return {String} String with HTML based on DOM tree.
8089 self.serialize = function(node) {
8090 var handlers, validate;
8092 validate = settings.validate;
8097 writer.text(node.value, node.raw);
8102 writer.comment(node.value);
8105 // Processing instruction
8107 writer.pi(node.name, node.value);
8111 10: function(node) {
8112 writer.doctype(node.value);
8117 writer.cdata(node.value);
8120 // Document fragment
8121 11: function(node) {
8122 if ((node = node.firstChild)) {
8125 } while ((node = node.next));
8132 function walk(node) {
8133 var handler = handlers[node.type], name, isEmpty, attrs, attrName, attrValue, sortedAttrs, i, l, elementRule;
8137 isEmpty = node.shortEnded;
8138 attrs = node.attributes;
8141 if (validate && attrs && attrs.length > 1) {
8143 sortedAttrs.map = {};
8145 elementRule = schema.getElementRule(node.name);
8146 for (i = 0, l = elementRule.attributesOrder.length; i < l; i++) {
8147 attrName = elementRule.attributesOrder[i];
8149 if (attrName in attrs.map) {
8150 attrValue = attrs.map[attrName];
8151 sortedAttrs.map[attrName] = attrValue;
8152 sortedAttrs.push({name: attrName, value: attrValue});
8156 for (i = 0, l = attrs.length; i < l; i++) {
8157 attrName = attrs[i].name;
8159 if (!(attrName in sortedAttrs.map)) {
8160 attrValue = attrs.map[attrName];
8161 sortedAttrs.map[attrName] = attrValue;
8162 sortedAttrs.push({name: attrName, value: attrValue});
8166 attrs = sortedAttrs;
8169 writer.start(node.name, attrs, isEmpty);
8172 if ((node = node.firstChild)) {
8175 } while ((node = node.next));
8185 // Serialize element and treat all non elements as fragments
8186 if (node.type == 1 && !settings.inner) {
8192 return writer.getContent();
8197 // Included from: js/tinymce/classes/dom/Serializer.js
8202 * Copyright, Moxiecode Systems AB
8203 * Released under LGPL License.
8205 * License: http://www.tinymce.com/license
8206 * Contributing: http://www.tinymce.com/contributing
8210 * This class is used to serialize DOM trees into a string. Consult the TinyMCE Wiki API for
8211 * more details and examples on how to use this class.
8213 * @class tinymce.dom.Serializer
8215 define("tinymce/dom/Serializer", [
8216 "tinymce/dom/DOMUtils",
8217 "tinymce/html/DomParser",
8218 "tinymce/html/Entities",
8219 "tinymce/html/Serializer",
8220 "tinymce/html/Node",
8221 "tinymce/html/Schema",
8223 "tinymce/util/Tools"
8224 ], function(DOMUtils, DomParser, Entities, Serializer, Node, Schema, Env, Tools) {
8225 var each = Tools.each, trim = Tools.trim;
8226 var DOM = DOMUtils.DOM;
8229 * Constructs a new DOM serializer class.
8232 * @method Serializer
8233 * @param {Object} settings Serializer settings object.
8234 * @param {tinymce.Editor} editor Optional editor to bind events to and get schema/dom from.
8236 return function(settings, editor) {
8237 var dom, schema, htmlParser;
8241 schema = editor.schema;
8244 // Default DOM and Schema if they are undefined
8246 schema = schema || new Schema(settings);
8247 settings.entity_encoding = settings.entity_encoding || 'named';
8248 settings.remove_trailing_brs = "remove_trailing_brs" in settings ? settings.remove_trailing_brs : true;
8250 htmlParser = new DomParser(settings, schema);
8252 // Convert move data-mce-src, data-mce-href and data-mce-style into nodes or process them if needed
8253 htmlParser.addAttributeFilter('src,href,style', function(nodes, name) {
8254 var i = nodes.length, node, value, internalName = 'data-mce-' + name;
8255 var urlConverter = settings.url_converter, urlConverterScope = settings.url_converter_scope, undef;
8260 value = node.attributes.map[internalName];
8261 if (value !== undef) {
8262 // Set external name to internal value and remove internal
8263 node.attr(name, value.length > 0 ? value : null);
8264 node.attr(internalName, null);
8266 // No internal attribute found then convert the value we have in the DOM
8267 value = node.attributes.map[name];
8269 if (name === "style") {
8270 value = dom.serializeStyle(dom.parseStyle(value), node.name);
8271 } else if (urlConverter) {
8272 value = urlConverter.call(urlConverterScope, value, name, node.name);
8275 node.attr(name, value.length > 0 ? value : null);
8280 // Remove internal classes mceItem<..> or mceSelected
8281 htmlParser.addAttributeFilter('class', function(nodes) {
8282 var i = nodes.length, node, value;
8286 value = node.attr('class').replace(/(?:^|\s)mce-item-\w+(?!\S)/g, '');
8287 node.attr('class', value.length > 0 ? value : null);
8291 // Remove bookmark elements
8292 htmlParser.addAttributeFilter('data-mce-type', function(nodes, name, args) {
8293 var i = nodes.length, node;
8298 if (node.attributes.map['data-mce-type'] === 'bookmark' && !args.cleanup) {
8304 // Remove expando attributes
8305 htmlParser.addAttributeFilter('data-mce-expando', function(nodes, name) {
8306 var i = nodes.length;
8309 nodes[i].attr(name, null);
8313 htmlParser.addNodeFilter('noscript', function(nodes) {
8314 var i = nodes.length, node;
8317 node = nodes[i].firstChild;
8320 node.value = Entities.decode(node.value);
8325 // Force script into CDATA sections and remove the mce- prefix also add comments around styles
8326 htmlParser.addNodeFilter('script,style', function(nodes, name) {
8327 var i = nodes.length, node, value;
8329 function trim(value) {
8330 /*jshint maxlen:255 */
8331 return value.replace(/(<!--\[CDATA\[|\]\]-->)/g, '\n')
8332 .replace(/^[\r\n]*|[\r\n]*$/g, '')
8333 .replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi, '')
8334 .replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g, '');
8339 value = node.firstChild ? node.firstChild.value : '';
8341 if (name === "script") {
8342 // Remove mce- prefix from script elements and remove default text/javascript mime type (HTML5)
8343 var type = (node.attr('type') || 'text/javascript').replace(/^mce\-/, '');
8344 node.attr('type', type === 'text/javascript' ? null : type);
8346 if (value.length > 0) {
8347 node.firstChild.value = '// <![CDATA[\n' + trim(value) + '\n// ]]>';
8350 if (value.length > 0) {
8351 node.firstChild.value = '<!--\n' + trim(value) + '\n-->';
8357 // Convert comments to cdata and handle protected comments
8358 htmlParser.addNodeFilter('#comment', function(nodes) {
8359 var i = nodes.length, node;
8364 if (node.value.indexOf('[CDATA[') === 0) {
8365 node.name = '#cdata';
8367 node.value = node.value.replace(/^\[CDATA\[|\]\]$/g, '');
8368 } else if (node.value.indexOf('mce:protected ') === 0) {
8369 node.name = "#text";
8372 node.value = unescape(node.value).substr(14);
8377 htmlParser.addNodeFilter('xml:namespace,input', function(nodes, name) {
8378 var i = nodes.length, node;
8382 if (node.type === 7) {
8384 } else if (node.type === 1) {
8385 if (name === "input" && !("type" in node.attributes.map)) {
8386 node.attr('type', 'text');
8392 // Fix list elements, TODO: Replace this later
8393 if (settings.fix_list_elements) {
8394 htmlParser.addNodeFilter('ul,ol', function(nodes) {
8395 var i = nodes.length, node, parentNode;
8399 parentNode = node.parent;
8401 if (parentNode.name === 'ul' || parentNode.name === 'ol') {
8402 if (node.prev && node.prev.name === 'li') {
8403 node.prev.append(node);
8410 // Remove internal data attributes
8411 htmlParser.addAttributeFilter('data-mce-src,data-mce-href,data-mce-style,data-mce-selected', function(nodes, name) {
8412 var i = nodes.length;
8415 nodes[i].attr(name, null);
8419 // Return public methods
8422 * Schema instance that was used to when the Serializer was constructed.
8424 * @field {tinymce.html.Schema} schema
8429 * Adds a node filter function to the parser used by the serializer, the parser will collect the specified nodes by name
8430 * and then execute the callback ones it has finished parsing the document.
8433 * parser.addNodeFilter('p,h1', function(nodes, name) {
8434 * for (var i = 0; i < nodes.length; i++) {
8435 * console.log(nodes[i].name);
8438 * @method addNodeFilter
8439 * @method {String} name Comma separated list of nodes to collect.
8440 * @param {function} callback Callback function to execute once it has collected nodes.
8442 addNodeFilter: htmlParser.addNodeFilter,
8445 * Adds a attribute filter function to the parser used by the serializer, the parser will
8446 * collect nodes that has the specified attributes
8447 * and then execute the callback ones it has finished parsing the document.
8450 * parser.addAttributeFilter('src,href', function(nodes, name) {
8451 * for (var i = 0; i < nodes.length; i++) {
8452 * console.log(nodes[i].name);
8455 * @method addAttributeFilter
8456 * @method {String} name Comma separated list of nodes to collect.
8457 * @param {function} callback Callback function to execute once it has collected nodes.
8459 addAttributeFilter: htmlParser.addAttributeFilter,
8462 * Serializes the specified browser DOM node into a HTML string.
8465 * @param {DOMNode} node DOM node to serialize.
8466 * @param {Object} args Arguments option that gets passed to event handlers.
8468 serialize: function(node, args) {
8469 var self = this, impl, doc, oldDoc, htmlSerializer, content;
8471 // Explorer won't clone contents of script and style and the
8472 // selected index of select elements are cleared on a clone operation.
8473 if (Env.ie && dom.select('script,style,select,map').length > 0) {
8474 content = node.innerHTML;
8475 node = node.cloneNode(false);
8476 dom.setHTML(node, content);
8478 node = node.cloneNode(true);
8481 // Nodes needs to be attached to something in WebKit/Opera
8482 // This fix will make DOM ranges and make Sizzle happy!
8483 impl = node.ownerDocument.implementation;
8484 if (impl.createHTMLDocument) {
8485 // Create an empty HTML document
8486 doc = impl.createHTMLDocument("");
8488 // Add the element or it's children if it's a body element to the new document
8489 each(node.nodeName == 'BODY' ? node.childNodes : [node], function(node) {
8490 doc.body.appendChild(doc.importNode(node, true));
8493 // Grab first child or body element for serialization
8494 if (node.nodeName != 'BODY') {
8495 node = doc.body.firstChild;
8500 // set the new document in DOMUtils so createElement etc works
8506 args.format = args.format || 'html';
8508 // Don't wrap content if we want selected html
8509 if (args.selection) {
8510 args.forced_root_block = '';
8514 if (!args.no_events) {
8516 self.onPreProcess(args);
8520 htmlSerializer = new Serializer(settings, schema);
8522 // Parse and serialize HTML
8523 args.content = htmlSerializer.serialize(
8524 htmlParser.parse(trim(args.getInner ? node.innerHTML : dom.getOuterHTML(node)), args)
8527 // Replace all BOM characters for now until we can find a better solution
8528 if (!args.cleanup) {
8529 args.content = args.content.replace(/\uFEFF/g, '');
8533 if (!args.no_events) {
8534 self.onPostProcess(args);
8537 // Restore the old document if it was changed
8544 return args.content;
8548 * Adds valid elements rules to the serializers schema instance this enables you to specify things
8549 * like what elements should be outputted and what attributes specific elements might have.
8550 * Consult the Wiki for more details on this format.
8553 * @param {String} rules Valid elements rules string to add to schema.
8555 addRules: function(rules) {
8556 schema.addValidElements(rules);
8560 * Sets the valid elements rules to the serializers schema instance this enables you to specify things
8561 * like what elements should be outputted and what attributes specific elements might have.
8562 * Consult the Wiki for more details on this format.
8565 * @param {String} rules Valid elements rules string.
8567 setRules: function(rules) {
8568 schema.setValidElements(rules);
8571 onPreProcess: function(args) {
8573 editor.fire('PreProcess', args);
8577 onPostProcess: function(args) {
8579 editor.fire('PostProcess', args);
8586 // Included from: js/tinymce/classes/dom/TridentSelection.js
8589 * TridentSelection.js
8591 * Copyright, Moxiecode Systems AB
8592 * Released under LGPL License.
8594 * License: http://www.tinymce.com/license
8595 * Contributing: http://www.tinymce.com/contributing
8599 * Selection class for old explorer versions. This one fakes the
8600 * native selection object available on modern browsers.
8602 * @class tinymce.dom.TridentSelection
8604 define("tinymce/dom/TridentSelection", [], function() {
8605 function Selection(selection) {
8606 var self = this, dom = selection.dom, FALSE = false;
8608 function getPosition(rng, start) {
8609 var checkRng, startIndex = 0, endIndex, inside,
8610 children, child, offset, index, position = -1, parent;
8612 // Setup test range, collapse it and get the parent
8613 checkRng = rng.duplicate();
8614 checkRng.collapse(start);
8615 parent = checkRng.parentElement();
8617 // Check if the selection is within the right document
8618 if (parent.ownerDocument !== selection.dom.doc) {
8622 // IE will report non editable elements as it's parent so look for an editable one
8623 while (parent.contentEditable === "false") {
8624 parent = parent.parentNode;
8627 // If parent doesn't have any children then return that we are inside the element
8628 if (!parent.hasChildNodes()) {
8629 return {node: parent, inside: 1};
8632 // Setup node list and endIndex
8633 children = parent.children;
8634 endIndex = children.length - 1;
8636 // Perform a binary search for the position
8637 while (startIndex <= endIndex) {
8638 index = Math.floor((startIndex + endIndex) / 2);
8640 // Move selection to node and compare the ranges
8641 child = children[index];
8642 checkRng.moveToElementText(child);
8643 position = checkRng.compareEndPoints(start ? 'StartToStart' : 'EndToEnd', rng);
8645 // Before/after or an exact match
8647 endIndex = index - 1;
8648 } else if (position < 0) {
8649 startIndex = index + 1;
8651 return {node: child};
8655 // Check if child position is before or we didn't find a position
8657 // No element child was found use the parent element and the offset inside that
8659 checkRng.moveToElementText(parent);
8660 checkRng.collapse(true);
8664 checkRng.collapse(false);
8667 // Walk character by character in text node until we hit the selected range endpoint,
8668 // hit the end of document or parent isn't the right one
8669 // We need to walk char by char since rng.text or rng.htmlText will trim line endings
8671 while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
8672 if (checkRng.move('character', 1) === 0 || parent != checkRng.parentElement()) {
8679 // Child position is after the selection endpoint
8680 checkRng.collapse(true);
8682 // Walk character by character in text node until we hit the selected range endpoint, hit
8683 // the end of document or parent isn't the right one
8685 while (checkRng.compareEndPoints(start ? 'StartToStart' : 'StartToEnd', rng) !== 0) {
8686 if (checkRng.move('character', -1) === 0 || parent != checkRng.parentElement()) {
8694 return {node: child, position: position, offset: offset, inside: inside};
8697 // Returns a W3C DOM compatible range object by using the IE Range API
8698 function getRange() {
8699 var ieRange = selection.getRng(), domRange = dom.createRng(), element, collapsed, tmpRange, element2, bookmark;
8701 // If selection is outside the current document just return an empty range
8702 element = ieRange.item ? ieRange.item(0) : ieRange.parentElement();
8703 if (element.ownerDocument != dom.doc) {
8707 collapsed = selection.isCollapsed();
8709 // Handle control selection
8711 domRange.setStart(element.parentNode, dom.nodeIndex(element));
8712 domRange.setEnd(domRange.startContainer, domRange.startOffset + 1);
8717 function findEndPoint(start) {
8718 var endPoint = getPosition(ieRange, start), container, offset, textNodeOffset = 0, sibling, undef, nodeValue;
8720 container = endPoint.node;
8721 offset = endPoint.offset;
8723 if (endPoint.inside && !container.hasChildNodes()) {
8724 domRange[start ? 'setStart' : 'setEnd'](container, 0);
8728 if (offset === undef) {
8729 domRange[start ? 'setStartBefore' : 'setEndAfter'](container);
8733 if (endPoint.position < 0) {
8734 sibling = endPoint.inside ? container.firstChild : container.nextSibling;
8737 domRange[start ? 'setStartAfter' : 'setEndAfter'](container);
8742 if (sibling.nodeType == 3) {
8743 domRange[start ? 'setStart' : 'setEnd'](sibling, 0);
8745 domRange[start ? 'setStartBefore' : 'setEndBefore'](sibling);
8751 // Find the text node and offset
8753 nodeValue = sibling.nodeValue;
8754 textNodeOffset += nodeValue.length;
8756 // We are at or passed the position we where looking for
8757 if (textNodeOffset >= offset) {
8758 container = sibling;
8759 textNodeOffset -= offset;
8760 textNodeOffset = nodeValue.length - textNodeOffset;
8764 sibling = sibling.nextSibling;
8767 // Find the text node and offset
8768 sibling = container.previousSibling;
8771 return domRange[start ? 'setStartBefore' : 'setEndBefore'](container);
8774 // If there isn't any text to loop then use the first position
8776 if (container.nodeType == 3) {
8777 domRange[start ? 'setStart' : 'setEnd'](sibling, container.nodeValue.length);
8779 domRange[start ? 'setStartAfter' : 'setEndAfter'](sibling);
8786 textNodeOffset += sibling.nodeValue.length;
8788 // We are at or passed the position we where looking for
8789 if (textNodeOffset >= offset) {
8790 container = sibling;
8791 textNodeOffset -= offset;
8795 sibling = sibling.previousSibling;
8799 domRange[start ? 'setStart' : 'setEnd'](container, textNodeOffset);
8806 // Find end point if needed
8811 // IE has a nasty bug where text nodes might throw "invalid argument" when you
8812 // access the nodeValue or other properties of text nodes. This seems to happend when
8813 // text nodes are split into two nodes by a delete/backspace call. So lets detect it and try to fix it.
8814 if (ex.number == -2147024809) {
8815 // Get the current selection
8816 bookmark = self.getBookmark(2);
8818 // Get start element
8819 tmpRange = ieRange.duplicate();
8820 tmpRange.collapse(true);
8821 element = tmpRange.parentElement();
8825 tmpRange = ieRange.duplicate();
8826 tmpRange.collapse(false);
8827 element2 = tmpRange.parentElement();
8828 element2.innerHTML = element2.innerHTML;
8831 // Remove the broken elements
8832 element.innerHTML = element.innerHTML;
8834 // Restore the selection
8835 self.moveToBookmark(bookmark);
8837 // Since the range has moved we need to re-get it
8838 ieRange = selection.getRng();
8843 // Find end point if needed
8848 throw ex; // Throw other errors
8855 this.getBookmark = function(type) {
8856 var rng = selection.getRng(), bookmark = {};
8858 function getIndexes(node) {
8859 var parent, root, children, i, indexes = [];
8861 parent = node.parentNode;
8862 root = dom.getRoot().parentNode;
8864 while (parent != root && parent.nodeType !== 9) {
8865 children = parent.children;
8867 i = children.length;
8869 if (node === children[i]) {
8876 parent = parent.parentNode;
8882 function getBookmarkEndPoint(start) {
8885 position = getPosition(rng, start);
8888 position: position.position,
8889 offset: position.offset,
8890 indexes: getIndexes(position.node),
8891 inside: position.inside
8896 // Non ubstructive bookmark
8898 // Handle text selection
8900 bookmark.start = getBookmarkEndPoint(true);
8902 if (!selection.isCollapsed()) {
8903 bookmark.end = getBookmarkEndPoint();
8906 bookmark.start = {ctrl: true, indexes: getIndexes(rng.item(0))};
8913 this.moveToBookmark = function(bookmark) {
8914 var rng, body = dom.doc.body;
8916 function resolveIndexes(indexes) {
8917 var node, i, idx, children;
8919 node = dom.getRoot();
8920 for (i = indexes.length - 1; i >= 0; i--) {
8921 children = node.children;
8924 if (idx <= children.length - 1) {
8925 node = children[idx];
8932 function setBookmarkEndPoint(start) {
8933 var endPoint = bookmark[start ? 'start' : 'end'], moveLeft, moveRng, undef, offset;
8936 moveLeft = endPoint.position > 0;
8938 moveRng = body.createTextRange();
8939 moveRng.moveToElementText(resolveIndexes(endPoint.indexes));
8941 offset = endPoint.offset;
8942 if (offset !== undef) {
8943 moveRng.collapse(endPoint.inside || moveLeft);
8944 moveRng.moveStart('character', moveLeft ? -offset : offset);
8946 moveRng.collapse(start);
8949 rng.setEndPoint(start ? 'StartToStart' : 'EndToStart', moveRng);
8957 if (bookmark.start) {
8958 if (bookmark.start.ctrl) {
8959 rng = body.createControlRange();
8960 rng.addElement(resolveIndexes(bookmark.start.indexes));
8963 rng = body.createTextRange();
8964 setBookmarkEndPoint(true);
8965 setBookmarkEndPoint();
8971 this.addRange = function(rng) {
8972 var ieRng, ctrlRng, startContainer, startOffset, endContainer, endOffset, sibling,
8973 doc = selection.dom.doc, body = doc.body, nativeRng, ctrlElm;
8975 function setEndPoint(start) {
8976 var container, offset, marker, tmpRng, nodes;
8978 marker = dom.create('a');
8979 container = start ? startContainer : endContainer;
8980 offset = start ? startOffset : endOffset;
8981 tmpRng = ieRng.duplicate();
8983 if (container == doc || container == doc.documentElement) {
8988 if (container.nodeType == 3) {
8989 container.parentNode.insertBefore(marker, container);
8990 tmpRng.moveToElementText(marker);
8991 tmpRng.moveStart('character', offset);
8993 ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
8995 nodes = container.childNodes;
8998 if (offset >= nodes.length) {
8999 dom.insertAfter(marker, nodes[nodes.length - 1]);
9001 container.insertBefore(marker, nodes[offset]);
9004 tmpRng.moveToElementText(marker);
9005 } else if (container.canHaveHTML) {
9006 // Empty node selection for example <div>|</div>
9007 // Setting innerHTML with a span marker then remove that marker seems to keep empty block elements open
9008 container.innerHTML = '<span></span>';
9009 marker = container.firstChild;
9010 tmpRng.moveToElementText(marker);
9011 tmpRng.collapse(FALSE); // Collapse false works better than true for some odd reason
9014 ieRng.setEndPoint(start ? 'StartToStart' : 'EndToEnd', tmpRng);
9019 // Setup some shorter versions
9020 startContainer = rng.startContainer;
9021 startOffset = rng.startOffset;
9022 endContainer = rng.endContainer;
9023 endOffset = rng.endOffset;
9024 ieRng = body.createTextRange();
9026 // If single element selection then try making a control selection out of it
9027 if (startContainer == endContainer && startContainer.nodeType == 1) {
9028 // Trick to place the caret inside an empty block element like <p></p>
9029 if (startOffset == endOffset && !startContainer.hasChildNodes()) {
9030 if (startContainer.canHaveHTML) {
9031 // Check if previous sibling is an empty block if it is then we need to render it
9032 // IE would otherwise move the caret into the sibling instead of the empty startContainer see: #5236
9033 // Example this: <p></p><p>|</p> would become this: <p>|</p><p></p>
9034 sibling = startContainer.previousSibling;
9035 if (sibling && !sibling.hasChildNodes() && dom.isBlock(sibling)) {
9036 sibling.innerHTML = '';
9041 startContainer.innerHTML = '<span></span><span></span>';
9042 ieRng.moveToElementText(startContainer.lastChild);
9044 dom.doc.selection.clear();
9045 startContainer.innerHTML = '';
9048 sibling.innerHTML = '';
9052 startOffset = dom.nodeIndex(startContainer);
9053 startContainer = startContainer.parentNode;
9057 if (startOffset == endOffset - 1) {
9059 ctrlElm = startContainer.childNodes[startOffset];
9060 ctrlRng = body.createControlRange();
9061 ctrlRng.addElement(ctrlElm);
9064 // Check if the range produced is on the correct element and is a control range
9065 // On IE 8 it will select the parent contentEditable container if you select an inner element see: #5398
9066 nativeRng = selection.getRng();
9067 if (nativeRng.item && ctrlElm === nativeRng.item(0)) {
9076 // Set start/end point of selection
9080 // Select the new range and scroll it into view
9084 // Expose range method
9085 this.getRangeAt = getRange;
9091 // Included from: js/tinymce/classes/util/VK.js
9096 * Copyright, Moxiecode Systems AB
9097 * Released under LGPL License.
9099 * License: http://www.tinymce.com/license
9100 * Contributing: http://www.tinymce.com/contributing
9104 * This file exposes a set of the common KeyCodes for use. Please grow it as needed.
9106 define("tinymce/util/VK", [
9120 modifierPressed: function(e) {
9121 return e.shiftKey || e.ctrlKey || e.altKey;
9124 metaKeyPressed: function(e) {
9125 // Check if ctrl or meta key is pressed also check if alt is false for Polish users
9126 return (Env.mac ? e.ctrlKey || e.metaKey : e.ctrlKey) && !e.altKey;
9131 // Included from: js/tinymce/classes/dom/ControlSelection.js
9134 * ControlSelection.js
9136 * Copyright, Moxiecode Systems AB
9137 * Released under LGPL License.
9139 * License: http://www.tinymce.com/license
9140 * Contributing: http://www.tinymce.com/contributing
9144 * This class handles control selection of elements. Controls are elements
9145 * that can be resized and needs to be selected as a whole. It adds custom resize handles
9146 * to all browser engines that support properly disabling the built in resize logic.
9148 * @class tinymce.dom.ControlSelection
9150 define("tinymce/dom/ControlSelection", [
9152 "tinymce/util/Tools",
9154 ], function(VK, Tools, Env) {
9155 return function(selection, editor) {
9156 var dom = editor.dom, each = Tools.each;
9157 var selectedElm, selectedElmGhost, resizeHandles, selectedHandle, lastMouseDownEvent;
9158 var startX, startY, selectedElmX, selectedElmY, startW, startH, ratio, resizeStarted;
9159 var width, height, editableDoc = editor.getDoc(), rootDocument = document, isIE = Env.ie && Env.ie < 11;
9161 // Details about each resize handle how to scale etc
9163 // Name: x multiplier, y multiplier, delta size x, delta size y
9174 // Add CSS for resize handles, cloned element and selected
9175 var rootClass = '.mce-content-body';
9176 editor.contentStyles.push(
9177 rootClass + ' div.mce-resizehandle {' +
9178 'position: absolute;' +
9179 'border: 1px solid black;' +
9180 'background: #FFF;' +
9185 rootClass + ' .mce-resizehandle:hover {' +
9186 'background: #000' +
9188 rootClass + ' img[data-mce-selected], hr[data-mce-selected] {' +
9189 'outline: 1px solid black;' +
9190 'resize: none' + // Have been talks about implementing this in browsers
9192 rootClass + ' .mce-clonedresizable {' +
9193 'position: absolute;' +
9194 (Env.gecko ? '' : 'outline: 1px dashed black;') + // Gecko produces trails while resizing
9196 'filter: alpha(opacity=50);' +
9201 function isResizable(elm) {
9202 if (editor.settings.object_resizing === false) {
9206 if (!/TABLE|IMG|DIV/.test(elm.nodeName)) {
9210 if (elm.getAttribute('data-mce-resize') === 'false') {
9217 function resizeGhostElement(e) {
9220 // Calc new width/height
9221 deltaX = e.screenX - startX;
9222 deltaY = e.screenY - startY;
9225 width = deltaX * selectedHandle[2] + startW;
9226 height = deltaY * selectedHandle[3] + startH;
9228 // Never scale down lower than 5 pixels
9229 width = width < 5 ? 5 : width;
9230 height = height < 5 ? 5 : height;
9232 // Constrain proportions when modifier key is pressed or if the nw, ne, sw, se corners are moved on an image
9233 if (VK.modifierPressed(e) || (selectedElm.nodeName == "IMG" && selectedHandle[2] * selectedHandle[3] !== 0)) {
9234 width = Math.round(height / ratio);
9235 height = Math.round(width * ratio);
9238 // Update ghost size
9239 dom.setStyles(selectedElmGhost, {
9244 // Update ghost X position if needed
9245 if (selectedHandle[2] < 0 && selectedElmGhost.clientWidth <= width) {
9246 dom.setStyle(selectedElmGhost, 'left', selectedElmX + (startW - width));
9249 // Update ghost Y position if needed
9250 if (selectedHandle[3] < 0 && selectedElmGhost.clientHeight <= height) {
9251 dom.setStyle(selectedElmGhost, 'top', selectedElmY + (startH - height));
9254 if (!resizeStarted) {
9255 editor.fire('ObjectResizeStart', {target: selectedElm, width: startW, height: startH});
9256 resizeStarted = true;
9260 function endGhostResize() {
9261 resizeStarted = false;
9263 function setSizeProp(name, value) {
9265 // Resize by using style or attribute
9266 if (selectedElm.style[name] || !editor.schema.isValid(selectedElm.nodeName.toLowerCase(), name)) {
9267 dom.setStyle(selectedElm, name, value);
9269 dom.setAttrib(selectedElm, name, value);
9274 // Set width/height properties
9275 setSizeProp('width', width);
9276 setSizeProp('height', height);
9278 dom.unbind(editableDoc, 'mousemove', resizeGhostElement);
9279 dom.unbind(editableDoc, 'mouseup', endGhostResize);
9281 if (rootDocument != editableDoc) {
9282 dom.unbind(rootDocument, 'mousemove', resizeGhostElement);
9283 dom.unbind(rootDocument, 'mouseup', endGhostResize);
9286 // Remove ghost and update resize handle positions
9287 dom.remove(selectedElmGhost);
9289 if (!isIE || selectedElm.nodeName == "TABLE") {
9290 showResizeRect(selectedElm);
9293 editor.fire('ObjectResized', {target: selectedElm, width: width, height: height});
9294 editor.nodeChanged();
9297 function showResizeRect(targetElm, mouseDownHandleName, mouseDownEvent) {
9298 var position, targetWidth, targetHeight, e, rect;
9300 // Fix when inline element is within a relaive container
9301 var offsetParent = editor.getBody().offsetParent || editor.getBody();
9303 // Get position and size of target
9304 position = dom.getPos(targetElm, offsetParent);
9305 selectedElmX = position.x;
9306 selectedElmY = position.y;
9307 rect = targetElm.getBoundingClientRect(); // Fix for Gecko offsetHeight for table with caption
9308 targetWidth = rect.width || (rect.right - rect.left);
9309 targetHeight = rect.height || (rect.bottom - rect.top);
9311 // Reset width/height if user selects a new image/table
9312 if (selectedElm != targetElm) {
9313 detachResizeStartListener();
9314 selectedElm = targetElm;
9318 // Makes it possible to disable resizing
9319 e = editor.fire('ObjectSelected', {target: targetElm});
9321 if (isResizable(targetElm) && !e.isDefaultPrevented()) {
9322 each(resizeHandles, function(handle, name) {
9323 var handleElm, handlerContainerElm;
9325 function startDrag(e) {
9326 resizeStarted = true;
9330 startW = selectedElm.clientWidth;
9331 startH = selectedElm.clientHeight;
9332 ratio = startH / startW;
9333 selectedHandle = handle;
9335 selectedElmGhost = selectedElm.cloneNode(true);
9336 dom.addClass(selectedElmGhost, 'mce-clonedresizable');
9337 selectedElmGhost.contentEditable = false; // Hides IE move layer cursor
9338 selectedElmGhost.unSelectabe = true;
9339 dom.setStyles(selectedElmGhost, {
9345 selectedElmGhost.removeAttribute('data-mce-selected');
9346 editor.getBody().appendChild(selectedElmGhost);
9348 dom.bind(editableDoc, 'mousemove', resizeGhostElement);
9349 dom.bind(editableDoc, 'mouseup', endGhostResize);
9351 if (rootDocument != editableDoc) {
9352 dom.bind(rootDocument, 'mousemove', resizeGhostElement);
9353 dom.bind(rootDocument, 'mouseup', endGhostResize);
9357 if (mouseDownHandleName) {
9358 // Drag started by IE native resizestart
9359 if (name == mouseDownHandleName) {
9360 startDrag(mouseDownEvent);
9366 // Get existing or render resize handle
9367 handleElm = dom.get('mceResizeHandle' + name);
9369 handlerContainerElm = editor.getBody();
9371 handleElm = dom.add(handlerContainerElm, 'div', {
9372 id: 'mceResizeHandle' + name,
9373 'data-mce-bogus': true,
9374 'class': 'mce-resizehandle',
9375 contentEditable: false, // Hides IE move layer cursor
9377 style: 'cursor:' + name + '-resize; margin:0; padding:0'
9380 dom.bind(handleElm, 'mousedown', function(e) {
9385 dom.show(handleElm);
9389 var halfHandleW = handleElm.offsetWidth / 2;
9390 var halfHandleH = handleElm.offsetHeight / 2;
9393 dom.setStyles(handleElm, {
9394 left: Math.floor((targetWidth * handle[0] + selectedElmX) - halfHandleW + (handle[2] * halfHandleW)),
9395 top: Math.floor((targetHeight * handle[1] + selectedElmY) - halfHandleH + (handle[3] * halfHandleH))
9400 dom.setStyles(handleElm, {
9401 left: (targetWidth * handle[0] + selectedElmX) - (handleElm.offsetWidth / 2),
9402 top: (targetHeight * handle[1] + selectedElmY) - (handleElm.offsetHeight / 2)
9409 selectedElm.setAttribute('data-mce-selected', '1');
9412 function hideResizeRect() {
9413 var name, handleElm;
9416 selectedElm.removeAttribute('data-mce-selected');
9419 for (name in resizeHandles) {
9420 handleElm = dom.get('mceResizeHandle' + name);
9422 dom.unbind(handleElm);
9423 dom.remove(handleElm);
9428 function updateResizeRect(e) {
9431 function isChildOrEqual(node, parent) {
9433 if (node === parent) {
9436 } while ((node = node.parentNode));
9439 // Remove data-mce-selected from all elements since they might have been copied using Ctrl+c/v
9440 each(dom.select('img[data-mce-selected],hr[data-mce-selected]'), function(img) {
9441 img.removeAttribute('data-mce-selected');
9444 controlElm = e.type == 'mousedown' ? e.target : selection.getNode();
9445 controlElm = dom.getParent(controlElm, isIE ? 'table' : 'table,img,hr');
9448 disableGeckoResize();
9450 if (isChildOrEqual(selection.getStart(), controlElm) && isChildOrEqual(selection.getEnd(), controlElm)) {
9451 if (!isIE || (controlElm != selection.getStart() && selection.getStart().nodeName !== 'IMG')) {
9452 showResizeRect(controlElm);
9461 function attachEvent(elm, name, func) {
9462 if (elm && elm.attachEvent) {
9463 elm.attachEvent('on' + name, func);
9467 function detachEvent(elm, name, func) {
9468 if (elm && elm.detachEvent) {
9469 elm.detachEvent('on' + name, func);
9473 function resizeNativeStart(e) {
9474 var target = e.srcElement, pos, name, corner, cornerX, cornerY, relativeX, relativeY;
9476 pos = target.getBoundingClientRect();
9477 relativeX = lastMouseDownEvent.clientX - pos.left;
9478 relativeY = lastMouseDownEvent.clientY - pos.top;
9480 // Figure out what corner we are draging on
9481 for (name in resizeHandles) {
9482 corner = resizeHandles[name];
9484 cornerX = target.offsetWidth * corner[0];
9485 cornerY = target.offsetHeight * corner[1];
9487 if (Math.abs(cornerX - relativeX) < 8 && Math.abs(cornerY - relativeY) < 8) {
9488 selectedHandle = corner;
9493 // Remove native selection and let the magic begin
9494 resizeStarted = true;
9495 editor.getDoc().selection.empty();
9496 showResizeRect(target, name, lastMouseDownEvent);
9499 function nativeControlSelect(e) {
9500 var target = e.srcElement;
9502 if (target != selectedElm) {
9503 detachResizeStartListener();
9505 if (target.id.indexOf('mceResizeHandle') === 0) {
9506 e.returnValue = false;
9510 if (target.nodeName == 'IMG' || target.nodeName == 'TABLE') {
9512 selectedElm = target;
9513 attachEvent(target, 'resizestart', resizeNativeStart);
9518 function detachResizeStartListener() {
9519 detachEvent(selectedElm, 'resizestart', resizeNativeStart);
9522 function disableGeckoResize() {
9524 // Disable object resizing on Gecko
9525 editor.getDoc().execCommand('enableObjectResizing', false, false);
9531 function controlSelect(elm) {
9538 ctrlRng = editableDoc.body.createControlRange();
9541 ctrlRng.addElement(elm);
9545 // Ignore since the element can't be control selected for example a P tag
9549 editor.on('init', function() {
9551 // Hide the resize rect on resize and reselect the image
9552 editor.on('ObjectResized', function(e) {
9553 if (e.target.nodeName != 'TABLE') {
9555 controlSelect(e.target);
9559 attachEvent(editor.getBody(), 'controlselect', nativeControlSelect);
9561 editor.on('mousedown', function(e) {
9562 lastMouseDownEvent = e;
9565 disableGeckoResize();
9568 // TODO: Drag/drop doesn't work
9569 editor.on('mouseup mousedown', function(e) {
9570 if (e.target.nodeName == 'IMG' || editor.selection.getNode().nodeName == 'IMG') {
9572 editor.selection.select(e.target);
9578 editor.on('nodechange mousedown ResizeEditor', updateResizeRect);
9580 // Update resize rect while typing in a table
9581 editor.on('keydown keyup', function(e) {
9582 if (selectedElm && selectedElm.nodeName == "TABLE") {
9583 updateResizeRect(e);
9587 // Hide rect on focusout since it would float on top of windows otherwise
9588 //editor.on('focusout', hideResizeRect);
9591 function destroy() {
9592 selectedElm = selectedElmGhost = null;
9595 detachResizeStartListener();
9596 detachEvent(editor.getBody(), 'controlselect', nativeControlSelect);
9601 controlSelect: controlSelect,
9607 // Included from: js/tinymce/classes/dom/Selection.js
9612 * Copyright, Moxiecode Systems AB
9613 * Released under LGPL License.
9615 * License: http://www.tinymce.com/license
9616 * Contributing: http://www.tinymce.com/contributing
9620 * This class handles text and control selection it's an crossbrowser utility class.
9621 * Consult the TinyMCE Wiki API for more details and examples on how to use this class.
9623 * @class tinymce.dom.Selection
9625 * // Getting the currently selected node for the active editor
9626 * alert(tinymce.activeEditor.selection.getNode().nodeName);
9628 define("tinymce/dom/Selection", [
9629 "tinymce/dom/TreeWalker",
9630 "tinymce/dom/TridentSelection",
9631 "tinymce/dom/ControlSelection",
9633 "tinymce/util/Tools"
9634 ], function(TreeWalker, TridentSelection, ControlSelection, Env, Tools) {
9635 var each = Tools.each, grep = Tools.grep, trim = Tools.trim;
9636 var isIE = Env.ie, isOpera = Env.opera;
9639 * Constructs a new selection instance.
9643 * @param {tinymce.dom.DOMUtils} dom DOMUtils object reference.
9644 * @param {Window} win Window to bind the selection object to.
9645 * @param {tinymce.dom.Serializer} serializer DOM serialization class to use for getContent.
9647 function Selection(dom, win, serializer, editor) {
9652 self.serializer = serializer;
9653 self.editor = editor;
9655 self.controlSelection = new ControlSelection(self, editor);
9657 // No W3C Range support
9658 if (!self.win.getSelection) {
9659 self.tridentSel = new TridentSelection(self);
9663 Selection.prototype = {
9665 * Move the selection cursor range to the specified node and offset.
9667 * @method setCursorLocation
9668 * @param {Node} node Node to put the cursor in.
9669 * @param {Number} offset Offset from the start of the node to put the cursor at.
9671 setCursorLocation: function(node, offset) {
9672 var self = this, rng = self.dom.createRng();
9673 rng.setStart(node, offset);
9674 rng.setEnd(node, offset);
9676 self.collapse(false);
9680 * Returns the selected contents using the DOM serializer passed in to this class.
9682 * @method getContent
9683 * @param {Object} s Optional settings class with for example output format text or html.
9684 * @return {String} Selected contents in for example HTML format.
9686 * // Alerts the currently selected contents
9687 * alert(tinymce.activeEditor.selection.getContent());
9689 * // Alerts the currently selected contents as plain text
9690 * alert(tinymce.activeEditor.selection.getContent({format: 'text'}));
9692 getContent: function(args) {
9693 var self = this, rng = self.getRng(), tmpElm = self.dom.create("body");
9694 var se = self.getSel(), whiteSpaceBefore, whiteSpaceAfter, fragment;
9697 whiteSpaceBefore = whiteSpaceAfter = '';
9699 args.format = args.format || 'html';
9700 args.selection = true;
9701 self.editor.fire('BeforeGetContent', args);
9703 if (args.format == 'text') {
9704 return self.isCollapsed() ? '' : (rng.text || (se.toString ? se.toString() : ''));
9707 if (rng.cloneContents) {
9708 fragment = rng.cloneContents();
9711 tmpElm.appendChild(fragment);
9713 } else if (rng.item !== undefined || rng.htmlText !== undefined) {
9714 // IE will produce invalid markup if elements are present that
9715 // it doesn't understand like custom elements or HTML5 elements.
9716 // Adding a BR in front of the contents and then remoiving it seems to fix it though.
9717 tmpElm.innerHTML = '<br>' + (rng.item ? rng.item(0).outerHTML : rng.htmlText);
9718 tmpElm.removeChild(tmpElm.firstChild);
9720 tmpElm.innerHTML = rng.toString();
9723 // Keep whitespace before and after
9724 if (/^\s/.test(tmpElm.innerHTML)) {
9725 whiteSpaceBefore = ' ';
9728 if (/\s+$/.test(tmpElm.innerHTML)) {
9729 whiteSpaceAfter = ' ';
9732 args.getInner = true;
9734 args.content = self.isCollapsed() ? '' : whiteSpaceBefore + self.serializer.serialize(tmpElm, args) + whiteSpaceAfter;
9735 self.editor.fire('GetContent', args);
9737 return args.content;
9741 * Sets the current selection to the specified content. If any contents is selected it will be replaced
9742 * with the contents passed in to this function. If there is no selection the contents will be inserted
9743 * where the caret is placed in the editor/page.
9745 * @method setContent
9746 * @param {String} content HTML contents to set could also be other formats depending on settings.
9747 * @param {Object} args Optional settings object with for example data format.
9749 * // Inserts some HTML contents at the current selection
9750 * tinymce.activeEditor.selection.setContent('<strong>Some contents</strong>');
9752 setContent: function(content, args) {
9753 var self = this, rng = self.getRng(), caretNode, doc = self.win.document, frag, temp;
9755 args = args || {format: 'html'};
9757 args.selection = true;
9758 content = args.content = content;
9760 // Dispatch before set content event
9761 if (!args.no_events) {
9762 self.editor.fire('BeforeSetContent', args);
9765 content = args.content;
9767 if (rng.insertNode) {
9768 // Make caret marker since insertNode places the caret in the beginning of text after insert
9769 content += '<span id="__caret">_</span>';
9771 // Delete and insert new node
9772 if (rng.startContainer == doc && rng.endContainer == doc) {
9773 // WebKit will fail if the body is empty since the range is then invalid and it can't insert contents
9774 doc.body.innerHTML = content;
9776 rng.deleteContents();
9778 if (doc.body.childNodes.length === 0) {
9779 doc.body.innerHTML = content;
9781 // createContextualFragment doesn't exists in IE 9 DOMRanges
9782 if (rng.createContextualFragment) {
9783 rng.insertNode(rng.createContextualFragment(content));
9785 // Fake createContextualFragment call in IE 9
9786 frag = doc.createDocumentFragment();
9787 temp = doc.createElement('div');
9789 frag.appendChild(temp);
9790 temp.outerHTML = content;
9792 rng.insertNode(frag);
9797 // Move to caret marker
9798 caretNode = self.dom.get('__caret');
9800 // Make sure we wrap it compleatly, Opera fails with a simple select call
9801 rng = doc.createRange();
9802 rng.setStartBefore(caretNode);
9803 rng.setEndBefore(caretNode);
9806 // Remove the caret position
9807 self.dom.remove('__caret');
9812 // Might fail on Opera for some odd reason
9816 // Delete content and get caret text selection
9817 doc.execCommand('Delete', false, null);
9818 rng = self.getRng();
9821 // Explorer removes spaces from the beginning of pasted contents
9822 if (/^\s+/.test(content)) {
9823 rng.pasteHTML('<span id="__mce_tmp">_</span>' + content);
9824 self.dom.remove('__mce_tmp');
9826 rng.pasteHTML(content);
9830 // Dispatch set content event
9831 if (!args.no_events) {
9832 self.editor.fire('SetContent', args);
9837 * Returns the start element of a selection range. If the start is in a text
9838 * node the parent element will be returned.
9841 * @return {Element} Start element of selection range.
9843 getStart: function() {
9844 var self = this, rng = self.getRng(), startElement, parentElement, checkRng, node;
9846 if (rng.duplicate || rng.item) {
9847 // Control selection, return first item
9852 // Get start element
9853 checkRng = rng.duplicate();
9854 checkRng.collapse(1);
9855 startElement = checkRng.parentElement();
9856 if (startElement.ownerDocument !== self.dom.doc) {
9857 startElement = self.dom.getRoot();
9860 // Check if range parent is inside the start element, then return the inner parent element
9861 // This will fix issues when a single element is selected, IE would otherwise return the wrong start element
9862 parentElement = node = rng.parentElement();
9863 while ((node = node.parentNode)) {
9864 if (node == startElement) {
9865 startElement = parentElement;
9870 return startElement;
9872 startElement = rng.startContainer;
9874 if (startElement.nodeType == 1 && startElement.hasChildNodes()) {
9875 startElement = startElement.childNodes[Math.min(startElement.childNodes.length - 1, rng.startOffset)];
9878 if (startElement && startElement.nodeType == 3) {
9879 return startElement.parentNode;
9882 return startElement;
9887 * Returns the end element of a selection range. If the end is in a text
9888 * node the parent element will be returned.
9891 * @return {Element} End element of selection range.
9893 getEnd: function() {
9894 var self = this, rng = self.getRng(), endElement, endOffset;
9896 if (rng.duplicate || rng.item) {
9901 rng = rng.duplicate();
9903 endElement = rng.parentElement();
9904 if (endElement.ownerDocument !== self.dom.doc) {
9905 endElement = self.dom.getRoot();
9908 if (endElement && endElement.nodeName == 'BODY') {
9909 return endElement.lastChild || endElement;
9914 endElement = rng.endContainer;
9915 endOffset = rng.endOffset;
9917 if (endElement.nodeType == 1 && endElement.hasChildNodes()) {
9918 endElement = endElement.childNodes[endOffset > 0 ? endOffset - 1 : endOffset];
9921 if (endElement && endElement.nodeType == 3) {
9922 return endElement.parentNode;
9930 * Returns a bookmark location for the current selection. This bookmark object
9931 * can then be used to restore the selection after some content modification to the document.
9933 * @method getBookmark
9934 * @param {Number} type Optional state if the bookmark should be simple or not. Default is complex.
9935 * @param {Boolean} normalized Optional state that enables you to get a position that it would be after normalization.
9936 * @return {Object} Bookmark object, use moveToBookmark with this object to restore the selection.
9938 * // Stores a bookmark of the current selection
9939 * var bm = tinymce.activeEditor.selection.getBookmark();
9941 * tinymce.activeEditor.setContent(tinymce.activeEditor.getContent() + 'Some new content');
9943 * // Restore the selection bookmark
9944 * tinymce.activeEditor.selection.moveToBookmark(bm);
9946 getBookmark: function(type, normalized) {
9947 var t = this, dom = t.dom, rng, rng2, id, collapsed, name, element, chr = '', styles;
9949 function findIndex(name, element) {
9952 each(dom.select(name), function(node, i) {
9953 if (node == element) {
9961 function normalizeTableCellSelection(rng) {
9962 function moveEndPoint(start) {
9963 var container, offset, childNodes, prefix = start ? 'start' : 'end';
9965 container = rng[prefix + 'Container'];
9966 offset = rng[prefix + 'Offset'];
9968 if (container.nodeType == 1 && container.nodeName == "TR") {
9969 childNodes = container.childNodes;
9970 container = childNodes[Math.min(start ? offset : offset - 1, childNodes.length - 1)];
9972 offset = start ? 0 : container.childNodes.length;
9973 rng['set' + (start ? 'Start' : 'End')](container, offset);
9984 function getLocation() {
9985 var rng = t.getRng(true), root = dom.getRoot(), bookmark = {};
9987 function getPoint(rng, start) {
9988 var container = rng[start ? 'startContainer' : 'endContainer'],
9989 offset = rng[start ? 'startOffset' : 'endOffset'], point = [], node, childNodes, after = 0;
9991 if (container.nodeType == 3) {
9993 for (node = container.previousSibling; node && node.nodeType == 3; node = node.previousSibling) {
9994 offset += node.nodeValue.length;
10000 childNodes = container.childNodes;
10002 if (offset >= childNodes.length && childNodes.length) {
10004 offset = Math.max(0, childNodes.length - 1);
10007 point.push(t.dom.nodeIndex(childNodes[offset], normalized) + after);
10010 for (; container && container != root; container = container.parentNode) {
10011 point.push(t.dom.nodeIndex(container, normalized));
10017 bookmark.start = getPoint(rng, true);
10019 if (!t.isCollapsed()) {
10020 bookmark.end = getPoint(rng);
10027 element = t.getNode();
10028 name = element.nodeName;
10030 if (name == 'IMG') {
10031 return {name: name, index: findIndex(name, element)};
10034 if (t.tridentSel) {
10035 return t.tridentSel.getBookmark(type);
10038 return getLocation();
10041 // Handle simple range
10043 return {rng: t.getRng()};
10047 id = dom.uniqueId();
10048 collapsed = t.isCollapsed();
10049 styles = 'overflow:hidden;line-height:0px';
10052 if (rng.duplicate || rng.item) {
10055 rng2 = rng.duplicate();
10058 // Insert start marker
10060 rng.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_start" style="' + styles + '">' + chr + '</span>');
10062 // Insert end marker
10064 rng2.collapse(false);
10066 // Detect the empty space after block elements in IE and move the
10067 // end back one character <p></p>] becomes <p>]</p>
10068 rng.moveToElementText(rng2.parentElement());
10069 if (rng.compareEndPoints('StartToEnd', rng2) === 0) {
10070 rng2.move('character', -1);
10073 rng2.pasteHTML('<span data-mce-type="bookmark" id="' + id + '_end" style="' + styles + '">' + chr + '</span>');
10076 // IE might throw unspecified error so lets ignore it
10080 // Control selection
10081 element = rng.item(0);
10082 name = element.nodeName;
10084 return {name: name, index: findIndex(name, element)};
10087 element = t.getNode();
10088 name = element.nodeName;
10089 if (name == 'IMG') {
10090 return {name: name, index: findIndex(name, element)};
10094 rng2 = normalizeTableCellSelection(rng.cloneRange());
10096 // Insert end marker
10098 rng2.collapse(false);
10099 rng2.insertNode(dom.create('span', {'data-mce-type': "bookmark", id: id + '_end', style: styles}, chr));
10102 rng = normalizeTableCellSelection(rng);
10103 rng.collapse(true);
10104 rng.insertNode(dom.create('span', {'data-mce-type': "bookmark", id: id + '_start', style: styles}, chr));
10107 t.moveToBookmark({id: id, keep: 1});
10113 * Restores the selection to the specified bookmark.
10115 * @method moveToBookmark
10116 * @param {Object} bookmark Bookmark to restore selection from.
10117 * @return {Boolean} true/false if it was successful or not.
10119 * // Stores a bookmark of the current selection
10120 * var bm = tinymce.activeEditor.selection.getBookmark();
10122 * tinymce.activeEditor.setContent(tinymce.activeEditor.getContent() + 'Some new content');
10124 * // Restore the selection bookmark
10125 * tinymce.activeEditor.selection.moveToBookmark(bm);
10127 moveToBookmark: function(bookmark) {
10128 var t = this, dom = t.dom, rng, root, startContainer, endContainer, startOffset, endOffset;
10130 function setEndPoint(start) {
10131 var point = bookmark[start ? 'start' : 'end'], i, node, offset, children;
10136 // Find container node
10137 for (node = root, i = point.length - 1; i >= 1; i--) {
10138 children = node.childNodes;
10140 if (point[i] > children.length - 1) {
10144 node = children[point[i]];
10147 // Move text offset to best suitable location
10148 if (node.nodeType === 3) {
10149 offset = Math.min(point[0], node.nodeValue.length);
10152 // Move element offset to best suitable location
10153 if (node.nodeType === 1) {
10154 offset = Math.min(point[0], node.childNodes.length);
10157 // Set offset within container node
10159 rng.setStart(node, offset);
10161 rng.setEnd(node, offset);
10168 function restoreEndPoint(suffix) {
10169 var marker = dom.get(bookmark.id + '_' + suffix), node, idx, next, prev, keep = bookmark.keep;
10172 node = marker.parentNode;
10174 if (suffix == 'start') {
10176 idx = dom.nodeIndex(marker);
10178 node = marker.firstChild;
10182 startContainer = endContainer = node;
10183 startOffset = endOffset = idx;
10186 idx = dom.nodeIndex(marker);
10188 node = marker.firstChild;
10192 endContainer = node;
10197 prev = marker.previousSibling;
10198 next = marker.nextSibling;
10200 // Remove all marker text nodes
10201 each(grep(marker.childNodes), function(node) {
10202 if (node.nodeType == 3) {
10203 node.nodeValue = node.nodeValue.replace(/\uFEFF/g, '');
10207 // Remove marker but keep children if for example contents where inserted into the marker
10208 // Also remove duplicated instances of the marker for example by a
10209 // split operation or by WebKit auto split on paste feature
10210 while ((marker = dom.get(bookmark.id + '_' + suffix))) {
10211 dom.remove(marker, 1);
10214 // If siblings are text nodes then merge them unless it's Opera since it some how removes the node
10215 // and we are sniffing since adding a lot of detection code for a browser with 3% of the market
10216 // isn't worth the effort. Sorry, Opera but it's just a fact
10217 if (prev && next && prev.nodeType == next.nodeType && prev.nodeType == 3 && !isOpera) {
10218 idx = prev.nodeValue.length;
10219 prev.appendData(next.nodeValue);
10222 if (suffix == 'start') {
10223 startContainer = endContainer = prev;
10224 startOffset = endOffset = idx;
10226 endContainer = prev;
10234 function addBogus(node) {
10235 // Adds a bogus BR element for empty block elements
10236 if (dom.isBlock(node) && !node.innerHTML && !isIE) {
10237 node.innerHTML = '<br data-mce-bogus="1" />';
10244 if (bookmark.start) {
10245 rng = dom.createRng();
10246 root = dom.getRoot();
10248 if (t.tridentSel) {
10249 return t.tridentSel.moveToBookmark(bookmark);
10252 if (setEndPoint(true) && setEndPoint()) {
10255 } else if (bookmark.id) {
10256 // Restore start/end points
10257 restoreEndPoint('start');
10258 restoreEndPoint('end');
10260 if (startContainer) {
10261 rng = dom.createRng();
10262 rng.setStart(addBogus(startContainer), startOffset);
10263 rng.setEnd(addBogus(endContainer), endOffset);
10266 } else if (bookmark.name) {
10267 t.select(dom.select(bookmark.name)[bookmark.index]);
10268 } else if (bookmark.rng) {
10269 t.setRng(bookmark.rng);
10275 * Selects the specified element. This will place the start and end of the selection range around the element.
10278 * @param {Element} node HMTL DOM element to select.
10279 * @param {Boolean} content Optional bool state if the contents should be selected or not on non IE browser.
10280 * @return {Element} Selected element the same element as the one that got passed in.
10282 * // Select the first paragraph in the active editor
10283 * tinymce.activeEditor.selection.select(tinymce.activeEditor.dom.select('p')[0]);
10285 select: function(node, content) {
10286 var self = this, dom = self.dom, rng = dom.createRng(), idx;
10288 // Clear stored range set by FocusManager
10289 self.lastFocusBookmark = null;
10291 function setPoint(node, start) {
10292 var walker = new TreeWalker(node, node);
10296 if (node.nodeType == 3 && trim(node.nodeValue).length !== 0) {
10298 rng.setStart(node, 0);
10300 rng.setEnd(node, node.nodeValue.length);
10307 if (node.nodeName == 'BR') {
10309 rng.setStartBefore(node);
10311 rng.setEndBefore(node);
10316 } while ((node = (start ? walker.next() : walker.prev())));
10320 if (!content && self.controlSelection.controlSelect(node)) {
10324 idx = dom.nodeIndex(node);
10325 rng.setStart(node.parentNode, idx);
10326 rng.setEnd(node.parentNode, idx + 1);
10328 // Find first/last text node or BR element
10341 * Returns true/false if the selection range is collapsed or not. Collapsed means if it's a caret or a larger selection.
10343 * @method isCollapsed
10344 * @return {Boolean} true/false state if the selection range is collapsed or not.
10345 * Collapsed means if it's a caret or a larger selection.
10347 isCollapsed: function() {
10348 var self = this, rng = self.getRng(), sel = self.getSel();
10350 if (!rng || rng.item) {
10354 if (rng.compareEndPoints) {
10355 return rng.compareEndPoints('StartToEnd', rng) === 0;
10358 return !sel || rng.collapsed;
10362 * Collapse the selection to start or end of range.
10365 * @param {Boolean} to_start Optional boolean state if to collapse to end or not. Defaults to start.
10367 collapse: function(to_start) {
10368 var self = this, rng = self.getRng(), node;
10370 // Control range on IE
10372 node = rng.item(0);
10373 rng = self.win.document.body.createTextRange();
10374 rng.moveToElementText(node);
10377 rng.collapse(!!to_start);
10382 * Returns the browsers internal selection object.
10385 * @return {Selection} Internal browser selection object.
10387 getSel: function() {
10388 var win = this.win;
10390 return win.getSelection ? win.getSelection() : win.document.selection;
10394 * Returns the browsers internal range object.
10397 * @param {Boolean} w3c Forces a compatible W3C range on IE.
10398 * @return {Range} Internal browser range object.
10399 * @see http://www.quirksmode.org/dom/range_intro.html
10400 * @see http://www.dotvoid.com/2001/03/using-the-range-object-in-mozilla/
10402 getRng: function(w3c) {
10403 var self = this, selection, rng, elm, doc = self.win.document, ieRng;
10405 // Use last rng passed from FocusManager if it's available this enables
10406 // calls to editor.selection.getStart() to work when caret focus is lost on IE
10407 if (!w3c && self.lastFocusBookmark) {
10408 var bookmark = self.lastFocusBookmark;
10410 // Convert bookmark to range IE 11 fix
10411 if (bookmark.startContainer) {
10412 rng = doc.createRange();
10413 rng.setStart(bookmark.startContainer, bookmark.startOffset);
10414 rng.setEnd(bookmark.endContainer, bookmark.endOffset);
10422 // Found tridentSel object then we need to use that one
10423 if (w3c && self.tridentSel) {
10424 return self.tridentSel.getRangeAt(0);
10428 if ((selection = self.getSel())) {
10429 if (selection.rangeCount > 0) {
10430 rng = selection.getRangeAt(0);
10432 rng = selection.createRange ? selection.createRange() : doc.createRange();
10436 // IE throws unspecified error here if TinyMCE is placed in a frame/iframe
10439 // We have W3C ranges and it's IE then fake control selection since IE9 doesn't handle that correctly yet
10440 if (isIE && rng && rng.setStart) {
10442 // IE will sometimes throw an exception here
10443 ieRng = doc.selection.createRange();
10448 if (ieRng && ieRng.item) {
10449 elm = ieRng.item(0);
10450 rng = doc.createRange();
10451 rng.setStartBefore(elm);
10452 rng.setEndAfter(elm);
10456 // No range found then create an empty one
10457 // This can occur when the editor is placed in a hidden container element on Gecko
10458 // Or on IE when there was an exception
10460 rng = doc.createRange ? doc.createRange() : doc.body.createTextRange();
10463 // If range is at start of document then move it to start of body
10464 if (rng.setStart && rng.startContainer.nodeType === 9 && rng.collapsed) {
10465 elm = self.dom.getRoot();
10466 rng.setStart(elm, 0);
10467 rng.setEnd(elm, 0);
10470 if (self.selectedRange && self.explicitRange) {
10471 if (rng.compareBoundaryPoints(rng.START_TO_START, self.selectedRange) === 0 &&
10472 rng.compareBoundaryPoints(rng.END_TO_END, self.selectedRange) === 0) {
10473 // Safari, Opera and Chrome only ever select text which causes the range to change.
10474 // This lets us use the originally set range if the selection hasn't been changed by the user.
10475 rng = self.explicitRange;
10477 self.selectedRange = null;
10478 self.explicitRange = null;
10486 * Changes the selection to the specified DOM range.
10489 * @param {Range} rng Range to select.
10491 setRng: function(rng, forward) {
10492 var self = this, sel;
10494 // Is IE specific range
10499 // Needed for some odd IE bug #1843306
10505 if (!self.tridentSel) {
10506 sel = self.getSel();
10509 self.explicitRange = rng;
10512 sel.removeAllRanges();
10515 // IE might throw errors here if the editor is within a hidden container and selection is changed
10518 // Forward is set to false and we have an extend function
10519 if (forward === false && sel.extend) {
10520 sel.collapse(rng.endContainer, rng.endOffset);
10521 sel.extend(rng.startContainer, rng.startOffset);
10524 // adding range isn't always successful so we need to check range count otherwise an exception can occur
10525 self.selectedRange = sel.rangeCount > 0 ? sel.getRangeAt(0) : null;
10528 // Is W3C Range fake range on IE
10529 if (rng.cloneRange) {
10531 self.tridentSel.addRange(rng);
10534 //IE9 throws an error here if called before selection is placed in the editor
10541 * Sets the current selection to the specified DOM element.
10544 * @param {Element} elm Element to set as the contents of the selection.
10545 * @return {Element} Returns the element that got passed in.
10547 * // Inserts a DOM node at current selection/caret location
10548 * tinymce.activeEditor.selection.setNode(tinymce.activeEditor.dom.create('img', {src: 'some.gif', title: 'some title'}));
10550 setNode: function(elm) {
10553 self.setContent(self.dom.getOuterHTML(elm));
10559 * Returns the currently selected element or the common ancestor element for both start and end of the selection.
10562 * @return {Element} Currently selected element or common ancestor element.
10564 * // Alerts the currently selected elements node name
10565 * alert(tinymce.activeEditor.selection.getNode().nodeName);
10567 getNode: function() {
10568 var self = this, rng = self.getRng(), elm;
10569 var startContainer = rng.startContainer, endContainer = rng.endContainer;
10570 var startOffset = rng.startOffset, endOffset = rng.endOffset;
10572 function skipEmptyTextNodes(node, forwards) {
10575 while (node && node.nodeType === 3 && node.length === 0) {
10576 node = forwards ? node.nextSibling : node.previousSibling;
10579 return node || orig;
10582 // Range maybe lost after the editor is made visible again
10584 return self.dom.getRoot();
10587 if (rng.setStart) {
10588 elm = rng.commonAncestorContainer;
10590 // Handle selection a image or other control like element such as anchors
10591 if (!rng.collapsed) {
10592 if (startContainer == endContainer) {
10593 if (endOffset - startOffset < 2) {
10594 if (startContainer.hasChildNodes()) {
10595 elm = startContainer.childNodes[startOffset];
10600 // If the anchor node is a element instead of a text node then return this element
10601 //if (tinymce.isWebKit && sel.anchorNode && sel.anchorNode.nodeType == 1)
10602 // return sel.anchorNode.childNodes[sel.anchorOffset];
10604 // Handle cases where the selection is immediately wrapped around a node and return that node instead of it's parent.
10605 // This happens when you double click an underlined word in FireFox.
10606 if (startContainer.nodeType === 3 && endContainer.nodeType === 3) {
10607 if (startContainer.length === startOffset) {
10608 startContainer = skipEmptyTextNodes(startContainer.nextSibling, true);
10610 startContainer = startContainer.parentNode;
10613 if (endOffset === 0) {
10614 endContainer = skipEmptyTextNodes(endContainer.previousSibling, false);
10616 endContainer = endContainer.parentNode;
10619 if (startContainer && startContainer === endContainer) {
10620 return startContainer;
10625 if (elm && elm.nodeType == 3) {
10626 return elm.parentNode;
10632 return rng.item ? rng.item(0) : rng.parentElement();
10635 getSelectedBlocks: function(startElm, endElm) {
10636 var self = this, dom = self.dom, node, root, selectedBlocks = [];
10638 root = dom.getRoot();
10639 startElm = dom.getParent(startElm || self.getStart(), dom.isBlock);
10640 endElm = dom.getParent(endElm || self.getEnd(), dom.isBlock);
10642 if (startElm && startElm != root) {
10643 selectedBlocks.push(startElm);
10646 if (startElm && endElm && startElm != endElm) {
10649 var walker = new TreeWalker(startElm, root);
10650 while ((node = walker.next()) && node != endElm) {
10651 if (dom.isBlock(node)) {
10652 selectedBlocks.push(node);
10657 if (endElm && startElm != endElm && endElm != root) {
10658 selectedBlocks.push(endElm);
10661 return selectedBlocks;
10664 isForward: function(){
10665 var dom = this.dom, sel = this.getSel(), anchorRange, focusRange;
10667 // No support for selection direction then always return true
10668 if (!sel || !sel.anchorNode || !sel.focusNode) {
10672 anchorRange = dom.createRng();
10673 anchorRange.setStart(sel.anchorNode, sel.anchorOffset);
10674 anchorRange.collapse(true);
10676 focusRange = dom.createRng();
10677 focusRange.setStart(sel.focusNode, sel.focusOffset);
10678 focusRange.collapse(true);
10680 return anchorRange.compareBoundaryPoints(anchorRange.START_TO_START, focusRange) <= 0;
10683 normalize: function() {
10684 var self = this, rng, normalized, collapsed;
10686 function normalizeEndPoint(start) {
10687 var container, offset, walker, dom = self.dom, body = dom.getRoot(), node, nonEmptyElementsMap, nodeName;
10689 function hasBrBeforeAfter(node, left) {
10690 var walker = new TreeWalker(node, dom.getParent(node.parentNode, dom.isBlock) || body);
10692 while ((node = walker[left ? 'prev' : 'next']())) {
10693 if (node.nodeName === "BR") {
10699 function isPrevNode(node, name) {
10700 return node.previousSibling && node.previousSibling.nodeName == name;
10703 // Walks the dom left/right to find a suitable text node to move the endpoint into
10704 // It will only walk within the current parent block or body and will stop if it hits a block or a BR/IMG
10705 function findTextNodeRelative(left, startNode) {
10706 var walker, lastInlineElement;
10708 startNode = startNode || container;
10709 walker = new TreeWalker(startNode, dom.getParent(startNode.parentNode, dom.isBlock) || body);
10711 // Walk left until we hit a text node we can move to or a block/br/img
10712 while ((node = walker[left ? 'prev' : 'next']())) {
10713 // Found text node that has a length
10714 if (node.nodeType === 3 && node.nodeValue.length > 0) {
10716 offset = left ? node.nodeValue.length : 0;
10721 // Break if we find a block or a BR/IMG/INPUT etc
10722 if (dom.isBlock(node) || nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
10726 lastInlineElement = node;
10729 // Only fetch the last inline element when in caret mode for now
10730 if (collapsed && lastInlineElement) {
10731 container = lastInlineElement;
10737 container = rng[(start ? 'start' : 'end') + 'Container'];
10738 offset = rng[(start ? 'start' : 'end') + 'Offset'];
10739 nonEmptyElementsMap = dom.schema.getNonEmptyElements();
10741 // If the container is a document move it to the body element
10742 if (container.nodeType === 9) {
10743 container = dom.getRoot();
10747 // If the container is body try move it into the closest text node or position
10748 if (container === body) {
10749 // If start is before/after a image, table etc
10751 node = container.childNodes[offset > 0 ? offset - 1 : 0];
10753 nodeName = node.nodeName.toLowerCase();
10754 if (nonEmptyElementsMap[node.nodeName] || node.nodeName == "TABLE") {
10760 // Resolve the index
10761 if (container.hasChildNodes()) {
10762 offset = Math.min(!start && offset > 0 ? offset - 1 : offset, container.childNodes.length - 1);
10763 container = container.childNodes[offset];
10766 // Don't walk into elements that doesn't have any child nodes like a IMG
10767 if (container.hasChildNodes() && !/TABLE/.test(container.nodeName)) {
10768 // Walk the DOM to find a text node to place the caret at or a BR
10770 walker = new TreeWalker(container, body);
10773 // Found a text node use that position
10774 if (node.nodeType === 3 && node.nodeValue.length > 0) {
10775 offset = start ? 0 : node.nodeValue.length;
10781 // Found a BR/IMG element that we can place the caret before
10782 if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
10783 offset = dom.nodeIndex(node);
10784 container = node.parentNode;
10786 // Put caret after image when moving the end point
10787 if (node.nodeName == "IMG" && !start) {
10794 } while ((node = (start ? walker.next() : walker.prev())));
10799 // Lean the caret to the left if possible
10801 // So this: <b>x</b><i>|x</i>
10802 // Becomes: <b>x|</b><i>x</i>
10803 // Seems that only gecko has issues with this
10804 if (container.nodeType === 3 && offset === 0) {
10805 findTextNodeRelative(true);
10808 // Lean left into empty inline elements when the caret is before a BR
10809 // So this: <i><b></b><i>|<br></i>
10810 // Becomes: <i><b>|</b><i><br></i>
10811 // Seems that only gecko has issues with this.
10812 // Special edge case for <p><a>x</a>|<br></p> since we don't want <p><a>x|</a><br></p>
10813 if (container.nodeType === 1) {
10814 node = container.childNodes[offset];
10815 if(node && node.nodeName === 'BR' && !isPrevNode(node, 'A') &&
10816 !hasBrBeforeAfter(node) && !hasBrBeforeAfter(node, true)) {
10817 findTextNodeRelative(true, container.childNodes[offset]);
10822 // Lean the start of the selection right if possible
10823 // So this: x[<b>x]</b>
10824 // Becomes: x<b>[x]</b>
10825 if (start && !collapsed && container.nodeType === 3 && offset === container.nodeValue.length) {
10826 findTextNodeRelative(false);
10829 // Set endpoint if it was normalized
10831 rng['set' + (start ? 'Start' : 'End')](container, offset);
10835 // Normalize only on non IE browsers for now
10840 rng = self.getRng();
10841 collapsed = rng.collapsed;
10843 // Normalize the end points
10844 normalizeEndPoint(true);
10847 normalizeEndPoint();
10850 // Set the selection if it was normalized
10852 // If it was collapsed then make sure it still is
10854 rng.collapse(true);
10857 //console.log(self.dom.dumpRng(rng));
10858 self.setRng(rng, self.isForward());
10863 * Executes callback of the current selection matches the specified selector or not and passes the state and args to the callback.
10865 * @method selectorChanged
10866 * @param {String} selector CSS selector to check for.
10867 * @param {function} callback Callback with state and args when the selector is matches or not.
10869 selectorChanged: function(selector, callback) {
10870 var self = this, currentSelectors;
10872 if (!self.selectorChangedData) {
10873 self.selectorChangedData = {};
10874 currentSelectors = {};
10876 self.editor.on('NodeChange', function(e) {
10877 var node = e.element, dom = self.dom, parents = dom.getParents(node, null, dom.getRoot()), matchedSelectors = {};
10879 // Check for new matching selectors
10880 each(self.selectorChangedData, function(callbacks, selector) {
10881 each(parents, function(node) {
10882 if (dom.is(node, selector)) {
10883 if (!currentSelectors[selector]) {
10884 // Execute callbacks
10885 each(callbacks, function(callback) {
10886 callback(true, {node: node, selector: selector, parents: parents});
10889 currentSelectors[selector] = callbacks;
10892 matchedSelectors[selector] = callbacks;
10898 // Check if current selectors still match
10899 each(currentSelectors, function(callbacks, selector) {
10900 if (!matchedSelectors[selector]) {
10901 delete currentSelectors[selector];
10903 each(callbacks, function(callback) {
10904 callback(false, {node: node, selector: selector, parents: parents});
10911 // Add selector listeners
10912 if (!self.selectorChangedData[selector]) {
10913 self.selectorChangedData[selector] = [];
10916 self.selectorChangedData[selector].push(callback);
10921 scrollIntoView: function(elm) {
10922 var y, viewPort, self = this, dom = self.dom;
10924 viewPort = dom.getViewPort(self.editor.getWin());
10925 y = dom.getPos(elm).y;
10926 if (y < viewPort.y || y + 25 > viewPort.y + viewPort.h) {
10927 self.editor.getWin().scrollTo(0, y < viewPort.y ? y : y - viewPort.h + 25);
10931 destroy: function() {
10933 this.controlSelection.destroy();
10940 // Included from: js/tinymce/classes/dom/RangeUtils.js
10945 * Copyright, Moxiecode Systems AB
10946 * Released under LGPL License.
10948 * License: http://www.tinymce.com/license
10949 * Contributing: http://www.tinymce.com/contributing
10955 * @class tinymce.dom.RangeUtils
10958 define("tinymce/dom/RangeUtils", [
10959 "tinymce/util/Tools"
10960 ], function(Tools) {
10961 var each = Tools.each;
10963 function RangeUtils(dom) {
10965 * Walks the specified range like object and executes the callback for each sibling collection it finds.
10968 * @param {Object} rng Range like object.
10969 * @param {function} callback Callback function to execute for each sibling collection.
10971 this.walk = function(rng, callback) {
10972 var startContainer = rng.startContainer,
10973 startOffset = rng.startOffset,
10974 endContainer = rng.endContainer,
10975 endOffset = rng.endOffset,
10976 ancestor, startPoint,
10977 endPoint, node, parent, siblings, nodes;
10979 // Handle table cell selection the table plugin enables
10980 // you to fake select table cells and perform formatting actions on them
10981 nodes = dom.select('td.mce-item-selected,th.mce-item-selected');
10982 if (nodes.length > 0) {
10983 each(nodes, function(node) {
10991 * Excludes start/end text node if they are out side the range
10994 * @param {Array} nodes Nodes to exclude items from.
10995 * @return {Array} Array with nodes excluding the start/end container if needed.
10997 function exclude(nodes) {
11000 // First node is excluded
11002 if (node.nodeType === 3 && node === startContainer && startOffset >= node.nodeValue.length) {
11003 nodes.splice(0, 1);
11006 // Last node is excluded
11007 node = nodes[nodes.length - 1];
11008 if (endOffset === 0 && nodes.length > 0 && node === endContainer && node.nodeType === 3) {
11009 nodes.splice(nodes.length - 1, 1);
11016 * Collects siblings
11019 * @param {Node} node Node to collect siblings from.
11020 * @param {String} name Name of the sibling to check for.
11021 * @return {Array} Array of collected siblings.
11023 function collectSiblings(node, name, end_node) {
11026 for (; node && node != end_node; node = node[name]) {
11027 siblings.push(node);
11034 * Find an end point this is the node just before the common ancestor root.
11037 * @param {Node} node Node to start at.
11038 * @param {Node} root Root/ancestor element to stop just before.
11039 * @return {Node} Node just before the root element.
11041 function findEndPoint(node, root) {
11043 if (node.parentNode == root) {
11047 node = node.parentNode;
11051 function walkBoundary(start_node, end_node, next) {
11052 var siblingName = next ? 'nextSibling' : 'previousSibling';
11054 for (node = start_node, parent = node.parentNode; node && node != end_node; node = parent) {
11055 parent = node.parentNode;
11056 siblings = collectSiblings(node == start_node ? node : node[siblingName], siblingName);
11058 if (siblings.length) {
11060 siblings.reverse();
11063 callback(exclude(siblings));
11068 // If index based start position then resolve it
11069 if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
11070 startContainer = startContainer.childNodes[startOffset];
11073 // If index based end position then resolve it
11074 if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
11075 endContainer = endContainer.childNodes[Math.min(endOffset - 1, endContainer.childNodes.length - 1)];
11079 if (startContainer == endContainer) {
11080 return callback(exclude([startContainer]));
11083 // Find common ancestor and end points
11084 ancestor = dom.findCommonAncestor(startContainer, endContainer);
11086 // Process left side
11087 for (node = startContainer; node; node = node.parentNode) {
11088 if (node === endContainer) {
11089 return walkBoundary(startContainer, ancestor, true);
11092 if (node === ancestor) {
11097 // Process right side
11098 for (node = endContainer; node; node = node.parentNode) {
11099 if (node === startContainer) {
11100 return walkBoundary(endContainer, ancestor);
11103 if (node === ancestor) {
11108 // Find start/end point
11109 startPoint = findEndPoint(startContainer, ancestor) || startContainer;
11110 endPoint = findEndPoint(endContainer, ancestor) || endContainer;
11113 walkBoundary(startContainer, startPoint, true);
11115 // Walk the middle from start to end point
11116 siblings = collectSiblings(
11117 startPoint == startContainer ? startPoint : startPoint.nextSibling,
11119 endPoint == endContainer ? endPoint.nextSibling : endPoint
11122 if (siblings.length) {
11123 callback(exclude(siblings));
11127 walkBoundary(endContainer, endPoint);
11131 * Splits the specified range at it's start/end points.
11134 * @param {Range/RangeObject} rng Range to split.
11135 * @return {Object} Range position object.
11137 this.split = function(rng) {
11138 var startContainer = rng.startContainer,
11139 startOffset = rng.startOffset,
11140 endContainer = rng.endContainer,
11141 endOffset = rng.endOffset;
11143 function splitText(node, offset) {
11144 return node.splitText(offset);
11147 // Handle single text node
11148 if (startContainer == endContainer && startContainer.nodeType == 3) {
11149 if (startOffset > 0 && startOffset < startContainer.nodeValue.length) {
11150 endContainer = splitText(startContainer, startOffset);
11151 startContainer = endContainer.previousSibling;
11153 if (endOffset > startOffset) {
11154 endOffset = endOffset - startOffset;
11155 startContainer = endContainer = splitText(endContainer, endOffset).previousSibling;
11156 endOffset = endContainer.nodeValue.length;
11163 // Split startContainer text node if needed
11164 if (startContainer.nodeType == 3 && startOffset > 0 && startOffset < startContainer.nodeValue.length) {
11165 startContainer = splitText(startContainer, startOffset);
11169 // Split endContainer text node if needed
11170 if (endContainer.nodeType == 3 && endOffset > 0 && endOffset < endContainer.nodeValue.length) {
11171 endContainer = splitText(endContainer, endOffset).previousSibling;
11172 endOffset = endContainer.nodeValue.length;
11177 startContainer: startContainer,
11178 startOffset: startOffset,
11179 endContainer: endContainer,
11180 endOffset: endOffset
11186 * Compares two ranges and checks if they are equal.
11189 * @method compareRanges
11190 * @param {DOMRange} rng1 First range to compare.
11191 * @param {DOMRange} rng2 First range to compare.
11192 * @return {Boolean} true/false if the ranges are equal.
11194 RangeUtils.compareRanges = function(rng1, rng2) {
11195 if (rng1 && rng2) {
11196 // Compare native IE ranges
11197 if (rng1.item || rng1.duplicate) {
11198 // Both are control ranges and the selected element matches
11199 if (rng1.item && rng2.item && rng1.item(0) === rng2.item(0)) {
11203 // Both are text ranges and the range matches
11204 if (rng1.isEqual && rng2.isEqual && rng2.isEqual(rng1)) {
11208 // Compare w3c ranges
11209 return rng1.startContainer == rng2.startContainer && rng1.startOffset == rng2.startOffset;
11219 // Included from: js/tinymce/classes/Formatter.js
11224 * Copyright, Moxiecode Systems AB
11225 * Released under LGPL License.
11227 * License: http://www.tinymce.com/license
11228 * Contributing: http://www.tinymce.com/contributing
11232 * Text formatter engine class. This class is used to apply formats like bold, italic, font size
11233 * etc to the current selection or specific nodes. This engine was build to replace the browsers
11234 * default formatting logic for execCommand due to it's inconsistent and buggy behavior.
11236 * @class tinymce.Formatter
11238 * tinymce.activeEditor.formatter.register('mycustomformat', {
11240 * styles: {color: '#ff0000'}
11243 * tinymce.activeEditor.formatter.apply('mycustomformat');
11245 define("tinymce/Formatter", [
11246 "tinymce/dom/TreeWalker",
11247 "tinymce/dom/RangeUtils",
11248 "tinymce/util/Tools"
11249 ], function(TreeWalker, RangeUtils, Tools) {
11251 * Constructs a new formatter instance.
11253 * @constructor Formatter
11254 * @param {tinymce.Editor} ed Editor instance to construct the formatter engine to.
11256 return function(ed) {
11259 selection = ed.selection,
11260 rangeUtils = new RangeUtils(dom),
11261 isValid = ed.schema.isValidChild,
11262 isBlock = dom.isBlock,
11263 forcedRootBlock = ed.settings.forced_root_block,
11264 nodeIndex = dom.nodeIndex,
11265 INVISIBLE_CHAR = '\uFEFF',
11266 MCE_ATTR_RE = /^(src|href|style)$/,
11271 getContentEditable = dom.getContentEditable,
11272 disableCaretContainer,
11273 markCaretContainersBogus;
11275 var each = Tools.each,
11278 extend = Tools.extend;
11280 function isTextBlock(name) {
11281 if (name.nodeType) {
11282 name = name.nodeName;
11285 return !!ed.schema.getTextBlockElements()[name.toLowerCase()];
11288 function getParents(node, selector) {
11289 return dom.getParents(node, selector, dom.getRoot());
11292 function isCaretNode(node) {
11293 return node.nodeType === 1 && node.id === '_mce_caret';
11296 function defaultFormats() {
11299 {selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', styles: {textAlign: 'left'}, defaultBlock: 'div'},
11300 {selector: 'img,table', collapsed: false, styles: {'float': 'left'}}
11304 {selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', styles: {textAlign: 'center'}, defaultBlock: 'div'},
11305 {selector: 'img', collapsed: false, styles: {display: 'block', marginLeft: 'auto', marginRight: 'auto'}},
11306 {selector: 'table', collapsed: false, styles: {marginLeft: 'auto', marginRight: 'auto'}}
11310 {selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', styles: {textAlign: 'right'}, defaultBlock: 'div'},
11311 {selector: 'img,table', collapsed: false, styles: {'float': 'right'}}
11315 {selector: 'figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li', styles: {textAlign: 'justify'}, defaultBlock: 'div'}
11319 {inline: 'strong', remove: 'all'},
11320 {inline: 'span', styles: {fontWeight: 'bold'}},
11321 {inline: 'b', remove: 'all'}
11325 {inline: 'em', remove: 'all'},
11326 {inline: 'span', styles: {fontStyle: 'italic'}},
11327 {inline: 'i', remove: 'all'}
11331 {inline: 'span', styles: {textDecoration: 'underline'}, exact: true},
11332 {inline: 'u', remove: 'all'}
11336 {inline: 'span', styles: {textDecoration: 'line-through'}, exact: true},
11337 {inline: 'strike', remove: 'all'}
11340 forecolor: {inline: 'span', styles: {color: '%value'}, wrap_links: false},
11341 hilitecolor: {inline: 'span', styles: {backgroundColor: '%value'}, wrap_links: false},
11342 fontname: {inline: 'span', styles: {fontFamily: '%value'}},
11343 fontsize: {inline: 'span', styles: {fontSize: '%value'}},
11344 fontsize_class: {inline: 'span', attributes: {'class': '%value'}},
11345 blockquote: {block: 'blockquote', wrapper: 1, remove: 'all'},
11346 subscript: {inline: 'sub'},
11347 superscript: {inline: 'sup'},
11348 code: {inline: 'code'},
11350 link: {inline: 'a', selector: 'a', remove: 'all', split: true, deep: true,
11351 onmatch: function() {
11355 onformat: function(elm, fmt, vars) {
11356 each(vars, function(value, key) {
11357 dom.setAttrib(elm, key, value);
11364 selector: 'b,strong,em,i,font,u,strike,sub,sup',
11368 block_expand: true,
11371 {selector: 'span', attributes: ['style', 'class'], remove: 'empty', split: true, expand: false, deep: true},
11372 {selector: '*', attributes: ['style', 'class'], split: false, expand: false, deep: true}
11376 // Register default block formats
11377 each('p h1 h2 h3 h4 h5 h6 div address pre div dt dd samp'.split(/\s/), function(name) {
11378 register(name, {block: name, remove: 'all'});
11381 // Register user defined formats
11382 register(ed.settings.formats);
11385 function addKeyboardShortcuts() {
11386 // Add some inline shortcuts
11387 ed.addShortcut('ctrl+b', 'bold_desc', 'Bold');
11388 ed.addShortcut('ctrl+i', 'italic_desc', 'Italic');
11389 ed.addShortcut('ctrl+u', 'underline_desc', 'Underline');
11391 // BlockFormat shortcuts keys
11392 for (var i = 1; i <= 6; i++) {
11393 ed.addShortcut('ctrl+' + i, '', ['FormatBlock', false, 'h' + i]);
11396 ed.addShortcut('ctrl+7', '', ['FormatBlock', false, 'p']);
11397 ed.addShortcut('ctrl+8', '', ['FormatBlock', false, 'div']);
11398 ed.addShortcut('ctrl+9', '', ['FormatBlock', false, 'address']);
11401 // Public functions
11404 * Returns the format by name or all formats if no name is specified.
11407 * @param {String} name Optional name to retrive by.
11408 * @return {Array/Object} Array/Object with all registred formats or a specific format.
11410 function get(name) {
11411 return name ? formats[name] : formats;
11415 * Registers a specific format by name.
11418 * @param {Object/String} name Name of the format for example "bold".
11419 * @param {Object/Array} format Optional format object or array of format variants
11420 * can only be omitted if the first arg is an object.
11422 function register(name, format) {
11424 if (typeof(name) !== 'string') {
11425 each(name, function(format, name) {
11426 register(name, format);
11429 // Force format into array and add it to internal collection
11430 format = format.length ? format : [format];
11432 each(format, function(format) {
11433 // Set deep to false by default on selector formats this to avoid removing
11434 // alignment on images inside paragraphs when alignment is changed on paragraphs
11435 if (format.deep === undef) {
11436 format.deep = !format.selector;
11440 if (format.split === undef) {
11441 format.split = !format.selector || format.inline;
11445 if (format.remove === undef && format.selector && !format.inline) {
11446 format.remove = 'none';
11449 // Mark format as a mixed format inline + block level
11450 if (format.selector && format.inline) {
11451 format.mixed = true;
11452 format.block_expand = true;
11455 // Split classes if needed
11456 if (typeof(format.classes) === 'string') {
11457 format.classes = format.classes.split(/\s+/);
11461 formats[name] = format;
11466 function getTextDecoration(node) {
11469 ed.dom.getParent(node, function(n) {
11470 decoration = ed.dom.getStyle(n, 'text-decoration');
11471 return decoration && decoration !== 'none';
11477 function processUnderlineAndColor(node) {
11478 var textDecoration;
11479 if (node.nodeType === 1 && node.parentNode && node.parentNode.nodeType === 1) {
11480 textDecoration = getTextDecoration(node.parentNode);
11481 if (ed.dom.getStyle(node, 'color') && textDecoration) {
11482 ed.dom.setStyle(node, 'text-decoration', textDecoration);
11483 } else if (ed.dom.getStyle(node, 'textdecoration') === textDecoration) {
11484 ed.dom.setStyle(node, 'text-decoration', null);
11490 * Applies the specified format to the current selection or specified node.
11493 * @param {String} name Name of format to apply.
11494 * @param {Object} vars Optional list of variables to replace within format before applying it.
11495 * @param {Node} node Optional node to apply the format to defaults to current selection.
11497 function apply(name, vars, node) {
11498 var formatList = get(name), format = formatList[0], bookmark, rng, isCollapsed = !node && selection.isCollapsed();
11500 function setElementFormat(elm, fmt) {
11501 fmt = fmt || format;
11504 if (fmt.onformat) {
11505 fmt.onformat(elm, fmt, vars, node);
11508 each(fmt.styles, function(value, name) {
11509 dom.setStyle(elm, name, replaceVars(value, vars));
11512 each(fmt.attributes, function(value, name) {
11513 dom.setAttrib(elm, name, replaceVars(value, vars));
11516 each(fmt.classes, function(value) {
11517 value = replaceVars(value, vars);
11519 if (!dom.hasClass(elm, value)) {
11520 dom.addClass(elm, value);
11526 function adjustSelectionToVisibleSelection() {
11527 function findSelectionEnd(start, end) {
11528 var walker = new TreeWalker(end);
11529 for (node = walker.current(); node; node = walker.prev()) {
11530 if (node.childNodes.length > 1 || node == start || node.tagName == 'BR') {
11536 // Adjust selection so that a end container with a end offset of zero is not included in the selection
11537 // as this isn't visible to the user.
11538 var rng = ed.selection.getRng();
11539 var start = rng.startContainer;
11540 var end = rng.endContainer;
11542 if (start != end && rng.endOffset === 0) {
11543 var newEnd = findSelectionEnd(start, end);
11544 var endOffset = newEnd.nodeType == 3 ? newEnd.length : newEnd.childNodes.length;
11546 rng.setEnd(newEnd, endOffset);
11552 function applyStyleToList(node, bookmark, wrapElm, newWrappers, process){
11553 var nodes = [], listIndex = -1, list, startIndex = -1, endIndex = -1, currentWrapElm;
11555 // find the index of the first child list.
11556 each(node.childNodes, function(n, index) {
11557 if (n.nodeName === "UL" || n.nodeName === "OL") {
11564 // get the index of the bookmarks
11565 each(node.childNodes, function(n, index) {
11566 if (n.nodeName === "SPAN" && dom.getAttrib(n, "data-mce-type") == "bookmark") {
11567 if (n.id == bookmark.id + "_start") {
11568 startIndex = index;
11569 } else if (n.id == bookmark.id + "_end") {
11575 // if the selection spans across an embedded list, or there isn't an embedded list - handle processing normally
11576 if (listIndex <= 0 || (startIndex < listIndex && endIndex > listIndex)) {
11577 each(grep(node.childNodes), process);
11580 currentWrapElm = dom.clone(wrapElm, FALSE);
11582 // create a list of the nodes on the same side of the list as the selection
11583 each(grep(node.childNodes), function(n, index) {
11584 if ((startIndex < listIndex && index < listIndex) || (startIndex > listIndex && index > listIndex)) {
11586 n.parentNode.removeChild(n);
11590 // insert the wrapping element either before or after the list.
11591 if (startIndex < listIndex) {
11592 node.insertBefore(currentWrapElm, list);
11593 } else if (startIndex > listIndex) {
11594 node.insertBefore(currentWrapElm, list.nextSibling);
11597 // add the new nodes to the list.
11598 newWrappers.push(currentWrapElm);
11600 each(nodes, function(node) {
11601 currentWrapElm.appendChild(node);
11604 return currentWrapElm;
11608 function applyRngStyle(rng, bookmark, node_specific) {
11609 var newWrappers = [], wrapName, wrapElm, contentEditable = true;
11611 // Setup wrapper element
11612 wrapName = format.inline || format.block;
11613 wrapElm = dom.create(wrapName);
11614 setElementFormat(wrapElm);
11616 rangeUtils.walk(rng, function(nodes) {
11617 var currentWrapElm;
11620 * Process a list of nodes wrap them.
11622 function process(node) {
11623 var nodeName, parentName, found, hasContentEditableState, lastContentEditable;
11625 lastContentEditable = contentEditable;
11626 nodeName = node.nodeName.toLowerCase();
11627 parentName = node.parentNode.nodeName.toLowerCase();
11629 // Node has a contentEditable value
11630 if (node.nodeType === 1 && getContentEditable(node)) {
11631 lastContentEditable = contentEditable;
11632 contentEditable = getContentEditable(node) === "true";
11633 hasContentEditableState = true; // We don't want to wrap the container only it's children
11636 // Stop wrapping on br elements
11637 if (isEq(nodeName, 'br')) {
11638 currentWrapElm = 0;
11640 // Remove any br elements when we wrap things
11641 if (format.block) {
11648 // If node is wrapper type
11649 if (format.wrapper && matchNode(node, name, vars)) {
11650 currentWrapElm = 0;
11654 // Can we rename the block
11655 // TODO: Break this if up, too complex
11656 if (contentEditable && !hasContentEditableState && format.block &&
11657 !format.wrapper && isTextBlock(nodeName) && isValid(parentName, wrapName)) {
11658 node = dom.rename(node, wrapName);
11659 setElementFormat(node);
11660 newWrappers.push(node);
11661 currentWrapElm = 0;
11665 // Handle selector patterns
11666 if (format.selector) {
11667 // Look for matching formats
11668 each(formatList, function(format) {
11669 // Check collapsed state if it exists
11670 if ('collapsed' in format && format.collapsed !== isCollapsed) {
11674 if (dom.is(node, format.selector) && !isCaretNode(node)) {
11675 setElementFormat(node, format);
11680 // Continue processing if a selector match wasn't found and a inline element is defined
11681 if (!format.inline || found) {
11682 currentWrapElm = 0;
11687 // Is it valid to wrap this item
11688 // TODO: Break this if up, too complex
11689 if (contentEditable && !hasContentEditableState && isValid(wrapName, nodeName) && isValid(parentName, wrapName) &&
11690 !(!node_specific && node.nodeType === 3 &&
11691 node.nodeValue.length === 1 &&
11692 node.nodeValue.charCodeAt(0) === 65279) &&
11693 !isCaretNode(node) &&
11694 (!format.inline || !isBlock(node))) {
11696 if (!currentWrapElm) {
11698 currentWrapElm = dom.clone(wrapElm, FALSE);
11699 node.parentNode.insertBefore(currentWrapElm, node);
11700 newWrappers.push(currentWrapElm);
11703 currentWrapElm.appendChild(node);
11704 } else if (nodeName == 'li' && bookmark) {
11705 // Start wrapping - if we are in a list node and have a bookmark, then
11706 // we will always begin by wrapping in a new element.
11707 currentWrapElm = applyStyleToList(node, bookmark, wrapElm, newWrappers, process);
11709 // Start a new wrapper for possible children
11710 currentWrapElm = 0;
11712 each(grep(node.childNodes), process);
11714 if (hasContentEditableState) {
11715 contentEditable = lastContentEditable; // Restore last contentEditable state from stack
11718 // End the last wrapper
11719 currentWrapElm = 0;
11723 // Process siblings from range
11724 each(nodes, process);
11727 // Wrap links inside as well, for example color inside a link when the wrapper is around the link
11728 if (format.wrap_links === false) {
11729 each(newWrappers, function(node) {
11730 function process(node) {
11731 var i, currentWrapElm, children;
11733 if (node.nodeName === 'A') {
11734 currentWrapElm = dom.clone(wrapElm, FALSE);
11735 newWrappers.push(currentWrapElm);
11737 children = grep(node.childNodes);
11738 for (i = 0; i < children.length; i++) {
11739 currentWrapElm.appendChild(children[i]);
11742 node.appendChild(currentWrapElm);
11745 each(grep(node.childNodes), process);
11753 each(newWrappers, function(node) {
11756 function getChildCount(node) {
11759 each(node.childNodes, function(node) {
11760 if (!isWhiteSpaceNode(node) && !isBookmarkNode(node)) {
11768 function mergeStyles(node) {
11771 each(node.childNodes, function(node) {
11772 if (node.nodeType == 1 && !isBookmarkNode(node) && !isCaretNode(node)) {
11774 return FALSE; // break loop
11778 // If child was found and of the same type as the current node
11779 if (child && matchName(child, format)) {
11780 clone = dom.clone(child, FALSE);
11781 setElementFormat(clone);
11783 dom.replace(clone, node, TRUE);
11784 dom.remove(child, 1);
11787 return clone || node;
11790 childCount = getChildCount(node);
11792 // Remove empty nodes but only if there is multiple wrappers and they are not block
11793 // elements so never remove single <h1></h1> since that would remove the
11794 // currrent empty block element where the caret is at
11795 if ((newWrappers.length > 1 || !isBlock(node)) && childCount === 0) {
11796 dom.remove(node, 1);
11800 if (format.inline || format.wrapper) {
11801 // Merges the current node with it's children of similar type to reduce the number of elements
11802 if (!format.exact && childCount === 1) {
11803 node = mergeStyles(node);
11806 // Remove/merge children
11807 each(formatList, function(format) {
11808 // Merge all children of similar type will move styles from child to parent
11809 // this: <span style="color:red"><b><span style="color:red; font-size:10px">text</span></b></span>
11810 // will become: <span style="color:red"><b><span style="font-size:10px">text</span></b></span>
11811 each(dom.select(format.inline, node), function(child) {
11814 // When wrap_links is set to false we don't want
11815 // to remove the format on children within links
11816 if (format.wrap_links === false) {
11817 parent = child.parentNode;
11820 if (parent.nodeName === 'A') {
11823 } while ((parent = parent.parentNode));
11826 removeFormat(format, vars, child, format.exact ? child : null);
11830 // Remove child if direct parent is of same type
11831 if (matchNode(node.parentNode, name, vars)) {
11832 dom.remove(node, 1);
11837 // Look for parent with similar style format
11838 if (format.merge_with_parents) {
11839 dom.getParent(node.parentNode, function(parent) {
11840 if (matchNode(parent, name, vars)) {
11841 dom.remove(node, 1);
11848 // Merge next and previous siblings if they are similar <b>text</b><b>text</b> becomes <b>texttext</b>
11849 if (node && format.merge_siblings !== false) {
11850 node = mergeSiblings(getNonWhiteSpaceSibling(node), node);
11851 node = mergeSiblings(node, getNonWhiteSpaceSibling(node, TRUE));
11859 if (node.nodeType) {
11860 rng = dom.createRng();
11861 rng.setStartBefore(node);
11862 rng.setEndAfter(node);
11863 applyRngStyle(expandRng(rng, formatList), null, true);
11865 applyRngStyle(node, null, true);
11868 if (!isCollapsed || !format.inline || dom.select('td.mce-item-selected,th.mce-item-selected').length) {
11869 // Obtain selection node before selection is unselected by applyRngStyle()
11870 var curSelNode = ed.selection.getNode();
11872 // If the formats have a default block and we can't find a parent block then
11873 // start wrapping it with a DIV this is for forced_root_blocks: false
11874 // It's kind of a hack but people should be using the default block type P since all desktop editors work that way
11875 if (!forcedRootBlock && formatList[0].defaultBlock && !dom.getParent(curSelNode, dom.isBlock)) {
11876 apply(formatList[0].defaultBlock);
11879 // Apply formatting to selection
11880 ed.selection.setRng(adjustSelectionToVisibleSelection());
11881 bookmark = selection.getBookmark();
11882 applyRngStyle(expandRng(selection.getRng(TRUE), formatList), bookmark);
11884 // Colored nodes should be underlined so that the color of the underline matches the text color.
11885 if (format.styles && (format.styles.color || format.styles.textDecoration)) {
11886 walk(curSelNode, processUnderlineAndColor, 'childNodes');
11887 processUnderlineAndColor(curSelNode);
11890 selection.moveToBookmark(bookmark);
11891 moveStart(selection.getRng(TRUE));
11894 performCaretAction('apply', name, vars);
11901 * Removes the specified format from the current selection or specified node.
11904 * @param {String} name Name of format to remove.
11905 * @param {Object} vars Optional list of variables to replace within format before removing it.
11906 * @param {Node/Range} node Optional node or DOM range to remove the format from defaults to current selection.
11908 function remove(name, vars, node) {
11909 var formatList = get(name), format = formatList[0], bookmark, rng, contentEditable = true;
11911 // Merges the styles for each node
11912 function process(node) {
11913 var children, i, l, lastContentEditable, hasContentEditableState;
11915 // Node has a contentEditable value
11916 if (node.nodeType === 1 && getContentEditable(node)) {
11917 lastContentEditable = contentEditable;
11918 contentEditable = getContentEditable(node) === "true";
11919 hasContentEditableState = true; // We don't want to wrap the container only it's children
11922 // Grab the children first since the nodelist might be changed
11923 children = grep(node.childNodes);
11925 // Process current node
11926 if (contentEditable && !hasContentEditableState) {
11927 for (i = 0, l = formatList.length; i < l; i++) {
11928 if (removeFormat(formatList[i], vars, node, node)) {
11934 // Process the children
11936 if (children.length) {
11937 for (i = 0, l = children.length; i < l; i++) {
11938 process(children[i]);
11941 if (hasContentEditableState) {
11942 contentEditable = lastContentEditable; // Restore last contentEditable state from stack
11948 function findFormatRoot(container) {
11951 // Find format root
11952 each(getParents(container.parentNode).reverse(), function(parent) {
11955 // Find format root element
11956 if (!formatRoot && parent.id != '_start' && parent.id != '_end') {
11957 // Is the node matching the format we are looking for
11958 format = matchNode(parent, name, vars);
11959 if (format && format.split !== false) {
11960 formatRoot = parent;
11968 function wrapAndSplit(format_root, container, target, split) {
11969 var parent, clone, lastClone, firstClone, i, formatRootParent;
11971 // Format root found then clone formats and split it
11973 formatRootParent = format_root.parentNode;
11975 for (parent = container.parentNode; parent && parent != formatRootParent; parent = parent.parentNode) {
11976 clone = dom.clone(parent, FALSE);
11978 for (i = 0; i < formatList.length; i++) {
11979 if (removeFormat(formatList[i], vars, clone, clone)) {
11985 // Build wrapper node
11988 clone.appendChild(lastClone);
11992 firstClone = clone;
11999 // Never split block elements if the format is mixed
12000 if (split && (!format.mixed || !isBlock(format_root))) {
12001 container = dom.split(format_root, container);
12004 // Wrap container in cloned formats
12006 target.parentNode.insertBefore(lastClone, target);
12007 firstClone.appendChild(target);
12014 function splitToFormatRoot(container) {
12015 return wrapAndSplit(findFormatRoot(container), container, container, true);
12018 function unwrap(start) {
12019 var node = dom.get(start ? '_start' : '_end'),
12020 out = node[start ? 'firstChild' : 'lastChild'];
12022 // If the end is placed within the start the result will be removed
12023 // So this checks if the out node is a bookmark node if it is it
12024 // checks for another more suitable node
12025 if (isBookmarkNode(out)) {
12026 out = out[start ? 'firstChild' : 'lastChild'];
12029 dom.remove(node, true);
12034 function removeRngStyle(rng) {
12035 var startContainer, endContainer;
12037 rng = expandRng(rng, formatList, TRUE);
12039 if (format.split) {
12040 startContainer = getContainer(rng, TRUE);
12041 endContainer = getContainer(rng);
12043 if (startContainer != endContainer) {
12044 // WebKit will render the table incorrectly if we wrap a TD in a SPAN
12045 // so lets see if the can use the first child instead
12046 // This will happen if you tripple click a table cell and use remove formatting
12047 if (/^(TR|TD)$/.test(startContainer.nodeName) && startContainer.firstChild) {
12048 if (startContainer.nodeName == "TD") {
12049 startContainer = startContainer.firstChild || startContainer;
12051 startContainer = startContainer.firstChild.firstChild || startContainer;
12055 // Wrap start/end nodes in span element since these might be cloned/moved
12056 startContainer = wrap(startContainer, 'span', {id: '_start', 'data-mce-type': 'bookmark'});
12057 endContainer = wrap(endContainer, 'span', {id: '_end', 'data-mce-type': 'bookmark'});
12060 splitToFormatRoot(startContainer);
12061 splitToFormatRoot(endContainer);
12063 // Unwrap start/end to get real elements again
12064 startContainer = unwrap(TRUE);
12065 endContainer = unwrap();
12067 startContainer = endContainer = splitToFormatRoot(startContainer);
12070 // Update range positions since they might have changed after the split operations
12071 rng.startContainer = startContainer.parentNode;
12072 rng.startOffset = nodeIndex(startContainer);
12073 rng.endContainer = endContainer.parentNode;
12074 rng.endOffset = nodeIndex(endContainer) + 1;
12077 // Remove items between start/end
12078 rangeUtils.walk(rng, function(nodes) {
12079 each(nodes, function(node) {
12082 // Remove parent span if it only contains text-decoration: underline, yet a parent node is also underlined.
12083 if (node.nodeType === 1 && ed.dom.getStyle(node, 'text-decoration') === 'underline' &&
12084 node.parentNode && getTextDecoration(node.parentNode) === 'underline') {
12090 'textDecoration': 'underline'
12100 if (node.nodeType) {
12101 rng = dom.createRng();
12102 rng.setStartBefore(node);
12103 rng.setEndAfter(node);
12104 removeRngStyle(rng);
12106 removeRngStyle(node);
12112 if (!selection.isCollapsed() || !format.inline || dom.select('td.mce-item-selected,th.mce-item-selected').length) {
12113 bookmark = selection.getBookmark();
12114 removeRngStyle(selection.getRng(TRUE));
12115 selection.moveToBookmark(bookmark);
12117 // Check if start element still has formatting then we are at: "<b>text|</b>text"
12118 // and need to move the start into the next text node
12119 if (format.inline && match(name, vars, selection.getStart())) {
12120 moveStart(selection.getRng(true));
12125 performCaretAction('remove', name, vars);
12130 * Toggles the specified format on/off.
12133 * @param {String} name Name of format to apply/remove.
12134 * @param {Object} vars Optional list of variables to replace within format before applying/removing it.
12135 * @param {Node} node Optional node to apply the format to or remove from. Defaults to current selection.
12137 function toggle(name, vars, node) {
12138 var fmt = get(name);
12140 if (match(name, vars, node) && (!('toggle' in fmt[0]) || fmt[0].toggle)) {
12141 remove(name, vars, node);
12143 apply(name, vars, node);
12148 * Return true/false if the specified node has the specified format.
12150 * @method matchNode
12151 * @param {Node} node Node to check the format on.
12152 * @param {String} name Format name to check.
12153 * @param {Object} vars Optional list of variables to replace before checking it.
12154 * @param {Boolean} similar Match format that has similar properties.
12155 * @return {Object} Returns the format object it matches or undefined if it doesn't match.
12157 function matchNode(node, name, vars, similar) {
12158 var formatList = get(name), format, i, classes;
12160 function matchItems(node, format, item_name) {
12161 var key, value, items = format[item_name], i;
12164 if (format.onmatch) {
12165 return format.onmatch(node, format, item_name);
12170 // Non indexed object
12171 if (items.length === undef) {
12172 for (key in items) {
12173 if (items.hasOwnProperty(key)) {
12174 if (item_name === 'attributes') {
12175 value = dom.getAttrib(node, key);
12177 value = getStyle(node, key);
12180 if (similar && !value && !format.exact) {
12184 if ((!similar || format.exact) && !isEq(value, normalizeStyleValue(replaceVars(items[key], vars), key))) {
12190 // Only one match needed for indexed arrays
12191 for (i = 0; i < items.length; i++) {
12192 if (item_name === 'attributes' ? dom.getAttrib(node, items[i]) : getStyle(node, items[i])) {
12202 if (formatList && node) {
12203 // Check each format in list
12204 for (i = 0; i < formatList.length; i++) {
12205 format = formatList[i];
12207 // Name name, attributes, styles and classes
12208 if (matchName(node, format) && matchItems(node, format, 'attributes') && matchItems(node, format, 'styles')) {
12210 if ((classes = format.classes)) {
12211 for (i = 0; i < classes.length; i++) {
12212 if (!dom.hasClass(node, classes[i])) {
12225 * Matches the current selection or specified node against the specified format name.
12228 * @param {String} name Name of format to match.
12229 * @param {Object} vars Optional list of variables to replace before checking it.
12230 * @param {Node} node Optional node to check.
12231 * @return {boolean} true/false if the specified selection/node matches the format.
12233 function match(name, vars, node) {
12236 function matchParents(node) {
12237 var root = dom.getRoot();
12239 // Find first node with similar format settings
12240 node = dom.getParent(node, function(node) {
12241 return node.parentNode === root || !!matchNode(node, name, vars, true);
12244 // Do an exact check on the similar format element
12245 return matchNode(node, name, vars);
12248 // Check specified node
12250 return matchParents(node);
12253 // Check selected node
12254 node = selection.getNode();
12255 if (matchParents(node)) {
12259 // Check start node if it's different
12260 startNode = selection.getStart();
12261 if (startNode != node) {
12262 if (matchParents(startNode)) {
12271 * Matches the current selection against the array of formats and returns a new array with matching formats.
12274 * @param {Array} names Name of format to match.
12275 * @param {Object} vars Optional list of variables to replace before checking it.
12276 * @return {Array} Array with matched formats.
12278 function matchAll(names, vars) {
12279 var startElement, matchedFormatNames = [], checkedMap = {};
12281 // Check start of selection for formats
12282 startElement = selection.getStart();
12283 dom.getParent(startElement, function(node) {
12286 for (i = 0; i < names.length; i++) {
12289 if (!checkedMap[name] && matchNode(node, name, vars)) {
12290 checkedMap[name] = true;
12291 matchedFormatNames.push(name);
12296 return matchedFormatNames;
12300 * Returns true/false if the specified format can be applied to the current selection or not. It
12301 * will currently only check the state for selector formats, it returns true on all other format types.
12304 * @param {String} name Name of format to check.
12305 * @return {boolean} true/false if the specified format can be applied to the current selection/node.
12307 function canApply(name) {
12308 var formatList = get(name), startNode, parents, i, x, selector;
12311 startNode = selection.getStart();
12312 parents = getParents(startNode);
12314 for (x = formatList.length - 1; x >= 0; x--) {
12315 selector = formatList[x].selector;
12317 // Format is not selector based then always return TRUE
12318 // Is it has a defaultBlock then it's likely it can be applied for example align on a non block element line
12319 if (!selector || formatList[x].defaultBlock) {
12323 for (i = parents.length - 1; i >= 0; i--) {
12324 if (dom.is(parents[i], selector)) {
12335 * Executes the specified callback when the current selection matches the formats or not.
12337 * @method formatChanged
12338 * @param {String} formats Comma separated list of formats to check for.
12339 * @param {function} callback Callback with state and args when the format is changed/toggled on/off.
12340 * @param {Boolean} similar True/false state if the match should handle similar or exact formats.
12342 function formatChanged(formats, callback, similar) {
12343 var currentFormats;
12345 // Setup format node change logic
12346 if (!formatChangeData) {
12347 formatChangeData = {};
12348 currentFormats = {};
12350 ed.on('NodeChange', function(e) {
12351 var parents = getParents(e.element), matchedFormats = {};
12353 // Check for new formats
12354 each(formatChangeData, function(callbacks, format) {
12355 each(parents, function(node) {
12356 if (matchNode(node, format, {}, callbacks.similar)) {
12357 if (!currentFormats[format]) {
12358 // Execute callbacks
12359 each(callbacks, function(callback) {
12360 callback(true, {node: node, format: format, parents: parents});
12363 currentFormats[format] = callbacks;
12366 matchedFormats[format] = callbacks;
12372 // Check if current formats still match
12373 each(currentFormats, function(callbacks, format) {
12374 if (!matchedFormats[format]) {
12375 delete currentFormats[format];
12377 each(callbacks, function(callback) {
12378 callback(false, {node: e.element, format: format, parents: parents});
12385 // Add format listeners
12386 each(formats.split(','), function(format) {
12387 if (!formatChangeData[format]) {
12388 formatChangeData[format] = [];
12389 formatChangeData[format].similar = similar;
12392 formatChangeData[format].push(callback);
12398 // Expose to public
12401 register: register,
12406 matchAll: matchAll,
12407 matchNode: matchNode,
12408 canApply: canApply,
12409 formatChanged: formatChanged
12414 addKeyboardShortcuts();
12415 ed.on('BeforeGetContent', function() {
12416 if (markCaretContainersBogus) {
12417 markCaretContainersBogus();
12420 ed.on('mouseup keydown', function(e) {
12421 if (disableCaretContainer) {
12422 disableCaretContainer(e);
12426 // Private functions
12429 * Checks if the specified nodes name matches the format inline/block or selector.
12432 * @param {Node} node Node to match against the specified format.
12433 * @param {Object} format Format object o match with.
12434 * @return {boolean} true/false if the format matches.
12436 function matchName(node, format) {
12437 // Check for inline match
12438 if (isEq(node, format.inline)) {
12442 // Check for block match
12443 if (isEq(node, format.block)) {
12447 // Check for selector match
12448 if (format.selector) {
12449 return node.nodeType == 1 && dom.is(node, format.selector);
12454 * Compares two string/nodes regardless of their case.
12457 * @param {String/Node} Node or string to compare.
12458 * @param {String/Node} Node or string to compare.
12459 * @return {boolean} True/false if they match.
12461 function isEq(str1, str2) {
12465 str1 = '' + (str1.nodeName || str1);
12466 str2 = '' + (str2.nodeName || str2);
12468 return str1.toLowerCase() == str2.toLowerCase();
12472 * Returns the style by name on the specified node. This method modifies the style
12473 * contents to make it more easy to match. This will resolve a few browser issues.
12476 * @param {Node} node to get style from.
12477 * @param {String} name Style name to get.
12478 * @return {String} Style item value.
12480 function getStyle(node, name) {
12481 return normalizeStyleValue(dom.getStyle(node, name), name);
12485 * Normalize style value by name. This method modifies the style contents
12486 * to make it more easy to match. This will resolve a few browser issues.
12489 * @param {Node} node to get style from.
12490 * @param {String} name Style name to get.
12491 * @return {String} Style item value.
12493 function normalizeStyleValue(value, name) {
12494 // Force the format to hex
12495 if (name == 'color' || name == 'backgroundColor') {
12496 value = dom.toHex(value);
12499 // Opera will return bold as 700
12500 if (name == 'fontWeight' && value == 700) {
12504 // Normalize fontFamily so "'Font name', Font" becomes: "Font name,Font"
12505 if (name == 'fontFamily') {
12506 value = value.replace(/[\'\"]/g, '').replace(/,\s+/g, ',');
12513 * Replaces variables in the value. The variable format is %var.
12516 * @param {String} value Value to replace variables in.
12517 * @param {Object} vars Name/value array with variables to replace.
12518 * @return {String} New value with replaced variables.
12520 function replaceVars(value, vars) {
12521 if (typeof(value) != "string") {
12522 value = value(vars);
12524 value = value.replace(/%(\w+)/g, function(str, name) {
12525 return vars[name] || str;
12532 function isWhiteSpaceNode(node) {
12533 return node && node.nodeType === 3 && /^([\t \r\n]+|)$/.test(node.nodeValue);
12536 function wrap(node, name, attrs) {
12537 var wrapper = dom.create(name, attrs);
12539 node.parentNode.insertBefore(wrapper, node);
12540 wrapper.appendChild(node);
12546 * Expands the specified range like object to depending on format.
12548 * For example on block formats it will move the start/end position
12549 * to the beginning of the current block.
12552 * @param {Object} rng Range like object.
12553 * @param {Array} formats Array with formats to expand by.
12554 * @return {Object} Expanded range like object.
12556 function expandRng(rng, format, remove) {
12557 var lastIdx, leaf, endPoint,
12558 startContainer = rng.startContainer,
12559 startOffset = rng.startOffset,
12560 endContainer = rng.endContainer,
12561 endOffset = rng.endOffset;
12563 // This function walks up the tree if there is no siblings before/after the node
12564 function findParentContainer(start) {
12565 var container, parent, sibling, siblingName, root;
12567 container = parent = start ? startContainer : endContainer;
12568 siblingName = start ? 'previousSibling' : 'nextSibling';
12569 root = dom.getRoot();
12571 function isBogusBr(node) {
12572 return node.nodeName == "BR" && node.getAttribute('data-mce-bogus') && !node.nextSibling;
12575 // If it's a text node and the offset is inside the text
12576 if (container.nodeType == 3 && !isWhiteSpaceNode(container)) {
12577 if (start ? startOffset > 0 : endOffset < container.nodeValue.length) {
12583 // Stop expanding on block elements
12584 if (!format[0].block_expand && isBlock(parent)) {
12589 for (sibling = parent[siblingName]; sibling; sibling = sibling[siblingName]) {
12590 if (!isBookmarkNode(sibling) && !isWhiteSpaceNode(sibling) && !isBogusBr(sibling)) {
12595 // Check if we can move up are we at root level or body level
12596 if (parent.parentNode == root) {
12597 container = parent;
12601 parent = parent.parentNode;
12607 // This function walks down the tree to find the leaf at the selection.
12608 // The offset is also returned as if node initially a leaf, the offset may be in the middle of the text node.
12609 function findLeaf(node, offset) {
12610 if (offset === undef) {
12611 offset = node.nodeType === 3 ? node.length : node.childNodes.length;
12614 while (node && node.hasChildNodes()) {
12615 node = node.childNodes[offset];
12617 offset = node.nodeType === 3 ? node.length : node.childNodes.length;
12620 return { node: node, offset: offset };
12623 // If index based start position then resolve it
12624 if (startContainer.nodeType == 1 && startContainer.hasChildNodes()) {
12625 lastIdx = startContainer.childNodes.length - 1;
12626 startContainer = startContainer.childNodes[startOffset > lastIdx ? lastIdx : startOffset];
12628 if (startContainer.nodeType == 3) {
12633 // If index based end position then resolve it
12634 if (endContainer.nodeType == 1 && endContainer.hasChildNodes()) {
12635 lastIdx = endContainer.childNodes.length - 1;
12636 endContainer = endContainer.childNodes[endOffset > lastIdx ? lastIdx : endOffset - 1];
12638 if (endContainer.nodeType == 3) {
12639 endOffset = endContainer.nodeValue.length;
12643 // Expands the node to the closes contentEditable false element if it exists
12644 function findParentContentEditable(node) {
12648 if (parent.nodeType === 1 && getContentEditable(parent)) {
12649 return getContentEditable(parent) === "false" ? parent : node;
12652 parent = parent.parentNode;
12658 function findWordEndPoint(container, offset, start) {
12659 var walker, node, pos, lastTextNode;
12661 function findSpace(node, offset) {
12662 var pos, pos2, str = node.nodeValue;
12664 if (typeof(offset) == "undefined") {
12665 offset = start ? str.length : 0;
12669 pos = str.lastIndexOf(' ', offset);
12670 pos2 = str.lastIndexOf('\u00a0', offset);
12671 pos = pos > pos2 ? pos : pos2;
12673 // Include the space on remove to avoid tag soup
12674 if (pos !== -1 && !remove) {
12678 pos = str.indexOf(' ', offset);
12679 pos2 = str.indexOf('\u00a0', offset);
12680 pos = pos !== -1 && (pos2 === -1 || pos < pos2) ? pos : pos2;
12686 if (container.nodeType === 3) {
12687 pos = findSpace(container, offset);
12690 return {container: container, offset: pos};
12693 lastTextNode = container;
12696 // Walk the nodes inside the block
12697 walker = new TreeWalker(container, dom.getParent(container, isBlock) || ed.getBody());
12698 while ((node = walker[start ? 'prev' : 'next']())) {
12699 if (node.nodeType === 3) {
12700 lastTextNode = node;
12701 pos = findSpace(node);
12704 return {container: node, offset: pos};
12706 } else if (isBlock(node)) {
12711 if (lastTextNode) {
12715 offset = lastTextNode.length;
12718 return {container: lastTextNode, offset: offset};
12722 function findSelectorEndPoint(container, sibling_name) {
12723 var parents, i, y, curFormat;
12725 if (container.nodeType == 3 && container.nodeValue.length === 0 && container[sibling_name]) {
12726 container = container[sibling_name];
12729 parents = getParents(container);
12730 for (i = 0; i < parents.length; i++) {
12731 for (y = 0; y < format.length; y++) {
12732 curFormat = format[y];
12734 // If collapsed state is set then skip formats that doesn't match that
12735 if ("collapsed" in curFormat && curFormat.collapsed !== rng.collapsed) {
12739 if (dom.is(parents[i], curFormat.selector)) {
12748 function findBlockEndPoint(container, sibling_name) {
12749 var node, root = dom.getRoot();
12751 // Expand to block of similar type
12752 if (!format[0].wrapper) {
12753 node = dom.getParent(container, format[0].block);
12756 // Expand to first wrappable block element or any block element
12758 node = dom.getParent(container.nodeType == 3 ? container.parentNode : container, function(node) {
12759 // Fixes #6183 where it would expand to editable parent element in inline mode
12760 return node != root && isTextBlock(node);
12764 // Exclude inner lists from wrapping
12765 if (node && format[0].wrapper) {
12766 node = getParents(node, 'ul,ol').reverse()[0] || node;
12769 // Didn't find a block element look for first/last wrappable element
12773 while (node[sibling_name] && !isBlock(node[sibling_name])) {
12774 node = node[sibling_name];
12776 // Break on BR but include it will be removed later on
12777 // we can't remove it now since we need to check if it can be wrapped
12778 if (isEq(node, 'br')) {
12784 return node || container;
12787 // Expand to closest contentEditable element
12788 startContainer = findParentContentEditable(startContainer);
12789 endContainer = findParentContentEditable(endContainer);
12791 // Exclude bookmark nodes if possible
12792 if (isBookmarkNode(startContainer.parentNode) || isBookmarkNode(startContainer)) {
12793 startContainer = isBookmarkNode(startContainer) ? startContainer : startContainer.parentNode;
12794 startContainer = startContainer.nextSibling || startContainer;
12796 if (startContainer.nodeType == 3) {
12801 if (isBookmarkNode(endContainer.parentNode) || isBookmarkNode(endContainer)) {
12802 endContainer = isBookmarkNode(endContainer) ? endContainer : endContainer.parentNode;
12803 endContainer = endContainer.previousSibling || endContainer;
12805 if (endContainer.nodeType == 3) {
12806 endOffset = endContainer.length;
12810 if (format[0].inline) {
12811 if (rng.collapsed) {
12812 // Expand left to closest word boundary
12813 endPoint = findWordEndPoint(startContainer, startOffset, true);
12815 startContainer = endPoint.container;
12816 startOffset = endPoint.offset;
12819 // Expand right to closest word boundary
12820 endPoint = findWordEndPoint(endContainer, endOffset);
12822 endContainer = endPoint.container;
12823 endOffset = endPoint.offset;
12827 // Avoid applying formatting to a trailing space.
12828 leaf = findLeaf(endContainer, endOffset);
12830 while (leaf.node && leaf.offset === 0 && leaf.node.previousSibling) {
12831 leaf = findLeaf(leaf.node.previousSibling);
12834 if (leaf.node && leaf.offset > 0 && leaf.node.nodeType === 3 &&
12835 leaf.node.nodeValue.charAt(leaf.offset - 1) === ' ') {
12837 if (leaf.offset > 1) {
12838 endContainer = leaf.node;
12839 endContainer.splitText(leaf.offset - 1);
12845 // Move start/end point up the tree if the leaves are sharp and if we are in different containers
12846 // Example * becomes !: !<p><b><i>*text</i><i>text*</i></b></p>!
12847 // This will reduce the number of wrapper elements that needs to be created
12848 // Move start point up the tree
12849 if (format[0].inline || format[0].block_expand) {
12850 if (!format[0].inline || (startContainer.nodeType != 3 || startOffset === 0)) {
12851 startContainer = findParentContainer(true);
12854 if (!format[0].inline || (endContainer.nodeType != 3 || endOffset === endContainer.nodeValue.length)) {
12855 endContainer = findParentContainer();
12859 // Expand start/end container to matching selector
12860 if (format[0].selector && format[0].expand !== FALSE && !format[0].inline) {
12861 // Find new startContainer/endContainer if there is better one
12862 startContainer = findSelectorEndPoint(startContainer, 'previousSibling');
12863 endContainer = findSelectorEndPoint(endContainer, 'nextSibling');
12866 // Expand start/end container to matching block element or text node
12867 if (format[0].block || format[0].selector) {
12868 // Find new startContainer/endContainer if there is better one
12869 startContainer = findBlockEndPoint(startContainer, 'previousSibling');
12870 endContainer = findBlockEndPoint(endContainer, 'nextSibling');
12872 // Non block element then try to expand up the leaf
12873 if (format[0].block) {
12874 if (!isBlock(startContainer)) {
12875 startContainer = findParentContainer(true);
12878 if (!isBlock(endContainer)) {
12879 endContainer = findParentContainer();
12884 // Setup index for startContainer
12885 if (startContainer.nodeType == 1) {
12886 startOffset = nodeIndex(startContainer);
12887 startContainer = startContainer.parentNode;
12890 // Setup index for endContainer
12891 if (endContainer.nodeType == 1) {
12892 endOffset = nodeIndex(endContainer) + 1;
12893 endContainer = endContainer.parentNode;
12896 // Return new range like object
12898 startContainer: startContainer,
12899 startOffset: startOffset,
12900 endContainer: endContainer,
12901 endOffset: endOffset
12906 * Removes the specified format for the specified node. It will also remove the node if it doesn't have
12907 * any attributes if the format specifies it to do so.
12910 * @param {Object} format Format object with items to remove from node.
12911 * @param {Object} vars Name/value object with variables to apply to format.
12912 * @param {Node} node Node to remove the format styles on.
12913 * @param {Node} compare_node Optional compare node, if specified the styles will be compared to that node.
12914 * @return {Boolean} True/false if the node was removed or not.
12916 function removeFormat(format, vars, node, compare_node) {
12917 var i, attrs, stylesModified;
12919 // Check if node matches format
12920 if (!matchName(node, format)) {
12924 // Should we compare with format attribs and styles
12925 if (format.remove != 'all') {
12927 each(format.styles, function(value, name) {
12928 value = normalizeStyleValue(replaceVars(value, vars), name);
12931 if (typeof(name) === 'number') {
12936 if (!compare_node || isEq(getStyle(compare_node, name), value)) {
12937 dom.setStyle(node, name, '');
12940 stylesModified = 1;
12943 // Remove style attribute if it's empty
12944 if (stylesModified && dom.getAttrib(node, 'style') === '') {
12945 node.removeAttribute('style');
12946 node.removeAttribute('data-mce-style');
12949 // Remove attributes
12950 each(format.attributes, function(value, name) {
12953 value = replaceVars(value, vars);
12956 if (typeof(name) === 'number') {
12961 if (!compare_node || isEq(dom.getAttrib(compare_node, name), value)) {
12962 // Keep internal classes
12963 if (name == 'class') {
12964 value = dom.getAttrib(node, name);
12966 // Build new class value where everything is removed except the internal prefixed classes
12968 each(value.split(/\s+/), function(cls) {
12969 if (/mce\w+/.test(cls)) {
12970 valueOut += (valueOut ? ' ' : '') + cls;
12974 // We got some internal classes left
12976 dom.setAttrib(node, name, valueOut);
12982 // IE6 has a bug where the attribute doesn't get removed correctly
12983 if (name == "class") {
12984 node.removeAttribute('className');
12987 // Remove mce prefixed attributes
12988 if (MCE_ATTR_RE.test(name)) {
12989 node.removeAttribute('data-mce-' + name);
12992 node.removeAttribute(name);
12997 each(format.classes, function(value) {
12998 value = replaceVars(value, vars);
13000 if (!compare_node || dom.hasClass(compare_node, value)) {
13001 dom.removeClass(node, value);
13005 // Check for non internal attributes
13006 attrs = dom.getAttribs(node);
13007 for (i = 0; i < attrs.length; i++) {
13008 if (attrs[i].nodeName.indexOf('_') !== 0) {
13014 // Remove the inline child if it's empty for example <b> or <span>
13015 if (format.remove != 'none') {
13016 removeNode(node, format);
13022 * Removes the node and wrap it's children in paragraphs before doing so or
13023 * appends BR elements to the beginning/end of the block element if forcedRootBlocks is disabled.
13025 * If the div in the node below gets removed:
13026 * text<div>text</div>text
13029 * text<div><br />text<br /></div>text
13031 * So when the div is removed the result is:
13032 * text<br />text<br />text
13035 * @param {Node} node Node to remove + apply BR/P elements to.
13036 * @param {Object} format Format rule.
13037 * @return {Node} Input node.
13039 function removeNode(node, format) {
13040 var parentNode = node.parentNode, rootBlockElm;
13042 function find(node, next, inc) {
13043 node = getNonWhiteSpaceSibling(node, next, inc);
13045 return !node || (node.nodeName == 'BR' || isBlock(node));
13048 if (format.block) {
13049 if (!forcedRootBlock) {
13050 // Append BR elements if needed before we remove the block
13051 if (isBlock(node) && !isBlock(parentNode)) {
13052 if (!find(node, FALSE) && !find(node.firstChild, TRUE, 1)) {
13053 node.insertBefore(dom.create('br'), node.firstChild);
13056 if (!find(node, TRUE) && !find(node.lastChild, FALSE, 1)) {
13057 node.appendChild(dom.create('br'));
13061 // Wrap the block in a forcedRootBlock if we are at the root of document
13062 if (parentNode == dom.getRoot()) {
13063 if (!format.list_block || !isEq(node, format.list_block)) {
13064 each(grep(node.childNodes), function(node) {
13065 if (isValid(forcedRootBlock, node.nodeName.toLowerCase())) {
13066 if (!rootBlockElm) {
13067 rootBlockElm = wrap(node, forcedRootBlock);
13069 rootBlockElm.appendChild(node);
13080 // Never remove nodes that isn't the specified inline element if a selector is specified too
13081 if (format.selector && format.inline && !isEq(format.inline, node)) {
13085 dom.remove(node, 1);
13089 * Returns the next/previous non whitespace node.
13092 * @param {Node} node Node to start at.
13093 * @param {boolean} next (Optional) Include next or previous node defaults to previous.
13094 * @param {boolean} inc (Optional) Include the current node in checking. Defaults to false.
13095 * @return {Node} Next or previous node or undefined if it wasn't found.
13097 function getNonWhiteSpaceSibling(node, next, inc) {
13099 next = next ? 'nextSibling' : 'previousSibling';
13101 for (node = inc ? node : node[next]; node; node = node[next]) {
13102 if (node.nodeType == 1 || !isWhiteSpaceNode(node)) {
13110 * Checks if the specified node is a bookmark node or not.
13113 * @param {Node} node Node to check if it's a bookmark node or not.
13114 * @return {Boolean} true/false if the node is a bookmark node.
13116 function isBookmarkNode(node) {
13117 return node && node.nodeType == 1 && node.getAttribute('data-mce-type') == 'bookmark';
13121 * Merges the next/previous sibling element if they match.
13124 * @param {Node} prev Previous node to compare/merge.
13125 * @param {Node} next Next node to compare/merge.
13126 * @return {Node} Next node if we didn't merge and prev node if we did.
13128 function mergeSiblings(prev, next) {
13129 var sibling, tmpSibling;
13132 * Compares two nodes and checks if it's attributes and styles matches.
13133 * This doesn't compare classes as items since their order is significant.
13136 * @param {Node} node1 First node to compare with.
13137 * @param {Node} node2 Second node to compare with.
13138 * @return {boolean} True/false if the nodes are the same or not.
13140 function compareElements(node1, node2) {
13141 // Not the same name
13142 if (node1.nodeName != node2.nodeName) {
13147 * Returns all the nodes attributes excluding internal ones, styles and classes.
13150 * @param {Node} node Node to get attributes from.
13151 * @return {Object} Name/value object with attributes and attribute values.
13153 function getAttribs(node) {
13156 each(dom.getAttribs(node), function(attr) {
13157 var name = attr.nodeName.toLowerCase();
13159 // Don't compare internal attributes or style
13160 if (name.indexOf('_') !== 0 && name !== 'style') {
13161 attribs[name] = dom.getAttrib(node, name);
13169 * Compares two objects checks if it's key + value exists in the other one.
13172 * @param {Object} obj1 First object to compare.
13173 * @param {Object} obj2 Second object to compare.
13174 * @return {boolean} True/false if the objects matches or not.
13176 function compareObjects(obj1, obj2) {
13179 for (name in obj1) {
13180 // Obj1 has item obj2 doesn't have
13181 if (obj1.hasOwnProperty(name)) {
13182 value = obj2[name];
13184 // Obj2 doesn't have obj1 item
13185 if (value === undef) {
13189 // Obj2 item has a different value
13190 if (obj1[name] != value) {
13194 // Delete similar value
13199 // Check if obj 2 has something obj 1 doesn't have
13200 for (name in obj2) {
13201 // Obj2 has item obj1 doesn't have
13202 if (obj2.hasOwnProperty(name)) {
13210 // Attribs are not the same
13211 if (!compareObjects(getAttribs(node1), getAttribs(node2))) {
13215 // Styles are not the same
13216 if (!compareObjects(dom.parseStyle(dom.getAttrib(node1, 'style')), dom.parseStyle(dom.getAttrib(node2, 'style')))) {
13223 function findElementSibling(node, sibling_name) {
13224 for (sibling = node; sibling; sibling = sibling[sibling_name]) {
13225 if (sibling.nodeType == 3 && sibling.nodeValue.length !== 0) {
13229 if (sibling.nodeType == 1 && !isBookmarkNode(sibling)) {
13237 // Check if next/prev exists and that they are elements
13238 if (prev && next) {
13239 // If previous sibling is empty then jump over it
13240 prev = findElementSibling(prev, 'previousSibling');
13241 next = findElementSibling(next, 'nextSibling');
13243 // Compare next and previous nodes
13244 if (compareElements(prev, next)) {
13245 // Append nodes between
13246 for (sibling = prev.nextSibling; sibling && sibling != next;) {
13247 tmpSibling = sibling;
13248 sibling = sibling.nextSibling;
13249 prev.appendChild(tmpSibling);
13252 // Remove next node
13255 // Move children into prev node
13256 each(grep(next.childNodes), function(node) {
13257 prev.appendChild(node);
13267 function getContainer(rng, start) {
13268 var container, offset, lastIdx;
13270 container = rng[start ? 'startContainer' : 'endContainer'];
13271 offset = rng[start ? 'startOffset' : 'endOffset'];
13273 if (container.nodeType == 1) {
13274 lastIdx = container.childNodes.length - 1;
13276 if (!start && offset) {
13280 container = container.childNodes[offset > lastIdx ? lastIdx : offset];
13283 // If start text node is excluded then walk to the next node
13284 if (container.nodeType === 3 && start && offset >= container.nodeValue.length) {
13285 container = new TreeWalker(container, ed.getBody()).next() || container;
13288 // If end text node is excluded then walk to the previous node
13289 if (container.nodeType === 3 && !start && offset === 0) {
13290 container = new TreeWalker(container, ed.getBody()).prev() || container;
13296 function performCaretAction(type, name, vars) {
13297 var caretContainerId = '_mce_caret', debug = ed.settings.caret_debug;
13299 // Creates a caret container bogus element
13300 function createCaretContainer(fill) {
13301 var caretContainer = dom.create('span', {id: caretContainerId, 'data-mce-bogus': true, style: debug ? 'color:red' : ''});
13304 caretContainer.appendChild(ed.getDoc().createTextNode(INVISIBLE_CHAR));
13307 return caretContainer;
13310 function isCaretContainerEmpty(node, nodes) {
13312 if ((node.nodeType === 3 && node.nodeValue !== INVISIBLE_CHAR) || node.childNodes.length > 1) {
13317 if (nodes && node.nodeType === 1) {
13321 node = node.firstChild;
13327 // Returns any parent caret container element
13328 function getParentCaretContainer(node) {
13330 if (node.id === caretContainerId) {
13334 node = node.parentNode;
13338 // Finds the first text node in the specified node
13339 function findFirstTextNode(node) {
13343 walker = new TreeWalker(node, node);
13345 for (node = walker.current(); node; node = walker.next()) {
13346 if (node.nodeType === 3) {
13353 // Removes the caret container for the specified node or all on the current document
13354 function removeCaretContainer(node, move_caret) {
13358 node = getParentCaretContainer(selection.getStart());
13361 while ((node = dom.get(caretContainerId))) {
13362 removeCaretContainer(node, false);
13366 rng = selection.getRng(true);
13368 if (isCaretContainerEmpty(node)) {
13369 if (move_caret !== false) {
13370 rng.setStartBefore(node);
13371 rng.setEndBefore(node);
13376 child = findFirstTextNode(node);
13378 if (child.nodeValue.charAt(0) === INVISIBLE_CHAR) {
13379 child = child.deleteData(0, 1);
13382 dom.remove(node, 1);
13385 selection.setRng(rng);
13389 // Applies formatting to the caret postion
13390 function applyCaretFormat() {
13391 var rng, caretContainer, textNode, offset, bookmark, container, text;
13393 rng = selection.getRng(true);
13394 offset = rng.startOffset;
13395 container = rng.startContainer;
13396 text = container.nodeValue;
13398 caretContainer = getParentCaretContainer(selection.getStart());
13399 if (caretContainer) {
13400 textNode = findFirstTextNode(caretContainer);
13403 // Expand to word is caret is in the middle of a text node and the char before/after is a alpha numeric character
13404 if (text && offset > 0 && offset < text.length && /\w/.test(text.charAt(offset)) && /\w/.test(text.charAt(offset - 1))) {
13405 // Get bookmark of caret position
13406 bookmark = selection.getBookmark();
13408 // Collapse bookmark range (WebKit)
13409 rng.collapse(true);
13411 // Expand the range to the closest word and split it at those points
13412 rng = expandRng(rng, get(name));
13413 rng = rangeUtils.split(rng);
13415 // Apply the format to the range
13416 apply(name, vars, rng);
13418 // Move selection back to caret position
13419 selection.moveToBookmark(bookmark);
13421 if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
13422 caretContainer = createCaretContainer(true);
13423 textNode = caretContainer.firstChild;
13425 rng.insertNode(caretContainer);
13428 apply(name, vars, caretContainer);
13430 apply(name, vars, caretContainer);
13433 // Move selection to text node
13434 selection.setCursorLocation(textNode, offset);
13438 function removeCaretFormat() {
13439 var rng = selection.getRng(true), container, offset, bookmark,
13440 hasContentAfter, node, formatNode, parents = [], i, caretContainer;
13442 container = rng.startContainer;
13443 offset = rng.startOffset;
13446 if (container.nodeType == 3) {
13447 if (offset != container.nodeValue.length || container.nodeValue === INVISIBLE_CHAR) {
13448 hasContentAfter = true;
13451 node = node.parentNode;
13455 if (matchNode(node, name, vars)) {
13460 if (node.nextSibling) {
13461 hasContentAfter = true;
13464 parents.push(node);
13465 node = node.parentNode;
13468 // Node doesn't have the specified format
13473 // Is there contents after the caret then remove the format on the element
13474 if (hasContentAfter) {
13475 // Get bookmark of caret position
13476 bookmark = selection.getBookmark();
13478 // Collapse bookmark range (WebKit)
13479 rng.collapse(true);
13481 // Expand the range to the closest word and split it at those points
13482 rng = expandRng(rng, get(name), true);
13483 rng = rangeUtils.split(rng);
13485 // Remove the format from the range
13486 remove(name, vars, rng);
13488 // Move selection back to caret position
13489 selection.moveToBookmark(bookmark);
13491 caretContainer = createCaretContainer();
13493 node = caretContainer;
13494 for (i = parents.length - 1; i >= 0; i--) {
13495 node.appendChild(dom.clone(parents[i], false));
13496 node = node.firstChild;
13499 // Insert invisible character into inner most format element
13500 node.appendChild(dom.doc.createTextNode(INVISIBLE_CHAR));
13501 node = node.firstChild;
13503 var block = dom.getParent(formatNode, isTextBlock);
13505 if (block && dom.isEmpty(block)) {
13506 // Replace formatNode with caretContainer when removing format from empty block like <p><b>|</b></p>
13507 formatNode.parentNode.replaceChild(caretContainer, formatNode);
13509 // Insert caret container after the formated node
13510 dom.insertAfter(caretContainer, formatNode);
13513 // Move selection to text node
13514 selection.setCursorLocation(node, 1);
13515 // If the formatNode is empty, we can remove it safely.
13516 if(dom.isEmpty(formatNode)) {
13517 dom.remove(formatNode);
13522 // Checks if the parent caret container node isn't empty if that is the case it
13523 // will remove the bogus state on all children that isn't empty
13524 function unmarkBogusCaretParents() {
13525 var caretContainer;
13527 caretContainer = getParentCaretContainer(selection.getStart());
13528 if (caretContainer && !dom.isEmpty(caretContainer)) {
13529 walk(caretContainer, function(node) {
13530 if (node.nodeType == 1 && node.id !== caretContainerId && !dom.isEmpty(node)) {
13531 dom.setAttrib(node, 'data-mce-bogus', null);
13537 // Only bind the caret events once
13538 if (!ed._hasCaretEvents) {
13539 // Mark current caret container elements as bogus when getting the contents so we don't end up with empty elements
13540 markCaretContainersBogus = function() {
13543 if (isCaretContainerEmpty(getParentCaretContainer(selection.getStart()), nodes)) {
13547 dom.setAttrib(nodes[i], 'data-mce-bogus', '1');
13552 disableCaretContainer = function(e) {
13553 var keyCode = e.keyCode;
13555 removeCaretContainer();
13557 // Remove caret container on keydown and it's a backspace, enter or left/right arrow keys
13558 if (keyCode == 8 || keyCode == 37 || keyCode == 39) {
13559 removeCaretContainer(getParentCaretContainer(selection.getStart()));
13562 unmarkBogusCaretParents();
13565 // Remove bogus state if they got filled by contents using editor.selection.setContent
13566 ed.on('SetContent', function(e) {
13568 unmarkBogusCaretParents();
13571 ed._hasCaretEvents = true;
13574 // Do apply or remove caret format
13575 if (type == "apply") {
13576 applyCaretFormat();
13578 removeCaretFormat();
13583 * Moves the start to the first suitable text node.
13585 function moveStart(rng) {
13586 var container = rng.startContainer,
13587 offset = rng.startOffset, isAtEndOfText,
13588 walker, node, nodes, tmpNode;
13590 // Convert text node into index if possible
13591 if (container.nodeType == 3 && offset >= container.nodeValue.length) {
13592 // Get the parent container location and walk from there
13593 offset = nodeIndex(container);
13594 container = container.parentNode;
13595 isAtEndOfText = true;
13598 // Move startContainer/startOffset in to a suitable node
13599 if (container.nodeType == 1) {
13600 nodes = container.childNodes;
13601 container = nodes[Math.min(offset, nodes.length - 1)];
13602 walker = new TreeWalker(container, dom.getParent(container, dom.isBlock));
13604 // If offset is at end of the parent node walk to the next one
13605 if (offset > nodes.length - 1 || isAtEndOfText) {
13609 for (node = walker.current(); node; node = walker.next()) {
13610 if (node.nodeType == 3 && !isWhiteSpaceNode(node)) {
13611 // IE has a "neat" feature where it moves the start node into the closest element
13612 // we can avoid this by inserting an element before it and then remove it after we set the selection
13613 tmpNode = dom.create('a', null, INVISIBLE_CHAR);
13614 node.parentNode.insertBefore(tmpNode, node);
13616 // Set selection and remove tmpNode
13617 rng.setStart(node, 0);
13618 selection.setRng(rng);
13619 dom.remove(tmpNode);
13629 // Included from: js/tinymce/classes/UndoManager.js
13634 * Copyright, Moxiecode Systems AB
13635 * Released under LGPL License.
13637 * License: http://www.tinymce.com/license
13638 * Contributing: http://www.tinymce.com/contributing
13642 * This class handles the undo/redo history levels for the editor. Since the build in undo/redo has major drawbacks a custom one was needed.
13644 * @class tinymce.UndoManager
13646 define("tinymce/UndoManager", [
13648 "tinymce/util/Tools"
13649 ], function(Env, Tools) {
13650 var trim = Tools.trim, trimContentRegExp;
13652 trimContentRegExp = new RegExp([
13653 '<span[^>]+data-mce-bogus[^>]+>[\u200B\uFEFF]+<\\/span>', // Trim bogus spans like caret containers
13654 '<div[^>]+data-mce-bogus[^>]+><\\/div>', // Trim bogus divs like resize handles
13655 '\\s?data-mce-selected="[^"]+"' // Trim temporaty data-mce prefixed attributes like data-mce-selected
13656 ].join('|'), 'gi');
13658 return function(editor) {
13659 var self, index = 0, data = [], beforeBookmark, isFirstTypedCharacter, lock;
13661 // Returns a trimmed version of the current editor contents
13662 function getContent() {
13663 return trim(editor.getContent({format: 'raw', no_events: 1}).replace(trimContentRegExp, ''));
13666 function addNonTypingUndoLevel() {
13667 self.typing = false;
13671 // Add initial undo level when the editor is initialized
13672 editor.on('init', function() {
13676 // Get position before an execCommand is processed
13677 editor.on('BeforeExecCommand', function(e) {
13678 var cmd = e.command;
13680 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint') {
13681 self.beforeChange();
13685 // Add undo level after an execCommand call was made
13686 editor.on('ExecCommand', function(e) {
13687 var cmd = e.command;
13689 if (cmd != 'Undo' && cmd != 'Redo' && cmd != 'mceRepaint') {
13694 editor.on('ObjectResizeStart', function() {
13695 self.beforeChange();
13698 editor.on('SaveContent ObjectResized', addNonTypingUndoLevel);
13699 editor.dom.bind(editor.dom.getRoot(), 'dragend', addNonTypingUndoLevel);
13700 editor.dom.bind(editor.getBody(), 'focusout', function() {
13701 if (!editor.removed && self.typing) {
13702 addNonTypingUndoLevel();
13706 editor.on('KeyUp', function(e) {
13707 var keyCode = e.keyCode;
13709 if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45 || keyCode == 13 || e.ctrlKey) {
13710 addNonTypingUndoLevel();
13711 editor.nodeChanged();
13714 if (keyCode == 46 || keyCode == 8 || (Env.mac && (keyCode == 91 || keyCode == 93))) {
13715 editor.nodeChanged();
13718 // Fire a TypingUndo event on the first character entered
13719 if (isFirstTypedCharacter && self.typing) {
13720 // Make the it dirty if the content was changed after typing the first character
13721 if (!editor.isDirty()) {
13722 editor.isNotDirty = !data[0] || getContent() == data[0].content;
13724 // Fire initial change event
13725 if (!editor.isNotDirty) {
13726 editor.fire('change', {level: data[0], lastLevel: null});
13730 editor.fire('TypingUndo');
13731 isFirstTypedCharacter = false;
13732 editor.nodeChanged();
13736 editor.on('KeyDown', function(e) {
13737 var keyCode = e.keyCode;
13739 // Is caracter positon keys left,right,up,down,home,end,pgdown,pgup,enter
13740 if ((keyCode >= 33 && keyCode <= 36) || (keyCode >= 37 && keyCode <= 40) || keyCode == 45) {
13742 addNonTypingUndoLevel();
13748 // If key isn't shift,ctrl,alt,capslock,metakey
13749 if ((keyCode < 16 || keyCode > 20) && keyCode != 224 && keyCode != 91 && !self.typing) {
13750 self.beforeChange();
13751 self.typing = true;
13753 isFirstTypedCharacter = true;
13757 editor.on('MouseDown', function() {
13759 addNonTypingUndoLevel();
13763 // Add keyboard shortcuts for undo/redo keys
13764 editor.addShortcut('ctrl+z', '', 'Undo');
13765 editor.addShortcut('ctrl+y,ctrl+shift+z', '', 'Redo');
13767 editor.on('AddUndo Undo Redo ClearUndos MouseUp', function(e) {
13768 if (!e.isDefaultPrevented()) {
13769 editor.nodeChanged();
13774 // Explose for debugging reasons
13778 * State if the user is currently typing or not. This will add a typing operation into one undo
13779 * level instead of one new level for each keystroke.
13781 * @field {Boolean} typing
13786 * Stores away a bookmark to be used when performing an undo action so that the selection is before
13787 * the change has been made.
13789 * @method beforeChange
13791 beforeChange: function() {
13793 beforeBookmark = editor.selection.getBookmark(2, true);
13798 * Adds a new undo level/snapshot to the undo list.
13801 * @param {Object} l Optional undo level object to add.
13802 * @return {Object} Undo level that got added or null it a level wasn't needed.
13804 add: function(level) {
13805 var i, settings = editor.settings, lastLevel;
13807 level = level || {};
13808 level.content = getContent();
13810 if (lock || editor.fire('BeforeAddUndo', {level: level}).isDefaultPrevented()) {
13814 // Add undo level if needed
13815 lastLevel = data[index];
13816 if (lastLevel && lastLevel.content == level.content) {
13820 // Set before bookmark on previous level
13822 data[index].beforeBookmark = beforeBookmark;
13825 // Time to compress
13826 if (settings.custom_undo_redo_levels) {
13827 if (data.length > settings.custom_undo_redo_levels) {
13828 for (i = 0; i < data.length - 1; i++) {
13829 data[i] = data[i + 1];
13833 index = data.length;
13837 // Get a non intrusive normalized bookmark
13838 level.bookmark = editor.selection.getBookmark(2, true);
13840 // Crop array if needed
13841 if (index < data.length - 1) {
13842 data.length = index + 1;
13846 index = data.length - 1;
13848 var args = {level: level, lastLevel: lastLevel};
13850 editor.fire('AddUndo', args);
13853 editor.fire('change', args);
13854 editor.isNotDirty = false;
13861 * Undoes the last action.
13864 * @return {Object} Undo level or null if no undo was performed.
13871 self.typing = false;
13875 level = data[--index];
13877 editor.setContent(level.content, {format: 'raw'});
13878 editor.selection.moveToBookmark(level.beforeBookmark);
13880 editor.fire('undo', {level: level});
13887 * Redoes the last action.
13890 * @return {Object} Redo level or null if no redo was performed.
13895 if (index < data.length - 1) {
13896 level = data[++index];
13898 editor.setContent(level.content, {format: 'raw'});
13899 editor.selection.moveToBookmark(level.bookmark);
13901 editor.fire('redo', {level: level});
13908 * Removes all undo levels.
13912 clear: function() {
13915 self.typing = false;
13916 editor.fire('ClearUndos');
13920 * Returns true/false if the undo manager has any undo levels.
13923 * @return {Boolean} true/false if the undo manager has any undo levels.
13925 hasUndo: function() {
13926 // Has undo levels or typing and content isn't the same as the initial level
13927 return index > 0 || (self.typing && data[0] && getContent() != data[0].content);
13931 * Returns true/false if the undo manager has any redo levels.
13934 * @return {Boolean} true/false if the undo manager has any redo levels.
13936 hasRedo: function() {
13937 return index < data.length - 1 && !this.typing;
13941 * Executes the specified function in an undo transation. The selection
13942 * before the modification will be stored to the undo stack and if the DOM changes
13943 * it will add a new undo level. Any methods within the transation that adds undo levels will
13944 * be ignored. So a transation can include calls to execCommand or editor.insertContent.
13947 * @param {function} callback Function to execute dom manipulation logic in.
13949 transact: function(callback) {
13950 self.beforeChange();
13964 // Included from: js/tinymce/classes/EnterKey.js
13969 * Copyright, Moxiecode Systems AB
13970 * Released under LGPL License.
13972 * License: http://www.tinymce.com/license
13973 * Contributing: http://www.tinymce.com/contributing
13977 * Contains logic for handling the enter key to split/generate block elements.
13979 define("tinymce/EnterKey", [
13980 "tinymce/dom/TreeWalker",
13982 ], function(TreeWalker, Env) {
13983 var isIE = Env.ie && Env.ie < 11;
13985 return function(editor) {
13986 var dom = editor.dom, selection = editor.selection, settings = editor.settings;
13987 var undoManager = editor.undoManager, schema = editor.schema, nonEmptyElementsMap = schema.getNonEmptyElements();
13989 function handleEnterKey(evt) {
13990 var rng = selection.getRng(true), tmpRng, editableRoot, container, offset, parentBlock, documentMode, shiftKey,
13991 newBlock, fragment, containerBlock, parentBlockName, containerBlockName, newBlockName, isAfterLastNodeInContainer;
13993 // Returns true if the block can be split into two blocks or not
13994 function canSplitBlock(node) {
13996 dom.isBlock(node) &&
13997 !/^(TD|TH|CAPTION|FORM)$/.test(node.nodeName) &&
13998 !/^(fixed|absolute)/i.test(node.style.position) &&
13999 dom.getContentEditable(node) !== "true";
14002 // Renders empty block on IE
14003 function renderBlockOnIE(block) {
14006 if (dom.isBlock(block)) {
14007 oldRng = selection.getRng();
14008 block.appendChild(dom.create('span', null, '\u00a0'));
14009 selection.select(block);
14010 block.lastChild.outerHTML = '';
14011 selection.setRng(oldRng);
14015 // Remove the first empty inline element of the block so this: <p><b><em></em></b>x</p> becomes this: <p>x</p>
14016 function trimInlineElementsOnLeftSideOfBlock(block) {
14017 var node = block, firstChilds = [], i;
14019 // Find inner most first child ex: <p><i><b>*</b></i></p>
14020 while ((node = node.firstChild)) {
14021 if (dom.isBlock(node)) {
14025 if (node.nodeType == 1 && !nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
14026 firstChilds.push(node);
14030 i = firstChilds.length;
14032 node = firstChilds[i];
14033 if (!node.hasChildNodes() || (node.firstChild == node.lastChild && node.firstChild.nodeValue === '')) {
14036 // Remove <a> </a> see #5381
14037 if (node.nodeName == "A" && (node.innerText || node.textContent) === ' ') {
14044 // Moves the caret to a suitable position within the root for example in the first non
14045 // pure whitespace text node or before an image
14046 function moveToCaretPosition(root) {
14047 var walker, node, rng, lastNode = root, tempElm;
14049 rng = dom.createRng();
14051 if (root.hasChildNodes()) {
14052 walker = new TreeWalker(root, root);
14054 while ((node = walker.current())) {
14055 if (node.nodeType == 3) {
14056 rng.setStart(node, 0);
14057 rng.setEnd(node, 0);
14061 if (nonEmptyElementsMap[node.nodeName.toLowerCase()]) {
14062 rng.setStartBefore(node);
14063 rng.setEndBefore(node);
14068 node = walker.next();
14072 rng.setStart(lastNode, 0);
14073 rng.setEnd(lastNode, 0);
14076 if (root.nodeName == 'BR') {
14077 if (root.nextSibling && dom.isBlock(root.nextSibling)) {
14078 // Trick on older IE versions to render the caret before the BR between two lists
14079 if (!documentMode || documentMode < 9) {
14080 tempElm = dom.create('br');
14081 root.parentNode.insertBefore(tempElm, root);
14084 rng.setStartBefore(root);
14085 rng.setEndBefore(root);
14087 rng.setStartAfter(root);
14088 rng.setEndAfter(root);
14091 rng.setStart(root, 0);
14092 rng.setEnd(root, 0);
14096 selection.setRng(rng);
14098 // Remove tempElm created for old IE:s
14099 dom.remove(tempElm);
14100 selection.scrollIntoView(root);
14103 // Creates a new block element by cloning the current one or creating a new one if the name is specified
14104 // This function will also copy any text formatting from the parent block and add it to the new one
14105 function createNewBlock(name) {
14106 var node = container, block, clonedNode, caretNode;
14108 block = name || parentBlockName == "TABLE" ? dom.create(name || newBlockName) : parentBlock.cloneNode(false);
14111 // Clone any parent styles
14112 if (settings.keep_styles !== false) {
14114 if (/^(SPAN|STRONG|B|EM|I|FONT|STRIKE|U)$/.test(node.nodeName)) {
14115 // Never clone a caret containers
14116 if (node.id == '_mce_caret') {
14120 clonedNode = node.cloneNode(false);
14121 dom.setAttrib(clonedNode, 'id', ''); // Remove ID since it needs to be document unique
14123 if (block.hasChildNodes()) {
14124 clonedNode.appendChild(block.firstChild);
14125 block.appendChild(clonedNode);
14127 caretNode = clonedNode;
14128 block.appendChild(clonedNode);
14131 } while ((node = node.parentNode));
14134 // BR is needed in empty blocks on non IE browsers
14136 caretNode.innerHTML = '<br data-mce-bogus="1">';
14142 // Returns true/false if the caret is at the start/end of the parent block element
14143 function isCaretAtStartOrEndOfBlock(start) {
14144 var walker, node, name;
14146 // Caret is in the middle of a text node like "a|b"
14147 if (container.nodeType == 3 && (start ? offset > 0 : offset < container.nodeValue.length)) {
14151 // If after the last element in block node edge case for #5091
14152 if (container.parentNode == parentBlock && isAfterLastNodeInContainer && !start) {
14156 // If the caret if before the first element in parentBlock
14157 if (start && container.nodeType == 1 && container == parentBlock.firstChild) {
14161 // Caret can be before/after a table
14162 if (container.nodeName === "TABLE" || (container.previousSibling && container.previousSibling.nodeName == "TABLE")) {
14163 return (isAfterLastNodeInContainer && !start) || (!isAfterLastNodeInContainer && start);
14166 // Walk the DOM and look for text nodes or non empty elements
14167 walker = new TreeWalker(container, parentBlock);
14169 // If caret is in beginning or end of a text block then jump to the next/previous node
14170 if (container.nodeType == 3) {
14171 if (start && offset === 0) {
14173 } else if (!start && offset == container.nodeValue.length) {
14178 while ((node = walker.current())) {
14179 if (node.nodeType === 1) {
14180 // Ignore bogus elements
14181 if (!node.getAttribute('data-mce-bogus')) {
14182 // Keep empty elements like <img /> <input /> but not trailing br:s like <p>text|<br></p>
14183 name = node.nodeName.toLowerCase();
14184 if (nonEmptyElementsMap[name] && name !== 'br') {
14188 } else if (node.nodeType === 3 && !/^[ \t\r\n]*$/.test(node.nodeValue)) {
14202 // Wraps any text nodes or inline elements in the specified forced root block name
14203 function wrapSelfAndSiblingsInDefaultBlock(container, offset) {
14204 var newBlock, parentBlock, startNode, node, next, rootBlockName, blockName = newBlockName || 'P';
14206 // Not in a block element or in a table cell or caption
14207 parentBlock = dom.getParent(container, dom.isBlock);
14208 rootBlockName = editor.getBody().nodeName.toLowerCase();
14209 if (!parentBlock || !canSplitBlock(parentBlock)) {
14210 parentBlock = parentBlock || editableRoot;
14212 if (!parentBlock.hasChildNodes()) {
14213 newBlock = dom.create(blockName);
14214 parentBlock.appendChild(newBlock);
14215 rng.setStart(newBlock, 0);
14216 rng.setEnd(newBlock, 0);
14220 // Find parent that is the first child of parentBlock
14222 while (node.parentNode != parentBlock) {
14223 node = node.parentNode;
14226 // Loop left to find start node start wrapping at
14227 while (node && !dom.isBlock(node)) {
14229 node = node.previousSibling;
14232 if (startNode && schema.isValidChild(rootBlockName, blockName.toLowerCase())) {
14233 newBlock = dom.create(blockName);
14234 startNode.parentNode.insertBefore(newBlock, startNode);
14236 // Start wrapping until we hit a block
14238 while (node && !dom.isBlock(node)) {
14239 next = node.nextSibling;
14240 newBlock.appendChild(node);
14244 // Restore range to it's past location
14245 rng.setStart(container, offset);
14246 rng.setEnd(container, offset);
14253 // Inserts a block or br before/after or in the middle of a split list of the LI is empty
14254 function handleEmptyListItem() {
14255 function isFirstOrLastLi(first) {
14256 var node = containerBlock[first ? 'firstChild' : 'lastChild'];
14258 // Find first/last element since there might be whitespace there
14260 if (node.nodeType == 1) {
14264 node = node[first ? 'nextSibling' : 'previousSibling'];
14267 return node === parentBlock;
14270 function getContainerBlock() {
14271 var containerBlockParent = containerBlock.parentNode;
14273 if (containerBlockParent.nodeName == 'LI') {
14274 return containerBlockParent;
14277 return containerBlock;
14280 // Check if we are in an nested list
14281 var containerBlockParentName = containerBlock.parentNode.nodeName;
14282 if (/^(OL|UL|LI)$/.test(containerBlockParentName)) {
14283 newBlockName = 'LI';
14286 newBlock = newBlockName ? createNewBlock(newBlockName) : dom.create('BR');
14288 if (isFirstOrLastLi(true) && isFirstOrLastLi()) {
14289 if (containerBlockParentName == 'LI') {
14290 // Nested list is inside a LI
14291 dom.insertAfter(newBlock, getContainerBlock());
14293 // Is first and last list item then replace the OL/UL with a text block
14294 dom.replace(newBlock, containerBlock);
14296 } else if (isFirstOrLastLi(true)) {
14297 if (containerBlockParentName == 'LI') {
14298 // List nested in an LI then move the list to a new sibling LI
14299 dom.insertAfter(newBlock, getContainerBlock());
14300 newBlock.appendChild(dom.doc.createTextNode(' ')); // Needed for IE so the caret can be placed
14301 newBlock.appendChild(containerBlock);
14303 // First LI in list then remove LI and add text block before list
14304 containerBlock.parentNode.insertBefore(newBlock, containerBlock);
14306 } else if (isFirstOrLastLi()) {
14307 // Last LI in list then remove LI and add text block after list
14308 dom.insertAfter(newBlock, getContainerBlock());
14309 renderBlockOnIE(newBlock);
14311 // Middle LI in list the split the list and insert a text block in the middle
14312 // Extract after fragment and insert it after the current block
14313 containerBlock = getContainerBlock();
14314 tmpRng = rng.cloneRange();
14315 tmpRng.setStartAfter(parentBlock);
14316 tmpRng.setEndAfter(containerBlock);
14317 fragment = tmpRng.extractContents();
14318 dom.insertAfter(fragment, containerBlock);
14319 dom.insertAfter(newBlock, containerBlock);
14322 dom.remove(parentBlock);
14323 moveToCaretPosition(newBlock);
14327 // Walks the parent block to the right and look for BR elements
14328 function hasRightSideContent() {
14329 var walker = new TreeWalker(container, parentBlock), node;
14331 while ((node = walker.next())) {
14332 if (nonEmptyElementsMap[node.nodeName.toLowerCase()] || node.length > 0) {
14338 // Inserts a BR element if the forced_root_block option is set to false or empty string
14339 function insertBr() {
14340 var brElm, extraBr, marker;
14342 if (container && container.nodeType == 3 && offset >= container.nodeValue.length) {
14343 // Insert extra BR element at the end block elements
14344 if (!isIE && !hasRightSideContent()) {
14345 brElm = dom.create('br');
14346 rng.insertNode(brElm);
14347 rng.setStartAfter(brElm);
14348 rng.setEndAfter(brElm);
14353 brElm = dom.create('br');
14354 rng.insertNode(brElm);
14356 // Rendering modes below IE8 doesn't display BR elements in PRE unless we have a \n before it
14357 if (isIE && parentBlockName == 'PRE' && (!documentMode || documentMode < 8)) {
14358 brElm.parentNode.insertBefore(dom.doc.createTextNode('\r'), brElm);
14361 // Insert temp marker and scroll to that
14362 marker = dom.create('span', {}, ' ');
14363 brElm.parentNode.insertBefore(marker, brElm);
14364 selection.scrollIntoView(marker);
14365 dom.remove(marker);
14368 rng.setStartAfter(brElm);
14369 rng.setEndAfter(brElm);
14371 rng.setStartBefore(brElm);
14372 rng.setEndBefore(brElm);
14375 selection.setRng(rng);
14379 // Trims any linebreaks at the beginning of node user for example when pressing enter in a PRE element
14380 function trimLeadingLineBreaks(node) {
14382 if (node.nodeType === 3) {
14383 node.nodeValue = node.nodeValue.replace(/^[\r\n]+/, '');
14386 node = node.firstChild;
14390 function getEditableRoot(node) {
14391 var root = dom.getRoot(), parent, editableRoot;
14393 // Get all parents until we hit a non editable parent or the root
14395 while (parent !== root && dom.getContentEditable(parent) !== "false") {
14396 if (dom.getContentEditable(parent) === "true") {
14397 editableRoot = parent;
14400 parent = parent.parentNode;
14403 return parent !== root ? editableRoot : root;
14406 // Adds a BR at the end of blocks that only contains an IMG or INPUT since
14407 // these might be floated and then they won't expand the block
14408 function addBrToBlockIfNeeded(block) {
14411 // IE will render the blocks correctly other browsers needs a BR
14413 block.normalize(); // Remove empty text nodes that got left behind by the extract
14415 // Check if the block is empty or contains a floated last child
14416 lastChild = block.lastChild;
14417 if (!lastChild || (/^(left|right)$/gi.test(dom.getStyle(lastChild, 'float', true)))) {
14418 dom.add(block, 'br');
14423 // Delete any selected contents
14424 if (!rng.collapsed) {
14425 editor.execCommand('Delete');
14429 // Event is blocked by some other handler for example the lists plugin
14430 if (evt.isDefaultPrevented()) {
14434 // Setup range items and newBlockName
14435 container = rng.startContainer;
14436 offset = rng.startOffset;
14437 newBlockName = (settings.force_p_newlines ? 'p' : '') || settings.forced_root_block;
14438 newBlockName = newBlockName ? newBlockName.toUpperCase() : '';
14439 documentMode = dom.doc.documentMode;
14440 shiftKey = evt.shiftKey;
14442 // Resolve node index
14443 if (container.nodeType == 1 && container.hasChildNodes()) {
14444 isAfterLastNodeInContainer = offset > container.childNodes.length - 1;
14445 container = container.childNodes[Math.min(offset, container.childNodes.length - 1)] || container;
14446 if (isAfterLastNodeInContainer && container.nodeType == 3) {
14447 offset = container.nodeValue.length;
14453 // Get editable root node normaly the body element but sometimes a div or span
14454 editableRoot = getEditableRoot(container);
14456 // If there is no editable root then enter is done inside a contentEditable false element
14457 if (!editableRoot) {
14461 undoManager.beforeChange();
14463 // If editable root isn't block nor the root of the editor
14464 if (!dom.isBlock(editableRoot) && editableRoot != dom.getRoot()) {
14465 if (!newBlockName || shiftKey) {
14472 // Wrap the current node and it's sibling in a default block if it's needed.
14473 // for example this <td>text|<b>text2</b></td> will become this <td><p>text|<b>text2</p></b></td>
14474 // This won't happen if root blocks are disabled or the shiftKey is pressed
14475 if ((newBlockName && !shiftKey) || (!newBlockName && shiftKey)) {
14476 container = wrapSelfAndSiblingsInDefaultBlock(container, offset);
14479 // Find parent block and setup empty block paddings
14480 parentBlock = dom.getParent(container, dom.isBlock);
14481 containerBlock = parentBlock ? dom.getParent(parentBlock.parentNode, dom.isBlock) : null;
14483 // Setup block names
14484 parentBlockName = parentBlock ? parentBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
14485 containerBlockName = containerBlock ? containerBlock.nodeName.toUpperCase() : ''; // IE < 9 & HTML5
14487 // Enter inside block contained within a LI then split or insert before/after LI
14488 if (containerBlockName == 'LI' && !evt.ctrlKey) {
14489 parentBlock = containerBlock;
14490 parentBlockName = containerBlockName;
14493 // Handle enter in LI
14494 if (parentBlockName == 'LI') {
14495 if (!newBlockName && shiftKey) {
14500 // Handle enter inside an empty list item
14501 if (dom.isEmpty(parentBlock)) {
14502 handleEmptyListItem();
14507 // Don't split PRE tags but insert a BR instead easier when writing code samples etc
14508 if (parentBlockName == 'PRE' && settings.br_in_pre !== false) {
14514 // If no root block is configured then insert a BR by default or if the shiftKey is pressed
14515 if ((!newBlockName && !shiftKey && parentBlockName != 'LI') || (newBlockName && shiftKey)) {
14521 // If parent block is root then never insert new blocks
14522 if (newBlockName && parentBlock === editor.getBody()) {
14526 // Default block name if it's not configured
14527 newBlockName = newBlockName || 'P';
14529 // Insert new block before/after the parent block depending on caret location
14530 if (isCaretAtStartOrEndOfBlock()) {
14531 // If the caret is at the end of a header we produce a P tag after it similar to Word unless we are in a hgroup
14532 if (/^(H[1-6]|PRE|FIGURE)$/.test(parentBlockName) && containerBlockName != 'HGROUP') {
14533 newBlock = createNewBlock(newBlockName);
14535 newBlock = createNewBlock();
14538 // Split the current container block element if enter is pressed inside an empty inner block element
14539 if (settings.end_container_on_empty_block && canSplitBlock(containerBlock) && dom.isEmpty(parentBlock)) {
14540 // Split container block for example a BLOCKQUOTE at the current blockParent location for example a P
14541 newBlock = dom.split(containerBlock, parentBlock);
14543 dom.insertAfter(newBlock, parentBlock);
14546 moveToCaretPosition(newBlock);
14547 } else if (isCaretAtStartOrEndOfBlock(true)) {
14548 // Insert new block before
14549 newBlock = parentBlock.parentNode.insertBefore(createNewBlock(), parentBlock);
14550 renderBlockOnIE(newBlock);
14552 // Extract after fragment and insert it after the current block
14553 tmpRng = rng.cloneRange();
14554 tmpRng.setEndAfter(parentBlock);
14555 fragment = tmpRng.extractContents();
14556 trimLeadingLineBreaks(fragment);
14557 newBlock = fragment.firstChild;
14558 dom.insertAfter(fragment, parentBlock);
14559 trimInlineElementsOnLeftSideOfBlock(newBlock);
14560 addBrToBlockIfNeeded(parentBlock);
14561 moveToCaretPosition(newBlock);
14564 dom.setAttrib(newBlock, 'id', ''); // Remove ID since it needs to be document unique
14568 editor.on('keydown', function(evt) {
14569 if (evt.keyCode == 13) {
14570 if (handleEnterKey(evt) !== false) {
14571 evt.preventDefault();
14578 // Included from: js/tinymce/classes/ForceBlocks.js
14583 * Copyright, Moxiecode Systems AB
14584 * Released under LGPL License.
14586 * License: http://www.tinymce.com/license
14587 * Contributing: http://www.tinymce.com/contributing
14590 define("tinymce/ForceBlocks", [], function() {
14591 return function(editor) {
14592 var settings = editor.settings, dom = editor.dom, selection = editor.selection;
14593 var schema = editor.schema, blockElements = schema.getBlockElements();
14595 function addRootBlocks() {
14596 var node = selection.getStart(), rootNode = editor.getBody(), rng;
14597 var startContainer, startOffset, endContainer, endOffset, rootBlockNode;
14598 var tempNode, offset = -0xFFFFFF, wrapped, restoreSelection;
14599 var tmpRng, rootNodeName, forcedRootBlock;
14601 forcedRootBlock = settings.forced_root_block;
14603 if (!node || node.nodeType !== 1 || !forcedRootBlock) {
14607 // Check if node is wrapped in block
14608 while (node && node != rootNode) {
14609 if (blockElements[node.nodeName]) {
14613 node = node.parentNode;
14616 // Get current selection
14617 rng = selection.getRng();
14618 if (rng.setStart) {
14619 startContainer = rng.startContainer;
14620 startOffset = rng.startOffset;
14621 endContainer = rng.endContainer;
14622 endOffset = rng.endOffset;
14625 restoreSelection = editor.getDoc().activeElement === rootNode;
14627 // IE throws unspecified error here sometimes
14630 // Force control range into text range
14632 node = rng.item(0);
14633 rng = editor.getDoc().body.createTextRange();
14634 rng.moveToElementText(node);
14637 restoreSelection = rng.parentElement().ownerDocument === editor.getDoc();
14638 tmpRng = rng.duplicate();
14639 tmpRng.collapse(true);
14640 startOffset = tmpRng.move('character', offset) * -1;
14642 if (!tmpRng.collapsed) {
14643 tmpRng = rng.duplicate();
14644 tmpRng.collapse(false);
14645 endOffset = (tmpRng.move('character', offset) * -1) - startOffset;
14649 // Wrap non block elements and text nodes
14650 node = rootNode.firstChild;
14651 rootNodeName = rootNode.nodeName.toLowerCase();
14653 // TODO: Break this up, too complex
14654 if (((node.nodeType === 3 || (node.nodeType == 1 && !blockElements[node.nodeName]))) &&
14655 schema.isValidChild(rootNodeName, forcedRootBlock.toLowerCase())) {
14656 // Remove empty text nodes
14657 if (node.nodeType === 3 && node.nodeValue.length === 0) {
14659 node = node.nextSibling;
14660 dom.remove(tempNode);
14664 if (!rootBlockNode) {
14665 rootBlockNode = dom.create(forcedRootBlock);
14666 node.parentNode.insertBefore(rootBlockNode, node);
14671 node = node.nextSibling;
14672 rootBlockNode.appendChild(tempNode);
14674 rootBlockNode = null;
14675 node = node.nextSibling;
14679 if (wrapped && restoreSelection) {
14680 if (rng.setStart) {
14681 rng.setStart(startContainer, startOffset);
14682 rng.setEnd(endContainer, endOffset);
14683 selection.setRng(rng);
14685 // Only select if the previous selection was inside the document to prevent auto focus in quirks mode
14687 rng = editor.getDoc().body.createTextRange();
14688 rng.moveToElementText(rootNode);
14689 rng.collapse(true);
14690 rng.moveStart('character', startOffset);
14692 if (endOffset > 0) {
14693 rng.moveEnd('character', endOffset);
14702 editor.nodeChanged();
14706 // Force root blocks
14707 if (settings.forced_root_block) {
14708 editor.on('NodeChange', addRootBlocks);
14713 // Included from: js/tinymce/classes/EditorCommands.js
14716 * EditorCommands.js
14718 * Copyright, Moxiecode Systems AB
14719 * Released under LGPL License.
14721 * License: http://www.tinymce.com/license
14722 * Contributing: http://www.tinymce.com/contributing
14726 * This class enables you to add custom editor commands and it contains
14727 * overrides for native browser commands to address various bugs and issues.
14729 * @class tinymce.EditorCommands
14731 define("tinymce/EditorCommands", [
14732 "tinymce/html/Serializer",
14734 "tinymce/util/Tools"
14735 ], function(Serializer, Env, Tools) {
14736 // Added for compression purposes
14737 var each = Tools.each, extend = Tools.extend;
14738 var map = Tools.map, inArray = Tools.inArray, explode = Tools.explode;
14739 var isGecko = Env.gecko, isIE = Env.ie;
14740 var TRUE = true, FALSE = false;
14742 return function(editor) {
14743 var dom = editor.dom,
14744 selection = editor.selection,
14745 commands = {state: {}, exec: {}, value: {}},
14746 settings = editor.settings,
14747 formatter = editor.formatter,
14751 * Executes the specified command.
14753 * @method execCommand
14754 * @param {String} command Command to execute.
14755 * @param {Boolean} ui Optional user interface state.
14756 * @param {Object} value Optional value for command.
14757 * @return {Boolean} true/false if the command was found or not.
14759 function execCommand(command, ui, value) {
14762 command = command.toLowerCase();
14763 if ((func = commands.exec[command])) {
14764 func(command, ui, value);
14772 * Queries the current state for a command for example if the current selection is "bold".
14774 * @method queryCommandState
14775 * @param {String} command Command to check the state of.
14776 * @return {Boolean/Number} true/false if the selected contents is bold or not, -1 if it's not found.
14778 function queryCommandState(command) {
14781 command = command.toLowerCase();
14782 if ((func = commands.state[command])) {
14783 return func(command);
14790 * Queries the command value for example the current fontsize.
14792 * @method queryCommandValue
14793 * @param {String} command Command to check the value of.
14794 * @return {Object} Command value of false if it's not found.
14796 function queryCommandValue(command) {
14799 command = command.toLowerCase();
14800 if ((func = commands.value[command])) {
14801 return func(command);
14808 * Adds commands to the command collection.
14810 * @method addCommands
14811 * @param {Object} command_list Name/value collection with commands to add, the names can also be comma separated.
14812 * @param {String} type Optional type to add, defaults to exec. Can be value or state as well.
14814 function addCommands(command_list, type) {
14815 type = type || 'exec';
14817 each(command_list, function(callback, command) {
14818 each(command.toLowerCase().split(','), function(command) {
14819 commands[type][command] = callback;
14824 // Expose public methods
14826 execCommand: execCommand,
14827 queryCommandState: queryCommandState,
14828 queryCommandValue: queryCommandValue,
14829 addCommands: addCommands
14834 function execNativeCommand(command, ui, value) {
14835 if (ui === undefined) {
14839 if (value === undefined) {
14843 return editor.getDoc().execCommand(command, ui, value);
14846 function isFormatMatch(name) {
14847 return formatter.match(name);
14850 function toggleFormat(name, value) {
14851 formatter.toggle(name, value ? {value: value} : undefined);
14852 editor.nodeChanged();
14855 function storeSelection(type) {
14856 bookmark = selection.getBookmark(type);
14859 function restoreSelection() {
14860 selection.moveToBookmark(bookmark);
14863 // Add execCommand overrides
14865 // Ignore these, added for compatibility
14866 'mceResetDesignMode,mceBeginUndoLevel': function() {},
14868 // Add undo manager logic
14869 'mceEndUndoLevel,mceAddUndoLevel': function() {
14870 editor.undoManager.add();
14873 'Cut,Copy,Paste': function(command) {
14874 var doc = editor.getDoc(), failed;
14876 // Try executing the native command
14878 execNativeCommand(command);
14884 // Present alert message about clipboard access not being available
14885 if (failed || !doc.queryCommandSupported(command)) {
14886 editor.windowManager.alert(
14887 "Your browser doesn't support direct access to the clipboard. " +
14888 "Please use the Ctrl+X/C/V keyboard shortcuts instead."
14893 // Override unlink command
14894 unlink: function(command) {
14895 if (selection.isCollapsed()) {
14896 selection.select(selection.getNode());
14899 execNativeCommand(command);
14900 selection.collapse(FALSE);
14903 // Override justify commands to use the text formatter engine
14904 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull': function(command) {
14905 var align = command.substring(7);
14907 if (align == 'full') {
14911 // Remove all other alignments first
14912 each('left,center,right,justify'.split(','), function(name) {
14913 if (align != name) {
14914 formatter.remove('align' + name);
14918 toggleFormat('align' + align);
14919 execCommand('mceRepaint');
14922 // Override list commands to fix WebKit bug
14923 'InsertUnorderedList,InsertOrderedList': function(command) {
14924 var listElm, listParent;
14926 execNativeCommand(command);
14928 // WebKit produces lists within block elements so we need to split them
14929 // we will replace the native list creation logic to custom logic later on
14930 // TODO: Remove this when the list creation logic is removed
14931 listElm = dom.getParent(selection.getNode(), 'ol,ul');
14933 listParent = listElm.parentNode;
14935 // If list is within a text block then split that block
14936 if (/^(H[1-6]|P|ADDRESS|PRE)$/.test(listParent.nodeName)) {
14938 dom.split(listParent, listElm);
14939 restoreSelection();
14944 // Override commands to use the text formatter engine
14945 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function(command) {
14946 toggleFormat(command);
14949 // Override commands to use the text formatter engine
14950 'ForeColor,HiliteColor,FontName': function(command, ui, value) {
14951 toggleFormat(command, value);
14954 FontSize: function(command, ui, value) {
14955 var fontClasses, fontSizes;
14957 // Convert font size 1-7 to styles
14958 if (value >= 1 && value <= 7) {
14959 fontSizes = explode(settings.font_size_style_values);
14960 fontClasses = explode(settings.font_size_classes);
14963 value = fontClasses[value - 1] || value;
14965 value = fontSizes[value - 1] || value;
14969 toggleFormat(command, value);
14972 RemoveFormat: function(command) {
14973 formatter.remove(command);
14976 mceBlockQuote: function() {
14977 toggleFormat('blockquote');
14980 FormatBlock: function(command, ui, value) {
14981 return toggleFormat(value || 'p');
14984 mceCleanup: function() {
14985 var bookmark = selection.getBookmark();
14987 editor.setContent(editor.getContent({cleanup: TRUE}), {cleanup: TRUE});
14989 selection.moveToBookmark(bookmark);
14992 mceRemoveNode: function(command, ui, value) {
14993 var node = value || selection.getNode();
14995 // Make sure that the body node isn't removed
14996 if (node != editor.getBody()) {
14998 editor.dom.remove(node, TRUE);
14999 restoreSelection();
15003 mceSelectNodeDepth: function(command, ui, value) {
15006 dom.getParent(selection.getNode(), function(node) {
15007 if (node.nodeType == 1 && counter++ == value) {
15008 selection.select(node);
15011 }, editor.getBody());
15014 mceSelectNode: function(command, ui, value) {
15015 selection.select(value);
15018 mceInsertContent: function(command, ui, value) {
15019 var parser, serializer, parentNode, rootNode, fragment, args;
15020 var marker, nodeRect, viewPortRect, rng, node, node2, bookmarkHtml, viewportBodyElement;
15022 function trimOrPaddLeftRight(html) {
15023 var rng, container, offset;
15025 rng = selection.getRng(true);
15026 container = rng.startContainer;
15027 offset = rng.startOffset;
15029 function hasSiblingText(siblingName) {
15030 return container[siblingName] && container[siblingName].nodeType == 3;
15033 if (container.nodeType == 3) {
15035 html = html.replace(/^ /, ' ');
15036 } else if (!hasSiblingText('previousSibling')) {
15037 html = html.replace(/^ /, ' ');
15040 if (offset < container.length) {
15041 html = html.replace(/ (<br>|)$/, ' ');
15042 } else if (!hasSiblingText('nextSibling')) {
15043 html = html.replace(/( | )(<br>|)$/, ' ');
15050 // Check for whitespace before/after value
15051 if (/^ | $/.test(value)) {
15052 value = trimOrPaddLeftRight(value);
15055 // Setup parser and serializer
15056 parser = editor.parser;
15057 serializer = new Serializer({}, editor.schema);
15058 bookmarkHtml = '<span id="mce_marker" data-mce-type="bookmark"></span>';
15060 // Run beforeSetContent handlers on the HTML to be inserted
15061 args = {content: value, format: 'html', selection: true};
15062 editor.fire('BeforeSetContent', args);
15063 value = args.content;
15065 // Add caret at end of contents if it's missing
15066 if (value.indexOf('{$caret}') == -1) {
15067 value += '{$caret}';
15070 // Replace the caret marker with a span bookmark element
15071 value = value.replace(/\{\$caret\}/, bookmarkHtml);
15073 // Insert node maker where we will insert the new HTML and get it's parent
15074 if (!selection.isCollapsed()) {
15075 editor.getDoc().execCommand('Delete', false, null);
15078 parentNode = selection.getNode();
15080 // Parse the fragment within the context of the parent node
15081 args = {context: parentNode.nodeName.toLowerCase()};
15082 fragment = parser.parse(value, args);
15084 // Move the caret to a more suitable location
15085 node = fragment.lastChild;
15086 if (node.attr('id') == 'mce_marker') {
15089 for (node = node.prev; node; node = node.walk(true)) {
15090 if (node.type == 3 || !dom.isBlock(node.name)) {
15091 node.parent.insert(marker, node, node.name === 'br');
15097 // If parser says valid we can insert the contents into that parent
15098 if (!args.invalid) {
15099 value = serializer.serialize(fragment);
15101 // Check if parent is empty or only has one BR element then set the innerHTML of that parent
15102 node = parentNode.firstChild;
15103 node2 = parentNode.lastChild;
15104 if (!node || (node === node2 && node.nodeName === 'BR')) {
15105 dom.setHTML(parentNode, value);
15107 selection.setContent(value);
15110 // If the fragment was invalid within that context then we need
15111 // to parse and process the parent it's inserted into
15113 // Insert bookmark node and get the parent
15114 selection.setContent(bookmarkHtml);
15115 parentNode = selection.getNode();
15116 rootNode = editor.getBody();
15118 // Opera will return the document node when selection is in root
15119 if (parentNode.nodeType == 9) {
15120 parentNode = node = rootNode;
15125 // Find the ancestor just before the root element
15126 while (node !== rootNode) {
15128 node = node.parentNode;
15131 // Get the outer/inner HTML depending on if we are in the root and parser and serialize that
15132 value = parentNode == rootNode ? rootNode.innerHTML : dom.getOuterHTML(parentNode);
15133 value = serializer.serialize(
15135 // Need to replace by using a function since $ in the contents would otherwise be a problem
15136 value.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i, function() {
15137 return serializer.serialize(fragment);
15142 // Set the inner/outer HTML depending on if we are in the root or not
15143 if (parentNode == rootNode) {
15144 dom.setHTML(rootNode, value);
15146 dom.setOuterHTML(parentNode, value);
15150 marker = dom.get('mce_marker');
15152 // Scroll range into view scrollIntoView on element can't be used since it will scroll the main view port as well
15153 nodeRect = dom.getRect(marker);
15154 viewPortRect = dom.getViewPort(editor.getWin());
15156 // Check if node is out side the viewport if it is then scroll to it
15157 if ((nodeRect.y + nodeRect.h > viewPortRect.y + viewPortRect.h || nodeRect.y < viewPortRect.y) ||
15158 (nodeRect.x > viewPortRect.x + viewPortRect.w || nodeRect.x < viewPortRect.x)) {
15159 viewportBodyElement = isIE ? editor.getDoc().documentElement : editor.getBody();
15160 viewportBodyElement.scrollLeft = nodeRect.x;
15161 viewportBodyElement.scrollTop = nodeRect.y - viewPortRect.h + 25;
15164 // Move selection before marker and remove it
15165 rng = dom.createRng();
15167 // If previous sibling is a text node set the selection to the end of that node
15168 node = marker.previousSibling;
15169 if (node && node.nodeType == 3) {
15170 rng.setStart(node, node.nodeValue.length);
15172 // TODO: Why can't we normalize on IE
15174 node2 = marker.nextSibling;
15175 if (node2 && node2.nodeType == 3) {
15176 node.appendData(node2.data);
15177 node2.parentNode.removeChild(node2);
15181 // If the previous sibling isn't a text node or doesn't exist set the selection before the marker node
15182 rng.setStartBefore(marker);
15183 rng.setEndBefore(marker);
15186 // Remove the marker node and set the new range
15187 dom.remove(marker);
15188 selection.setRng(rng);
15190 // Dispatch after event and add any visual elements needed
15191 editor.fire('SetContent', args);
15192 editor.addVisual();
15195 mceInsertRawHTML: function(command, ui, value) {
15196 selection.setContent('tiny_mce_marker');
15198 editor.getContent().replace(/tiny_mce_marker/g, function() {
15204 mceToggleFormat: function(command, ui, value) {
15205 toggleFormat(value);
15208 mceSetContent: function(command, ui, value) {
15209 editor.setContent(value);
15212 'Indent,Outdent': function(command) {
15213 var intentValue, indentUnit, value;
15215 // Setup indent level
15216 intentValue = settings.indentation;
15217 indentUnit = /[a-z%]+$/i.exec(intentValue);
15218 intentValue = parseInt(intentValue, 10);
15220 if (!queryCommandState('InsertUnorderedList') && !queryCommandState('InsertOrderedList')) {
15221 // If forced_root_blocks is set to false we don't have a block to indent so lets create a div
15222 if (!settings.forced_root_block && !dom.getParent(selection.getNode(), dom.isBlock)) {
15223 formatter.apply('div');
15226 each(selection.getSelectedBlocks(), function(element) {
15227 var indentStyleName;
15229 if (element.nodeName != "LI") {
15230 indentStyleName = dom.getStyle(element, 'direction', true) == 'rtl' ? 'paddingRight' : 'paddingLeft';
15232 if (command == 'outdent') {
15233 value = Math.max(0, parseInt(element.style[indentStyleName] || 0, 10) - intentValue);
15234 dom.setStyle(element, indentStyleName, value ? value + indentUnit : '');
15236 value = (parseInt(element.style[indentStyleName] || 0, 10) + intentValue) + indentUnit;
15237 dom.setStyle(element, indentStyleName, value);
15242 execNativeCommand(command);
15246 mceRepaint: function() {
15249 storeSelection(TRUE);
15251 if (selection.getSel()) {
15252 selection.getSel().selectAllChildren(editor.getBody());
15255 selection.collapse(TRUE);
15256 restoreSelection();
15263 InsertHorizontalRule: function() {
15264 editor.execCommand('mceInsertContent', false, '<hr />');
15267 mceToggleVisualAid: function() {
15268 editor.hasVisual = !editor.hasVisual;
15269 editor.addVisual();
15272 mceReplaceContent: function(command, ui, value) {
15273 editor.execCommand('mceInsertContent', false, value.replace(/\{\$selection\}/g, selection.getContent({format: 'text'})));
15276 mceInsertLink: function(command, ui, value) {
15279 if (typeof(value) == 'string') {
15280 value = {href: value};
15283 anchor = dom.getParent(selection.getNode(), 'a');
15285 // Spaces are never valid in URLs and it's a very common mistake for people to make so we fix it here.
15286 value.href = value.href.replace(' ', '%20');
15288 // Remove existing links if there could be child links or that the href isn't specified
15289 if (!anchor || !value.href) {
15290 formatter.remove('link');
15293 // Apply new link to selection
15295 formatter.apply('link', value, anchor);
15299 selectAll: function() {
15300 var root = dom.getRoot(), rng = dom.createRng();
15302 // Old IE does a better job with selectall than new versions
15303 if (selection.getRng().setStart) {
15304 rng.setStart(root, 0);
15305 rng.setEnd(root, root.childNodes.length);
15307 selection.setRng(rng);
15309 execNativeCommand('SelectAll');
15313 mceNewDocument: function() {
15314 editor.setContent('');
15318 // Add queryCommandState overrides
15320 // Override justify commands
15321 'JustifyLeft,JustifyCenter,JustifyRight,JustifyFull': function(command) {
15322 var name = 'align' + command.substring(7);
15323 var nodes = selection.isCollapsed() ? [dom.getParent(selection.getNode(), dom.isBlock)] : selection.getSelectedBlocks();
15324 var matches = map(nodes, function(node) {
15325 return !!formatter.matchNode(node, name);
15327 return inArray(matches, TRUE) !== -1;
15330 'Bold,Italic,Underline,Strikethrough,Superscript,Subscript': function(command) {
15331 return isFormatMatch(command);
15334 mceBlockQuote: function() {
15335 return isFormatMatch('blockquote');
15338 Outdent: function() {
15341 if (settings.inline_styles) {
15342 if ((node = dom.getParent(selection.getStart(), dom.isBlock)) && parseInt(node.style.paddingLeft, 10) > 0) {
15346 if ((node = dom.getParent(selection.getEnd(), dom.isBlock)) && parseInt(node.style.paddingLeft, 10) > 0) {
15352 queryCommandState('InsertUnorderedList') ||
15353 queryCommandState('InsertOrderedList') ||
15354 (!settings.inline_styles && !!dom.getParent(selection.getNode(), 'BLOCKQUOTE'))
15358 'InsertUnorderedList,InsertOrderedList': function(command) {
15359 var list = dom.getParent(selection.getNode(), 'ul,ol');
15363 command === 'insertunorderedlist' && list.tagName === 'UL' ||
15364 command === 'insertorderedlist' && list.tagName === 'OL'
15369 // Add queryCommandValue overrides
15371 'FontSize,FontName': function(command) {
15372 var value = 0, parent;
15374 if ((parent = dom.getParent(selection.getNode(), 'span'))) {
15375 if (command == 'fontsize') {
15376 value = parent.style.fontSize;
15378 value = parent.style.fontFamily.replace(/, /g, ',').replace(/[\'\"]/g, '').toLowerCase();
15386 // Add undo manager logic
15389 editor.undoManager.undo();
15393 editor.undoManager.redo();
15399 // Included from: js/tinymce/classes/util/URI.js
15404 * Copyright, Moxiecode Systems AB
15405 * Released under LGPL License.
15407 * License: http://www.tinymce.com/license
15408 * Contributing: http://www.tinymce.com/contributing
15412 * This class handles parsing, modification and serialization of URI/URL strings.
15413 * @class tinymce.util.URI
15415 define("tinymce/util/URI", [
15416 "tinymce/util/Tools"
15417 ], function(Tools) {
15418 var each = Tools.each, trim = Tools.trim;
15421 * Constructs a new URI instance.
15425 * @param {String} url URI string to parse.
15426 * @param {Object} settings Optional settings object.
15428 function URI(url, settings) {
15429 var self = this, baseUri, base_url;
15434 // Default settings
15435 settings = self.settings = settings || {};
15437 // Strange app protocol that isn't http/https or local anchor
15438 // For example: mailto,skype,tel etc.
15439 if (/^([\w\-]+):([^\/]{2})/i.test(url) || /^\s*#/.test(url)) {
15444 // Absolute path with no host, fake host and protocol
15445 if (url.indexOf('/') === 0 && url.indexOf('//') !== 0) {
15446 url = (settings.base_uri ? settings.base_uri.protocol || 'http' : 'http') + '://mce_host' + url;
15449 // Relative path http:// or protocol relative //path
15450 if (!/^[\w\-]*:?\/\//.test(url)) {
15451 base_url = settings.base_uri ? settings.base_uri.path : new URI(location.href).directory;
15452 url = ((settings.base_uri && settings.base_uri.protocol) || 'http') + '://mce_host' + self.toAbsPath(base_url, url);
15455 // Parse URL (Credits goes to Steave, http://blog.stevenlevithan.com/archives/parseuri)
15456 url = url.replace(/@@/g, '(mce_at)'); // Zope 3 workaround, they use @@something
15458 /*jshint maxlen: 255 */
15459 url = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(url);
15461 each(["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"], function(v, i) {
15464 // Zope 3 workaround, they use @@something
15466 part = part.replace(/\(mce_at\)/g, '@@');
15472 baseUri = settings.base_uri;
15474 if (!self.protocol) {
15475 self.protocol = baseUri.protocol;
15478 if (!self.userInfo) {
15479 self.userInfo = baseUri.userInfo;
15482 if (!self.port && self.host === 'mce_host') {
15483 self.port = baseUri.port;
15486 if (!self.host || self.host === 'mce_host') {
15487 self.host = baseUri.host;
15493 //t.path = t.path || '/';
15498 * Sets the internal path part of the URI.
15501 * @param {string} path Path string to set.
15503 setPath: function(path) {
15506 path = /^(.*?)\/?(\w+)?$/.exec(path);
15508 // Update path parts
15509 self.path = path[0];
15510 self.directory = path[1];
15511 self.file = path[2];
15519 * Converts the specified URI into a relative URI based on the current URI instance location.
15521 * @method toRelative
15522 * @param {String} uri URI to convert into a relative path/URI.
15523 * @return {String} Relative URI from the point specified in the current URI instance.
15525 * // Converts an absolute URL to an relative URL url will be somedir/somefile.htm
15526 * var url = new tinymce.util.URI('http://www.site.com/dir/').toRelative('http://www.site.com/dir/somedir/somefile.htm');
15528 toRelative: function(uri) {
15529 var self = this, output;
15531 if (uri === "./") {
15535 uri = new URI(uri, {base_uri: self});
15537 // Not on same domain/port or protocol
15538 if ((uri.host != 'mce_host' && self.host != uri.host && uri.host) || self.port != uri.port || self.protocol != uri.protocol) {
15539 return uri.getURI();
15542 var tu = self.getURI(), uu = uri.getURI();
15544 // Allow usage of the base_uri when relative_urls = true
15545 if(tu == uu || (tu.charAt(tu.length - 1) == "/" && tu.substr(0, tu.length - 1) == uu)) {
15549 output = self.toRelPath(self.path, uri.path);
15553 output += '?' + uri.query;
15558 output += '#' + uri.anchor;
15565 * Converts the specified URI into a absolute URI based on the current URI instance location.
15567 * @method toAbsolute
15568 * @param {String} uri URI to convert into a relative path/URI.
15569 * @param {Boolean} noHost No host and protocol prefix.
15570 * @return {String} Absolute URI from the point specified in the current URI instance.
15572 * // Converts an relative URL to an absolute URL url will be http://www.site.com/dir/somedir/somefile.htm
15573 * var url = new tinymce.util.URI('http://www.site.com/dir/').toAbsolute('somedir/somefile.htm');
15575 toAbsolute: function(uri, noHost) {
15576 uri = new URI(uri, {base_uri: this});
15578 return uri.getURI(this.host == uri.host && this.protocol == uri.protocol ? noHost : 0);
15582 * Converts a absolute path into a relative path.
15584 * @method toRelPath
15585 * @param {String} base Base point to convert the path from.
15586 * @param {String} path Absolute path to convert into a relative path.
15588 toRelPath: function(base, path) {
15589 var items, breakPoint = 0, out = '', i, l;
15592 base = base.substring(0, base.lastIndexOf('/'));
15593 base = base.split('/');
15594 items = path.split('/');
15596 if (base.length >= items.length) {
15597 for (i = 0, l = base.length; i < l; i++) {
15598 if (i >= items.length || base[i] != items[i]) {
15599 breakPoint = i + 1;
15605 if (base.length < items.length) {
15606 for (i = 0, l = items.length; i < l; i++) {
15607 if (i >= base.length || base[i] != items[i]) {
15608 breakPoint = i + 1;
15614 if (breakPoint === 1) {
15618 for (i = 0, l = base.length - (breakPoint - 1); i < l; i++) {
15622 for (i = breakPoint - 1, l = items.length; i < l; i++) {
15623 if (i != breakPoint - 1) {
15624 out += "/" + items[i];
15634 * Converts a relative path into a absolute path.
15636 * @method toAbsPath
15637 * @param {String} base Base point to convert the path from.
15638 * @param {String} path Relative path to convert into an absolute path.
15640 toAbsPath: function(base, path) {
15641 var i, nb = 0, o = [], tr, outPath;
15644 tr = /\/$/.test(path) ? '/' : '';
15645 base = base.split('/');
15646 path = path.split('/');
15648 // Remove empty chunks
15649 each(base, function(k) {
15657 // Merge relURLParts chunks
15658 for (i = path.length - 1, o = []; i >= 0; i--) {
15659 // Ignore empty or .
15660 if (path[i].length === 0 || path[i] === ".") {
15665 if (path[i] === '..') {
15679 i = base.length - nb;
15683 outPath = o.reverse().join('/');
15685 outPath = base.slice(0, i).join('/') + '/' + o.reverse().join('/');
15688 // Add front / if it's needed
15689 if (outPath.indexOf('/') !== 0) {
15690 outPath = '/' + outPath;
15693 // Add traling / if it's needed
15694 if (tr && outPath.lastIndexOf('/') !== outPath.length - 1) {
15702 * Returns the full URI of the internal structure.
15705 * @param {Boolean} noProtoHost Optional no host and protocol part. Defaults to false.
15707 getURI: function(noProtoHost) {
15708 var s, self = this;
15711 if (!self.source || noProtoHost) {
15714 if (!noProtoHost) {
15715 if (self.protocol) {
15716 s += self.protocol + '://';
15719 if (self.userInfo) {
15720 s += self.userInfo + '@';
15728 s += ':' + self.port;
15737 s += '?' + self.query;
15741 s += '#' + self.anchor;
15747 return self.source;
15754 // Included from: js/tinymce/classes/util/Class.js
15759 * Copyright 2003-2012, Moxiecode Systems AB, All rights reserved.
15763 * This utilitiy class is used for easier inheritage.
15766 * * Exposed super functions: this._super();
15768 * * Dummy functions
15769 * * Property functions: var value = object.value(); and object.value(newValue);
15770 * * Static functions
15771 * * Defaults settings
15773 define("tinymce/util/Class", [
15774 "tinymce/util/Tools"
15775 ], function(Tools) {
15776 var each = Tools.each, extend = Tools.extend;
15778 var extendClass, initializing;
15783 // Provides classical inheritance, based on code made by John Resig
15784 Class.extend = extendClass = function(prop) {
15785 var Self = this, _super = Self.prototype, prototype, name, member;
15787 // The dummy class constructor
15789 var i, mixins, mixin, self;
15791 // All construction is actually done in the init method
15792 if (!initializing) {
15795 // Run class constuctor
15797 self.init.apply(self, arguments);
15800 // Run mixin constructors
15801 mixins = self.Mixins;
15807 mixin.init.apply(self, arguments);
15814 // Dummy function, needs to be extended in order to provide functionality
15819 // Creates a overloaded method for the class
15820 // this enables you to use this._super(); to call the super function
15821 function createMethod(name, fn) {
15823 var self = this, tmp = self._super, ret;
15825 self._super = _super[name];
15826 ret = fn.apply(self, arguments);
15833 // Instantiate a base class (but only create the instance,
15834 // don't run the init constructor)
15835 initializing = true;
15836 prototype = new Self();
15837 initializing = false;
15841 each(prop.Mixins, function(mixin) {
15844 for (var name in mixin) {
15845 if (name !== "init") {
15846 prop[name] = mixin[name];
15851 if (_super.Mixins) {
15852 prop.Mixins = _super.Mixins.concat(prop.Mixins);
15856 // Generate dummy methods
15857 if (prop.Methods) {
15858 each(prop.Methods.split(','), function(name) {
15859 prop[name] = dummy;
15863 // Generate property methods
15864 if (prop.Properties) {
15865 each(prop.Properties.split(','), function(name) {
15866 var fieldName = '_' + name;
15868 prop[name] = function(value) {
15869 var self = this, undef;
15872 if (value !== undef) {
15873 self[fieldName] = value;
15879 return self[fieldName];
15884 // Static functions
15885 if (prop.Statics) {
15886 each(prop.Statics, function(func, name) {
15887 Class[name] = func;
15891 // Default settings
15892 if (prop.Defaults && _super.Defaults) {
15893 prop.Defaults = extend({}, _super.Defaults, prop.Defaults);
15896 // Copy the properties over onto the new prototype
15897 for (name in prop) {
15898 member = prop[name];
15900 if (typeof member == "function" && _super[name]) {
15901 prototype[name] = createMethod(name, member);
15903 prototype[name] = member;
15907 // Populate our constructed prototype object
15908 Class.prototype = prototype;
15910 // Enforce the constructor to be what we expect
15911 Class.constructor = Class;
15913 // And make this class extendible
15914 Class.extend = extendClass;
15922 // Included from: js/tinymce/classes/ui/Selector.js
15927 * Copyright, Moxiecode Systems AB
15928 * Released under LGPL License.
15930 * License: http://www.tinymce.com/license
15931 * Contributing: http://www.tinymce.com/contributing
15935 * Selector engine, enables you to select controls by using CSS like expressions.
15936 * We currently only support basic CSS expressions to reduce the size of the core
15937 * and the ones we support should be enough for most cases.
15940 * Supported expressions:
15945 * element[attr*=value]
15946 * element[attr~=value]
15947 * element[attr!=value]
15948 * element[attr^=value]
15949 * element[attr$=value]
15951 * element:not(<expression>)
15957 * element > element
15959 * @class tinymce.ui.Selector
15961 define("tinymce/ui/Selector", [
15962 "tinymce/util/Class",
15963 "tinymce/util/Tools"
15964 ], function(Class, Tools) {
15968 * Produces an array with a unique set of objects. It will not compare the values
15969 * but the references of the objects.
15973 * @param {Array} array Array to make into an array with unique items.
15974 * @return {Array} Array with unique items.
15976 function unique(array) {
15977 var uniqueItems = [], i = array.length, item;
15982 if (!item.__checked) {
15983 uniqueItems.push(item);
15984 item.__checked = 1;
15988 i = uniqueItems.length;
15990 delete uniqueItems[i].__checked;
15993 return uniqueItems;
15996 var expression = /^([\w\\*]+)?(?:#([\w\\]+))?(?:\.([\w\\\.]+))?(?:\[\@?([\w\\]+)([\^\$\*!~]?=)([\w\\]+)\])?(?:\:(.+))?/i;
15998 /*jshint maxlen:255 */
15999 var chunker = /((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,
16000 whiteSpace = /^\s*|\s*$/g,
16003 var Selector = Class.extend({
16005 * Constructs a new Selector instance.
16009 * @param {String} selector CSS like selector expression.
16011 init: function(selector) {
16012 var match = this.match;
16014 function compileNameFilter(name) {
16016 name = name.toLowerCase();
16018 return function(item) {
16019 return name === '*' || item.type === name;
16024 function compileIdFilter(id) {
16026 return function(item) {
16027 return item._name === id;
16032 function compileClassesFilter(classes) {
16034 classes = classes.split('.');
16036 return function(item) {
16037 var i = classes.length;
16040 if (!item.hasClass(classes[i])) {
16050 function compileAttrFilter(name, cmp, check) {
16052 return function(item) {
16053 var value = item[name] ? item[name]() : '';
16055 return !cmp ? !!check :
16056 cmp === "=" ? value === check :
16057 cmp === "*=" ? value.indexOf(check) >= 0 :
16058 cmp === "~=" ? (" " + value + " ").indexOf(" " + check + " ") >= 0 :
16059 cmp === "!=" ? value != check :
16060 cmp === "^=" ? value.indexOf(check) === 0 :
16061 cmp === "$=" ? value.substr(value.length - check.length) === check :
16067 function compilePsuedoFilter(name) {
16071 name = /(?:not\((.+)\))|(.+)/i.exec(name);
16076 return function(item, index, length) {
16077 return name === 'first' ? index === 0 :
16078 name === 'last' ? index === length - 1 :
16079 name === 'even' ? index % 2 === 0 :
16080 name === 'odd' ? index % 2 === 1 :
16081 item[name] ? item[name]() :
16085 // Compile not expression
16086 notSelectors = parseChunks(name[1], []);
16088 return function(item) {
16089 return !match(item, notSelectors);
16095 function compile(selector, filters, direct) {
16098 function add(filter) {
16100 filters.push(filter);
16104 // Parse expression into parts
16105 parts = expression.exec(selector.replace(whiteSpace, ''));
16107 add(compileNameFilter(parts[1]));
16108 add(compileIdFilter(parts[2]));
16109 add(compileClassesFilter(parts[3]));
16110 add(compileAttrFilter(parts[4], parts[5], parts[6]));
16111 add(compilePsuedoFilter(parts[7]));
16113 // Mark the filter with psuedo for performance
16114 filters.psuedo = !!parts[7];
16115 filters.direct = direct;
16120 // Parser logic based on Sizzle by John Resig
16121 function parseChunks(selector, selectors) {
16122 var parts = [], extra, matches, i;
16126 matches = chunker.exec(selector);
16129 selector = matches[3];
16130 parts.push(matches[1]);
16133 extra = matches[3];
16140 parseChunks(extra, selectors);
16144 for (i = 0; i < parts.length; i++) {
16145 if (parts[i] != '>') {
16146 selector.push(compile(parts[i], [], parts[i - 1] === '>'));
16150 selectors.push(selector);
16155 this._selectors = parseChunks(selector, []);
16159 * Returns true/false if the selector matches the specified control.
16162 * @param {tinymce.ui.Control} control Control to match agains the selector.
16163 * @param {Array} selectors Optional array of selectors, mostly used internally.
16164 * @return {Boolean} true/false state if the control matches or not.
16166 match: function(control, selectors) {
16167 var i, l, si, sl, selector, fi, fl, filters, index, length, siblings, count, item;
16169 selectors = selectors || this._selectors;
16170 for (i = 0, l = selectors.length; i < l; i++) {
16171 selector = selectors[i];
16172 sl = selector.length;
16176 for (si = sl - 1; si >= 0; si--) {
16177 filters = selector[si];
16180 // Find the index and length since a psuedo filter like :first needs it
16181 if (filters.psuedo) {
16182 siblings = item.parent().items();
16183 index = Tools.inArray(item, siblings);
16184 length = siblings.length;
16187 for (fi = 0, fl = filters.length; fi < fl; fi++) {
16188 if (!filters[fi](item, index, length)) {
16198 // If it didn't match the right most expression then
16199 // break since it's no point looking at the parents
16200 if (si === sl - 1) {
16205 item = item.parent();
16209 // If we found all selectors then return true otherwise continue looking
16210 if (count === sl) {
16219 * Returns a tinymce.ui.Collection with matches of the specified selector inside the specified container.
16222 * @param {tinymce.ui.Control} container Container to look for items in.
16223 * @return {tinymce.ui.Collection} Collection with matched elements.
16225 find: function(container) {
16226 var matches = [], i, l, selectors = this._selectors;
16228 function collect(items, selector, index) {
16229 var i, l, fi, fl, item, filters = selector[index];
16231 for (i = 0, l = items.length; i < l; i++) {
16234 // Run each filter agains the item
16235 for (fi = 0, fl = filters.length; fi < fl; fi++) {
16236 if (!filters[fi](item, i, l)) {
16242 // All filters matched the item
16244 // Matched item is on the last expression like: panel toolbar [button]
16245 if (index == selector.length - 1) {
16246 matches.push(item);
16248 // Collect next expression type
16250 collect(item.items(), selector, index + 1);
16253 } else if (filters.direct) {
16257 // Collect child items
16259 collect(item.items(), selector, index);
16264 if (container.items) {
16265 for (i = 0, l = selectors.length; i < l; i++) {
16266 collect(container.items(), selectors[i], 0);
16269 // Unique the matches if needed
16271 matches = unique(matches);
16275 // Fix for circular reference
16278 Collection = Selector.Collection;
16281 return new Collection(matches);
16288 // Included from: js/tinymce/classes/ui/Collection.js
16293 * Copyright, Moxiecode Systems AB
16294 * Released under LGPL License.
16296 * License: http://www.tinymce.com/license
16297 * Contributing: http://www.tinymce.com/contributing
16301 * Control collection, this class contains control instances and it enables you to
16302 * perform actions on all the contained items. This is very similar to how jQuery works.
16305 * someCollection.show().disabled(true);
16307 * @class tinymce.ui.Collection
16309 define("tinymce/ui/Collection", [
16310 "tinymce/util/Tools",
16311 "tinymce/ui/Selector",
16312 "tinymce/util/Class"
16313 ], function(Tools, Selector, Class) {
16316 var Collection, proto, push = Array.prototype.push, slice = Array.prototype.slice;
16320 * Current number of contained control instances.
16328 * Constructor for the collection.
16332 * @param {Array} items Optional array with items to add.
16334 init: function(items) {
16341 * Adds new items to the control collection.
16344 * @param {Array} items Array if items to add to collection.
16345 * @return {tinymce.ui.Collection} Current collection instance.
16347 add: function(items) {
16350 // Force single item into array
16351 if (!Tools.isArray(items)) {
16352 if (items instanceof Collection) {
16353 self.add(items.toArray());
16355 push.call(self, items);
16358 push.apply(self, items);
16365 * Sets the contents of the collection. This will remove any existing items
16366 * and replace them with the ones specified in the input array.
16369 * @param {Array} items Array with items to set into the Collection.
16370 * @return {tinymce.ui.Collection} Collection instance.
16372 set: function(items) {
16373 var self = this, len = self.length, i;
16378 // Remove old entries
16379 for (i = self.length; i < len; i++) {
16387 * Filters the collection item based on the specified selector expression or selector function.
16390 * @param {String} selector Selector expression to filter items by.
16391 * @return {tinymce.ui.Collection} Collection containing the filtered items.
16393 filter: function(selector) {
16394 var self = this, i, l, matches = [], item, match;
16396 // Compile string into selector expression
16397 if (typeof(selector) === "string") {
16398 selector = new Selector(selector);
16400 match = function(item) {
16401 return selector.match(item);
16404 // Use selector as matching function
16408 for (i = 0, l = self.length; i < l; i++) {
16412 matches.push(item);
16416 return new Collection(matches);
16420 * Slices the items within the collection.
16423 * @param {Number} index Index to slice at.
16424 * @param {Number} len Optional length to slice.
16425 * @return {tinymce.ui.Collection} Current collection.
16427 slice: function() {
16428 return new Collection(slice.apply(this, arguments));
16432 * Makes the current collection equal to the specified index.
16435 * @param {Number} index Index of the item to set the collection to.
16436 * @return {tinymce.ui.Collection} Current collection.
16438 eq: function(index) {
16439 return index === -1 ? this.slice(index) : this.slice(index, +index + 1);
16443 * Executes the specified callback on each item in collection.
16446 * @param {function} callback Callback to execute for each item in collection.
16447 * @return {tinymce.ui.Collection} Current collection instance.
16449 each: function(callback) {
16450 Tools.each(this, callback);
16456 * Returns an JavaScript array object of the contents inside the collection.
16459 * @return {Array} Array with all items from collection.
16461 toArray: function() {
16462 return Tools.toArray(this);
16466 * Finds the index of the specified control or return -1 if it isn't in the collection.
16469 * @param {Control} ctrl Control instance to look for.
16470 * @return {Number} Index of the specified control or -1.
16472 indexOf: function(ctrl) {
16473 var self = this, i = self.length;
16476 if (self[i] === ctrl) {
16485 * Returns a new collection of the contents in reverse order.
16488 * @return {tinymce.ui.Collection} Collection instance with reversed items.
16490 reverse: function() {
16491 return new Collection(Tools.toArray(this).reverse());
16495 * Returns true/false if the class exists or not.
16498 * @param {String} cls Class to check for.
16499 * @return {Boolean} true/false state if the class exists or not.
16501 hasClass: function(cls) {
16502 return this[0] ? this[0].hasClass(cls) : false;
16506 * Sets/gets the specific property on the items in the collection. The same as executing control.<property>(<value>);
16509 * @param {String} name Property name to get/set.
16510 * @param {Object} value Optional object value to set.
16511 * @return {tinymce.ui.Collection} Current collection instance or value of the first item on a get operation.
16513 prop: function(name, value) {
16514 var self = this, undef, item;
16516 if (value !== undef) {
16517 self.each(function(item) {
16528 if (item && item[name]) {
16529 return item[name]();
16534 * Executes the specific function name with optional arguments an all items in collection if it exists.
16536 * @example collection.exec("myMethod", arg1, arg2, arg3);
16538 * @param {String} name Name of the function to execute.
16539 * @param {Object} ... Multiple arguments to pass to each function.
16540 * @return {tinymce.ui.Collection} Current collection.
16542 exec: function(name) {
16543 var self = this, args = Tools.toArray(arguments).slice(1);
16545 self.each(function(item) {
16547 item[name].apply(item, args);
16555 * Remove all items from collection and DOM.
16558 * @return {tinymce.ui.Collection} Current collection.
16560 remove: function() {
16561 var i = this.length;
16571 * Fires the specified event by name and arguments on the control. This will execute all
16572 * bound event handlers.
16575 * @param {String} name Name of the event to fire.
16576 * @param {Object} args Optional arguments to pass to the event.
16577 * @return {tinymce.ui.Collection} Current collection instance.
16579 // fire: function(event, args) {}, -- Generated by code below
16582 * Binds a callback to the specified event. This event can both be
16583 * native browser events like "click" or custom ones like PostRender.
16585 * The callback function will have two parameters the first one being the control that received the event
16586 * the second one will be the event object either the browsers native event object or a custom JS object.
16589 * @param {String} name Name of the event to bind. For example "click".
16590 * @param {String/function} callback Callback function to execute ones the event occurs.
16591 * @return {tinymce.ui.Collection} Current collection instance.
16593 // on: function(name, callback) {}, -- Generated by code below
16596 * Unbinds the specified event and optionally a specific callback. If you omit the name
16597 * parameter all event handlers will be removed. If you omit the callback all event handles
16598 * by the specified name will be removed.
16601 * @param {String} name Optional name for the event to unbind.
16602 * @param {function} callback Optional callback function to unbind.
16603 * @return {tinymce.ui.Collection} Current collection instance.
16605 // off: function(name, callback) {}, -- Generated by code below
16608 * Shows the items in the current collection.
16611 * @return {tinymce.ui.Collection} Current collection instance.
16613 // show: function() {}, -- Generated by code below
16616 * Hides the items in the current collection.
16619 * @return {tinymce.ui.Collection} Current collection instance.
16621 // hide: function() {}, -- Generated by code below
16624 * Sets/gets the text contents of the items in the current collection.
16627 * @return {tinymce.ui.Collection} Current collection instance or text value of the first item on a get operation.
16629 // text: function(value) {}, -- Generated by code below
16632 * Sets/gets the name contents of the items in the current collection.
16635 * @return {tinymce.ui.Collection} Current collection instance or name value of the first item on a get operation.
16637 // name: function(value) {}, -- Generated by code below
16640 * Sets/gets the disabled state on the items in the current collection.
16643 * @return {tinymce.ui.Collection} Current collection instance or disabled state of the first item on a get operation.
16645 // disabled: function(state) {}, -- Generated by code below
16648 * Sets/gets the active state on the items in the current collection.
16651 * @return {tinymce.ui.Collection} Current collection instance or active state of the first item on a get operation.
16653 // active: function(state) {}, -- Generated by code below
16656 * Sets/gets the selected state on the items in the current collection.
16659 * @return {tinymce.ui.Collection} Current collection instance or selected state of the first item on a get operation.
16661 // selected: function(state) {}, -- Generated by code below
16664 * Sets/gets the selected state on the items in the current collection.
16667 * @return {tinymce.ui.Collection} Current collection instance or visible state of the first item on a get operation.
16669 // visible: function(state) {}, -- Generated by code below
16672 * Adds a class to all items in the collection.
16675 * @param {String} cls Class to add to each item.
16676 * @return {tinymce.ui.Collection} Current collection instance.
16678 // addClass: function(cls) {}, -- Generated by code below
16681 * Removes the specified class from all items in collection.
16683 * @method removeClass
16684 * @param {String} cls Class to remove from each item.
16685 * @return {tinymce.ui.Collection} Current collection instance.
16687 // removeClass: function(cls) {}, -- Generated by code below
16690 // Extend tinymce.ui.Collection prototype with some generated control specific methods
16691 Tools.each('fire on off show hide addClass removeClass append prepend before after reflow'.split(' '), function(name) {
16692 proto[name] = function() {
16693 var args = Tools.toArray(arguments);
16695 this.each(function(ctrl) {
16696 if (name in ctrl) {
16697 ctrl[name].apply(ctrl, args);
16705 // Extend tinymce.ui.Collection prototype with some property methods
16706 Tools.each('text name disabled active selected checked visible parent value data'.split(' '), function(name) {
16707 proto[name] = function(value) {
16708 return this.prop(name, value);
16712 // Create class based on the new prototype
16713 Collection = Class.extend(proto);
16715 // Stick Collection into Selector to prevent circual references
16716 Selector.Collection = Collection;
16721 // Included from: js/tinymce/classes/ui/DomUtils.js
16726 * Copyright, Moxiecode Systems AB
16727 * Released under LGPL License.
16729 * License: http://www.tinymce.com/license
16730 * Contributing: http://www.tinymce.com/contributing
16733 define("tinymce/ui/DomUtils", [
16734 "tinymce/util/Tools",
16735 "tinymce/dom/DOMUtils"
16736 ], function(Tools, DOMUtils) {
16741 return DOMUtils.DOM.uniqueId();
16744 createFragment: function(html) {
16745 return DOMUtils.DOM.createFragment(html);
16748 getWindowSize: function() {
16749 return DOMUtils.DOM.getViewPort();
16752 getSize: function(elm) {
16753 return DOMUtils.DOM.getSize(elm);
16756 getPos: function(elm, root) {
16757 return DOMUtils.DOM.getPos(elm, root);
16760 getViewPort: function(win) {
16761 return DOMUtils.DOM.getViewPort(win);
16764 get: function(id) {
16765 return document.getElementById(id);
16768 addClass : function(elm, cls) {
16769 return DOMUtils.DOM.addClass(elm, cls);
16772 removeClass : function(elm, cls) {
16773 return DOMUtils.DOM.removeClass(elm, cls);
16776 hasClass : function(elm, cls) {
16777 return DOMUtils.DOM.hasClass(elm, cls);
16780 toggleClass: function(elm, cls, state) {
16781 return DOMUtils.DOM.toggleClass(elm, cls, state);
16784 css: function(elm, name, value) {
16785 return DOMUtils.DOM.setStyle(elm, name, value);
16788 on: function(target, name, callback, scope) {
16789 return DOMUtils.DOM.bind(target, name, callback, scope);
16792 off: function(target, name, callback) {
16793 return DOMUtils.DOM.unbind(target, name, callback);
16796 fire: function(target, name, args) {
16797 return DOMUtils.DOM.fire(target, name, args);
16800 innerHtml: function(elm, html) {
16801 // Workaround for <div> in <p> bug on IE 8 #6178
16802 DOMUtils.DOM.setHTML(elm, html);
16807 // Included from: js/tinymce/classes/ui/Control.js
16812 * Copyright, Moxiecode Systems AB
16813 * Released under LGPL License.
16815 * License: http://www.tinymce.com/license
16816 * Contributing: http://www.tinymce.com/contributing
16820 * This is the base class for all controls and containers. All UI control instances inherit
16821 * from this one as it has the base logic needed by all of them.
16823 * @class tinymce.ui.Control
16825 define("tinymce/ui/Control", [
16826 "tinymce/util/Class",
16827 "tinymce/util/Tools",
16828 "tinymce/ui/Collection",
16829 "tinymce/ui/DomUtils"
16830 ], function(Class, Tools, Collection, DomUtils) {
16833 var nativeEvents = Tools.makeMap("focusin focusout scroll click dblclick mousedown mouseup mousemove mouseover" +
16834 " mouseout mouseenter mouseleave wheel keydown keypress keyup contextmenu", " ");
16836 var elementIdCache = {};
16837 var hasMouseWheelEventSupport = "onmousewheel" in document;
16838 var hasWheelEventSupport = false;
16840 var Control = Class.extend({
16842 controlIdLookup: {}
16846 * Class/id prefix to use for all controls.
16849 * @field {String} classPrefix
16851 classPrefix: "mce-",
16854 * Constructs a new control instance with the specified settings.
16857 * @param {Object} settings Name/value object with settings.
16858 * @setting {String} style Style CSS properties to add.
16859 * @setting {String} border Border box values example: 1 1 1 1
16860 * @setting {String} padding Padding box values example: 1 1 1 1
16861 * @setting {String} margin Margin box values example: 1 1 1 1
16862 * @setting {Number} minWidth Minimal width for the control.
16863 * @setting {Number} minHeight Minimal height for the control.
16864 * @setting {String} classes Space separated list of classes to add.
16865 * @setting {String} role WAI-ARIA role to use for control.
16866 * @setting {Boolean} hidden Is the control hidden by default.
16867 * @setting {Boolean} disabled Is the control disabled by default.
16868 * @setting {String} name Name of the control instance.
16870 init: function(settings) {
16871 var self = this, classes, i;
16873 self.settings = settings = Tools.extend({}, self.Defaults, settings);
16876 self._id = DomUtils.id();
16877 self._text = self._name = '';
16878 self._width = self._height = 0;
16879 self._aria = {role: settings.role};
16882 classes = settings.classes;
16884 classes = classes.split(' ');
16886 i = classes.length;
16888 classes.map[classes[i]] = true;
16892 self._classes = classes || [];
16893 self.visible(true);
16895 // Set some properties
16896 Tools.each('title text width height name classes visible disabled active value'.split(' '), function(name) {
16897 var value = settings[name], undef;
16899 if (value !== undef) {
16901 } else if (self['_' + name] === undef) {
16902 self['_' + name] = false;
16906 self.on('click', function() {
16907 if (self.disabled()) {
16912 // TODO: Is this needed duplicate code see above?
16913 if (settings.classes) {
16914 Tools.each(settings.classes.split(' '), function(cls) {
16915 self.addClass(cls);
16920 * Name/value object with settings for the current control.
16922 * @field {Object} settings
16924 self.settings = settings;
16926 self._borderBox = self.parseBox(settings.border);
16927 self._paddingBox = self.parseBox(settings.padding);
16928 self._marginBox = self.parseBox(settings.margin);
16930 if (settings.hidden) {
16935 // Will generate getter/setter methods for these properties
16936 Properties: 'parent,title,text,width,height,disabled,active,name,value',
16938 // Will generate empty dummy functions for these
16939 Methods: 'renderHtml',
16942 * Returns the root element to render controls into.
16944 * @method getContainerElm
16945 * @return {Element} HTML DOM element to render into.
16947 getContainerElm: function() {
16948 return document.body;
16952 * Returns a control instance for the current DOM element.
16954 * @method getParentCtrl
16955 * @param {Element} elm HTML dom element to get parent control from.
16956 * @return {tinymce.ui.Control} Control instance or undefined.
16958 getParentCtrl: function(elm) {
16962 ctrl = Control.controlIdLookup[elm.id];
16967 elm = elm.parentNode;
16974 * Parses the specified box value. A box value contains 1-4 properties in clockwise order.
16977 * @param {String/Number} value Box value "0 1 2 3" or "0" etc.
16978 * @return {Object} Object with top/right/bottom/left properties.
16981 parseBox: function(value) {
16982 var len, radix = 10;
16988 if (typeof(value) === "number") {
16989 value = value || 0;
16999 value = value.split(' ');
17000 len = value.length;
17003 value[1] = value[2] = value[3] = value[0];
17004 } else if (len === 2) {
17005 value[2] = value[0];
17006 value[3] = value[1];
17007 } else if (len === 3) {
17008 value[3] = value[1];
17012 top: parseInt(value[0], radix) || 0,
17013 right: parseInt(value[1], radix) || 0,
17014 bottom: parseInt(value[2], radix) || 0,
17015 left: parseInt(value[3], radix) || 0
17019 borderBox: function() {
17020 return this._borderBox;
17023 paddingBox: function() {
17024 return this._paddingBox;
17027 marginBox: function() {
17028 return this._marginBox;
17031 measureBox: function(elm, prefix) {
17032 function getStyle(name) {
17033 var defaultView = document.defaultView;
17036 // Remove camelcase
17037 name = name.replace(/[A-Z]/g, function(a) {
17041 return defaultView.getComputedStyle(elm, null).getPropertyValue(name);
17044 return elm.currentStyle[name];
17047 function getSide(name) {
17048 var val = parseInt(getStyle(name), 10);
17050 return isNaN(val) ? 0 : val;
17054 top: getSide(prefix + "TopWidth"),
17055 right: getSide(prefix + "RightWidth"),
17056 bottom: getSide(prefix + "BottomWidth"),
17057 left: getSide(prefix + "LeftWidth")
17062 * Initializes the current controls layout rect.
17063 * This will be executed by the layout managers to determine the
17064 * default minWidth/minHeight etc.
17066 * @method initLayoutRect
17067 * @return {Object} Layout rect instance.
17069 initLayoutRect: function() {
17070 var self = this, settings = self.settings, borderBox, layoutRect;
17071 var elm = self.getEl(), width, height, minWidth, minHeight, autoResize;
17072 var startMinWidth, startMinHeight;
17075 borderBox = self._borderBox = self._borderBox || self.measureBox(elm, 'border');
17076 self._paddingBox = self._paddingBox || self.measureBox(elm, 'padding');
17077 self._marginBox = self._marginBox || self.measureBox(elm, 'margin');
17079 // Setup minWidth/minHeight and width/height
17080 startMinWidth = settings.minWidth;
17081 startMinHeight = settings.minHeight;
17082 minWidth = startMinWidth || elm.offsetWidth;
17083 minHeight = startMinHeight || elm.offsetHeight;
17084 width = settings.width;
17085 height = settings.height;
17086 autoResize = settings.autoResize;
17087 autoResize = typeof(autoResize) != "undefined" ? autoResize : !width && !height;
17089 width = width || minWidth;
17090 height = height || minHeight;
17092 var deltaW = borderBox.left + borderBox.right;
17093 var deltaH = borderBox.top + borderBox.bottom;
17095 var maxW = settings.maxWidth || 0xFFFF;
17096 var maxH = settings.maxHeight || 0xFFFF;
17098 // Setup initial layout rect
17099 self._layoutRect = layoutRect = {
17100 x: settings.x || 0,
17101 y: settings.y || 0,
17106 contentW: width - deltaW,
17107 contentH: height - deltaH,
17108 innerW: width - deltaW,
17109 innerH: height - deltaH,
17110 startMinWidth: startMinWidth || 0,
17111 startMinHeight: startMinHeight || 0,
17112 minW: Math.min(minWidth, maxW),
17113 minH: Math.min(minHeight, maxH),
17116 autoResize: autoResize,
17120 self._lastLayoutRect = {};
17126 * Getter/setter for the current layout rect.
17128 * @method layoutRect
17129 * @param {Object} [newRect] Optional new layout rect.
17130 * @return {tinymce.ui.Control/Object} Current control or rect object.
17132 layoutRect: function(newRect) {
17133 var self = this, curRect = self._layoutRect, lastLayoutRect, size, deltaWidth, deltaHeight, undef, repaintControls;
17135 // Initialize default layout rect
17137 curRect = self.initLayoutRect();
17140 // Set new rect values
17142 // Calc deltas between inner and outer sizes
17143 deltaWidth = curRect.deltaW;
17144 deltaHeight = curRect.deltaH;
17147 if (newRect.x !== undef) {
17148 curRect.x = newRect.x;
17152 if (newRect.y !== undef) {
17153 curRect.y = newRect.y;
17157 if (newRect.minW !== undef) {
17158 curRect.minW = newRect.minW;
17162 if (newRect.minH !== undef) {
17163 curRect.minH = newRect.minH;
17166 // Set new width and calculate inner width
17168 if (size !== undef) {
17169 size = size < curRect.minW ? curRect.minW : size;
17170 size = size > curRect.maxW ? curRect.maxW : size;
17172 curRect.innerW = size - deltaWidth;
17175 // Set new height and calculate inner height
17177 if (size !== undef) {
17178 size = size < curRect.minH ? curRect.minH : size;
17179 size = size > curRect.maxH ? curRect.maxH : size;
17181 curRect.innerH = size - deltaHeight;
17184 // Set new inner width and calculate width
17185 size = newRect.innerW;
17186 if (size !== undef) {
17187 size = size < curRect.minW - deltaWidth ? curRect.minW - deltaWidth : size;
17188 size = size > curRect.maxW - deltaWidth ? curRect.maxW - deltaWidth : size;
17189 curRect.innerW = size;
17190 curRect.w = size + deltaWidth;
17193 // Set new height and calculate inner height
17194 size = newRect.innerH;
17195 if (size !== undef) {
17196 size = size < curRect.minH - deltaHeight ? curRect.minH - deltaHeight : size;
17197 size = size > curRect.maxH - deltaHeight ? curRect.maxH - deltaHeight : size;
17198 curRect.innerH = size;
17199 curRect.h = size + deltaHeight;
17202 // Set new contentW
17203 if (newRect.contentW !== undef) {
17204 curRect.contentW = newRect.contentW;
17207 // Set new contentH
17208 if (newRect.contentH !== undef) {
17209 curRect.contentH = newRect.contentH;
17212 // Compare last layout rect with the current one to see if we need to repaint or not
17213 lastLayoutRect = self._lastLayoutRect;
17214 if (lastLayoutRect.x !== curRect.x || lastLayoutRect.y !== curRect.y ||
17215 lastLayoutRect.w !== curRect.w || lastLayoutRect.h !== curRect.h) {
17216 repaintControls = Control.repaintControls;
17218 if (repaintControls) {
17219 if (repaintControls.map && !repaintControls.map[self._id]) {
17220 repaintControls.push(self);
17221 repaintControls.map[self._id] = true;
17225 lastLayoutRect.x = curRect.x;
17226 lastLayoutRect.y = curRect.y;
17227 lastLayoutRect.w = curRect.w;
17228 lastLayoutRect.h = curRect.h;
17238 * Repaints the control after a layout operation.
17242 repaint: function() {
17243 var self = this, style, bodyStyle, rect, borderBox, borderW = 0, borderH = 0, lastRepaintRect;
17245 style = self.getEl().style;
17246 rect = self._layoutRect;
17247 lastRepaintRect = self._lastRepaintRect || {};
17249 borderBox = self._borderBox;
17250 borderW = borderBox.left + borderBox.right;
17251 borderH = borderBox.top + borderBox.bottom;
17253 if (rect.x !== lastRepaintRect.x) {
17254 style.left = rect.x + 'px';
17255 lastRepaintRect.x = rect.x;
17258 if (rect.y !== lastRepaintRect.y) {
17259 style.top = rect.y + 'px';
17260 lastRepaintRect.y = rect.y;
17263 if (rect.w !== lastRepaintRect.w) {
17264 style.width = (rect.w - borderW) + 'px';
17265 lastRepaintRect.w = rect.w;
17268 if (rect.h !== lastRepaintRect.h) {
17269 style.height = (rect.h - borderH) + 'px';
17270 lastRepaintRect.h = rect.h;
17273 // Update body if needed
17274 if (self._hasBody && rect.innerW !== lastRepaintRect.innerW) {
17275 bodyStyle = self.getEl('body').style;
17276 bodyStyle.width = (rect.innerW) + 'px';
17277 lastRepaintRect.innerW = rect.innerW;
17280 if (self._hasBody && rect.innerH !== lastRepaintRect.innerH) {
17281 bodyStyle = bodyStyle || self.getEl('body').style;
17282 bodyStyle.height = (rect.innerH) + 'px';
17283 lastRepaintRect.innerH = rect.innerH;
17286 self._lastRepaintRect = lastRepaintRect;
17287 self.fire('repaint', {}, false);
17291 * Binds a callback to the specified event. This event can both be
17292 * native browser events like "click" or custom ones like PostRender.
17294 * The callback function will be passed a DOM event like object that enables yout do stop propagation.
17297 * @param {String} name Name of the event to bind. For example "click".
17298 * @param {String/function} callback Callback function to execute ones the event occurs.
17299 * @return {tinymce.ui.Control} Current control object.
17301 on: function(name, callback) {
17302 var self = this, bindings, handlers, names, i;
17304 function resolveCallbackName(name) {
17305 var callback, scope;
17307 return function(e) {
17309 self.parents().each(function(ctrl) {
17310 var callbacks = ctrl.settings.callbacks;
17312 if (callbacks && (callback = callbacks[name])) {
17319 return callback.call(scope, e);
17324 if (typeof(callback) == 'string') {
17325 callback = resolveCallbackName(callback);
17328 names = name.toLowerCase().split(' ');
17333 bindings = self._bindings;
17335 bindings = self._bindings = {};
17338 handlers = bindings[name];
17340 handlers = bindings[name] = [];
17343 handlers.push(callback);
17345 if (nativeEvents[name]) {
17346 if (!self._nativeEvents) {
17347 self._nativeEvents = {name: true};
17349 self._nativeEvents[name] = true;
17352 if (self._rendered) {
17353 self.bindPendingEvents();
17363 * Unbinds the specified event and optionally a specific callback. If you omit the name
17364 * parameter all event handlers will be removed. If you omit the callback all event handles
17365 * by the specified name will be removed.
17368 * @param {String} [name] Name for the event to unbind.
17369 * @param {function} [callback] Callback function to unbind.
17370 * @return {mxex.ui.Control} Current control object.
17372 off: function(name, callback) {
17373 var self = this, i, bindings = self._bindings, handlers, bindingName, names, hi;
17377 names = name.toLowerCase().split(' ');
17381 handlers = bindings[name];
17383 // Unbind all handlers
17385 for (bindingName in bindings) {
17386 bindings[bindingName].length = 0;
17393 // Unbind all by name
17395 handlers.length = 0;
17397 // Unbind specific ones
17398 hi = handlers.length;
17400 if (handlers[hi] === callback) {
17401 handlers.splice(hi, 1);
17408 self._bindings = [];
17416 * Fires the specified event by name and arguments on the control. This will execute all
17417 * bound event handlers.
17420 * @param {String} name Name of the event to fire.
17421 * @param {Object} [args] Arguments to pass to the event.
17422 * @param {Boolean} [bubble] Value to control bubbeling. Defaults to true.
17423 * @return {Object} Current arguments object.
17425 fire: function(name, args, bubble) {
17426 var self = this, i, l, handlers, parentCtrl;
17428 name = name.toLowerCase();
17430 // Dummy function that gets replaced on the delegation state functions
17431 function returnFalse() {
17435 // Dummy function that gets replaced on the delegation state functions
17436 function returnTrue() {
17440 // Setup empty object if args is omited
17443 // Stick type into event object
17448 // Stick control into event
17449 if (!args.control) {
17450 args.control = self;
17453 // Add event delegation methods if they are missing
17454 if (!args.preventDefault) {
17455 // Add preventDefault method
17456 args.preventDefault = function() {
17457 args.isDefaultPrevented = returnTrue;
17460 // Add stopPropagation
17461 args.stopPropagation = function() {
17462 args.isPropagationStopped = returnTrue;
17465 // Add stopImmediatePropagation
17466 args.stopImmediatePropagation = function() {
17467 args.isImmediatePropagationStopped = returnTrue;
17470 // Add event delegation states
17471 args.isDefaultPrevented = returnFalse;
17472 args.isPropagationStopped = returnFalse;
17473 args.isImmediatePropagationStopped = returnFalse;
17476 if (self._bindings) {
17477 handlers = self._bindings[name];
17480 for (i = 0, l = handlers.length; i < l; i++) {
17481 // Execute callback and break if the callback returns a false
17482 if (!args.isImmediatePropagationStopped() && handlers[i].call(self, args) === false) {
17489 // Bubble event up to parent controls
17490 if (bubble !== false) {
17491 parentCtrl = self.parent();
17492 while (parentCtrl && !args.isPropagationStopped()) {
17493 parentCtrl.fire(name, args, false);
17494 parentCtrl = parentCtrl.parent();
17502 * Returns a control collection with all parent controls.
17505 * @param {String} selector Optional selector expression to find parents.
17506 * @return {tinymce.ui.Collection} Collection with all parent controls.
17508 parents: function(selector) {
17509 var ctrl = this, parents = new Collection();
17511 // Add each parent to collection
17512 for (ctrl = ctrl.parent(); ctrl; ctrl = ctrl.parent()) {
17516 // Filter away everything that doesn't match the selector
17518 parents = parents.filter(selector);
17525 * Returns the control next to the current control.
17528 * @return {tinymce.ui.Control} Next control instance.
17531 var parentControls = this.parent().items();
17533 return parentControls[parentControls.indexOf(this) + 1];
17537 * Returns the control previous to the current control.
17540 * @return {tinymce.ui.Control} Previous control instance.
17543 var parentControls = this.parent().items();
17545 return parentControls[parentControls.indexOf(this) - 1];
17549 * Find the common ancestor for two control instances.
17551 * @method findCommonAncestor
17552 * @param {tinymce.ui.Control} ctrl1 First control.
17553 * @param {tinymce.ui.Control} ctrl2 Second control.
17554 * @return {tinymce.ui.Control} Ancestor control instance.
17556 findCommonAncestor: function(ctrl1, ctrl2) {
17560 parentCtrl = ctrl2;
17562 while (parentCtrl && ctrl1 != parentCtrl) {
17563 parentCtrl = parentCtrl.parent();
17566 if (ctrl1 == parentCtrl) {
17570 ctrl1 = ctrl1.parent();
17577 * Returns true/false if the specific control has the specific class.
17580 * @param {String} cls Class to check for.
17581 * @param {String} [group] Sub element group name.
17582 * @return {Boolean} True/false if the control has the specified class.
17584 hasClass: function(cls, group) {
17585 var classes = this._classes[group || 'control'];
17587 cls = this.classPrefix + cls;
17589 return classes && !!classes.map[cls];
17593 * Adds the specified class to the control
17596 * @param {String} cls Class to check for.
17597 * @param {String} [group] Sub element group name.
17598 * @return {tinymce.ui.Control} Current control object.
17600 addClass: function(cls, group) {
17601 var self = this, classes, elm;
17603 cls = this.classPrefix + cls;
17604 classes = self._classes[group || 'control'];
17609 self._classes[group || 'control'] = classes;
17612 if (!classes.map[cls]) {
17613 classes.map[cls] = cls;
17616 if (self._rendered) {
17617 elm = self.getEl(group);
17620 elm.className = classes.join(' ');
17629 * Removes the specified class from the control.
17631 * @method removeClass
17632 * @param {String} cls Class to remove.
17633 * @param {String} [group] Sub element group name.
17634 * @return {tinymce.ui.Control} Current control object.
17636 removeClass: function(cls, group) {
17637 var self = this, classes, i, elm;
17639 cls = this.classPrefix + cls;
17640 classes = self._classes[group || 'control'];
17641 if (classes && classes.map[cls]) {
17642 delete classes.map[cls];
17644 i = classes.length;
17646 if (classes[i] === cls) {
17647 classes.splice(i, 1);
17652 if (self._rendered) {
17653 elm = self.getEl(group);
17656 elm.className = classes.join(' ');
17664 * Toggles the specified class on the control.
17666 * @method toggleClass
17667 * @param {String} cls Class to remove.
17668 * @param {Boolean} state True/false state to add/remove class.
17669 * @param {String} [group] Sub element group name.
17670 * @return {tinymce.ui.Control} Current control object.
17672 toggleClass: function(cls, state, group) {
17676 self.addClass(cls, group);
17678 self.removeClass(cls, group);
17685 * Returns the class string for the specified group name.
17688 * @param {String} [group] Group to get clases by.
17689 * @return {String} Classes for the specified group.
17691 classes: function(group) {
17692 var classes = this._classes[group || 'control'];
17694 return classes ? classes.join(' ') : '';
17698 * Sets the inner HTML of the control element.
17700 * @method innerHtml
17701 * @param {String} html Html string to set as inner html.
17702 * @return {tinymce.ui.Control} Current control object.
17704 innerHtml: function(html) {
17705 DomUtils.innerHtml(this.getEl(), html);
17710 * Returns the control DOM element or sub element.
17713 * @param {String} [suffix] Suffix to get element by.
17714 * @param {Boolean} [dropCache] True if the cache for the element should be dropped.
17715 * @return {Element} HTML DOM element for the current control or it's children.
17717 getEl: function(suffix, dropCache) {
17718 var elm, id = suffix ? this._id + '-' + suffix : this._id;
17720 elm = elementIdCache[id] = (dropCache === true ? null : elementIdCache[id]) || DomUtils.get(id);
17726 * Sets/gets the visible for the control.
17729 * @param {Boolean} state Value to set to control.
17730 * @return {Boolean/tinymce.ui.Control} Current control on a set operation or current state on a get.
17732 visible: function(state) {
17733 var self = this, parentCtrl;
17735 if (typeof(state) !== "undefined") {
17736 if (self._visible !== state) {
17737 if (self._rendered) {
17738 self.getEl().style.display = state ? '' : 'none';
17741 self._visible = state;
17743 // Parent container needs to reflow
17744 parentCtrl = self.parent();
17746 parentCtrl._lastRect = null;
17749 self.fire(state ? 'show' : 'hide');
17755 return self._visible;
17759 * Sets the visible state to true.
17762 * @return {tinymce.ui.Control} Current control instance.
17765 return this.visible(true);
17769 * Sets the visible state to false.
17772 * @return {tinymce.ui.Control} Current control instance.
17775 return this.visible(false);
17779 * Focuses the current control.
17782 * @return {tinymce.ui.Control} Current control instance.
17784 focus: function() {
17786 this.getEl().focus();
17795 * Blurs the current control.
17798 * @return {tinymce.ui.Control} Current control instance.
17801 this.getEl().blur();
17807 * Sets the specified aria property.
17810 * @param {String} name Name of the aria property to set.
17811 * @param {String} value Value of the aria property.
17812 * @return {tinymce.ui.Control} Current control instance.
17814 aria: function(name, value) {
17815 var self = this, elm = self.getEl();
17817 if (typeof(value) === "undefined") {
17818 return self._aria[name];
17820 self._aria[name] = value;
17823 if (self._rendered) {
17824 if (name == 'label') {
17825 elm.setAttribute('aria-labeledby', self._id);
17828 elm.setAttribute(name == 'role' ? name : 'aria-' + name, value);
17835 * Encodes the specified string with HTML entities. It will also
17836 * translate the string to different languages.
17839 * @param {String/Object/Array} text Text to entity encode.
17840 * @param {Boolean} [translate=true] False if the contents shouldn't be translated.
17841 * @return {String} Encoded and possible traslated string.
17843 encode: function(text, translate) {
17844 if (translate !== false && Control.translate) {
17845 text = Control.translate(text);
17848 return (text || '').replace(/[&<>"]/g, function(match) {
17849 return '&#' + match.charCodeAt(0) + ';';
17854 * Adds items before the current control.
17857 * @param {Array/tinymce.ui.Collection} items Array of items to prepend before this control.
17858 * @return {tinymce.ui.Control} Current control instance.
17860 before: function(items) {
17861 var self = this, parent = self.parent();
17864 parent.insert(items, parent.items().indexOf(self), true);
17871 * Adds items after the current control.
17874 * @param {Array/tinymce.ui.Collection} items Array of items to append after this control.
17875 * @return {tinymce.ui.Control} Current control instance.
17877 after: function(items) {
17878 var self = this, parent = self.parent();
17881 parent.insert(items, parent.items().indexOf(self));
17888 * Removes the current control from DOM and from UI collections.
17891 * @return {tinymce.ui.Control} Current control instance.
17893 remove: function() {
17894 var self = this, elm = self.getEl(), parent = self.parent(), newItems;
17897 var controls = self.items().toArray();
17898 var i = controls.length;
17900 controls[i].remove();
17904 if (parent && parent.items) {
17907 parent.items().each(function(item) {
17908 if (item !== self) {
17909 newItems.push(item);
17913 parent.items().set(newItems);
17914 parent._lastRect = null;
17917 if (self._eventsRoot && self._eventsRoot == self) {
17921 delete Control.controlIdLookup[self._id];
17923 if (elm.parentNode) {
17924 elm.parentNode.removeChild(elm);
17931 * Renders the control before the specified element.
17933 * @method renderBefore
17934 * @param {Element} elm Element to render before.
17935 * @return {tinymce.ui.Control} Current control instance.
17937 renderBefore: function(elm) {
17940 elm.parentNode.insertBefore(DomUtils.createFragment(self.renderHtml()), elm);
17947 * Renders the control to the specified element.
17949 * @method renderBefore
17950 * @param {Element} elm Element to render to.
17951 * @return {tinymce.ui.Control} Current control instance.
17953 renderTo: function(elm) {
17956 elm = elm || self.getContainerElm();
17957 elm.appendChild(DomUtils.createFragment(self.renderHtml()));
17964 * Post render method. Called after the control has been rendered to the target.
17966 * @method postRender
17967 * @return {tinymce.ui.Control} Current control instance.
17969 postRender: function() {
17970 var self = this, settings = self.settings, elm, box, parent, name, parentEventsRoot;
17972 // Bind on<event> settings
17973 for (name in settings) {
17974 if (name.indexOf("on") === 0) {
17975 self.on(name.substr(2), settings[name]);
17979 if (self._eventsRoot) {
17980 for (parent = self.parent(); !parentEventsRoot && parent; parent = parent.parent()) {
17981 parentEventsRoot = parent._eventsRoot;
17984 if (parentEventsRoot) {
17985 for (name in parentEventsRoot._nativeEvents) {
17986 self._nativeEvents[name] = true;
17991 self.bindPendingEvents();
17993 if (settings.style) {
17994 elm = self.getEl();
17996 elm.setAttribute('style', settings.style);
17997 elm.style.cssText = settings.style;
18001 if (!self._visible) {
18002 DomUtils.css(self.getEl(), 'display', 'none');
18005 if (self.settings.border) {
18006 box = self.borderBox();
18007 DomUtils.css(self.getEl(), {
18008 'border-top-width': box.top,
18009 'border-right-width': box.right,
18010 'border-bottom-width': box.bottom,
18011 'border-left-width': box.left
18015 // Add instance to lookup
18016 Control.controlIdLookup[self._id] = self;
18018 for (var key in self._aria) {
18019 self.aria(key, self._aria[key]);
18022 self.fire('postrender', {}, false);
18026 * Scrolls the current control into view.
18028 * @method scrollIntoView
18029 * @param {String} align Alignment in view top|center|bottom.
18030 * @return {tinymce.ui.Control} Current control instance.
18032 scrollIntoView: function(align) {
18033 function getOffset(elm, rootElm) {
18034 var x, y, parent = elm;
18037 while (parent && parent != rootElm && parent.nodeType) {
18038 x += parent.offsetLeft || 0;
18039 y += parent.offsetTop || 0;
18040 parent = parent.offsetParent;
18043 return {x: x, y: y};
18046 var elm = this.getEl(), parentElm = elm.parentNode;
18047 var x, y, width, height, parentWidth, parentHeight;
18048 var pos = getOffset(elm, parentElm);
18052 width = elm.offsetWidth;
18053 height = elm.offsetHeight;
18054 parentWidth = parentElm.clientWidth;
18055 parentHeight = parentElm.clientHeight;
18057 if (align == "end") {
18058 x -= parentWidth - width;
18059 y -= parentHeight - height;
18060 } else if (align == "center") {
18061 x -= (parentWidth / 2) - (width / 2);
18062 y -= (parentHeight / 2) - (height / 2);
18065 parentElm.scrollLeft = x;
18066 parentElm.scrollTop = y;
18072 * Binds pending DOM events.
18076 bindPendingEvents: function() {
18077 var self = this, i, l, parents, eventRootCtrl, nativeEvents, name;
18079 function delegate(e) {
18080 var control = self.getParentCtrl(e.target);
18083 control.fire(e.type, e);
18087 function mouseLeaveHandler() {
18088 var ctrl = eventRootCtrl._lastHoverCtrl;
18091 ctrl.fire("mouseleave", {target: ctrl.getEl()});
18093 ctrl.parents().each(function(ctrl) {
18094 ctrl.fire("mouseleave", {target: ctrl.getEl()});
18097 eventRootCtrl._lastHoverCtrl = null;
18101 function mouseEnterHandler(e) {
18102 var ctrl = self.getParentCtrl(e.target), lastCtrl = eventRootCtrl._lastHoverCtrl, idx = 0, i, parents, lastParents;
18104 // Over on a new control
18105 if (ctrl !== lastCtrl) {
18106 eventRootCtrl._lastHoverCtrl = ctrl;
18108 parents = ctrl.parents().toArray().reverse();
18109 parents.push(ctrl);
18112 lastParents = lastCtrl.parents().toArray().reverse();
18113 lastParents.push(lastCtrl);
18115 for (idx = 0; idx < lastParents.length; idx++) {
18116 if (parents[idx] !== lastParents[idx]) {
18121 for (i = lastParents.length - 1; i >= idx; i--) {
18122 lastCtrl = lastParents[i];
18123 lastCtrl.fire("mouseleave", {
18124 target : lastCtrl.getEl()
18129 for (i = idx; i < parents.length; i++) {
18131 ctrl.fire("mouseenter", {
18132 target : ctrl.getEl()
18138 function fixWheelEvent(e) {
18139 e.preventDefault();
18141 if (e.type == "mousewheel") {
18142 e.deltaY = - 1/40 * e.wheelDelta;
18144 if (e.wheelDeltaX) {
18145 e.deltaX = -1/40 * e.wheelDeltaX;
18149 e.deltaY = e.detail;
18152 e = self.fire("wheel", e);
18155 self._rendered = true;
18157 nativeEvents = self._nativeEvents;
18158 if (nativeEvents) {
18159 // Find event root element if it exists
18160 parents = self.parents().toArray();
18161 parents.unshift(self);
18162 for (i = 0, l = parents.length; !eventRootCtrl && i < l; i++) {
18163 eventRootCtrl = parents[i]._eventsRoot;
18166 // Event root wasn't found the use the root control
18167 if (!eventRootCtrl) {
18168 eventRootCtrl = parents[parents.length - 1] || self;
18171 // Set the eventsRoot property on children that didn't have it
18172 self._eventsRoot = eventRootCtrl;
18173 for (l = i, i = 0; i < l; i++) {
18174 parents[i]._eventsRoot = eventRootCtrl;
18177 // Bind native event delegates
18178 for (name in nativeEvents) {
18179 if (!nativeEvents) {
18183 if (name === "wheel" && !hasWheelEventSupport) {
18184 if (hasMouseWheelEventSupport) {
18185 DomUtils.on(self.getEl(), "mousewheel", fixWheelEvent);
18187 DomUtils.on(self.getEl(), "DOMMouseScroll", fixWheelEvent);
18193 // Special treatment for mousenter/mouseleave since these doesn't bubble
18194 if (name === "mouseenter" || name === "mouseleave") {
18195 // Fake mousenter/mouseleave
18196 if (!eventRootCtrl._hasMouseEnter) {
18197 DomUtils.on(eventRootCtrl.getEl(), "mouseleave", mouseLeaveHandler);
18198 DomUtils.on(eventRootCtrl.getEl(), "mouseover", mouseEnterHandler);
18199 eventRootCtrl._hasMouseEnter = 1;
18201 } else if (!eventRootCtrl[name]) {
18202 DomUtils.on(eventRootCtrl.getEl(), name, delegate);
18203 eventRootCtrl[name] = true;
18206 // Remove the event once it's bound
18207 nativeEvents[name] = false;
18213 * Reflows the current control and it's parents.
18214 * This should be used after you for example append children to the current control so
18215 * that the layout managers know that they need to reposition everything.
18218 * container.append({type: 'button', text: 'My button'}).reflow();
18221 * @return {tinymce.ui.Control} Current control instance.
18223 reflow: function() {
18230 * Sets/gets the parent container for the control.
18233 * @param {tinymce.ui.Container} parent Optional parent to set.
18234 * @return {tinymce.ui.Control} Parent control or the current control on a set action.
18236 // parent: function(parent) {} -- Generated
18239 * Sets/gets the text for the control.
18242 * @param {String} value Value to set to control.
18243 * @return {String/tinymce.ui.Control} Current control on a set operation or current value on a get.
18245 // text: function(value) {} -- Generated
18248 * Sets/gets the width for the control.
18251 * @param {Number} value Value to set to control.
18252 * @return {Number/tinymce.ui.Control} Current control on a set operation or current value on a get.
18254 // width: function(value) {} -- Generated
18257 * Sets/gets the height for the control.
18260 * @param {Number} value Value to set to control.
18261 * @return {Number/tinymce.ui.Control} Current control on a set operation or current value on a get.
18263 // height: function(value) {} -- Generated
18266 * Sets/gets the disabled state on the control.
18269 * @param {Boolean} state Value to set to control.
18270 * @return {Boolean/tinymce.ui.Control} Current control on a set operation or current state on a get.
18272 // disabled: function(state) {} -- Generated
18275 * Sets/gets the active for the control.
18278 * @param {Boolean} state Value to set to control.
18279 * @return {Boolean/tinymce.ui.Control} Current control on a set operation or current state on a get.
18281 // active: function(state) {} -- Generated
18284 * Sets/gets the name for the control.
18287 * @param {String} value Value to set to control.
18288 * @return {String/tinymce.ui.Control} Current control on a set operation or current value on a get.
18290 // name: function(value) {} -- Generated
18293 * Sets/gets the title for the control.
18296 * @param {String} value Value to set to control.
18297 * @return {String/tinymce.ui.Control} Current control on a set operation or current value on a get.
18299 // title: function(value) {} -- Generated
18305 // Included from: js/tinymce/classes/ui/Factory.js
18310 * Copyright, Moxiecode Systems AB
18311 * Released under LGPL License.
18313 * License: http://www.tinymce.com/license
18314 * Contributing: http://www.tinymce.com/contributing
18317 /*global tinymce:true */
18320 * This class is a factory for control instances. This enables you
18321 * to create instances of controls without having to require the UI controls directly.
18323 * It also allow you to override or add new control types.
18325 * @class tinymce.ui.Factory
18327 define("tinymce/ui/Factory", [], function() {
18330 var types = {}, namespaceInit;
18334 * Adds a new control instance type to the factory.
18337 * @param {String} type Type name for example "button".
18338 * @param {function} typeClass Class type function.
18340 add: function(type, typeClass) {
18341 types[type.toLowerCase()] = typeClass;
18345 * Returns true/false if the specified type exists or not.
18348 * @param {String} type Type to look for.
18349 * @return {Boolean} true/false if the control by name exists.
18351 has: function(type) {
18352 return !!types[type.toLowerCase()];
18356 * Creates a new control instance based on the settings provided. The instance created will be
18357 * based on the specified type property it can also create whole structures of components out of
18358 * the specified JSON object.
18361 * tinymce.ui.Factory.create({
18363 * text: 'Hello world!'
18367 * @param {Object/String} settings Name/Value object with items used to create the type.
18368 * @return {tinymce.ui.Control} Control instance based on the specified type.
18370 create: function(type, settings) {
18371 var ControlType, name, namespace;
18373 // Build type lookup
18374 if (!namespaceInit) {
18375 namespace = tinymce.ui;
18377 for (name in namespace) {
18378 types[name.toLowerCase()] = namespace[name];
18381 namespaceInit = true;
18384 // If string is specified then use it as the type
18385 if (typeof(type) == 'string') {
18386 settings = settings || {};
18387 settings.type = type;
18390 type = settings.type;
18393 // Find control type
18394 type = type.toLowerCase();
18395 ControlType = types[type];
18399 if (!ControlType) {
18400 throw new Error("Could not find control by type: " + type);
18405 ControlType = new ControlType(settings);
18406 ControlType.type = type; // Set the type on the instance, this will be used by the Selector engine
18408 return ControlType;
18413 // Included from: js/tinymce/classes/ui/Container.js
18418 * Copyright, Moxiecode Systems AB
18419 * Released under LGPL License.
18421 * License: http://www.tinymce.com/license
18422 * Contributing: http://www.tinymce.com/contributing
18426 * Container control. This is extended by all controls that can have
18427 * children such as panels etc. You can also use this class directly as an
18428 * generic container instance. The container doesn't have any specific role or style.
18430 * @-x-less Container.less
18431 * @class tinymce.ui.Container
18432 * @extends tinymce.ui.Control
18434 define("tinymce/ui/Container", [
18435 "tinymce/ui/Control",
18436 "tinymce/ui/Collection",
18437 "tinymce/ui/Selector",
18438 "tinymce/ui/Factory",
18439 "tinymce/util/Tools",
18440 "tinymce/ui/DomUtils"
18441 ], function(Control, Collection, Selector, Factory, Tools, DomUtils) {
18444 var selectorCache = {};
18446 return Control.extend({
18448 innerClass: 'container-inner',
18451 * Constructs a new control instance with the specified settings.
18454 * @param {Object} settings Name/value object with settings.
18455 * @setting {Array} items Items to add to container in JSON format or control instances.
18456 * @setting {String} layout Layout manager by name to use.
18457 * @setting {Object} defaults Default settings to apply to all items.
18459 init: function(settings) {
18462 self._super(settings);
18463 settings = self.settings;
18464 self._fixed = settings.fixed;
18465 self._items = new Collection();
18467 self.addClass('container');
18468 self.addClass('container-body', 'body');
18470 if (settings.containerCls) {
18471 self.addClass(settings.containerCls);
18474 self._layout = Factory.create((settings.layout || self.layout) + 'layout');
18476 if (self.settings.items) {
18477 self.add(self.settings.items);
18481 self._hasBody = true;
18485 * Returns a collection of child items that the container currently have.
18488 * @return {tinymce.ui.Collection} Control collection direct child controls.
18490 items: function() {
18491 return this._items;
18495 * Find child controls by selector.
18498 * @param {String} selector Selector CSS pattern to find children by.
18499 * @return {tinymce.ui.Collection} Control collection with child controls.
18501 find: function(selector) {
18502 selector = selectorCache[selector] = selectorCache[selector] || new Selector(selector);
18504 return selector.find(this);
18508 * Adds one or many items to the current container. This will create instances of
18509 * the object representations if needed.
18512 * @param {Array/Object/tinymce.ui.Control} items Array or item that will be added to the container.
18513 * @return {tinymce.ui.Collection} Current collection control.
18515 add: function(items) {
18518 self.items().add(self.create(items)).parent(self);
18524 * Focuses the current container instance. This will look
18525 * for the first control in the container and focus that.
18528 * @return {tinymce.ui.Collection} Current instance.
18530 focus: function() {
18534 self.keyNav.focusFirst();
18543 * Replaces the specified child control with a new control.
18546 * @param {tinymce.ui.Control} oldItem Old item to be replaced.
18547 * @param {tinymce.ui.Control} newItem New item to be inserted.
18549 replace: function(oldItem, newItem) {
18550 var ctrlElm, items = this.items(), i = items.length;
18552 // Replace the item in collection
18554 if (items[i] === oldItem) {
18555 items[i] = newItem;
18561 // Remove new item from DOM
18562 ctrlElm = newItem.getEl();
18564 ctrlElm.parentNode.removeChild(ctrlElm);
18567 // Remove old item from DOM
18568 ctrlElm = oldItem.getEl();
18570 ctrlElm.parentNode.removeChild(ctrlElm);
18575 newItem.parent(this);
18579 * Creates the specified items. If any of the items is plain JSON style objects
18580 * it will convert these into real tinymce.ui.Control instances.
18583 * @param {Array} items Array of items to convert into control instances.
18584 * @return {Array} Array with control instances.
18586 create: function(items) {
18587 var self = this, settings, ctrlItems = [];
18589 // Non array structure, then force it into an array
18590 if (!Tools.isArray(items)) {
18594 // Add default type to each child control
18595 Tools.each(items, function(item) {
18597 // Construct item if needed
18598 if (!(item instanceof Control)) {
18599 // Name only then convert it to an object
18600 if (typeof(item) == "string") {
18601 item = {type: item};
18604 // Create control instance based on input settings and default settings
18605 settings = Tools.extend({}, self.settings.defaults, item);
18606 item.type = settings.type = settings.type || item.type || self.settings.defaultType ||
18607 (settings.defaults ? settings.defaults.type : null);
18608 item = Factory.create(settings);
18611 ctrlItems.push(item);
18619 * Renders new control instances.
18623 renderNew: function() {
18626 // Render any new items
18627 self.items().each(function(ctrl, index) {
18628 var containerElm, fragment;
18632 if (!ctrl._rendered) {
18633 containerElm = self.getEl('body');
18634 fragment = DomUtils.createFragment(ctrl.renderHtml());
18636 // Insert or append the item
18637 if (containerElm.hasChildNodes() && index <= containerElm.childNodes.length - 1) {
18638 containerElm.insertBefore(fragment, containerElm.childNodes[index]);
18640 containerElm.appendChild(fragment);
18647 self._layout.applyClasses(self);
18648 self._lastRect = null;
18654 * Appends new instances to the current container.
18657 * @param {Array/tinymce.ui.Collection} items Array if controls to append.
18658 * @return {tinymce.ui.Container} Current container instance.
18660 append: function(items) {
18661 return this.add(items).renderNew();
18665 * Prepends new instances to the current container.
18668 * @param {Array/tinymce.ui.Collection} items Array if controls to prepend.
18669 * @return {tinymce.ui.Container} Current container instance.
18671 prepend: function(items) {
18674 self.items().set(self.create(items).concat(self.items().toArray()));
18676 return self.renderNew();
18680 * Inserts an control at a specific index.
18683 * @param {Array/tinymce.ui.Collection} items Array if controls to insert.
18684 * @param {Number} index Index to insert controls at.
18685 * @param {Boolean} [before=false] Inserts controls before the index.
18687 insert: function(items, index, before) {
18688 var self = this, curItems, beforeItems, afterItems;
18690 items = self.create(items);
18691 curItems = self.items();
18693 if (!before && index < curItems.length - 1) {
18697 if (index >= 0 && index < curItems.length) {
18698 beforeItems = curItems.slice(0, index).toArray();
18699 afterItems = curItems.slice(index).toArray();
18700 curItems.set(beforeItems.concat(items, afterItems));
18703 return self.renderNew();
18707 * Populates the form fields from the specified JSON data object.
18709 * Control items in the form that matches the data will have it's value set.
18712 * @param {Object} data JSON data object to set control values by.
18713 * @return {tinymce.ui.Container} Current form instance.
18715 fromJSON: function(data) {
18718 for (var name in data) {
18719 self.find('#' + name).value(data[name]);
18726 * Serializes the form into a JSON object by getting all items
18727 * that has a name and a value.
18730 * @return {Object} JSON object with form data.
18732 toJSON: function() {
18733 var self = this, data = {};
18735 self.find('*').each(function(ctrl) {
18736 var name = ctrl.name(), value = ctrl.value();
18738 if (name && typeof(value) != "undefined") {
18739 data[name] = value;
18746 preRender: function() {
18750 * Renders the control as a HTML string.
18752 * @method renderHtml
18753 * @return {String} HTML representing the control.
18755 renderHtml: function() {
18756 var self = this, layout = self._layout;
18759 layout.preRender(self);
18762 '<div id="' + self._id + '" class="' + self.classes() + '" role="' + this.settings.role + '">' +
18763 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">'+
18764 (self.settings.html || '') + layout.renderHtml(self) +
18771 * Post render method. Called after the control has been rendered to the target.
18773 * @method postRender
18774 * @return {tinymce.ui.Container} Current combobox instance.
18776 postRender: function() {
18777 var self = this, box;
18779 self.items().exec('postRender');
18782 self._layout.postRender(self);
18783 self._rendered = true;
18785 if (self.settings.style) {
18786 DomUtils.css(self.getEl(), self.settings.style);
18789 if (self.settings.border) {
18790 box = self.borderBox();
18791 DomUtils.css(self.getEl(), {
18792 'border-top-width': box.top,
18793 'border-right-width': box.right,
18794 'border-bottom-width': box.bottom,
18795 'border-left-width': box.left
18803 * Initializes the current controls layout rect.
18804 * This will be executed by the layout managers to determine the
18805 * default minWidth/minHeight etc.
18807 * @method initLayoutRect
18808 * @return {Object} Layout rect instance.
18810 initLayoutRect: function() {
18811 var self = this, layoutRect = self._super();
18813 // Recalc container size by asking layout manager
18814 self._layout.recalc(self);
18820 * Recalculates the positions of the controls in the current container.
18821 * This is invoked by the reflow method and shouldn't be called directly.
18825 recalc: function() {
18826 var self = this, rect = self._layoutRect, lastRect = self._lastRect;
18828 if (!lastRect || lastRect.w != rect.w || lastRect.h != rect.h) {
18829 self._layout.recalc(self);
18830 rect = self.layoutRect();
18831 self._lastRect = {x: rect.x, y: rect.y, w: rect.w, h: rect.h};
18837 * Reflows the current container and it's children and possible parents.
18838 * This should be used after you for example append children to the current control so
18839 * that the layout managers know that they need to reposition everything.
18842 * container.append({type: 'button', text: 'My button'}).reflow();
18845 * @return {tinymce.ui.Container} Current container instance.
18847 reflow: function() {
18850 if (this.visible()) {
18851 Control.repaintControls = [];
18852 Control.repaintControls.map = {};
18854 items = this.recalc();
18855 i = Control.repaintControls.length;
18858 Control.repaintControls[i].repaint();
18862 if (this.settings.layout !== "flow" && this.settings.layout !== "stack") {
18866 Control.repaintControls = [];
18874 // Included from: js/tinymce/classes/ui/DragHelper.js
18879 * Copyright, Moxiecode Systems AB
18880 * Released under LGPL License.
18882 * License: http://www.tinymce.com/license
18883 * Contributing: http://www.tinymce.com/contributing
18887 * Drag/drop helper class.
18890 * var dragHelper = new tinymce.ui.DragHelper('mydiv', {
18891 * start: function(evt) {
18894 * drag: function(evt) {
18897 * end: function(evt) {
18901 * @class tinymce.ui.DragHelper
18903 define("tinymce/ui/DragHelper", [
18904 "tinymce/ui/DomUtils"
18905 ], function(DomUtils) {
18908 function getDocumentSize() {
18909 var doc = document, documentElement, body, scrollWidth, clientWidth;
18910 var offsetWidth, scrollHeight, clientHeight, offsetHeight, max = Math.max;
18912 documentElement = doc.documentElement;
18915 scrollWidth = max(documentElement.scrollWidth, body.scrollWidth);
18916 clientWidth = max(documentElement.clientWidth, body.clientWidth);
18917 offsetWidth = max(documentElement.offsetWidth, body.offsetWidth);
18919 scrollHeight = max(documentElement.scrollHeight, body.scrollHeight);
18920 clientHeight = max(documentElement.clientHeight, body.clientHeight);
18921 offsetHeight = max(documentElement.offsetHeight, body.offsetHeight);
18924 width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
18925 height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
18929 return function(id, settings) {
18930 var eventOverlayElm, doc = document, downButton, start, stop, drag, startX, startY;
18932 settings = settings || {};
18934 function getHandleElm() {
18935 return doc.getElementById(settings.handle || id);
18938 start = function(e) {
18939 var docSize = getDocumentSize(), handleElm, cursor;
18941 e.preventDefault();
18942 downButton = e.button;
18943 handleElm = getHandleElm();
18944 startX = e.screenX;
18945 startY = e.screenY;
18947 // Grab cursor from handle
18948 if (window.getComputedStyle) {
18949 cursor = window.getComputedStyle(handleElm, null).getPropertyValue("cursor");
18951 cursor = handleElm.runtimeStyle.cursor;
18954 // Create event overlay and add it to document
18955 eventOverlayElm = doc.createElement('div');
18956 DomUtils.css(eventOverlayElm, {
18957 position: "absolute",
18959 width: docSize.width,
18960 height: docSize.height,
18961 zIndex: 0x7FFFFFFF,
18967 doc.body.appendChild(eventOverlayElm);
18969 // Bind mouse events
18970 DomUtils.on(doc, 'mousemove', drag);
18971 DomUtils.on(doc, 'mouseup', stop);
18977 drag = function(e) {
18978 if (e.button !== downButton) {
18982 e.deltaX = e.screenX - startX;
18983 e.deltaY = e.screenY - startY;
18985 e.preventDefault();
18989 stop = function(e) {
18990 DomUtils.off(doc, 'mousemove', drag);
18991 DomUtils.off(doc, 'mouseup', stop);
18993 eventOverlayElm.parentNode.removeChild(eventOverlayElm);
18995 if (settings.stop) {
19001 * Destroys the drag/drop helper instance.
19005 this.destroy = function() {
19006 DomUtils.off(getHandleElm());
19009 DomUtils.on(getHandleElm(), 'mousedown', start);
19013 // Included from: js/tinymce/classes/ui/Scrollable.js
19018 * Copyright, Moxiecode Systems AB
19019 * Released under LGPL License.
19021 * License: http://www.tinymce.com/license
19022 * Contributing: http://www.tinymce.com/contributing
19026 * This mixin makes controls scrollable using custom scrollbars.
19028 * @-x-less Scrollable.less
19029 * @mixin tinymce.ui.Scrollable
19031 define("tinymce/ui/Scrollable", [
19032 "tinymce/ui/DomUtils",
19033 "tinymce/ui/DragHelper"
19034 ], function(DomUtils, DragHelper) {
19040 self.on('repaint', self.renderScroll);
19043 renderScroll: function() {
19044 var self = this, margin = 2;
19046 function repaintScroll() {
19047 var hasScrollH, hasScrollV, bodyElm;
19049 function repaintAxis(axisName, posName, sizeName, contentSizeName, hasScroll, ax) {
19050 var containerElm, scrollBarElm, scrollThumbElm;
19051 var containerSize, scrollSize, ratio, rect;
19052 var posNameLower, sizeNameLower;
19054 scrollBarElm = self.getEl('scroll' + axisName);
19055 if (scrollBarElm) {
19056 posNameLower = posName.toLowerCase();
19057 sizeNameLower = sizeName.toLowerCase();
19059 if (self.getEl('absend')) {
19060 DomUtils.css(self.getEl('absend'), posNameLower, self.layoutRect()[contentSizeName] - 1);
19064 DomUtils.css(scrollBarElm, 'display', 'none');
19068 DomUtils.css(scrollBarElm, 'display', 'block');
19069 containerElm = self.getEl('body');
19070 scrollThumbElm = self.getEl('scroll' + axisName + "t");
19071 containerSize = containerElm["client" + sizeName] - (margin * 2);
19072 containerSize -= hasScrollH && hasScrollV ? scrollBarElm["client" + ax] : 0;
19073 scrollSize = containerElm["scroll" + sizeName];
19074 ratio = containerSize / scrollSize;
19077 rect[posNameLower] = containerElm["offset" + posName] + margin;
19078 rect[sizeNameLower] = containerSize;
19079 DomUtils.css(scrollBarElm, rect);
19082 rect[posNameLower] = containerElm["scroll" + posName] * ratio;
19083 rect[sizeNameLower] = containerSize * ratio;
19084 DomUtils.css(scrollThumbElm, rect);
19088 bodyElm = self.getEl('body');
19089 hasScrollH = bodyElm.scrollWidth > bodyElm.clientWidth;
19090 hasScrollV = bodyElm.scrollHeight > bodyElm.clientHeight;
19092 repaintAxis("h", "Left", "Width", "contentW", hasScrollH, "Height");
19093 repaintAxis("v", "Top", "Height", "contentH", hasScrollV, "Width");
19096 function addScroll() {
19097 function addScrollAxis(axisName, posName, sizeName, deltaPosName, ax) {
19098 var scrollStart, axisId = self._id + '-scroll' + axisName, prefix = self.classPrefix;
19100 self.getEl().appendChild(DomUtils.createFragment(
19101 '<div id="' + axisId + '" class="' + prefix + 'scrollbar ' + prefix + 'scrollbar-' + axisName + '">' +
19102 '<div id="' + axisId + 't" class="' + prefix + 'scrollbar-thumb"></div>' +
19106 self.draghelper = new DragHelper(axisId + 't', {
19107 start: function() {
19108 scrollStart = self.getEl('body')["scroll" + posName];
19109 DomUtils.addClass(DomUtils.get(axisId), prefix + 'active');
19112 drag: function(e) {
19113 var ratio, hasScrollH, hasScrollV, containerSize, layoutRect = self.layoutRect();
19115 hasScrollH = layoutRect.contentW > layoutRect.innerW;
19116 hasScrollV = layoutRect.contentH > layoutRect.innerH;
19117 containerSize = self.getEl('body')["client" + sizeName] - (margin * 2);
19118 containerSize -= hasScrollH && hasScrollV ? self.getEl('scroll' + axisName)["client" + ax] : 0;
19120 ratio = containerSize / self.getEl('body')["scroll" + sizeName];
19121 self.getEl('body')["scroll" + posName] = scrollStart + (e["delta" + deltaPosName] / ratio);
19125 DomUtils.removeClass(DomUtils.get(axisId), prefix + 'active');
19129 self.on('click', function(e) {
19130 if (e.target.id == self._id + '-scrollv') {
19136 self.addClass('scroll');
19138 addScrollAxis("v", "Top", "Height", "Y", "Width");
19139 addScrollAxis("h", "Left", "Width", "X", "Height");
19142 if (self.settings.autoScroll) {
19143 if (!self._hasScroll) {
19144 self._hasScroll = true;
19147 self.on('wheel', function(e) {
19148 var bodyEl = self.getEl('body');
19150 bodyEl.scrollLeft += (e.deltaX || 0) * 10;
19151 bodyEl.scrollTop += e.deltaY * 10;
19156 DomUtils.on(self.getEl('body'), "scroll", repaintScroll);
19165 // Included from: js/tinymce/classes/ui/Panel.js
19170 * Copyright, Moxiecode Systems AB
19171 * Released under LGPL License.
19173 * License: http://www.tinymce.com/license
19174 * Contributing: http://www.tinymce.com/contributing
19178 * Creates a new panel.
19180 * @-x-less Panel.less
19181 * @class tinymce.ui.Panel
19182 * @extends tinymce.ui.Container
19183 * @mixes tinymce.ui.Scrollable
19185 define("tinymce/ui/Panel", [
19186 "tinymce/ui/Container",
19187 "tinymce/ui/Scrollable"
19188 ], function(Container, Scrollable) {
19191 return Container.extend({
19194 containerCls: 'panel'
19197 Mixins: [Scrollable],
19200 * Renders the control as a HTML string.
19202 * @method renderHtml
19203 * @return {String} HTML representing the control.
19205 renderHtml: function() {
19206 var self = this, layout = self._layout, innerHtml = self.settings.html;
19209 layout.preRender(self);
19211 if (typeof(innerHtml) == "undefined") {
19213 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">' +
19214 layout.renderHtml(self) +
19218 if (typeof(innerHtml) == 'function') {
19219 innerHtml = innerHtml.call(self);
19222 self._hasBody = false;
19226 '<div id="' + self._id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
19227 (self._preBodyHtml || '') +
19235 // Included from: js/tinymce/classes/ui/Movable.js
19240 * Copyright, Moxiecode Systems AB
19241 * Released under LGPL License.
19243 * License: http://www.tinymce.com/license
19244 * Contributing: http://www.tinymce.com/contributing
19248 * Movable mixin. Makes controls movable absolute and relative to other elements.
19250 * @mixin tinymce.ui.Movable
19252 define("tinymce/ui/Movable", [
19253 "tinymce/ui/DomUtils"
19254 ], function(DomUtils) {
19257 function calculateRelativePosition(ctrl, targetElm, rel) {
19258 var ctrlElm, pos, x, y, selfW, selfH, targetW, targetH, viewport;
19260 viewport = DomUtils.getViewPort();
19262 // Get pos of target
19263 pos = DomUtils.getPos(targetElm);
19272 // Get size of self
19273 ctrlElm = ctrl.getEl();
19274 selfW = ctrlElm.offsetWidth;
19275 selfH = ctrlElm.offsetHeight;
19277 // Get size of target
19278 targetW = targetElm.offsetWidth;
19279 targetH = targetElm.offsetHeight;
19281 // Parse align string
19282 rel = (rel || '').split('');
19285 if (rel[0] === 'b') {
19289 if (rel[1] === 'r') {
19293 if (rel[0] === 'c') {
19294 y += Math.round(targetH / 2);
19297 if (rel[1] === 'c') {
19298 x += Math.round(targetW / 2);
19302 if (rel[3] === 'b') {
19306 if (rel[4] === 'r') {
19310 if (rel[3] === 'c') {
19311 y -= Math.round(selfH / 2);
19314 if (rel[4] === 'c') {
19315 x -= Math.round(selfW / 2);
19328 * Tests various positions to get the most suitable one.
19330 * @method testMoveRel
19331 * @param {DOMElement} elm Element to position against.
19332 * @param {Array} rels Array with relative positions.
19333 * @return {String} Best suitable relative position.
19335 testMoveRel: function(elm, rels) {
19336 var viewPortRect = DomUtils.getViewPort();
19338 for (var i = 0; i < rels.length; i++) {
19339 var pos = calculateRelativePosition(this, elm, rels[i]);
19342 if (pos.x > 0 && pos.x + pos.w < viewPortRect.w && pos.y > 0 && pos.y + pos.h < viewPortRect.h) {
19346 if (pos.x > viewPortRect.x && pos.x + pos.w < viewPortRect.w + viewPortRect.x &&
19347 pos.y > viewPortRect.y && pos.y + pos.h < viewPortRect.h + viewPortRect.y) {
19357 * Move relative to the specified element.
19360 * @param {Element} elm Element to move relative to.
19361 * @param {String} rel Relative mode. For example: br-tl.
19362 * @return {tinymce.ui.Control} Current control instance.
19364 moveRel: function(elm, rel) {
19365 if (typeof(rel) != 'string') {
19366 rel = this.testMoveRel(elm, rel);
19369 var pos = calculateRelativePosition(this, elm, rel);
19370 return this.moveTo(pos.x, pos.y);
19374 * Move by a relative x, y values.
19377 * @param {Number} dx Relative x position.
19378 * @param {Number} dy Relative y position.
19379 * @return {tinymce.ui.Control} Current control instance.
19381 moveBy: function(dx, dy) {
19382 var self = this, rect = self.layoutRect();
19384 self.moveTo(rect.x + dx, rect.y + dy);
19390 * Move to absolute position.
19393 * @param {Number} x Absolute x position.
19394 * @param {Number} y Absolute y position.
19395 * @return {tinymce.ui.Control} Current control instance.
19397 moveTo: function(x, y) {
19400 // TODO: Move this to some global class
19401 function contrain(value, max, size) {
19406 if (value + size > max) {
19407 value = max - size;
19408 return value < 0 ? 0 : value;
19414 if (self.settings.constrainToViewport) {
19415 var viewPortRect = DomUtils.getViewPort(window);
19416 var layoutRect = self.layoutRect();
19418 x = contrain(x, viewPortRect.w + viewPortRect.x, layoutRect.w);
19419 y = contrain(y, viewPortRect.h + viewPortRect.y, layoutRect.h);
19422 if (self._rendered) {
19423 self.layoutRect({x: x, y: y}).repaint();
19425 self.settings.x = x;
19426 self.settings.y = y;
19429 self.fire('move', {x: x, y: y});
19436 // Included from: js/tinymce/classes/ui/Resizable.js
19441 * Copyright, Moxiecode Systems AB
19442 * Released under LGPL License.
19444 * License: http://www.tinymce.com/license
19445 * Contributing: http://www.tinymce.com/contributing
19449 * Resizable mixin. Enables controls to be resized.
19451 * @mixin tinymce.ui.Resizable
19453 define("tinymce/ui/Resizable", [
19454 "tinymce/ui/DomUtils"
19455 ], function(DomUtils) {
19460 * Resizes the control to contents.
19462 * @method resizeToContent
19464 resizeToContent: function() {
19465 this._layoutRect.autoResize = true;
19466 this._lastRect = null;
19471 * Resizes the control to a specific width/height.
19474 * @param {Number} w Control width.
19475 * @param {Number} h Control height.
19476 * @return {tinymce.ui.Control} Current control instance.
19478 resizeTo: function(w, h) {
19480 if (w <= 1 || h <= 1) {
19481 var rect = DomUtils.getWindowSize();
19483 w = w <= 1 ? w * rect.w : w;
19484 h = h <= 1 ? h * rect.h : h;
19487 this._layoutRect.autoResize = false;
19488 return this.layoutRect({minW: w, minH: h, w: w, h: h}).reflow();
19492 * Resizes the control to a specific relative width/height.
19495 * @param {Number} dw Relative control width.
19496 * @param {Number} dh Relative control height.
19497 * @return {tinymce.ui.Control} Current control instance.
19499 resizeBy: function(dw, dh) {
19500 var self = this, rect = self.layoutRect();
19502 return self.resizeTo(rect.w + dw, rect.h + dh);
19507 // Included from: js/tinymce/classes/ui/FloatPanel.js
19512 * Copyright, Moxiecode Systems AB
19513 * Released under LGPL License.
19515 * License: http://www.tinymce.com/license
19516 * Contributing: http://www.tinymce.com/contributing
19520 * This class creates a floating panel.
19522 * @-x-less FloatPanel.less
19523 * @class tinymce.ui.FloatPanel
19524 * @extends tinymce.ui.Panel
19525 * @mixes tinymce.ui.Movable
19526 * @mixes tinymce.ui.Resizable
19528 define("tinymce/ui/FloatPanel", [
19529 "tinymce/ui/Panel",
19530 "tinymce/ui/Movable",
19531 "tinymce/ui/Resizable",
19532 "tinymce/ui/DomUtils"
19533 ], function(Panel, Movable, Resizable, DomUtils) {
19536 var documentClickHandler, documentScrollHandler, visiblePanels = [];
19537 var zOrder = [], hasModal;
19539 var FloatPanel = Panel.extend({
19540 Mixins: [Movable, Resizable],
19543 * Constructs a new control instance with the specified settings.
19546 * @param {Object} settings Name/value object with settings.
19547 * @setting {Boolean} autohide Automatically hide the panel.
19549 init: function(settings) {
19552 function reorder() {
19553 var i, zIndex = FloatPanel.zIndex || 0xFFFF, topModal;
19555 if (zOrder.length) {
19556 for (i = 0; i < zOrder.length; i++) {
19557 if (zOrder[i].modal) {
19559 topModal = zOrder[i];
19562 zOrder[i].getEl().style.zIndex = zIndex;
19563 zOrder[i].zIndex = zIndex;
19568 var modalBlockEl = document.getElementById(self.classPrefix + 'modal-block');
19571 DomUtils.css(modalBlockEl, 'z-index', topModal.zIndex - 1);
19572 } else if (modalBlockEl) {
19573 modalBlockEl.parentNode.removeChild(modalBlockEl);
19577 FloatPanel.currentZIndex = zIndex;
19580 function isChildOf(ctrl, parent) {
19582 if (ctrl == parent) {
19586 ctrl = ctrl.parent();
19591 * Repositions the panel to the top of page if the panel is outside of the visual viewport. It will
19592 * also reposition all child panels of the current panel.
19594 function repositionPanel(panel) {
19595 var scrollY = DomUtils.getViewPort().y;
19597 function toggleFixedChildPanels(fixed, deltaY) {
19600 for (var i = 0; i < visiblePanels.length; i++) {
19601 if (visiblePanels[i] != panel) {
19602 parent = visiblePanels[i].parent();
19604 while (parent && (parent = parent.parent())) {
19605 if (parent == panel) {
19606 visiblePanels[i].fixed(fixed).moveBy(0, deltaY).repaint();
19613 if (panel.settings.autofix) {
19614 if (!panel._fixed) {
19615 panel._autoFixY = panel.layoutRect().y;
19617 if (panel._autoFixY < scrollY) {
19618 panel.fixed(true).layoutRect({y: 0}).repaint();
19619 toggleFixedChildPanels(true, scrollY - panel._autoFixY);
19622 if (panel._autoFixY > scrollY) {
19623 panel.fixed(false).layoutRect({y: panel._autoFixY}).repaint();
19624 toggleFixedChildPanels(false, panel._autoFixY - scrollY);
19630 self._super(settings);
19631 self._eventsRoot = self;
19633 self.addClass('floatpanel');
19635 // Hide floatpanes on click out side the root button
19636 if (settings.autohide) {
19637 if (!documentClickHandler) {
19638 documentClickHandler = function(e) {
19639 var i, clickCtrl = self.getParentCtrl(e.target);
19641 // Hide any float panel when a click is out side that float panel and the
19642 // float panels direct parent for example a click on a menu button
19643 i = visiblePanels.length;
19645 var panel = visiblePanels[i];
19647 if (panel.settings.autohide) {
19649 if (isChildOf(clickCtrl, panel) || panel.parent() === clickCtrl) {
19654 e = panel.fire('autohide', {target: e.target});
19655 if (!e.isDefaultPrevented()) {
19662 DomUtils.on(document, 'click', documentClickHandler);
19665 visiblePanels.push(self);
19668 if (settings.autofix) {
19669 if (!documentScrollHandler) {
19670 documentScrollHandler = function() {
19673 i = visiblePanels.length;
19675 repositionPanel(visiblePanels[i]);
19679 DomUtils.on(window, 'scroll', documentScrollHandler);
19682 self.on('move', function() {
19683 repositionPanel(this);
19687 self.on('postrender show', function(e) {
19688 if (e.control == self) {
19689 var modalBlockEl, prefix = self.classPrefix;
19691 if (self.modal && !hasModal) {
19692 modalBlockEl = DomUtils.createFragment('<div id="' + prefix + 'modal-block" class="' +
19693 prefix + 'reset ' + prefix + 'fade"></div>');
19694 modalBlockEl = modalBlockEl.firstChild;
19696 self.getContainerElm().appendChild(modalBlockEl);
19698 setTimeout(function() {
19699 DomUtils.addClass(modalBlockEl, prefix + 'in');
19700 DomUtils.addClass(self.getEl(), prefix + 'in');
19711 self.on('close hide', function(e) {
19712 if (e.control == self) {
19713 var i = zOrder.length;
19716 if (zOrder[i] === self) {
19717 zOrder.splice(i, 1);
19725 self.on('show', function() {
19726 self.parents().each(function(ctrl) {
19734 if (settings.popover) {
19735 self._preBodyHtml = '<div class="' + self.classPrefix + 'arrow"></div>';
19736 self.addClass('popover').addClass('bottom').addClass('start');
19740 fixed: function(state) {
19743 if (self._fixed != state) {
19744 if (self._rendered) {
19745 var viewport = DomUtils.getViewPort();
19748 self.layoutRect().y -= viewport.y;
19750 self.layoutRect().y += viewport.y;
19754 self.toggleClass('fixed', state);
19755 self._fixed = state;
19762 * Shows the current float panel.
19765 * @return {tinymce.ui.FloatPanel} Current floatpanel instance.
19768 var self = this, i, state = self._super();
19770 i = visiblePanels.length;
19772 if (visiblePanels[i] === self) {
19778 visiblePanels.push(self);
19785 * Hides the current float panel.
19788 * @return {tinymce.ui.FloatPanel} Current floatpanel instance.
19791 removeVisiblePanel(this);
19792 return this._super();
19796 * Hides all visible the float panels.
19800 hideAll: function() {
19801 FloatPanel.hideAll();
19805 * Closes the float panel. This will remove the float panel from page and fire the close event.
19809 close: function() {
19812 self.fire('close');
19814 return self.remove();
19818 * Removes the float panel from page.
19822 remove: function() {
19823 removeVisiblePanel(this);
19829 * Hides all visible the float panels.
19834 FloatPanel.hideAll = function() {
19835 var i = visiblePanels.length;
19838 var panel = visiblePanels[i];
19840 if (panel.settings.autohide) {
19841 panel.fire('cancel', {}, false);
19843 visiblePanels.splice(i, 1);
19848 function removeVisiblePanel(panel) {
19851 i = visiblePanels.length;
19853 if (visiblePanels[i] === panel) {
19854 visiblePanels.splice(i, 1);
19862 // Included from: js/tinymce/classes/ui/KeyboardNavigation.js
19865 * KeyboardNavigation.js
19867 * Copyright, Moxiecode Systems AB
19868 * Released under LGPL License.
19870 * License: http://www.tinymce.com/license
19871 * Contributing: http://www.tinymce.com/contributing
19875 * This class handles keyboard navigation of controls and elements.
19877 * @class tinymce.ui.KeyboardNavigation
19879 define("tinymce/ui/KeyboardNavigation", [
19880 "tinymce/ui/DomUtils"
19881 ], function(DomUtils) {
19885 * Create a new KeyboardNavigation instance to handle the focus for a specific element.
19888 * @param {Object} settings the settings object to define how keyboard navigation works.
19890 * @setting {tinymce.ui.Control} root the root control navigation focus movement is scoped to this root.
19891 * @setting {Array} items an array containing the items to move focus between. Every object in this array must have an
19892 * id attribute which maps to the actual DOM element and it must be able to have focus i.e. tabIndex=-1.
19893 * @setting {Function} onCancel the callback for when the user presses escape or otherwise indicates canceling.
19894 * @setting {Function} onAction (optional) the action handler to call when the user activates an item.
19895 * @setting {Boolean} enableLeftRight (optional, default) when true, the up/down arrows move through items.
19896 * @setting {Boolean} enableUpDown (optional) when true, the up/down arrows move through items.
19897 * Note for both up/down and left/right explicitly set both enableLeftRight and enableUpDown to true.
19899 return function(settings) {
19900 var root = settings.root, enableUpDown = settings.enableUpDown !== false;
19901 var enableLeftRight = settings.enableLeftRight !== false;
19902 var items = settings.items, focussedId;
19905 * Initializes the items array if needed. This will collect items/elements
19906 * from the specified root control.
19908 function initItems() {
19913 // Root is a container then get child elements using the UI API
19914 root.find('*').each(function(ctrl) {
19915 if (ctrl.canFocus) {
19916 items.push(ctrl.getEl());
19920 // Root is a control/widget then get the child elements of that control
19921 var elements = root.getEl().getElementsByTagName('*');
19922 for (var i = 0; i < elements.length; i++) {
19923 if (elements[i].id && elements[i]) {
19924 items.push(elements[i]);
19932 * Returns the currently focused element.
19935 * @return {Element} Currently focused element.
19937 function getFocusElement() {
19938 return document.getElementById(focussedId);
19942 * Returns the currently focused elements wai aria role.
19945 * @param {Element} elm Optional element to get role from.
19946 * @return {String} Role of specified element.
19948 function getRole(elm) {
19949 elm = elm || getFocusElement();
19951 return elm && elm.getAttribute('role');
19955 * Returns the role of the parent element.
19958 * @param {Element} elm Optional element to get parent role from.
19959 * @return {String} Role of the first parent that has a role.
19961 function getParentRole(elm) {
19962 var role, parent = elm || getFocusElement();
19964 while ((parent = parent.parentNode)) {
19965 if ((role = getRole(parent))) {
19972 * Returns an wai aria property by name.
19975 * @param {String} name Name of the aria property to get for example "disabled".
19976 * @return {String} Aria property value.
19978 function getAriaProp(name) {
19979 var elm = document.getElementById(focussedId);
19982 return elm.getAttribute('aria-' + name);
19987 * Executes the onAction event callback. This is when the user presses enter/space.
19991 function action() {
19992 var focusElm = getFocusElement();
19994 if (focusElm && (focusElm.nodeName == "TEXTAREA" || focusElm.type == "text")) {
19998 if (settings.onAction) {
19999 settings.onAction(focussedId);
20001 DomUtils.fire(getFocusElement(), 'click', {keyboard: true});
20008 * Cancels the current navigation. The same as pressing the Esc key.
20012 function cancel() {
20015 if (settings.onCancel) {
20016 if ((focusElm = getFocusElement())) {
20020 settings.onCancel();
20022 settings.root.fire('cancel');
20027 * Moves the focus to the next or previous item. It will wrap to start/end if it can't move.
20029 * @method moveFocus
20030 * @param {Number} dir Direction for move -1 or 1.
20032 function moveFocus(dir) {
20033 var idx = -1, focusElm, i;
20034 var visibleItems = [];
20036 function isVisible(elm) {
20037 var rootElm = root ? root.getEl() : document.body;
20039 while (elm && elm != rootElm) {
20040 if (elm.style.display == 'none') {
20044 elm = elm.parentNode;
20052 // TODO: Optimize this, will be slow on lots of items
20053 i = visibleItems.length;
20054 for (i = 0; i < items.length; i++) {
20055 if (isVisible(items[i])) {
20056 visibleItems.push(items[i]);
20060 i = visibleItems.length;
20062 if (visibleItems[i].id === focussedId) {
20070 idx = visibleItems.length - 1;
20071 } else if (idx >= visibleItems.length) {
20075 focusElm = visibleItems[idx];
20077 focussedId = focusElm.id;
20079 if (settings.actOnFocus) {
20085 * Moves focus to the first item or the last focused item if root is a toolbar.
20087 * @method focusFirst
20088 * @return {[type]} [description]
20090 function focusFirst() {
20093 rootRole = getRole(settings.root.getEl());
20098 if (rootRole == 'toolbar' && items[i].id === focussedId) {
20107 // Handle accessible keys
20108 root.on('keydown', function(e) {
20109 var DOM_VK_LEFT = 37, DOM_VK_RIGHT = 39, DOM_VK_UP = 38, DOM_VK_DOWN = 40;
20110 var DOM_VK_ESCAPE = 27, DOM_VK_ENTER = 14, DOM_VK_RETURN = 13, DOM_VK_SPACE = 32, DOM_VK_TAB = 9;
20111 var preventDefault;
20113 switch (e.keyCode) {
20115 if (enableLeftRight) {
20116 if (settings.leftAction) {
20117 settings.leftAction();
20122 preventDefault = true;
20127 if (enableLeftRight) {
20128 if (getRole() == 'menuitem' && getParentRole() == 'menu') {
20129 if (getAriaProp('haspopup')) {
20136 preventDefault = true;
20141 if (enableUpDown) {
20143 preventDefault = true;
20148 if (enableUpDown) {
20149 if (getRole() == 'menuitem' && getParentRole() == 'menubar') {
20151 } else if (getRole() == 'button' && getAriaProp('haspopup')) {
20157 preventDefault = true;
20162 preventDefault = true;
20171 case DOM_VK_ESCAPE:
20172 preventDefault = true;
20177 case DOM_VK_RETURN:
20179 preventDefault = action();
20183 if (preventDefault) {
20184 e.stopPropagation();
20185 e.preventDefault();
20189 // Init on focus in
20190 root.on('focusin', function(e) {
20192 focussedId = e.target.id;
20196 moveFocus: moveFocus,
20197 focusFirst: focusFirst,
20203 // Included from: js/tinymce/classes/ui/Window.js
20208 * Copyright, Moxiecode Systems AB
20209 * Released under LGPL License.
20211 * License: http://www.tinymce.com/license
20212 * Contributing: http://www.tinymce.com/contributing
20216 * Creates a new window.
20218 * @-x-less Window.less
20219 * @class tinymce.ui.Window
20220 * @extends tinymce.ui.FloatPanel
20222 define("tinymce/ui/Window", [
20223 "tinymce/ui/FloatPanel",
20224 "tinymce/ui/Panel",
20225 "tinymce/ui/DomUtils",
20226 "tinymce/ui/KeyboardNavigation",
20227 "tinymce/ui/DragHelper"
20228 ], function(FloatPanel, Panel, DomUtils, KeyboardNavigation, DragHelper) {
20231 var Window = FloatPanel.extend({
20237 containerCls: 'panel',
20240 submit: function() {
20241 this.fire('submit', {data: this.toJSON()});
20244 close: function() {
20251 * Constructs a instance with the specified settings.
20254 * @param {Object} settings Name/value object with settings.
20256 init: function(settings) {
20259 self._super(settings);
20261 self.addClass('window');
20262 self._fixed = true;
20264 // Create statusbar
20265 if (settings.buttons) {
20266 self.statusbar = new Panel({
20276 items: settings.buttons
20279 self.statusbar.addClass('foot');
20280 self.statusbar.parent(self);
20283 self.on('click', function(e) {
20284 if (e.target.className.indexOf(self.classPrefix + 'close') != -1) {
20289 self.aria('label', settings.title);
20290 self._fullscreen = false;
20294 * Recalculates the positions of the controls in the current container.
20295 * This is invoked by the reflow method and shouldn't be called directly.
20299 recalc: function() {
20300 var self = this, statusbar = self.statusbar, layoutRect, width, needsRecalc;
20302 if (self._fullscreen) {
20303 self.layoutRect(DomUtils.getWindowSize());
20304 self.layoutRect().contentH = self.layoutRect().innerH;
20309 layoutRect = self.layoutRect();
20311 // Resize window based on title width
20312 if (self.settings.title && !self._fullscreen) {
20313 width = layoutRect.headerW;
20314 if (width > layoutRect.w) {
20315 self.layoutRect({w: width});
20316 needsRecalc = true;
20320 // Resize window based on statusbar width
20322 statusbar.layoutRect({w: self.layoutRect().innerW}).recalc();
20324 width = statusbar.layoutRect().minW + layoutRect.deltaW;
20325 if (width > layoutRect.w) {
20326 self.layoutRect({w: width});
20327 needsRecalc = true;
20331 // Recalc body and disable auto resize
20338 * Initializes the current controls layout rect.
20339 * This will be executed by the layout managers to determine the
20340 * default minWidth/minHeight etc.
20342 * @method initLayoutRect
20343 * @return {Object} Layout rect instance.
20345 initLayoutRect: function() {
20346 var self = this, layoutRect = self._super(), deltaH = 0, headEl;
20348 // Reserve vertical space for title
20349 if (self.settings.title && !self._fullscreen) {
20350 headEl = self.getEl('head');
20351 layoutRect.headerW = headEl.offsetWidth;
20352 layoutRect.headerH = headEl.offsetHeight;
20353 deltaH += layoutRect.headerH;
20356 // Reserve vertical space for statusbar
20357 if (self.statusbar) {
20358 deltaH += self.statusbar.layoutRect().h;
20361 layoutRect.deltaH += deltaH;
20362 layoutRect.minH += deltaH;
20363 //layoutRect.innerH -= deltaH;
20364 layoutRect.h += deltaH;
20366 var rect = DomUtils.getWindowSize();
20368 layoutRect.x = Math.max(0, rect.w / 2 - layoutRect.w / 2);
20369 layoutRect.y = Math.max(0, rect.h / 2 - layoutRect.h / 2);
20375 * Renders the control as a HTML string.
20377 * @method renderHtml
20378 * @return {String} HTML representing the control.
20380 renderHtml: function() {
20381 var self = this, layout = self._layout, id = self._id, prefix = self.classPrefix;
20382 var settings = self.settings, headerHtml = '', footerHtml = '', html = settings.html;
20385 layout.preRender(self);
20387 if (settings.title) {
20389 '<div id="' + id + '-head" class="' + prefix + 'window-head">' +
20390 '<div class="' + prefix + 'title">' + self.encode(settings.title) + '</div>' +
20391 '<button type="button" class="' + prefix + 'close" aria-hidden="true">×</button>' +
20392 '<div id="' + id + '-dragh" class="' + prefix + 'dragh"></div>' +
20397 if (settings.url) {
20398 html = '<iframe src="' + settings.url + '" tabindex="-1"></iframe>';
20401 if (typeof(html) == "undefined") {
20402 html = layout.renderHtml(self);
20405 if (self.statusbar) {
20406 footerHtml = self.statusbar.renderHtml();
20410 '<div id="' + id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
20412 '<div id="' + id + '-body" class="' + self.classes('body') + '">' +
20421 * Switches the window fullscreen mode.
20423 * @method fullscreen
20424 * @param {Boolean} state True/false state.
20425 * @return {tinymce.ui.Window} Current window instance.
20427 fullscreen: function(state) {
20428 var self = this, documentElement = document.documentElement, slowRendering, prefix = self.classPrefix, layoutRect;
20430 if (state != self._fullscreen) {
20431 DomUtils.on(window, 'resize', function() {
20434 if (self._fullscreen) {
20435 // Time the layout time if it's to slow use a timeout to not hog the CPU
20436 if (!slowRendering) {
20437 time = new Date().getTime();
20439 var rect = DomUtils.getWindowSize();
20440 self.moveTo(0, 0).resizeTo(rect.w, rect.h);
20442 if ((new Date().getTime()) - time > 50) {
20443 slowRendering = true;
20446 if (!self._timer) {
20447 self._timer = setTimeout(function() {
20448 var rect = DomUtils.getWindowSize();
20449 self.moveTo(0, 0).resizeTo(rect.w, rect.h);
20458 layoutRect = self.layoutRect();
20459 self._fullscreen = state;
20462 self._borderBox = self.parseBox(self.settings.border);
20463 self.getEl('head').style.display = '';
20464 layoutRect.deltaH += layoutRect.headerH;
20465 DomUtils.removeClass(documentElement, prefix + 'fullscreen');
20466 DomUtils.removeClass(document.body, prefix + 'fullscreen');
20467 self.removeClass('fullscreen');
20468 self.moveTo(self._initial.x, self._initial.y).resizeTo(self._initial.w, self._initial.h);
20470 self._initial = {x: layoutRect.x, y: layoutRect.y, w: layoutRect.w, h: layoutRect.h};
20472 self._borderBox = self.parseBox('0');
20473 self.getEl('head').style.display = 'none';
20474 layoutRect.deltaH -= layoutRect.headerH + 2;
20475 DomUtils.addClass(documentElement, prefix + 'fullscreen');
20476 DomUtils.addClass(document.body, prefix + 'fullscreen');
20477 self.addClass('fullscreen');
20479 var rect = DomUtils.getWindowSize();
20480 self.moveTo(0, 0).resizeTo(rect.w, rect.h);
20484 return self.reflow();
20488 * Called after the control has been rendered.
20490 * @method postRender
20492 postRender: function() {
20493 var self = this, items = [], focusCtrl, autoFocusFound, startPos;
20495 setTimeout(function() {
20496 self.addClass('in');
20499 self.keyboardNavigation = new KeyboardNavigation({
20501 enableLeftRight: false,
20502 enableUpDown: false,
20504 onCancel: function() {
20509 self.find('*').each(function(ctrl) {
20510 if (ctrl.canFocus) {
20511 autoFocusFound = autoFocusFound || ctrl.settings.autofocus;
20512 focusCtrl = focusCtrl || ctrl;
20514 // TODO: Figure out a better way
20515 if (ctrl.type == 'filepicker') {
20516 items.push(ctrl.getEl('inp'));
20518 if (ctrl.getEl('open')) {
20519 items.push(ctrl.getEl('open').firstChild);
20522 items.push(ctrl.getEl());
20527 if (self.statusbar) {
20528 self.statusbar.find('*').each(function(ctrl) {
20529 if (ctrl.canFocus) {
20530 autoFocusFound = autoFocusFound || ctrl.settings.autofocus;
20531 focusCtrl = focusCtrl || ctrl;
20532 items.push(ctrl.getEl());
20539 if (self.statusbar) {
20540 self.statusbar.postRender();
20543 if (!autoFocusFound && focusCtrl) {
20547 this.dragHelper = new DragHelper(self._id + '-dragh', {
20548 start: function() {
20550 x: self.layoutRect().x,
20551 y: self.layoutRect().y
20555 drag: function(e) {
20556 self.moveTo(startPos.x + e.deltaX, startPos.y + e.deltaY);
20560 self.on('submit', function(e) {
20561 if (!e.isDefaultPrevented()) {
20568 * Fires a submit event with the serialized form.
20571 * @return {Object} Event arguments object.
20573 submit: function() {
20574 // Blur current control so a onchange is fired before submit
20575 var ctrl = this.getParentCtrl(document.activeElement);
20580 return this.fire('submit', {data: this.toJSON()});
20584 * Removes the current control from DOM and from UI collections.
20587 * @return {tinymce.ui.Control} Current control instance.
20589 remove: function() {
20593 self.dragHelper.destroy();
20595 if (self.statusbar) {
20596 this.statusbar.remove();
20604 // Included from: js/tinymce/classes/ui/MessageBox.js
20609 * Copyright, Moxiecode Systems AB
20610 * Released under LGPL License.
20612 * License: http://www.tinymce.com/license
20613 * Contributing: http://www.tinymce.com/contributing
20617 * This class is used to create MessageBoxes like alerts/confirms etc.
20619 * @class tinymce.ui.Window
20620 * @extends tinymce.ui.FloatPanel
20622 define("tinymce/ui/MessageBox", [
20623 "tinymce/ui/Window"
20624 ], function(Window) {
20627 var MessageBox = Window.extend({
20629 * Constructs a instance with the specified settings.
20632 * @param {Object} settings Name/value object with settings.
20634 init: function(settings) {
20641 containerCls: 'panel',
20643 buttons: {type: "button", text: "Ok", action: "ok"},
20652 this._super(settings);
20657 * Ok buttons constant.
20661 * @field {Number} OK
20666 * Ok/cancel buttons constant.
20670 * @field {Number} OK_CANCEL
20675 * yes/no buttons constant.
20679 * @field {Number} YES_NO
20684 * yes/no/cancel buttons constant.
20688 * @field {Number} YES_NO_CANCEL
20693 * Constructs a new message box and renders it to the body element.
20697 * @param {Object} settings Name/value object with settings.
20699 msgBox: function(settings) {
20700 var buttons, callback = settings.callback || function() {};
20702 switch (settings.buttons) {
20703 case MessageBox.OK_CANCEL:
20705 {type: "button", text: "Ok", subtype: "primary", onClick: function(e) {
20706 e.control.parents()[1].close();
20710 {type: "button", text: "Cancel", onClick: function(e) {
20711 e.control.parents()[1].close();
20717 case MessageBox.YES_NO:
20719 {type: "button", text: "Ok", subtype: "primary", onClick: function(e) {
20720 e.control.parents()[1].close();
20726 case MessageBox.YES_NO_CANCEL:
20728 {type: "button", text: "Ok", subtype: "primary", onClick: function(e) {
20729 e.control.parents()[1].close();
20736 {type: "button", text: "Ok", subtype: "primary", onClick: function(e) {
20737 e.control.parents()[1].close();
20743 return new Window({
20753 title: settings.title,
20759 text: settings.text
20761 onClose: settings.onClose
20762 }).renderTo(document.body).reflow();
20766 * Creates a new alert dialog.
20769 * @param {Object} settings Settings for the alert dialog.
20770 * @param {function} [callback] Callback to execute when the user makes a choice.
20772 alert: function(settings, callback) {
20773 if (typeof(settings) == "string") {
20774 settings = {text: settings};
20777 settings.callback = callback;
20778 return MessageBox.msgBox(settings);
20782 * Creates a new confirm dialog.
20785 * @param {Object} settings Settings for the confirm dialog.
20786 * @param {function} [callback] Callback to execute when the user makes a choice.
20788 confirm: function(settings, callback) {
20789 if (typeof(settings) == "string") {
20790 settings = {text: settings};
20793 settings.callback = callback;
20794 settings.buttons = MessageBox.OK_CANCEL;
20796 return MessageBox.msgBox(settings);
20804 // Included from: js/tinymce/classes/WindowManager.js
20809 * Copyright, Moxiecode Systems AB
20810 * Released under LGPL License.
20812 * License: http://www.tinymce.com/license
20813 * Contributing: http://www.tinymce.com/contributing
20817 * This class handles the creation of native windows and dialogs. This class can be extended to provide for example inline dialogs.
20819 * @class tinymce.WindowManager
20821 * // Opens a new dialog with the file.htm file and the size 320x240
20822 * // It also adds a custom parameter this can be retrieved by using tinyMCEPopup.getWindowArg inside the dialog.
20823 * tinymce.activeEditor.windowManager.open({
20831 * // Displays an alert box using the active editors window manager instance
20832 * tinymce.activeEditor.windowManager.alert('Hello world!');
20834 * // Displays an confirm box and an alert message will be displayed depending on what you choose in the confirm
20835 * tinymce.activeEditor.windowManager.confirm("Do you want to do something", function(s) {
20837 * tinymce.activeEditor.windowManager.alert("Ok");
20839 * tinymce.activeEditor.windowManager.alert("Cancel");
20842 define("tinymce/WindowManager", [
20843 "tinymce/ui/Window",
20844 "tinymce/ui/MessageBox"
20845 ], function(Window, MessageBox) {
20846 return function(editor) {
20847 var self = this, windows = [];
20849 self.windows = windows;
20852 * Opens a new window.
20855 * @param {Object} args Optional name/value settings collection contains things like width/height/url etc.
20856 * @option {String} title Window title.
20857 * @option {String} file URL of the file to open in the window.
20858 * @option {Number} width Width in pixels.
20859 * @option {Number} height Height in pixels.
20860 * @option {Boolean} resizable Specifies whether the popup window is resizable or not.
20861 * @option {Boolean} maximizable Specifies whether the popup window has a "maximize" button and can get maximized or not.
20862 * @option {String/bool} scrollbars Specifies whether the popup window can have scrollbars if required (i.e. content
20863 * larger than the popup size specified).
20865 self.open = function(args, params) {
20869 args.url = args.url || args.file; // Legacy
20871 args.width = parseInt(args.width || 320, 10);
20872 args.height = parseInt(args.height || 240, 10);
20878 defaults: args.defaults,
20879 type: args.bodyType || 'form',
20884 if (!args.url && !args.buttons) {
20886 {text: 'Ok', subtype: 'primary', onclick: function() {
20887 win.find('form')[0].submit();
20891 {text: 'Cancel', onclick: function() {
20897 win = new Window(args);
20900 win.on('close', function() {
20901 var i = windows.length;
20904 if (windows[i] === win) {
20905 windows.splice(i, 1);
20914 win.on('postRender', function() {
20915 this.find('*').each(function(ctrl) {
20916 var name = ctrl.name();
20918 if (name in args.data) {
20919 ctrl.value(args.data[name]);
20925 // store parameters
20926 win.params = params || {};
20928 // Takes a snapshot in the FocusManager of the selection before focus is lost to dialog
20929 editor.nodeChanged();
20931 return win.renderTo(document.body).reflow();
20935 * Creates a alert dialog. Please don't use the blocking behavior of this
20936 * native version use the callback method instead then it can be extended.
20939 * @param {String} message Text to display in the new alert dialog.
20940 * @param {function} callback Callback function to be executed after the user has selected ok.
20941 * @param {Object} scope Optional scope to execute the callback in.
20943 * // Displays an alert box using the active editors window manager instance
20944 * tinymce.activeEditor.windowManager.alert('Hello world!');
20946 self.alert = function(message, callback, scope) {
20947 MessageBox.alert(message, function() {
20948 callback.call(scope || this);
20953 * Creates a confirm dialog. Please don't use the blocking behavior of this
20954 * native version use the callback method instead then it can be extended.
20957 * @param {String} messageText to display in the new confirm dialog.
20958 * @param {function} callback Callback function to be executed after the user has selected ok or cancel.
20959 * @param {Object} scope Optional scope to execute the callback in.
20961 * // Displays an confirm box and an alert message will be displayed depending on what you choose in the confirm
20962 * tinymce.activeEditor.windowManager.confirm("Do you want to do something", function(s) {
20964 * tinymce.activeEditor.windowManager.alert("Ok");
20966 * tinymce.activeEditor.windowManager.alert("Cancel");
20969 self.confirm = function(message, callback, scope) {
20970 MessageBox.confirm(message, function(state) {
20971 callback.call(scope || this, state);
20976 * Closes the top most window.
20980 self.close = function() {
20981 if (windows.length) {
20982 windows[windows.length - 1].close();
20987 * Returns the params of the last window open call. This can be used in iframe based
20988 * dialog to get params passed from the tinymce plugin.
20991 * var dialogArguments = top.tinymce.activeEditor.windowManager.getParams();
20993 * @method getParams
20994 * @return {Object} Name/value object with parameters passed from windowManager.open call.
20996 self.getParams = function() {
20997 if (windows.length) {
20998 return windows[windows.length - 1].params;
21005 * Sets the params of the last opened window.
21007 * @method setParams
21008 * @param {Object} params Params object to set for the last opened window.
21010 self.setParams = function(params) {
21011 if (windows.length) {
21012 windows[windows.length - 1].params = params;
21018 // Included from: js/tinymce/classes/util/Quirks.js
21023 * Copyright, Moxiecode Systems AB
21024 * Released under LGPL License.
21026 * License: http://www.tinymce.com/license
21027 * Contributing: http://www.tinymce.com/contributing
21033 * This file includes fixes for various browser quirks it's made to make it easy to add/remove browser specific fixes.
21035 * @class tinymce.util.Quirks
21037 define("tinymce/util/Quirks", [
21039 "tinymce/dom/RangeUtils",
21040 "tinymce/html/Node",
21041 "tinymce/html/Entities",
21043 "tinymce/util/Tools"
21044 ], function(VK, RangeUtils, Node, Entities, Env, Tools) {
21045 return function(editor) {
21046 var each = Tools.each;
21047 var BACKSPACE = VK.BACKSPACE, DELETE = VK.DELETE, dom = editor.dom, selection = editor.selection,
21048 settings = editor.settings, parser = editor.parser, serializer = editor.serializer;
21049 var isGecko = Env.gecko, isIE = Env.ie, isWebKit = Env.webkit;
21052 * Executes a command with a specific state this can be to enable/disable browser editing features.
21054 function setEditorCommandState(cmd, state) {
21056 editor.getDoc().execCommand(cmd, false, state);
21063 * Returns current IE document mode.
21065 function getDocumentMode() {
21066 var documentMode = editor.getDoc().documentMode;
21068 return documentMode ? documentMode : 6;
21072 * Returns true/false if the event is prevented or not.
21075 * @param {Event} e Event object.
21076 * @return {Boolean} true/false if the event is prevented or not.
21078 function isDefaultPrevented(e) {
21079 return e.isDefaultPrevented();
21083 * Fixes a WebKit bug when deleting contents using backspace or delete key.
21084 * WebKit will produce a span element if you delete across two block elements.
21087 * <h1>a</h1><p>|b</p>
21089 * Will produce this on backspace:
21090 * <h1>a<span class="Apple-style-span" style="<all runtime styles>">b</span></p>
21092 * This fixes the backspace to produce:
21095 * See bug: https://bugs.webkit.org/show_bug.cgi?id=45784
21097 * This code is a bit of a hack and hopefully it will be fixed soon in WebKit.
21099 function cleanupStylesWhenDeleting() {
21100 function removeMergedFormatSpans(isDelete) {
21101 var rng, blockElm, wrapperElm, bookmark, container, offset, elm;
21103 function isAtStartOrEndOfElm() {
21104 if (container.nodeType == 3) {
21105 if (isDelete && offset == container.length) {
21109 if (!isDelete && offset === 0) {
21115 rng = selection.getRng();
21116 var tmpRng = [rng.startContainer, rng.startOffset, rng.endContainer, rng.endOffset];
21118 if (!rng.collapsed) {
21122 container = rng[(isDelete ? 'start' : 'end') + 'Container'];
21123 offset = rng[(isDelete ? 'start' : 'end') + 'Offset'];
21125 if (container.nodeType == 3) {
21126 blockElm = dom.getParent(rng.startContainer, dom.isBlock);
21128 // On delete clone the root span of the next block element
21130 blockElm = dom.getNext(blockElm, dom.isBlock);
21133 if (blockElm && (isAtStartOrEndOfElm() || !rng.collapsed)) {
21134 // Wrap children of block in a EM and let WebKit stick is
21135 // runtime styles junk into that EM
21136 wrapperElm = dom.create('em', {'id': '__mceDel'});
21138 each(Tools.grep(blockElm.childNodes), function(node) {
21139 wrapperElm.appendChild(node);
21142 blockElm.appendChild(wrapperElm);
21146 // Do the backspace/delete action
21147 rng = dom.createRng();
21148 rng.setStart(tmpRng[0], tmpRng[1]);
21149 rng.setEnd(tmpRng[2], tmpRng[3]);
21150 selection.setRng(rng);
21151 editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
21153 // Remove temp wrapper element
21155 bookmark = selection.getBookmark();
21157 while ((elm = dom.get('__mceDel'))) {
21158 dom.remove(elm, true);
21161 selection.moveToBookmark(bookmark);
21165 editor.on('keydown', function(e) {
21168 isDelete = e.keyCode == DELETE;
21169 if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
21170 e.preventDefault();
21171 removeMergedFormatSpans(isDelete);
21175 editor.addCommand('Delete', function() {removeMergedFormatSpans();});
21179 * Makes sure that the editor body becomes empty when backspace or delete is pressed in empty editors.
21190 function emptyEditorWhenDeleting() {
21191 function serializeRng(rng) {
21192 var body = dom.create("body");
21193 var contents = rng.cloneContents();
21194 body.appendChild(contents);
21195 return selection.serializer.serialize(body, {format: 'html'});
21198 function allContentsSelected(rng) {
21199 var selection = serializeRng(rng);
21201 var allRng = dom.createRng();
21202 allRng.selectNode(editor.getBody());
21204 var allSelection = serializeRng(allRng);
21205 return selection === allSelection;
21208 editor.on('keydown', function(e) {
21209 var keyCode = e.keyCode, isCollapsed;
21211 // Empty the editor if it's needed for example backspace at <p><b>|</b></p>
21212 if (!isDefaultPrevented(e) && (keyCode == DELETE || keyCode == BACKSPACE)) {
21213 isCollapsed = editor.selection.isCollapsed();
21215 // Selection is collapsed but the editor isn't empty
21216 if (isCollapsed && !dom.isEmpty(editor.getBody())) {
21220 // IE deletes all contents correctly when everything is selected
21221 if (isIE && !isCollapsed) {
21225 // Selection isn't collapsed but not all the contents is selected
21226 if (!isCollapsed && !allContentsSelected(editor.selection.getRng())) {
21230 // Manually empty the editor
21231 e.preventDefault();
21232 editor.setContent('');
21233 editor.selection.setCursorLocation(editor.getBody(), 0);
21234 editor.nodeChanged();
21240 * WebKit doesn't select all the nodes in the body when you press Ctrl+A.
21241 * This selects the whole body so that backspace/delete logic will delete everything
21243 function selectAll() {
21244 editor.on('keydown', function(e) {
21245 if (!isDefaultPrevented(e) && e.keyCode == 65 && VK.metaKeyPressed(e)) {
21246 e.preventDefault();
21247 editor.execCommand('SelectAll');
21253 * WebKit has a weird issue where it some times fails to properly convert keypresses to input method keystrokes.
21254 * The IME on Mac doesn't initialize when it doesn't fire a proper focus event.
21256 * This seems to happen when the user manages to click the documentElement element then the window doesn't get proper focus until
21257 * you enter a character into the editor.
21259 * It also happens when the first focus in made to the body.
21261 * See: https://bugs.webkit.org/show_bug.cgi?id=83566
21263 function inputMethodFocus() {
21264 if (!editor.settings.content_editable) {
21265 // Case 1 IME doesn't initialize if you focus the document
21266 dom.bind(editor.getDoc(), 'focusin', function() {
21267 selection.setRng(selection.getRng());
21270 // Case 2 IME doesn't initialize if you click the documentElement it also doesn't properly fire the focusin event
21271 dom.bind(editor.getDoc(), 'mousedown', function(e) {
21272 if (e.target == editor.getDoc().documentElement) {
21273 editor.getWin().focus();
21274 selection.setRng(selection.getRng());
21281 * Backspacing in FireFox/IE from a paragraph into a horizontal rule results in a floating text node because the
21282 * browser just deletes the paragraph - the browser fails to merge the text node with a horizontal rule so it is
21283 * left there. TinyMCE sees a floating text node and wraps it in a paragraph on the key up event (ForceBlocks.js
21284 * addRootBlocks), meaning the action does nothing. With this code, FireFox/IE matche the behaviour of other
21287 function removeHrOnBackspace() {
21288 editor.on('keydown', function(e) {
21289 if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
21290 if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
21291 var node = selection.getNode();
21292 var previousSibling = node.previousSibling;
21294 if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "hr") {
21295 dom.remove(previousSibling);
21296 e.preventDefault();
21304 * Firefox 3.x has an issue where the body element won't get proper focus if you click out
21305 * side it's rectangle.
21307 function focusBody() {
21308 // Fix for a focus bug in FF 3.x where the body element
21309 // wouldn't get proper focus if the user clicked on the HTML element
21310 if (!window.Range.prototype.getClientRects) { // Detect getClientRects got introduced in FF 4
21311 editor.on('mousedown', function(e) {
21312 if (!isDefaultPrevented(e) && e.target.nodeName === "HTML") {
21313 var body = editor.getBody();
21315 // Blur the body it's focused but not correctly focused
21318 // Refocus the body after a little while
21319 setTimeout(function() {
21328 * WebKit has a bug where it isn't possible to select image, hr or anchor elements
21329 * by clicking on them so we need to fake that.
21331 function selectControlElements() {
21332 editor.on('click', function(e) {
21335 // Workaround for bug, http://bugs.webkit.org/show_bug.cgi?id=12250
21336 // WebKit can't even do simple things like selecting an image
21337 // Needs tobe the setBaseAndExtend or it will fail to select floated images
21338 if (/^(IMG|HR)$/.test(e.nodeName)) {
21339 selection.getSel().setBaseAndExtent(e, 0, e, 1);
21342 if (e.nodeName == 'A' && dom.hasClass(e, 'mce-item-anchor')) {
21343 selection.select(e);
21346 editor.nodeChanged();
21351 * Fixes a Gecko bug where the style attribute gets added to the wrong element when deleting between two block elements.
21353 * Fixes do backspace/delete on this:
21354 * <p>bla[ck</p><p style="color:red">r]ed</p>
21360 * <p style="color:red">bla|ed</p>
21362 function removeStylesWhenDeletingAcrossBlockElements() {
21363 function getAttributeApplyFunction() {
21364 var template = dom.getAttribs(selection.getStart().cloneNode(false));
21366 return function() {
21367 var target = selection.getStart();
21369 if (target !== editor.getBody()) {
21370 dom.setAttrib(target, "style", null);
21372 each(template, function(attr) {
21373 target.setAttributeNode(attr.cloneNode(true));
21379 function isSelectionAcrossElements() {
21380 return !selection.isCollapsed() &&
21381 dom.getParent(selection.getStart(), dom.isBlock) != dom.getParent(selection.getEnd(), dom.isBlock);
21384 editor.on('keypress', function(e) {
21385 var applyAttributes;
21387 if (!isDefaultPrevented(e) && (e.keyCode == 8 || e.keyCode == 46) && isSelectionAcrossElements()) {
21388 applyAttributes = getAttributeApplyFunction();
21389 editor.getDoc().execCommand('delete', false, null);
21391 e.preventDefault();
21396 dom.bind(editor.getDoc(), 'cut', function(e) {
21397 var applyAttributes;
21399 if (!isDefaultPrevented(e) && isSelectionAcrossElements()) {
21400 applyAttributes = getAttributeApplyFunction();
21402 setTimeout(function() {
21410 * Fire a nodeChanged when the selection is changed on WebKit this fixes selection issues on iOS5. It only fires the nodeChange
21411 * event every 50ms since it would other wise update the UI when you type and it hogs the CPU.
21413 function selectionChangeNodeChanged() {
21414 var lastRng, selectionTimer;
21416 editor.on('selectionchange', function() {
21417 if (selectionTimer) {
21418 clearTimeout(selectionTimer);
21419 selectionTimer = 0;
21422 selectionTimer = window.setTimeout(function() {
21423 var rng = selection.getRng();
21425 // Compare the ranges to see if it was a real change or not
21426 if (!lastRng || !RangeUtils.compareRanges(rng, lastRng)) {
21427 editor.nodeChanged();
21435 * Screen readers on IE needs to have the role application set on the body.
21437 function ensureBodyHasRoleApplication() {
21438 document.body.setAttribute("role", "application");
21442 * Backspacing into a table behaves differently depending upon browser type.
21443 * Therefore, disable Backspace when cursor immediately follows a table.
21445 function disableBackspaceIntoATable() {
21446 editor.on('keydown', function(e) {
21447 if (!isDefaultPrevented(e) && e.keyCode === BACKSPACE) {
21448 if (selection.isCollapsed() && selection.getRng(true).startOffset === 0) {
21449 var previousSibling = selection.getNode().previousSibling;
21450 if (previousSibling && previousSibling.nodeName && previousSibling.nodeName.toLowerCase() === "table") {
21451 e.preventDefault();
21460 * Old IE versions can't properly render BR elements in PRE tags white in contentEditable mode. So this
21461 * logic adds a \n before the BR so that it will get rendered.
21463 function addNewLinesBeforeBrInPre() {
21464 // IE8+ rendering mode does the right thing with BR in PRE
21465 if (getDocumentMode() > 7) {
21469 // Enable display: none in area and add a specific class that hides all BR elements in PRE to
21470 // avoid the caret from getting stuck at the BR elements while pressing the right arrow key
21471 setEditorCommandState('RespectVisibilityInDesign', true);
21472 editor.contentStyles.push('.mceHideBrInPre pre br {display: none}');
21473 dom.addClass(editor.getBody(), 'mceHideBrInPre');
21475 // Adds a \n before all BR elements in PRE to get them visual
21476 parser.addNodeFilter('pre', function(nodes) {
21477 var i = nodes.length, brNodes, j, brElm, sibling;
21480 brNodes = nodes[i].getAll('br');
21481 j = brNodes.length;
21483 brElm = brNodes[j];
21485 // Add \n before BR in PRE elements on older IE:s so the new lines get rendered
21486 sibling = brElm.prev;
21487 if (sibling && sibling.type === 3 && sibling.value.charAt(sibling.value - 1) != '\n') {
21488 sibling.value += '\n';
21490 brElm.parent.insert(new Node('#text', 3), brElm, true).value = '\n';
21496 // Removes any \n before BR elements in PRE since other browsers and in contentEditable=false mode they will be visible
21497 serializer.addNodeFilter('pre', function(nodes) {
21498 var i = nodes.length, brNodes, j, brElm, sibling;
21501 brNodes = nodes[i].getAll('br');
21502 j = brNodes.length;
21504 brElm = brNodes[j];
21505 sibling = brElm.prev;
21506 if (sibling && sibling.type == 3) {
21507 sibling.value = sibling.value.replace(/\r?\n$/, '');
21515 * Moves style width/height to attribute width/height when the user resizes an image on IE.
21517 function removePreSerializedStylesWhenSelectingControls() {
21518 dom.bind(editor.getBody(), 'mouseup', function() {
21519 var value, node = selection.getNode();
21521 // Moved styles to attributes on IMG eements
21522 if (node.nodeName == 'IMG') {
21523 // Convert style width to width attribute
21524 if ((value = dom.getStyle(node, 'width'))) {
21525 dom.setAttrib(node, 'width', value.replace(/[^0-9%]+/g, ''));
21526 dom.setStyle(node, 'width', '');
21529 // Convert style height to height attribute
21530 if ((value = dom.getStyle(node, 'height'))) {
21531 dom.setAttrib(node, 'height', value.replace(/[^0-9%]+/g, ''));
21532 dom.setStyle(node, 'height', '');
21539 * Backspace or delete on WebKit will combine all visual styles in a span if the last character is deleted.
21541 * For example backspace on:
21545 * <p><span style="font-weight: bold">|<br></span></p>
21547 * When it should produce:
21548 * <p><b>|<br></b></p>
21550 * See: https://bugs.webkit.org/show_bug.cgi?id=81656
21552 function keepInlineElementOnDeleteBackspace() {
21553 editor.on('keydown', function(e) {
21554 var isDelete, rng, container, offset, brElm, sibling, collapsed, nonEmptyElements;
21556 isDelete = e.keyCode == DELETE;
21557 if (!isDefaultPrevented(e) && (isDelete || e.keyCode == BACKSPACE) && !VK.modifierPressed(e)) {
21558 rng = selection.getRng();
21559 container = rng.startContainer;
21560 offset = rng.startOffset;
21561 collapsed = rng.collapsed;
21563 // Override delete if the start container is a text node and is at the beginning of text or
21564 // just before/after the last character to be deleted in collapsed mode
21565 if (container.nodeType == 3 && container.nodeValue.length > 0 && ((offset === 0 && !collapsed) ||
21566 (collapsed && offset === (isDelete ? 0 : 1)))) {
21567 // Edge case when deleting <p><b><img> |x</b></p>
21568 sibling = container.previousSibling;
21569 if (sibling && sibling.nodeName == "IMG") {
21573 nonEmptyElements = editor.schema.getNonEmptyElements();
21575 // Prevent default logic since it's broken
21576 e.preventDefault();
21578 // Insert a BR before the text node this will prevent the containing element from being deleted/converted
21579 brElm = dom.create('br', {id: '__tmp'});
21580 container.parentNode.insertBefore(brElm, container);
21582 // Do the browser delete
21583 editor.getDoc().execCommand(isDelete ? 'ForwardDelete' : 'Delete', false, null);
21585 // Check if the previous sibling is empty after deleting for example: <p><b></b>|</p>
21586 container = selection.getRng().startContainer;
21587 sibling = container.previousSibling;
21588 if (sibling && sibling.nodeType == 1 && !dom.isBlock(sibling) && dom.isEmpty(sibling) &&
21589 !nonEmptyElements[sibling.nodeName.toLowerCase()]) {
21590 dom.remove(sibling);
21593 // Remove the temp element we inserted
21594 dom.remove('__tmp');
21601 * Removes a blockquote when backspace is pressed at the beginning of it.
21604 * <blockquote><p>|x</p></blockquote>
21609 function removeBlockQuoteOnBackSpace() {
21610 // Add block quote deletion handler
21611 editor.on('keydown', function(e) {
21612 var rng, container, offset, root, parent;
21614 if (isDefaultPrevented(e) || e.keyCode != VK.BACKSPACE) {
21618 rng = selection.getRng();
21619 container = rng.startContainer;
21620 offset = rng.startOffset;
21621 root = dom.getRoot();
21622 parent = container;
21624 if (!rng.collapsed || offset !== 0) {
21628 while (parent && parent.parentNode && parent.parentNode.firstChild == parent && parent.parentNode != root) {
21629 parent = parent.parentNode;
21632 // Is the cursor at the beginning of a blockquote?
21633 if (parent.tagName === 'BLOCKQUOTE') {
21634 // Remove the blockquote
21635 editor.formatter.toggle('blockquote', null, parent);
21637 // Move the caret to the beginning of container
21638 rng = dom.createRng();
21639 rng.setStart(container, 0);
21640 rng.setEnd(container, 0);
21641 selection.setRng(rng);
21647 * Sets various Gecko editing options on mouse down and before a execCommand to disable inline table editing that is broken etc.
21649 function setGeckoEditingOptions() {
21650 function setOpts() {
21651 editor._refreshContentEditable();
21653 setEditorCommandState("StyleWithCSS", false);
21654 setEditorCommandState("enableInlineTableEditing", false);
21656 if (!settings.object_resizing) {
21657 setEditorCommandState("enableObjectResizing", false);
21661 if (!settings.readonly) {
21662 editor.on('BeforeExecCommand MouseDown', setOpts);
21667 * Fixes a gecko link bug, when a link is placed at the end of block elements there is
21668 * no way to move the caret behind the link. This fix adds a bogus br element after the link.
21670 * For example this:
21671 * <p><b><a href="#">x</a></b></p>
21674 * <p><b><a href="#">x</a></b><br></p>
21676 function addBrAfterLastLinks() {
21677 function fixLinks() {
21678 each(dom.select('a'), function(node) {
21679 var parentNode = node.parentNode, root = dom.getRoot();
21681 if (parentNode.lastChild === node) {
21682 while (parentNode && !dom.isBlock(parentNode)) {
21683 if (parentNode.parentNode.lastChild !== parentNode || parentNode === root) {
21687 parentNode = parentNode.parentNode;
21690 dom.add(parentNode, 'br', {'data-mce-bogus': 1});
21695 editor.on('SetContent ExecCommand', function(e) {
21696 if (e.type == "setcontent" || e.command === 'mceInsertLink') {
21703 * WebKit will produce DIV elements here and there by default. But since TinyMCE uses paragraphs by
21704 * default we want to change that behavior.
21706 function setDefaultBlockType() {
21707 if (settings.forced_root_block) {
21708 editor.on('init', function() {
21709 setEditorCommandState('DefaultParagraphSeparator', settings.forced_root_block);
21715 * Removes ghost selections from images/tables on Gecko.
21717 function removeGhostSelection() {
21718 editor.on('Undo Redo SetContent', function(e) {
21720 editor.execCommand('mceRepaint');
21726 * Deletes the selected image on IE instead of navigating to previous page.
21728 function deleteControlItemOnBackSpace() {
21729 editor.on('keydown', function(e) {
21732 if (!isDefaultPrevented(e) && e.keyCode == BACKSPACE) {
21733 rng = editor.getDoc().selection.createRange();
21734 if (rng && rng.item) {
21735 e.preventDefault();
21736 editor.undoManager.beforeChange();
21737 dom.remove(rng.item(0));
21738 editor.undoManager.add();
21745 * IE10 doesn't properly render block elements with the right height until you add contents to them.
21746 * This fixes that by adding a padding-right to all empty text block elements.
21747 * See: https://connect.microsoft.com/IE/feedback/details/743881
21749 function renderEmptyBlocksFix() {
21750 var emptyBlocksCSS;
21753 if (getDocumentMode() >= 10) {
21754 emptyBlocksCSS = '';
21755 each('p div h1 h2 h3 h4 h5 h6'.split(' '), function(name, i) {
21756 emptyBlocksCSS += (i > 0 ? ',' : '') + name + ':empty';
21759 editor.contentStyles.push(emptyBlocksCSS + '{padding-right: 1px !important}');
21764 * Old IE versions can't retain contents within noscript elements so this logic will store the contents
21765 * as a attribute and the insert that value as it's raw text when the DOM is serialized.
21767 function keepNoScriptContents() {
21768 if (getDocumentMode() < 9) {
21769 parser.addNodeFilter('noscript', function(nodes) {
21770 var i = nodes.length, node, textNode;
21774 textNode = node.firstChild;
21777 node.attr('data-mce-innertext', textNode.value);
21782 serializer.addNodeFilter('noscript', function(nodes) {
21783 var i = nodes.length, node, textNode, value;
21787 textNode = nodes[i].firstChild;
21790 textNode.value = Entities.decode(textNode.value);
21792 // Old IE can't retain noscript value so an attribute is used to store it
21793 value = node.attributes.map['data-mce-innertext'];
21795 node.attr('data-mce-innertext', null);
21796 textNode = new Node('#text', 3);
21797 textNode.value = value;
21798 textNode.raw = true;
21799 node.append(textNode);
21808 * IE has an issue where you can't select/move the caret by clicking outside the body if the document is in standards mode.
21810 function fixCaretSelectionOfDocumentElementOnIe() {
21811 var doc = dom.doc, body = doc.body, started, startRng, htmlElm;
21813 // Return range from point or null if it failed
21814 function rngFromPoint(x, y) {
21815 var rng = body.createTextRange();
21818 rng.moveToPoint(x, y);
21820 // IE sometimes throws and exception, so lets just ignore it
21827 // Fires while the selection is changing
21828 function selectionChange(e) {
21831 // Check if the button is down or not
21833 // Create range from mouse position
21834 pointRng = rngFromPoint(e.x, e.y);
21837 // Check if pointRange is before/after selection then change the endPoint
21838 if (pointRng.compareEndPoints('StartToStart', startRng) > 0) {
21839 pointRng.setEndPoint('StartToStart', startRng);
21841 pointRng.setEndPoint('EndToEnd', startRng);
21851 // Removes listeners
21852 function endSelection() {
21853 var rng = doc.selection.createRange();
21855 // If the range is collapsed then use the last start range
21856 if (startRng && !rng.item && rng.compareEndPoints('StartToEnd', rng) === 0) {
21860 dom.unbind(doc, 'mouseup', endSelection);
21861 dom.unbind(doc, 'mousemove', selectionChange);
21862 startRng = started = 0;
21865 // Make HTML element unselectable since we are going to handle selection by hand
21866 doc.documentElement.unselectable = true;
21868 // Detect when user selects outside BODY
21869 dom.bind(doc, 'mousedown contextmenu', function(e) {
21870 if (e.target.nodeName === 'HTML') {
21875 // Detect vertical scrollbar, since IE will fire a mousedown on the scrollbar and have target set as HTML
21876 htmlElm = doc.documentElement;
21877 if (htmlElm.scrollHeight > htmlElm.clientHeight) {
21882 // Setup start position
21883 startRng = rngFromPoint(e.x, e.y);
21885 // Listen for selection change events
21886 dom.bind(doc, 'mouseup', endSelection);
21887 dom.bind(doc, 'mousemove', selectionChange);
21897 * Fixes selection issues on Gecko where the caret can be placed between two inline elements like <b>a</b>|<b>b</b>
21898 * this fix will lean the caret right into the closest inline element.
21900 function normalizeSelection() {
21901 // Normalize selection for example <b>a</b><i>|a</i> becomes <b>a|</b><i>a</i> except for Ctrl+A since it selects everything
21902 editor.on('keyup focusin', function(e) {
21903 if (e.keyCode != 65 || !VK.metaKeyPressed(e)) {
21904 selection.normalize();
21910 * Forces Gecko to render a broken image icon if it fails to load an image.
21912 function showBrokenImageIcon() {
21913 editor.contentStyles.push(
21914 'img:-moz-broken {' +
21915 '-moz-force-broken-image-icon:1;' +
21916 'min-width:24px;' +
21917 'min-height:24px' +
21923 * iOS has a bug where it's impossible to type if the document has a touchstart event
21924 * bound and the user touches the document while having the on screen keyboard visible.
21926 * The touch event moves the focus to the parent document while having the caret inside the iframe
21927 * this fix moves the focus back into the iframe document.
21929 function restoreFocusOnKeyDown() {
21930 if (!editor.inline) {
21931 editor.on('keydown', function() {
21932 if (document.activeElement == document.body) {
21933 editor.getWin().focus();
21940 disableBackspaceIntoATable();
21941 removeBlockQuoteOnBackSpace();
21942 emptyEditorWhenDeleting();
21943 normalizeSelection();
21947 keepInlineElementOnDeleteBackspace();
21948 cleanupStylesWhenDeleting();
21949 inputMethodFocus();
21950 selectControlElements();
21951 setDefaultBlockType();
21955 selectionChangeNodeChanged();
21956 restoreFocusOnKeyDown();
21963 if (isIE && Env.ie < 11) {
21964 removeHrOnBackspace();
21965 ensureBodyHasRoleApplication();
21966 addNewLinesBeforeBrInPre();
21967 removePreSerializedStylesWhenSelectingControls();
21968 deleteControlItemOnBackSpace();
21969 renderEmptyBlocksFix();
21970 keepNoScriptContents();
21971 fixCaretSelectionOfDocumentElementOnIe();
21976 removeHrOnBackspace();
21978 removeStylesWhenDeletingAcrossBlockElements();
21979 setGeckoEditingOptions();
21980 addBrAfterLastLinks();
21981 removeGhostSelection();
21982 showBrokenImageIcon();
21987 // Included from: js/tinymce/classes/util/Observable.js
21992 * Copyright, Moxiecode Systems AB
21993 * Released under LGPL License.
21995 * License: http://www.tinymce.com/license
21996 * Contributing: http://www.tinymce.com/contributing
22000 * This mixin will add event binding logic to classes.
22002 * @mixin tinymce.util.Observable
22004 define("tinymce/util/Observable", [
22005 "tinymce/util/Tools"
22006 ], function(Tools) {
22007 var bindingsName = "__bindings";
22008 var nativeEvents = Tools.makeMap(
22009 "focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange" +
22010 " mouseout mouseenter mouseleave keydown keypress keyup contextmenu dragend dragover draggesture dragdrop drop drag", ' '
22013 function returnFalse() {
22017 function returnTrue() {
22023 * Fires the specified event by name.
22026 * @param {String} name Name of the event to fire.
22027 * @param {tinymce.Event/Object?} args Event arguments.
22028 * @param {Boolean?} bubble True/false if the event is to be bubbled.
22029 * @return {tinymce.Event} Event instance passed in converted into tinymce.Event instance.
22031 * instance.fire('event', {...});
22033 fire: function(name, args, bubble) {
22034 var self = this, handlers, i, l, callback, parent;
22036 name = name.toLowerCase();
22040 // Setup target is there isn't one
22041 if (!args.target) {
22042 args.target = self;
22045 // Add event delegation methods if they are missing
22046 if (!args.preventDefault) {
22047 // Add preventDefault method
22048 args.preventDefault = function() {
22049 args.isDefaultPrevented = returnTrue;
22052 // Add stopPropagation
22053 args.stopPropagation = function() {
22054 args.isPropagationStopped = returnTrue;
22057 // Add stopImmediatePropagation
22058 args.stopImmediatePropagation = function() {
22059 args.isImmediatePropagationStopped = returnTrue;
22062 // Add event delegation states
22063 args.isDefaultPrevented = returnFalse;
22064 args.isPropagationStopped = returnFalse;
22065 args.isImmediatePropagationStopped = returnFalse;
22068 //console.log(name, args);
22070 if (self[bindingsName]) {
22071 handlers = self[bindingsName][name];
22074 for (i = 0, l = handlers.length; i < l; i++) {
22075 handlers[i] = callback = handlers[i];
22077 // Stop immediate propagation if needed
22078 if (args.isImmediatePropagationStopped()) {
22082 // If callback returns false then prevent default and stop all propagation
22083 if (callback.call(self, args) === false) {
22084 args.preventDefault();
22091 // Bubble event up to parents
22092 if (bubble !== false && self.parent) {
22093 parent = self.parent();
22094 while (parent && !args.isPropagationStopped()) {
22095 parent.fire(name, args, false);
22096 parent = parent.parent();
22104 * Binds an event listener to a specific event by name.
22107 * @param {String} name Event name or space separated list of events to bind.
22108 * @param {callback} callback Callback to be executed when the event occurs.
22109 * @return {Object} Current class instance.
22111 * instance.on('event', function(e) {
22112 * // Callback logic
22115 on: function(name, callback) {
22116 var self = this, bindings, handlers, names, i;
22118 if (callback === false) {
22119 callback = function() {
22125 names = name.toLowerCase().split(' ');
22130 bindings = self[bindingsName];
22132 bindings = self[bindingsName] = {};
22135 handlers = bindings[name];
22137 handlers = bindings[name] = [];
22138 if (self.bindNative && nativeEvents[name]) {
22139 self.bindNative(name);
22143 handlers.push(callback);
22151 * Unbinds an event listener to a specific event by name.
22154 * @param {String?} name Name of the event to unbind.
22155 * @param {callback?} callback Callback to unbind.
22156 * @return {Object} Current class instance.
22158 * // Unbind specific callback
22159 * instance.off('event', handler);
22161 * // Unbind all listeners by name
22162 * instance.off('event');
22164 * // Unbind all events
22167 off: function(name, callback) {
22168 var self = this, i, bindings = self[bindingsName], handlers, bindingName, names, hi;
22172 names = name.toLowerCase().split(' ');
22176 handlers = bindings[name];
22178 // Unbind all handlers
22180 for (bindingName in bindings) {
22181 bindings[name].length = 0;
22188 // Unbind all by name
22190 handlers.length = 0;
22192 // Unbind specific ones
22193 hi = handlers.length;
22195 if (handlers[hi] === callback) {
22196 handlers.splice(hi, 1);
22201 if (!handlers.length && self.unbindNative && nativeEvents[name]) {
22202 self.unbindNative(name);
22203 delete bindings[name];
22208 if (self.unbindNative) {
22209 for (name in bindings) {
22210 self.unbindNative(name);
22214 self[bindingsName] = [];
22223 // Included from: js/tinymce/classes/Shortcuts.js
22228 * Copyright, Moxiecode Systems AB
22229 * Released under LGPL License.
22231 * License: http://www.tinymce.com/license
22232 * Contributing: http://www.tinymce.com/contributing
22236 * Contains all logic for handling of keyboard shortcuts.
22238 define("tinymce/Shortcuts", [
22239 "tinymce/util/Tools",
22241 ], function(Tools, Env) {
22242 var each = Tools.each, explode = Tools.explode;
22244 var keyCodeLookup = {
22250 return function(editor) {
22251 var self = this, shortcuts = {};
22253 editor.on('keyup keypress keydown', function(e) {
22254 if (e.altKey || e.ctrlKey || e.metaKey) {
22255 each(shortcuts, function(shortcut) {
22256 var ctrlKey = Env.mac ? (e.ctrlKey || e.metaKey) : e.ctrlKey;
22258 if (shortcut.ctrl != ctrlKey || shortcut.alt != e.altKey || shortcut.shift != e.shiftKey) {
22262 if (e.keyCode == shortcut.keyCode || (e.charCode && e.charCode == shortcut.charCode)) {
22263 e.preventDefault();
22265 if (e.type == "keydown") {
22266 shortcut.func.call(shortcut.scope);
22276 * Adds a keyboard shortcut for some command or function.
22278 * @method addShortcut
22279 * @param {String} pattern Shortcut pattern. Like for example: ctrl+alt+o.
22280 * @param {String} desc Text description for the command.
22281 * @param {String/Function} cmdFunc Command name string or function to execute when the key is pressed.
22282 * @param {Object} sc Optional scope to execute the function in.
22283 * @return {Boolean} true/false state if the shortcut was added or not.
22285 self.add = function(pattern, desc, cmdFunc, scope) {
22290 if (typeof(cmdFunc) === 'string') {
22291 cmdFunc = function() {
22292 editor.execCommand(cmd, false, null);
22294 } else if (Tools.isArray(cmd)) {
22295 cmdFunc = function() {
22296 editor.execCommand(cmd[0], cmd[1], cmd[2]);
22300 each(explode(pattern.toLowerCase()), function(pattern) {
22303 scope: scope || editor,
22304 desc: editor.translate(desc),
22310 each(explode(pattern, '+'), function(value) {
22315 shortcut[value] = true;
22319 shortcut.charCode = value.charCodeAt(0);
22320 shortcut.keyCode = keyCodeLookup[value] || value.toUpperCase().charCodeAt(0);
22325 (shortcut.ctrl ? 'ctrl' : '') + ',' +
22326 (shortcut.alt ? 'alt' : '') + ',' +
22327 (shortcut.shift ? 'shift' : '') + ',' +
22337 // Included from: js/tinymce/classes/Editor.js
22342 * Copyright, Moxiecode Systems AB
22343 * Released under LGPL License.
22345 * License: http://www.tinymce.com/license
22346 * Contributing: http://www.tinymce.com/contributing
22349 /*jshint scripturl:true */
22352 * Include the base event class documentation.
22354 * @include ../../../tools/docs/tinymce.Event.js
22358 * This class contains the core logic for a TinyMCE editor.
22360 * @class tinymce.Editor
22361 * @mixes tinymce.util.Observable
22363 * // Add a class to all paragraphs in the editor.
22364 * tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'someclass');
22366 * // Gets the current editors selection as text
22367 * tinymce.activeEditor.selection.getContent({format: 'text'});
22369 * // Creates a new editor instance
22370 * var ed = new tinymce.Editor('textareaid', {
22372 * }, tinymce.EditorManager);
22374 * // Select each item the user clicks on
22375 * ed.on('click', function(e) {
22376 * ed.selection.select(e.target);
22381 define("tinymce/Editor", [
22382 "tinymce/dom/DOMUtils",
22383 "tinymce/AddOnManager",
22384 "tinymce/html/Node",
22385 "tinymce/dom/Serializer",
22386 "tinymce/html/Serializer",
22387 "tinymce/dom/Selection",
22388 "tinymce/Formatter",
22389 "tinymce/UndoManager",
22390 "tinymce/EnterKey",
22391 "tinymce/ForceBlocks",
22392 "tinymce/EditorCommands",
22393 "tinymce/util/URI",
22394 "tinymce/dom/ScriptLoader",
22395 "tinymce/dom/EventUtils",
22396 "tinymce/WindowManager",
22397 "tinymce/html/Schema",
22398 "tinymce/html/DomParser",
22399 "tinymce/util/Quirks",
22401 "tinymce/util/Tools",
22402 "tinymce/util/Observable",
22403 "tinymce/Shortcuts"
22405 DOMUtils, AddOnManager, Node, DomSerializer, Serializer,
22406 Selection, Formatter, UndoManager, EnterKey, ForceBlocks, EditorCommands,
22407 URI, ScriptLoader, EventUtils, WindowManager,
22408 Schema, DomParser, Quirks, Env, Tools, Observable, Shortcuts
22410 // Shorten these names
22411 var DOM = DOMUtils.DOM, ThemeManager = AddOnManager.ThemeManager, PluginManager = AddOnManager.PluginManager;
22412 var extend = Tools.extend, each = Tools.each, explode = Tools.explode;
22413 var inArray = Tools.inArray, trim = Tools.trim, resolve = Tools.resolve;
22414 var Event = EventUtils.Event;
22415 var isGecko = Env.gecko, ie = Env.ie, isOpera = Env.opera;
22417 function getEventTarget(editor, eventName) {
22418 if (eventName == 'selectionchange' || eventName == 'drop') {
22419 return editor.getDoc();
22422 // Need to bind mousedown/mouseup etc to document not body in iframe mode
22423 // Since the user might click on the HTML element not the BODY
22424 if (!editor.inline && /^mouse|click|contextmenu/.test(eventName)) {
22425 return editor.getDoc();
22428 return editor.getBody();
22432 * Include documentation for all the events.
22434 * @include ../../../tools/docs/tinymce.Editor.js
22438 * Constructs a editor instance by id.
22442 * @param {String} id Unique id for the editor.
22443 * @param {Object} settings Settings for the editor.
22444 * @param {tinymce.EditorManager} editorManager EditorManager instance.
22445 * @author Moxiecode
22447 function Editor(id, settings, editorManager) {
22448 var self = this, documentBaseUrl, baseUri;
22450 documentBaseUrl = self.documentBaseUrl = editorManager.documentBaseURL;
22451 baseUri = editorManager.baseURI;
22454 * Name/value collection with editor settings.
22456 * @property settings
22459 * // Get the value of the theme setting
22460 * tinymce.activeEditor.windowManager.alert("You are using the " + tinymce.activeEditor.settings.theme + " theme");
22462 self.settings = settings = extend({
22469 document_base_url: documentBaseUrl,
22470 add_form_submit_trigger: true,
22471 submit_patch: true,
22472 add_unload_trigger: true,
22473 convert_urls: true,
22474 relative_urls: true,
22475 remove_script_host: true,
22476 object_resizing: true,
22477 doctype: '<!DOCTYPE html>',
22479 font_size_style_values: 'xx-small,x-small,small,medium,large,x-large,xx-large',
22481 // See: http://www.w3.org/TR/CSS2/fonts.html#propdef-font-size
22482 font_size_legacy_values: 'xx-small,small,medium,large,x-large,xx-large,300%',
22483 forced_root_block: 'p',
22484 hidden_input: true,
22485 padd_empty_editor: true,
22487 indentation: '30px',
22488 inline_styles: true,
22489 convert_fonts_to_spans: true,
22491 indent_before: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,' +
22492 'tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
22493 indent_after: 'p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,ul,li,area,table,thead,' +
22494 'tfoot,tbody,tr,section,article,hgroup,aside,figure,option,optgroup,datalist',
22496 entity_encoding: 'named',
22497 url_converter: self.convertURL,
22498 url_converter_scope: self,
22503 AddOnManager.settings = settings;
22504 AddOnManager.baseURL = editorManager.baseURL;
22507 * Editor instance id, normally the same as the div/textarea that was replaced.
22512 self.id = settings.id = id;
22515 * State to force the editor to return false on a isDirty call.
22517 * @property isNotDirty
22520 * function ajaxSave() {
22521 * var ed = tinymce.get('elm1');
22523 * // Save contents using some XHR call
22524 * alert(ed.getContent());
22526 * ed.isNotDirty = true; // Force not dirty state
22529 self.isNotDirty = true;
22532 * Name/Value object containting plugin instances.
22534 * @property plugins
22537 * // Execute a method inside a plugin directly
22538 * tinymce.activeEditor.plugins.someplugin.someMethod();
22543 * URI object to document configured for the TinyMCE instance.
22545 * @property documentBaseURI
22546 * @type tinymce.util.URI
22548 * // Get relative URL from the location of document_base_url
22549 * tinymce.activeEditor.documentBaseURI.toRelative('/somedir/somefile.htm');
22551 * // Get absolute URL from the location of document_base_url
22552 * tinymce.activeEditor.documentBaseURI.toAbsolute('somefile.htm');
22554 self.documentBaseURI = new URI(settings.document_base_url || documentBaseUrl, {
22559 * URI object to current document that holds the TinyMCE editor instance.
22561 * @property baseURI
22562 * @type tinymce.util.URI
22564 * // Get relative URL from the location of the API
22565 * tinymce.activeEditor.baseURI.toRelative('/somedir/somefile.htm');
22567 * // Get absolute URL from the location of the API
22568 * tinymce.activeEditor.baseURI.toAbsolute('somefile.htm');
22570 self.baseURI = baseUri;
22573 * Array with CSS files to load into the iframe.
22575 * @property contentCSS
22578 self.contentCSS = [];
22581 * Array of CSS styles to add to head of document when the editor loads.
22583 * @property contentStyles
22586 self.contentStyles = [];
22588 // Creates all events like onClick, onSetContent etc see Editor.Events.js for the actual logic
22589 self.shortcuts = new Shortcuts(self);
22591 // Internal command handler objects
22592 self.execCommands = {};
22593 self.queryStateCommands = {};
22594 self.queryValueCommands = {};
22595 self.loadedCSS = {};
22597 self.suffix = editorManager.suffix;
22598 self.editorManager = editorManager;
22599 self.inline = settings.inline;
22602 self.execCallback('setup', self);
22605 Editor.prototype = {
22607 * Renderes the editor/adds it to the page.
22611 render: function() {
22612 var self = this, settings = self.settings, id = self.id, suffix = self.suffix;
22614 // Page is not loaded yet, wait for it
22615 if (!Event.domLoaded) {
22616 DOM.bind(window, 'ready', function() {
22622 self.editorManager.settings = settings;
22624 // Element not found, then skip initialization
22625 if (!self.getElement()) {
22629 // No editable support old iOS versions etc
22630 if (!Env.contentEditable) {
22634 // Hide target element early to prevent content flashing
22635 if (!settings.inline) {
22636 self.orgVisibility = self.getElement().style.visibility;
22637 self.getElement().style.visibility = 'hidden';
22639 self.inline = true;
22642 var form = self.getElement().form || DOM.getParent(id, 'form');
22644 self.formElement = form;
22646 // Add hidden input for non input elements inside form elements
22647 if (settings.hidden_input && !/TEXTAREA|INPUT/i.test(self.getElement().nodeName)) {
22648 DOM.insertAfter(DOM.create('input', {type: 'hidden', name: id}), id);
22651 // Pass submit/reset from form to editor instance
22652 self.formEventDelegate = function(e) {
22653 self.fire(e.type, e);
22656 DOM.bind(form, 'submit reset', self.formEventDelegate);
22658 // Reset contents in editor when the form is reset
22659 self.on('reset', function() {
22660 self.setContent(self.startContent, {format: 'raw'});
22663 // Check page uses id="submit" or name="submit" for it's submit button
22664 if (settings.submit_patch && !form.submit.nodeType && !form.submit.length && !form._mceOldSubmit) {
22665 form._mceOldSubmit = form.submit;
22666 form.submit = function() {
22667 self.editorManager.triggerSave();
22668 self.isNotDirty = true;
22670 return form._mceOldSubmit(form);
22676 * Window manager reference, use this to open new windows and dialogs.
22678 * @property windowManager
22679 * @type tinymce.WindowManager
22681 * // Shows an alert message
22682 * tinymce.activeEditor.windowManager.alert('Hello world!');
22684 * // Opens a new dialog with the file.htm file and the size 320x240
22685 * // It also adds a custom parameter this can be retrieved by using tinyMCEPopup.getWindowArg inside the dialog.
22686 * tinymce.activeEditor.windowManager.open({
22694 self.windowManager = new WindowManager(self);
22696 if (settings.encoding == 'xml') {
22697 self.on('GetContent', function(e) {
22699 e.content = DOM.encode(e.content);
22704 if (settings.add_form_submit_trigger) {
22705 self.on('submit', function() {
22706 if (self.initialized) {
22712 if (settings.add_unload_trigger) {
22713 self._beforeUnload = function() {
22714 if (self.initialized && !self.destroyed && !self.isHidden()) {
22715 self.save({format: 'raw', no_events: true, set_dirty: false});
22719 self.editorManager.on('BeforeUnload', self._beforeUnload);
22723 function loadScripts() {
22724 var scriptLoader = ScriptLoader.ScriptLoader;
22726 if (settings.language && settings.language != 'en') {
22727 settings.language_url = self.editorManager.baseURL + '/langs/' + settings.language + '.js';
22730 if (settings.language_url) {
22731 scriptLoader.add(settings.language_url);
22734 if (settings.theme && typeof settings.theme != "function" &&
22735 settings.theme.charAt(0) != '-' && !ThemeManager.urls[settings.theme]) {
22736 ThemeManager.load(settings.theme, 'themes/' + settings.theme + '/theme' + suffix + '.js');
22739 if (Tools.isArray(settings.plugins)) {
22740 settings.plugins = settings.plugins.join(' ');
22743 each(settings.external_plugins, function(url, name) {
22744 PluginManager.load(name, url);
22745 settings.plugins += ' ' + name;
22748 each(settings.plugins.split(/[ ,]/), function(plugin) {
22749 plugin = trim(plugin);
22751 if (plugin && !PluginManager.urls[plugin]) {
22752 if (plugin.charAt(0) == '-') {
22753 plugin = plugin.substr(1, plugin.length);
22755 var dependencies = PluginManager.dependencies(plugin);
22757 each(dependencies, function(dep) {
22758 var defaultSettings = {
22761 suffix:'/plugin' + suffix + '.js'
22764 dep = PluginManager.createUrl(defaultSettings, dep);
22765 PluginManager.load(dep.resource, dep);
22768 PluginManager.load(plugin, {
22769 prefix: 'plugins/',
22771 suffix: '/plugin' + suffix + '.js'
22777 scriptLoader.loadQueue(function() {
22778 if (!self.removed) {
22788 * Initializes the editor this will be called automatically when
22789 * all plugins/themes and language packs are loaded by the rendered method.
22790 * This method will setup the iframe and create the theme and plugin instances.
22795 var self = this, settings = self.settings, elm = self.getElement();
22796 var w, h, minHeight, n, o, url, bodyId, bodyClass, re, i, initializedPlugins = [];
22798 self.editorManager.add(self);
22800 settings.aria_label = settings.aria_label || DOM.getAttrib(elm, 'aria-label', self.getLang('aria.rich_text_area'));
22803 * Reference to the theme instance that was used to generate the UI.
22806 * @type tinymce.Theme
22808 * // Executes a method on the theme directly
22809 * tinymce.activeEditor.theme.someMethod();
22811 if (settings.theme) {
22812 if (typeof settings.theme != "function") {
22813 settings.theme = settings.theme.replace(/-/, '');
22814 o = ThemeManager.get(settings.theme);
22815 self.theme = new o(self, ThemeManager.urls[settings.theme]);
22817 if (self.theme.init) {
22818 self.theme.init(self, ThemeManager.urls[settings.theme] || self.documentBaseUrl.replace(/\/$/, ''));
22821 self.theme = settings.theme;
22825 function initPlugin(plugin) {
22826 var constr = PluginManager.get(plugin), url, pluginInstance;
22828 url = PluginManager.urls[plugin] || self.documentBaseUrl.replace(/\/$/, '');
22829 plugin = trim(plugin);
22830 if (constr && inArray(initializedPlugins, plugin) === -1) {
22831 each(PluginManager.dependencies(plugin), function(dep){
22835 pluginInstance = new constr(self, url);
22837 self.plugins[plugin] = pluginInstance;
22839 if (pluginInstance.init) {
22840 pluginInstance.init(self, url);
22841 initializedPlugins.push(plugin);
22846 // Create all plugins
22847 each(settings.plugins.replace(/\-/g, '').split(/[ ,]/), initPlugin);
22849 // Enables users to override the control factory
22850 self.fire('BeforeRenderUI');
22853 if (settings.render_ui && self.theme) {
22854 self.orgDisplay = elm.style.display;
22856 if (typeof settings.theme != "function") {
22857 w = settings.width || elm.style.width || elm.offsetWidth;
22858 h = settings.height || elm.style.height || elm.offsetHeight;
22859 minHeight = settings.min_height || 100;
22860 re = /^[0-9\.]+(|px)$/i;
22862 if (re.test('' + w)) {
22863 w = Math.max(parseInt(w, 10) + (o.deltaWidth || 0), 100);
22866 if (re.test('' + h)) {
22867 h = Math.max(parseInt(h, 10) + (o.deltaHeight || 0), minHeight);
22871 o = self.theme.renderUI({
22875 deltaWidth: settings.delta_width,
22876 deltaHeight: settings.delta_height
22880 if (!settings.content_editable) {
22881 DOM.setStyles(o.sizeContainer || o.editorContainer, {
22887 h = (o.iframeHeight || h) + (typeof(h) == 'number' ? (o.deltaHeight || 0) : '');
22888 if (h < minHeight) {
22893 o = settings.theme(self, elm);
22895 // Convert element type to id:s
22896 if (o.editorContainer.nodeType) {
22897 o.editorContainer = o.editorContainer.id = o.editorContainer.id || self.id + "_parent";
22900 // Convert element type to id:s
22901 if (o.iframeContainer.nodeType) {
22902 o.iframeContainer = o.iframeContainer.id = o.iframeContainer.id || self.id + "_iframecontainer";
22905 // Use specified iframe height or the targets offsetHeight
22906 h = o.iframeHeight || elm.offsetHeight;
22909 self.editorContainer = o.editorContainer;
22912 // Load specified content CSS last
22913 if (settings.content_css) {
22914 each(explode(settings.content_css), function(u) {
22915 self.contentCSS.push(self.documentBaseURI.toAbsolute(u));
22919 // Load specified content CSS last
22920 if (settings.content_style) {
22921 self.contentStyles.push(settings.content_style);
22924 // Content editable mode ends here
22925 if (settings.content_editable) {
22926 elm = n = o = null; // Fix IE leak
22927 return self.initContentBody();
22930 // User specified a document.domain value
22931 if (document.domain && location.hostname != document.domain) {
22932 self.editorManager.relaxedDomain = document.domain;
22935 self.iframeHTML = settings.doctype + '<html><head>';
22937 // We only need to override paths if we have to
22938 // IE has a bug where it remove site absolute urls to relative ones if this is specified
22939 if (settings.document_base_url != self.documentBaseUrl) {
22940 self.iframeHTML += '<base href="' + self.documentBaseURI.getURI() + '" />';
22943 // IE8 doesn't support carets behind images setting ie7_compat would force IE8+ to run in IE7 compat mode.
22944 if (!Env.caretAfter && settings.ie7_compat) {
22945 self.iframeHTML += '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
22948 self.iframeHTML += '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
22950 // Load the CSS by injecting them into the HTML this will reduce "flicker"
22951 for (i = 0; i < self.contentCSS.length; i++) {
22952 var cssUrl = self.contentCSS[i];
22953 self.iframeHTML += '<link type="text/css" rel="stylesheet" href="' + cssUrl + '" />';
22954 self.loadedCSS[cssUrl] = true;
22957 bodyId = settings.body_id || 'tinymce';
22958 if (bodyId.indexOf('=') != -1) {
22959 bodyId = self.getParam('body_id', '', 'hash');
22960 bodyId = bodyId[self.id] || bodyId;
22963 bodyClass = settings.body_class || '';
22964 if (bodyClass.indexOf('=') != -1) {
22965 bodyClass = self.getParam('body_class', '', 'hash');
22966 bodyClass = bodyClass[self.id] || '';
22969 self.iframeHTML += '</head><body id="' + bodyId + '" class="mce-content-body ' + bodyClass + '" ' +
22970 'onload="window.parent.tinymce.get(\'' + self.id + '\').fire(\'load\');"><br></body></html>';
22972 // Domain relaxing enabled, then set document domain
22973 // TODO: Fix this old stuff
22974 if (self.editorManager.relaxedDomain && (ie || (isOpera && parseFloat(window.opera.version()) < 11))) {
22975 // We need to write the contents here in IE since multiple writes messes up refresh button and back button
22976 url = 'javascript:(function(){document.open();document.domain="' + document.domain + '";' +
22977 'var ed = window.parent.tinymce.get("' + self.id + '");document.write(ed.iframeHTML);' +
22978 'document.close();ed.initContentBody();})()';
22982 // TODO: ACC add the appropriate description on this.
22983 n = DOM.add(o.iframeContainer, 'iframe', {
22984 id: self.id + "_ifr",
22985 src: url || 'javascript:""', // Workaround for HTTPS warning in IE6/7
22987 allowTransparency: "true",
22988 title: self.editorManager.translate(
22989 "Rich Text Area. Press ALT-F9 for menu. " +
22990 "Press ALT-F10 for toolbar. Press ALT-0 for help"
22995 display: 'block' // Important for Gecko to render the iframe correctly
22999 self.contentAreaContainer = o.iframeContainer;
23001 if (o.editorContainer) {
23002 DOM.get(o.editorContainer).style.display = self.orgDisplay;
23005 DOM.get(self.id).style.display = 'none';
23006 DOM.setAttrib(self.id, 'aria-hidden', true);
23008 if (!self.editorManager.relaxedDomain || !url) {
23009 self.initContentBody();
23012 elm = n = o = null; // Cleanup
23016 * This method get called by the init method ones the iframe is loaded.
23017 * It will fill the iframe with contents, setups DOM and selection objects for the iframe.
23019 * @method initContentBody
23022 initContentBody: function() {
23023 var self = this, settings = self.settings, targetElm = DOM.get(self.id), doc = self.getDoc(), body, contentCssText;
23025 // Restore visibility on target element
23026 if (!settings.inline) {
23027 self.getElement().style.visibility = self.orgVisibility;
23030 // Setup iframe body
23031 if ((!ie || !self.editorManager.relaxedDomain) && !settings.content_editable) {
23033 doc.write(self.iframeHTML);
23036 if (self.editorManager.relaxedDomain) {
23037 doc.domain = self.editorManager.relaxedDomain;
23041 if (settings.content_editable) {
23042 self.on('remove', function() {
23043 var body = this.getBody();
23045 DOM.removeClass(body, 'mce-content-body');
23046 DOM.removeClass(body, 'mce-edit-focus');
23047 DOM.setAttrib(body, 'tabIndex', null);
23048 DOM.setAttrib(body, 'contentEditable', null);
23051 DOM.addClass(targetElm, 'mce-content-body');
23052 targetElm.tabIndex = -1;
23053 self.contentDocument = doc = settings.content_document || document;
23054 self.contentWindow = settings.content_window || window;
23055 self.bodyElement = targetElm;
23057 // Prevent leak in IE
23058 settings.content_document = settings.content_window = null;
23061 settings.root_name = targetElm.nodeName.toLowerCase();
23064 // It will not steal focus while setting contentEditable
23065 body = self.getBody();
23066 body.disabled = true;
23068 if (!settings.readonly) {
23069 body.contentEditable = self.getParam('content_editable_state', true);
23072 body.disabled = false;
23075 * Schema instance, enables you to validate elements and it's children.
23078 * @type tinymce.html.Schema
23080 self.schema = new Schema(settings);
23083 * DOM instance for the editor.
23086 * @type tinymce.dom.DOMUtils
23088 * // Adds a class to all paragraphs within the editor
23089 * tinymce.activeEditor.dom.addClass(tinymce.activeEditor.dom.select('p'), 'someclass');
23091 self.dom = new DOMUtils(doc, {
23093 url_converter: self.convertURL,
23094 url_converter_scope: self,
23095 hex_colors: settings.force_hex_style_colors,
23096 class_filter: settings.class_filter,
23097 update_styles: true,
23098 root_element: settings.content_editable ? self.id : null,
23099 schema: self.schema,
23100 onSetAttrib: function(e) {
23101 self.fire('SetAttrib', e);
23106 * HTML parser will be used when contents is inserted into the editor.
23109 * @type tinymce.html.DomParser
23111 self.parser = new DomParser(settings, self.schema);
23113 // Convert src and href into data-mce-src, data-mce-href and data-mce-style
23114 self.parser.addAttributeFilter('src,href,style', function(nodes, name) {
23115 var i = nodes.length, node, dom = self.dom, value, internalName;
23119 value = node.attr(name);
23120 internalName = 'data-mce-' + name;
23122 // Add internal attribute if we need to we don't on a refresh of the document
23123 if (!node.attributes.map[internalName]) {
23124 if (name === "style") {
23125 node.attr(internalName, dom.serializeStyle(dom.parseStyle(value), node.name));
23127 node.attr(internalName, self.convertURL(value, name, node.name));
23133 // Keep scripts from executing
23134 self.parser.addNodeFilter('script', function(nodes) {
23135 var i = nodes.length, node;
23139 node.attr('type', 'mce-' + (node.attr('type') || 'text/javascript'));
23143 self.parser.addNodeFilter('#cdata', function(nodes) {
23144 var i = nodes.length, node;
23149 node.name = '#comment';
23150 node.value = '[CDATA[' + node.value + ']]';
23154 self.parser.addNodeFilter('p,h1,h2,h3,h4,h5,h6,div', function(nodes) {
23155 var i = nodes.length, node, nonEmptyElements = self.schema.getNonEmptyElements();
23160 if (node.isEmpty(nonEmptyElements)) {
23161 node.empty().append(new Node('br', 1)).shortEnded = true;
23167 * DOM serializer for the editor. Will be used when contents is extracted from the editor.
23169 * @property serializer
23170 * @type tinymce.dom.Serializer
23172 * // Serializes the first paragraph in the editor into a string
23173 * tinymce.activeEditor.serializer.serialize(tinymce.activeEditor.dom.select('p')[0]);
23175 self.serializer = new DomSerializer(settings, self);
23178 * Selection instance for the editor.
23180 * @property selection
23181 * @type tinymce.dom.Selection
23183 * // Sets some contents to the current selection in the editor
23184 * tinymce.activeEditor.selection.setContent('Some contents');
23186 * // Gets the current selection
23187 * alert(tinymce.activeEditor.selection.getContent());
23189 * // Selects the first paragraph found
23190 * tinymce.activeEditor.selection.select(tinymce.activeEditor.dom.select('p')[0]);
23192 self.selection = new Selection(self.dom, self.getWin(), self.serializer, self);
23195 * Formatter instance.
23197 * @property formatter
23198 * @type tinymce.Formatter
23200 self.formatter = new Formatter(self);
23203 * Undo manager instance, responsible for handling undo levels.
23205 * @property undoManager
23206 * @type tinymce.UndoManager
23208 * // Undoes the last modification to the editor
23209 * tinymce.activeEditor.undoManager.undo();
23211 self.undoManager = new UndoManager(self);
23213 self.forceBlocks = new ForceBlocks(self);
23214 self.enterKey = new EnterKey(self);
23215 self.editorCommands = new EditorCommands(self);
23217 self.fire('PreInit');
23219 if (!settings.browser_spellcheck && !settings.gecko_spellcheck) {
23220 doc.body.spellcheck = false; // Gecko
23221 DOM.setAttrib(body, "spellcheck", "false");
23224 self.fire('PostRender');
23226 self.quirks = Quirks(self);
23228 if (settings.directionality) {
23229 body.dir = settings.directionality;
23232 if (settings.nowrap) {
23233 body.style.whiteSpace = "nowrap";
23236 if (settings.protect) {
23237 self.on('BeforeSetContent', function(e) {
23238 each(settings.protect, function(pattern) {
23239 e.content = e.content.replace(pattern, function(str) {
23240 return '<!--mce:protected ' + escape(str) + '-->';
23246 self.on('SetContent', function() {
23247 self.addVisual(self.getBody());
23250 // Remove empty contents
23251 if (settings.padd_empty_editor) {
23252 self.on('PostProcess', function(e) {
23253 e.content = e.content.replace(/^(<p[^>]*>( | |\s|\u00a0|)<\/p>[\r\n]*|<br \/>[\r\n]*)$/, '');
23257 self.load({initial: true, format: 'html'});
23258 self.startContent = self.getContent({format: 'raw'});
23261 * Is set to true after the editor instance has been initialized
23263 * @property initialized
23266 * function isEditorInitialized(editor) {
23267 * return editor && editor.initialized;
23270 self.initialized = true;
23272 each(self._pendingNativeEvents, function(name) {
23273 self.dom.bind(getEventTarget(self, name), name, function(e) {
23274 self.fire(e.type, e);
23280 self.nodeChanged({initial: true});
23281 self.execCallback('init_instance_callback', self);
23283 // Add editor specific CSS styles
23284 if (self.contentStyles.length > 0) {
23285 contentCssText = '';
23287 each(self.contentStyles, function(style) {
23288 contentCssText += style + "\r\n";
23291 self.dom.addStyle(contentCssText);
23294 // Load specified content CSS last
23295 each(self.contentCSS, function(cssUrl) {
23296 if (!self.loadedCSS[cssUrl]) {
23297 self.dom.loadCSS(cssUrl);
23298 self.loadedCSS[cssUrl] = true;
23302 // Handle auto focus
23303 if (settings.auto_focus) {
23304 setTimeout(function () {
23305 var ed = self.editorManager.get(settings.auto_focus);
23307 ed.selection.select(ed.getBody(), 1);
23308 ed.selection.collapse(1);
23309 ed.getBody().focus();
23310 ed.getWin().focus();
23314 // Clean up references for IE
23315 targetElm = doc = body = null;
23319 * Focuses/activates the editor. This will set this editor as the activeEditor in the tinymce collection
23320 * it will also place DOM focus inside the editor.
23323 * @param {Boolean} skip_focus Skip DOM focus. Just set is as the active editor.
23325 focus: function(skip_focus) {
23326 var oed, self = this, selection = self.selection, contentEditable = self.settings.content_editable, rng;
23327 var controlElm, doc = self.getDoc(), body;
23330 // Get selected control element
23331 rng = selection.getRng();
23333 controlElm = rng.item(0);
23336 self._refreshContentEditable();
23338 // Focus the window iframe
23339 if (!contentEditable) {
23340 // WebKit needs this call to fire focusin event properly see #5948
23341 // But Opera pre Blink engine will produce an empty selection so skip Opera
23343 self.getBody().focus();
23346 self.getWin().focus();
23349 // Focus the body as well since it's contentEditable
23350 if (isGecko || contentEditable) {
23351 body = self.getBody();
23353 // Check for setActive since it doesn't scroll to the element
23354 if (body.setActive) {
23360 if (contentEditable) {
23361 selection.normalize();
23365 // Restore selected control element
23366 // This is needed when for example an image is selected within a
23367 // layer a call to focus will then remove the control selection
23368 if (controlElm && controlElm.ownerDocument == doc) {
23369 rng = doc.body.createControlRange();
23370 rng.addElement(controlElm);
23375 if (self.editorManager.activeEditor != self) {
23376 if ((oed = self.editorManager.activeEditor)) {
23377 oed.fire('deactivate', {relatedTarget: self});
23380 self.fire('activate', {relatedTarget: oed});
23383 self.editorManager.activeEditor = self;
23387 * Executes a legacy callback. This method is useful to call old 2.x option callbacks.
23388 * There new event model is a better way to add callback so this method might be removed in the future.
23390 * @method execCallback
23391 * @param {String} name Name of the callback to execute.
23392 * @return {Object} Return value passed from callback function.
23394 execCallback: function(name) {
23395 var self = this, callback = self.settings[name], scope;
23401 // Look through lookup
23402 if (self.callbackLookup && (scope = self.callbackLookup[name])) {
23403 callback = scope.func;
23404 scope = scope.scope;
23407 if (typeof(callback) === 'string') {
23408 scope = callback.replace(/\.\w+$/, '');
23409 scope = scope ? resolve(scope) : 0;
23410 callback = resolve(callback);
23411 self.callbackLookup = self.callbackLookup || {};
23412 self.callbackLookup[name] = {func: callback, scope: scope};
23415 return callback.apply(scope || self, Array.prototype.slice.call(arguments, 1));
23419 * Translates the specified string by replacing variables with language pack items it will also check if there is
23420 * a key mathcin the input.
23422 * @method translate
23423 * @param {String} text String to translate by the language pack data.
23424 * @return {String} Translated string.
23426 translate: function(text) {
23427 var lang = this.settings.language || 'en', i18n = this.editorManager.i18n;
23433 return i18n[lang + '.' + text] || text.replace(/\{\#([^\}]+)\}/g, function(a, b) {
23434 return i18n[lang + '.' + b] || '{#' + b + '}';
23439 * Returns a language pack item by name/key.
23442 * @param {String} name Name/key to get from the language pack.
23443 * @param {String} defaultVal Optional default value to retrive.
23445 getLang: function(name, defaultVal) {
23447 this.editorManager.i18n[(this.settings.language || 'en') + '.' + name] ||
23448 (defaultVal !== undefined ? defaultVal : '{#' + name + '}')
23453 * Returns a configuration parameter by name.
23456 * @param {String} name Configruation parameter to retrive.
23457 * @param {String} defaultVal Optional default value to return.
23458 * @param {String} type Optional type parameter.
23459 * @return {String} Configuration parameter value or default value.
23461 * // Returns a specific config value from the currently active editor
23462 * var someval = tinymce.activeEditor.getParam('myvalue');
23464 * // Returns a specific config value from a specific editor instance by id
23465 * var someval2 = tinymce.get('my_editor').getParam('myvalue');
23467 getParam: function(name, defaultVal, type) {
23468 var value = name in this.settings ? this.settings[name] : defaultVal, output;
23470 if (type === 'hash') {
23473 if (typeof(value) === 'string') {
23474 each(value.indexOf('=') > 0 ? value.split(/[;,](?![^=;,]*(?:[;,]|$))/) : value.split(','), function(value) {
23475 value = value.split('=');
23477 if (value.length > 1) {
23478 output[trim(value[0])] = trim(value[1]);
23480 output[trim(value[0])] = trim(value);
23494 * Distpaches out a onNodeChange event to all observers. This method should be called when you
23495 * need to update the UI states or element path etc.
23497 * @method nodeChanged
23499 nodeChanged: function() {
23500 var self = this, selection = self.selection, node, parents, root;
23502 // Fix for bug #1896577 it seems that this can not be fired while the editor is loading
23503 if (self.initialized && !self.settings.disable_nodechange) {
23505 root = self.getBody();
23506 node = selection.getStart() || root;
23507 node = ie && node.ownerDocument != self.getDoc() ? self.getBody() : node; // Fix for IE initial state
23509 // Edge case for <p>|<img></p>
23510 if (node.nodeName == 'IMG' && selection.isCollapsed()) {
23511 node = node.parentNode;
23514 // Get parents and add them to object
23516 self.dom.getParent(node, function(node) {
23517 if (node === root) {
23521 parents.push(node);
23524 self.fire('NodeChange', {element: node, parents: parents});
23529 * Adds a button that later gets created by the ControlManager. This is a shorter and easier method
23530 * of adding buttons without the need to deal with the ControlManager directly. But it's also less
23531 * powerfull if you need more control use the ControlManagers factory methods instead.
23533 * @method addButton
23534 * @param {String} name Button name to add.
23535 * @param {Object} settings Settings object with title, cmd etc.
23537 * // Adds a custom button to the editor that inserts contents when clicked
23541 * toolbar: 'example'
23543 * setup: function(ed) {
23544 * ed.addButton('example', {
23545 * title: 'My title',
23546 * image: '../js/tinymce/plugins/example/img/example.gif',
23547 * onclick: function() {
23548 * ed.insertContent('Hello world!!');
23554 addButton: function(name, settings) {
23557 if (settings.cmd) {
23558 settings.onclick = function() {
23559 self.execCommand(settings.cmd);
23563 if (!settings.text && !settings.icon) {
23564 settings.icon = name;
23567 self.buttons = self.buttons || {};
23568 settings.tooltip = settings.tooltip || settings.title;
23569 self.buttons[name] = settings;
23573 * Adds a menu item to be used in the menus of the modern theme.
23575 * @method addMenuItem
23576 * @param {String} name Menu item name to add.
23577 * @param {Object} settings Settings object with title, cmd etc.
23579 * // Adds a custom menu item to the editor that inserts contents when clicked
23580 * // The context option allows you to add the menu item to an existing default menu
23584 * setup: function(ed) {
23585 * ed.addMenuItem('example', {
23586 * title: 'My menu item',
23587 * context: 'tools',
23588 * onclick: function() {
23589 * ed.insertContent('Hello world!!');
23595 addMenuItem: function(name, settings) {
23598 if (settings.cmd) {
23599 settings.onclick = function() {
23600 self.execCommand(settings.cmd);
23604 self.menuItems = self.menuItems || {};
23605 self.menuItems[name] = settings;
23609 * Adds a custom command to the editor, you can also override existing commands with this method.
23610 * The command that you add can be executed with execCommand.
23612 * @method addCommand
23613 * @param {String} name Command name to add/override.
23614 * @param {addCommandCallback} callback Function to execute when the command occurs.
23615 * @param {Object} scope Optional scope to execute the function in.
23617 * // Adds a custom command that later can be executed using execCommand
23621 * setup: function(ed) {
23622 * // Register example command
23623 * ed.addCommand('mycommand', function(ui, v) {
23624 * ed.windowManager.alert('Hello world!! Selection: ' + ed.selection.getContent({format: 'text'}));
23629 addCommand: function(name, callback, scope) {
23631 * Callback function that gets called when a command is executed.
23633 * @callback addCommandCallback
23634 * @param {Boolean} ui Display UI state true/false.
23635 * @param {Object} value Optional value for command.
23636 * @return {Boolean} True/false state if the command was handled or not.
23638 this.execCommands[name] = {func: callback, scope: scope || this};
23642 * Adds a custom query state command to the editor, you can also override existing commands with this method.
23643 * The command that you add can be executed with queryCommandState function.
23645 * @method addQueryStateHandler
23646 * @param {String} name Command name to add/override.
23647 * @param {addQueryStateHandlerCallback} callback Function to execute when the command state retrival occurs.
23648 * @param {Object} scope Optional scope to execute the function in.
23650 addQueryStateHandler: function(name, callback, scope) {
23652 * Callback function that gets called when a queryCommandState is executed.
23654 * @callback addQueryStateHandlerCallback
23655 * @return {Boolean} True/false state if the command is enabled or not like is it bold.
23657 this.queryStateCommands[name] = {func: callback, scope: scope || this};
23661 * Adds a custom query value command to the editor, you can also override existing commands with this method.
23662 * The command that you add can be executed with queryCommandValue function.
23664 * @method addQueryValueHandler
23665 * @param {String} name Command name to add/override.
23666 * @param {addQueryValueHandlerCallback} callback Function to execute when the command value retrival occurs.
23667 * @param {Object} scope Optional scope to execute the function in.
23669 addQueryValueHandler: function(name, callback, scope) {
23671 * Callback function that gets called when a queryCommandValue is executed.
23673 * @callback addQueryValueHandlerCallback
23674 * @return {Object} Value of the command or undefined.
23676 this.queryValueCommands[name] = {func: callback, scope: scope || this};
23680 * Adds a keyboard shortcut for some command or function.
23682 * @method addShortcut
23683 * @param {String} pattern Shortcut pattern. Like for example: ctrl+alt+o.
23684 * @param {String} desc Text description for the command.
23685 * @param {String/Function} cmdFunc Command name string or function to execute when the key is pressed.
23686 * @param {Object} sc Optional scope to execute the function in.
23687 * @return {Boolean} true/false state if the shortcut was added or not.
23689 addShortcut: function(pattern, desc, cmdFunc, scope) {
23690 this.shortcuts.add(pattern, desc, cmdFunc, scope);
23694 * Executes a command on the current instance. These commands can be TinyMCE internal commands prefixed with "mce" or
23695 * they can be build in browser commands such as "Bold". A compleate list of browser commands is available on MSDN or Mozilla.org.
23696 * This function will dispatch the execCommand function on each plugin, theme or the execcommand_callback option if none of these
23697 * return true it will handle the command as a internal browser command.
23699 * @method execCommand
23700 * @param {String} cmd Command name to execute, for example mceLink or Bold.
23701 * @param {Boolean} ui True/false state if a UI (dialog) should be presented or not.
23702 * @param {mixed} value Optional command value, this can be anything.
23703 * @param {Object} a Optional arguments object.
23705 execCommand: function(cmd, ui, value, args) {
23706 var self = this, state = 0, cmdItem;
23708 if (!/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(cmd) && (!args || !args.skip_focus)) {
23712 args = extend({}, args);
23713 args = self.fire('BeforeExecCommand', {command: cmd, ui: ui, value: value});
23714 if (args.isDefaultPrevented()) {
23718 // Registred commands
23719 if ((cmdItem = self.execCommands[cmd])) {
23720 // Fall through on true
23721 if (cmdItem.func.call(cmdItem.scope, ui, value) !== true) {
23722 self.fire('ExecCommand', {command: cmd, ui: ui, value: value});
23728 each(self.plugins, function(p) {
23729 if (p.execCommand && p.execCommand(cmd, ui, value)) {
23730 self.fire('ExecCommand', {command: cmd, ui: ui, value: value});
23741 if (self.theme && self.theme.execCommand && self.theme.execCommand(cmd, ui, value)) {
23742 self.fire('ExecCommand', {command: cmd, ui: ui, value: value});
23747 if (self.editorCommands.execCommand(cmd, ui, value)) {
23748 self.fire('ExecCommand', {command: cmd, ui: ui, value: value});
23752 // Browser commands
23753 self.getDoc().execCommand(cmd, ui, value);
23754 self.fire('ExecCommand', {command: cmd, ui: ui, value: value});
23758 * Returns a command specific state, for example if bold is enabled or not.
23760 * @method queryCommandState
23761 * @param {string} cmd Command to query state from.
23762 * @return {Boolean} Command specific state, for example if bold is enabled or not.
23764 queryCommandState: function(cmd) {
23765 var self = this, queryItem, returnVal;
23767 // Is hidden then return undefined
23768 if (self._isHidden()) {
23772 // Registred commands
23773 if ((queryItem = self.queryStateCommands[cmd])) {
23774 returnVal = queryItem.func.call(queryItem.scope);
23776 // Fall though on true
23777 if (returnVal !== true) {
23783 returnVal = self.editorCommands.queryCommandState(cmd);
23784 if (returnVal !== -1) {
23788 // Browser commands
23790 return self.getDoc().queryCommandState(cmd);
23792 // Fails sometimes see bug: 1896577
23797 * Returns a command specific value, for example the current font size.
23799 * @method queryCommandValue
23800 * @param {string} cmd Command to query value from.
23801 * @return {Object} Command specific value, for example the current font size.
23803 queryCommandValue: function(cmd) {
23804 var self = this, queryItem, returnVal;
23806 // Is hidden then return undefined
23807 if (self._isHidden()) {
23811 // Registred commands
23812 if ((queryItem = self.queryValueCommands[cmd])) {
23813 returnVal = queryItem.func.call(queryItem.scope);
23815 // Fall though on true
23816 if (returnVal !== true) {
23822 returnVal = self.editorCommands.queryCommandValue(cmd);
23823 if (returnVal !== undefined) {
23827 // Browser commands
23829 return self.getDoc().queryCommandValue(cmd);
23831 // Fails sometimes see bug: 1896577
23836 * Shows the editor and hides any textarea/div that the editor is supposed to replace.
23843 DOM.show(self.getContainer());
23850 * Hides the editor and shows any textarea/div that the editor is supposed to replace.
23855 var self = this, doc = self.getDoc();
23857 // Fixed bug where IE has a blinking cursor left from the editor
23859 doc.execCommand('SelectAll');
23862 // We must save before we hide so Safari doesn't crash
23865 // defer the call to hide to prevent an IE9 crash #4921
23866 DOM.hide(self.getContainer());
23867 DOM.setStyle(self.id, 'display', self.orgDisplay);
23872 * Returns true/false if the editor is hidden or not.
23875 * @return {Boolean} True/false if the editor is hidden or not.
23877 isHidden: function() {
23878 return !DOM.isHidden(this.id);
23882 * Sets the progress state, this will display a throbber/progess for the editor.
23883 * This is ideal for asycronous operations like an AJAX save call.
23885 * @method setProgressState
23886 * @param {Boolean} state Boolean state if the progress should be shown or hidden.
23887 * @param {Number} time Optional time to wait before the progress gets shown.
23888 * @return {Boolean} Same as the input state.
23890 * // Show progress for the active editor
23891 * tinymce.activeEditor.setProgressState(true);
23893 * // Hide progress for the active editor
23894 * tinymce.activeEditor.setProgressState(false);
23896 * // Show progress after 3 seconds
23897 * tinymce.activeEditor.setProgressState(true, 3000);
23899 setProgressState: function(state, time) {
23900 this.fire('ProgressState', {state: state, time: time});
23904 * Loads contents from the textarea or div element that got converted into an editor instance.
23905 * This method will move the contents from that textarea or div into the editor by using setContent
23906 * so all events etc that method has will get dispatched as well.
23909 * @param {Object} args Optional content object, this gets passed around through the whole load process.
23910 * @return {String} HTML string that got set into the editor.
23912 load: function(args) {
23913 var self = this, elm = self.getElement(), html;
23919 html = self.setContent(elm.value !== undefined ? elm.value : elm.innerHTML, args);
23920 args.element = elm;
23922 if (!args.no_events) {
23923 self.fire('LoadContent', args);
23926 args.element = elm = null;
23933 * Saves the contents from a editor out to the textarea or div element that got converted into an editor instance.
23934 * This method will move the HTML contents from the editor into that textarea or div by getContent
23935 * so all events etc that method has will get dispatched as well.
23938 * @param {Object} args Optional content object, this gets passed around through the whole save process.
23939 * @return {String} HTML string that got set into the textarea/div.
23941 save: function(args) {
23942 var self = this, elm = self.getElement(), html, form;
23944 if (!elm || !self.initialized) {
23951 args.element = elm;
23952 html = args.content = self.getContent(args);
23954 if (!args.no_events) {
23955 self.fire('SaveContent', args);
23958 html = args.content;
23960 if (!/TEXTAREA|INPUT/i.test(elm.nodeName)) {
23961 elm.innerHTML = html;
23963 // Update hidden form element
23964 if ((form = DOM.getParent(self.id, 'form'))) {
23965 each(form.elements, function(elm) {
23966 if (elm.name == self.id) {
23976 args.element = elm = null;
23978 if (args.set_dirty !== false) {
23979 self.isNotDirty = true;
23986 * Sets the specified content to the editor instance, this will cleanup the content before it gets set using
23987 * the different cleanup rules options.
23989 * @method setContent
23990 * @param {String} content Content to set to editor, normally HTML contents but can be other formats as well.
23991 * @param {Object} args Optional content object, this gets passed around through the whole set process.
23992 * @return {String} HTML string that got set into the editor.
23994 * // Sets the HTML contents of the activeEditor editor
23995 * tinymce.activeEditor.setContent('<span>some</span> html');
23997 * // Sets the raw contents of the activeEditor editor
23998 * tinymce.activeEditor.setContent('<span>some</span> html', {format: 'raw'});
24000 * // Sets the content of a specific editor (my_editor in this example)
24001 * tinymce.get('my_editor').setContent(data);
24003 * // Sets the bbcode contents of the activeEditor editor if the bbcode plugin was added
24004 * tinymce.activeEditor.setContent('[b]some[/b] html', {format: 'bbcode'});
24006 setContent: function(content, args) {
24007 var self = this, body = self.getBody(), forcedRootBlockName;
24009 // Setup args object
24011 args.format = args.format || 'html';
24013 args.content = content;
24015 // Do preprocessing
24016 if (!args.no_events) {
24017 self.fire('BeforeSetContent', args);
24020 content = args.content;
24022 // Padd empty content in Gecko and Safari. Commands will otherwise fail on the content
24023 // It will also be impossible to place the caret in the editor unless there is a BR element present
24024 if (content.length === 0 || /^\s+$/.test(content)) {
24025 forcedRootBlockName = self.settings.forced_root_block;
24027 // Check if forcedRootBlock is configured and that the block is a valid child of the body
24028 if (forcedRootBlockName && self.schema.isValidChild(body.nodeName.toLowerCase(), forcedRootBlockName.toLowerCase())) {
24029 if (ie && ie < 11) {
24030 // IE renders BR elements in blocks so lets just add an empty block
24031 content = '<' + forcedRootBlockName + '></' + forcedRootBlockName + '>';
24033 content = '<' + forcedRootBlockName + '><br data-mce-bogus="1"></' + forcedRootBlockName + '>';
24036 // We need to add a BR when forced_root_block is disabled on non IE browsers to place the caret
24037 content = '<br data-mce-bogus="1">';
24040 body.innerHTML = content;
24042 self.fire('SetContent', args);
24044 // Parse and serialize the html
24045 if (args.format !== 'raw') {
24046 content = new Serializer({}, self.schema).serialize(
24047 self.parser.parse(content, {isRootContent: true})
24051 // Set the new cleaned contents to the editor
24052 args.content = trim(content);
24053 self.dom.setHTML(body, args.content);
24055 // Do post processing
24056 if (!args.no_events) {
24057 self.fire('SetContent', args);
24060 // Don't normalize selection if the focused element isn't the body in
24061 // content editable mode since it will steal focus otherwise
24062 /*if (!self.settings.content_editable || document.activeElement === self.getBody()) {
24063 self.selection.normalize();
24067 // Move selection to start of body if it's a after init setContent call
24068 // This prevents IE 7/8 from moving focus to empty editors
24069 if (!args.initial) {
24070 self.selection.select(body, true);
24071 self.selection.collapse(true);
24074 return args.content;
24078 * Gets the content from the editor instance, this will cleanup the content before it gets returned using
24079 * the different cleanup rules options.
24081 * @method getContent
24082 * @param {Object} args Optional content object, this gets passed around through the whole get process.
24083 * @return {String} Cleaned content string, normally HTML contents.
24085 * // Get the HTML contents of the currently active editor
24086 * console.debug(tinymce.activeEditor.getContent());
24088 * // Get the raw contents of the currently active editor
24089 * tinymce.activeEditor.getContent({format: 'raw'});
24091 * // Get content of a specific editor:
24092 * tinymce.get('content id').getContent()
24094 getContent: function(args) {
24095 var self = this, content, body = self.getBody();
24097 // Setup args object
24099 args.format = args.format || 'html';
24101 args.getInner = true;
24103 // Do preprocessing
24104 if (!args.no_events) {
24105 self.fire('BeforeGetContent', args);
24108 // Get raw contents or by default the cleaned contents
24109 if (args.format == 'raw') {
24110 content = body.innerHTML;
24111 } else if (args.format == 'text') {
24112 content = body.innerText || body.textContent;
24114 content = self.serializer.serialize(body, args);
24117 // Trim whitespace in beginning/end of HTML
24118 if (args.format != 'text') {
24119 args.content = trim(content);
24121 args.content = content;
24124 // Do post processing
24125 if (!args.no_events) {
24126 self.fire('GetContent', args);
24129 return args.content;
24133 * Inserts content at caret position.
24135 * @method insertContent
24136 * @param {String} content Content to insert.
24138 insertContent: function(content) {
24139 this.execCommand('mceInsertContent', false, content);
24143 * Returns true/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents.
24146 * @return {Boolean} True/false if the editor is dirty or not. It will get dirty if the user has made modifications to the contents.
24148 * if (tinymce.activeEditor.isDirty())
24149 * alert("You must save your contents.");
24151 isDirty: function() {
24152 return !this.isNotDirty;
24156 * Returns the editors container element. The container element wrappes in
24157 * all the elements added to the page for the editor. Such as UI, iframe etc.
24159 * @method getContainer
24160 * @return {Element} HTML DOM element for the editor container.
24162 getContainer: function() {
24165 if (!self.container) {
24166 self.container = DOM.get(self.editorContainer || self.id + '_parent');
24169 return self.container;
24173 * Returns the editors content area container element. The this element is the one who
24174 * holds the iframe or the editable element.
24176 * @method getContentAreaContainer
24177 * @return {Element} HTML DOM element for the editor area container.
24179 getContentAreaContainer: function() {
24180 return this.contentAreaContainer;
24184 * Returns the target element/textarea that got replaced with a TinyMCE editor instance.
24186 * @method getElement
24187 * @return {Element} HTML DOM element for the replaced element.
24189 getElement: function() {
24190 return DOM.get(this.settings.content_element || this.id);
24194 * Returns the iframes window object.
24197 * @return {Window} Iframe DOM window object.
24199 getWin: function() {
24200 var self = this, elm;
24202 if (!self.contentWindow) {
24203 elm = DOM.get(self.id + "_ifr");
24206 self.contentWindow = elm.contentWindow;
24210 return self.contentWindow;
24214 * Returns the iframes document object.
24217 * @return {Document} Iframe DOM document object.
24219 getDoc: function() {
24220 var self = this, win;
24222 if (!self.contentDocument) {
24223 win = self.getWin();
24226 self.contentDocument = win.document;
24230 return self.contentDocument;
24234 * Returns the iframes body element.
24237 * @return {Element} Iframe body element.
24239 getBody: function() {
24240 return this.bodyElement || this.getDoc().body;
24244 * URL converter function this gets executed each time a user adds an img, a or
24245 * any other element that has a URL in it. This will be called both by the DOM and HTML
24246 * manipulation functions.
24248 * @method convertURL
24249 * @param {string} url URL to convert.
24250 * @param {string} name Attribute name src, href etc.
24251 * @param {string/HTMLElement} elm Tag name or HTML DOM element depending on HTML or DOM insert.
24252 * @return {string} Converted URL string.
24254 convertURL: function(url, name, elm) {
24255 var self = this, settings = self.settings;
24257 // Use callback instead
24258 if (settings.urlconverter_callback) {
24259 return self.execCallback('urlconverter_callback', url, elm, true, name);
24262 // Don't convert link href since thats the CSS files that gets loaded into the editor also skip local file URLs
24263 if (!settings.convert_urls || (elm && elm.nodeName == 'LINK') || url.indexOf('file:') === 0 || url.length === 0) {
24267 // Convert to relative
24268 if (settings.relative_urls) {
24269 return self.documentBaseURI.toRelative(url);
24272 // Convert to absolute
24273 url = self.documentBaseURI.toAbsolute(url, settings.remove_script_host);
24279 * Adds visual aid for tables, anchors etc so they can be more easily edited inside the editor.
24281 * @method addVisual
24282 * @param {Element} elm Optional root element to loop though to find tables etc that needs the visual aid.
24284 addVisual: function(elm) {
24285 var self = this, settings = self.settings, dom = self.dom, cls;
24287 elm = elm || self.getBody();
24289 if (self.hasVisual === undefined) {
24290 self.hasVisual = settings.visual;
24293 each(dom.select('table,a', elm), function(elm) {
24296 switch (elm.nodeName) {
24298 cls = settings.visual_table_class || 'mce-item-table';
24299 value = dom.getAttrib(elm, 'border');
24301 if (!value || value == '0') {
24302 if (self.hasVisual) {
24303 dom.addClass(elm, cls);
24305 dom.removeClass(elm, cls);
24312 if (!dom.getAttrib(elm, 'href', false)) {
24313 value = dom.getAttrib(elm, 'name') || elm.id;
24314 cls = 'mce-item-anchor';
24317 if (self.hasVisual) {
24318 dom.addClass(elm, cls);
24320 dom.removeClass(elm, cls);
24329 self.fire('VisualAid', {element: elm, hasVisual: self.hasVisual});
24333 * Removes the editor from the dom and tinymce collection.
24337 remove: function() {
24338 var self = this, elm = self.getContainer(), doc = self.getDoc();
24340 if (!self.removed) {
24341 self.removed = 1; // Cancels post remove event execution
24343 // Fixed bug where IE has a blinking cursor left from the editor
24345 doc.execCommand('SelectAll');
24348 // We must save before we hide so Safari doesn't crash
24351 DOM.setStyle(self.id, 'display', self.orgDisplay);
24353 // Don't clear the window or document if content editable
24354 // is enabled since other instances might still be present
24355 if (!self.settings.content_editable) {
24356 Event.unbind(self.getWin());
24357 Event.unbind(self.getDoc());
24360 Event.unbind(self.getBody());
24363 self.fire('remove');
24365 self.editorManager.remove(self);
24370 bindNative: function(name) {
24373 if (self.initialized) {
24374 self.dom.bind(getEventTarget(self, name), name, function(e) {
24375 self.fire(name, e);
24378 if (!self._pendingNativeEvents) {
24379 self._pendingNativeEvents = [name];
24381 self._pendingNativeEvents.push(name);
24386 unbindNative: function(name) {
24389 if (self.initialized) {
24390 self.dom.unbind(name);
24395 * Destroys the editor instance by removing all events, element references or other resources
24396 * that could leak memory. This method will be called automatically when the page is unloaded
24397 * but you can also call it directly if you know what you are doing.
24400 * @param {Boolean} automatic Optional state if the destroy is an automatic destroy or user called one.
24402 destroy: function(automatic) {
24403 var self = this, form;
24405 // One time is enough
24406 if (self.destroyed) {
24410 // We must unbind on Gecko since it would otherwise produce the pesky "attempt
24411 // to run compile-and-go script on a cleared scope" message
24413 Event.unbind(self.getDoc());
24414 Event.unbind(self.getWin());
24415 Event.unbind(self.getBody());
24419 self.editorManager.off('beforeunload', self._beforeUnload);
24422 if (self.theme && self.theme.destroy) {
24423 self.theme.destroy();
24426 // Destroy controls, selection and dom
24427 self.selection.destroy();
24428 self.dom.destroy();
24431 form = self.formElement;
24433 form.submit = form._mceOldSubmit;
24434 form._mceOldSubmit = null;
24435 DOM.unbind(form, 'submit reset', self.formEventDelegate);
24438 self.contentAreaContainer = self.formElement = self.container = null;
24439 self.settings.content_element = self.bodyElement = self.contentDocument = self.contentWindow = null;
24441 if (self.selection) {
24442 self.selection = self.selection.win = self.selection.dom = self.selection.dom.doc = null;
24445 self.destroyed = 1;
24448 // Internal functions
24450 _refreshContentEditable: function() {
24451 var self = this, body, parent;
24453 // Check if the editor was hidden and the re-initalize contentEditable mode by removing and adding the body again
24454 if (self._isHidden()) {
24455 body = self.getBody();
24456 parent = body.parentNode;
24458 parent.removeChild(body);
24459 parent.appendChild(body);
24465 _isHidden: function() {
24472 // Weird, wheres that cursor selection?
24473 sel = this.selection.getSel();
24474 return (!sel || !sel.rangeCount || sel.rangeCount === 0);
24478 extend(Editor.prototype, Observable);
24483 // Included from: js/tinymce/classes/util/I18n.js
24488 * Copyright, Moxiecode Systems AB
24489 * Released under LGPL License.
24491 * License: http://www.tinymce.com/license
24492 * Contributing: http://www.tinymce.com/contributing
24496 * I18n class that handles translation of TinyMCE UI.
24497 * Uses po style with csharp style parameters.
24499 * @class tinymce.util.I18n
24501 define("tinymce/util/I18n", [], function() {
24508 * Adds translations for a specific language code.
24511 * @param {String} code Language code like sv_SE.
24512 * @param {Array} items Name/value array with English en_US to sv_SE.
24514 add: function(code, items) {
24515 for (var name in items) {
24516 data[name] = items[name];
24521 * Translates the specified text.
24523 * It has a few formats:
24524 * I18n.translate("Text");
24525 * I18n.translate(["Text {0}/{1}", 0, 1]);
24526 * I18n.translate({raw: "Raw string"});
24528 * @method translate
24529 * @param {String/Object/Array} text Text to translate.
24530 * @return {String} String that got translated.
24532 translate: function(text) {
24533 if (typeof(text) == "undefined") {
24537 if (typeof(text) != "string" && text.raw) {
24542 var values = text.slice(1);
24544 text = (data[text[0]] || text[0]).replace(/\{([^\}]+)\}/g, function(match1, match2) {
24545 return values[match2];
24549 return data[text] || text;
24556 // Included from: js/tinymce/classes/FocusManager.js
24561 * Copyright, Moxiecode Systems AB
24562 * Released under LGPL License.
24564 * License: http://www.tinymce.com/license
24565 * Contributing: http://www.tinymce.com/contributing
24569 * This class manages the focus/blur state of the editor. This class is needed since some
24570 * browsers fire false focus/blur states when the selection is moved to a UI dialog or similar.
24572 * This class will fire two events focus and blur on the editor instances that got affected.
24573 * It will also handle the restore of selection when the focus is lost and returned.
24575 * @class tinymce.FocusManager
24577 define("tinymce/FocusManager", [
24578 "tinymce/dom/DOMUtils",
24580 ], function(DOMUtils, Env) {
24582 * Constructs a new focus manager instance.
24584 * @constructor FocusManager
24585 * @param {tinymce.EditorManager} editorManager Editor manager instance to handle focus for.
24587 function FocusManager(editorManager) {
24588 function getActiveElement() {
24590 return document.activeElement;
24592 // IE sometimes fails to get the activeElement when resizing table
24593 // TODO: Investigate this
24594 return document.body;
24598 // We can't store a real range on IE 11 since it gets mutated so we need to use a bookmark object
24599 // TODO: Move this to a separate range utils class since it's it's logic is present in Selection as well.
24600 function createBookmark(rng) {
24601 if (rng && rng.startContainer) {
24603 startContainer: rng.startContainer,
24604 startOffset: rng.startOffset,
24605 endContainer: rng.endContainer,
24606 endOffset: rng.endOffset
24613 function bookmarkToRng(editor, bookmark) {
24616 if (bookmark.startContainer) {
24617 rng = editor.getDoc().createRange();
24618 rng.setStart(bookmark.startContainer, bookmark.startOffset);
24619 rng.setEnd(bookmark.endContainer, bookmark.endOffset);
24627 function registerEvents(e) {
24628 var editor = e.editor, lastRng, selectionChangeHandler;
24630 function isUIElement(elm) {
24631 return !!DOMUtils.DOM.getParent(elm, FocusManager.isEditorUIElement);
24634 editor.on('init', function() {
24635 // On IE take selection snapshot onbeforedeactivate
24636 if ("onbeforedeactivate" in document && Env.ie < 11) {
24637 editor.dom.bind(editor.getBody(), 'beforedeactivate', function() {
24638 var ieSelection = editor.getDoc().selection;
24641 lastRng = ieSelection && ieSelection.createRange ? ieSelection.createRange() : editor.selection.getRng();
24643 // IE throws "Unexcpected call to method or property access" some times so lets ignore it
24646 } else if (editor.inline || Env.ie > 10) {
24647 // On other browsers take snapshot on nodechange in inline mode since they have Ghost selections for iframes
24648 editor.on('nodechange keyup', function() {
24649 var isInBody, node = document.activeElement;
24651 // IE 11 reports active element as iframe not body of iframe
24652 if (node && node.id == editor.id + '_ifr') {
24653 node = editor.getBody();
24656 // Check if selection is within editor body
24658 if (node == editor.getBody()) {
24663 node = node.parentNode;
24667 lastRng = editor.selection.getRng();
24671 // Handles the issue with WebKit not retaining selection within inline document
24672 // If the user releases the mouse out side the body while selecting a nodeChange won't
24673 // fire and there for the selection snapshot won't be stored
24674 // TODO: Optimize this since we only need to bind these on the active editor
24676 selectionChangeHandler = function() {
24677 var rng = editor.selection.getRng();
24679 // Store when it's non collapsed
24680 if (!rng.collapsed) {
24685 // Bind selection handler
24686 DOMUtils.DOM.bind(document, 'selectionchange', selectionChangeHandler);
24688 editor.on('remove', function() {
24689 DOMUtils.DOM.unbind(document, 'selectionchange', selectionChangeHandler);
24695 editor.on('focusin', function() {
24696 var focusedEditor = editorManager.focusedEditor;
24698 if (editor.selection.lastFocusBookmark) {
24699 editor.selection.setRng(bookmarkToRng(editor, editor.selection.lastFocusBookmark));
24700 editor.selection.lastFocusBookmark = null;
24703 if (focusedEditor != editor) {
24704 if (focusedEditor) {
24705 focusedEditor.fire('blur', {focusedEditor: editor});
24708 editorManager.activeEditor = editor;
24709 editor.fire('focus', {blurredEditor: focusedEditor});
24710 editor.focus(false);
24711 editorManager.focusedEditor = editor;
24715 editor.on('focusout', function() {
24716 editor.selection.lastFocusBookmark = createBookmark(lastRng);
24718 window.setTimeout(function() {
24719 var focusedEditor = editorManager.focusedEditor;
24721 // Focus from editorA into editorB then don't restore selection
24722 if (focusedEditor != editor) {
24723 editor.selection.lastFocusBookmark = null;
24726 // Still the same editor the the blur was outside any editor UI
24727 if (!isUIElement(getActiveElement()) && focusedEditor == editor) {
24728 editor.fire('blur', {focusedEditor: null});
24729 editorManager.focusedEditor = null;
24730 editor.selection.lastFocusBookmark = null;
24736 editorManager.on('AddEditor', registerEvents);
24740 * Returns true if the specified element is part of the UI for example an button or text input.
24742 * @method isEditorUIElement
24743 * @param {Element} elm Element to check if it's part of the UI or not.
24744 * @return {Boolean} True/false state if the element is part of the UI or not.
24746 FocusManager.isEditorUIElement = function(elm) {
24747 return elm.className.indexOf('mce-') !== -1;
24750 return FocusManager;
24753 // Included from: js/tinymce/classes/EditorManager.js
24758 * Copyright, Moxiecode Systems AB
24759 * Released under LGPL License.
24761 * License: http://www.tinymce.com/license
24762 * Contributing: http://www.tinymce.com/contributing
24766 * This class used as a factory for manager for tinymce.Editor instances.
24769 * tinymce.EditorManager.init({});
24771 * @class tinymce.EditorManager
24772 * @mixes tinymce.util.Observable
24775 define("tinymce/EditorManager", [
24777 "tinymce/dom/DOMUtils",
24778 "tinymce/util/URI",
24780 "tinymce/util/Tools",
24781 "tinymce/util/Observable",
24782 "tinymce/util/I18n",
24783 "tinymce/FocusManager"
24784 ], function(Editor, DOMUtils, URI, Env, Tools, Observable, I18n, FocusManager) {
24785 var DOM = DOMUtils.DOM;
24786 var explode = Tools.explode, each = Tools.each, extend = Tools.extend;
24787 var instanceCounter = 0, beforeUnloadDelegate;
24789 var EditorManager = {
24791 * Major version of TinyMCE build.
24793 * @property majorVersion
24796 majorVersion : '4',
24799 * Minor version of TinyMCE build.
24801 * @property minorVersion
24804 minorVersion : '0.5',
24807 * Release date of TinyMCE build.
24809 * @property releaseDate
24812 releaseDate: '2013-08-27',
24815 * Collection of editor instances.
24817 * @property editors
24820 * for (edId in tinymce.editors)
24821 * tinymce.editors[edId].save();
24826 * Collection of language pack data.
24834 * Currently active editor instance.
24836 * @property activeEditor
24837 * @type tinymce.Editor
24839 * tinyMCE.activeEditor.selection.getContent();
24840 * tinymce.EditorManager.activeEditor.selection.getContent();
24842 activeEditor: null,
24844 setup: function() {
24845 var self = this, baseURL, documentBaseURL, suffix = "", preInit;
24847 // Get base URL for the current document
24848 documentBaseURL = document.location.href.replace(/[\?#].*$/, '').replace(/[\/\\][^\/]+$/, '');
24849 if (!/[\/\\]$/.test(documentBaseURL)) {
24850 documentBaseURL += '/';
24853 // If tinymce is defined and has a base use that or use the old tinyMCEPreInit
24854 preInit = window.tinymce || window.tinyMCEPreInit;
24856 baseURL = preInit.base || preInit.baseURL;
24857 suffix = preInit.suffix;
24859 // Get base where the tinymce script is located
24860 var scripts = document.getElementsByTagName('script');
24861 for (var i = 0; i < scripts.length; i++) {
24862 var src = scripts[i].src;
24864 if (/tinymce(\.jquery|)(\.min|\.dev|)\.js/.test(src)) {
24865 if (src.indexOf('.min') != -1) {
24869 baseURL = src.substring(0, src.lastIndexOf('/'));
24876 * Base URL where the root directory if TinyMCE is located.
24878 * @property baseURL
24881 self.baseURL = new URI(documentBaseURL).toAbsolute(baseURL);
24884 * Document base URL where the current document is located.
24886 * @property documentBaseURL
24889 self.documentBaseURL = documentBaseURL;
24892 * Absolute baseURI for the installation path of TinyMCE.
24894 * @property baseURI
24895 * @type tinymce.util.URI
24897 self.baseURI = new URI(self.baseURL);
24900 * Current suffix to add to each plugin/theme that gets loaded for example ".min".
24905 self.suffix = suffix;
24907 self.focusManager = new FocusManager(self);
24911 * Initializes a set of editors. This method will create editors based on various settings.
24914 * @param {Object} settings Settings object to be passed to each editor instance.
24916 * // Initializes a editor using the longer method
24917 * tinymce.EditorManager.init({
24918 * some_settings : 'some value'
24921 * // Initializes a editor instance using the shorter version
24923 * some_settings : 'some value'
24926 init: function(settings) {
24927 var self = this, editors = [], editor;
24929 function createId(elm) {
24932 // Use element id, or unique name or generate a unique id
24936 if (id && !DOM.get(id)) {
24939 // Generate unique name
24940 id = DOM.uniqueId();
24943 elm.setAttribute('id', id);
24949 function execCallback(se, n, s) {
24956 return f.apply(s || this, Array.prototype.slice.call(arguments, 2));
24959 function hasClass(n, c) {
24960 return c.constructor === RegExp ? c.test(n.className) : DOM.hasClass(n, c);
24963 self.settings = settings;
24965 DOM.bind(window, 'ready', function() {
24968 execCallback(settings, 'onpageload');
24970 if (settings.types) {
24971 // Process type specific selector
24972 each(settings.types, function(type) {
24973 each(DOM.select(type.selector), function(elm) {
24974 var editor = new Editor(createId(elm), extend({}, settings, type), self);
24975 editors.push(editor);
24981 } else if (settings.selector) {
24982 // Process global selector
24983 each(DOM.select(settings.selector), function(elm) {
24984 var editor = new Editor(createId(elm), settings, self);
24985 editors.push(editor);
24992 // Fallback to old setting
24993 switch (settings.mode) {
24995 l = settings.elements || '';
24998 each(explode(l), function(v) {
25000 editor = new Editor(v, settings, self);
25001 editors.push(editor);
25002 editor.render(true);
25004 each(document.forms, function(f) {
25005 each(f.elements, function(e) {
25006 if (e.name === v) {
25007 v = 'mce_editor_' + instanceCounter++;
25008 DOM.setAttrib(e, 'id', v);
25010 editor = new Editor(v, settings, self);
25011 editors.push(editor);
25022 case "specific_textareas":
25023 each(DOM.select('textarea'), function(elm) {
25024 if (settings.editor_deselector && hasClass(elm, settings.editor_deselector)) {
25028 if (!settings.editor_selector || hasClass(elm, settings.editor_selector)) {
25029 editor = new Editor(createId(elm), settings, self);
25030 editors.push(editor);
25031 editor.render(true);
25037 // Call onInit when all editors are initialized
25038 if (settings.oninit) {
25041 each(editors, function(ed) {
25044 if (!ed.initialized) {
25046 ed.on('init', function() {
25051 execCallback(settings, 'oninit');
25060 execCallback(settings, 'oninit');
25068 * Returns a editor instance by id.
25071 * @param {String/Number} id Editor instance id or index to return.
25072 * @return {tinymce.Editor} Editor instance to return.
25074 * // Adds an onclick event to an editor by id (shorter version)
25075 * tinymce.get('mytextbox').on('click', function(e) {
25076 * ed.windowManager.alert('Hello world!');
25079 * // Adds an onclick event to an editor by id (longer version)
25080 * tinymce.EditorManager.get('mytextbox').on('click', function(e) {
25081 * ed.windowManager.alert('Hello world!');
25084 get: function(id) {
25085 if (id === undefined) {
25086 return this.editors;
25089 return this.editors[id];
25093 * Adds an editor instance to the editor collection. This will also set it as the active editor.
25096 * @param {tinymce.Editor} editor Editor instance to add to the collection.
25097 * @return {tinymce.Editor} The same instance that got passed in.
25099 add: function(editor) {
25100 var self = this, editors = self.editors;
25102 // Add named and index editor instance
25103 editors[editor.id] = editor;
25104 editors.push(editor);
25106 self.activeEditor = editor;
25109 * Fires when an editor is added to the EditorManager collection.
25112 * @param {Object} e Event arguments.
25114 self.fire('AddEditor', {editor: editor});
25116 if (!beforeUnloadDelegate) {
25117 beforeUnloadDelegate = function() {
25118 self.fire('BeforeUnload');
25121 DOM.bind(window, 'beforeunload', beforeUnloadDelegate);
25128 * Creates an editor instance and adds it to the EditorManager collection.
25130 * @method createEditor
25131 * @param {String} id Instance id to use for editor.
25132 * @param {Object} settings Editor instance settings.
25133 * @return {tinymce.Editor} Editor instance that got created.
25135 createEditor: function(id, settings) {
25136 return this.add(new Editor(id, settings, this));
25140 * Removes a editor or editors form page.
25143 * // Remove all editors bound to divs
25144 * tinymce.remove('div');
25146 * // Remove all editors bound to textareas
25147 * tinymce.remove('textarea');
25149 * // Remove all editors
25150 * tinymce.remove();
25152 * // Remove specific instance by id
25153 * tinymce.remove('#id');
25156 * @param {tinymce.Editor/String/Object} [selector] CSS selector or editor instance to remove.
25157 * @return {tinymce.Editor} The editor that got passed in will be return if it was found otherwise null.
25159 remove: function(selector) {
25160 var self = this, i, editors = self.editors, editor;
25162 // Remove all editors
25164 for (i = editors.length - 1; i >= 0; i--) {
25165 self.remove(editors[i]);
25171 // Remove editors by selector
25172 if (typeof(selector) == "string") {
25173 selector = selector.selector || selector;
25175 each(DOM.select(selector), function(elm) {
25176 self.remove(editors[elm.id]);
25182 // Remove specific editor
25185 // Not in the collection
25186 if (!editors[editor.id]) {
25190 delete editors[editor.id];
25192 for (i = 0; i < editors.length; i++) {
25193 if (editors[i] == editor) {
25194 editors.splice(i, 1);
25199 // Select another editor since the active one was removed
25200 if (self.activeEditor == editor) {
25201 self.activeEditor = editors[0];
25204 // Don't remove missing editor or removed instances
25205 if (!editor || editor.removed) {
25213 * Fires when an editor is removed from EditorManager collection.
25215 * @event RemoveEditor
25216 * @param {Object} e Event arguments.
25218 self.fire('RemoveEditor', {editor: editor});
25220 if (!editors.length) {
25221 DOM.unbind(window, 'beforeunload', beforeUnloadDelegate);
25228 * Executes a specific command on the currently active editor.
25230 * @method execCommand
25231 * @param {String} c Command to perform for example Bold.
25232 * @param {Boolean} u Optional boolean state if a UI should be presented for the command or not.
25233 * @param {String} v Optional value parameter like for example an URL to a link.
25234 * @return {Boolean} true/false if the command was executed or not.
25236 execCommand: function(cmd, ui, value) {
25237 var self = this, editor = self.get(value);
25239 // Manager commands
25241 case "mceAddEditor":
25242 if (!self.get(value)) {
25243 new Editor(value, self.settings, self).render();
25248 case "mceRemoveEditor":
25255 case 'mceToggleEditor':
25257 self.execCommand('mceAddEditor', 0, value);
25261 if (editor.isHidden()) {
25270 // Run command on active editor
25271 if (self.activeEditor) {
25272 return self.activeEditor.execCommand(cmd, ui, value);
25279 * Calls the save method on all editor instances in the collection. This can be useful when a form is to be submitted.
25281 * @method triggerSave
25283 * // Saves all contents
25284 * tinyMCE.triggerSave();
25286 triggerSave: function() {
25287 each(this.editors, function(editor) {
25293 * Adds a language pack, this gets called by the loaded language files like en.js.
25296 * @param {String} code Optional language code.
25297 * @param {Object} items Name/value object with translations.
25299 addI18n: function(code, items) {
25300 I18n.add(code, items);
25304 * Translates the specified string using the language pack items.
25306 * @method translate
25307 * @param {String/Array/Object} text String to translate
25308 * @return {String} Translated string.
25310 translate: function(text) {
25311 return I18n.translate(text);
25315 extend(EditorManager, Observable);
25317 EditorManager.setup();
25319 // Export EditorManager as tinymce/tinymce in global namespace
25320 window.tinymce = window.tinyMCE = EditorManager;
25322 return EditorManager;
25325 // Included from: js/tinymce/classes/LegacyInput.js
25330 * Copyright, Moxiecode Systems AB
25331 * Released under LGPL License.
25333 * License: http://www.tinymce.com/license
25334 * Contributing: http://www.tinymce.com/contributing
25337 define("tinymce/LegacyInput", [
25338 "tinymce/EditorManager",
25339 "tinymce/util/Tools"
25340 ], function(EditorManager, Tools) {
25341 var each = Tools.each, explode = Tools.explode;
25343 EditorManager.on('AddEditor', function(e) {
25344 var editor = e.editor;
25346 editor.on('preInit', function() {
25347 var filters, fontSizes, dom, settings = editor.settings;
25349 function replaceWithSpan(node, styles) {
25350 each(styles, function(value, name) {
25352 dom.setStyle(node, name, value);
25356 dom.rename(node, 'span');
25359 function convert(e) {
25362 if (settings.convert_fonts_to_spans) {
25363 each(dom.select('font,u,strike', e.node), function(node) {
25364 filters[node.nodeName.toLowerCase()](dom, node);
25369 if (settings.inline_styles) {
25370 fontSizes = explode(settings.font_size_legacy_values);
25373 font: function(dom, node) {
25374 replaceWithSpan(node, {
25375 backgroundColor: node.style.backgroundColor,
25377 fontFamily: node.face,
25378 fontSize: fontSizes[parseInt(node.size, 10) - 1]
25382 u: function(dom, node) {
25383 replaceWithSpan(node, {
25384 textDecoration: 'underline'
25388 strike: function(dom, node) {
25389 replaceWithSpan(node, {
25390 textDecoration: 'line-through'
25395 editor.on('PreProcess SetContent', convert);
25401 // Included from: js/tinymce/classes/util/XHR.js
25406 * Copyright, Moxiecode Systems AB
25407 * Released under LGPL License.
25409 * License: http://www.tinymce.com/license
25410 * Contributing: http://www.tinymce.com/contributing
25414 * This class enables you to send XMLHTTPRequests cross browser.
25415 * @class tinymce.util.XHR
25418 * // Sends a low level Ajax request
25419 * tinymce.util.XHR.send({
25421 * success: function(text) {
25422 * console.debug(text);
25426 define("tinymce/util/XHR", [], function() {
25429 * Sends a XMLHTTPRequest.
25430 * Consult the Wiki for details on what settings this method takes.
25433 * @param {Object} settings Object will target URL, callbacks and other info needed to make the request.
25435 send: function(settings) {
25436 var xhr, count = 0;
25439 if (!settings.async || xhr.readyState == 4 || count++ > 10000) {
25440 if (settings.success && count < 10000 && xhr.status == 200) {
25441 settings.success.call(settings.success_scope, '' + xhr.responseText, xhr, settings);
25442 } else if (settings.error) {
25443 settings.error.call(settings.error_scope, count > 10000 ? 'TIMED_OUT' : 'GENERAL', xhr, settings);
25448 setTimeout(ready, 10);
25452 // Default settings
25453 settings.scope = settings.scope || this;
25454 settings.success_scope = settings.success_scope || settings.scope;
25455 settings.error_scope = settings.error_scope || settings.scope;
25456 settings.async = settings.async === false ? false : true;
25457 settings.data = settings.data || '';
25459 xhr = new XMLHttpRequest();
25462 if (xhr.overrideMimeType) {
25463 xhr.overrideMimeType(settings.content_type);
25466 xhr.open(settings.type || (settings.data ? 'POST' : 'GET'), settings.url, settings.async);
25468 if (settings.content_type) {
25469 xhr.setRequestHeader('Content-Type', settings.content_type);
25472 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
25474 xhr.send(settings.data);
25476 // Syncronous request
25477 if (!settings.async) {
25481 // Wait for response, onReadyStateChange can not be used since it leaks memory in IE
25482 setTimeout(ready, 10);
25488 // Included from: js/tinymce/classes/util/JSON.js
25493 * Copyright, Moxiecode Systems AB
25494 * Released under LGPL License.
25496 * License: http://www.tinymce.com/license
25497 * Contributing: http://www.tinymce.com/contributing
25501 * JSON parser and serializer class.
25503 * @class tinymce.util.JSON
25506 * // JSON parse a string into an object
25507 * var obj = tinymce.util.JSON.parse(somestring);
25509 * // JSON serialize a object into an string
25510 * var str = tinymce.util.JSON.serialize(obj);
25512 define("tinymce/util/JSON", [], function() {
25513 function serialize(o, quote) {
25516 quote = quote || '"';
25524 if (t == 'string') {
25525 v = '\bb\tt\nn\ff\rr\""\'\'\\\\';
25527 return quote + o.replace(/([\u0080-\uFFFF\x00-\x1f\"\'\\])/g, function(a, b) {
25528 // Make sure single quotes never get encoded inside double quotes for JSON compatibility
25529 if (quote === '"' && a === "'") {
25536 return '\\' + v.charAt(i + 1);
25539 a = b.charCodeAt().toString(16);
25541 return '\\u' + '0000'.substring(a.length) + a;
25545 if (t == 'object') {
25546 if (o.hasOwnProperty && Object.prototype.toString.call(o) === '[object Array]') {
25547 for (i=0, v = '['; i<o.length; i++) {
25548 v += (i > 0 ? ',' : '') + serialize(o[i], quote);
25557 if (o.hasOwnProperty(name)) {
25558 v += typeof o[name] != 'function' ? (v.length > 1 ? ',' + quote : quote) + name +
25559 quote +':' + serialize(o[name], quote) : '';
25571 * Serializes the specified object as a JSON string.
25573 * @method serialize
25574 * @param {Object} obj Object to serialize as a JSON string.
25575 * @param {String} quote Optional quote string defaults to ".
25576 * @return {string} JSON string serialized from input.
25578 serialize: serialize,
25581 * Unserializes/parses the specified JSON string into a object.
25584 * @param {string} s JSON String to parse into a JavaScript object.
25585 * @return {Object} Object from input JSON string or undefined if it failed.
25587 parse: function(text) {
25590 return window[String.fromCharCode(101) + 'val']('(' + text + ')');
25600 // Included from: js/tinymce/classes/util/JSONRequest.js
25605 * Copyright, Moxiecode Systems AB
25606 * Released under LGPL License.
25608 * License: http://www.tinymce.com/license
25609 * Contributing: http://www.tinymce.com/contributing
25613 * This class enables you to use JSON-RPC to call backend methods.
25615 * @class tinymce.util.JSONRequest
25617 * var json = new tinymce.util.JSONRequest({
25618 * url: 'somebackend.php'
25621 * // Send RPC call 1
25623 * method: 'someMethod1',
25624 * params: ['a', 'b'],
25625 * success: function(result) {
25626 * console.dir(result);
25630 * // Send RPC call 2
25632 * method: 'someMethod2',
25633 * params: ['a', 'b'],
25634 * success: function(result) {
25635 * console.dir(result);
25639 define("tinymce/util/JSONRequest", [
25640 "tinymce/util/JSON",
25641 "tinymce/util/XHR",
25642 "tinymce/util/Tools"
25643 ], function(JSON, XHR, Tools) {
25644 var extend = Tools.extend;
25646 function JSONRequest(settings) {
25647 this.settings = extend({}, settings);
25652 * Simple helper function to send a JSON-RPC request without the need to initialize an object.
25653 * Consult the Wiki API documentation for more details on what you can pass to this function.
25657 * @param {Object} o Call object where there are three field id, method and params this object should also contain callbacks etc.
25659 JSONRequest.sendRPC = function(o) {
25660 return new JSONRequest().send(o);
25663 JSONRequest.prototype = {
25665 * Sends a JSON-RPC call. Consult the Wiki API documentation for more details on what you can pass to this function.
25668 * @param {Object} args Call object where there are three field id, method and params this object should also contain callbacks etc.
25670 send: function(args) {
25671 var ecb = args.error, scb = args.success;
25673 args = extend(this.settings, args);
25675 args.success = function(c, x) {
25678 if (typeof(c) == 'undefined') {
25680 error : 'JSON Parse error.'
25685 ecb.call(args.error_scope || args.scope, c.error, x);
25687 scb.call(args.success_scope || args.scope, c.result);
25691 args.error = function(ty, x) {
25693 ecb.call(args.error_scope || args.scope, ty, x);
25697 args.data = JSON.serialize({
25698 id: args.id || 'c' + (this.count++),
25699 method: args.method,
25700 params: args.params
25703 // JSON content type for Ruby on rails. Bug: #1883287
25704 args.content_type = 'application/json';
25710 return JSONRequest;
25713 // Included from: js/tinymce/classes/util/JSONP.js
25718 * Copyright, Moxiecode Systems AB
25719 * Released under LGPL License.
25721 * License: http://www.tinymce.com/license
25722 * Contributing: http://www.tinymce.com/contributing
25725 define("tinymce/util/JSONP", [
25726 "tinymce/dom/DOMUtils"
25727 ], function(DOMUtils) {
25732 send: function(settings) {
25733 var self = this, dom = DOMUtils.DOM, count = settings.count !== undefined ? settings.count : self.count;
25734 var id = 'tinymce_jsonp_' + count;
25736 self.callbacks[count] = function(json) {
25738 delete self.callbacks[count];
25740 settings.callback(json);
25743 dom.add(dom.doc.body, 'script', {
25746 type: 'text/javascript'
25754 // Included from: js/tinymce/classes/util/LocalStorage.js
25759 * Copyright, Moxiecode Systems AB
25760 * Released under LGPL License.
25762 * License: http://www.tinymce.com/license
25763 * Contributing: http://www.tinymce.com/contributing
25767 * This class will simulate LocalStorage on IE 7 and return the native version on modern browsers.
25768 * Storage is done using userData on IE 7 and a special serialization format. The format is designed
25769 * to be as small as possible by making sure that the keys and values doesn't need to be encoded. This
25770 * makes it possible to store for example HTML data.
25772 * Storage format for userData:
25773 * <base 32 key length>,<key string>,<base 32 value length>,<value>,...
25775 * For example this data key1=value1,key2=value2 would be:
25776 * 4,key1,6,value1,4,key2,6,value2
25778 * @class tinymce.util.LocalStorage
25782 * tinymce.util.LocalStorage.setItem('key', 'value');
25783 * var value = tinymce.util.LocalStorage.getItem('key');
25785 define("tinymce/util/LocalStorage", [], function() {
25786 var LocalStorage, storageElm, items, keys, userDataKey, hasOldIEDataSupport;
25788 // Check for native support
25789 if (window.localStorage) {
25790 return localStorage;
25793 userDataKey = "tinymce";
25794 storageElm = document.documentElement;
25795 hasOldIEDataSupport = !!storageElm.addBehavior;
25797 if (hasOldIEDataSupport) {
25798 storageElm.addBehavior('#default#userData');
25802 * Gets the keys names and updates LocalStorage.length property. Since IE7 doesn't have any getters/setters.
25804 function updateKeys() {
25807 for (var key in items) {
25811 LocalStorage.length = keys.length;
25815 * Loads the userData string and parses it into the items structure.
25818 var key, data, value, pos = 0;
25822 // localStorage can be disabled on WebKit/Gecko so make a dummy storage
25823 if (!hasOldIEDataSupport) {
25827 function next(end) {
25828 var value, nextPos;
25830 nextPos = end !== undefined ? pos + end : data.indexOf(',', pos);
25831 if (nextPos === -1 || nextPos > data.length) {
25835 value = data.substring(pos, nextPos);
25841 storageElm.load(userDataKey);
25842 data = storageElm.getAttribute(userDataKey) || '';
25845 key = next(parseInt(next(), 32) || 0);
25846 if (key !== null) {
25847 value = next(parseInt(next(), 32) || 0);
25848 items[key] = value;
25850 } while (key !== null);
25856 * Saves the items structure into a the userData format.
25859 var value, data = '';
25861 // localStorage can be disabled on WebKit/Gecko so make a dummy storage
25862 if (!hasOldIEDataSupport) {
25866 for (var key in items) {
25867 value = items[key];
25868 data += (data ? ',' : '') + key.length.toString(32) + ',' + key + ',' + value.length.toString(32) + ',' + value;
25871 storageElm.setAttribute(userDataKey, data);
25872 storageElm.save(userDataKey);
25878 * Length of the number of items in storage.
25882 * @return {Number} Number of items in storage.
25887 * Returns the key name by index.
25890 * @param {Number} index Index of key to return.
25891 * @return {String} Key value or null if it wasn't found.
25893 key: function(index) {
25894 return keys[index];
25898 * Returns the value if the specified key or null if it wasn't found.
25901 * @param {String} key Key of item to retrive.
25902 * @return {String} Value of the specified item or null if it wasn't found.
25904 getItem: function(key) {
25905 return key in items ? items[key] : null;
25909 * Sets the value of the specified item by it's key.
25912 * @param {String} key Key of the item to set.
25913 * @param {String} value Value of the item to set.
25915 setItem: function(key, value) {
25916 items[key] = "" + value;
25921 * Removes the specified item by key.
25923 * @method removeItem
25924 * @param {String} key Key of item to remove.
25926 removeItem: function(key) {
25932 * Removes all items.
25936 clear: function() {
25944 return LocalStorage;
25947 // Included from: js/tinymce/classes/Compat.js
25952 * Copyright, Moxiecode Systems AB
25953 * Released under LGPL License.
25955 * License: http://www.tinymce.com/license
25956 * Contributing: http://www.tinymce.com/contributing
25960 * TinyMCE core class.
25964 * @borrow-members tinymce.EditorManager
25965 * @borrow-members tinymce.util.Tools
25967 define("tinymce/Compat", [
25968 "tinymce/dom/DOMUtils",
25969 "tinymce/dom/EventUtils",
25970 "tinymce/dom/ScriptLoader",
25971 "tinymce/AddOnManager",
25972 "tinymce/util/Tools",
25974 ], function(DOMUtils, EventUtils, ScriptLoader, AddOnManager, Tools, Env) {
25975 var tinymce = window.tinymce;
25978 * @property {tinymce.dom.DOMUtils} DOM Global DOM instance.
25979 * @property {tinymce.dom.ScriptLoader} ScriptLoader Global ScriptLoader instance.
25980 * @property {tinymce.AddOnManager} PluginManager Global PluginManager instance.
25981 * @property {tinymce.AddOnManager} ThemeManager Global ThemeManager instance.
25983 tinymce.DOM = DOMUtils.DOM;
25984 tinymce.ScriptLoader = ScriptLoader.ScriptLoader;
25985 tinymce.PluginManager = AddOnManager.PluginManager;
25986 tinymce.ThemeManager = AddOnManager.ThemeManager;
25988 tinymce.dom = tinymce.dom || {};
25989 tinymce.dom.Event = EventUtils.Event;
25991 Tools.each(Tools, function(func, key) {
25992 tinymce[key] = func;
25995 Tools.each('isOpera isWebKit isIE isGecko isMac'.split(' '), function(name) {
25996 tinymce[name] = Env[name.substr(2).toLowerCase()];
26002 // Describe the different namespaces
26005 * Root level namespace this contains classes directly releated to the TinyMCE editor.
26007 * @namespace tinymce
26011 * Contains classes for handling the browsers DOM.
26013 * @namespace tinymce.dom
26017 * Contains html parser and serializer logic.
26019 * @namespace tinymce.html
26023 * Contains the different UI types such as buttons, listboxes etc.
26025 * @namespace tinymce.ui
26029 * Contains various utility classes such as json parser, cookies etc.
26031 * @namespace tinymce.util
26034 // Included from: js/tinymce/classes/ui/Layout.js
26039 * Copyright, Moxiecode Systems AB
26040 * Released under LGPL License.
26042 * License: http://www.tinymce.com/license
26043 * Contributing: http://www.tinymce.com/contributing
26047 * Base layout manager class.
26049 * @class tinymce.ui.Layout
26051 define("tinymce/ui/Layout", [
26052 "tinymce/util/Class",
26053 "tinymce/util/Tools"
26054 ], function(Class, Tools) {
26057 return Class.extend({
26059 firstControlClass: 'first',
26060 lastControlClass: 'last'
26064 * Constructs a layout instance with the specified settings.
26067 * @param {Object} settings Name/value object with settings.
26069 init: function(settings) {
26070 this.settings = Tools.extend({}, this.Defaults, settings);
26074 * This method gets invoked before the layout renders the controls.
26076 * @method preRender
26077 * @param {tinymce.ui.Container} container Container instance to preRender.
26079 preRender: function(container) {
26080 container.addClass(this.settings.containerClass, 'body');
26084 * Applies layout classes to the container.
26088 applyClasses: function(container) {
26089 var self = this, settings = self.settings, items, firstClass, lastClass;
26091 items = container.items().filter(':visible');
26092 firstClass = settings.firstControlClass;
26093 lastClass = settings.lastControlClass;
26095 items.each(function(item) {
26096 item.removeClass(firstClass).removeClass(lastClass);
26098 if (settings.controlClass) {
26099 item.addClass(settings.controlClass);
26103 items.eq(0).addClass(firstClass);
26104 items.eq(-1).addClass(lastClass);
26108 * Renders the specified container and any layout specific HTML.
26110 * @method renderHtml
26111 * @param {tinymce.ui.Container} container Container to render HTML for.
26113 renderHtml: function(container) {
26114 var self = this, settings = self.settings, items, html = '';
26116 items = container.items();
26117 items.eq(0).addClass(settings.firstControlClass);
26118 items.eq(-1).addClass(settings.lastControlClass);
26120 items.each(function(item) {
26121 if (settings.controlClass) {
26122 item.addClass(settings.controlClass);
26125 html += item.renderHtml();
26132 * Recalculates the positions of the controls in the specified container.
26135 * @param {tinymce.ui.Container} container Container instance to recalc.
26137 recalc: function() {
26141 * This method gets invoked after the layout renders the controls.
26143 * @method postRender
26144 * @param {tinymce.ui.Container} container Container instance to postRender.
26146 postRender: function() {
26151 // Included from: js/tinymce/classes/ui/AbsoluteLayout.js
26154 * AbsoluteLayout.js
26156 * Copyright, Moxiecode Systems AB
26157 * Released under LGPL License.
26159 * License: http://www.tinymce.com/license
26160 * Contributing: http://www.tinymce.com/contributing
26164 * LayoutManager for absolute positioning. This layout manager is more of
26165 * a base class for other layouts but can be created and used directly.
26167 * @-x-less AbsoluteLayout.less
26168 * @class tinymce.ui.AbsoluteLayout
26169 * @extends tinymce.ui.Layout
26171 define("tinymce/ui/AbsoluteLayout", [
26172 "tinymce/ui/Layout"
26173 ], function(Layout) {
26176 return Layout.extend({
26178 containerClass: 'abs-layout',
26179 controlClass: 'abs-layout-item'
26183 * Recalculates the positions of the controls in the specified container.
26186 * @param {tinymce.ui.Container} container Container instance to recalc.
26188 recalc: function(container) {
26189 container.items().filter(':visible').each(function(ctrl) {
26190 var settings = ctrl.settings;
26206 * Renders the specified container and any layout specific HTML.
26208 * @method renderHtml
26209 * @param {tinymce.ui.Container} container Container to render HTML for.
26211 renderHtml: function(container) {
26212 return '<div id="' + container._id + '-absend" class="' + container.classPrefix + 'abs-end"></div>' + this._super(container);
26217 // Included from: js/tinymce/classes/ui/Tooltip.js
26222 * Copyright, Moxiecode Systems AB
26223 * Released under LGPL License.
26225 * License: http://www.tinymce.com/license
26226 * Contributing: http://www.tinymce.com/contributing
26230 * Creates a tooltip instance.
26232 * @-x-less ToolTip.less
26233 * @class tinymce.ui.ToolTip
26234 * @extends tinymce.ui.Control
26235 * @mixes tinymce.ui.Movable
26237 define("tinymce/ui/Tooltip", [
26238 "tinymce/ui/Control",
26239 "tinymce/ui/Movable"
26240 ], function(Control, Movable) {
26241 return Control.extend({
26245 classes: 'widget tooltip tooltip-n'
26249 * Sets/gets the current label text.
26252 * @param {String} [text] New label text.
26253 * @return {String|tinymce.ui.Tooltip} Current text or current label instance.
26255 text: function(value) {
26258 if (typeof(value) != "undefined") {
26259 self._value = value;
26261 if (self._rendered) {
26262 self.getEl().lastChild.innerHTML = self.encode(value);
26268 return self._value;
26272 * Renders the control as a HTML string.
26274 * @method renderHtml
26275 * @return {String} HTML representing the control.
26277 renderHtml: function() {
26278 var self = this, prefix = self.classPrefix;
26281 '<div id="' + self._id + '" class="' + self.classes() + '" role="presentation">' +
26282 '<div class="' + prefix + 'tooltip-arrow"></div>' +
26283 '<div class="' + prefix + 'tooltip-inner">' + self.encode(self._text) + '</div>' +
26289 * Repaints the control after a layout operation.
26293 repaint: function() {
26294 var self = this, style, rect;
26296 style = self.getEl().style;
26297 rect = self._layoutRect;
26299 style.left = rect.x + 'px';
26300 style.top = rect.y + 'px';
26301 style.zIndex = 0xFFFF + 0xFFFF;
26306 // Included from: js/tinymce/classes/ui/Widget.js
26311 * Copyright, Moxiecode Systems AB
26312 * Released under LGPL License.
26314 * License: http://www.tinymce.com/license
26315 * Contributing: http://www.tinymce.com/contributing
26319 * Widget base class a widget is a control that has a tooltip and some basic states.
26321 * @class tinymce.ui.Widget
26322 * @extends tinymce.ui.Control
26324 define("tinymce/ui/Widget", [
26325 "tinymce/ui/Control",
26326 "tinymce/ui/Tooltip"
26327 ], function(Control, Tooltip) {
26332 var Widget = Control.extend({
26334 * Constructs a instance with the specified settings.
26337 * @param {Object} settings Name/value object with settings.
26338 * @setting {String} tooltip Tooltip text to display when hovering.
26339 * @setting {Boolean} autofocus True if the control should be focused when rendered.
26340 * @setting {String} text Text to display inside widget.
26342 init: function(settings) {
26345 self._super(settings);
26346 self.canFocus = true;
26348 if (settings.tooltip && Widget.tooltips !== false) {
26349 self.on('mouseenter mouseleave', function(e) {
26350 var tooltip = self.tooltip().moveTo(-0xFFFF);
26352 if (e.control == self && e.type == 'mouseenter') {
26353 var rel = tooltip.text(settings.tooltip).show().testMoveRel(self.getEl(), ['bc-tc', 'bc-tl', 'bc-tr']);
26355 tooltip.toggleClass('tooltip-n', rel == 'bc-tc');
26356 tooltip.toggleClass('tooltip-nw', rel == 'bc-tl');
26357 tooltip.toggleClass('tooltip-ne', rel == 'bc-tr');
26359 tooltip.moveRel(self.getEl(), rel);
26366 self.aria('label', settings.tooltip);
26370 * Returns the current tooltip instance.
26373 * @return {tinymce.ui.Tooltip} Tooltip instance.
26375 tooltip: function() {
26379 tooltip = new Tooltip({type: 'tooltip'});
26380 tooltip.renderTo(self.getContainerElm());
26387 * Sets/gets the active state of the widget.
26390 * @param {Boolean} [state] State if the control is active.
26391 * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
26393 active: function(state) {
26394 var self = this, undef;
26396 if (state !== undef) {
26397 self.aria('pressed', state);
26398 self.toggleClass('active', state);
26401 return self._super(state);
26405 * Sets/gets the disabled state of the widget.
26408 * @param {Boolean} [state] State if the control is disabled.
26409 * @return {Boolean|tinymce.ui.Widget} True/false or current widget instance.
26411 disabled: function(state) {
26412 var self = this, undef;
26414 if (state !== undef) {
26415 self.aria('disabled', state);
26416 self.toggleClass('disabled', state);
26419 return self._super(state);
26423 * Called after the control has been rendered.
26425 * @method postRender
26427 postRender: function() {
26428 var self = this, settings = self.settings;
26430 self._rendered = true;
26434 if (!self.parent() && (settings.width || settings.height)) {
26435 self.initLayoutRect();
26439 if (settings.autofocus) {
26440 setTimeout(function() {
26447 * Removes the current control from DOM and from UI collections.
26450 * @return {tinymce.ui.Control} Current control instance.
26452 remove: function() {
26465 // Included from: js/tinymce/classes/ui/Button.js
26470 * Copyright, Moxiecode Systems AB
26471 * Released under LGPL License.
26473 * License: http://www.tinymce.com/license
26474 * Contributing: http://www.tinymce.com/contributing
26478 * This class is used to create buttons. You can create them directly or through the Factory.
26481 * // Create and render a button to the body element
26482 * tinymce.ui.Factory.create({
26484 * text: 'My button'
26485 * }).renderTo(document.body);
26487 * @-x-less Button.less
26488 * @class tinymce.ui.Button
26489 * @extends tinymce.ui.Widget
26491 define("tinymce/ui/Button", [
26492 "tinymce/ui/Widget"
26493 ], function(Widget) {
26496 return Widget.extend({
26498 classes: "widget btn",
26503 * Constructs a new button instance with the specified settings.
26506 * @param {Object} settings Name/value object with settings.
26507 * @setting {String} size Size of the button small|medium|large.
26508 * @setting {String} image Image to use for icon.
26509 * @setting {String} icon Icon to use for button.
26511 init: function(settings) {
26512 var self = this, size;
26514 self.on('click mousedown', function(e) {
26515 e.preventDefault();
26518 self._super(settings);
26519 size = settings.size;
26521 if (settings.subtype) {
26522 self.addClass(settings.subtype);
26526 self.addClass('btn-' + size);
26531 * Repaints the button for example after it's been resizes by a layout engine.
26535 repaint: function() {
26536 var btnStyle = this.getEl().firstChild.style;
26538 btnStyle.width = btnStyle.height = "100%";
26544 * Renders the control as a HTML string.
26546 * @method renderHtml
26547 * @return {String} HTML representing the control.
26549 renderHtml: function() {
26550 var self = this, id = self._id, prefix = self.classPrefix;
26551 var icon = self.settings.icon, image = '';
26553 if (self.settings.image) {
26555 image = ' style="background-image: url(\'' + self.settings.image + '\')"';
26558 icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + icon : '';
26561 '<div id="' + id + '" class="' + self.classes() + '" tabindex="-1">' +
26562 '<button role="presentation" type="button" tabindex="-1">' +
26563 (icon ? '<i class="' + icon + '"' + image + '></i>' : '') +
26564 (self._text ? (icon ? ' ' : '') + self.encode(self._text) : '') +
26572 // Included from: js/tinymce/classes/ui/ButtonGroup.js
26577 * Copyright, Moxiecode Systems AB
26578 * Released under LGPL License.
26580 * License: http://www.tinymce.com/license
26581 * Contributing: http://www.tinymce.com/contributing
26585 * This control enables you to put multiple buttons into a group. This is
26586 * useful when you want to combine similar toolbar buttons into a group.
26589 * // Create and render a buttongroup with two buttons to the body element
26590 * tinymce.ui.Factory.create({
26591 * type: 'buttongroup',
26593 * {text: 'Button A'},
26594 * {text: 'Button B'}
26596 * }).renderTo(document.body);
26598 * @-x-less ButtonGroup.less
26599 * @class tinymce.ui.ButtonGroup
26600 * @extends tinymce.ui.Container
26602 define("tinymce/ui/ButtonGroup", [
26603 "tinymce/ui/Container"
26604 ], function(Container) {
26607 return Container.extend({
26609 defaultType: 'button',
26614 * Renders the control as a HTML string.
26616 * @method renderHtml
26617 * @return {String} HTML representing the control.
26619 renderHtml: function() {
26620 var self = this, layout = self._layout;
26622 self.addClass('btn-group');
26624 layout.preRender(self);
26627 '<div id="' + self._id + '" class="' + self.classes() + '">'+
26628 '<div id="' + self._id + '-body">'+
26629 (self.settings.html || '') + layout.renderHtml(self) +
26637 // Included from: js/tinymce/classes/ui/Checkbox.js
26642 * Copyright, Moxiecode Systems AB
26643 * Released under LGPL License.
26645 * License: http://www.tinymce.com/license
26646 * Contributing: http://www.tinymce.com/contributing
26650 * This control creates a custom checkbox.
26653 * // Create and render a checkbox to the body element
26654 * tinymce.ui.Factory.create({
26655 * type: 'checkbox',
26657 * text: 'My checkbox'
26658 * }).renderTo(document.body);
26660 * @-x-less Checkbox.less
26661 * @class tinymce.ui.Checkbox
26662 * @extends tinymce.ui.Widget
26664 define("tinymce/ui/Checkbox", [
26665 "tinymce/ui/Widget"
26666 ], function(Widget) {
26669 return Widget.extend({
26671 classes: "checkbox",
26677 * Constructs a new Checkbox instance with the specified settings.
26680 * @param {Object} settings Name/value object with settings.
26681 * @setting {Boolean} checked True if the checkbox should be checked by default.
26683 init: function(settings) {
26686 self._super(settings);
26688 self.on('click mousedown', function(e) {
26689 e.preventDefault();
26692 self.on('click', function(e) {
26693 e.preventDefault();
26695 if (!self.disabled()) {
26696 self.checked(!self.checked());
26700 self.checked(self.settings.checked);
26704 * Getter/setter function for the checked state.
26707 * @param {Boolean} [state] State to be set.
26708 * @return {Boolean|tinymce.ui.Checkbox} True/false or checkbox if it's a set operation.
26710 checked: function(state) {
26713 if (typeof state != "undefined") {
26715 self.addClass('checked');
26717 self.removeClass('checked');
26720 self._checked = state;
26721 self.aria('checked', state);
26726 return self._checked;
26730 * Getter/setter function for the value state.
26733 * @param {Boolean} [state] State to be set.
26734 * @return {Boolean|tinymce.ui.Checkbox} True/false or checkbox if it's a set operation.
26736 value: function(state) {
26737 return this.checked(state);
26741 * Renders the control as a HTML string.
26743 * @method renderHtml
26744 * @return {String} HTML representing the control.
26746 renderHtml: function() {
26747 var self = this, id = self._id, prefix = self.classPrefix;
26750 '<div id="' + id + '" class="' + self.classes() + '" unselectable="on" aria-labeledby="' + id + '-al" tabindex="-1">' +
26751 '<i class="' + prefix + 'ico ' + prefix + 'i-checkbox"></i>' +
26752 '<span id="' + id +'-al" class="' + prefix + 'label">' + self.encode(self._text) + '</span>' +
26759 // Included from: js/tinymce/classes/ui/PanelButton.js
26764 * Copyright, Moxiecode Systems AB
26765 * Released under LGPL License.
26767 * License: http://www.tinymce.com/license
26768 * Contributing: http://www.tinymce.com/contributing
26772 * Creates a new panel button.
26774 * @class tinymce.ui.PanelButton
26775 * @extends tinymce.ui.Button
26777 define("tinymce/ui/PanelButton", [
26778 "tinymce/ui/Button",
26779 "tinymce/ui/FloatPanel"
26780 ], function(Button, FloatPanel) {
26783 return Button.extend({
26785 * Shows the panel for the button.
26787 * @method showPanel
26789 showPanel: function() {
26790 var self = this, settings = self.settings;
26792 settings.panel.popover = true;
26793 settings.panel.autohide = true;
26797 self.panel = new FloatPanel(settings.panel).on('hide', function() {
26798 self.active(false);
26799 }).parent(self).renderTo(self.getContainerElm());
26800 self.panel.fire('show');
26801 self.panel.reflow();
26806 self.panel.moveRel(self.getEl(), settings.popoverAlign || 'bc-tc');
26810 * Hides the panel for the button.
26812 * @method hidePanel
26814 hidePanel: function() {
26823 * Called after the control has been rendered.
26825 * @method postRender
26827 postRender: function() {
26830 self.on('click', function(e) {
26831 if (e.control === self) {
26832 if (self.panel && self.panel.visible()) {
26840 return self._super();
26845 // Included from: js/tinymce/classes/ui/ColorButton.js
26850 * Copyright, Moxiecode Systems AB
26851 * Released under LGPL License.
26853 * License: http://www.tinymce.com/license
26854 * Contributing: http://www.tinymce.com/contributing
26858 * This class creates a color button control. This is a split button in which the main
26859 * button has a visual representation of the currently selected color. When clicked
26860 * the caret button displays a color picker, allowing the user to select a new color.
26862 * @-x-less ColorButton.less
26863 * @class tinymce.ui.ColorButton
26864 * @extends tinymce.ui.PanelButton
26866 define("tinymce/ui/ColorButton", [
26867 "tinymce/ui/PanelButton",
26868 "tinymce/dom/DOMUtils"
26869 ], function(PanelButton, DomUtils) {
26872 var DOM = DomUtils.DOM;
26874 return PanelButton.extend({
26876 * Constructs a new ColorButton instance with the specified settings.
26879 * @param {Object} settings Name/value object with settings.
26881 init: function(settings) {
26882 this._super(settings);
26883 this.addClass('colorbutton');
26887 * Getter/setter for the current color.
26890 * @param {String} [color] Color to set.
26891 * @return {String|tinymce.ui.ColorButton} Current color or current instance.
26893 color: function(color) {
26895 this._color = color;
26896 this.getEl('preview').style.backgroundColor = color;
26900 return this._color;
26904 * Renders the control as a HTML string.
26906 * @method renderHtml
26907 * @return {String} HTML representing the control.
26909 renderHtml: function() {
26910 var self = this, id = self._id, prefix = self.classPrefix;
26911 var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
26912 var image = self.settings.image ? ' style="background-image: url(\'' + self.settings.image + '\')"' : '';
26915 '<div id="' + id + '" class="' + self.classes() + '">' +
26916 '<button role="presentation" hidefocus type="button" tabindex="-1">' +
26917 (icon ? '<i class="' + icon + '"' + image + '></i>' : '') +
26918 '<span id="' + id + '-preview" class="' + prefix + 'preview"></span>' +
26919 (self._text ? (icon ? ' ' : '') + (self._text) : '') +
26921 '<button type="button" class="' + prefix + 'open" hidefocus tabindex="-1">' +
26922 ' <i class="' + prefix + 'caret"></i>' +
26929 * Called after the control has been rendered.
26931 * @method postRender
26933 postRender: function() {
26934 var self = this, onClickHandler = self.settings.onclick;
26936 self.on('click', function(e) {
26937 if (e.control == self && !DOM.getParent(e.target, '.' + self.classPrefix + 'open')) {
26938 e.stopImmediatePropagation();
26939 onClickHandler.call(self, e);
26943 delete self.settings.onclick;
26945 return self._super();
26951 // Included from: js/tinymce/classes/ui/ComboBox.js
26956 * Copyright, Moxiecode Systems AB
26957 * Released under LGPL License.
26959 * License: http://www.tinymce.com/license
26960 * Contributing: http://www.tinymce.com/contributing
26964 * This class creates a combobox control. Select box that you select a value from or
26965 * type a value into.
26967 * @-x-less ComboBox.less
26968 * @class tinymce.ui.ComboBox
26969 * @extends tinymce.ui.Widget
26971 define("tinymce/ui/ComboBox", [
26972 "tinymce/ui/Widget",
26973 "tinymce/ui/DomUtils"
26974 ], function(Widget, DomUtils) {
26977 return Widget.extend({
26979 * Constructs a new control instance with the specified settings.
26982 * @param {Object} settings Name/value object with settings.
26983 * @setting {String} placeholder Placeholder text to display.
26985 init: function(settings) {
26988 self._super(settings);
26989 self.addClass('combobox');
26991 self.on('click', function(e) {
26992 var elm = e.target;
26995 if (elm.id && elm.id.indexOf('-open') != -1) {
26996 self.fire('action');
26999 elm = elm.parentNode;
27003 // TODO: Rework this
27004 self.on('keydown', function(e) {
27005 if (e.target.nodeName == "INPUT" && e.keyCode == 13) {
27006 self.parents().reverse().each(function(ctrl) {
27007 e.preventDefault();
27008 self.fire('change');
27018 if (settings.placeholder) {
27019 self.addClass('placeholder');
27021 self.on('focusin', function() {
27022 if (!self._hasOnChange) {
27023 DomUtils.on(self.getEl('inp'), 'change', function() {
27024 self.fire('change');
27027 self._hasOnChange = true;
27030 if (self.hasClass('placeholder')) {
27031 self.getEl('inp').value = '';
27032 self.removeClass('placeholder');
27036 self.on('focusout', function() {
27037 if (self.value().length === 0) {
27038 self.getEl('inp').value = settings.placeholder;
27039 self.addClass('placeholder');
27046 * Getter/setter function for the control value.
27049 * @param {String} [value] Value to be set.
27050 * @return {String|tinymce.ui.ComboBox} Value or self if it's a set operation.
27052 value: function(value) {
27055 if (typeof(value) != "undefined") {
27056 self._value = value;
27057 self.removeClass('placeholder');
27059 if (self._rendered) {
27060 self.getEl('inp').value = value;
27066 if (self._rendered) {
27067 value = self.getEl('inp').value;
27069 if (value != self.settings.placeholder) {
27076 return self._value;
27080 * Getter/setter function for the disabled state.
27083 * @param {Boolean} [state] State to be set.
27084 * @return {Boolean|tinymce.ui.ComboBox} True/false or self if it's a set operation.
27086 disabled: function(state) {
27089 self._super(state);
27091 if (self._rendered) {
27092 self.getEl('inp').disabled = state;
27097 * Focuses the input area of the control.
27101 focus: function() {
27102 this.getEl('inp').focus();
27106 * Repaints the control after a layout operation.
27110 repaint: function() {
27111 var self = this, elm = self.getEl(), openElm = self.getEl('open'), rect = self.layoutRect();
27112 var width, lineHeight;
27115 width = rect.w - openElm.offsetWidth - 10;
27117 width = rect.w - 10;
27120 // Detect old IE 7+8 add lineHeight to align caret vertically in the middle
27121 var doc = document;
27122 if (doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
27123 lineHeight = (self.layoutRect().h - 2) + 'px';
27126 DomUtils.css(elm.firstChild, {
27128 lineHeight: lineHeight
27137 * Post render method. Called after the control has been rendered to the target.
27139 * @method postRender
27140 * @return {tinymce.ui.ComboBox} Current combobox instance.
27142 postRender: function() {
27145 DomUtils.on(this.getEl('inp'), 'change', function() {
27146 self.fire('change');
27149 return self._super();
27153 * Renders the control as a HTML string.
27155 * @method renderHtml
27156 * @return {String} HTML representing the control.
27158 renderHtml: function() {
27159 var self = this, id = self._id, settings = self.settings, prefix = self.classPrefix;
27160 var value = settings.value || settings.placeholder || '';
27161 var icon, text, openBtnHtml = '';
27163 icon = settings.icon ? prefix + 'ico ' + prefix + 'i-' + settings.icon : '';
27166 if (icon || text) {
27168 '<div id="' + id + '-open" class="' + prefix + 'btn ' + prefix + 'open" tabIndex="-1">' +
27169 '<button id="' + id + '-action" type="button" hidefocus tabindex="-1">' +
27170 (icon ? '<i class="' + icon + '"></i>' : '<i class="' + prefix + 'caret"></i>') +
27171 (text ? (icon ? ' ' : '') + text : '') +
27176 self.addClass('has-open');
27180 '<div id="' + id + '" class="' + self.classes() + '">' +
27181 '<input id="' + id + '-inp" class="' + prefix + 'textbox ' + prefix + 'placeholder" value="' +
27182 value + '" hidefocus="true">' +
27190 // Included from: js/tinymce/classes/ui/Path.js
27195 * Copyright, Moxiecode Systems AB
27196 * Released under LGPL License.
27198 * License: http://www.tinymce.com/license
27199 * Contributing: http://www.tinymce.com/contributing
27203 * Creates a new path control.
27205 * @-x-less Path.less
27206 * @class tinymce.ui.Path
27207 * @extends tinymce.ui.Control
27209 define("tinymce/ui/Path", [
27210 "tinymce/ui/Control",
27211 "tinymce/ui/KeyboardNavigation"
27212 ], function(Control, KeyboardNavigation) {
27215 return Control.extend({
27217 delimiter: "\u00BB"
27221 * Constructs a instance with the specified settings.
27224 * @param {Object} settings Name/value object with settings.
27225 * @setting {String} delimiter Delimiter to display between items in path.
27227 init: function(settings) {
27230 self._super(settings);
27231 self.addClass('path');
27232 self.canFocus = true;
27234 self.on('click', function(e) {
27235 var index, target = e.target;
27237 if ((index = target.getAttribute('data-index'))) {
27238 self.fire('select', {value: self.data()[index], index: index});
27244 * Focuses the current control.
27247 * @return {tinymce.ui.Control} Current control instance.
27249 focus: function() {
27252 self.keyNav = new KeyboardNavigation({
27254 enableLeftRight: true
27257 self.keyNav.focusFirst();
27263 * Sets/gets the data to be used for the path.
27266 * @param {Array} data Array with items name is rendered to path.
27268 data: function(data) {
27271 if (typeof(data) !== "undefined") {
27282 * Updated the path.
27286 update: function() {
27287 this.innerHtml(this._getPathHtml());
27291 * Called after the control has been rendered.
27293 * @method postRender
27295 postRender: function() {
27300 self.data(self.settings.data);
27304 * Renders the control as a HTML string.
27306 * @method renderHtml
27307 * @return {String} HTML representing the control.
27309 renderHtml: function() {
27313 '<div id="' + self._id + '" class="' + self.classPrefix + 'path">' +
27314 self._getPathHtml() +
27319 _getPathHtml: function() {
27320 var self = this, parts = self._data || [], i, l, html = '', prefix = self.classPrefix;
27322 for (i = 0, l = parts.length; i < l; i++) {
27324 (i > 0 ? '<div class="'+ prefix + 'divider" aria-hidden="true"> ' + self.settings.delimiter + ' </div>' : '') +
27325 '<div role="button" class="' + prefix + 'path-item' + (i == l - 1 ? ' ' + prefix + 'last' : '') + '" data-index="' +
27326 i + '" tabindex="-1" id="' + self._id + '-' + i +'">' + parts[i].name + '</div>'
27331 html = '<div class="' + prefix + 'path-item"> </div>';
27339 // Included from: js/tinymce/classes/ui/ElementPath.js
27344 * Copyright, Moxiecode Systems AB
27345 * Released under LGPL License.
27347 * License: http://www.tinymce.com/license
27348 * Contributing: http://www.tinymce.com/contributing
27352 * This control creates an path for the current selections parent elements in TinyMCE.
27354 * @class tinymce.ui.ElementPath
27355 * @extends tinymce.ui.Path
27357 define("tinymce/ui/ElementPath", [
27359 "tinymce/EditorManager"
27360 ], function(Path, EditorManager) {
27361 return Path.extend({
27363 * Post render method. Called after the control has been rendered to the target.
27365 * @method postRender
27366 * @return {tinymce.ui.ElementPath} Current combobox instance.
27368 postRender: function() {
27369 var self = this, editor = EditorManager.activeEditor;
27371 function isBogus(elm) {
27372 return elm.nodeType === 1 && (elm.nodeName == "BR" || !!elm.getAttribute('data-mce-bogus'));
27375 self.on('select', function(e) {
27376 var parents = [], node, body = editor.getBody();
27380 node = editor.selection.getStart();
27381 while (node && node != body) {
27382 if (!isBogus(node)) {
27383 parents.push(node);
27386 node = node.parentNode;
27389 editor.selection.select(parents[parents.length - 1 - e.index]);
27390 editor.nodeChanged();
27393 editor.on('nodeChange', function(e) {
27394 var parents = [], selectionParents = e.parents, i = selectionParents.length;
27397 if (selectionParents[i].nodeType == 1 && !isBogus(selectionParents[i])) {
27398 var args = editor.fire('ResolveName', {
27399 name: selectionParents[i].nodeName.toLowerCase(),
27400 target: selectionParents[i]
27403 parents.push({name: args.name});
27407 self.data(parents);
27410 return self._super();
27415 // Included from: js/tinymce/classes/ui/FormItem.js
27420 * Copyright, Moxiecode Systems AB
27421 * Released under LGPL License.
27423 * License: http://www.tinymce.com/license
27424 * Contributing: http://www.tinymce.com/contributing
27428 * This class is a container created by the form element with
27429 * a label and control item.
27431 * @class tinymce.ui.FormItem
27432 * @extends tinymce.ui.Container
27433 * @setting {String} label Label to display for the form item.
27435 define("tinymce/ui/FormItem", [
27436 "tinymce/ui/Container"
27437 ], function(Container) {
27440 return Container.extend({
27450 * Renders the control as a HTML string.
27452 * @method renderHtml
27453 * @return {String} HTML representing the control.
27455 renderHtml: function() {
27456 var self = this, layout = self._layout, prefix = self.classPrefix;
27458 self.addClass('formitem');
27459 layout.preRender(self);
27462 '<div id="' + self._id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
27463 (self.settings.title ? ('<div id="' + self._id + '-title" class="' + prefix + 'title">' +
27464 self.settings.title + '</div>') : '') +
27465 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">' +
27466 (self.settings.html || '') + layout.renderHtml(self) +
27474 // Included from: js/tinymce/classes/ui/Form.js
27479 * Copyright, Moxiecode Systems AB
27480 * Released under LGPL License.
27482 * License: http://www.tinymce.com/license
27483 * Contributing: http://www.tinymce.com/contributing
27487 * This class creates a form container. A form container has the ability
27488 * to automatically wrap items in tinymce.ui.FormItem instances.
27490 * Each FormItem instance is a container for the label and the item.
27493 * tinymce.ui.Factory.create({
27496 * {type: 'textbox', label: 'My text box'}
27498 * }).renderTo(document.body);
27500 * @class tinymce.ui.Form
27501 * @extends tinymce.ui.Container
27503 define("tinymce/ui/Form", [
27504 "tinymce/ui/Container",
27505 "tinymce/ui/FormItem"
27506 ], function(Container, FormItem) {
27509 return Container.extend({
27511 containerCls: 'form',
27513 direction: 'column',
27522 * This method gets invoked before the control is rendered.
27524 * @method preRender
27526 preRender: function() {
27527 var self = this, items = self.items();
27529 // Wrap any labeled items in FormItems
27530 items.each(function(ctrl) {
27531 var formItem, label = ctrl.settings.label;
27534 formItem = new FormItem({
27536 autoResize: "overflow",
27537 defaults: {flex: 1},
27539 {type: 'label', text: label, flex: 0, forId: ctrl._id}
27543 formItem.type = 'formitem';
27545 if (typeof(ctrl.settings.flex) == "undefined") {
27546 ctrl.settings.flex = 1;
27549 self.replace(ctrl, formItem);
27550 formItem.add(ctrl);
27556 * Recalcs label widths.
27560 recalcLabels: function() {
27561 var self = this, maxLabelWidth = 0, labels = [], i, labelGap;
27563 if (self.settings.labelGapCalc === false) {
27567 self.items().filter('formitem').each(function(item) {
27568 var labelCtrl = item.items()[0], labelWidth = labelCtrl.getEl().clientWidth;
27570 maxLabelWidth = labelWidth > maxLabelWidth ? labelWidth : maxLabelWidth;
27571 labels.push(labelCtrl);
27574 labelGap = self.settings.labelGap || 0;
27578 labels[i].settings.minWidth = maxLabelWidth + labelGap;
27583 * Getter/setter for the visibility state.
27586 * @param {Boolean} [state] True/false state to show/hide.
27587 * @return {tinymce.ui.Form|Boolean} True/false state or current control.
27589 visible: function(state) {
27590 var val = this._super(state);
27592 if (state === true && this._rendered) {
27593 this.recalcLabels();
27600 * Fires a submit event with the serialized form.
27603 * @return {Object} Event arguments object.
27605 submit: function() {
27606 // Blur current control so a onchange is fired before submit
27607 var ctrl = this.getParentCtrl(document.activeElement);
27612 return this.fire('submit', {data: this.toJSON()});
27616 * Post render method. Called after the control has been rendered to the target.
27618 * @method postRender
27619 * @return {tinymce.ui.ComboBox} Current combobox instance.
27621 postRender: function() {
27625 self.recalcLabels();
27626 self.fromJSON(self.settings.data);
27631 // Included from: js/tinymce/classes/ui/FieldSet.js
27636 * Copyright, Moxiecode Systems AB
27637 * Released under LGPL License.
27639 * License: http://www.tinymce.com/license
27640 * Contributing: http://www.tinymce.com/contributing
27644 * This class creates fieldset containers.
27646 * @-x-less FieldSet.less
27647 * @class tinymce.ui.FieldSet
27648 * @extends tinymce.ui.Form
27650 define("tinymce/ui/FieldSet", [
27652 ], function(Form) {
27655 return Form.extend({
27657 containerCls: 'fieldset',
27659 direction: 'column',
27662 padding: "25 15 5 15",
27669 * Renders the control as a HTML string.
27671 * @method renderHtml
27672 * @return {String} HTML representing the control.
27674 renderHtml: function() {
27675 var self = this, layout = self._layout, prefix = self.classPrefix;
27678 layout.preRender(self);
27681 '<fieldset id="' + self._id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
27682 (self.settings.title ? ('<legend id="' + self._id + '-title" class="' + prefix + 'fieldset-title">' +
27683 self.settings.title + '</legend>') : '') +
27684 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">' +
27685 (self.settings.html || '') + layout.renderHtml(self) +
27693 // Included from: js/tinymce/classes/ui/FilePicker.js
27698 * Copyright, Moxiecode Systems AB
27699 * Released under LGPL License.
27701 * License: http://www.tinymce.com/license
27702 * Contributing: http://www.tinymce.com/contributing
27705 /*global tinymce:true */
27708 * This class creates a file picker control.
27710 * @class tinymce.ui.FilePicker
27711 * @extends tinymce.ui.ComboBox
27713 define("tinymce/ui/FilePicker", [
27714 "tinymce/ui/ComboBox"
27715 ], function(ComboBox) {
27718 return ComboBox.extend({
27720 * Constructs a new control instance with the specified settings.
27723 * @param {Object} settings Name/value object with settings.
27725 init: function(settings) {
27726 var self = this, editor = tinymce.activeEditor, fileBrowserCallback;
27728 settings.spellcheck = false;
27730 fileBrowserCallback = editor.settings.file_browser_callback;
27731 if (fileBrowserCallback) {
27732 settings.icon = 'browse';
27734 settings.onaction = function() {
27735 fileBrowserCallback(
27736 self.getEl('inp').id,
27737 self.getEl('inp').value,
27744 self._super(settings);
27749 // Included from: js/tinymce/classes/ui/FitLayout.js
27754 * Copyright, Moxiecode Systems AB
27755 * Released under LGPL License.
27757 * License: http://www.tinymce.com/license
27758 * Contributing: http://www.tinymce.com/contributing
27762 * This layout manager will resize the control to be the size of it's parent container.
27763 * In other words width: 100% and height: 100%.
27765 * @-x-less FitLayout.less
27766 * @class tinymce.ui.FitLayout
27767 * @extends tinymce.ui.AbsoluteLayout
27769 define("tinymce/ui/FitLayout", [
27770 "tinymce/ui/AbsoluteLayout"
27771 ], function(AbsoluteLayout) {
27774 return AbsoluteLayout.extend({
27776 * Recalculates the positions of the controls in the specified container.
27779 * @param {tinymce.ui.Container} container Container instance to recalc.
27781 recalc: function(container) {
27782 var contLayoutRect = container.layoutRect(), paddingBox = container.paddingBox();
27784 container.items().filter(':visible').each(function(ctrl) {
27786 x: paddingBox.left,
27788 w: contLayoutRect.innerW - paddingBox.right - paddingBox.left,
27789 h: contLayoutRect.innerH - paddingBox.top - paddingBox.bottom
27800 // Included from: js/tinymce/classes/ui/FlexLayout.js
27805 * Copyright, Moxiecode Systems AB
27806 * Released under LGPL License.
27808 * License: http://www.tinymce.com/license
27809 * Contributing: http://www.tinymce.com/contributing
27813 * This layout manager works similar to the CSS flex box.
27815 * @setting {String} direction row|row-reverse|column|column-reverse
27816 * @setting {Number} flex A positive-number to flex by.
27817 * @setting {String} align start|end|center|stretch
27818 * @setting {String} pack start|end|justify
27820 * @class tinymce.ui.FlexLayout
27821 * @extends tinymce.ui.AbsoluteLayout
27823 define("tinymce/ui/FlexLayout", [
27824 "tinymce/ui/AbsoluteLayout"
27825 ], function(AbsoluteLayout) {
27828 return AbsoluteLayout.extend({
27830 * Recalculates the positions of the controls in the specified container.
27833 * @param {tinymce.ui.Container} container Container instance to recalc.
27835 recalc: function(container) {
27836 // A ton of variables, needs to be in the same scope for performance
27837 var i, l, items, contLayoutRect, contPaddingBox, contSettings, align, pack, spacing, totalFlex, availableSpace, direction;
27838 var ctrl, ctrlLayoutRect, ctrlSettings, flex, maxSizeItems = [], size, maxSize, ratio, rect, pos, maxAlignEndPos;
27839 var sizeName, minSizeName, posName, maxSizeName, beforeName, innerSizeName, afterName, deltaSizeName, contentSizeName;
27840 var alignAxisName, alignInnerSizeName, alignSizeName, alignMinSizeName, alignMaxSizeName, alignBeforeName, alignAfterName;
27841 var alignDeltaSizeName, alignContentSizeName;
27842 var max = Math.max, min = Math.min;
27844 // Get container items, properties and settings
27845 items = container.items().filter(':visible');
27846 contLayoutRect = container.layoutRect();
27847 contPaddingBox = container._paddingBox;
27848 contSettings = container.settings;
27849 direction = contSettings.direction;
27850 align = contSettings.align;
27851 pack = contSettings.pack;
27852 spacing = contSettings.spacing || 0;
27854 if (direction == "row-reversed" || direction == "column-reverse") {
27855 items = items.set(items.toArray().reverse());
27856 direction = direction.split('-')[0];
27859 // Setup axis variable name for row/column direction since the calculations is the same
27860 if (direction == "column") {
27863 minSizeName = "minH";
27864 maxSizeName = "maxH";
27865 innerSizeName = "innerH";
27866 beforeName = 'top';
27867 afterName = 'bottom';
27868 deltaSizeName = "deltaH";
27869 contentSizeName = "contentH";
27871 alignBeforeName = "left";
27872 alignSizeName = "w";
27873 alignAxisName = "x";
27874 alignInnerSizeName = "innerW";
27875 alignMinSizeName = "minW";
27876 alignMaxSizeName = "maxW";
27877 alignAfterName = "right";
27878 alignDeltaSizeName = "deltaW";
27879 alignContentSizeName = "contentW";
27883 minSizeName = "minW";
27884 maxSizeName = "maxW";
27885 innerSizeName = "innerW";
27886 beforeName = 'left';
27887 afterName = 'right';
27888 deltaSizeName = "deltaW";
27889 contentSizeName = "contentW";
27891 alignBeforeName = "top";
27892 alignSizeName = "h";
27893 alignAxisName = "y";
27894 alignInnerSizeName = "innerH";
27895 alignMinSizeName = "minH";
27896 alignMaxSizeName = "maxH";
27897 alignAfterName = "bottom";
27898 alignDeltaSizeName = "deltaH";
27899 alignContentSizeName = "contentH";
27902 // Figure out total flex, availableSpace and collect any max size elements
27903 availableSpace = contLayoutRect[innerSizeName] - contPaddingBox[beforeName] - contPaddingBox[beforeName];
27904 maxAlignEndPos = totalFlex = 0;
27905 for (i = 0, l = items.length; i < l; i++) {
27907 ctrlLayoutRect = ctrl.layoutRect();
27908 ctrlSettings = ctrl.settings;
27909 flex = ctrlSettings.flex;
27910 availableSpace -= (i < l - 1 ? spacing : 0);
27915 // Flexed item has a max size then we need to check if we will hit that size
27916 if (ctrlLayoutRect[maxSizeName]) {
27917 maxSizeItems.push(ctrl);
27920 ctrlLayoutRect.flex = flex;
27923 availableSpace -= ctrlLayoutRect[minSizeName];
27925 // Calculate the align end position to be used to check for overflow/underflow
27926 size = contPaddingBox[alignBeforeName] + ctrlLayoutRect[alignMinSizeName] + contPaddingBox[alignAfterName];
27927 if (size > maxAlignEndPos) {
27928 maxAlignEndPos = size;
27932 // Calculate minW/minH
27934 if (availableSpace < 0) {
27935 rect[minSizeName] = contLayoutRect[minSizeName] - availableSpace + contLayoutRect[deltaSizeName];
27937 rect[minSizeName] = contLayoutRect[innerSizeName] - availableSpace + contLayoutRect[deltaSizeName];
27940 rect[alignMinSizeName] = maxAlignEndPos + contLayoutRect[alignDeltaSizeName];
27942 rect[contentSizeName] = contLayoutRect[innerSizeName] - availableSpace;
27943 rect[alignContentSizeName] = maxAlignEndPos;
27944 rect.minW = min(rect.minW, contLayoutRect.maxW);
27945 rect.minH = min(rect.minH, contLayoutRect.maxH);
27946 rect.minW = max(rect.minW, contLayoutRect.startMinWidth);
27947 rect.minH = max(rect.minH, contLayoutRect.startMinHeight);
27949 // Resize container container if minSize was changed
27950 if (contLayoutRect.autoResize && (rect.minW != contLayoutRect.minW || rect.minH != contLayoutRect.minH)) {
27951 rect.w = rect.minW;
27952 rect.h = rect.minH;
27954 container.layoutRect(rect);
27955 this.recalc(container);
27957 // Forced recalc for example if items are hidden/shown
27958 if (container._lastRect === null) {
27959 var parentCtrl = container.parent();
27961 parentCtrl._lastRect = null;
27962 parentCtrl.recalc();
27969 // Handle max size elements, check if they will become to wide with current options
27970 ratio = availableSpace / totalFlex;
27971 for (i = 0, l = maxSizeItems.length; i < l; i++) {
27972 ctrl = maxSizeItems[i];
27973 ctrlLayoutRect = ctrl.layoutRect();
27974 maxSize = ctrlLayoutRect[maxSizeName];
27975 size = ctrlLayoutRect[minSizeName] + Math.ceil(ctrlLayoutRect.flex * ratio);
27977 if (size > maxSize) {
27978 availableSpace -= (ctrlLayoutRect[maxSizeName] - ctrlLayoutRect[minSizeName]);
27979 totalFlex -= ctrlLayoutRect.flex;
27980 ctrlLayoutRect.flex = 0;
27981 ctrlLayoutRect.maxFlexSize = maxSize;
27983 ctrlLayoutRect.maxFlexSize = 0;
27987 // Setup new ratio, target layout rect, start position
27988 ratio = availableSpace / totalFlex;
27989 pos = contPaddingBox[beforeName];
27992 // Handle pack setting moves the start position to end, center
27993 if (totalFlex === 0) {
27994 if (pack == "end") {
27995 pos = availableSpace + contPaddingBox[beforeName];
27996 } else if (pack == "center") {
27998 (contLayoutRect[innerSizeName] / 2) - ((contLayoutRect[innerSizeName] - availableSpace) / 2)
27999 ) + contPaddingBox[beforeName];
28002 pos = contPaddingBox[beforeName];
28004 } else if (pack == "justify") {
28005 pos = contPaddingBox[beforeName];
28006 spacing = Math.floor(availableSpace / (items.length - 1));
28010 // Default aligning (start) the other ones needs to be calculated while doing the layout
28011 rect[alignAxisName] = contPaddingBox[alignBeforeName];
28013 // Start laying out controls
28014 for (i = 0, l = items.length; i < l; i++) {
28016 ctrlLayoutRect = ctrl.layoutRect();
28017 size = ctrlLayoutRect.maxFlexSize || ctrlLayoutRect[minSizeName];
28019 // Align the control on the other axis
28020 if (align === "center") {
28021 rect[alignAxisName] = Math.round((contLayoutRect[alignInnerSizeName] / 2) - (ctrlLayoutRect[alignSizeName] / 2));
28022 } else if (align === "stretch") {
28023 rect[alignSizeName] = max(
28024 ctrlLayoutRect[alignMinSizeName] || 0,
28025 contLayoutRect[alignInnerSizeName] - contPaddingBox[alignBeforeName] - contPaddingBox[alignAfterName]
28027 rect[alignAxisName] = contPaddingBox[alignBeforeName];
28028 } else if (align === "end") {
28029 rect[alignAxisName] = contLayoutRect[alignInnerSizeName] - ctrlLayoutRect[alignSizeName] - contPaddingBox.top;
28032 // Calculate new size based on flex
28033 if (ctrlLayoutRect.flex > 0) {
28034 size += Math.ceil(ctrlLayoutRect.flex * ratio);
28037 rect[sizeName] = size;
28038 rect[posName] = pos;
28039 ctrl.layoutRect(rect);
28041 // Recalculate containers
28046 // Move x/y position
28047 pos += size + spacing;
28053 // Included from: js/tinymce/classes/ui/FlowLayout.js
28058 * Copyright, Moxiecode Systems AB
28059 * Released under LGPL License.
28061 * License: http://www.tinymce.com/license
28062 * Contributing: http://www.tinymce.com/contributing
28066 * This layout manager will place the controls by using the browsers native layout.
28068 * @-x-less FlowLayout.less
28069 * @class tinymce.ui.FlowLayout
28070 * @extends tinymce.ui.Layout
28072 define("tinymce/ui/FlowLayout", [
28073 "tinymce/ui/Layout"
28074 ], function(Layout) {
28075 return Layout.extend({
28077 containerClass: 'flow-layout',
28078 controlClass: 'flow-layout-item',
28083 * Recalculates the positions of the controls in the specified container.
28086 * @param {tinymce.ui.Container} container Container instance to recalc.
28088 recalc: function(container) {
28089 container.items().filter(':visible').each(function(ctrl) {
28098 // Included from: js/tinymce/classes/ui/FormatControls.js
28101 * FormatControls.js
28103 * Copyright, Moxiecode Systems AB
28104 * Released under LGPL License.
28106 * License: http://www.tinymce.com/license
28107 * Contributing: http://www.tinymce.com/contributing
28111 * Internal class containing all TinyMCE specific control types such as
28112 * format listboxes, fontlist boxes, toolbar buttons etc.
28114 * @class tinymce.ui.FormatControls
28116 define("tinymce/ui/FormatControls", [
28117 "tinymce/ui/Control",
28118 "tinymce/ui/Widget",
28119 "tinymce/ui/FloatPanel",
28120 "tinymce/util/Tools",
28121 "tinymce/EditorManager",
28123 ], function(Control, Widget, FloatPanel, Tools, EditorManager, Env) {
28124 var each = Tools.each;
28126 EditorManager.on('AddEditor', function(e) {
28127 registerControls(e.editor);
28130 Control.translate = function(text) {
28131 return EditorManager.translate(text);
28134 Widget.tooltips = !Env.iOS;
28136 function registerControls(editor) {
28139 // Generates a preview for a format
28140 function getPreviewCss(format) {
28141 var name, previewElm, dom = editor.dom;
28142 var previewCss = '', parentFontSize, previewStyles;
28144 previewStyles = editor.settings.preview_styles;
28146 // No preview forced
28147 if (previewStyles === false) {
28152 if (!previewStyles) {
28153 previewStyles = 'font-family font-size font-weight text-decoration ' +
28154 'text-transform color background-color border border-radius';
28157 // Removes any variables since these can't be previewed
28158 function removeVars(val) {
28159 return val.replace(/%(\w+)/g, '');
28162 // Create block/inline element to use for preview
28163 format = editor.formatter.get(format);
28168 format = format[0];
28169 name = format.block || format.inline || 'span';
28170 previewElm = dom.create(name);
28172 // Add format styles to preview element
28173 each(format.styles, function(value, name) {
28174 value = removeVars(value);
28177 dom.setStyle(previewElm, name, value);
28181 // Add attributes to preview element
28182 each(format.attributes, function(value, name) {
28183 value = removeVars(value);
28186 dom.setAttrib(previewElm, name, value);
28190 // Add classes to preview element
28191 each(format.classes, function(value) {
28192 value = removeVars(value);
28194 if (!dom.hasClass(previewElm, value)) {
28195 dom.addClass(previewElm, value);
28199 editor.fire('PreviewFormats');
28201 // Add the previewElm outside the visual area
28202 dom.setStyles(previewElm, {position: 'absolute', left: -0xFFFF});
28203 editor.getBody().appendChild(previewElm);
28205 // Get parent container font size so we can compute px values out of em/% for older IE:s
28206 parentFontSize = dom.getStyle(editor.getBody(), 'fontSize', true);
28207 parentFontSize = /px$/.test(parentFontSize) ? parseInt(parentFontSize, 10) : 0;
28209 each(previewStyles.split(' '), function(name) {
28210 var value = dom.getStyle(previewElm, name, true);
28212 // If background is transparent then check if the body has a background color we can use
28213 if (name == 'background-color' && /transparent|rgba\s*\([^)]+,\s*0\)/.test(value)) {
28214 value = dom.getStyle(editor.getBody(), name, true);
28216 // Ignore white since it's the default color, not the nicest fix
28217 // TODO: Fix this by detecting runtime style
28218 if (dom.toHex(value).toLowerCase() == '#ffffff') {
28223 if (name == 'color') {
28224 // Ignore black since it's the default color, not the nicest fix
28225 // TODO: Fix this by detecting runtime style
28226 if (dom.toHex(value).toLowerCase() == '#000000') {
28231 // Old IE won't calculate the font size so we need to do that manually
28232 if (name == 'font-size') {
28233 if (/em|%$/.test(value)) {
28234 if (parentFontSize === 0) {
28238 // Convert font size from em/% to px
28239 value = parseFloat(value, 10) / (/%$/.test(value) ? 100 : 1);
28240 value = (value * parentFontSize) + 'px';
28244 if (name == "border" && value) {
28245 previewCss += 'padding:0 2px;';
28248 previewCss += name + ':' + value + ';';
28251 editor.fire('AfterPreviewFormats');
28253 //previewCss += 'line-height:normal';
28255 dom.remove(previewElm);
28260 function createListBoxChangeHandler(items, formatName) {
28261 return function() {
28264 editor.on('nodeChange', function(e) {
28265 var formatter = editor.formatter;
28268 each(e.parents, function(node) {
28269 each(items, function(item) {
28271 if (formatter.matchNode(node, formatName, {value: item.value})) {
28272 value = item.value;
28275 if (formatter.matchNode(node, item.value)) {
28276 value = item.value;
28295 function createFormats(formats) {
28296 formats = formats.split(';');
28298 var i = formats.length;
28300 formats[i] = formats[i].split('=');
28306 function createFormatMenu() {
28307 var count = 0, newFormats = [];
28309 var defaultStyleFormats = [
28310 {title: 'Headers', items: [
28311 {title: 'Header 1', format: 'h1'},
28312 {title: 'Header 2', format: 'h2'},
28313 {title: 'Header 3', format: 'h3'},
28314 {title: 'Header 4', format: 'h4'},
28315 {title: 'Header 5', format: 'h5'},
28316 {title: 'Header 6', format: 'h6'}
28319 {title: 'Inline', items: [
28320 {title: 'Bold', icon: 'bold', format: 'bold'},
28321 {title: 'Italic', icon: 'italic', format: 'italic'},
28322 {title: 'Underline', icon: 'underline', format: 'underline'},
28323 {title: 'Strikethrough', icon: 'strikethrough', format: 'strikethrough'},
28324 {title: 'Superscript', icon: 'superscript', format: 'superscript'},
28325 {title: 'Subscript', icon: 'subscript', format: 'subscript'},
28326 {title: 'Code', icon: 'code', format: 'code'}
28329 {title: 'Blocks', items: [
28330 {title: 'Paragraph', format: 'p'},
28331 {title: 'Blockquote', format: 'blockquote'},
28332 {title: 'Div', format: 'div'},
28333 {title: 'Pre', format: 'pre'}
28336 {title: 'Alignment', items: [
28337 {title: 'Left', icon: 'alignleft', format: 'alignleft'},
28338 {title: 'Center', icon: 'aligncenter', format: 'aligncenter'},
28339 {title: 'Right', icon: 'alignright', format: 'alignright'},
28340 {title: 'Justify', icon: 'alignjustify', format: 'alignjustify'}
28344 function createMenu(formats) {
28351 each(formats, function(format) {
28353 text: format.title,
28357 if (format.items) {
28358 menuItem.menu = createMenu(format.items);
28360 var formatName = format.format || "custom" + count++;
28362 if (!format.format) {
28363 format.name = formatName;
28364 newFormats.push(format);
28367 menuItem.format = formatName;
28370 menu.push(menuItem);
28376 editor.on('init', function() {
28377 each(newFormats, function(format) {
28378 editor.formatter.register(format.name, format);
28382 var menu = createMenu(editor.settings.style_formats || defaultStyleFormats);
28387 onPostRender: function(e) {
28388 editor.fire('renderFormatsMenu', {control: e.control});
28393 textStyle: function() {
28394 if (this.settings.format) {
28395 return getPreviewCss(this.settings.format);
28399 onPostRender: function() {
28400 var self = this, formatName = this.settings.format;
28403 self.parent().on('show', function() {
28404 self.disabled(!editor.formatter.canApply(formatName));
28405 self.active(editor.formatter.match(formatName));
28410 onclick: function() {
28411 if (this.settings.format) {
28412 toggleFormat(this.settings.format);
28421 formatMenu = createFormatMenu();
28423 // Simple format controls <control/format>:<UI text>
28427 underline: 'Underline',
28428 strikethrough: 'Strikethrough',
28429 subscript: 'Subscript',
28430 superscript: 'Superscript'
28431 }, function(text, name) {
28432 editor.addButton(name, {
28434 onPostRender: function() {
28438 if (editor.formatter) {
28439 editor.formatter.formatChanged(name, function(state) {
28440 self.active(state);
28443 editor.on('init', function() {
28444 editor.formatter.formatChanged(name, function(state) {
28445 self.active(state);
28450 onclick: function() {
28451 toggleFormat(name);
28456 // Simple command controls <control>:[<UI text>,<Command>]
28458 outdent: ['Decrease indent', 'Outdent'],
28459 indent: ['Increase indent', 'Indent'],
28460 cut: ['Cut', 'Cut'],
28461 copy: ['Copy', 'Copy'],
28462 paste: ['Paste', 'Paste'],
28463 help: ['Help', 'mceHelp'],
28464 selectall: ['Select all', 'SelectAll'],
28465 hr: ['Insert horizontal rule', 'InsertHorizontalRule'],
28466 removeformat: ['Clear formatting', 'RemoveFormat'],
28467 visualaid: ['Visual aids', 'mceToggleVisualAid'],
28468 newdocument: ['New document', 'mceNewDocument']
28469 }, function(item, name) {
28470 editor.addButton(name, {
28476 // Simple command controls with format state
28478 blockquote: ['Toggle blockquote', 'mceBlockQuote'],
28479 numlist: ['Numbered list', 'InsertOrderedList'],
28480 bullist: ['Bullet list', 'InsertUnorderedList'],
28481 subscript: ['Subscript', 'Subscript'],
28482 superscript: ['Superscript', 'Superscript'],
28483 alignleft: ['Align left', 'JustifyLeft'],
28484 aligncenter: ['Align center', 'JustifyCenter'],
28485 alignright: ['Align right', 'JustifyRight'],
28486 alignjustify: ['Justify', 'JustifyFull']
28487 }, function(item, name) {
28488 editor.addButton(name, {
28491 onPostRender: function() {
28495 if (editor.formatter) {
28496 editor.formatter.formatChanged(name, function(state) {
28497 self.active(state);
28500 editor.on('init', function() {
28501 editor.formatter.formatChanged(name, function(state) {
28502 self.active(state);
28510 function hasUndo() {
28511 return editor.undoManager ? editor.undoManager.hasUndo() : false;
28514 function hasRedo() {
28515 return editor.undoManager ? editor.undoManager.hasRedo() : false;
28518 function toggleUndoState() {
28521 self.disabled(!hasUndo());
28522 editor.on('Undo Redo AddUndo TypingUndo', function() {
28523 self.disabled(!hasUndo());
28527 function toggleRedoState() {
28530 self.disabled(!hasRedo());
28531 editor.on('Undo Redo AddUndo TypingUndo', function() {
28532 self.disabled(!hasRedo());
28536 function toggleVisualAidState() {
28539 editor.on('VisualAid', function(e) {
28540 self.active(e.hasVisual);
28543 self.active(editor.hasVisual);
28546 editor.addButton('undo', {
28548 onPostRender: toggleUndoState,
28552 editor.addButton('redo', {
28554 onPostRender: toggleRedoState,
28558 editor.addMenuItem('newdocument', {
28559 text: 'New document',
28560 shortcut: 'Ctrl+N',
28561 icon: 'newdocument',
28562 cmd: 'mceNewDocument'
28565 editor.addMenuItem('undo', {
28568 shortcut: 'Ctrl+Z',
28569 onPostRender: toggleUndoState,
28573 editor.addMenuItem('redo', {
28576 shortcut: 'Ctrl+Y',
28577 onPostRender: toggleRedoState,
28581 editor.addMenuItem('visualaid', {
28582 text: 'Visual aids',
28584 onPostRender: toggleVisualAidState,
28585 cmd: 'mceToggleVisualAid'
28589 cut: ['Cut', 'Cut', 'Ctrl+X'],
28590 copy: ['Copy', 'Copy', 'Ctrl+C'],
28591 paste: ['Paste', 'Paste', 'Ctrl+V'],
28592 selectall: ['Select all', 'SelectAll', 'Ctrl+A'],
28593 bold: ['Bold', 'Bold', 'Ctrl+B'],
28594 italic: ['Italic', 'Italic', 'Ctrl+I'],
28595 underline: ['Underline', 'Underline'],
28596 strikethrough: ['Strikethrough', 'Strikethrough'],
28597 subscript: ['Subscript', 'Subscript'],
28598 superscript: ['Superscript', 'Superscript'],
28599 removeformat: ['Clear formatting', 'RemoveFormat']
28600 }, function(item, name) {
28601 editor.addMenuItem(name, {
28609 editor.on('mousedown', function() {
28610 FloatPanel.hideAll();
28613 function toggleFormat(fmt) {
28615 fmt = fmt.control.value();
28619 editor.execCommand('mceToggleFormat', false, fmt);
28623 editor.addButton('styleselect', {
28624 type: 'menubutton',
28629 editor.addButton('formatselect', function() {
28630 var items = [], blocks = createFormats(editor.settings.block_formats ||
28632 'Address=address;' +
28642 each(blocks, function(block) {
28646 textStyle: function() {
28647 return getPreviewCss(block[1]);
28654 text: {raw: blocks[0][0]},
28657 onselect: toggleFormat,
28658 onPostRender: createListBoxChangeHandler(items)
28662 editor.addButton('fontselect', function() {
28663 var defaultFontsFormats =
28664 'Andale Mono=andale mono,times;' +
28665 'Arial=arial,helvetica,sans-serif;' +
28666 'Arial Black=arial black,avant garde;' +
28667 'Book Antiqua=book antiqua,palatino;' +
28668 'Comic Sans MS=comic sans ms,sans-serif;' +
28669 'Courier New=courier new,courier;' +
28670 'Georgia=georgia,palatino;' +
28671 'Helvetica=helvetica;' +
28672 'Impact=impact,chicago;' +
28674 'Tahoma=tahoma,arial,helvetica,sans-serif;' +
28675 'Terminal=terminal,monaco;' +
28676 'Times New Roman=times new roman,times;' +
28677 'Trebuchet MS=trebuchet ms,geneva;' +
28678 'Verdana=verdana,geneva;' +
28679 'Webdings=webdings;' +
28680 'Wingdings=wingdings,zapf dingbats';
28682 var items = [], fonts = createFormats(editor.settings.font_formats || defaultFontsFormats);
28684 each(fonts, function(font) {
28686 text: {raw: font[0]},
28688 textStyle: font[1].indexOf('dings') == -1 ? 'font-family:' + font[1] : ''
28694 text: 'Font Family',
28695 tooltip: 'Font Family',
28698 onPostRender: createListBoxChangeHandler(items, 'fontname'),
28699 onselect: function(e) {
28700 if (e.control.settings.value) {
28701 editor.execCommand('FontName', false, e.control.settings.value);
28707 editor.addButton('fontsizeselect', function() {
28708 var items = [], defaultFontsizeFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
28709 var fontsize_formats = editor.settings.fontsize_formats || defaultFontsizeFormats;
28711 each(fontsize_formats.split(' '), function(item) {
28712 items.push({text: item, value: item});
28717 text: 'Font Sizes',
28718 tooltip: 'Font Sizes',
28721 onPostRender: createListBoxChangeHandler(items, 'fontsize'),
28722 onclick: function(e) {
28723 if (e.control.settings.value) {
28724 editor.execCommand('FontSize', false, e.control.settings.value);
28730 editor.addMenuItem('formats', {
28737 // Included from: js/tinymce/classes/ui/GridLayout.js
28742 * Copyright, Moxiecode Systems AB
28743 * Released under LGPL License.
28745 * License: http://www.tinymce.com/license
28746 * Contributing: http://www.tinymce.com/contributing
28750 * This layout manager places controls in a grid.
28752 * @setting {Number} spacing Spacing between controls.
28753 * @setting {Number} spacingH Horizontal spacing between controls.
28754 * @setting {Number} spacingV Vertical spacing between controls.
28755 * @setting {Number} columns Number of columns to use.
28756 * @setting {String/Array} alignH start|end|center|stretch or array of values for each column.
28757 * @setting {String/Array} alignV start|end|center|stretch or array of values for each column.
28758 * @setting {String} pack start|end
28760 * @class tinymce.ui.GridLayout
28761 * @extends tinymce.ui.AbsoluteLayout
28763 define("tinymce/ui/GridLayout", [
28764 "tinymce/ui/AbsoluteLayout"
28765 ], function(AbsoluteLayout) {
28768 return AbsoluteLayout.extend({
28770 * Recalculates the positions of the controls in the specified container.
28773 * @param {tinymce.ui.Container} container Container instance to recalc.
28775 recalc: function(container) {
28776 var settings = container.settings, rows, cols, items, contLayoutRect, width, height, rect,
28777 ctrlLayoutRect, ctrl, x, y, posX, posY, ctrlSettings, contPaddingBox, align, spacingH, spacingV, alignH, alignV, maxX, maxY,
28778 colWidths = [], rowHeights = [], ctrlMinWidth, ctrlMinHeight, alignX, alignY, availableWidth, availableHeight;
28780 // Get layout settings
28781 settings = container.settings;
28782 items = container.items().filter(':visible');
28783 contLayoutRect = container.layoutRect();
28784 cols = settings.columns || Math.ceil(Math.sqrt(items.length));
28785 rows = Math.ceil(items.length / cols);
28786 spacingH = settings.spacingH || settings.spacing || 0;
28787 spacingV = settings.spacingV || settings.spacing || 0;
28788 alignH = settings.alignH || settings.align;
28789 alignV = settings.alignV || settings.align;
28790 contPaddingBox = container._paddingBox;
28792 if (alignH && typeof(alignH) == "string") {
28796 if (alignV && typeof(alignV) == "string") {
28800 // Zero padd columnWidths
28801 for (x = 0; x < cols; x++) {
28805 // Zero padd rowHeights
28806 for (y = 0; y < rows; y++) {
28807 rowHeights.push(0);
28810 // Calculate columnWidths and rowHeights
28811 for (y = 0; y < rows; y++) {
28812 for (x = 0; x < cols; x++) {
28813 ctrl = items[y * cols + x];
28820 ctrlLayoutRect = ctrl.layoutRect();
28821 ctrlMinWidth = ctrlLayoutRect.minW;
28822 ctrlMinHeight = ctrlLayoutRect.minH;
28824 colWidths[x] = ctrlMinWidth > colWidths[x] ? ctrlMinWidth : colWidths[x];
28825 rowHeights[y] = ctrlMinHeight > rowHeights[y] ? ctrlMinHeight : rowHeights[y];
28830 availableWidth = contLayoutRect.innerW - contPaddingBox.left - contPaddingBox.right;
28831 for (maxX = 0, x = 0; x < cols; x++) {
28832 maxX += colWidths[x] + (x > 0 ? spacingH : 0);
28833 availableWidth -= (x > 0 ? spacingH : 0) + colWidths[x];
28837 availableHeight = contLayoutRect.innerH - contPaddingBox.top - contPaddingBox.bottom;
28838 for (maxY = 0, y = 0; y < rows; y++) {
28839 maxY += rowHeights[y] + (y > 0 ? spacingV : 0);
28840 availableHeight -= (y > 0 ? spacingV : 0) + rowHeights[y];
28843 maxX += contPaddingBox.left + contPaddingBox.right;
28844 maxY += contPaddingBox.top + contPaddingBox.bottom;
28846 // Calculate minW/minH
28848 rect.minW = maxX + (contLayoutRect.w - contLayoutRect.innerW);
28849 rect.minH = maxY + (contLayoutRect.h - contLayoutRect.innerH);
28851 rect.contentW = rect.minW - contLayoutRect.deltaW;
28852 rect.contentH = rect.minH - contLayoutRect.deltaH;
28853 rect.minW = Math.min(rect.minW, contLayoutRect.maxW);
28854 rect.minH = Math.min(rect.minH, contLayoutRect.maxH);
28855 rect.minW = Math.max(rect.minW, contLayoutRect.startMinWidth);
28856 rect.minH = Math.max(rect.minH, contLayoutRect.startMinHeight);
28858 // Resize container container if minSize was changed
28859 if (contLayoutRect.autoResize && (rect.minW != contLayoutRect.minW || rect.minH != contLayoutRect.minH)) {
28860 rect.w = rect.minW;
28861 rect.h = rect.minH;
28863 container.layoutRect(rect);
28864 this.recalc(container);
28866 // Forced recalc for example if items are hidden/shown
28867 if (container._lastRect === null) {
28868 var parentCtrl = container.parent();
28870 parentCtrl._lastRect = null;
28871 parentCtrl.recalc();
28878 // Update contentW/contentH so absEnd moves correctly
28879 if (contLayoutRect.autoResize) {
28880 rect = container.layoutRect(rect);
28881 rect.contentW = rect.minW - contLayoutRect.deltaW;
28882 rect.contentH = rect.minH - contLayoutRect.deltaH;
28887 if (settings.packV == 'start') {
28890 flexV = availableHeight > 0 ? Math.floor(availableHeight / rows) : 0;
28893 // Calculate totalFlex
28895 var flexWidths = settings.flexWidths;
28897 for (x = 0; x < flexWidths.length; x++) {
28898 totalFlex += flexWidths[x];
28904 // Calculate new column widths based on flex values
28905 var ratio = availableWidth / totalFlex;
28906 for (x = 0; x < cols; x++) {
28907 colWidths[x] += flexWidths ? Math.ceil(flexWidths[x] * ratio) : ratio;
28910 // Move/resize controls
28911 posY = contPaddingBox.top;
28912 for (y = 0; y < rows; y++) {
28913 posX = contPaddingBox.left;
28914 height = rowHeights[y] + flexV;
28916 for (x = 0; x < cols; x++) {
28917 ctrl = items[y * cols + x];
28919 // No more controls to render then break
28924 // Get control settings and calculate x, y
28925 ctrlSettings = ctrl.settings;
28926 ctrlLayoutRect = ctrl.layoutRect();
28927 width = colWidths[x];
28928 alignX = alignY = 0;
28929 ctrlLayoutRect.x = posX;
28930 ctrlLayoutRect.y = posY;
28932 // Align control horizontal
28933 align = ctrlSettings.alignH || (alignH ? (alignH[x] || alignH[0]) : null);
28934 if (align == "center") {
28935 ctrlLayoutRect.x = posX + (width / 2) - (ctrlLayoutRect.w / 2);
28936 } else if (align == "right") {
28937 ctrlLayoutRect.x = posX + width - ctrlLayoutRect.w;
28938 } else if (align == "stretch") {
28939 ctrlLayoutRect.w = width;
28942 // Align control vertical
28943 align = ctrlSettings.alignV || (alignV ? (alignV[x] || alignV[0]) : null);
28944 if (align == "center") {
28945 ctrlLayoutRect.y = posY + (height / 2) - (ctrlLayoutRect.h / 2);
28946 } else if (align == "bottom") {
28947 ctrlLayoutRect.y = posY + height - ctrlLayoutRect.h;
28948 } else if (align == "stretch") {
28949 ctrlLayoutRect.h = height;
28952 ctrl.layoutRect(ctrlLayoutRect);
28954 posX += width + spacingH;
28961 posY += height + spacingV;
28967 // Included from: js/tinymce/classes/ui/Iframe.js
28972 * Copyright, Moxiecode Systems AB
28973 * Released under LGPL License.
28975 * License: http://www.tinymce.com/license
28976 * Contributing: http://www.tinymce.com/contributing
28979 /*jshint scripturl:true */
28982 * This class creates an iframe.
28984 * @setting {String} url Url to open in the iframe.
28986 * @-x-less Iframe.less
28987 * @class tinymce.ui.Iframe
28988 * @extends tinymce.ui.Widget
28990 define("tinymce/ui/Iframe", [
28991 "tinymce/ui/Widget"
28992 ], function(Widget) {
28995 return Widget.extend({
28997 * Renders the control as a HTML string.
28999 * @method renderHtml
29000 * @return {String} HTML representing the control.
29002 renderHtml: function() {
29005 self.addClass('iframe');
29006 self.canFocus = false;
29009 '<iframe id="' + self._id + '" class="' + self.classes() + '" tabindex="-1" src="' +
29010 (self.settings.url || "javascript:\'\'") + '" frameborder="0"></iframe>'
29015 * Setter for the iframe source.
29018 * @param {String} src Source URL for iframe.
29020 src: function(src) {
29021 this.getEl().src = src;
29025 * Inner HTML for the iframe.
29028 * @param {String} html HTML string to set as HTML inside the iframe.
29029 * @param {function} callback Optional callback to execute when the iframe body is filled with contents.
29030 * @return {tinymce.ui.Iframe} Current iframe control.
29032 html: function(html, callback) {
29033 var self = this, body = this.getEl().contentWindow.document.body;
29035 // Wait for iframe to initialize IE 10 takes time
29037 setTimeout(function() {
29041 body.innerHTML = html;
29053 // Included from: js/tinymce/classes/ui/Label.js
29058 * Copyright, Moxiecode Systems AB
29059 * Released under LGPL License.
29061 * License: http://www.tinymce.com/license
29062 * Contributing: http://www.tinymce.com/contributing
29066 * This class creates a label element. A label is a simple text control
29067 * that can be bound to other controls.
29069 * @-x-less Label.less
29070 * @class tinymce.ui.Label
29071 * @extends tinymce.ui.Widget
29073 define("tinymce/ui/Label", [
29074 "tinymce/ui/Widget"
29075 ], function(Widget) {
29078 return Widget.extend({
29080 * Constructs a instance with the specified settings.
29083 * @param {Object} settings Name/value object with settings.
29084 * @param {Boolean} multiline Multiline label.
29086 init: function(settings) {
29089 self._super(settings);
29090 self.addClass('widget');
29091 self.addClass('label');
29092 self.canFocus = false;
29094 if (settings.multiline) {
29095 self.addClass('autoscroll');
29098 if (settings.strong) {
29099 self.addClass('strong');
29104 * Initializes the current controls layout rect.
29105 * This will be executed by the layout managers to determine the
29106 * default minWidth/minHeight etc.
29108 * @method initLayoutRect
29109 * @return {Object} Layout rect instance.
29111 initLayoutRect: function() {
29112 var self = this, layoutRect = self._super();
29114 if (self.settings.multiline) {
29115 // Check if the text fits within maxW if not then try word wrapping it
29116 if (self.getEl().offsetWidth > layoutRect.maxW) {
29117 layoutRect.minW = layoutRect.maxW;
29118 self.addClass('multiline');
29121 self.getEl().style.width = layoutRect.minW + 'px';
29122 layoutRect.startMinH = layoutRect.h = layoutRect.minH = Math.min(layoutRect.maxH, self.getEl().offsetHeight);
29129 * Sets/gets the disabled state on the control.
29132 * @param {Boolean} state Value to set to control.
29133 * @return {Boolean/tinymce.ui.Label} Current control on a set operation or current state on a get.
29135 disabled: function(state) {
29136 var self = this, undef;
29138 if (state !== undef) {
29139 self.toggleClass('label-disabled', state);
29141 if (self._rendered) {
29142 self.getEl()[0].className = self.classes();
29146 return self._super(state);
29150 * Repaints the control after a layout operation.
29154 repaint: function() {
29157 if (!self.settings.multiline) {
29158 self.getEl().style.lineHeight = self.layoutRect().h + 'px';
29161 return self._super();
29165 * Sets/gets the current label text.
29168 * @param {String} [text] New label text.
29169 * @return {String|tinymce.ui.Label} Current text or current label instance.
29171 text: function(text) {
29174 if (self._rendered && text) {
29175 this.innerHtml(self.encode(text));
29178 return self._super(text);
29182 * Renders the control as a HTML string.
29184 * @method renderHtml
29185 * @return {String} HTML representing the control.
29187 renderHtml: function() {
29188 var self = this, forId = self.settings.forId;
29191 '<label id="' + self._id + '" class="' + self.classes() + '"' + (forId ? ' for="' + forId : '') + '">' +
29192 self.encode(self._text) +
29199 // Included from: js/tinymce/classes/ui/Toolbar.js
29204 * Copyright, Moxiecode Systems AB
29205 * Released under LGPL License.
29207 * License: http://www.tinymce.com/license
29208 * Contributing: http://www.tinymce.com/contributing
29212 * Creates a new toolbar.
29214 * @class tinymce.ui.Toolbar
29215 * @extends tinymce.ui.Container
29217 define("tinymce/ui/Toolbar", [
29218 "tinymce/ui/Container",
29219 "tinymce/ui/KeyboardNavigation"
29220 ], function(Container, KeyboardNavigation) {
29223 return Container.extend({
29230 * Constructs a instance with the specified settings.
29233 * @param {Object} settings Name/value object with settings.
29235 init: function(settings) {
29238 self._super(settings);
29239 self.addClass('toolbar');
29243 * Called after the control has been rendered.
29245 * @method postRender
29247 postRender: function() {
29250 self.items().addClass('toolbar-item');
29252 self.keyNav = new KeyboardNavigation({
29254 enableLeftRight: true
29257 return self._super();
29262 // Included from: js/tinymce/classes/ui/MenuBar.js
29267 * Copyright, Moxiecode Systems AB
29268 * Released under LGPL License.
29270 * License: http://www.tinymce.com/license
29271 * Contributing: http://www.tinymce.com/contributing
29275 * Creates a new menubar.
29277 * @-x-less MenuBar.less
29278 * @class tinymce.ui.MenuBar
29279 * @extends tinymce.ui.Container
29281 define("tinymce/ui/MenuBar", [
29282 "tinymce/ui/Toolbar"
29283 ], function(Toolbar) {
29286 return Toolbar.extend({
29289 containerCls: 'menubar',
29297 // Included from: js/tinymce/classes/ui/MenuButton.js
29302 * Copyright, Moxiecode Systems AB
29303 * Released under LGPL License.
29305 * License: http://www.tinymce.com/license
29306 * Contributing: http://www.tinymce.com/contributing
29310 * Creates a new menu button.
29312 * @-x-less MenuButton.less
29313 * @class tinymce.ui.MenuButton
29314 * @extends tinymce.ui.Button
29316 define("tinymce/ui/MenuButton", [
29317 "tinymce/ui/Button",
29318 "tinymce/ui/Factory",
29319 "tinymce/ui/MenuBar"
29320 ], function(Button, Factory, MenuBar) {
29323 // TODO: Maybe add as some global function
29324 function isChildOf(node, parent) {
29326 if (parent === node) {
29330 node = node.parentNode;
29336 var MenuButton = Button.extend({
29338 * Constructs a instance with the specified settings.
29341 * @param {Object} settings Name/value object with settings.
29343 init: function(settings) {
29346 self._renderOpen = true;
29347 self._super(settings);
29349 self.addClass('menubtn');
29351 if (settings.fixedWidth) {
29352 self.addClass('fixed-width');
29355 self.aria('haspopup', true);
29356 self.hasPopup = true;
29360 * Shows the menu for the button.
29364 showMenu: function() {
29365 var self = this, settings = self.settings, menu;
29367 if (self.menu && self.menu.visible()) {
29368 return self.hideMenu();
29372 menu = settings.menu || [];
29374 // Is menu array then auto constuct menu control
29381 menu.type = menu.type || 'menu';
29384 self.menu = Factory.create(menu).parent(self).renderTo(self.getContainerElm());
29385 self.fire('createmenu');
29386 self.menu.reflow();
29387 self.menu.on('cancel', function(e) {
29388 if (e.control === self.menu) {
29393 self.menu.on('show hide', function(e) {
29394 if (e.control == self.menu) {
29395 self.activeMenu(e.type == 'show');
29399 self.aria('expanded', true);
29403 self.menu.layoutRect({w: self.layoutRect().w});
29404 self.menu.moveRel(self.getEl(), ['bl-tl', 'tl-bl']);
29408 * Hides the menu for the button.
29412 hideMenu: function() {
29416 self.menu.items().each(function(item) {
29417 if (item.hideMenu) {
29423 self.aria('expanded', false);
29428 * Sets the active menu state.
29432 activeMenu: function(state) {
29433 this.toggleClass('active', state);
29437 * Renders the control as a HTML string.
29439 * @method renderHtml
29440 * @return {String} HTML representing the control.
29442 renderHtml: function() {
29443 var self = this, id = self._id, prefix = self.classPrefix;
29444 var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
29446 self.aria('role', self.parent() instanceof MenuBar ? 'menuitem' : 'button');
29449 '<div id="' + id + '" class="' + self.classes() + '" tabindex="-1">' +
29450 '<button id="' + id + '-open" role="presentation" type="button" tabindex="-1">' +
29451 (icon ? '<i class="' + icon + '"></i>' : '') +
29452 '<span>' + (self._text ? (icon ? ' ' : '') + self.encode(self._text) : '') + '</span>' +
29453 ' <i class="' + prefix + 'caret"></i>' +
29460 * Gets invoked after the control has been rendered.
29462 * @method postRender
29464 postRender: function() {
29467 self.on('click', function(e) {
29468 if (e.control === self && isChildOf(e.target, self.getEl())) {
29472 self.menu.items()[0].focus();
29477 self.on('mouseenter', function(e) {
29478 var overCtrl = e.control, parent = self.parent(), hasVisibleSiblingMenu;
29480 if (overCtrl && parent && overCtrl instanceof MenuButton && overCtrl.parent() == parent) {
29481 parent.items().filter('MenuButton').each(function(ctrl) {
29482 if (ctrl.hideMenu && ctrl != overCtrl) {
29483 if (ctrl.menu && ctrl.menu.visible()) {
29484 hasVisibleSiblingMenu = true;
29491 if (hasVisibleSiblingMenu) {
29492 overCtrl.focus(); // Fix for: #5887
29493 overCtrl.showMenu();
29498 return self._super();
29502 * Sets/gets the current button text.
29505 * @param {String} [text] New button text.
29506 * @return {String|tinymce.ui.MenuButton} Current text or current MenuButton instance.
29508 text: function(text) {
29509 var self = this, i, children;
29511 if (self._rendered) {
29512 children = self.getEl('open').getElementsByTagName('span');
29513 for (i = 0; i < children.length; i++) {
29514 children[i].innerHTML = self.encode(text);
29518 return this._super(text);
29522 * Removes the control and it's menus.
29526 remove: function() {
29530 this.menu.remove();
29538 // Included from: js/tinymce/classes/ui/ListBox.js
29543 * Copyright, Moxiecode Systems AB
29544 * Released under LGPL License.
29546 * License: http://www.tinymce.com/license
29547 * Contributing: http://www.tinymce.com/contributing
29551 * Creates a new list box control.
29553 * @-x-less ListBox.less
29554 * @class tinymce.ui.ListBox
29555 * @extends tinymce.ui.MenuButton
29557 define("tinymce/ui/ListBox", [
29558 "tinymce/ui/MenuButton"
29559 ], function(MenuButton) {
29562 return MenuButton.extend({
29564 * Constructs a instance with the specified settings.
29567 * @param {Object} settings Name/value object with settings.
29568 * @setting {Array} values Array with values to add to list box.
29570 init: function(settings) {
29571 var self = this, values, i, selected, selectedText, lastItemCtrl;
29573 self._values = values = settings.values;
29575 for (i = 0; i < values.length; i++) {
29576 selected = values[i].selected || settings.value === values[i].value;
29579 selectedText = selectedText || values[i].text;
29580 self._value = values[i].value;
29584 settings.menu = values;
29587 settings.text = settings.text || selectedText || values[0].text;
29589 self._super(settings);
29590 self.addClass('listbox');
29592 self.on('select', function(e) {
29593 var ctrl = e.control;
29595 if (lastItemCtrl) {
29596 e.lastControl = lastItemCtrl;
29599 if (settings.multiple) {
29600 ctrl.active(!ctrl.active());
29602 self.value(e.control.settings.value);
29605 lastItemCtrl = ctrl;
29610 * Getter/setter function for the control value.
29613 * @param {String} [value] Value to be set.
29614 * @return {Boolean/tinymce.ui.ListBox} Value or self if it's a set operation.
29616 value: function(value) {
29617 var self = this, active, selectedText, menu, i;
29619 function activateByValue(menu, value) {
29620 menu.items().each(function(ctrl) {
29621 active = ctrl.value() === value;
29624 selectedText = selectedText || ctrl.text();
29627 ctrl.active(active);
29630 activateByValue(ctrl.menu, value);
29635 if (typeof(value) != "undefined") {
29637 activateByValue(self.menu, value);
29639 menu = self.settings.menu;
29640 for (i = 0; i < menu.length; i++) {
29641 active = menu[i].value == value;
29644 selectedText = selectedText || menu[i].text;
29647 menu[i].active = active;
29651 self.text(selectedText || this.settings.text);
29654 return self._super(value);
29659 // Included from: js/tinymce/classes/ui/MenuItem.js
29664 * Copyright, Moxiecode Systems AB
29665 * Released under LGPL License.
29667 * License: http://www.tinymce.com/license
29668 * Contributing: http://www.tinymce.com/contributing
29672 * Creates a new menu item.
29674 * @-x-less MenuItem.less
29675 * @class tinymce.ui.MenuItem
29676 * @extends tinymce.ui.Control
29678 define("tinymce/ui/MenuItem", [
29679 "tinymce/ui/Widget",
29680 "tinymce/ui/Factory"
29681 ], function(Widget, Factory) {
29684 return Widget.extend({
29691 * Constructs a instance with the specified settings.
29694 * @param {Object} settings Name/value object with settings.
29695 * @setting {Boolean} selectable Selectable menu.
29696 * @setting {Array} menu Submenu array with items.
29697 * @setting {String} shortcut Shortcut to display for menu item. Example: Ctrl+X
29699 init: function(settings) {
29702 self.hasPopup = true;
29704 self._super(settings);
29706 settings = self.settings;
29708 self.addClass('menu-item');
29710 if (settings.menu) {
29711 self.addClass('menu-item-expand');
29714 if (settings.preview) {
29715 self.addClass('menu-item-preview');
29718 if (self._text === '-' || self._text === '|') {
29719 self.addClass('menu-item-sep');
29720 self.aria('role', 'separator');
29721 self.canFocus = false;
29725 if (settings.selectable) {
29726 self.aria('role', 'menuitemcheckbox');
29727 self.aria('checked', true);
29728 self.addClass('menu-item-checkbox');
29729 settings.icon = 'selected';
29732 self.on('mousedown', function(e) {
29733 e.preventDefault();
29736 self.on('mouseenter click', function(e) {
29737 if (e.control === self) {
29738 if (!settings.menu && e.type === 'click') {
29739 self.parent().hideAll();
29740 self.fire('cancel');
29741 self.fire('select');
29746 setTimeout(function() {
29747 self.menu.items()[0].focus();
29754 if (settings.menu) {
29755 self.aria('haspopup', true);
29760 * Returns true/false if the menuitem has sub menu.
29763 * @return {Boolean} True/false state if it has submenu.
29765 hasMenus: function() {
29766 return !!this.settings.menu;
29770 * Shows the menu for the menu item.
29774 showMenu: function() {
29775 var self = this, settings = self.settings, menu, parent = self.parent();
29777 parent.items().each(function(ctrl) {
29778 if (ctrl !== self) {
29783 if (settings.menu) {
29787 menu = settings.menu;
29789 // Is menu array then auto constuct menu control
29796 menu.type = menu.type || 'menu';
29799 if (parent.settings.itemDefaults) {
29800 menu.itemDefaults = parent.settings.itemDefaults;
29803 menu = self.menu = Factory.create(menu).parent(self).renderTo(self.getContainerElm());
29806 menu.on('cancel', function() {
29810 menu.on('hide', function(e) {
29811 if (e.control === menu) {
29812 self.removeClass('selected');
29819 menu._parentMenu = parent;
29821 menu.addClass('menu-sub');
29823 var rel = menu.testMoveRel(self.getEl(), ['tr-tl', 'br-bl', 'tl-tr', 'bl-br']);
29824 menu.moveRel(self.getEl(), rel);
29826 rel = 'menu-sub-' + rel;
29827 menu.removeClass(menu._lastRel);
29828 menu.addClass(rel);
29829 menu._lastRel = rel;
29831 self.addClass('selected');
29832 self.aria('expanded', true);
29837 * Hides the menu for the menu item.
29841 hideMenu: function() {
29845 self.menu.items().each(function(item) {
29846 if (item.hideMenu) {
29852 self.aria('expanded', false);
29859 * Renders the control as a HTML string.
29861 * @method renderHtml
29862 * @return {String} HTML representing the control.
29864 renderHtml: function() {
29865 var self = this, id = self._id, settings = self.settings, prefix = self.classPrefix, text = self.encode(self._text);
29866 var icon = self.settings.icon;
29869 self.parent().addClass('menu-has-icons');
29872 icon = prefix + 'ico ' + prefix + 'i-' + (self.settings.icon || 'none');
29875 '<div id="' + id + '" class="' + self.classes() + '" tabindex="-1">' +
29876 (text !== '-' ? '<i class="' + icon + '"></i> ' : '') +
29877 (text !== '-' ? '<span id="' + id + '-text" class="' + prefix + 'text">' + text + '</span>' : '') +
29878 (settings.shortcut ? '<div id="' + id + '-shortcut" class="' + prefix + 'menu-shortcut">' +
29879 settings.shortcut + '</div>' : '') +
29880 (settings.menu ? '<div class="' + prefix + 'caret"></div>' : '') +
29886 * Gets invoked after the control has been rendered.
29888 * @method postRender
29890 postRender: function() {
29891 var self = this, settings = self.settings;
29893 var textStyle = settings.textStyle;
29894 if (typeof(textStyle) == "function") {
29895 textStyle = textStyle.call(this);
29899 var textElm = self.getEl('text');
29901 textElm.setAttribute('style', textStyle);
29905 return self._super();
29909 * Removes the control and it's menus.
29913 remove: function() {
29917 this.menu.remove();
29923 // Included from: js/tinymce/classes/ui/Menu.js
29928 * Copyright, Moxiecode Systems AB
29929 * Released under LGPL License.
29931 * License: http://www.tinymce.com/license
29932 * Contributing: http://www.tinymce.com/contributing
29936 * Creates a new menu.
29938 * @-x-less Menu.less
29939 * @class tinymce.ui.Menu
29940 * @extends tinymce.ui.FloatPanel
29942 define("tinymce/ui/Menu", [
29943 "tinymce/ui/FloatPanel",
29944 "tinymce/ui/KeyboardNavigation",
29945 "tinymce/ui/MenuItem",
29946 "tinymce/util/Tools"
29947 ], function(FloatPanel, KeyboardNavigation, MenuItem, Tools) {
29950 var Menu = FloatPanel.extend({
29952 defaultType: 'menuitem',
29959 * Constructs a instance with the specified settings.
29962 * @param {Object} settings Name/value object with settings.
29964 init: function(settings) {
29967 settings.autohide = true;
29968 settings.constrainToViewport = true;
29970 if (settings.itemDefaults) {
29971 var items = settings.items, i = items.length;
29974 items[i] = Tools.extend({}, settings.itemDefaults, items[i]);
29978 self._super(settings);
29979 self.addClass('menu');
29981 self.keyNav = new KeyboardNavigation({
29983 enableUpDown: true,
29984 enableLeftRight: true,
29986 leftAction: function() {
29987 if (self.parent() instanceof MenuItem) {
29988 self.keyNav.cancel();
29992 onCancel: function() {
29993 self.fire('cancel', {}, false);
30000 * Repaints the control after a layout operation.
30004 repaint: function() {
30005 this.toggleClass('menu-align', true);
30009 this.getEl().style.height = '';
30010 this.getEl('body').style.height = '';
30016 * Hides/closes the menu.
30020 cancel: function() {
30024 self.fire('cancel');
30025 self.fire('select');
30029 * Hide menu and all sub menus.
30033 hideAll: function() {
30036 this.find('menuitem').exec('hideMenu');
30038 return self._super();
30042 * Invoked before the menu is rendered.
30044 * @method preRender
30046 preRender: function() {
30049 self.items().each(function(ctrl) {
30050 var settings = ctrl.settings;
30052 if (settings.icon || settings.selectable) {
30053 self._hasIcons = true;
30058 return self._super();
30065 // Included from: js/tinymce/classes/ui/Radio.js
30070 * Copyright, Moxiecode Systems AB
30071 * Released under LGPL License.
30073 * License: http://www.tinymce.com/license
30074 * Contributing: http://www.tinymce.com/contributing
30078 * Creates a new radio button.
30080 * @-x-less Radio.less
30081 * @class tinymce.ui.Radio
30082 * @extends tinymce.ui.Checkbox
30084 define("tinymce/ui/Radio", [
30085 "tinymce/ui/Checkbox"
30086 ], function(Checkbox) {
30089 return Checkbox.extend({
30097 // Included from: js/tinymce/classes/ui/ResizeHandle.js
30102 * Copyright, Moxiecode Systems AB
30103 * Released under LGPL License.
30105 * License: http://www.tinymce.com/license
30106 * Contributing: http://www.tinymce.com/contributing
30110 * Renders a resize handle that fires ResizeStart, Resize and ResizeEnd events.
30112 * @-x-less ResizeHandle.less
30113 * @class tinymce.ui.ResizeHandle
30114 * @extends tinymce.ui.Widget
30116 define("tinymce/ui/ResizeHandle", [
30117 "tinymce/ui/Widget",
30118 "tinymce/ui/DragHelper"
30119 ], function(Widget, DragHelper) {
30122 return Widget.extend({
30124 * Renders the control as a HTML string.
30126 * @method renderHtml
30127 * @return {String} HTML representing the control.
30129 renderHtml: function() {
30130 var self = this, prefix = self.classPrefix;
30132 self.addClass('resizehandle');
30134 if (self.settings.direction == "both") {
30135 self.addClass('resizehandle-both');
30138 self.canFocus = false;
30141 '<div id="' + self._id + '" class="' + self.classes() + '">' +
30142 '<i class="' + prefix + 'ico ' + prefix + 'i-resize"></i>' +
30148 * Called after the control has been rendered.
30150 * @method postRender
30152 postRender: function() {
30157 self.resizeDragHelper = new DragHelper(this._id, {
30158 start: function() {
30159 self.fire('ResizeStart');
30162 drag: function(e) {
30163 if (self.settings.direction != "both") {
30167 self.fire('Resize', e);
30171 self.fire('ResizeEnd');
30178 // Included from: js/tinymce/classes/ui/Spacer.js
30183 * Copyright, Moxiecode Systems AB
30184 * Released under LGPL License.
30186 * License: http://www.tinymce.com/license
30187 * Contributing: http://www.tinymce.com/contributing
30191 * Creates a spacer. This control is used in flex layouts for example.
30193 * @-x-less Spacer.less
30194 * @class tinymce.ui.Spacer
30195 * @extends tinymce.ui.Widget
30197 define("tinymce/ui/Spacer", [
30198 "tinymce/ui/Widget"
30199 ], function(Widget) {
30202 return Widget.extend({
30204 * Renders the control as a HTML string.
30206 * @method renderHtml
30207 * @return {String} HTML representing the control.
30209 renderHtml: function() {
30212 self.addClass('spacer');
30213 self.canFocus = false;
30215 return '<div id="' + self._id + '" class="' + self.classes() + '"></div>';
30220 // Included from: js/tinymce/classes/ui/SplitButton.js
30225 * Copyright, Moxiecode Systems AB
30226 * Released under LGPL License.
30228 * License: http://www.tinymce.com/license
30229 * Contributing: http://www.tinymce.com/contributing
30233 * Creates a split button.
30235 * @-x-less SplitButton.less
30236 * @class tinymce.ui.SplitButton
30237 * @extends tinymce.ui.Button
30239 define("tinymce/ui/SplitButton", [
30240 "tinymce/ui/MenuButton",
30241 "tinymce/dom/DOMUtils"
30242 ], function(MenuButton, DomUtils) {
30243 var DOM = DomUtils.DOM;
30245 return MenuButton.extend({
30247 classes: "widget btn splitbtn",
30248 role: "splitbutton"
30252 * Repaints the control after a layout operation.
30256 repaint: function() {
30257 var self = this, elm = self.getEl(), rect = self.layoutRect(), mainButtonElm, menuButtonElm, btnStyle;
30261 mainButtonElm = elm.firstChild;
30262 menuButtonElm = elm.lastChild;
30264 DOM.css(mainButtonElm, {
30265 width: rect.w - menuButtonElm.offsetWidth,
30269 DOM.css(menuButtonElm, {
30273 btnStyle = mainButtonElm.firstChild.style;
30274 btnStyle.width = btnStyle.height = "100%";
30276 btnStyle = menuButtonElm.firstChild.style;
30277 btnStyle.width = btnStyle.height = "100%";
30283 * Sets the active menu state.
30287 activeMenu: function(state) {
30290 DOM.toggleClass(self.getEl().lastChild, self.classPrefix + 'active', state);
30294 * Renders the control as a HTML string.
30296 * @method renderHtml
30297 * @return {String} HTML representing the control.
30299 renderHtml: function() {
30300 var self = this, id = self._id, prefix = self.classPrefix;
30301 var icon = self.settings.icon ? prefix + 'ico ' + prefix + 'i-' + self.settings.icon : '';
30304 '<div id="' + id + '" class="' + self.classes() + '">' +
30305 '<button type="button" hidefocus tabindex="-1">' +
30306 (icon ? '<i class="' + icon + '"></i>' : '') +
30307 (self._text ? (icon ? ' ' : '') + self._text : '') +
30309 '<button type="button" class="' + prefix + 'open" hidefocus tabindex="-1">' +
30310 //(icon ? '<i class="' + icon + '"></i>' : '') +
30311 (self._menuBtnText ? (icon ? ' ' : '') + self._menuBtnText : '') +
30312 ' <i class="' + prefix + 'caret"></i>' +
30319 * Called after the control has been rendered.
30321 * @method postRender
30323 postRender: function() {
30324 var self = this, onClickHandler = self.settings.onclick;
30326 self.on('click', function(e) {
30327 if (e.control == this && !DOM.getParent(e.target, '.' + this.classPrefix + 'open')) {
30328 e.stopImmediatePropagation();
30329 onClickHandler.call(this, e);
30333 delete self.settings.onclick;
30335 return self._super();
30340 // Included from: js/tinymce/classes/ui/StackLayout.js
30345 * Copyright, Moxiecode Systems AB
30346 * Released under LGPL License.
30348 * License: http://www.tinymce.com/license
30349 * Contributing: http://www.tinymce.com/contributing
30353 * This layout uses the browsers layout when the items are blocks.
30355 * @-x-less StackLayout.less
30356 * @class tinymce.ui.StackLayout
30357 * @extends tinymce.ui.FlowLayout
30359 define("tinymce/ui/StackLayout", [
30360 "tinymce/ui/FlowLayout"
30361 ], function(FlowLayout) {
30364 return FlowLayout.extend({
30366 containerClass: 'stack-layout',
30367 controlClass: 'stack-layout-item',
30373 // Included from: js/tinymce/classes/ui/TabPanel.js
30378 * Copyright, Moxiecode Systems AB
30379 * Released under LGPL License.
30381 * License: http://www.tinymce.com/license
30382 * Contributing: http://www.tinymce.com/contributing
30386 * Creates a tab panel control.
30388 * @-x-less TabPanel.less
30389 * @class tinymce.ui.TabPanel
30390 * @extends tinymce.ui.Panel
30392 * @setting {Number} activeTab Active tab index.
30394 define("tinymce/ui/TabPanel", [
30395 "tinymce/ui/Panel",
30396 "tinymce/ui/DomUtils"
30397 ], function(Panel, DomUtils) {
30400 return Panel.extend({
30404 layout: 'absolute',
30411 * Activates the specified tab by index.
30413 * @method activateTab
30414 * @param {Number} idx Index of the tab to activate.
30416 activateTab: function(idx) {
30417 if (this.activeTabId) {
30418 DomUtils.removeClass(this.getEl(this.activeTabId), this.classPrefix + 'active');
30421 this.activeTabId = 't' + idx;
30423 DomUtils.addClass(this.getEl('t' + idx), this.classPrefix + 'active');
30425 if (idx != this.lastIdx) {
30426 this.items()[this.lastIdx].hide();
30427 this.lastIdx = idx;
30430 this.items()[idx].show().fire('showtab');
30435 * Renders the control as a HTML string.
30437 * @method renderHtml
30438 * @return {String} HTML representing the control.
30440 renderHtml: function() {
30441 var self = this, layout = self._layout, tabsHtml = '', prefix = self.classPrefix;
30444 layout.preRender(self);
30446 self.items().each(function(ctrl, i) {
30448 '<div id="' + self._id + '-t' + i + '" class="' + prefix + 'tab" unselectable="on">' +
30449 self.encode(ctrl.settings.title) +
30455 '<div id="' + self._id + '" class="' + self.classes() + '" hideFocus="1" tabIndex="-1">' +
30456 '<div id="' + self._id + '-head" class="' + prefix + 'tabs">' +
30459 '<div id="' + self._id + '-body" class="' + self.classes('body') + '">' +
30460 layout.renderHtml(self) +
30467 * Called after the control has been rendered.
30469 * @method postRender
30471 postRender: function() {
30476 self.settings.activeTab = self.settings.activeTab || 0;
30477 self.activateTab(self.settings.activeTab);
30479 this.on('click', function(e) {
30480 var targetParent = e.target.parentNode;
30482 if (e.target.parentNode.id == self._id + '-head') {
30483 var i = targetParent.childNodes.length;
30486 if (targetParent.childNodes[i] == e.target) {
30487 self.activateTab(i);
30495 * Initializes the current controls layout rect.
30496 * This will be executed by the layout managers to determine the
30497 * default minWidth/minHeight etc.
30499 * @method initLayoutRect
30500 * @return {Object} Layout rect instance.
30502 initLayoutRect: function() {
30503 var self = this, rect, minW, minH;
30506 self.items().each(function(item, i) {
30507 minW = Math.max(minW, item.layoutRect().minW);
30508 minH = Math.max(minH, item.layoutRect().minH);
30509 if (self.settings.activeTab != i) {
30514 self.items().each(function(ctrl) {
30515 ctrl.settings.x = 0;
30516 ctrl.settings.y = 0;
30517 ctrl.settings.w = minW;
30518 ctrl.settings.h = minH;
30528 var headH = self.getEl('head').offsetHeight;
30530 self.settings.minWidth = minW;
30531 self.settings.minHeight = minH + headH;
30533 rect = self._super();
30534 rect.deltaH += self.getEl('head').offsetHeight;
30535 rect.innerH = rect.h - rect.deltaH;
30542 // Included from: js/tinymce/classes/ui/TextBox.js
30547 * Copyright, Moxiecode Systems AB
30548 * Released under LGPL License.
30550 * License: http://www.tinymce.com/license
30551 * Contributing: http://www.tinymce.com/contributing
30555 * Creates a new textbox.
30557 * @-x-less TextBox.less
30558 * @class tinymce.ui.TextBox
30559 * @extends tinymce.ui.Widget
30561 define("tinymce/ui/TextBox", [
30562 "tinymce/ui/Widget",
30563 "tinymce/ui/DomUtils"
30564 ], function(Widget, DomUtils) {
30567 return Widget.extend({
30569 * Constructs a instance with the specified settings.
30572 * @param {Object} settings Name/value object with settings.
30573 * @setting {Boolean} multiline True if the textbox is a multiline control.
30574 * @setting {Number} maxLength Max length for the textbox.
30575 * @setting {Number} size Size of the textbox in characters.
30577 init: function(settings) {
30580 self._super(settings);
30582 self._value = settings.value || '';
30583 self.addClass('textbox');
30585 if (settings.multiline) {
30586 self.addClass('multiline');
30588 // TODO: Rework this
30589 self.on('keydown', function(e) {
30590 if (e.keyCode == 13) {
30591 self.parents().reverse().each(function(ctrl) {
30592 e.preventDefault();
30605 * Getter/setter function for the control value.
30608 * @param {String} [value] Value to be set.
30609 * @return {String|tinymce.ui.ComboBox} Value or self if it's a set operation.
30611 value: function(value) {
30614 if (typeof(value) != "undefined") {
30615 self._value = value;
30617 if (self._rendered) {
30618 self.getEl().value = value;
30624 if (self._rendered) {
30625 return self.getEl().value;
30628 return self._value;
30632 * Repaints the control after a layout operation.
30636 repaint: function() {
30637 var self = this, style, rect, borderBox, borderW = 0, borderH = 0, lastRepaintRect;
30639 style = self.getEl().style;
30640 rect = self._layoutRect;
30641 lastRepaintRect = self._lastRepaintRect || {};
30643 // Detect old IE 7+8 add lineHeight to align caret vertically in the middle
30644 var doc = document;
30645 if (!self.settings.multiline && doc.all && (!doc.documentMode || doc.documentMode <= 8)) {
30646 style.lineHeight = (rect.h - borderH) + 'px';
30649 borderBox = self._borderBox;
30650 borderW = borderBox.left + borderBox.right + 8;
30651 borderH = borderBox.top + borderBox.bottom + (self.settings.multiline ? 8 : 0);
30653 if (rect.x !== lastRepaintRect.x) {
30654 style.left = rect.x + 'px';
30655 lastRepaintRect.x = rect.x;
30658 if (rect.y !== lastRepaintRect.y) {
30659 style.top = rect.y + 'px';
30660 lastRepaintRect.y = rect.y;
30663 if (rect.w !== lastRepaintRect.w) {
30664 style.width = (rect.w - borderW) + 'px';
30665 lastRepaintRect.w = rect.w;
30668 if (rect.h !== lastRepaintRect.h) {
30669 style.height = (rect.h - borderH) + 'px';
30670 lastRepaintRect.h = rect.h;
30673 self._lastRepaintRect = lastRepaintRect;
30674 self.fire('repaint', {}, false);
30680 * Renders the control as a HTML string.
30682 * @method renderHtml
30683 * @return {String} HTML representing the control.
30685 renderHtml: function() {
30686 var self = this, id = self._id, settings = self.settings, value = self.encode(self._value, false), extraAttrs = '';
30688 if ("spellcheck" in settings) {
30689 extraAttrs += ' spellcheck="' + settings.spellcheck + '"';
30692 if (settings.maxLength) {
30693 extraAttrs += ' maxlength="' + settings.maxLength + '"';
30696 if (settings.size) {
30697 extraAttrs += ' size="' + settings.size + '"';
30700 if (settings.subtype) {
30701 extraAttrs += ' type="' + settings.subtype + '"';
30704 if (settings.multiline) {
30706 '<textarea id="' + id + '" class="' + self.classes() + '" ' +
30707 (settings.rows ? ' rows="' + settings.rows + '"' : '') +
30708 ' hidefocus="true"' + extraAttrs + '>' + value +
30713 return '<input id="' + id + '" class="' + self.classes() + '" value="' + value + '" hidefocus="true"' + extraAttrs + '>';
30717 * Called after the control has been rendered.
30719 * @method postRender
30721 postRender: function() {
30724 DomUtils.on(self.getEl(), 'change', function(e) {
30725 self.fire('change', e);
30728 return self._super();
30733 // Included from: js/tinymce/classes/ui/Throbber.js
30738 * Copyright, Moxiecode Systems AB
30739 * Released under LGPL License.
30741 * License: http://www.tinymce.com/license
30742 * Contributing: http://www.tinymce.com/contributing
30746 * This class enables you to display a Throbber for any element.
30748 * @-x-less Throbber.less
30749 * @class tinymce.ui.Throbber
30751 define("tinymce/ui/Throbber", [
30752 "tinymce/ui/DomUtils"
30753 ], function(DomUtils) {
30757 * Constructs a new throbber.
30760 * @param {Element} elm DOM Html element to display throbber in.
30762 return function(elm) {
30763 var self = this, state;
30766 * Shows the throbber.
30769 * @param {Number} [time] Time to wait before showing.
30770 * @return {tinymce.ui.Throbber} Current throbber instance.
30772 self.show = function(time) {
30777 window.setTimeout(function() {
30779 elm.appendChild(DomUtils.createFragment('<div class="mce-throbber"></div>'));
30787 * Hides the throbber.
30790 * @return {tinymce.ui.Throbber} Current throbber instance.
30792 self.hide = function() {
30793 var child = elm.lastChild;
30795 if (child && child.className.indexOf('throbber') != -1) {
30796 child.parentNode.removeChild(child);
30806 expose(["tinymce/dom/Sizzle","tinymce/html/Styles","tinymce/dom/EventUtils","tinymce/dom/TreeWalker","tinymce/util/Tools","tinymce/dom/Range","tinymce/html/Entities","tinymce/Env","tinymce/dom/DOMUtils","tinymce/dom/ScriptLoader","tinymce/AddOnManager","tinymce/html/Node","tinymce/html/Schema","tinymce/html/SaxParser","tinymce/html/DomParser","tinymce/html/Writer","tinymce/html/Serializer","tinymce/dom/Serializer","tinymce/dom/TridentSelection","tinymce/util/VK","tinymce/dom/ControlSelection","tinymce/dom/Selection","tinymce/dom/RangeUtils","tinymce/Formatter","tinymce/UndoManager","tinymce/EnterKey","tinymce/ForceBlocks","tinymce/EditorCommands","tinymce/util/URI","tinymce/util/Class","tinymce/ui/Selector","tinymce/ui/Collection","tinymce/ui/DomUtils","tinymce/ui/Control","tinymce/ui/Factory","tinymce/ui/Container","tinymce/ui/DragHelper","tinymce/ui/Scrollable","tinymce/ui/Panel","tinymce/ui/Movable","tinymce/ui/Resizable","tinymce/ui/FloatPanel","tinymce/ui/KeyboardNavigation","tinymce/ui/Window","tinymce/ui/MessageBox","tinymce/WindowManager","tinymce/util/Quirks","tinymce/util/Observable","tinymce/Shortcuts","tinymce/Editor","tinymce/util/I18n","tinymce/FocusManager","tinymce/EditorManager","tinymce/LegacyInput","tinymce/util/XHR","tinymce/util/JSON","tinymce/util/JSONRequest","tinymce/util/JSONP","tinymce/util/LocalStorage","tinymce/Compat","tinymce/ui/Layout","tinymce/ui/AbsoluteLayout","tinymce/ui/Tooltip","tinymce/ui/Widget","tinymce/ui/Button","tinymce/ui/ButtonGroup","tinymce/ui/Checkbox","tinymce/ui/PanelButton","tinymce/ui/ColorButton","tinymce/ui/ComboBox","tinymce/ui/Path","tinymce/ui/ElementPath","tinymce/ui/FormItem","tinymce/ui/Form","tinymce/ui/FieldSet","tinymce/ui/FilePicker","tinymce/ui/FitLayout","tinymce/ui/FlexLayout","tinymce/ui/FlowLayout","tinymce/ui/FormatControls","tinymce/ui/GridLayout","tinymce/ui/Iframe","tinymce/ui/Label","tinymce/ui/Toolbar","tinymce/ui/MenuBar","tinymce/ui/MenuButton","tinymce/ui/ListBox","tinymce/ui/MenuItem","tinymce/ui/Menu","tinymce/ui/Radio","tinymce/ui/ResizeHandle","tinymce/ui/Spacer","tinymce/ui/SplitButton","tinymce/ui/StackLayout","tinymce/ui/TabPanel","tinymce/ui/TextBox","tinymce/ui/Throbber"]);