[ Index ]
 

Code source de Plume CMS 1.2.2

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/manager/js/ -> dragsort.js (source)

   1  /* Drag and drop tools by Tim Taylor. Code is under public license.
   2  http://tool-man.org/examples/sorting.html */
   3  
   4  // TODO: refactor away duplicationg in DragSort and DragSortX
   5  var dragSort = {
   6      getSortableItems : function(e) {
   7          var items = e.getElementsByTagName('div');
   8          var res = Array();
   9          for (var i = 0; i < items.length; i++) {
  10              if (items[i].className.match(/(^|\s)sort(\s|$)/)) {
  11                  res.push(items[i]);
  12              }
  13          }
  14          return res;
  15      },
  16      
  17      getOrder : function(e) {
  18          var items = dragSort.getSortableItems(e);
  19          var res = '';
  20          for (var i = 0; i< items.length; i++) {
  21              res += items[i].id+';';
  22          }
  23          
  24          return res.replace(/;$/,'');
  25      },
  26      
  27      makeElementSortable : function(e) {
  28          var items = dragSort.getSortableItems(e);
  29          for (var i = 0; i < items.length; i++) {
  30              dragSort.makeItemSortable(items[i]);
  31          }
  32      },
  33      
  34      prepareItem : function(e) {
  35          for (var i=0; i < e.childNodes.length; i++) {
  36              if (e.childNodes[i].nodeName == 'P' &&
  37              e.childNodes[i].className == 'nojsfield') {
  38                  e.removeChild(e.childNodes[i]);
  39              }
  40          }
  41          e.className += ' sortJS';
  42      },
  43      
  44      makeItemSortable : function(item) {
  45          Drag.makeDraggable(item);
  46          
  47          dragSort.prepareItem(item);
  48          
  49          item.setDragThresholdY(5);
  50          item.style.position = 'relative';
  51          item.onDragStart = dragSort.onDragStart;
  52          item.onDrag = dragSort.onDrag;
  53          item.onDragEnd = dragSort.onDragEnd;
  54      },
  55      
  56      onDragStart : function(nwPosition, sePosition, nwOffset, seOffset) {
  57          var items = dragSort.getSortableItems(this.parentNode);
  58          var minOffset = Coordinates.northwestOffset(items[0], true);
  59          var maxOffset = Coordinates.northwestOffset(items[items.length - 1], true);
  60          this.constrain(minOffset, maxOffset);
  61      },
  62  
  63      onDrag : function(nwPosition, sePosition, nwOffset, seOffset) {
  64          var parent = this.parentNode;
  65  
  66          var item = this;
  67          var next = DragUtils.nextItem(item);
  68          while (next != null && this.offsetTop >= next.offsetTop - 2) {
  69              var item = next;
  70              var next = DragUtils.nextItem(item);
  71          }
  72          if (this != item) {
  73              DragUtils.swap(this, next);
  74              return;
  75          }
  76  
  77          var item = this;
  78          var previous = DragUtils.previousItem(item);
  79          while (previous != null && this.offsetTop <= previous.offsetTop + 2) {
  80              var item = previous;
  81              var previous = DragUtils.previousItem(item);
  82          }
  83          if (this != item) {
  84              DragUtils.swap(this, item);
  85              return;
  86          }
  87      },
  88  
  89      onDragEnd : function(nwPosition, sePosition, nwOffset, seOffset) {
  90          this.style["top"] = "0px";
  91          this.style["left"] = "0px";
  92          
  93          if (dragSort.dest != null) {
  94              dragSort.dest.value = dragSort.getOrder(this.parentNode);
  95          }
  96      }
  97  };
  98  
  99  var DragUtils = {
 100      swap : function(item1, item2) {
 101          var parent = item1.parentNode;
 102          parent.removeChild(item1);
 103          parent.insertBefore(item1, item2);
 104  
 105          item1.style["top"] = "0px";
 106          item1.style["left"] = "0px";
 107      },
 108  
 109      nextItem : function(item) {
 110          var sibling = item.nextSibling;
 111          while (sibling != null) {
 112              if (sibling.nodeName == item.nodeName) return sibling;
 113              sibling = sibling.nextSibling;
 114          }
 115          return null;
 116      },
 117  
 118      previousItem : function(item) {
 119          var sibling = item.previousSibling;
 120          while (sibling != null) {
 121              if (sibling.nodeName == item.nodeName) return sibling;
 122              sibling = sibling.previousSibling;
 123          }
 124          return null;
 125      }
 126  };


Généré le : Mon Nov 26 11:57:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics