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

Ticket #9032: fix_scriptaculous_loading_rewrite.diff

File fix_scriptaculous_loading_rewrite.diff, 2.8 kB (added by sokrat3s, 1 year ago)
  • spinoffs/scriptaculous/src/scriptaculous.js

    old new  
    2323 
    2424var Scriptaculous = { 
    2525  Version: '1.7.1_beta3', 
     26  REQUIRED_PROTOTYPE: '1.5.2', 
     27   
     28  // Start with the element "el" and recursively descend the DOM  
     29  // looking for the scriptaculous.js script element. 
     30  // 
     31  // This method is used because getElementsByTagName() doesn't 
     32  // work twice in Firefox in the head element during load. 
     33  // So if a a developer tries to clone this script for their own 
     34  // scripts then things will break in the second use of this type 
     35  // of loader. 
     36  // As described in #4335 by petermichaux. 
     37  search: function(el) { 
     38    if (el.src && el.src.match(/scriptaculous\.js(\?.*)?$/)) { 
     39      return el; 
     40    } 
     41 
     42    var kids = el.childNodes, 
     43        s; // holds the scriptaculous script element if found 
     44 
     45    for (var i=0; i<kids.length; i++) { 
     46      if (s = this.search(kids[i])) { // yes just one equals sign 
     47        return s; 
     48      } 
     49    } 
     50  }, 
     51   
    2652  require: function(libraryName) { 
    2753    // inserting via DOM fails in Safari 2.0, so brute force approach 
    2854    document.write('<script type="text/javascript" src="'+libraryName+'"></script>'); 
    2955  }, 
    30   REQUIRED_PROTOTYPE: '1.5.2', 
    31   load: function() { 
     56         
     57       load: function() { 
    3258    function convertVersionString(versionString){ 
    3359      var r = versionString.split('.'); 
    3460      return parseInt(r[0])*100000 + parseInt(r[1])*1000 + parseInt(r[2]); 
     
    4268       throw("script.aculo.us requires the Prototype JavaScript framework >= " + 
    4369        Scriptaculous.REQUIRED_PROTOTYPE); 
    4470     
    45     $A(document.getElementsByTagName("script")).findAll( function(s) { 
    46       return (s.src && s.src.match(/scriptaculous\.js(\?.*)?$/)) 
    47     }).each( function(s) { 
    48       var path = s.src.replace(/scriptaculous\.js(\?.*)?$/,''); 
    49       var includes = s.src.match(/\?.*load=([a-z,]*)/); 
    50       (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider,sound').split(',').each( 
    51        function(include) { Scriptaculous.require(path+include+'.js') }); 
    52     }); 
     71    var s = this.search(document), // holds the scriptaculous script element 
     72        path = s.src.replace(/scriptaculous\.js(\?.*)?$/, ''), 
     73        includes = s.src.match(/\?.*load=([a-z,]*)/);  
     74                 
     75                // include the files specified in the scriptaculous script element src attribute 
     76    // or all the scriptaculous files 
     77    includes = (includes ? includes[1] : 'builder,effects,dragdrop,controls,slider').split(','); 
     78 
     79    for (var i=0; i<includes.length; i++) { 
     80      this.require(path + includes[i] + '.js'); 
     81    } 
    5382  } 
    54 
     83   
     84}; 
    5585 
    5686Scriptaculous.load();