| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524 | 
							- /**
 
-  * ControlManager.js
 
-  *
 
-  * Copyright 2009, Moxiecode Systems AB
 
-  * Released under LGPL License.
 
-  *
 
-  * License: http://tinymce.moxiecode.com/license
 
-  * Contributing: http://tinymce.moxiecode.com/contributing
 
-  */
 
- (function(tinymce) {
 
- 	// Shorten names
 
- 	var DOM = tinymce.DOM, Event = tinymce.dom.Event, each = tinymce.each, extend = tinymce.extend;
 
- 	/**
 
- 	 * This class is responsible for managing UI control instances. It's both a factory and a collection for the controls.
 
- 	 * @class tinymce.ControlManager
 
- 	 */
 
- 	tinymce.create('tinymce.ControlManager', {
 
- 		/**
 
- 		 * Constructs a new control manager instance.
 
- 		 * Consult the Wiki for more details on this class.
 
- 		 *
 
- 		 * @constructor
 
- 		 * @method ControlManager
 
- 		 * @param {tinymce.Editor} ed TinyMCE editor instance to add the control to.
 
- 		 * @param {Object} s Optional settings object for the control manager.
 
- 		 */
 
- 		ControlManager : function(ed, s) {
 
- 			var t = this, i;
 
- 			s = s || {};
 
- 			t.editor = ed;
 
- 			t.controls = {};
 
- 			t.onAdd = new tinymce.util.Dispatcher(t);
 
- 			t.onPostRender = new tinymce.util.Dispatcher(t);
 
- 			t.prefix = s.prefix || ed.id + '_';
 
- 			t._cls = {};
 
- 			t.onPostRender.add(function() {
 
- 				each(t.controls, function(c) {
 
- 					c.postRender();
 
- 				});
 
- 			});
 
- 		},
 
- 		/**
 
- 		 * Returns a control by id or undefined it it wasn't found.
 
- 		 *
 
- 		 * @method get
 
- 		 * @param {String} id Control instance name.
 
- 		 * @return {tinymce.ui.Control} Control instance or undefined.
 
- 		 */
 
- 		get : function(id) {
 
- 			return this.controls[this.prefix + id] || this.controls[id];
 
- 		},
 
- 		/**
 
- 		 * Sets the active state of a control by id.
 
- 		 *
 
- 		 * @method setActive
 
- 		 * @param {String} id Control id to set state on.
 
- 		 * @param {Boolean} s Active state true/false.
 
- 		 * @return {tinymce.ui.Control} Control instance that got activated or null if it wasn't found.
 
- 		 */
 
- 		setActive : function(id, s) {
 
- 			var c = null;
 
- 			if (c = this.get(id))
 
- 				c.setActive(s);
 
- 			return c;
 
- 		},
 
- 		/**
 
- 		 * Sets the dsiabled state of a control by id.
 
- 		 *
 
- 		 * @method setDisabled
 
- 		 * @param {String} id Control id to set state on.
 
- 		 * @param {Boolean} s Active state true/false.
 
- 		 * @return {tinymce.ui.Control} Control instance that got disabled or null if it wasn't found.
 
- 		 */
 
- 		setDisabled : function(id, s) {
 
- 			var c = null;
 
- 			if (c = this.get(id))
 
- 				c.setDisabled(s);
 
- 			return c;
 
- 		},
 
- 		/**
 
- 		 * Adds a control to the control collection inside the manager.
 
- 		 *
 
- 		 * @method add
 
- 		 * @param {tinymce.ui.Control} Control instance to add to collection.
 
- 		 * @return {tinymce.ui.Control} Control instance that got passed in.
 
- 		 */
 
- 		add : function(c) {
 
- 			var t = this;
 
- 			if (c) {
 
- 				t.controls[c.id] = c;
 
- 				t.onAdd.dispatch(c, t);
 
- 			}
 
- 			return c;
 
- 		},
 
- 		/**
 
- 		 * Creates a control by name, when a control is created it will automatically add it to the control collection.
 
- 		 * It first ask all plugins for the specified control if the plugins didn't return a control then the default behavior
 
- 		 * will be used.
 
- 		 *
 
- 		 * @method createControl
 
- 		 * @param {String} n Control name to create for example "separator".
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createControl : function(n) {
 
- 			var c, t = this, ed = t.editor;
 
- 			each(ed.plugins, function(p) {
 
- 				if (p.createControl) {
 
- 					c = p.createControl(n, t);
 
- 					if (c)
 
- 						return false;
 
- 				}
 
- 			});
 
- 			switch (n) {
 
- 				case "|":
 
- 				case "separator":
 
- 					return t.createSeparator();
 
- 			}
 
- 			if (!c && ed.buttons && (c = ed.buttons[n]))
 
- 				return t.createButton(n, c);
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a drop menu control instance by id.
 
- 		 *
 
- 		 * @method createDropMenu
 
- 		 * @param {String} id Unique id for the new dropdown instance. For example "some menu".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createDropMenu : function(id, s, cc) {
 
- 			var t = this, ed = t.editor, c, bm, v, cls;
 
- 			s = extend({
 
- 				'class' : 'mceDropDown',
 
- 				constrain : ed.settings.constrain_menus
 
- 			}, s);
 
- 			s['class'] = s['class'] + ' ' + ed.getParam('skin') + 'Skin';
 
- 			if (v = ed.getParam('skin_variant'))
 
- 				s['class'] += ' ' + ed.getParam('skin') + 'Skin' + v.substring(0, 1).toUpperCase() + v.substring(1);
 
- 			id = t.prefix + id;
 
- 			cls = cc || t._cls.dropmenu || tinymce.ui.DropMenu;
 
- 			c = t.controls[id] = new cls(id, s);
 
- 			c.onAddItem.add(function(c, o) {
 
- 				var s = o.settings;
 
- 				s.title = ed.getLang(s.title, s.title);
 
- 				if (!s.onclick) {
 
- 					s.onclick = function(v) {
 
- 						if (s.cmd)
 
- 							ed.execCommand(s.cmd, s.ui || false, s.value);
 
- 					};
 
- 				}
 
- 			});
 
- 			ed.onRemove.add(function() {
 
- 				c.destroy();
 
- 			});
 
- 			// Fix for bug #1897785, #1898007
 
- 			if (tinymce.isIE) {
 
- 				c.onShowMenu.add(function() {
 
- 					// IE 8 needs focus in order to store away a range with the current collapsed caret location
 
- 					ed.focus();
 
- 					bm = ed.selection.getBookmark(1);
 
- 				});
 
- 				c.onHideMenu.add(function() {
 
- 					if (bm) {
 
- 						ed.selection.moveToBookmark(bm);
 
- 						bm = 0;
 
- 					}
 
- 				});
 
- 			}
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a list box control instance by id. A list box is either a native select element or a DOM/JS based list box control. This
 
- 		 * depends on the use_native_selects settings state.
 
- 		 *
 
- 		 * @method createListBox
 
- 		 * @param {String} id Unique id for the new listbox instance. For example "styles".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createListBox : function(id, s, cc) {
 
- 			var t = this, ed = t.editor, cmd, c, cls;
 
- 			if (t.get(id))
 
- 				return null;
 
- 			s.title = ed.translate(s.title);
 
- 			s.scope = s.scope || ed;
 
- 			if (!s.onselect) {
 
- 				s.onselect = function(v) {
 
- 					ed.execCommand(s.cmd, s.ui || false, v || s.value);
 
- 				};
 
- 			}
 
- 			s = extend({
 
- 				title : s.title,
 
- 				'class' : 'mce_' + id,
 
- 				scope : s.scope,
 
- 				control_manager : t
 
- 			}, s);
 
- 			id = t.prefix + id;
 
- 			function useNativeListForAccessibility(ed) {
 
- 				return ed.settings.use_accessible_selects && !tinymce.isGecko
 
- 			}
 
- 			if (ed.settings.use_native_selects || useNativeListForAccessibility(ed))
 
- 				c = new tinymce.ui.NativeListBox(id, s);
 
- 			else {
 
- 				cls = cc || t._cls.listbox || tinymce.ui.ListBox;
 
- 				c = new cls(id, s, ed);
 
- 			}
 
- 			t.controls[id] = c;
 
- 			// Fix focus problem in Safari
 
- 			if (tinymce.isWebKit) {
 
- 				c.onPostRender.add(function(c, n) {
 
- 					// Store bookmark on mousedown
 
- 					Event.add(n, 'mousedown', function() {
 
- 						ed.bookmark = ed.selection.getBookmark(1);
 
- 					});
 
- 					// Restore on focus, since it might be lost
 
- 					Event.add(n, 'focus', function() {
 
- 						ed.selection.moveToBookmark(ed.bookmark);
 
- 						ed.bookmark = null;
 
- 					});
 
- 				});
 
- 			}
 
- 			if (c.hideMenu)
 
- 				ed.onMouseDown.add(c.hideMenu, c);
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a button control instance by id.
 
- 		 *
 
- 		 * @method createButton
 
- 		 * @param {String} id Unique id for the new button instance. For example "bold".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createButton : function(id, s, cc) {
 
- 			var t = this, ed = t.editor, o, c, cls;
 
- 			if (t.get(id))
 
- 				return null;
 
- 			s.title = ed.translate(s.title);
 
- 			s.label = ed.translate(s.label);
 
- 			s.scope = s.scope || ed;
 
- 			if (!s.onclick && !s.menu_button) {
 
- 				s.onclick = function() {
 
- 					ed.execCommand(s.cmd, s.ui || false, s.value);
 
- 				};
 
- 			}
 
- 			s = extend({
 
- 				title : s.title,
 
- 				'class' : 'mce_' + id,
 
- 				unavailable_prefix : ed.getLang('unavailable', ''),
 
- 				scope : s.scope,
 
- 				control_manager : t
 
- 			}, s);
 
- 			id = t.prefix + id;
 
- 			if (s.menu_button) {
 
- 				cls = cc || t._cls.menubutton || tinymce.ui.MenuButton;
 
- 				c = new cls(id, s, ed);
 
- 				ed.onMouseDown.add(c.hideMenu, c);
 
- 			} else {
 
- 				cls = t._cls.button || tinymce.ui.Button;
 
- 				c = new cls(id, s, ed);
 
- 			}
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a menu button control instance by id.
 
- 		 *
 
- 		 * @method createMenuButton
 
- 		 * @param {String} id Unique id for the new menu button instance. For example "menu1".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createMenuButton : function(id, s, cc) {
 
- 			s = s || {};
 
- 			s.menu_button = 1;
 
- 			return this.createButton(id, s, cc);
 
- 		},
 
- 		/**
 
- 		 * Creates a split button control instance by id.
 
- 		 *
 
- 		 * @method createSplitButton
 
- 		 * @param {String} id Unique id for the new split button instance. For example "spellchecker".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createSplitButton : function(id, s, cc) {
 
- 			var t = this, ed = t.editor, cmd, c, cls;
 
- 			if (t.get(id))
 
- 				return null;
 
- 			s.title = ed.translate(s.title);
 
- 			s.scope = s.scope || ed;
 
- 			if (!s.onclick) {
 
- 				s.onclick = function(v) {
 
- 					ed.execCommand(s.cmd, s.ui || false, v || s.value);
 
- 				};
 
- 			}
 
- 			if (!s.onselect) {
 
- 				s.onselect = function(v) {
 
- 					ed.execCommand(s.cmd, s.ui || false, v || s.value);
 
- 				};
 
- 			}
 
- 			s = extend({
 
- 				title : s.title,
 
- 				'class' : 'mce_' + id,
 
- 				scope : s.scope,
 
- 				control_manager : t
 
- 			}, s);
 
- 			id = t.prefix + id;
 
- 			cls = cc || t._cls.splitbutton || tinymce.ui.SplitButton;
 
- 			c = t.add(new cls(id, s, ed));
 
- 			ed.onMouseDown.add(c.hideMenu, c);
 
- 			return c;
 
- 		},
 
- 		/**
 
- 		 * Creates a color split button control instance by id.
 
- 		 *
 
- 		 * @method createColorSplitButton
 
- 		 * @param {String} id Unique id for the new color split button instance. For example "forecolor".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createColorSplitButton : function(id, s, cc) {
 
- 			var t = this, ed = t.editor, cmd, c, cls, bm;
 
- 			if (t.get(id))
 
- 				return null;
 
- 			s.title = ed.translate(s.title);
 
- 			s.scope = s.scope || ed;
 
- 			if (!s.onclick) {
 
- 				s.onclick = function(v) {
 
- 					if (tinymce.isIE)
 
- 						bm = ed.selection.getBookmark(1);
 
- 					ed.execCommand(s.cmd, s.ui || false, v || s.value);
 
- 				};
 
- 			}
 
- 			if (!s.onselect) {
 
- 				s.onselect = function(v) {
 
- 					ed.execCommand(s.cmd, s.ui || false, v || s.value);
 
- 				};
 
- 			}
 
- 			s = extend({
 
- 				title : s.title,
 
- 				'class' : 'mce_' + id,
 
- 				'menu_class' : ed.getParam('skin') + 'Skin',
 
- 				scope : s.scope,
 
- 				more_colors_title : ed.getLang('more_colors')
 
- 			}, s);
 
- 			id = t.prefix + id;
 
- 			cls = cc || t._cls.colorsplitbutton || tinymce.ui.ColorSplitButton;
 
- 			c = new cls(id, s, ed);
 
- 			ed.onMouseDown.add(c.hideMenu, c);
 
- 			// Remove the menu element when the editor is removed
 
- 			ed.onRemove.add(function() {
 
- 				c.destroy();
 
- 			});
 
- 			// Fix for bug #1897785, #1898007
 
- 			if (tinymce.isIE) {
 
- 				c.onShowMenu.add(function() {
 
- 					// IE 8 needs focus in order to store away a range with the current collapsed caret location
 
- 					ed.focus();
 
- 					bm = ed.selection.getBookmark(1);
 
- 				});
 
- 				c.onHideMenu.add(function() {
 
- 					if (bm) {
 
- 						ed.selection.moveToBookmark(bm);
 
- 						bm = 0;
 
- 					}
 
- 				});
 
- 			}
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a toolbar container control instance by id.
 
- 		 *
 
- 		 * @method createToolbar
 
- 		 * @param {String} id Unique id for the new toolbar container control instance. For example "toolbar1".
 
- 		 * @param {Object} s Optional settings object for the control.
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createToolbar : function(id, s, cc) {
 
- 			var c, t = this, cls;
 
- 			id = t.prefix + id;
 
- 			cls = cc || t._cls.toolbar || tinymce.ui.Toolbar;
 
- 			c = new cls(id, s, t.editor);
 
- 			if (t.get(id))
 
- 				return null;
 
- 			return t.add(c);
 
- 		},
 
- 		
 
- 		createToolbarGroup : function(id, s, cc) {
 
- 			var c, t = this, cls;
 
- 			id = t.prefix + id;
 
- 			cls = cc || this._cls.toolbarGroup || tinymce.ui.ToolbarGroup;
 
- 			c = new cls(id, s, t.editor);
 
- 			
 
- 			if (t.get(id))
 
- 				return null;
 
- 			
 
- 			return t.add(c);
 
- 		},
 
- 		/**
 
- 		 * Creates a separator control instance.
 
- 		 *
 
- 		 * @method createSeparator
 
- 		 * @param {Object} cc Optional control class to use instead of the default one.
 
- 		 * @return {tinymce.ui.Control} Control instance that got created and added.
 
- 		 */
 
- 		createSeparator : function(cc) {
 
- 			var cls = cc || this._cls.separator || tinymce.ui.Separator;
 
- 			return new cls();
 
- 		},
 
- 		/**
 
- 		 * Overrides a specific control type with a custom class.
 
- 		 *
 
- 		 * @method setControlType
 
- 		 * @param {string} n Name of the control to override for example button or dropmenu.
 
- 		 * @param {function} c Class reference to use instead of the default one.
 
- 		 * @return {function} Same as the class reference.
 
- 		 */
 
- 		setControlType : function(n, c) {
 
- 			return this._cls[n.toLowerCase()] = c;
 
- 		},
 
- 	
 
- 		/**
 
- 		 * Destroy.
 
- 		 *
 
- 		 * @method destroy
 
- 		 */
 
- 		destroy : function() {
 
- 			each(this.controls, function(c) {
 
- 				c.destroy();
 
- 			});
 
- 			this.controls = null;
 
- 		}
 
- 	});
 
- })(tinymce);
 
 
  |