From 1237f9d8ad9f58652619205faca8b6e5efb69c2f Mon Sep 17 00:00:00 2001 From: kikito Date: Thu, 30 Jul 2015 13:19:34 +0200 Subject: [PATCH] make a comments module. Move module initializing to application.js --- app/assets/javascripts/application.js | 11 ++++++++++- app/assets/javascripts/comments.js.coffee | 12 ++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 5c03e171e..08153c4ec 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -18,4 +18,13 @@ //= require app //= require_tree . -$(function(){ $(document).foundation(); }); +var initialize_modules = function() { + App.Comments.initialize(); +}; + +$(function(){ + $(document).foundation(); + + $(document).ready(initialize_modules) + $(document).on('page:load', initialize_modules) +}); diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 79333e0c7..a84cd02ac 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -1,13 +1,13 @@ -jQuery -> - toggle_comment = (id) -> +App.Comments = + + toggle_form: (id) -> $("#js-comment-form-#{id}").toggle() - ready = -> + initialize: -> $('body').on 'click', '.js-add-comment-link', -> id = $(this).data().id - toggle_comment(id) + App.Comments.toggle_form(id) false - $(document).ready(ready) - $(document).on('page:load', ready) \ No newline at end of file +