generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.7.2 vs generators/jelly/templates/javascripts/jelly.js in honkster-jelly-0.7.3

- old
+ new

@@ -1,10 +1,10 @@ /** * Jelly. a sweet unobtrusive javascript framework * for jQuery and Rails * - * version 0.7.2 + * version 0.7.3 * * Copyright (c) 2009 Pivotal Labs * Licensed under the MIT license. * * * Date: 2009-07-20 9:50:50 (Mon, 20 Jul 2009) @@ -64,12 +64,29 @@ } for (var i = 0; i < observers.length; i++) { var observer = observers[i]; if (observer[params.method]) { - observer[params.method].apply(observer, params.arguments); + if (observer.detach && observer.detach()) { + this.garbageCollectObserver(observer); + } else { + observer[params.method].apply(observer, params.arguments); + } } } +}; + +Jelly.garbageCollectObserver = function(observer) { + var index = Jelly.observers.indexOf(observer); + if (index > -1) { + this.arrayRemove(Jelly.observers, index, index + 1); + } +}; + +Jelly.arrayRemove = function(array, from, to) { + var rest = array.slice((to || from) + 1 || array.length); + array.length = from < 0 ? array.length + from : from; + return array.push.apply(array, rest); }; Jelly.Components = { init: function() { for (var i = 0; i < Jelly.components.length; i++) {