2008-01-17 16:44:05 +01:00
|
|
|
// Some global instances
|
|
|
|
var tinymce = null, tinyMCEPopup, tinyMCE;
|
2005-08-23 03:33:52 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
tinyMCEPopup = {
|
|
|
|
init : function() {
|
|
|
|
var t = this, w = t.getWin(), ti;
|
|
|
|
|
|
|
|
// Find API
|
|
|
|
tinymce = w.tinymce;
|
|
|
|
tinyMCE = w.tinyMCE;
|
|
|
|
t.editor = tinymce.EditorManager.activeEditor;
|
|
|
|
t.params = t.editor.windowManager.params;
|
|
|
|
|
|
|
|
// Setup local DOM
|
|
|
|
t.dom = t.editor.windowManager.createInstance('tinymce.dom.DOMUtils', document);
|
|
|
|
t.dom.loadCSS(t.editor.settings.popup_css);
|
|
|
|
|
|
|
|
// Setup on init listeners
|
|
|
|
t.listeners = [];
|
|
|
|
t.onInit = {
|
|
|
|
add : function(f, s) {
|
|
|
|
t.listeners.push({func : f, scope : s});
|
|
|
|
}
|
|
|
|
};
|
2005-08-23 03:33:52 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
t.isWindow = !t.getWindowArg('mce_inline');
|
|
|
|
t.id = t.getWindowArg('mce_window_id');
|
|
|
|
t.editor.windowManager.onOpen.dispatch(t.editor.windowManager, window);
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
2005-08-23 03:33:52 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
getWin : function() {
|
|
|
|
return window.dialogArguments || opener || parent || top;
|
|
|
|
},
|
2005-11-06 04:30:11 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
getWindowArg : function(n, dv) {
|
|
|
|
var v = this.params[n];
|
2005-08-23 03:33:52 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
return tinymce.is(v) ? v : dv;
|
|
|
|
},
|
2005-08-23 03:33:52 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
getParam : function(n, dv) {
|
|
|
|
return this.editor.getParam(n, dv);
|
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
getLang : function(n, dv) {
|
|
|
|
return this.editor.getLang(n, dv);
|
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-31 19:10:46 +01:00
|
|
|
execCommand : function(cmd, ui, val, a) {
|
2008-01-17 16:44:05 +01:00
|
|
|
this.restoreSelection();
|
2008-01-31 19:10:46 +01:00
|
|
|
return this.editor.execCommand(cmd, ui, val, a || {skip_focus : 1});
|
2008-01-17 16:44:05 +01:00
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
resizeToInnerSize : function() {
|
|
|
|
var t = this, n, b = document.body, vp = t.dom.getViewPort(window), dw, dh;
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
dw = t.getWindowArg('mce_width') - vp.w;
|
|
|
|
dh = t.getWindowArg('mce_height') - vp.h;
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (t.isWindow)
|
|
|
|
window.resizeBy(dw, dh);
|
|
|
|
else
|
|
|
|
t.editor.windowManager.resizeBy(dw, dh, t.id);
|
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
executeOnLoad : function(s) {
|
|
|
|
this.onInit.add(function() {
|
|
|
|
eval(s);
|
|
|
|
});
|
|
|
|
},
|
2005-11-06 04:30:11 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
storeSelection : function() {
|
|
|
|
this.editor.windowManager.bookmark = tinyMCEPopup.editor.selection.getBookmark('simple');
|
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
restoreSelection : function() {
|
|
|
|
var t = tinyMCEPopup;
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (!t.isWindow && tinymce.isIE)
|
|
|
|
t.editor.selection.moveToBookmark(t.editor.windowManager.bookmark);
|
|
|
|
},
|
2005-11-06 04:30:11 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
requireLangPack : function() {
|
|
|
|
var u = this.getWindowArg('plugin_url') || this.getWindowArg('theme_url');
|
2005-11-06 04:30:11 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (u)
|
|
|
|
document.write('<script type="text/javascript" src="' + u + '/langs/' + this.editor.settings.language + '_dlg.js' + '"></script>');
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
pickColor : function(e, element_id) {
|
|
|
|
this.execCommand('mceColorPicker', true, {
|
|
|
|
color : document.getElementById(element_id).value,
|
|
|
|
func : function(c) {
|
|
|
|
document.getElementById(element_id).value = c;
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-31 19:10:46 +01:00
|
|
|
try {
|
2008-01-17 16:44:05 +01:00
|
|
|
document.getElementById(element_id).onchange();
|
2008-01-31 19:10:46 +01:00
|
|
|
} catch (ex) {
|
|
|
|
// Try fire event, ignore errors
|
|
|
|
}
|
2006-11-21 01:55:06 +01:00
|
|
|
}
|
2008-01-17 16:44:05 +01:00
|
|
|
});
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
openBrowser : function(element_id, type, option) {
|
|
|
|
tinyMCEPopup.restoreSelection();
|
|
|
|
this.editor.execCallback('file_browser_callback', element_id, document.getElementById(element_id).value, type, window);
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
close : function() {
|
|
|
|
var t = this;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
t.dom = t.dom.doc = null; // Cleanup
|
|
|
|
t.editor.windowManager.close(window, t.id);
|
|
|
|
},
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Internal functions
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
_restoreSelection : function() {
|
|
|
|
var e = window.event.srcElement;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (e.nodeName == 'INPUT' && (e.type == 'submit' || e.type == 'button'))
|
|
|
|
tinyMCEPopup.restoreSelection();
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
/* _restoreSelection : function() {
|
|
|
|
var e = window.event.srcElement;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// If user focus a non text input or textarea
|
|
|
|
if ((e.nodeName != 'INPUT' && e.nodeName != 'TEXTAREA') || e.type != 'text')
|
|
|
|
tinyMCEPopup.restoreSelection();
|
|
|
|
},*/
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
_onDOMLoaded : function() {
|
|
|
|
var t = this, ti = document.title, bm, h;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Translate page
|
|
|
|
h = document.body.innerHTML;
|
2006-11-21 01:55:06 +01:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Replace a=x with a="x" in IE
|
|
|
|
if (tinymce.isIE)
|
|
|
|
h = h.replace(/ (value|title|alt)=([^\s>]+)/gi, ' $1="$2"');
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
document.body.innerHTML = t.editor.translate(h);
|
|
|
|
document.title = ti = t.editor.translate(ti);
|
|
|
|
document.body.style.display = '';
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Restore selection in IE when focus is placed on a non textarea or input element of the type text
|
|
|
|
if (tinymce.isIE)
|
|
|
|
document.attachEvent('onmouseup', tinyMCEPopup._restoreSelection);
|
2007-05-28 21:30:05 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
t.restoreSelection();
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Call onInit
|
|
|
|
tinymce.each(t.listeners, function(o) {
|
|
|
|
o.func.call(o.scope, t.editor);
|
|
|
|
});
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
t.resizeToInnerSize();
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (t.isWindow)
|
|
|
|
window.focus();
|
|
|
|
else
|
|
|
|
t.editor.windowManager.setTitle(ti, t.id);
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (!tinymce.isIE && !t.isWindow) {
|
|
|
|
tinymce.dom.Event._add(document, 'focus', function() {
|
|
|
|
t.editor.windowManager.focus(t.id)
|
|
|
|
});
|
|
|
|
}
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Patch for accessibility
|
|
|
|
tinymce.each(t.dom.select('select'), function(e) {
|
|
|
|
e.onkeydown = tinyMCEPopup._accessHandler;
|
|
|
|
});
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
// Move focus to window
|
|
|
|
window.focus();
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
_accessHandler : function(e) {
|
|
|
|
var e = e || window.event;
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (e.keyCode == 13 || e.keyCode == 32) {
|
|
|
|
e = e.target || e.srcElement;
|
2006-03-30 09:50:33 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
if (e.onchange)
|
|
|
|
e.onchange();
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
return tinymce.dom.Event.cancel(e);
|
|
|
|
}
|
2006-11-21 01:55:06 +01:00
|
|
|
},
|
2005-09-26 08:52:30 +02:00
|
|
|
|
2008-01-17 16:44:05 +01:00
|
|
|
_wait : function() {
|
|
|
|
var t = this, ti;
|
|
|
|
|
|
|
|
if (tinymce.isIE && document.location.protocol != 'https:') {
|
|
|
|
// Fake DOMContentLoaded on IE
|
|
|
|
document.write('<script id=__ie_onload defer src=\'javascript:""\';><\/script>');
|
|
|
|
document.getElementById("__ie_onload").onreadystatechange = function() {
|
|
|
|
if (this.readyState == "complete") {
|
|
|
|
t._onDOMLoaded();
|
|
|
|
document.getElementById("__ie_onload").onreadystatechange = null; // Prevent leak
|
|
|
|
}
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
if (tinymce.isIE || tinymce.isWebKit) {
|
|
|
|
ti = setInterval(function() {
|
|
|
|
if (/loaded|complete/.test(document.readyState)) {
|
|
|
|
clearInterval(ti);
|
|
|
|
t._onDOMLoaded();
|
|
|
|
}
|
|
|
|
}, 10);
|
|
|
|
} else {
|
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
|
|
|
t._onDOMLoaded();
|
|
|
|
}, false);
|
|
|
|
}
|
|
|
|
}
|
2006-11-21 01:55:06 +01:00
|
|
|
}
|
2008-01-17 16:44:05 +01:00
|
|
|
};
|
2005-09-26 08:52:30 +02:00
|
|
|
|
|
|
|
tinyMCEPopup.init();
|
2008-01-17 16:44:05 +01:00
|
|
|
tinyMCEPopup._wait(); // Wait for DOM Content Loaded
|