includes/clientside/tinymce/tiny_mce_popup.js
changeset 1193 e3b94bd055dc
parent 778 57ce13805b6f
equal deleted inserted replaced
1192:5882f0eebb34 1193:e3b94bd055dc
     1 // Some global instances
       
     2 var tinymce = null, tinyMCEPopup, tinyMCE;
       
     3 
     1 
     4 tinyMCEPopup = {
     2 // Uncomment and change this document.domain value if you are loading the script cross subdomains
     5 	init : function() {
     3 // document.domain = 'moxiecode.com';
     6 		var t = this, w, ti, li, q, i, it;
       
     7 
     4 
     8 		li = ('' + document.location.search).replace(/^\?/, '').split('&');
     5 var tinymce=null,tinyMCEPopup,tinyMCE;tinyMCEPopup={init:function(){var b=this,a,c;a=b.getWin();tinymce=a.tinymce;tinyMCE=a.tinyMCE;b.editor=tinymce.EditorManager.activeEditor;b.params=b.editor.windowManager.params;b.features=b.editor.windowManager.features;b.dom=b.editor.windowManager.createInstance("tinymce.dom.DOMUtils",document);if(b.features.popup_css!==false){b.dom.loadCSS(b.features.popup_css||b.editor.settings.popup_css)}b.listeners=[];b.onInit={add:function(e,d){b.listeners.push({func:e,scope:d})}};b.isWindow=!b.getWindowArg("mce_inline");b.id=b.getWindowArg("mce_window_id");b.editor.windowManager.onOpen.dispatch(b.editor.windowManager,window)},getWin:function(){return(!window.frameElement&&window.dialogArguments)||opener||parent||top},getWindowArg:function(c,b){var a=this.params[c];return tinymce.is(a)?a:b},getParam:function(b,a){return this.editor.getParam(b,a)},getLang:function(b,a){return this.editor.getLang(b,a)},execCommand:function(d,c,e,b){b=b||{};b.skip_focus=1;this.restoreSelection();return this.editor.execCommand(d,c,e,b)},resizeToInnerSize:function(){var e=this,g,a=document.body,c=e.dom.getViewPort(window),d,f;d=e.getWindowArg("mce_width")-c.w;f=e.getWindowArg("mce_height")-c.h;if(e.isWindow){window.resizeBy(d,f)}else{e.editor.windowManager.resizeBy(d,f,e.id)}},executeOnLoad:function(s){this.onInit.add(function(){eval(s)})},storeSelection:function(){this.editor.windowManager.bookmark=tinyMCEPopup.editor.selection.getBookmark(1)},restoreSelection:function(){var a=tinyMCEPopup;if(!a.isWindow&&tinymce.isIE){a.editor.selection.moveToBookmark(a.editor.windowManager.bookmark)}},requireLangPack:function(){var b=this,a=b.getWindowArg("plugin_url")||b.getWindowArg("theme_url");if(a&&b.editor.settings.language&&b.features.translate_i18n!==false){a+="/langs/"+b.editor.settings.language+"_dlg.js";if(!tinymce.ScriptLoader.isDone(a)){document.write('<script type="text/javascript" src="'+tinymce._addVer(a)+'"><\/script>');tinymce.ScriptLoader.markDone(a)}}},pickColor:function(b,a){this.execCommand("mceColorPicker",true,{color:document.getElementById(a).value,func:function(e){document.getElementById(a).value=e;try{document.getElementById(a).onchange()}catch(d){}}})},openBrowser:function(a,c,b){tinyMCEPopup.restoreSelection();this.editor.execCallback("file_browser_callback",a,document.getElementById(a).value,c,window)},confirm:function(b,a,c){this.editor.windowManager.confirm(b,a,c,window)},alert:function(b,a,c){this.editor.windowManager.alert(b,a,c,window)},close:function(){var a=this;function b(){a.editor.windowManager.close(window);tinymce=tinyMCE=a.editor=a.params=a.dom=a.dom.doc=null}if(tinymce.isOpera){a.getWin().setTimeout(b,0)}else{b()}},_restoreSelection:function(){var a=window.event.srcElement;if(a.nodeName=="INPUT"&&(a.type=="submit"||a.type=="button")){tinyMCEPopup.restoreSelection()}},_onDOMLoaded:function(){var b=tinyMCEPopup,d=document.title,e,c,a;if(b.domLoaded){return}b.domLoaded=1;if(b.features.translate_i18n!==false){c=document.body.innerHTML;if(tinymce.isIE){c=c.replace(/ (value|title|alt)=([^"][^\s>]+)/gi,' $1="$2"')}document.dir=b.editor.getParam("directionality","");if((a=b.editor.translate(c))&&a!=c){document.body.innerHTML=a}if((a=b.editor.translate(d))&&a!=d){document.title=d=a}}document.body.style.display="";if(tinymce.isIE){document.attachEvent("onmouseup",tinyMCEPopup._restoreSelection);b.dom.add(b.dom.select("head")[0],"base",{target:"_self"})}b.restoreSelection();b.resizeToInnerSize();if(!b.isWindow){b.editor.windowManager.setTitle(window,d)}else{window.focus()}if(!tinymce.isIE&&!b.isWindow){tinymce.dom.Event._add(document,"focus",function(){b.editor.windowManager.focus(b.id)})}tinymce.each(b.dom.select("select"),function(f){f.onkeydown=tinyMCEPopup._accessHandler});tinymce.each(b.listeners,function(f){f.func.call(f.scope,b.editor)});if(b.getWindowArg("mce_auto_focus",true)){window.focus();tinymce.each(document.forms,function(g){tinymce.each(g.elements,function(f){if(b.dom.hasClass(f,"mceFocus")&&!f.disabled){f.focus();return false}})})}document.onkeyup=tinyMCEPopup._closeWinKeyHandler},_accessHandler:function(a){a=a||window.event;if(a.keyCode==13||a.keyCode==32){a=a.target||a.srcElement;if(a.onchange){a.onchange()}return tinymce.dom.Event.cancel(a)}},_closeWinKeyHandler:function(a){a=a||window.event;if(a.keyCode==27){tinyMCEPopup.close()}},_wait:function(){if(document.attachEvent){document.attachEvent("onreadystatechange",function(){if(document.readyState==="complete"){document.detachEvent("onreadystatechange",arguments.callee);tinyMCEPopup._onDOMLoaded()}});if(document.documentElement.doScroll&&window==window.top){(function(){if(tinyMCEPopup.domLoaded){return}try{document.documentElement.doScroll("left")}catch(a){setTimeout(arguments.callee,0);return}tinyMCEPopup._onDOMLoaded()})()}document.attachEvent("onload",tinyMCEPopup._onDOMLoaded)}else{if(document.addEventListener){window.addEventListener("DOMContentLoaded",tinyMCEPopup._onDOMLoaded,false);window.addEventListener("load",tinyMCEPopup._onDOMLoaded,false)}}}};tinyMCEPopup.init();tinyMCEPopup._wait();
     9 		q = {};
       
    10 		for (i=0; i<li.length; i++) {
       
    11 			it = li[i].split('=');
       
    12 			q[unescape(it[0])] = unescape(it[1]);
       
    13 		}
       
    14 
       
    15 		if (q.mce_rdomain)
       
    16 			document.domain = q.mce_rdomain;
       
    17 
       
    18 		// Find window & API
       
    19 		w = t.getWin();
       
    20 		tinymce = w.tinymce;
       
    21 		tinyMCE = w.tinyMCE;
       
    22 		t.editor = tinymce.EditorManager.activeEditor;
       
    23 		t.params = t.editor.windowManager.params;
       
    24 		t.features = t.editor.windowManager.features;
       
    25 
       
    26 		// Setup local DOM
       
    27 		t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
       
    28 
       
    29 		// Enables you to skip loading the default css
       
    30 		if (t.features.popup_css !== false)
       
    31 			t.dom.loadCSS(t.features.popup_css || t.editor.settings.popup_css);
       
    32 
       
    33 		// Setup on init listeners
       
    34 		t.listeners = [];
       
    35 		t.onInit = {
       
    36 			add : function(f, s) {
       
    37 				t.listeners.push({func : f, scope : s});
       
    38 			}
       
    39 		};
       
    40 
       
    41 		t.isWindow = !t.getWindowArg('mce_inline');
       
    42 		t.id = t.getWindowArg('mce_window_id');
       
    43 		t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
       
    44 	},
       
    45 
       
    46 	getWin : function() {
       
    47 		return window.dialogArguments || opener || parent || top;
       
    48 	},
       
    49 
       
    50 	getWindowArg : function(n, dv) {
       
    51 		var v = this.params[n];
       
    52 
       
    53 		return tinymce.is(v) ? v : dv;
       
    54 	},
       
    55 
       
    56 	getParam : function(n, dv) {
       
    57 		return this.editor.getParam(n, dv);
       
    58 	},
       
    59 
       
    60 	getLang : function(n, dv) {
       
    61 		return this.editor.getLang(n, dv);
       
    62 	},
       
    63 
       
    64 	execCommand : function(cmd, ui, val, a) {
       
    65 		a = a || {};
       
    66 		a.skip_focus = 1;
       
    67 
       
    68 		this.restoreSelection();
       
    69 		return this.editor.execCommand(cmd, ui, val, a);
       
    70 	},
       
    71 
       
    72 	resizeToInnerSize : function() {
       
    73 		var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
       
    74 
       
    75 		dw = t.getWindowArg('mce_width') - vp.w;
       
    76 		dh = t.getWindowArg('mce_height') - vp.h;
       
    77 
       
    78 		if (t.isWindow)
       
    79 			window.resizeBy(dw, dh);
       
    80 		else
       
    81 			t.editor.windowManager.resizeBy(dw, dh, t.id);
       
    82 	},
       
    83 
       
    84 	executeOnLoad : function(s) {
       
    85 		this.onInit.add(function() {
       
    86 			eval(s);
       
    87 		});
       
    88 	},
       
    89 
       
    90 	storeSelection : function() {
       
    91 		this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
       
    92 	},
       
    93 
       
    94 	restoreSelection : function() {
       
    95 		var t = tinyMCEPopup;
       
    96 
       
    97 		if (!t.isWindow && tinymce.isIE)
       
    98 			t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
       
    99 	},
       
   100 
       
   101 	requireLangPack : function() {
       
   102 		var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
       
   103 
       
   104 		if (u && this.editor.settings.language) {
       
   105 			u += '/langs/' + this.editor.settings.language + '_dlg.js';
       
   106 
       
   107 			if (!tinymce.ScriptLoader.isDone(u)) {
       
   108 				document.write('<script type="text/javascript" src="' + tinymce._addVer(u) + '"></script>');
       
   109 				tinymce.ScriptLoader.markDone(u);
       
   110 			}
       
   111 		}
       
   112 	},
       
   113 
       
   114 	pickColor : function(e, element_id) {
       
   115 		this.execCommand('mceColorPicker', true, {
       
   116 			color : document.getElementById(element_id).value,
       
   117 			func : function(c) {
       
   118 				document.getElementById(element_id).value = c;
       
   119 
       
   120 				try {
       
   121 					document.getElementById(element_id).onchange();
       
   122 				} catch (ex) {
       
   123 					// Try fire event, ignore errors
       
   124 				}
       
   125 			}
       
   126 		});
       
   127 	},
       
   128 
       
   129 	openBrowser : function(element_id, type, option) {
       
   130 		tinyMCEPopup.restoreSelection();
       
   131 		this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);
       
   132 	},
       
   133 
       
   134 	confirm : function(t, cb, s) {
       
   135 		this.editor.windowManager.confirm(t, cb, s, window);
       
   136 	},
       
   137 
       
   138 	alert : function(tx, cb, s) {
       
   139 		this.editor.windowManager.alert(tx, cb, s, window);
       
   140 	},
       
   141 
       
   142 	close : function() {
       
   143 		var t = this;
       
   144 
       
   145 		// To avoid domain relaxing issue in Opera
       
   146 		function close() {
       
   147 			t.editor.windowManager.close(window);
       
   148 			tinymce = tinyMCE = t.editor = t.params = t.dom = t.dom.doc = null; // Cleanup
       
   149 		};
       
   150 
       
   151 		if (tinymce.isOpera)
       
   152 			t.getWin().setTimeout(close, 0);
       
   153 		else
       
   154 			close();
       
   155 	},
       
   156 
       
   157 	// Internal functions	
       
   158 
       
   159 	_restoreSelection : function() {
       
   160 		var e = window.event.srcElement;
       
   161 
       
   162 		if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
       
   163 			tinyMCEPopup.restoreSelection();
       
   164 	},
       
   165 
       
   166 /*	_restoreSelection : function() {
       
   167 		var e = window.event.srcElement;
       
   168 
       
   169 		// If user focus a non text input or textarea
       
   170 		if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
       
   171 			tinyMCEPopup.restoreSelection();
       
   172 	},*/
       
   173 
       
   174 	_onDOMLoaded : function() {
       
   175 		var t = this, ti = document.title, bm, h, nv;
       
   176 
       
   177 		// Translate page
       
   178 		if (t.features.translate_i18n !== false) {
       
   179 			h = document.body.innerHTML;
       
   180 
       
   181 			// Replace a=x with a="x" in IE
       
   182 			if (tinymce.isIE)
       
   183 				h = h.replace(/ (value|title|alt)=([^"][^\s>]+)/gi, ' $1="$2"')
       
   184 
       
   185 			document.dir = t.editor.getParam('directionality','');
       
   186 
       
   187 			if ((nv = t.editor.translate(h)) && nv != h)
       
   188 				document.body.innerHTML = nv;
       
   189 
       
   190 			if ((nv = t.editor.translate(ti)) && nv != ti)
       
   191 				document.title = ti = nv;
       
   192 		}
       
   193 
       
   194 		document.body.style.display = '';
       
   195 
       
   196 		// Restore selection in IE when focus is placed on a non textarea or input element of the type text
       
   197 		if (tinymce.isIE)
       
   198 			document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
       
   199 
       
   200 		t.restoreSelection();
       
   201 		t.resizeToInnerSize();
       
   202 
       
   203 		// Set inline title
       
   204 		if (!t.isWindow)
       
   205 			t.editor.windowManager.setTitle(window, ti);
       
   206 		else
       
   207 			window.focus();
       
   208 
       
   209 		if (!tinymce.isIE && !t.isWindow) {
       
   210 			tinymce.dom.Event._add(document, 'focus', function() {
       
   211 				t.editor.windowManager.focus(t.id)
       
   212 			});
       
   213 		}
       
   214 
       
   215 		// Patch for accessibility
       
   216 		tinymce.each(t.dom.select('select'), function(e) {
       
   217 			e.onkeydown = tinyMCEPopup._accessHandler;
       
   218 		});
       
   219 
       
   220 		// Call onInit
       
   221 		// Init must be called before focus so the selection won't get lost by the focus call
       
   222 		tinymce.each(t.listeners, function(o) {
       
   223 			o.func.call(o.scope, t.editor);
       
   224 		});
       
   225 
       
   226 		// Move focus to window
       
   227 		if (t.getWindowArg('mce_auto_focus', true)) {
       
   228 			window.focus();
       
   229 
       
   230 			// Focus element with mceFocus class
       
   231 			tinymce.each(document.forms, function(f) {
       
   232 				tinymce.each(f.elements, function(e) {
       
   233 					if (t.dom.hasClass(e, 'mceFocus') && !e.disabled) {
       
   234 						e.focus();
       
   235 						return false; // Break loop
       
   236 					}
       
   237 				});
       
   238 			});
       
   239 		}
       
   240 
       
   241 		document.onkeyup = tinyMCEPopup._closeWinKeyHandler;
       
   242 	},
       
   243 
       
   244 	_accessHandler : function(e) {
       
   245 		e = e || window.event;
       
   246 
       
   247 		if (e.keyCode == 13 || e.keyCode == 32) {
       
   248 			e = e.target || e.srcElement;
       
   249 
       
   250 			if (e.onchange)
       
   251 				e.onchange();
       
   252 
       
   253 			return tinymce.dom.Event.cancel(e);
       
   254 		}
       
   255 	},
       
   256 
       
   257 	_closeWinKeyHandler : function(e) {
       
   258 		e = e || window.event;
       
   259 
       
   260 		if (e.keyCode == 27)
       
   261 			tinyMCEPopup.close();
       
   262 	},
       
   263 
       
   264 	_wait : function() {
       
   265 		var t = this, ti;
       
   266 
       
   267 		if (tinymce.isIE && document.location.protocol != 'https:') {
       
   268 			// Fake DOMContentLoaded on IE
       
   269 			document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');
       
   270 			document.getElementById("__ie_onload").onreadystatechange = function() {
       
   271 				if (this.readyState == "complete") {
       
   272 					t._onDOMLoaded();
       
   273 					document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
       
   274 				}
       
   275 			};
       
   276 		} else {
       
   277 			if (tinymce.isIE || tinymce.isWebKit) {
       
   278 				ti = setInterval(function() {
       
   279 					if (/loaded|complete/.test(document.readyState)) {
       
   280 						clearInterval(ti);
       
   281 						t._onDOMLoaded();
       
   282 					}
       
   283 				}, 10);
       
   284 			} else {
       
   285 				window.addEventListener('DOMContentLoaded', function() {
       
   286 					t._onDOMLoaded();
       
   287 				}, false);
       
   288 			}
       
   289 		}
       
   290 	}
       
   291 };
       
   292 
       
   293 tinyMCEPopup.init();
       
   294 tinyMCEPopup._wait(); // Wait for DOM Content Loaded