Fixed one unlocalized string in sidebar editor; fixed sidebar editor jQuery init race condition seen under Firefox and Chromium on 64-bit
authorDan
Wed, 08 Jul 2009 18:50:17 -0400
changeset 1039 4226cedb3bc4
parent 1038 6a04793ae13c
child 1040 c631faf25a12
Fixed one unlocalized string in sidebar editor; fixed sidebar editor jQuery init race condition seen under Firefox and Chromium on 64-bit
includes/clientside/sbedit.js
language/english/admin.json
--- a/includes/clientside/sbedit.js	Wed Jul 08 18:49:04 2009 -0400
+++ b/includes/clientside/sbedit.js	Wed Jul 08 18:50:17 2009 -0400
@@ -1,6 +1,13 @@
-addOnloadHook(function()
+var sbedit_load = function()
   {
-    load_component(['jquery', 'jquery-ui']);
+    if ( !window.jQuery )
+    {
+      load_component(['jquery', 'jquery-ui']);
+      // this seems to be the only way to make the sortables init properly
+      // FIXME find out what we're waiting for here, and wait on it the right way
+      window.setTimeout(sbedit_load, 200);
+      return true;
+    }
     $('.sbedit-column').sortable({
       handle: '.sbedit-handle',
       connectWith: '.sbedit-column',
@@ -9,21 +16,37 @@
         ajaxUpdateSidebarOrder();
       }
     });
-  });
+  };
+  
+addOnloadHook(sbedit_load);
 
 function serialize_sidebar()
 {
   var columns = {};
   var i = 0;
-  $('.sbedit-column').each(function(i, e)
-    {
-      var arr = $(e).sortable('toArray');
-      for ( var j = 0; j < arr.length; j++ )
-        arr[j] = parseInt(arr[j].replace(/^block:/, ''));
-      
-      i++;
-      columns[i] = arr;
-    });
+  try
+  {
+    $('.sbedit-column').each(function(i, e)
+      {
+        // console.debug(e, ' TOARRAY: ', $(e).sortable('toArray'));
+        var arr = $(e).sortable('toArray');
+        if ( !arr )
+        {
+          console.error('Retrieving order failed!');
+          throw new Exception();
+        }
+          
+        for ( var j = 0; j < arr.length; j++ )
+          arr[j] = parseInt(arr[j].replace(/^block:/, ''));
+        
+        i++;
+        columns[i] = arr;
+      });
+  }
+  catch ( e )
+  {
+    return false;
+  }
   return toJSONString(columns);
 }
 
@@ -261,12 +284,29 @@
 {
   setAjaxLoading();
   var ser = serialize_sidebar();
+  if ( !ser )
+  {
+    var msg = document.createElement('div');
+    $(msg)
+      .addClass('error-box-mini')
+      .text('jQuery failure: returned invalid serialized sidebar data')
+      .css('position', 'fixed')
+      .css('bottom', 1)
+      .appendTo('body')
+      .css('left', ( getWidth() / 2 ) - ( $(msg).width() / 2 ));
+    setTimeout(function()
+      {
+        $(msg).fadeOut(500, function() { $(this).remove(); });
+      }, 1000);
+    unsetAjaxLoading();
+    return false;
+  }
   $.post(makeUrlNS('Special', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext)
     {
       var msg = document.createElement('div');
       $(msg)
         .addClass('info-box-mini')
-        .text('Sidebar order saved.')
+        .text($lang.get('sbedit_msg_order_saved'))
         .css('position', 'fixed')
         .css('bottom', 1)
         .appendTo('body')
--- a/language/english/admin.json	Wed Jul 08 18:49:04 2009 -0400
+++ b/language/english/admin.json	Wed Jul 08 18:50:17 2009 -0400
@@ -1187,6 +1187,7 @@
       msg_block_moved: 'Item moved.',
       msg_block_deleted: 'Item deleted.',
       msg_plugin_not_loaded: 'Plugin isn\'t loaded',
+      msg_order_saved: 'Sidebar order saved.',
       note_block_unnamed: 'Unnamed',
       hint_rename: 'Double-click to rename this block',
       note_block_disabled: '(disabled)',