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

Changeset 3085

Show
Ignore:
Timestamp:
11/18/05 17:27:26 (4 years ago)
Author:
madrobby
Message:

script.aculo.us: Update lib/prototype.js to Prototype 1.4.0_rc3

Files:

Legend:

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

    r3072 r3085  
    11*SVN* 
     2 
     3* Update lib/prototype.js to Prototype 1.4.0_rc3 
    24 
    35* Make 'contents' a synonym for 'content' on Effect.Scale scaleMode option 
  • spinoffs/scriptaculous/lib/prototype.js

    r2757 r3085  
    1 /*  Prototype JavaScript framework, version 1.4.0_rc2 
     1/*  Prototype JavaScript framework, version 1.4.0_rc3 
    22 *  (c) 2005 Sam Stephenson <sam@conio.net> 
    33 * 
     
    1212 
    1313var Prototype = { 
    14   Version: '1.4.0_rc2', 
     14  Version: '1.4.0_rc3', 
     15  ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 
    1516 
    1617  emptyFunction: function() {}, 
     
    142143  stripTags: function() { 
    143144    return this.replace(/<\/?[^>]+>/gi, ''); 
     145  }, 
     146 
     147  stripScripts: function() { 
     148    return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), ''); 
     149  }, 
     150 
     151  extractScripts: function() { 
     152    var matchAll = new RegExp(Prototype.ScriptFragment, 'img'); 
     153    var matchOne = new RegExp(Prototype.ScriptFragment, 'im'); 
     154    return (this.match(matchAll) || []).map(function(scriptTag) { 
     155      return (scriptTag.match(matchOne) || ['', ''])[1]; 
     156    }); 
     157  }, 
     158 
     159  evalScripts: function() { 
     160    return this.extractScripts().map(eval); 
    144161  }, 
    145162 
     
    215232    var result = true; 
    216233    this.each(function(value, index) { 
    217       if (!(result &= (iterator || Prototype.K)(value, index))) 
    218       throw $break; 
     234      result = result && !!(iterator || Prototype.K)(value, index); 
     235      if (!result) throw $break; 
    219236    }); 
    220237    return result; 
     
    224241    var result = true; 
    225242    this.each(function(value, index) { 
    226       if (result &= (iterator || Prototype.K)(value, index)) 
     243      if (result = !!(iterator || Prototype.K)(value, index)) 
    227244        throw $break; 
    228245    }); 
     
    426443    for (var i = 0; i < this.length; i++) 
    427444      if (this[i] == object) return i; 
    428     return false
     445    return -1
    429446  }, 
    430447 
     
    487504  return hash; 
    488505} 
    489 var Range = Class.create(); 
    490 Object.extend(Range.prototype, Enumerable); 
    491 Object.extend(Range.prototype, { 
     506ObjectRange = Class.create(); 
     507Object.extend(ObjectRange.prototype, Enumerable); 
     508Object.extend(ObjectRange.prototype, { 
    492509  initialize: function(start, end, exclusive) { 
    493510    this.start = start; 
     
    514531 
    515532var $R = function(start, end, exclusive) { 
    516   return new Range(start, end, exclusive); 
     533  return new ObjectRange(start, end, exclusive); 
    517534} 
    518535 
     
    550567        try { 
    551568          responder[callback].apply(responder, [request, transport, json]); 
    552         } catch (e) { 
    553         } 
     569        } catch (e) {} 
    554570      } 
    555571    }); 
     
    627643 
    628644    } catch (e) { 
    629       (this.options.onException || Prototype.emptyFunction)(this, e); 
    630       Ajax.Responders.dispatch('onException', this, e); 
     645      this.dispatchException(e); 
    631646    } 
    632647  }, 
     
    662677  }, 
    663678 
     679  header: function(name) { 
     680    try { 
     681      return this.transport.getResponseHeader(name); 
     682    } catch (e) {} 
     683  }, 
     684 
    664685  evalJSON: function() { 
    665686    try { 
    666       var json = this.transport.getResponseHeader('X-JSON'), object; 
    667       object = eval(json); 
    668       return object; 
     687      return eval(this.header('X-JSON')); 
     688    } catch (e) {} 
     689  }, 
     690 
     691  evalResponse: function() { 
     692    try { 
     693      return eval(this.transport.responseText); 
    669694    } catch (e) { 
     695      this.dispatchException(e); 
    670696    } 
    671697  }, 
     
    675701    var transport = this.transport, json = this.evalJSON(); 
    676702 
    677     if (event == 'Complete') 
    678       (this.options['on' + this.transport.status] 
    679        || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] 
    680        || Prototype.emptyFunction)(transport, json); 
    681  
    682     (this.options['on' + event] || Prototype.emptyFunction)(transport, json); 
    683     Ajax.Responders.dispatch('on' + event, this, transport, json); 
     703    if (event == 'Complete') { 
     704      try { 
     705        (this.options['on' + this.transport.status] 
     706         || this.options['on' + (this.responseIsSuccess() ? 'Success' : 'Failure')] 
     707         || Prototype.emptyFunction)(transport, json); 
     708      } catch (e) { 
     709        this.dispatchException(e); 
     710      } 
     711 
     712      if (this.header('Content-type') == 'text/javascript') 
     713        this.evalResponse(); 
     714    } 
     715 
     716    try { 
     717      (this.options['on' + event] || Prototype.emptyFunction)(transport, json); 
     718      Ajax.Responders.dispatch('on' + event, this, transport, json); 
     719    } catch (e) { 
     720      this.dispatchException(e); 
     721    } 
    684722 
    685723    /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ 
    686724    if (event == 'Complete') 
    687725      this.transport.onreadystatechange = Prototype.emptyFunction; 
     726  }, 
     727 
     728  dispatchException: function(exception) { 
     729    (this.options.onException || Prototype.emptyFunction)(this, exception); 
     730    Ajax.Responders.dispatch('onException', this, exception); 
    688731  } 
    689732}); 
    690733 
    691734Ajax.Updater = Class.create(); 
    692 Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)'; 
    693735 
    694736Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { 
     
    715757    var receiver = this.responseIsSuccess() ? 
    716758      this.containers.success : this.containers.failure; 
    717  
    718     var match    = new RegExp(Ajax.Updater.ScriptFragment, 'img'); 
    719     var response = this.transport.responseText.replace(match, ''); 
    720     var scripts  = this.transport.responseText.match(match); 
     759    var response = this.transport.responseText; 
     760 
     761    if (!this.options.evalScripts) 
     762      response = response.stripScripts(); 
    721763 
    722764    if (receiver) { 
     
    724766        new this.options.insertion(receiver, response); 
    725767      } else { 
    726         receiver.innerHTML = response
     768        Element.update(receiver, response)
    727769      } 
    728770    } 
     
    731773      if (this.onComplete) 
    732774        setTimeout(this.onComplete.bind(this), 10); 
    733     } 
    734  
    735     if (this.options.evalScripts && scripts) { 
    736       match = new RegExp(Ajax.Updater.ScriptFragment, 'im'); 
    737       setTimeout((function() { 
    738         for (var i = 0; i < scripts.length; i++) 
    739           eval(scripts[i].match(match)[1]); 
    740       }).bind(this), 10); 
    741775    } 
    742776  } 
     
    829863    element = $(element); 
    830864    element.parentNode.removeChild(element); 
     865  }, 
     866 
     867  update: function(element, html) { 
     868    $(element).innerHTML = html.stripScripts(); 
     869    setTimeout(function() {html.evalScripts()}, 10); 
    831870  }, 
    832871 
     
    9701009  initialize: function(element, content) { 
    9711010    this.element = $(element); 
    972     this.content = content
     1011    this.content = content.stripScripts()
    9731012 
    9741013    if (this.adjacency && this.element.insertAdjacentHTML) { 
     
    9871026      this.insertContent([this.range.createContextualFragment(this.content)]); 
    9881027    } 
     1028 
     1029    setTimeout(function() {content.evalScripts()}, 10); 
    9891030  }, 
    9901031 
     
    10801121    this.set(this.select(function(className) { 
    10811122      return className != classNameToRemove; 
    1082     })); 
     1123    }).join(' ')); 
    10831124  }, 
    10841125 
     
    11101151 
    11111152  activate: function(element) { 
    1112     $(element).focus(); 
    1113     $(element).select(); 
     1153    element = $(element); 
     1154    element.focus(); 
     1155    if (element.select) 
     1156      element.select(); 
    11141157  } 
    11151158} 
     
    11791222  }, 
    11801223 
     1224  findFirstElement: function(form) { 
     1225    return Form.getElements(form).find(function(element) { 
     1226      return element.type != 'hidden' && !element.disabled && 
     1227        ['input', 'select', 'textarea'].include(element.tagName.toLowerCase()); 
     1228    }); 
     1229  }, 
     1230 
    11811231  focusFirstElement: function(form) { 
    1182     form = $(form); 
    1183     var elements = Form.getElements(form); 
    1184     for (var i = 0; i < elements.length; i++) { 
    1185       var element = elements[i]; 
    1186       if (element.type != 'hidden' && !element.disabled) { 
    1187         Field.activate(element); 
    1188         break; 
    1189       } 
    1190     } 
     1232    Field.activate(Form.findFirstElement(form)); 
    11911233  }, 
    11921234 
     
    13501392        case 'checkbox': 
    13511393        case 'radio': 
    1352           element.target = this; 
    1353           element.prev_onclick = element.onclick || Prototype.emptyFunction; 
    1354           element.onclick = function() { 
    1355             this.prev_onclick(); 
    1356             this.target.onElementEvent(); 
    1357           } 
     1394          Event.observe(element, 'click', this.onElementEvent.bind(this)); 
    13581395          break; 
    13591396        case 'password': 
     
    13621399        case 'select-one': 
    13631400        case 'select-multiple': 
    1364           element.target = this; 
    1365           element.prev_onchange = element.onchange || Prototype.emptyFunction; 
    1366           element.onchange = function() { 
    1367             this.prev_onchange(); 
    1368             this.target.onElementEvent(); 
    1369           } 
     1401          Event.observe(element, 'change', this.onElementEvent.bind(this)); 
    13701402          break; 
    13711403      }