From 994774ec65d08ecccb47edaedf7636a181ecf4d0 Mon Sep 17 00:00:00 2001 From: David Gil Date: Fri, 14 Aug 2015 21:23:06 +0200 Subject: [PATCH] prevents for Comments.initialize to be called twice causing unexpected behaviour in forms, when initialize_modules is called on ajax:complete --- app/assets/javascripts/application.js | 4 +--- app/assets/javascripts/comments.js.coffee | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 34f0ece62..ed87ec326 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -31,7 +31,5 @@ $(function(){ $(document).ready(initialize_modules); $(document).on('page:load', initialize_modules); - $(document).on('ajax:complete', function(){ - App.Users.initialize(); - }); + $(document).on('ajax:complete', initialize_modules); }); diff --git a/app/assets/javascripts/comments.js.coffee b/app/assets/javascripts/comments.js.coffee index 0831d8a20..f6243beab 100644 --- a/app/assets/javascripts/comments.js.coffee +++ b/app/assets/javascripts/comments.js.coffee @@ -17,7 +17,17 @@ App.Comments = $("#js-comment-form-#{id}").toggle() initialize: -> - $('body').on 'click', '.js-add-comment-link', -> - id = $(this).data().id - App.Comments.toggle_form(id) - false + # $('body').on 'click', '.js-add-comment-link', -> + # id = $(this).data().id + # App.Comments.toggle_form(id) + # false + # + $('body .js-add-comment-link').each -> + $this = $(this) + + unless $this.data('initialized') is 'yes' + $this.on('click', -> + id = $(this).data().id + App.Comments.toggle_form(id) + false + ).data 'initialized', 'yes'