app/assets/javascripts/poke_js.js in poke_js-0.1.3 vs app/assets/javascripts/poke_js.js in poke_js-0.1.4
- old
+ new
@@ -16,36 +16,49 @@
define: function(namespace_string, definition) {
var found_namespace = POKE.get_or_create(namespace_string);
return $.extend(found_namespace, definition);
},
+ get_action_namespace: function(controller, format) {
+ var levels = controller.split('/');
+ levels.push(format);
+ var current_namespace = APP;
+
+ for (var i=0;i<levels.length;i++) {
+ var level = levels[i];
+ if (POKE.blank(current_namespace[level]))
+ return false;
+ current_namespace = current_namespace[level];
+ }
+ return current_namespace;
+ },
+
exec_all: function(controller, format, action) {
POKE.exec("all", format);
POKE.exec(controller, format);
POKE.exec(controller, format, action);
},
exec: function(controller, format, action) {
- var ns = APP,
+ var action_namespace = POKE.get_action_namespace(controller, format)
+
+ if ($.type(action_namespace) === "object") {
action = (action === undefined) ? "init" : action;
+ var funct = action_namespace[action],
+ params = action_namespace[action + "_params"];
- if (controller !== "" && ns[controller] &&
- format !== "" && ns[controller][format]) {
- var funct = ns[controller][format][action],
- params = ns[controller][format][action + "_params"];
-
if ($.isFunction(funct))
funct(params);
}
},
init: function() {
var $body = $('body');
POKE.exec_all($body.data("controller"), "html", $body.data("action"));
}
};
-if (POKE.blank(window["APP"]))
+if (POKE.blank(window["APP"])) {
APP = {
namespace_string: function(namespace_string) {
return "APP." + namespace_string;
},
get_or_create: function(namespace_string) {
@@ -53,6 +66,8 @@
},
define: function(namespace_string, definition) {
return POKE.define(APP.namespace_string(namespace_string), definition);
}
};
-$(POKE.init);
+}
+$(POKE.init);
+$(document).on('page:change', POKE.init);
\ No newline at end of file