[ Index ]
 

Code source de Dotclear 2.0-beta6

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/plugins/widgets/ -> widgets.js (source)

   1  var dragdrop = ToolMan.dragdrop();
   2  $(function() {
   3      $('input[@name="wreset"]').click(function() {
   4          return window.confirm(dotclear.msg.confirm_widgets_reset);
   5      });
   6  });
   7  
   8  $(function() {
   9      var widgets = document.getElementById('widgets');
  10      var w_nav = document.getElementById('dndnav');
  11      var w_ext = document.getElementById('dndextra');
  12      
  13      w_nav.className = 'hideControls';
  14      w_ext.className = 'hideControls';
  15      
  16      removeElements(document.getElementById('listWidgets'),'input');
  17      removeElements(widgets,'p');
  18      removeElements(w_nav,'p');
  19      removeElements(w_ext,'p');
  20      hideElements(w_nav,'input');
  21      hideElements(w_ext,'input');
  22      
  23      configControls(w_nav);
  24      configControls(w_ext);
  25      
  26      dragdrop.makeListContainer(widgets,'div',setHandle);
  27      if (!document.all) { widgets.factory = true; }
  28      dragdrop.makeListContainer(w_nav,'div',setHandle);
  29      w_nav.onDragEnd = navDragEnd;
  30      dragdrop.makeListContainer(w_ext,'div',setHandle);
  31      w_ext.onDragEnd = extraDragEnd;
  32      
  33      // Helper to remove some elements
  34  	function removeElements(p,name) {
  35          name = name || 'div';
  36          $(p).find(name+'.js-remove').each(function() {
  37              this.parentNode.removeChild(this);
  38          });
  39      }
  40      
  41      // Helper to hide elements (but keep them)
  42  	function hideElements(p,name) {
  43          name = name || 'div';
  44          $(p).find(name+'.js-hide').each(function() {
  45              $(this).toggle();
  46          });
  47      }    
  48      
  49  	function removeEmptyMsg(p) {
  50          $(p).find('p.empty-widgets').each(function() {
  51              this.parentNode.removeChild(this);
  52          });
  53      }
  54      
  55      // Events on dragEnd
  56  	function navDragEnd() {
  57          formControls(this.parentNode,'nav');
  58          configControls(this.parentNode);
  59          removeEmptyMsg(this.parentNode);
  60      }
  61  	function extraDragEnd() {
  62          formControls(this.parentNode,'extra');
  63          configControls(this.parentNode);
  64          removeEmptyMsg(this.parentNode);
  65      }
  66      
  67      // dragEnd helper
  68  	function formControls(e,pr) {
  69          var items = new Array();
  70          for (var i=0; i<e.childNodes.length; i++) {
  71              if (e.childNodes[i].nodeType == 1 && e.childNodes[i].nodeName.toLowerCase() == 'div') {
  72                  items.push(e.childNodes[i]);
  73              }
  74          }
  75          
  76          var fields, itype;
  77          var r = new RegExp('^w\[[a-z]+]\[[0-9]+][[](.+?)]$','');
  78          for (i=0; i<items.length; i++) {
  79              // Change field names
  80              fields = getFormControls(items[i]);
  81              var j;
  82              var f;
  83              for (j=0; j<fields.length; j++) {
  84                  if (r.test(fields[j].name)) {
  85                      itype = fields[j].name.replace(r,'$1');
  86                      
  87                      $(fields[j]).attr('name','w['+pr+']['+i+']['+itype+']');
  88                      
  89                      if (itype == 'order') {
  90                          fields[j].value = i;
  91                      }
  92                  }
  93              }
  94          }
  95      }
  96      
  97  	function getFormControls(e) {
  98          var input = e.getElementsByTagName('input');
  99          var textarea = e.getElementsByTagName('textarea');
 100          var select = e.getElementsByTagName('select');
 101          var items = new Array();
 102          var i;
 103          for (i=0; i<input.length; i++) { items.push(input[i]); }
 104          for (i=0; i<select.length; i++) { items.push(select[i]); }
 105          for (i=0; i<textarea.length; i++) { items.push(textarea[i]); }
 106          
 107          return items;
 108      }
 109      
 110  	function configControls(e) {
 111          var items = new Array();
 112          for (var i=0; i<e.childNodes.length; i++) {
 113              if (e.childNodes[i].nodeType == 1 && e.childNodes[i].nodeName.toLowerCase() == 'div') {
 114                  items.push(e.childNodes[i]);
 115              }
 116          }
 117          
 118          var title, img_ctrl, img, space;
 119          for (i in items) {
 120              // Append config control
 121              title = items[i].getElementsByTagName('h4').item(0);
 122              img_ctrl = title.firstChild;
 123              
 124              // There already an image
 125              if (img_ctrl.nodeName.toLowerCase() == 'img') {
 126                  continue;
 127              }
 128              
 129              // Nothing to configure
 130              if (title.nextSibling.childNodes.length == 0) {
 131                  continue;
 132              }
 133              
 134              img = document.createElement('img');
 135              img.src = 'images/plus.png';
 136              img.alt = '[+]';
 137              img.control = title.nextSibling;
 138              img.onclick = function() { widgetConfig.call(this); };
 139              space = document.createTextNode(' ');
 140              title.insertBefore(img,img_ctrl);
 141              title.insertBefore(space,img_ctrl);
 142          }
 143      }
 144      
 145  	function widgetConfig() {
 146          if (this.control.style.display == 'block') {
 147              this.control.style.display = 'none';
 148              this.src = 'images/plus.png';
 149              this.alt = '[+]';
 150          } else {
 151              this.control.style.display = 'block';
 152              this.src = 'images/minus.png';
 153              this.alt = '[-]';
 154          }
 155      }
 156      
 157  	function setHandle(item) {
 158          var handle = item.getElementsByTagName('h4').item(0);
 159          handle.className = 'handler';
 160          item.toolManDragGroup.setHandle(handle);
 161      }
 162  });
 163  
 164  //
 165  // For Safari, we need to make a hard copy of the form and submit copy.
 166  // Yeah, a simple clone of the form is not enough
 167  // I hate this browser!
 168  //
 169  if (document.childNodes && !document.all && !navigator.taintEnabled)
 170  {
 171      $(function() {
 172          $('#sidebarsWidgets').submit(function() {
 173              // Create a new form and copy each element inside
 174              var f = document.createElement('form');
 175              f.action = this.action;
 176              f.method = this.method;
 177              $(f).hide();
 178              var fset = document.createElement('fieldset');
 179              f.appendChild(fset);
 180              
 181              document.body.appendChild(f);
 182              
 183              $(this).find('input').each(function() {
 184                  var i = document.createElement('input');
 185                  i.type = this.type;
 186                  i.name = this.name;
 187                  i.value = this.value;
 188                  if (this.type == 'checkbox') {
 189                      i.checked = this.checked;
 190                  }
 191                  fset.appendChild(i);
 192              });
 193              
 194              $(this).find('textarea').each(function() {
 195                  var i = document.createElement('textarea');
 196                  i.name = this.name;
 197                  i.value = this.value;
 198                  fset.appendChild(i);
 199              });
 200              
 201              $(this).find('select').each(function() {
 202                  var i = document.createElement('input');
 203                  i.name = this.name;
 204                  i.value = this.value;
 205                  fset.appendChild(i);
 206              });
 207              
 208              $(fset).append('<input type="hidden" name="wup" value="1"/>');
 209              f.submit();
 210              
 211              return false;
 212          });
 213      });
 214  }


Généré le : Fri Feb 23 22:16:06 2007 par Balluche grâce à PHPXref 0.7