Changeset 6452


Ignore:
Timestamp:
Apr 23, 2014, 2:30:25 PM (8 years ago)
Author:
Nicklas Nordborg
Message:

References #1729: Move in-page <script> elements to external *.js files

Do not store references to all opened dialogs. Instead use window.open() with empty string to check if the window already exists or not.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/include/scripts/main-2.js

    r6450 r6452  
    11971197  dialogs.openPopup = function(url, name, width, height)
    11981198  {
     1199   
     1200    // Rescale according to user settings
     1201    var scale = App.getScale();
     1202    width = width * scale;
     1203    height = height * scale;
     1204
     1205    /*
     1206      We will try to position the popup window in the center of
     1207      the parent window.
     1208    */
     1209    var pos = App.getWindowPosition(window.top);
     1210    var top = Math.ceil(pos.top+(pos.height-height) / 2);
     1211    var left = Math.ceil(pos.left+(pos.width-width) / 2);
     1212    if (top < 0 && pos.top >= 0) top = 0;
     1213    if (left < 0 && pos.left >= 0) left = 0;
     1214
     1215    var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
     1216    options += ",top="+top+",left="+left+",width="+width+",height="+height;
     1217
    11991218    // Check if another window with the same name already exists
    1200     var oldWin = dialogs.getDialog(name);
     1219    var oldWin = window.open('', name, options);
    12011220    try
    12021221    {
    1203       if (oldWin && !oldWin.closed)
     1222      if (oldWin && !oldWin.closed && oldWin.App)
    12041223      {
    12051224        var msg = 'This window has already been opened. ';
     
    12171236    {}
    12181237   
    1219     // Rescale according to user settings
    1220     var scale = App.getScale();
    1221     width = width * scale;
    1222     height = height * scale;
    1223 
    1224     /*
    1225       We will try to position the popup window in the center of
    1226       the parent window.
    1227     */
    1228     var pos = App.getWindowPosition(window.top);
    1229     var top = Math.ceil(pos.top+(pos.height-height) / 2);
    1230     var left = Math.ceil(pos.left+(pos.width-width) / 2);
    1231     if (top < 0 && pos.top >= 0) top = 0;
    1232     if (left < 0 && pos.left >= 0) left = 0;
    1233 
    1234     var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
    1235     options += ",top="+top+",left="+left+",width="+width+",height="+height;
    1236 
    12371238    var newWin;
    12381239    if (App.isTooLongUrl(url))
     
    12471248    }
    12481249    newWin.focus();
    1249     Data.setPageValue(name, newWin, 'open.windows');
     1250    return newWin;
    12501251  }
    12511252 
     
    12561257  dialogs.getDialog = function(name)
    12571258  {
    1258     return Data.getPageValue(name, 'open.windows') || null;
     1259    var options = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes';
     1260    options += ',top=0,left=0,width=100,height=100';
     1261    var win = window.open('', name, options);
     1262    if (!win.closed && win.App)
     1263    {
     1264      return win;
     1265    }
     1266    else
     1267    {
     1268      win.close();
     1269      return null;
     1270    }
    12591271  }
    12601272 
Note: See TracChangeset for help on using the changeset viewer.