Changeset 6529


Ignore:
Timestamp:
Sep 19, 2014, 11:58:22 AM (8 years ago)
Author:
Nicklas Nordborg
Message:

References #1841: Investigate problems with popup windows

I was not able to repoduce the problems. Main suspect is a timeout in popup.js that was too short and caused the browser to report bogus window sizes. The timeout is not really critical as long as the user doesn't resize the browser window before the timeout.

It could also be an issue with 'close_popup' script that re-applied the size correction a second time, though this should only be noticable at the pixel level and the issue was seen also when aborting a dialog without saving. In any case, the 'close_popup' script has been fixed so that it doesn't care about dialog positions anymore.

The dialog positions are now stored in the 'localStorage' instead of in javascript variables. This should makes it possible to remember positions between browser restarts, but to be on the safe side against filling the local storage or currupted values, the old values are forgotten when logging in.

Location:
branches/3.3-stable/www
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-stable/www/common/close_popup.jsp

    r6387 r6529  
    6464<base:page type="popup" title="<%=title%>">
    6565<base:head scripts="~close_popup.js" />
    66 <base:body>
     66<base:body data-no-dialog-position="1">
    6767  <div id="page-data" class="datacontainer"
    6868    data-wait="<%=millisecondsToWait%>"
  • branches/3.3-stable/www/include/scripts/main-2.js

    r6526 r6529  
    2828  var topWin = null;
    2929  var app = {};
    30  
     30  var internal = {};
     31
     32  var root;
     33  var sessionId;
     34  var storage;
     35  var rememberDialogPositions;
     36
    3137  /**
    3238    Get the root URL path of this BASE installation. Always ends with a '/' (eg. /base/)
     
    3440  app.getRoot = function()
    3541  {
    36     return Data.get(document.body, 'app-root');
     42    return root;
    3743  }
    3844 
     
    4349  app.getSessionId = function()
    4450  {
    45     return Data.get(document.body, 'session-id', '');
     51    return sessionId;
    4652  }
    4753
     
    8793  app.rememberDialogPositions = function()
    8894  {
    89     return Data.int(document.body, 'remember-dialog-positions', 1);
     95    return rememberDialogPositions;
    9096  }
    9197 
     
    193199  app.localStorage = function()
    194200  {
    195     var storage = null;
     201    return storage;
     202  }
     203 
     204  app.setLocal = function(key, value)
     205  {
     206    if (storage == null) return;
     207    storage.setItem(root+':'+key, value);
     208  }
     209 
     210  app.getLocal = function(key, defaultValue)
     211  {
     212    if (storage == null) return defaultValue || null;
     213    return storage.getItem(root+':'+key) || defaultValue || null;
     214  }
     215 
     216  app.removeLocal = function(key)
     217  {
     218    if (storage == null) return;
     219    storage.removeItem(root+':'+key);
     220  }
     221 
     222  /**
     223    Write a message to the browser debug console.
     224  */
     225  app.debug = function(message)
     226  {
     227    console.log(message);
     228  }
     229 
     230  internal.initApp = function()
     231  {
     232    root = Data.get(document.body, 'app-root');
     233    sessionId = Data.get(document.body, 'session-id', '');
     234
    196235    try
    197236    {
     
    203242      // selected for cookies, so we have to catch this situation
    204243    }
    205     return storage;
    206   }
    207  
    208   /**
    209     Write a message to the browser debug console.
    210   */
    211   app.debug = function(message)
    212   {
    213     console.log(message);
    214   }
     244   
     245    rememberDialogPositions = Data.int(document.body, 'remember-dialog-positions', 1) && storage != null;
     246  }
     247 
     248  document.addEventListener('DOMContentLoaded', internal.initApp, false);
    215249 
    216250  return app;
     
    12201254  dialogs.openPopup = function(url, name, width, height)
    12211255  {
    1222     // Get last position of the window
    1223     var position = null;
    1224     if (App.rememberDialogPositions())
    1225     {
    1226       position = JSON.parse(Data.getPageValue("last-position", name));
    1227     }
    1228 
    1229     if (!position)
     1256    // Get last position of the window -- can be null
     1257    var position = internal.getLastDialogPosition(name);
     1258
     1259    if (position == null)
    12301260    {
    12311261      // If no last position is know, use the specified settings
     
    12451275
    12461276    var options = "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes";
     1277    options += ",top="+position.top+",left="+position.left+",width="+position.width+",height="+position.height;
    12471278    // Check if another window with the same name already exists
    1248     var oldWin = window.open('', name, options+",top="+position.top+",left="+position.left+",width="+position.width+",height="+position.height);
     1279    var oldWin = window.open('', name, options);
    12491280    try
    12501281    {
     
    12581289          return;
    12591290        }
    1260         position = App.getWindowPosition(oldWin);
    1261         oldWin.close();
    12621291        url += '&warnIfOpen=0';
    12631292      }
     
    12661295    {}
    12671296   
    1268     if (App.rememberDialogPositions())
    1269     {
    1270       Data.setPageValue('requested-position', JSON.stringify(position), name);
    1271     }
    1272     options += ",top="+position.top+",left="+position.left+",width="+position.width+",height="+position.height;
     1297    internal.saveRequestedDialogPosition(name, position);
     1298
    12731299    var newWin;
    12741300    if (App.isTooLongUrl(url))
     
    12851311    newWin.focus();
    12861312    return newWin;
     1313  }
     1314 
     1315  internal.getLastDialogPosition = function(name)
     1316  {
     1317    if (!App.rememberDialogPositions()) return null;
     1318    return JSON.parse(App.getLocal('dialog-position:'+name));
     1319  }
     1320 
     1321  internal.saveRequestedDialogPosition = function(name, position)
     1322  {
     1323    if (!App.rememberDialogPositions()) return;
     1324    App.setLocal('dialog-position-req:'+name, JSON.stringify(position));
     1325  }
     1326 
     1327  dialogs.forgetDialogPositions = function()
     1328  {
     1329    var storage = App.localStorage();
     1330    if (!storage) return;
     1331   
     1332    var prefix = App.getRoot()+':dialog-position:';
     1333   
     1334    for (var i = storage.length-1; i >= 0; i--)
     1335    {
     1336      var key = storage.key(i);
     1337      if (key.indexOf(prefix) == 0) storage.removeItem(key);
     1338    }
    12871339  }
    12881340 
  • branches/3.3-stable/www/include/scripts/popup.js

    r6507 r6529  
    2929  var dy = 0;
    3030 
     31  var saveDialogPosition = false;
     32 
    3133  // If the popup dialog is read-only BASE will not
    3234  // display a warning when trying to re-open the same dialog
     
    3941  internal.delayInitPosition = function()
    4042  {
    41     setTimeout(internal.initPosition, 20);
     43    saveDialogPosition = window.top.name && App.rememberDialogPositions();
     44    if (saveDialogPosition) setTimeout(internal.initPosition, 500);
    4245  }
    4346 
     
    4649  internal.initPosition = function()
    4750  {
    48     if (window.top.name && App.rememberDialogPositions())
     51    var key = 'dialog-position-req:'+window.top.name;
     52    var rpos = JSON.parse(App.getLocal(key));
     53//    alert('['+window.screenX+', '+window.screenY+'], ['+rpos.width+', ' + rpos.height+'], ['+window.innerWidth+', ' + window.innerHeight+'], [' + window.outerWidth+', '+window.outerHeight+']');
     54    if (rpos)
    4955    {
    50       var rpos = JSON.parse(Data.getPageValue("requested-position", window.top.name));
     56      App.removeLocal(key);
    5157      var cpos = App.getWindowPosition(window.top);
    5258      dx = rpos.width-cpos.width;
     
    5763  internal.savePosition = function()
    5864  {
    59     if (window.top.name && App.rememberDialogPositions())
    60     {
    61       var pos = App.getWindowPosition(window.top);
    62       pos.width += dx;
    63       pos.height += dy;
    64       Data.setPageValue("last-position", JSON.stringify(pos), window.top.name);
    65     }
     65    if (!saveDialogPosition || Data.int(document.body, 'no-dialog-position')) return;
     66   
     67    var pos = App.getWindowPosition(window.top);
     68    pos.width += dx;
     69    pos.height += dy;
     70    App.setLocal('dialog-position:'+window.top.name, JSON.stringify(pos));
    6671  }
    6772 
  • branches/3.3-stable/www/index.jsp

    r6138 r6529  
    3939%>
    4040<base:page>
    41   <base:head>
     41  <base:head scripts="~index.js">
    4242  <%
    4343  if (RssNewsFeed.isEnabled())
  • branches/3.3-stable/www/login.js

    r6523 r6529  
    8181    if (storage)
    8282    {
    83       storage.setItem('last-login', lastLogin);
     83      App.setLocal('last-login', lastLogin);
    8484    }
    8585    else
     
    9999    if (storage)
    100100    {
    101       lastLogin = storage.getItem('last-login');
     101      lastLogin = App.getLocal('last-login');
    102102    }
    103103    if (!lastLogin)
  • branches/3.3-stable/www/my_base/user/preferences.js

    r6400 r6529  
    2626{
    2727  var preferences = {};
     28 
     29  var initialRememberDialogPositions;
    2830 
    2931  preferences.initPage = function()
     
    6668    Events.addEventHandler('stickyItems', 'dblclick', Preferences.moveFromSticky);
    6769    Events.addEventHandler('allItems', 'dblclick', Preferences.moveToSticky);
     70   
     71    var frm = document.forms['preferences'];
     72    initialRememberDialogPositions = frm.remember_positions.checked;
     73   
     74    if (!App.localStorage())
     75    {
     76      frm.remember_positions.checked = false;
     77      frm.remember_positions.disabled = true;
     78      Doc.element('rememberPositions').title = 'Your browser doesn\'t support this feature';
     79      Doc.addClass('rememberPositions', 'disabled');
     80    }
    6881  }
    6982
     
    113126    {
    114127      var sticky_items = frm.sticky_items;
    115       for (var i = 0; i < sticky_items.length; i++) // >
     128      for (var i = 0; i < sticky_items.length; i++)
    116129      {
    117130        sticky_items.options[i].selected = true;
    118131      }
     132     
     133      if (initialRememberDialogPositions && !frm.remember_positions.checked)
     134      {
     135        Dialogs.forgetDialogPositions();
     136        Data.set(document.body, 'no-dialog-position', 1);
     137      }
     138     
    119139      frm.submit();
    120140    }
  • branches/3.3-stable/www/my_base/user/preferences.jsp

    r6503 r6529  
    300300          <th>Dialogs</th>
    301301          <td>
    302             <label><input type="checkbox" name="remember_positions" value="1"
     302            <label id="rememberPositions"><input type="checkbox" name="remember_positions" value="1"
    303303              <%=rememberDialogPositions ? "checked" : "" %>
    304304              >Remember positions</label>
Note: See TracChangeset for help on using the changeset viewer.