Changeset 6626
- Timestamp:
- 04/29/07 05:37:07 (1 year ago)
- Files:
-
- spinoffs/prototype/trunk/CHANGELOG (modified) (1 diff)
- spinoffs/prototype/trunk/src/ajax.js (modified) (3 diffs)
- spinoffs/prototype/trunk/src/array.js (modified) (3 diffs)
- spinoffs/prototype/trunk/src/base.js (modified) (1 diff)
- spinoffs/prototype/trunk/src/dom.js (modified) (4 diffs)
- spinoffs/prototype/trunk/test/unit/base.html (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
spinoffs/prototype/trunk/CHANGELOG
r6621 r6626 1 1 *SVN* 2 3 * Add Function#curry, Function#delay, Function#defer, and Function#wrap. Closes #8134. [Andrew Dupont, Tobie Langel, sam] 2 4 3 5 *1.5.1* (it is a mystery) spinoffs/prototype/trunk/src/ajax.js
r6558 r6626 108 108 this.options.asynchronous); 109 109 110 if (this.options.asynchronous) 111 setTimeout(function() { this.respondToReadyState(1) }.bind(this), 10); 110 if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1); 112 111 113 112 this.transport.onreadystatechange = this.onStateChange.bind(this); … … 268 267 269 268 if (this.success()) { 270 if (this.onComplete) 271 setTimeout(this.onComplete.bind(this), 10); 269 if (this.onComplete) this.onComplete.bind(this).defer(); 272 270 } 273 271 } … … 308 306 this.lastText = request.responseText; 309 307 } 310 this.timer = setTimeout(this.onTimerEvent.bind(this), 311 this.decay * this.frequency * 1000); 308 this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency); 312 309 }, 313 310 spinoffs/prototype/trunk/src/array.js
r6555 r6626 1 var $A = Array.from = function(iterable) {1 function $A(iterable) { 2 2 if (!iterable) return []; 3 3 if (iterable.toArray) { … … 12 12 13 13 if (Prototype.Browser.WebKit) { 14 $A = Array.from = function(iterable) {14 function $A(iterable) { 15 15 if (!iterable) return []; 16 16 if (!(typeof iterable == 'function' && iterable == '[object NodeList]') && … … 25 25 } 26 26 } 27 28 Array.from = $A; 27 29 28 30 Object.extend(Array.prototype, Enumerable); spinoffs/prototype/trunk/src/base.js
r6555 r6626 67 67 }); 68 68 69 Function.prototype.bind = function() { 70 var __method = this, args = $A(arguments), object = args.shift(); 71 return function() { 72 return __method.apply(object, args.concat($A(arguments))); 69 Object.extend(Function.prototype, { 70 bind: function() { 71 var __method = this, args = $A(arguments), object = args.shift(); 72 return function() { 73 return __method.apply(object, args.concat($A(arguments))); 74 } 75 }, 76 77 bindAsEventListener: function() { 78 var __method = this, args = $A(arguments), object = args.shift(); 79 return function(event) { 80 return __method.apply(object, [(event || window.event)].concat(args).concat($A(arguments))); 81 } 82 }, 83 84 curry: function() { 85 var __method = this, args = $A(arguments); 86 return function() { 87 return __method.apply(this, args.concat($A(arguments))); 88 } 89 }, 90 91 delay: function() { 92 var __method = this, args = $A(arguments), timeout = args.shift() * 1000; 93 return window.setTimeout(function() { 94 return __method.apply(__method, args); 95 }, timeout); 96 }, 97 98 wrap: function(wrapper) { 99 var __method = this; 100 return function() { 101 return wrapper.apply(this, [__method.bind(this)].concat($A(arguments))); 102 } 73 103 } 74 } 104 }); 75 105 76 Function.prototype.bindAsEventListener = function(object) { 77 var __method = this, args = $A(arguments), object = args.shift(); 78 return function(event) { 79 return __method.apply(object, [( event || window.event)].concat(args).concat($A(arguments))); 80 } 81 } 106 Function.prototype.defer = Function.prototype.delay.curry(0.01); 82 107 83 108 Object.extend(Number.prototype, { spinoffs/prototype/trunk/src/dom.js
r6598 r6626 106 106 html = typeof html == 'undefined' ? '' : html.toString(); 107 107 $(element).innerHTML = html.stripScripts(); 108 setTimeout(function() {html.evalScripts()}, 10);108 html.evalScripts.bind(html).defer(); 109 109 return element; 110 110 }, … … 121 121 range.createContextualFragment(html.stripScripts()), element); 122 122 } 123 setTimeout(function() {html.evalScripts()}, 10);123 html.evalScripts.bind(html).defer(); 124 124 return element; 125 125 }, … … 505 505 element.innerHTML = html.stripScripts(); 506 506 } 507 setTimeout(function() { html.evalScripts() }, 10);507 html.evalScripts.bind(html).defer(); 508 508 return element; 509 509 } … … 699 699 } 700 700 701 setTimeout(function() {content.evalScripts()}, 10);701 content.evalScripts.bind(content).defer(); 702 702 }, 703 703 spinoffs/prototype/trunk/test/unit/base.html
r6555 r6626 86 86 }}, 87 87 88 testFunctionCurry: function() { with(this) { 89 var split = function(delimiter, string) { return string.split(delimiter); }; 90 var splitOnColons = split.curry(":"); 91 assertEnumEqual(split(":", "0:1:2:3:4:5"), splitOnColons("0:1:2:3:4:5")); 92 }}, 93 94 testFunctionDelay: function() { with(this) { 95 window.delayed = undefined; 96 var delayedFunction = function() { window.delayed = true; }; 97 var delayedFunctionWithArgs = function() { window.delayedWithArgs = $A(arguments).join(' '); }; 98 delayedFunction.delay(0.8); 99 delayedFunctionWithArgs.delay(0.8, 'hello', 'world'); 100 assertUndefined(window.delayed); 101 wait(1000, function() { 102 assert(window.delayed); 103 assertEqual('hello world', window.delayedWithArgs); 104 }); 105 }}, 106 107 testFunctionWrap: function() { with(this) { 108 function sayHello(){ 109 return 'hello world'; 110 }; 111 112 assertEqual('HELLO WORLD', sayHello.wrap(function(proceed) { 113 return proceed().toUpperCase(); 114 })()); 115 116 var temp = String.prototype.capitalize; 117 String.prototype.capitalize = String.prototype.capitalize.wrap(function(proceed, eachWord) { 118 if(eachWord && this.include(' ')) return this.split(' ').map(function(str){ 119 return str.capitalize(); 120 }).join(' '); 121 return proceed(); 122 }); 123 assertEqual('Hello world', 'hello world'.capitalize()); 124 assertEqual('Hello World', 'hello world'.capitalize(true)); 125 assertEqual('Hello', 'hello'.capitalize()); 126 String.prototype.capitalize = temp; 127 }}, 128 129 testFunctionDefer: function() { with(this) { 130 window.deferred = undefined; 131 var deferredFunction = function() { window.deferred = true; }; 132 deferredFunction.defer(); 133 assertUndefined(window.deferred); 134 wait(50, function() { 135 assert(window.deferred); 136 }); 137 }}, 138 88 139 testObjectInspect: function() { with(this) { 89 140 assertEqual('undefined', Object.inspect());