includes/clientside/sbedit.js
changeset 1039 4226cedb3bc4
parent 943 6eab82abc952
child 1274 673a1b6712fa
equal deleted inserted replaced
1038:6a04793ae13c 1039:4226cedb3bc4
     1 addOnloadHook(function()
     1 var sbedit_load = function()
     2   {
     2   {
     3     load_component(['jquery', 'jquery-ui']);
     3     if ( !window.jQuery )
       
     4     {
       
     5       load_component(['jquery', 'jquery-ui']);
       
     6       // this seems to be the only way to make the sortables init properly
       
     7       // FIXME find out what we're waiting for here, and wait on it the right way
       
     8       window.setTimeout(sbedit_load, 200);
       
     9       return true;
       
    10     }
     4     $('.sbedit-column').sortable({
    11     $('.sbedit-column').sortable({
     5       handle: '.sbedit-handle',
    12       handle: '.sbedit-handle',
     6       connectWith: '.sbedit-column',
    13       connectWith: '.sbedit-column',
     7       stop: function()
    14       stop: function()
     8       {
    15       {
     9         ajaxUpdateSidebarOrder();
    16         ajaxUpdateSidebarOrder();
    10       }
    17       }
    11     });
    18     });
    12   });
    19   };
       
    20   
       
    21 addOnloadHook(sbedit_load);
    13 
    22 
    14 function serialize_sidebar()
    23 function serialize_sidebar()
    15 {
    24 {
    16   var columns = {};
    25   var columns = {};
    17   var i = 0;
    26   var i = 0;
    18   $('.sbedit-column').each(function(i, e)
    27   try
    19     {
    28   {
    20       var arr = $(e).sortable('toArray');
    29     $('.sbedit-column').each(function(i, e)
    21       for ( var j = 0; j < arr.length; j++ )
    30       {
    22         arr[j] = parseInt(arr[j].replace(/^block:/, ''));
    31         // console.debug(e, ' TOARRAY: ', $(e).sortable('toArray'));
    23       
    32         var arr = $(e).sortable('toArray');
    24       i++;
    33         if ( !arr )
    25       columns[i] = arr;
    34         {
    26     });
    35           console.error('Retrieving order failed!');
       
    36           throw new Exception();
       
    37         }
       
    38           
       
    39         for ( var j = 0; j < arr.length; j++ )
       
    40           arr[j] = parseInt(arr[j].replace(/^block:/, ''));
       
    41         
       
    42         i++;
       
    43         columns[i] = arr;
       
    44       });
       
    45   }
       
    46   catch ( e )
       
    47   {
       
    48     return false;
       
    49   }
    27   return toJSONString(columns);
    50   return toJSONString(columns);
    28 }
    51 }
    29 
    52 
    30 function sbedit_open_editor(a)
    53 function sbedit_open_editor(a)
    31 {
    54 {
   259 
   282 
   260 function ajaxUpdateSidebarOrder()
   283 function ajaxUpdateSidebarOrder()
   261 {
   284 {
   262   setAjaxLoading();
   285   setAjaxLoading();
   263   var ser = serialize_sidebar();
   286   var ser = serialize_sidebar();
       
   287   if ( !ser )
       
   288   {
       
   289     var msg = document.createElement('div');
       
   290     $(msg)
       
   291       .addClass('error-box-mini')
       
   292       .text('jQuery failure: returned invalid serialized sidebar data')
       
   293       .css('position', 'fixed')
       
   294       .css('bottom', 1)
       
   295       .appendTo('body')
       
   296       .css('left', ( getWidth() / 2 ) - ( $(msg).width() / 2 ));
       
   297     setTimeout(function()
       
   298       {
       
   299         $(msg).fadeOut(500, function() { $(this).remove(); });
       
   300       }, 1000);
       
   301     unsetAjaxLoading();
       
   302     return false;
       
   303   }
   264   $.post(makeUrlNS('Special', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext)
   304   $.post(makeUrlNS('Special', 'EditSidebar', 'update_order'), { order: ser }, function(response, statustext)
   265     {
   305     {
   266       var msg = document.createElement('div');
   306       var msg = document.createElement('div');
   267       $(msg)
   307       $(msg)
   268         .addClass('info-box-mini')
   308         .addClass('info-box-mini')
   269         .text('Sidebar order saved.')
   309         .text($lang.get('sbedit_msg_order_saved'))
   270         .css('position', 'fixed')
   310         .css('position', 'fixed')
   271         .css('bottom', 1)
   311         .css('bottom', 1)
   272         .appendTo('body')
   312         .appendTo('body')
   273         .css('left', ( getWidth() / 2 ) - ( $(msg).width() / 2 ));
   313         .css('left', ( getWidth() / 2 ) - ( $(msg).width() / 2 ));
   274       setTimeout(function()
   314       setTimeout(function()