Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4921

Show
Ignore:
Timestamp:
09/03/06 18:52:33 (2 years ago)
Author:
madrobby
Message:

script.aculo.us: Make Sortable.serialize handle DOM IDs like "some_element_1" correctly, fixes #5324

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/scriptaculous/CHANGELOG

    r4889 r4921  
    11*SVN* 
     2 
     3* Make Sortable.serialize handle DOM IDs like "some_element_1" correctly, fixes #5324 
    24 
    35* Add assertRespondsTo and shouldRespondTo assertions 
  • spinoffs/scriptaculous/src/dragdrop.js

    r4855 r4921  
    575575 
    576576var Sortable = { 
     577  SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/, 
     578   
    577579  sortables: {}, 
    578580   
     
    621623      scrollSensitivity: 20, 
    622624      scrollSpeed: 15, 
    623       format:      /^[^_]*_(.*)$/
     625      format:      this.SERIALIZE_RULE
    624626      onChange:    Prototype.emptyFunction, 
    625627      onUpdate:    Prototype.emptyFunction 
  • spinoffs/scriptaculous/test/unit/sortable_test.html

    r4101 r4921  
    3838</div> 
    3939 
     40<!--  
     41  By default, _ is the only valid seperator 
     42  for the DOM ids. Complex element ids as in 
     43  the form of "some_element_id_1" should also 
     44  be parsed correctly (only the last part should 
     45  be serialized) 
     46--> 
     47<ul id="sortable_complex"> 
     48  <li id="a_b_item_1" class="a">item 1</li> 
     49  <li id="ab_item_2" class="c b">item 1 
     50    <ul> 
     51      <li id="item_99">!!!</li> 
     52    </ul> 
     53  </li> 
     54  <li id="a-b-item_3z_33" class="b">item 1</li> 
     55  <li id="a-item-xy" class="x y">item 1</li> 
     56  <!-- a comment --> 
     57</ul> 
     58 
     59 
    4060<ul id="sortable_specialcreate"> 
    4161  <li id="y1item">item 1</li> 
     
    6080      Sortable.create('sortable_specialcreate',{ format:/(\d+)/ }); 
    6181      Sortable.create('sortable_specialformat'); 
     82      Sortable.create('sortable_complex'); 
    6283    }}, 
    6384     
     
    6889      Sortable.destroy('sortable_specialformat'); 
    6990      Sortable.destroy('sortable_specialcreate'); 
     91      Sortable.destroy('sortable_complex'); 
    7092    }}, 
    7193     
    7294    testSortableSerializeSequenceBasics: function() { with(this) { 
    7395      assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3', Sortable.serialize('sortable1'));       
     96       
    7497      // test empty sortable 
    7598      assertEqual('', Sortable.serialize('sortable3')); 
     
    82105     
    83106    testSortableSerializeFormat: function() { with(this) { 
    84       // shauld correctly serialize from option given to Sortable.create() 
     107      // should correctly serialize from option given to Sortable.create() 
    85108      assertEqual('sortable_specialcreate[]=1&sortable_specialcreate[]=2',  
    86109        Sortable.serialize('sortable_specialcreate')); 
     
    101124      assertEqual('sortable1[]=1&sortable1[]=2&sortable1[]=3',  
    102125        Sortable.serialize('sortable1',{format:/^[^_]*_(.*)$/})); 
     126         
     127      // Ensure default options.format handles longer, more complex list 
     128      // item IDs 
     129      assertEqual('sortable_complex[]=1&sortable_complex[]=2&sortable_complex[]=33&sortable_complex[]=', 
     130        Sortable.serialize('sortable_complex')); 
     131    }}, 
     132     
     133    testSortableSerializeRule: function() { with(this) { 
     134      var ids = ['x','x-y','test_test','x_y_z','x_y-x_z']; 
     135      ids.each(function(id){ 
     136        assertEqual('1', 
     137          (id+'_1').match(Sortable.SERIALIZE_RULE)[1]); 
     138      }); 
     139       
     140      assertNull('x'.match(Sortable.SERIALIZE_RULE)); 
    103141    }}, 
    104142