includes/clientside/sbedit.js
changeset 943 6eab82abc952
parent 886 041c86ff16d5
child 1039 4226cedb3bc4
equal deleted inserted replaced
942:18db38c70a41 943:6eab82abc952
    50     .attr('id', 'sb_blockedit')
    50     .attr('id', 'sb_blockedit')
    51     .addClass('sbedit-float')
    51     .addClass('sbedit-float')
    52     .css('height', $(parent).height())
    52     .css('height', $(parent).height())
    53     .css('top', offset.top)
    53     .css('top', offset.top)
    54     .css('left', offset.left)
    54     .css('left', offset.left)
    55     .appendTo('body')
    55     .appendTo('body');
       
    56   var item_id = parseInt($(parent).attr('id').replace(/^block:/, ''));
       
    57   
       
    58   $(box)
    56     .animate({ width: 500, height: 400, top: top, left: (getWidth() / 2) - 250 }, 400, function()
    59     .animate({ width: 500, height: 400, top: top, left: (getWidth() / 2) - 250 }, 400, function()
    57       {
    60       {
    58         var whitey = whiteOutElement(this);
    61         var whitey = whiteOutElement(this);
    59         $(this).append('<textarea style="width: 100%; height: 360px;" rows="20" cols="80"></textarea>');
    62         $(this).append('<textarea style="width: 98%; height: 360px; margin: 0 auto; display: block;" rows="20" cols="80"></textarea>');
    60         $(this).append('<p style="text-align: center;"><a href="#" onclick="sbedit_edit_save(this); return false;">' + $lang.get('etc_save_changes') + '</a> | <a href="#" onclick="sbedit_edit_cancel(this); return false;">' + $lang.get('etc_cancel') + '</a></p>');
    63         $(this).append('<p style="text-align: center;"><a href="#" onclick="sbedit_edit_save(this); return false;">' + $lang.get('etc_save_changes') + '</a> | <a href="#" onclick="sbedit_edit_cancel(this); return false;">' + $lang.get('etc_cancel') + '</a></p>');
    61         $.get(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id=' + this.item_id), {}, function(response, statustext)
    64         $.get(makeUrlNS('Special', 'EditSidebar', 'action=getsource&noheaders&id=' + item_id), {}, function(response, statustext)
    62           {
    65           {
    63             $('textarea', box).attr('value', response);
    66             $('textarea', box).val(response);
    64             $(whitey).remove();
    67             $(whitey).remove();
       
    68             
       
    69             $(box).attr('enano:item_id', item_id);
    65           }, 'html');
    70           }, 'html');
    66       })
    71       })
    67     .get(0);
    72     .get(0);
    68   box.parentdiv = parent;
       
    69   box.item_id = parseInt($(parent).attr('id').replace(/^block:/, ''));
       
    70 }
    73 }
    71 
    74 
    72 function sbedit_edit_save(a)
    75 function sbedit_edit_save(a)
    73 {
    76 {
    74   var box = a.parentNode.parentNode;
    77   var box = a.parentNode.parentNode;
    75   var parent = box.parentdiv;
    78   var parent = document.getElementById('block:' + $(box).attr('enano:item_id'));
    76   var whitey = whiteOutElement(box);
    79   var whitey = whiteOutElement(box);
    77   $.post(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id=' + box.item_id), { content: $('textarea', box).attr('value') }, function(response, statustext)
    80   $.post(makeUrlNS('Special', 'EditSidebar', 'noheaders&action=save&id=' + $(box).attr('enano:item_id')), { content: $('textarea', box).attr('value') }, function(response, statustext)
    78     {
    81     {
    79       whiteOutReportSuccess(whitey);
    82       whiteOutReportSuccess(whitey);
    80       setTimeout(function()
    83       setTimeout(function()
    81         {
    84         {
    82           sbedit_close_editor(parent, box);
    85           sbedit_close_editor(parent, box);
    85 }
    88 }
    86 
    89 
    87 function sbedit_edit_cancel(a)
    90 function sbedit_edit_cancel(a)
    88 {
    91 {
    89   var box = a.parentNode.parentNode;
    92   var box = a.parentNode.parentNode;
    90   var parent = box.parentdiv;
    93   var parent = document.getElementById('block:' + $(box).attr('enano:item_id'));
    91   
    94   
    92   sbedit_close_editor(parent, box);
    95   sbedit_close_editor(parent, box);
    93 }
    96 }
    94 
    97 
    95 function sbedit_close_editor(parent, box)
    98 function sbedit_close_editor(parent, box)
    96 {
    99 {
       
   100   if ( !parent )
       
   101   {
       
   102     console.warn('Failed to get DOM object for parent, skipping transition effect');
       
   103   }
       
   104   
       
   105   if ( jQuery.fx.off || !parent )
       
   106   {
       
   107     enlighten(true, 'sbedit-shade');
       
   108     $('body').get(0).removeChild(box);
       
   109     return true;
       
   110   }
       
   111   
    97   var offset = $(parent).offset();
   112   var offset = $(parent).offset();
    98   $(box).empty().animate(
   113   $(box).empty().animate(
    99     {
   114     {
   100       width:  $(parent).width(),
   115       width:  $(parent).width(),
   101       height: $(parent).height(),
   116       height: $(parent).height(),