app/assets/javascripts/poke_js.js in poke_js-0.1.2 vs app/assets/javascripts/poke_js.js in poke_js-0.1.3

- old
+ new

@@ -1,28 +1,28 @@ //http://stackoverflow.com/questions/6167805/using-rails-3-1-where-do-you-put-your-page-specific-javascript-code POKE = { blank: function(o) { return typeof o === "undefined" || o === null; }, - present: function(o) { - return !POKE.blank(o); + get_or_create: function(namespace_string) { + var current_namepace = window; + $.each(namespace_string.split('.'), function(index, level) { + if (POKE.blank(current_namepace[level])) + current_namepace[level] = {}; + current_namepace = current_namepace[level]; + }); + + return current_namepace; }, - get_or_create: function(namespace, o) { - if (POKE.blank(o)) - o = APP; - if (POKE.blank(o[namespace])) - o[namespace] = {}; - return o[namespace]; + define: function(namespace_string, definition) { + var found_namespace = POKE.get_or_create(namespace_string); + return $.extend(found_namespace, definition); }, - define: function(namespace, hash, o) { - var o_namespace = POKE.get_or_create(namespace, o); - return $.extend(o_namespace, hash); - }, exec_all: function(controller, format, action) { - POKE.exec("app", format); + POKE.exec("all", format); POKE.exec(controller, format); POKE.exec(controller, format, action); }, exec: function(controller, format, action) { var ns = APP, @@ -42,7 +42,17 @@ POKE.exec_all($body.data("controller"), "html", $body.data("action")); } }; if (POKE.blank(window["APP"])) - APP = {}; + APP = { + namespace_string: function(namespace_string) { + return "APP." + namespace_string; + }, + get_or_create: function(namespace_string) { + return POKE.define(APP.namespace_string(namespace_string)); + }, + define: function(namespace_string, definition) { + return POKE.define(APP.namespace_string(namespace_string), definition); + } + }; $(POKE.init); \ No newline at end of file