generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.12.0 vs generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.13.0
- old
+ new
@@ -1,9 +1,9 @@
/**
* Jelly. a sweet unobtrusive javascript framework for Rails
*
- * version 0.12.0
+ * version 0.13.0
*
* Copyright (c) 2009 Pivotal Labs
* Licensed under the MIT license.
*
* * Date: 2009-07-20 9:50:50 (Mon, 20 Jul 2009)
@@ -30,42 +30,50 @@
return destination;
};
extend(Jelly, {
init:function () {
this.observers = [];
+ this.run = this.Observers.run;
this.attach = this.Observers.attach;
this.notifyObservers = this.Observers.notify;
this.Pages.init();
},
Observers:{
- attach:function () {
+ run:function () {
if (this === Jelly) {
- return Jelly.Observers.attach.apply(this.observers, arguments);
+ return Jelly.Observers.run.apply(this.observers, arguments);
}
- var self = Jelly.Observers;
- for (var i = 0; i < arguments.length; i++) {
- var definitionOrComponent = arguments[i];
- if (definitionOrComponent.component) {
- self.attachFromDefinition.call(
- this,
- self.evaluateComponent(definitionOrComponent.component),
- definitionOrComponent.arguments
- );
- } else if (Object.prototype.toString.call(definitionOrComponent) === "[object Array]") {
- self.attachFromDefinition.call(
- this,
- self.evaluateComponent(definitionOrComponent[0]),
- definitionOrComponent.slice(1)
- );
- } else {
- self.pushIfObserver.call(this, Jelly.Observers.evaluateComponent(definitionOrComponent));
+ for (var i=0, len=arguments.length; i < len; i++) {
+ var op = arguments[i];
+ switch (op[0]) {
+ case ("attach"):
+ Jelly.Observers.runAttachOp.call(this, op);
+ break;
+ case ("notify"):
+ Jelly.Observers.runNotifyOp.call(this, op);
+ break;
}
+
}
},
- attachFromDefinition:function (component, args) {
+ runAttachOp:function (op) {
+ if (op[0] !== "attach") {
+ throw "op " + JSON.stringify(op) + " is not an attach op"
+ }
+ var args = [op[1]];
+ args.concat.apply(args, op.slice(2));
+ Jelly.Observers.attach.apply(this, args);
+ },
+
+ attach:function () {
+ if (this === Jelly) {
+ return Jelly.Observers.attach.apply(this.observers, arguments);
+ }
+ var component = Jelly.Observers.evaluateComponent(arguments[0]);
+ var args = Array.prototype.slice.call(arguments, 1);
if (component.init) {
var initReturnValue = component.init.apply(component, args);
if (initReturnValue === false || initReturnValue === null) {
} else {
Jelly.Observers.pushIfObserver.call(this, initReturnValue || component);
@@ -83,53 +91,41 @@
if (observer) {
this.push(observer);
}
},
- notify:function (instructions) {
+ runNotifyOp:function(op) {
+ if (op[0] !== "notify") {
+ throw "op " + JSON.stringify(op) + " is not a notify op"
+ }
+ var args = [op[1]];
+ args.push.apply(args, op.slice(2));
+ Jelly.Observers.notify.apply(this, args);
+ },
+
+ notify:function () {
if (this === Jelly) {
return Jelly.Observers.notify.apply(this.observers, arguments);
}
- var previousNotifying = Jelly.Observers.notifying;
- Jelly.Observers.notifying = true;
- if (Object.prototype.toString.call(instructions) !== "[object Array]") {
- instructions = [instructions];
- }
- var pristineObservers = this.slice(0);
- var observers;
- for (var i = 0; i < instructions.length; i++) {
- var instruction = instructions[i];
-
- // Deprecate 'on' in favor of making each page action a Component.
- if (instruction.on) {
- observers = [eval(instruction.on)];
- } else {
- observers = pristineObservers;
- }
-
- if (instruction.method) {
- for (var j = 0; j < observers.length; j++) {
- var observer = observers[j];
- Jelly.Observers.notifyObserver.call(this, observer, instruction.method, instruction.arguments);
- Jelly.Observers.notifyObserver.call(this, observer, 'on_notify', [instruction]);
- }
- }
-
- if (instruction.attach) {
- Jelly.Observers.attach.apply(this, instruction.attach);
- }
+ var observers = this.slice(0);
+ var message = arguments[0];
+ var args = Array.prototype.slice.call(arguments, 1);
+ var instruction = [message];
+ instruction.push.apply(instruction, args);
+ for (var i = 0, len = observers.length; i < len; i++) {
+ var observer = observers[i];
+ Jelly.Observers.notifyObserver.call(this, observer, message, args);
+ Jelly.Observers.notifyObserver.call(this, observer, 'on_notify', instruction);
}
-
- Jelly.Observers.notifying = previousNotifying;
},
- notifyObserver:function (observer, method, arguments) {
+ notifyObserver:function (observer, method, args) {
if (observer[method]) {
if (observer.detach && observer.detach()) {
Jelly.Observers.garbageCollectObserver.call(this, observer);
} else {
- observer[method].apply(observer, arguments);
+ observer[method].apply(observer, args);
}
}
},
notifying:false,