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

Changeset 8222

Show
Ignore:
Timestamp:
11/27/07 18:21:50 (1 year ago)
Author:
andrew
Message:

* Re-enable the XPath approach in Selector for Safari 3. Falls back to the non-XPath version when it sees a problematic token. [Andrew Dupont]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • spinoffs/prototype/trunk/CHANGELOG

    r8221 r8222  
     1* Re-enable the XPath approach in Selector for Safari 3. Falls back to the non-XPath version when it sees a problematic token. [Andrew Dupont] 
     2 
    13* Fix a bug in the IE-specific Element#descendantOf logic. [Nicholas, Andrew Dupont] 
    24 
  • spinoffs/prototype/trunk/src/prototype.js

    r7962 r8222  
    3131  Prototype.BrowserFeatures.SpecificElementExtensions = false; 
    3232   
    33 if (Prototype.Browser.WebKit) 
    34   Prototype.BrowserFeatures.XPath = false; 
    3533 
    3634<%= include 'base.js', 'string.js' %> 
  • spinoffs/prototype/trunk/src/selector.js

    r8151 r8222  
    99  }, 
    1010   
     11  shouldUseXPath: function() { 
     12    if (!Prototype.BrowserFeatures.XPath) return false; 
     13     
     14    var e = this.expression; 
     15 
     16    // Safari 3 chokes on :*-of-type and :empty 
     17    if (Prototype.Browser.WebKit &&  
     18     (e.include("-of-type") || e.include(":empty"))) 
     19      return false; 
     20     
     21    // XPath can't do namespaced attributes, nor can it read 
     22    // the "checked" property from DOM nodes 
     23    if ((/(\[[\w-]*?:|:checked)/).test(this.expression)) 
     24      return false; 
     25 
     26    return true; 
     27  }, 
     28   
    1129  compileMatcher: function() { 
    12     // Selectors with namespaced attributes can't use the XPath version 
    13     if (Prototype.BrowserFeatures.XPath && !(/(\[[\w-]*?:|:checked)/).test(this.expression)) 
     30    if (this.shouldUseXPath()) 
    1431      return this.compileXPathMatcher(); 
    1532     
     
    134151    className:    "[contains(concat(' ', @class, ' '), ' #{1} ')]", 
    135152    id:           "[@id='#{1}']", 
    136     attrPresence: "[@#{1}]", 
     153    attrPresence: function(m) { 
     154      m[1] = m[1].toLowerCase(); 
     155      return new Template("[@#{1}]").evaluate(m); 
     156    }, 
    137157    attr: function(m) { 
     158      m[1] = m[1].toLowerCase(); 
    138159      m[3] = m[5] || m[6]; 
    139160      return new Template(Selector.xpath.operators[m[2]]).evaluate(m); 
  • spinoffs/prototype/trunk/test/unit/selector.html

    r8071 r8222  
    159159 
    160160    testSelectorWithTagNameAndAttributeExistence: function() {with(this) { 
    161       assertEnumEqual($$('#fixtures h1'), $$('h1[class]')); 
    162       assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]')); 
    163       assertEnumEqual([$('item_3')], $$('li#item_3[class]')); 
     161      assertEnumEqual($$('#fixtures h1'), $$('h1[class]'), 'h1[class]'); 
     162      assertEnumEqual($$('#fixtures h1'), $$('h1[CLASS]'), 'h1[CLASS]'); 
     163      assertEnumEqual([$('item_3')], $$('li#item_3[class]'), 'li#item_3[class]'); 
    164164    }}, 
    165165