Changeset 3085
- Timestamp:
- 11/18/05 17:27:26 (4 years ago)
- Files:
-
- spinoffs/scriptaculous/CHANGELOG (modified) (1 diff)
- spinoffs/scriptaculous/lib/prototype.js (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/scriptaculous/CHANGELOG
r3072 r3085 1 1 *SVN* 2 3 * Update lib/prototype.js to Prototype 1.4.0_rc3 2 4 3 5 * 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_rc 21 /* Prototype JavaScript framework, version 1.4.0_rc3 2 2 * (c) 2005 Sam Stephenson <sam@conio.net> 3 3 * … … 12 12 13 13 var Prototype = { 14 Version: '1.4.0_rc2', 14 Version: '1.4.0_rc3', 15 ScriptFragment: '(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)', 15 16 16 17 emptyFunction: function() {}, … … 142 143 stripTags: function() { 143 144 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); 144 161 }, 145 162 … … 215 232 var result = true; 216 233 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; 219 236 }); 220 237 return result; … … 224 241 var result = true; 225 242 this.each(function(value, index) { 226 if (result &=(iterator || Prototype.K)(value, index))243 if (result = !!(iterator || Prototype.K)(value, index)) 227 244 throw $break; 228 245 }); … … 426 443 for (var i = 0; i < this.length; i++) 427 444 if (this[i] == object) return i; 428 return false;445 return -1; 429 446 }, 430 447 … … 487 504 return hash; 488 505 } 489 varRange = Class.create();490 Object.extend( Range.prototype, Enumerable);491 Object.extend( Range.prototype, {506 ObjectRange = Class.create(); 507 Object.extend(ObjectRange.prototype, Enumerable); 508 Object.extend(ObjectRange.prototype, { 492 509 initialize: function(start, end, exclusive) { 493 510 this.start = start; … … 514 531 515 532 var $R = function(start, end, exclusive) { 516 return new Range(start, end, exclusive);533 return new ObjectRange(start, end, exclusive); 517 534 } 518 535 … … 550 567 try { 551 568 responder[callback].apply(responder, [request, transport, json]); 552 } catch (e) { 553 } 569 } catch (e) {} 554 570 } 555 571 }); … … 627 643 628 644 } catch (e) { 629 (this.options.onException || Prototype.emptyFunction)(this, e); 630 Ajax.Responders.dispatch('onException', this, e); 645 this.dispatchException(e); 631 646 } 632 647 }, … … 662 677 }, 663 678 679 header: function(name) { 680 try { 681 return this.transport.getResponseHeader(name); 682 } catch (e) {} 683 }, 684 664 685 evalJSON: function() { 665 686 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); 669 694 } catch (e) { 695 this.dispatchException(e); 670 696 } 671 697 }, … … 675 701 var transport = this.transport, json = this.evalJSON(); 676 702 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 } 684 722 685 723 /* Avoid memory leak in MSIE: clean up the oncomplete event handler */ 686 724 if (event == 'Complete') 687 725 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); 688 731 } 689 732 }); 690 733 691 734 Ajax.Updater = Class.create(); 692 Ajax.Updater.ScriptFragment = '(?:<script.*?>)((\n|.)*?)(?:<\/script>)';693 735 694 736 Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), { … … 715 757 var receiver = this.responseIsSuccess() ? 716 758 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(); 721 763 722 764 if (receiver) { … … 724 766 new this.options.insertion(receiver, response); 725 767 } else { 726 receiver.innerHTML = response;768 Element.update(receiver, response); 727 769 } 728 770 } … … 731 773 if (this.onComplete) 732 774 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);741 775 } 742 776 } … … 829 863 element = $(element); 830 864 element.parentNode.removeChild(element); 865 }, 866 867 update: function(element, html) { 868 $(element).innerHTML = html.stripScripts(); 869 setTimeout(function() {html.evalScripts()}, 10); 831 870 }, 832 871 … … 970 1009 initialize: function(element, content) { 971 1010 this.element = $(element); 972 this.content = content ;1011 this.content = content.stripScripts(); 973 1012 974 1013 if (this.adjacency && this.element.insertAdjacentHTML) { … … 987 1026 this.insertContent([this.range.createContextualFragment(this.content)]); 988 1027 } 1028 1029 setTimeout(function() {content.evalScripts()}, 10); 989 1030 }, 990 1031 … … 1080 1121 this.set(this.select(function(className) { 1081 1122 return className != classNameToRemove; 1082 }) );1123 }).join(' ')); 1083 1124 }, 1084 1125 … … 1110 1151 1111 1152 activate: function(element) { 1112 $(element).focus(); 1113 $(element).select(); 1153 element = $(element); 1154 element.focus(); 1155 if (element.select) 1156 element.select(); 1114 1157 } 1115 1158 } … … 1179 1222 }, 1180 1223 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 1181 1231 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)); 1191 1233 }, 1192 1234 … … 1350 1392 case 'checkbox': 1351 1393 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)); 1358 1395 break; 1359 1396 case 'password': … … 1362 1399 case 'select-one': 1363 1400 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)); 1370 1402 break; 1371 1403 }