Dotclear


Ignore:
Timestamp:
10/06/13 00:26:27 (12 years ago)
Author:
Lepeltier kévin <kevin@…>
Branch:
widgets
Message:

widgets : fléche pour réordonner sans drag&drop

File:
1 edited

Legend:

Unmodified
Added
Removed
  • plugins/widgets/widgets.js

    r2400 r2401  
    1717     order = title.find('input[name*=order]'); 
    1818     link = $('<a href="#" alt="expand" class="aexpand"/>').append(title.text()); 
    19      rem = title.find('input[name*=_rem]'); 
     19     tools = title.find('.toolsWidget'); 
    2020     br = title.find('br'); 
    21      title.empty().append(order).append(link).append(rem).append(br); 
     21     title.empty().append(order).append(link).append(tools).append(br); 
    2222      
    2323     var img = document.createElement('img'); 
     
    5252}; 
    5353 
    54 $(function() {  
     54function reorder(ul) { 
     55     // réordonne 
     56     if( ul.attr('id') ) { 
     57          $list = ul.find('li').not('.empty-widgets'); 
     58          $list.each(function(i) { 
     59               $this = $(this); 
     60                
     61               // trouve la zone de réception 
     62               var name = ul.attr('id').split('dnd').join(''); 
     63                
     64               // modifie le name en conséquence 
     65               $this.find('*[name^=w]').each(function(){ 
     66                    tab = $(this).attr('name').split(']['); 
     67                    tab[0] = "w["+name; 
     68                    tab[1] = i; 
     69                    $(this).attr('name', tab.join('][')); 
     70               }); 
     71                
     72               // ainsi que le champ d'ordre sans js (au cas ou) 
     73               $this.find('input[title=ordre]').val(i); 
     74                
     75               // active ou désactive les fléches 
     76               if( i == 0 ) { 
     77                    $this.find('input.upWidget').prop('disabled', true); 
     78                    $this.find('input.upWidget').prop('src', 'images/disabled_up.png' ); 
     79               } else { 
     80                    $this.find('input.upWidget').removeAttr('disabled'); 
     81                    $this.find('input.upWidget').prop('src', 'images/up.png' ); 
     82               } 
     83               if( i == $list.length-1 ) { 
     84                    $this.find('input.downWidget').prop('disabled', true); 
     85                    $this.find('input.downWidget').prop('src', 'images/disabled_down.png' ); 
     86               } else { 
     87                    $this.find('input.downWidget').removeAttr('disabled'); 
     88                    $this.find('input.downWidget').prop('src', 'images/down.png' ); 
     89               } 
     90                
     91          }); 
     92     } 
     93} 
     94 
     95$(function() { 
    5596     // reset 
    5697     $('input[name="wreset"]').click(function() { 
     
    65106      
    66107     // remove 
    67      $('input[name*=rem]').change(function () { 
    68          if ($(this).attr("checked")) { 
    69              $(this).parents('li').remove(); 
    70          } 
     108     $('input[name*=rem]').click(function (e) { 
     109          e.preventDefault(); 
     110          $(this).parents('li').remove(); 
    71111     }); 
    72112      
     113     // move 
     114     $('input[name*=down]').click(function (e) { 
     115          e.preventDefault(); 
     116          $this = $(this); 
     117          $li = $this.parents('li'); 
     118          $li.next().after($li); 
     119          reorder($this.parents('ul.connected')); 
     120     }); 
     121     $('input[name*=up]').click(function (e) { 
     122          e.preventDefault(); 
     123          $this = $(this); 
     124          $li = $this.parents('li'); 
     125          $li.prev().before($li); 
     126          reorder($this.parents('ul.connected')); 
     127     }); 
    73128}); 
Note: See TracChangeset for help on using the changeset viewer.

Sites map