generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.8.13 vs generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.8.14

- old
+ new

@@ -9,162 +9,165 @@ * * * Date: 2009-07-20 9:50:50 (Mon, 20 Jul 2009) * */ -if (!window.Jelly) Jelly = new Object(); -if (!Function.prototype.bind) { - Function.prototype.bind = function(object) { - var self = this; - return function() { - return self.apply(object, arguments); +(function($) { + if (!window.Jelly) window.Jelly = new Object(); + var Jelly = window.Jelly; + if (!Function.prototype.bind) { + Function.prototype.bind = function(object) { + var self = this; + return function() { + return self.apply(object, arguments); + } } } -} -$.extend(Jelly, { - init: function() { - this.observers = []; - this.attach = this.Observers.attach; - this.notifyObservers = this.Observers.notify; - this.Pages.init(); - }, + $.extend(Jelly, { + init: function() { + this.observers = []; + this.attach = this.Observers.attach; + this.notifyObservers = this.Observers.notify; + this.Pages.init(); + }, - Observers: { - attach: function() { - if (this == Jelly) { - return Jelly.Observers.attach.apply(this.observers, arguments); - } - for (var i = 0; i < arguments.length; i++) { - var definitionOrComponent = arguments[i]; - if (definitionOrComponent.component) { - var component = Jelly.Observers.evaluateComponent(definitionOrComponent.component); - if (component.init) { - var initReturnValue = component.init.apply(component, definitionOrComponent.arguments); - if (initReturnValue === false || initReturnValue === null) { + Observers: { + attach: function() { + if (this == Jelly) { + return Jelly.Observers.attach.apply(this.observers, arguments); + } + for (var i = 0; i < arguments.length; i++) { + var definitionOrComponent = arguments[i]; + if (definitionOrComponent.component) { + var component = Jelly.Observers.evaluateComponent(definitionOrComponent.component); + if (component.init) { + var initReturnValue = component.init.apply(component, definitionOrComponent.arguments); + if (initReturnValue === false || initReturnValue === null) { + } else { + Jelly.Observers.pushIfObserver.call(this, initReturnValue || component); + } } else { - Jelly.Observers.pushIfObserver.call(this, initReturnValue || component); + Jelly.Observers.pushIfObserver.call(this, component); } } else { - Jelly.Observers.pushIfObserver.call(this, component); + Jelly.Observers.pushIfObserver.call(this, Jelly.Observers.evaluateComponent(definitionOrComponent)); } - } else { - Jelly.Observers.pushIfObserver.call(this, Jelly.Observers.evaluateComponent(definitionOrComponent)); } - } - }, + }, - evaluateComponent: function(component) { - return eval(component); - }, + evaluateComponent: function(component) { + return eval(component); + }, - pushIfObserver: function(observer) { - if (observer) { - this.push(observer); - } - }, + pushIfObserver: function(observer) { + if (observer) { + this.push(observer); + } + }, - notify: function(instructions) { - if (this == Jelly) { - return Jelly.Observers.notify.apply(this.observers, arguments); - } - var previousNotifying = Jelly.Observers.notifying; - Jelly.Observers.notifying = true; - if (!$.isArray(instructions)) { - instructions = [instructions]; - } + notify: function(instructions) { + if (this == Jelly) { + return Jelly.Observers.notify.apply(this.observers, arguments); + } + var previousNotifying = Jelly.Observers.notifying; + Jelly.Observers.notifying = true; + if (!$.isArray(instructions)) { + instructions = [instructions]; + } - var pristineObservers = this.slice(0); - var observers; - for (var i = 0; i < instructions.length; i++) { - var instruction = instructions[i]; + 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; - } + // 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.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); + } } - if (instruction.attach) { - Jelly.Observers.attach.apply(this, instruction.attach); + Jelly.Observers.notifying = previousNotifying; + }, + + notifyObserver: function(observer, method, arguments) { + if (observer[method]) { + if (observer.detach && observer.detach()) { + Jelly.Observers.garbageCollectObserver.call(this, observer); + } else { + observer[method].apply(observer, arguments); + } } - } + }, - Jelly.Observers.notifying = previousNotifying; - }, + notifying: false, - notifyObserver: function(observer, method, arguments) { - if (observer[method]) { - if (observer.detach && observer.detach()) { - Jelly.Observers.garbageCollectObserver.call(this, observer); - } else { - observer[method].apply(observer, arguments); + garbageCollectObserver: function(observer) { + var index = this.indexOf(observer); + if (index > -1) { + Jelly.Observers.remove.call(this, index, index + 1); } + }, + + remove: function(from, to) { + var rest = this.slice((to || from) + 1 || this.length); + this.length = from < 0 ? this.length + from : from; + return this.push.apply(this, rest); } }, - notifying: false, + Pages: { + init: function() { + this.all = {}; + Jelly.all = this.all; // Deprecated + }, - garbageCollectObserver: function(observer) { - var index = this.indexOf(observer); - if (index > -1) { - Jelly.Observers.remove.call(this, index, index + 1); + add: function(name) { + var page = new Jelly.Page.Constructor(name); + for (var i = 1; i < arguments.length; i++) { + $.extend(page, arguments[i]); + } + return page; } }, - remove: function(from, to) { - var rest = this.slice((to || from) + 1 || this.length); - this.length = from < 0 ? this.length + from : from; - return this.push.apply(this, rest); - } - }, + Page: { + init: function(controllerName, actionName) { + var page = Jelly.Pages.all[controllerName] || new Jelly.Page.Constructor(controllerName); + window.page = page; + if (page.all) page.all(); + if (page[actionName]) page[actionName].call(page); + page.loaded = true; + return page; + }, + Constructor: function(name) { + this.loaded = false; + this.documentHref = Jelly.Location.documentHref; - Pages: { - init: function() { - this.all = {}; - Jelly.all = this.all; // Deprecated + this.name = name; + Jelly.Pages.all[name] = this; + } }, - add: function(name) { - var page = new Jelly.Page.Constructor(name); - for (var i = 1; i < arguments.length; i++) { - $.extend(page, arguments[i]); + Location: { + on_redirect: function(location) { + top.location.href = location; } - return page; } - }, + }); + Jelly.add = Jelly.Pages.add; // Deprecated - Page: { - init: function(controllerName, actionName) { - var page = Jelly.Pages.all[controllerName] || new Jelly.Page.Constructor(controllerName); - window.page = page; - if (page.all) page.all(); - if (page[actionName]) page[actionName].call(page); - page.loaded = true; - return page; - }, - Constructor: function(name) { - this.loaded = false; - this.documentHref = Jelly.Location.documentHref; - - this.name = name; - Jelly.Pages.all[name] = this; - } - }, - - Location: { - on_redirect: function(location) { - top.location.href = location; - } - } -}); -Jelly.add = Jelly.Pages.add; // Deprecated - -Jelly.init(); + Jelly.init(); +})(jQuery)