From 7b8cd65a558d9d708d5c1afc36f3b791cf6a260f Mon Sep 17 00:00:00 2001 From: John Bintz Date: Wed, 10 Apr 2013 18:34:47 -0400 Subject: [PATCH] fix some slow javascript. oops --- app/assets/javascripts/cocoon.js | 3 +-- app/assets/javascripts/cocoon/ordered.js | 8 +++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/cocoon.js b/app/assets/javascripts/cocoon.js index b45c389..8ce999b 100644 --- a/app/assets/javascripts/cocoon.js +++ b/app/assets/javascripts/cocoon.js @@ -11,7 +11,7 @@ return $(this).parent().siblings(selector); } - $('.add_fields').live('click', function(e) { + $(document).on('click', '.add_fields', function(e) { e.preventDefault(); var $this = $(this), assoc = $this.data('association'), @@ -67,7 +67,6 @@ trigger_node.trigger('cocoon:before-remove', [node_to_delete]); - var timeout = trigger_node.data('remove-timeout') || 0; setTimeout( diff --git a/app/assets/javascripts/cocoon/ordered.js b/app/assets/javascripts/cocoon/ordered.js index ca85f39..9bedf89 100644 --- a/app/assets/javascripts/cocoon/ordered.js +++ b/app/assets/javascripts/cocoon/ordered.js @@ -1,8 +1,7 @@ -//= require jquery.ui.all -// (function($) { $.cocoon = { ordered: { + isSetUp: false, options: { items: '> .nested-fields', stop: function(e, ui) { @@ -74,7 +73,10 @@ }); }); - $(document).on('cocoon:after-insert', function() { $.cocoon.ordered.setup(); }); + if (!$.cocoon.ordered.isSetUp) { + $(document).on('cocoon:after-insert', function() { $.cocoon.ordered.setup(); }); + $.cocoon.ordered.isSetUp = true; + } } }, };