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

Changeset 6639

Show
Ignore:
Timestamp:
04/30/07 09:57:28 (2 years ago)
Author:
tobie
Message:

Add Element#wrap which wraps the element inside a new one. ref. #5732.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/branches/dom/CHANGELOG

    r6638 r6639  
    11*SVN* 
     2 
     3* Add Element#wrap which wraps the element inside a new one. Closes #5732. [P. Vande, Tobie Langel] 
    24 
    35* Make Element into a constructor: new Element(tagName, attributes). Add Element#writeAttribute which accepts a hash of attributes or a name/value pair. Closes #7476. [Mislav Marohnić, haraldmartin, Tobie Langel] 
  • spinoffs/prototype/branches/dom/src/dom.js

    r6638 r6639  
    171171    } 
    172172    content.evalScripts.bind(content).defer();    
     173    return element; 
     174  }, 
     175   
     176  wrap: function(element, wrapper) { 
     177    element = $(element); 
     178    wrapper = wrapper || 'div'; 
     179    if(typeof wrapper == 'string') wrapper = new Element(wrapper); 
     180    else Element.extend(wrapper); 
     181    element.parentNode.replaceChild(wrapper, element); 
     182    wrapper.appendChild(element); 
    173183    return element; 
    174184  }, 
  • spinoffs/prototype/branches/dom/test/unit/dom.html

    r6638 r6639  
    403403      assert(getInnerHTML('element-insertions-main').endsWith('some backward-compatibility testing bottom')); 
    404404    }}, 
    405  
     405     
     406    testElementWrap: function() {with(this) { 
     407      var element = $('wrap'), parent = document.createElement('div'); 
     408      element.wrap('div'); 
     409      assert(getInnerHTML('wrap-container').startsWith('<div><p')); 
     410      element.wrap(parent); 
     411      assert(getInnerHTML('wrap-container').startsWith('<div><div><p')); 
     412      assert(typeof parent.setStyle == 'function'); 
     413      element.wrap(); 
     414      assert(getInnerHTML('wrap-container').startsWith('<div><div><div><p')); 
     415    }}, 
     416     
    406417    testElementVisible: function(){with(this) { 
    407418      assertNotEqual('none', $('test-visible').style.display);