4 * Copyright 2009, Moxiecode Systems AB
5 * Released under LGPL License.
7 * License: http://tinymce.moxiecode.com/license
8 * Contributing: http://tinymce.moxiecode.com/contributing
12 var Dispatcher = tinymce.util.Dispatcher, each = tinymce.each, isIE = tinymce.isIE, isOpera = tinymce.isOpera;
15 * This class handles the creation of native windows and dialogs. This class can be extended to provide for example inline dialogs.
17 * @class tinymce.WindowManager
19 * // Opens a new dialog with the file.htm file and the size 320x240
20 * // It also adds a custom parameter this can be retrieved by using tinyMCEPopup.getWindowArg inside the dialog.
21 * tinyMCE.activeEditor.windowManager.open({
29 * // Displays an alert box using the active editors window manager instance
30 * tinyMCE.activeEditor.windowManager.alert('Hello world!');
32 * // Displays an confirm box and an alert message will be displayed depending on what you choose in the confirm
33 * tinyMCE.activeEditor.windowManager.confirm("Do you want to do something", function(s) {
35 * tinyMCE.activeEditor.windowManager.alert("Ok");
37 * tinyMCE.activeEditor.windowManager.alert("Cancel");
40 tinymce.create('tinymce.WindowManager', {
42 * Constructs a new window manager instance.
45 * @method WindowManager
46 * @param {tinymce.Editor} ed Editor instance that the windows are bound to.
48 WindowManager : function(ed) {
52 t.onOpen = new Dispatcher(t);
53 t.onClose = new Dispatcher(t);
62 * @param {Object} s Optional name/value settings collection contains things like width/height/url etc.
63 * @option {String} title Window title.
64 * @option {String} file URL of the file to open in the window.
65 * @option {Number} width Width in pixels.
66 * @option {Number} height Height in pixels.
67 * @option {Boolean} resizable Specifies whether the popup window is resizable or not.
68 * @option {Boolean} maximizable Specifies whether the popup window has a "maximize" button and can get maximized or not.
69 * @option {Boolean} inline Specifies whether to display in-line (set to 1 or true for in-line display; requires inlinepopups plugin).
70 * @option {String/Boolean} popup_css Optional CSS to use in the popup. Set to false to remove the default one.
71 * @option {Boolean} translate_i18n Specifies whether translation should occur or not of i18 key strings. Default is true.
72 * @option {String/bool} close_previous Specifies whether a previously opened popup window is to be closed or not (like when calling the file browser window over the advlink popup).
73 * @option {String/bool} scrollbars Specifies whether the popup window can have scrollbars if required (i.e. content larger than the popup size specified).
74 * @param {Object} p Optional parameters/arguments collection can be used by the dialogs to retrive custom parameters.
75 * @option {String} plugin_url url to plugin if opening plugin window that calls tinyMCEPopup.requireLangPack() and needs access to the plugin language js files
77 open : function(s, p) {
78 var t = this, f = '', x, y, mo = t.editor.settings.dialog_type == 'modal', w, sw, sh, vp = tinymce.DOM.getViewPort(), u;
80 // Default some options
83 sw = isOpera ? vp.w : screen.width; // Opera uses windows inside the Opera window
84 sh = isOpera ? vp.h : screen.height;
85 s.name = s.name || 'mc_' + new Date().getTime();
86 s.width = parseInt(s.width || 320);
87 s.height = parseInt(s.height || 240);
89 s.left = s.left || parseInt(sw / 2.0) - (s.width / 2.0);
90 s.top = s.top || parseInt(sh / 2.0) - (s.height / 2.0);
92 p.mce_width = s.width;
93 p.mce_height = s.height;
94 p.mce_auto_focus = s.auto_focus;
100 s.dialogWidth = s.width + 'px';
101 s.dialogHeight = s.height + 'px';
102 s.scroll = s.scrollbars || false;
106 // Build features string
107 each(s, function(v, k) {
108 if (tinymce.is(v, 'boolean'))
109 v = v ? 'yes' : 'no';
111 if (!/^(name|url)$/.test(k)) {
113 f += (f ? ';' : '') + k + ':' + v;
115 f += (f ? ',' : '') + k + '=' + v;
121 t.onOpen.dispatch(t, s, p);
124 u = tinymce._addVer(u);
129 window.showModalDialog(u, window, f);
131 w = window.open(u, s.name, f);
137 alert(t.editor.getLang('popup_blocked'));
141 * Closes the specified window. This will also dispatch out a onClose event.
144 * @param {Window} w Native window object to close.
146 close : function(w) {
148 this.onClose.dispatch(this);
152 * Creates a instance of a class. This method was needed since IE can't create instances
153 * of classes from a parent window due to some reference problem. Any arguments passed after the class name
154 * will be passed as arguments to the constructor.
156 * @method createInstance
157 * @param {String} cl Class name to create an instance of.
158 * @return {Object} Instance of the specified class.
160 * var uri = tinyMCEPopup.editor.windowManager.createInstance('tinymce.util.URI', 'http://www.somesite.com');
161 * alert(uri.getURI());
163 createInstance : function(cl, a, b, c, d, e) {
164 var f = tinymce.resolve(cl);
166 return new f(a, b, c, d, e);
170 * Creates a confirm dialog. Please don't use the blocking behavior of this
171 * native version use the callback method instead then it can be extended.
174 * @param {String} t Title for the new confirm dialog.
175 * @param {function} cb Callback function to be executed after the user has selected ok or cancel.
176 * @param {Object} s Optional scope to execute the callback in.
178 * // Displays an confirm box and an alert message will be displayed depending on what you choose in the confirm
179 * tinyMCE.activeEditor.windowManager.confirm("Do you want to do something", function(s) {
181 * tinyMCE.activeEditor.windowManager.alert("Ok");
183 * tinyMCE.activeEditor.windowManager.alert("Cancel");
186 confirm : function(t, cb, s, w) {
189 cb.call(s || this, w.confirm(this._decode(this.editor.getLang(t, t))));
193 * Creates a alert dialog. Please don't use the blocking behavior of this
194 * native version use the callback method instead then it can be extended.
197 * @param {String} t Title for the new alert dialog.
198 * @param {function} cb Callback function to be executed after the user has selected ok.
199 * @param {Object} s Optional scope to execute the callback in.
201 * // Displays an alert box using the active editors window manager instance
202 * tinyMCE.activeEditor.windowManager.alert('Hello world!');
204 alert : function(tx, cb, s, w) {
208 w.alert(t._decode(t.editor.getLang(tx, tx)));
215 * Resizes the specified window or id.
217 * @param {Number} dw Delta width.
218 * @param {Number} dh Delta height.
219 * @param {window/id} win Window if the dialog isn't inline. Id if the dialog is inline.
221 resizeBy : function(dw, dh, win) {
222 win.resizeBy(dw, dh);
225 // Internal functions
227 _decode : function(s) {
228 return tinymce.DOM.decode(s).replace(/\\n/g, '\n');