From 1c00b90749b93f0f305b43714cb7e2fc58b0bf56 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 7 May 2010 15:46:35 -0600 Subject: [PATCH] Horde.popup() improvements Add name and noalert options. Return true on success. --- horde/js/popup.js | 48 ++++++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/horde/js/popup.js b/horde/js/popup.js index 4cbde2030..d6c367081 100644 --- a/horde/js/popup.js +++ b/horde/js/popup.js @@ -12,13 +12,17 @@ window.Horde = window.Horde || {}; /** * Open a popup window. * - * @param object $opts The following params: + * Parameters: * 'height' - The height of the popup window. (Default: 650 px) * 'menu' - Show the browser menu in the popup? (Default: no) + * 'name' - The name for the window. (Default: none) + * 'noalert' - Don't show alert if window could not open. (Default: false) * 'onload' - A function to call when the window is loaded. (Default: none) * 'params' - Any additional params to pass to the script. (Default: no args) * 'width' - The width of the popup window. (Default: 700 px) * 'url' - The URL to open in the popup window. + * + * Returns true if window was opened, false otherwise. */ Horde.popup = function(opts) { @@ -26,11 +30,11 @@ Horde.popup = function(opts) opts = decodeURIComponent(opts).evalJSON(true); } - var q, win, + var name, q, win, height = Math.min(screen.height - 75, opts.height || 650), menu = (opts.menu ? 'yes' : 'no'), - name = new Date().getTime(), params = $H(), + uniq = new Date().getTime(), url = opts.url, width = Math.min(screen.width - 75, opts.width || 700); @@ -45,23 +49,31 @@ Horde.popup = function(opts) params.set(a.key, unescape(a.value)); }); } - params.set('uniq', name); + params.set('uniq', uniq); - win = window.open(url + '?' + params.toQueryString(), name, 'menubar=' + menu + ',toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',left=0,top=0'); + win = window.open(url + '?' + params.toQueryString(), opts.name || uniq, 'menubar=' + menu + ',toolbar=no,location=no,status=yes,scrollbars=yes,resizable=yes,width=' + width + ',height=' + height + ',left=0,top=0'); if (!win) { - alert(Horde.popup_block_text); - } else { - if (opts.onload) { - opts.onload = eval(opts.onload); - win.onload = opts.onload.curry(win); - } - if (Object.isUndefined(win.name)) { - win.name = name; - } - if (Object.isUndefined(win.opener)) { - win.opener = self; + if (!opts.noalert) { + alert(Horde.popup_block_text); } - win.focus(); + return false; } -}; + + if (opts.onload) { + opts.onload = eval(opts.onload); + win.onload = opts.onload.curry(win); + } + + if (Object.isUndefined(win.name)) { + win.name = name; + } + + if (Object.isUndefined(win.opener)) { + win.opener = self; + } + + win.focus(); + + return true; +} -- 2.11.0