[ Index ]
 

Code source de WordPress 2.1.2

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

title

Body

[fermer]

/wp-includes/js/ -> list-manipulation-js.php (source)

   1  <?php @require_once('../../wp-config.php'); cache_javascript_headers(); ?>
   2  addLoadEvent(function(){theList=new listMan();});
   3  function deleteSomething(what,id,message,obj){if(!obj)obj=theList;if(!message)message="<?php printf(js_escape(__('Are you sure you want to delete this %s?')),"'+what+'"); ?>";if(confirm(message))return obj.ajaxDelete(what,id);else return false;}
   4  function dimSomething(what,id,dimClass,obj){if(!obj)obj=theList;return obj.ajaxDimmer(what,id,dimClass);}
   5  
   6  var listMan = Class.create();
   7  Object.extend(listMan.prototype, {
   8      ajaxRespEl: 'ajax-response',
   9      ajaxHandler: false,
  10      inputData: '',
  11      clearInputs: [],
  12      showLink: true,
  13      topAdder: false,
  14      alt: 'alternate',
  15      altOffset: 0,
  16      addComplete: null,
  17      delComplete: null,
  18      dimComplete: null,
  19      dataStore: null,
  20      formStore: null,
  21  
  22      initialize: function(theListId) {
  23          this.theList = $(theListId ? theListId : 'the-list');
  24          if ( !this.theList )
  25              return false;
  26          Element.cleanWhitespace(this.theList);
  27      },
  28  
  29      // sends add-what and fields contained in where
  30      // recieves html with top element having an id like what-#
  31      ajaxAdder: function( what, where, update ) { // Do NOT wrap TR in TABLE TBODY
  32          var ajaxAdd = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
  33          if ( ajaxAdd.notInitialized() )
  34              return true;
  35          ajaxAdd.options.parameters += '&action=' + ( update ? 'update-' : 'add-' ) + what + '&' + this.grabInputs( where, ajaxAdd ) + this.inputData;
  36          var tempObj=this;
  37          ajaxAdd.addOnComplete( function(transport) {
  38              var newItems = $A(transport.responseXML.getElementsByTagName(what));
  39              if ( newItems ) {
  40                  var showLinkMessage = '';
  41                  var m = '';
  42                  newItems.each( function(i) {
  43                      var id = i.getAttribute('id');
  44                      var exists = $(what+'-'+id);
  45                      if ( exists )
  46                          tempObj.replaceListItem( exists, getNodeValue(i,'response_data'), update );
  47                      else
  48                          tempObj.addListItem( getNodeValue(i, 'response_data') );
  49                      m = getNodeValue(i, 'show-link');
  50                      showLinkMessage += showLinkMessage ? "<br />\n" : '';
  51                      if ( m )
  52                          showLinkMessage += m;
  53                      else
  54                          showLinkMessage += "<a href='#" + what + '-' + id + "'><?php echo js_escape(__('Jump to new item')); ?>";
  55                  });
  56                  if ( tempObj.showLink && showLinkMessage )
  57                      Element.update(ajaxAdd.myResponseElement,"<div id='jumplink' class='updated fade'><p>" + showLinkMessage + "</p></div>");
  58              }
  59              if ( tempObj.addComplete && typeof tempObj.addComplete == 'function' )
  60                  tempObj.addComplete( what, where, update, transport );
  61              tempObj.recolorList();
  62              ajaxAdd.restoreInputs = null;
  63          });
  64          if ( !update )
  65              ajaxAdd.addOnWPError( function(transport) { tempObj.restoreForm(ajaxAdd.restoreInputs); });
  66          ajaxAdd.request(ajaxAdd.url);
  67          if ( !update )
  68              this.clear();
  69          return false;
  70      },
  71  
  72      // sends update-what and fields contained in where
  73      // recieves html with top element having an id like what-#
  74      ajaxUpdater: function( what, where ) { return this.ajaxAdder( what, where, true ); },
  75  
  76      // sends delete-what and id#
  77      ajaxDelete: function( what, id ) {
  78          var ajaxDel = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
  79          if( ajaxDel.notInitialized() )
  80              return true;
  81          var tempObj = this;
  82          var action = 'delete-' + what + '&id=' + id;
  83          var idName = what.replace('-as-spam','') + '-' + id;
  84          ajaxDel.addOnComplete( function(transport) {
  85              Element.update(ajaxDel.myResponseElement,'');
  86              tempObj.destore(action);
  87              if( tempObj.delComplete && typeof tempObj.delComplete == 'function' )
  88                  tempObj.delComplete( what, id, transport );
  89          });
  90          ajaxDel.addOnWPError( function(transport) { tempObj.restore(action, true); });
  91          ajaxDel.options.parameters += '&action=' + action + this.inputData;
  92          ajaxDel.request(ajaxDel.url);
  93          this.store(action, idName);
  94          tempObj.removeListItem( idName );
  95          return false;
  96      },
  97  
  98      // Toggles class nomes
  99      // sends dim-what and id#
 100      ajaxDimmer: function( what, id, dimClass ) {
 101          ajaxDim = new WPAjax( this.ajaxHandler, this.ajaxRespEl );
 102          if ( ajaxDim.notInitialized() )
 103              return true;
 104          var tempObj = this;
 105          var action = 'dim-' + what + '&id=' + id;
 106          var idName = what + '-' + id;
 107          ajaxDim.addOnComplete( function(transport) {
 108              Element.update(ajaxDim.myResponseElement,'');
 109              tempObj.destore(action);
 110              if ( tempObj.dimComplete && typeof tempObj.dimComplete == 'function' )
 111                  tempObj.dimComplete( what, id, dimClass, transport );
 112          });
 113          ajaxDim.addOnWPError( function(transport) { tempObj.restore(action, true); });
 114          ajaxDim.options.parameters += '&action=' + action + this.inputData;
 115          ajaxDim.request(ajaxDim.url);
 116          this.store(action, idName);
 117          this.dimItem( idName, dimClass );
 118          return false;
 119      },
 120  
 121      addListItem: function( h ) {
 122          new Insertion[this.topAdder ? 'Top' : 'Bottom'](this.theList,h);
 123          Element.cleanWhitespace(this.theList);
 124          var id = this.topAdder ? this.theList.firstChild.id : this.theList.lastChild.id;
 125          if ( this.alt )
 126              if ( this.theList.childNodes.length % 2 )
 127                  Element.addClassName($(id),this.alt);
 128          Fat.fade_element(id);
 129      },
 130  
 131      // only hides the element sa it can be put back again if necessary
 132      removeListItem: function( id, noFade ) {
 133          id = $(id);
 134          if ( !noFade ) {
 135              Fat.fade_element(id.id,null,700,'#FF3333');
 136              var tempObj = this;
 137              var func = function() { id.hide(); tempObj.recolorList(); }
 138              setTimeout(func, 705);
 139          } else {
 140              id.hide();
 141              this.recolorList();
 142          }
 143      },
 144  
 145      replaceListItem: function( id, h, update ) {
 146          id = $(id);
 147          if ( !update ) {
 148              Element.remove(id);
 149              this.addListItem( h );
 150              return;
 151          }
 152          id.replace(h);
 153          Fat.fade_element(id.id);
 154      },
 155  
 156      // toggles class
 157      dimItem: function( id, dimClass, noFade ) {
 158          id = $(id);
 159          if ( Element.hasClassName(id,dimClass) ) {
 160              if ( !noFade )
 161                  Fat.fade_element(id.id,null,700,null);
 162              Element.removeClassName(id,dimClass);
 163          } else {
 164              if ( !noFade )
 165                  Fat.fade_element(id.id,null,700,'#FF3333');
 166              Element.addClassName(id,dimClass);
 167          }
 168      },
 169  
 170      // store an element in case we need it later
 171      store: function(action, id) {
 172          if ( !this.dataStore )
 173              this.dataStore = $H();
 174          this.dataStore[action] = $(id).cloneNode(true);
 175      },
 176  
 177      // delete from store
 178      destore: function(action) { delete(this.dataStore[action]); },
 179  
 180      // restore element from store into existing (possibly hidden) element of same id
 181      restore: function(action, error) {
 182          var id = this.dataStore[action].id;
 183          this.theList.replaceChild(this.dataStore[action], $(id));
 184          delete(this.dataStore[action]);
 185          if ( error ) {
 186              func = function() { Element.setStyle($(id),{backgroundColor:'#FF3333'}); }
 187              func(); setTimeout(func, 705); // Hit it twice in case it's still fading.
 188          }
 189      },
 190  
 191      // Like Form.serialize, but excludes action and sets up clearInputs
 192      grabInputs: function( where, ajaxObj ) {
 193          if ( ajaxObj )
 194              ajaxObj.restoreInputs = [];
 195          var elements = Form.getElements($(where));
 196          var queryComponents = new Array();
 197          for (var i = 0; i < elements.length; i++) {
 198              if ( 'action' == elements[i].name )
 199                  continue;
 200              if ( 'hidden' != elements[i].type && 'submit' != elements[i].type && 'button' != elements[i].type ) {
 201                  this.clearInputs.push(elements[i]);
 202                  if ( ajaxObj )
 203                      ajaxObj.restoreInputs.push([elements[i], elements[i].value]);
 204              }
 205              var queryComponent = Form.Element.serialize(elements[i]);
 206              if (queryComponent) {
 207                  queryComponents.push(queryComponent);
 208              }
 209          }
 210          return queryComponents.join('&');
 211      },
 212  
 213      // form.reset() can only do whole forms.  This can do subsections.
 214      clear: function() {
 215          this.clearInputs.each( function(i) {
 216              i = $(i);
 217              if ( 'textarea' == i.tagName.toLowerCase() )
 218                  i.value = '';
 219              else
 220                  switch ( i.type.toLowerCase() ) {
 221                      case 'password': case 'text':
 222                          i.value = '';
 223                          break;
 224                      case 'checkbox': case 'radio':
 225                          i.checked = false;
 226                          break;
 227                      case 'select': case 'select-one':
 228                          i.selectedIndex = null;
 229                          break;
 230                      case 'select-multiple':
 231                          for (var o = 0; o < i.length; o++) i.options[o].selected = false;
 232                          break;
 233                  }
 234          });
 235          this.clearInputs = [];
 236      },
 237  
 238      restoreForm: function(elements) {
 239          elements.each( function(i) {
 240              i[0].value = i[1];
 241          });
 242      },
 243  
 244      recolorList: function() {
 245          if ( !this.alt )
 246              return;
 247          var alt = this.alt;
 248          var offset = this.altOffset;
 249          var listItems = $A(this.theList.childNodes).findAll( function(i) { return Element.visible(i) } );
 250          listItems.each( function(i,n) {
 251              if ( ( n + offset ) % 2 )
 252                  Element.removeClassName(i,alt);
 253              else
 254                  Element.addClassName(i,alt);
 255          });
 256      }
 257  });
 258  
 259  //No submit unless code returns true.
 260  function killSubmit ( code, e ) {
 261      e = e ? e : window.event;
 262      if ( !e ) return;
 263      var t = e.target ? e.target : e.srcElement;
 264      if ( ( 'text' == t.type && e.keyCode == 13 ) || ( 'submit' == t.type && 'click' == e.type ) ) {
 265          if ( ( 'string' == typeof code && !eval(code) ) || ( 'function' == typeof code && !code() ) ) {
 266              e.returnValue = false; e.cancelBubble = true; return false;
 267          }
 268      }
 269  }
 270  //Generic but lame JS closure
 271  function encloseFunc(f){var a=arguments[1];return function(){return f(a);}}


Généré le : Fri Mar 30 19:41:27 2007 par Balluche grâce à PHPXref 0.7