Sha256: 2a668269870be8a75cb8cacd297597c4084596d82589d7686ca12ba5aee00ad9

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

//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, o) {
        if (POKE.blank(o))
            o = APP;
        if (POKE.blank(o[namespace]))
            o[namespace] = {};
        return o[namespace];
    },
    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(controller, format);
        POKE.exec(controller, format, action);
    },
    exec: function(controller, format, action) {
        var ns = APP,
            action = (action === undefined) ? "init" : action;

        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"]))
    APP = {};
$(POKE.init);

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
poke_js-0.1.2 app/assets/javascripts/poke_js.js