Permalink
Browse files

Setting up basic javascript framework

  • Loading branch information...
1 parent f58d6df commit e0db60399e911f3a094d8defa159bdffedf02a1e @nahurst committed Mar 18, 2013
Showing with 42 additions and 13 deletions.
  1. +39 −12 app/assets/javascripts/application.js
  2. +3 −1 app/views/layouts/application.html.erb
@@ -1,18 +1,45 @@
-// This is a manifest file that'll be compiled into application.js, which will include all the files
-// listed below.
-//
-// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
-// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
-//
-// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
-// the compiled file.
-//
-// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
-// GO AFTER THE REQUIRES BELOW.
-//
//= require jquery
//= require jquery_ujs
//= require foundation
//= require_tree .
$(document).foundation();
+var APP = APP || {};
+APP = {
+ common: {
+ init: function() {
+
+ alert("init");
+ },
+ },
+ mail_merges: {
+ 'new': function() {
+ alert("new");
+
+ }
+ },
+}
+
+UTIL = {
+ exec : function(controller, action){
+ var ns = APP,
+ action = (action === undefined) ? "init" : action;
+
+ if (controller !== "" &&
+ ns[controller] &&
+ typeof ns[controller][action] === "function" ) {
+ ns[controller][action]();
+ }
+ },
+ init: function() {
+ var body = document.body,
+ controller = body.getAttribute("data-controller"),
+ action = body.getAttribute("data-action");
+ UTIL.exec("common");
+ UTIL.exec(controller);
+ UTIL.exec(controller, action);
+ }
+};
+$(document).ready(UTIL.init);
+
+
@@ -9,7 +9,9 @@
<%= csrf_meta_tags %>
<%= yield(:head) %>
</head>
- <body class="<%= controller_name %> <%= action_name %>">
+ <body class="<%= controller_name %> <%= action_name %>"
+ data-controller="<%= controller_name %>"
+ data-action="<%= action_name %>">
<div id="container" class="container">
<header>
<%= render 'layouts/navigation' %>

0 comments on commit e0db603

Please sign in to comment.