prototype: Update Template, Selector, Ajax.*, and ObjectRange classes to use the new class system.

This commit is contained in:
Sam Stephenson 2007-08-18 23:21:29 +00:00
parent 75b3f3c844
commit 6086db40a7
5 changed files with 43 additions and 56 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Update Template, Selector, Ajax.*, and ObjectRange classes to use the new class system. [Mislav Marohnić]
* Change Abstract.TimedObserver to subclass PeriodicalExecuter and tweak its subclasses to use new inheritance functionality. TimedObserver can now be stopped the same way as PeriodicalExecuter. Closes #8589. [Mislav Marohnić]
* Fix Class.mixin to extend the class's prototype. [Mislav Marohnić]

View File

@ -40,17 +40,12 @@ Ajax.Responders = {
Object.extend(Ajax.Responders, Enumerable);
Ajax.Responders.register({
onCreate: function() {
Ajax.activeRequestCount++;
},
onComplete: function() {
Ajax.activeRequestCount--;
}
onCreate: function() { Ajax.activeRequestCount++ },
onComplete: function() { Ajax.activeRequestCount-- }
});
Ajax.Base = function() { };
Ajax.Base.prototype = {
setOptions: function(options) {
Ajax.Base = Class.create({
initialize: function(options) {
this.options = {
method: 'post',
asynchronous: true,
@ -66,18 +61,14 @@ Ajax.Base.prototype = {
if (Object.isString(this.options.parameters))
this.options.parameters = this.options.parameters.toQueryParams();
}
};
});
Ajax.Request = Class.create();
Ajax.Request.Events =
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
Ajax.Request = Class.create(Ajax.Base, {
_complete: false,
initialize: function(url, options) {
initialize: function($super, url, options) {
$super(options);
this.transport = Ajax.getTransport();
this.setOptions(options);
this.request(url);
},
@ -233,8 +224,10 @@ Ajax.Request.prototype = Object.extend(new Ajax.Base(), {
}
});
Ajax.Response = Class.create();
Ajax.Response.prototype = {
Ajax.Request.Events =
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
Ajax.Response = Class.create({
initialize: function(request){
this.request = request;
var transport = this.transport = request.transport,
@ -301,27 +294,23 @@ Ajax.Response.prototype = {
this.request.dispatchException(e);
}
}
};
});
Ajax.Updater = Class.create();
Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
initialize: function(container, url, options) {
Ajax.Updater = Class.create(Ajax.Request, {
initialize: function($super, container, url, options) {
this.container = {
success: (container.success || container),
failure: (container.failure || (container.success ? null : container))
};
this.transport = Ajax.getTransport();
this.setOptions(options);
var onComplete = this.options.onComplete || Prototype.emptyFunction;
this.options.onComplete = (function(response, param) {
options = options || { };
var onComplete = options.onComplete;
options.onComplete = (function(response, param) {
this.updateContent(response.responseText);
onComplete(response, param);
if (Object.isFunction(onComplete)) onComplete(response, param);
}).bind(this);
this.request(url);
$super(url, options);
},
updateContent: function(responseText) {
@ -347,10 +336,9 @@ Object.extend(Object.extend(Ajax.Updater.prototype, Ajax.Request.prototype), {
}
});
Ajax.PeriodicalUpdater = Class.create();
Ajax.PeriodicalUpdater.prototype = Object.extend(new Ajax.Base(), {
initialize: function(container, url, options) {
this.setOptions(options);
Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
initialize: function($super, container, url, options) {
$super(options);
this.onComplete = this.options.onComplete;
this.frequency = (this.options.frequency || 2);

View File

@ -1,6 +1,4 @@
ObjectRange = Class.create();
Object.extend(ObjectRange.prototype, Enumerable);
Object.extend(ObjectRange.prototype, {
ObjectRange = Class.create({
initialize: function(start, end, exclusive) {
this.start = start;
this.end = end;
@ -13,17 +11,19 @@ Object.extend(ObjectRange.prototype, {
iterator(value);
value = value.succ();
}
},
include: function(value) {
if (value < this.start)
return false;
if (this.exclusive)
return value < this.end;
return value <= this.end;
}
}
});
Object.extend(ObjectRange.prototype, Enumerable);
ObjectRange.prototype.include = function(value) {
if (value < this.start)
return false;
if (this.exclusive)
return value < this.end;
return value <= this.end;
};
var $R = function(start, end, exclusive) {
return new ObjectRange(start, end, exclusive);
};
};

View File

@ -2,9 +2,7 @@
* part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
* license. Please see http://www.yui-ext.com/ for more information. */
var Selector = Class.create();
Selector.prototype = {
var Selector = Class.create({
initialize: function(expression) {
this.expression = expression.strip();
this.compileMatcher();
@ -118,7 +116,7 @@ Selector.prototype = {
inspect: function() {
return "#<Selector:" + this.expression.inspect() + ">";
}
};
});
Object.extend(Selector, {
_cache: { },

View File

@ -230,9 +230,7 @@ Object.extend(String.prototype.escapeHTML, {
with (String.prototype.escapeHTML) div.appendChild(text);
var Template = Class.create();
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
Template.prototype = {
var Template = Class.create({
initialize: function(template, pattern) {
this.template = template.toString();
this.pattern = pattern || Template.Pattern;
@ -263,4 +261,5 @@ Template.prototype = {
return before + String.interpret(ctx);
}.bind(this));
}
};
});
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;