Index: branches/RC/core/admin_templates/js/script.js =================================================================== diff -u -r11412 -r11482 --- branches/RC/core/admin_templates/js/script.js (.../script.js) (revision 11412) +++ branches/RC/core/admin_templates/js/script.js (.../script.js) (revision 11482) @@ -151,12 +151,13 @@ if (submitted) { return; } + submitted = true; - unload_legal = true; + unload_legal = true; // bug: when opening new popup from this window, then this window is not refreshed and this mark stays forever var $form = document.getElementById($form_name); - if (typeof $form.onsubmit == "function") { + if (typeof $form.onsubmit == 'function') { $form.onsubmit(); } @@ -374,8 +375,31 @@ submit_event(prefix,'',$t,url); } -function openwin($url,$name,$width,$height) +function openwin($url, $name, $width, $height, $options) { + var $settings = { + url: base_url + 'core/admin_templates/blank.html?width=' + $width + '&height=' + $height + '&TB_iframe=true&modal=true', + caption: 'Loading ...', + onAfterShow: function () { + getFrame('main').onAfterWindowOpen($url, $name); + } + }; + + if ($options !== undefined) { + $.extend($settings, $options); + } + + if (window.name != 'main') { + // all popups are opened based on main frame + return getFrame('main').TB.show($settings); + } + + TB.show($settings); + + return ; + + + // prevent window from opening larger, then screen resolution on user's computer (to Kostja) // alert('openwin: name = ['+$name+']'); @@ -390,6 +414,21 @@ return window.open($url,$name,$window_params); } +function onAfterWindowOpen($url, $window_name) { + // this is always invoked from "main" frame + var $popup_window = $('#' + TB.getId('TB_iframeContent')).get(0).contentWindow; + if (!$.isFunction($popup_window.onLoad)) { + // iframe onload happens on frame content change too -> don't react on it + return ; + } + + $popup_window.onLoad(); + $popup_window.name = $window_name; + $popup_window.location.href = $url; + + TB.setWindowMetaData('window_name', $window_name); // used to simulate window.opener functionality +} + function OnResizePopup(e) { if (!document.all) { var $winW = window.innerWidth; @@ -429,27 +468,60 @@ } $window_size = $default_size; } - var $kf = document.getElementById($form_name); - var $window_name = $t.replace(/(\/|-)/g, '_'); // replace "/" and "-" with "_" $window_size = $window_size.split('x'); + var $window_name = $t.replace(/(\/|-)/g, '_'); // replace "/" and "-" with "_" - openwin('', $window_name, $window_size[0], $window_size[1]); + var $options = { + onAfterShow: function () { + getFrame('main').onAfterOpenPopup($prefix_special, $event, $t); + } + }; + + openwin('', $window_name, $window_size[0], $window_size[1], $options); +} + +function onAfterOpenPopup($prefix_special, $event, $t) { + // this is always invoked from "main" frame + var $popup_window = $('#' + TB.getId('TB_iframeContent')).get(0).contentWindow; + if (!$.isFunction($popup_window.onLoad)) { + // iframe onload happens on frame content change too -> don't react on it + return ; + } + + var $window_name = $t.replace(/(\/|-)/g, '_'); // replace "/" and "-" with "_" + + $popup_window.onLoad(); + $popup_window.name = $window_name; + TB.setWindowMetaData('window_name', $window_name); // used to simulate window.opener functionality + + var $opener = getWindowOpener($popup_window); + if ($opener === null) { + // we are already in main window + $opener = window; + } + + var $kf = $opener.document.getElementById($opener.$form_name); $kf.target = $window_name; - var $prev_opener = opener_action('p'); - event_bak = get_hidden_field('events[' + $prefix_special + ']') - if (!event_bak) event_bak = ''; - submit_event($prefix_special, $event, $t); - opener_action($prev_opener); // restore opener in parent window - set_hidden_field('events[' + $prefix_special + ']', event_bak); // restore event + var $prev_opener = $opener.opener_action('p'); + event_bak = $opener.get_hidden_field('events[' + $prefix_special + ']') + if (!event_bak) { + event_bak = ''; + } + $opener.submit_event($prefix_special, $event, $t); + + $opener.opener_action($prev_opener); // restore opener in parent window + $opener.set_hidden_field('events[' + $prefix_special + ']', event_bak); // restore event + // AJAX popup size respoce is received after std_edit_item/std_precreate_item function exit - set_hidden_field($prefix_special + '_mode', null); + $opener.set_hidden_field($prefix_special + '_mode', null); - Application.processHooks($prefix_special + ':OnAfterOpenPopup'); + $opener.Application.processHooks($prefix_special + ':OnAfterOpenPopup'); } + function openSelector($prefix, $url, $dst_field, $window_size, $event) { // if url has additional params - store it and make hidden fields from it (later, below) @@ -593,7 +665,8 @@ if ($value === null) { if ($field) { - $kf.removeChild($field); +// alert('tag name on remove: ' + $field.parentNode.tagName); + $field.parentNode.removeChild($field); // bug: sometimes hidden fields are inside BODY tag in DOM model, why? } return true; } @@ -778,8 +851,14 @@ function set_window_title($title) { var $window = window; - if($window.parent) $window = $window.parent; - $window.document.title = (main_title.length ? main_title + ' - ' : '') + $title; + + if ($window.name != 'main') { + // traverse through real popups + $window = getFrame('main'); + } + + $window.top.document.title = (main_title.length ? main_title + ' - ' : '') + $title; + $window.TB.setWindowTitle($title); } function set_filter($prefix_special, $filter_id, $filter_value, $ajax) @@ -1421,6 +1500,7 @@ var curleft = curtop = 0; if (obj.offsetParent) { + // could raise "Unspecified error" in IE curleft = obj.offsetLeft - (with_scroll ? obj.scrollLeft : 0) curtop = obj.offsetTop - (with_scroll ? obj.scrollTop : 0) while (obj = obj.offsetParent) { @@ -1465,11 +1545,22 @@ Application.setHook('m:OnAfterWindowLoad', func); } -function replaceFireBug() { - if (!window.console || !console.firebug) { - var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml", - "group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"]; +function replaceFireBug($load) { + if (!isset($load)) { + $load = true; + } + if (window.console === undefined || !console.firebug) { + if ($load && $.isFunction(window.loadFirebugConsole)) { + window.loadFirebugConsole(); + return replaceFireBug(false); + } + + var names = [ + 'log', 'debug', 'info', 'warn', 'error', 'assert', 'dir', 'dirxml', + 'group', 'groupEnd', 'time', 'timeEnd', 'count', 'trace', 'profile', 'profileEnd' + ]; + window.console = {}; for (var i = 0; i < names.length; ++i) { window.console[names[i]] = function($msg) { @@ -1491,13 +1582,13 @@ el.fireEvent('onchange'); } } -function WatchClosing(win, url) +function WatchClosing(win, $url) { window.setTimeout(function() { if (win.closed) { var req = Request.getRequest(); - var $ajax_mark = (url.indexOf('?') ? '&' : '?') + 'ajax=yes'; - req.open('GET', url + $ajax_mark, false); //!!!SYNCRONIOUS!!! REQUEST (3rd param = false!!!) + var $ajax_mark = ($url.indexOf('?') ? '&' : '?') + 'ajax=yes'; + req.open('GET', $url + $ajax_mark, false); //!!!SYNCRONIOUS!!! REQUEST (3rd param = false!!!) req.send(null); } }, @@ -1528,5 +1619,30 @@ return ; } - getFrame('head').$('#help_link').attr('href', $user_docs_url + '/' + $title_preset); -} \ No newline at end of file + $('#help_link', getFrame('head').document).attr('href', $user_docs_url + '/' + $title_preset); +} + +// window management functions: + +function getWindowOpener($window) { + // use this intead of "window.opener" + if ($window.name == 'main') { + return null; + } + + return getFrame('main').TB.findWindow($window.name, -1); +} + +function window_close($close_callback) { + // use this instead of "window.close();" + if (window.name == 'main') { + return ; + } + + if ($close_callback !== undefined) { + return getFrame('main').TB.remove(null, $close_callback); + } + + return getFrame('main').TB.remove(); +} +