From 33b27d2fa70abbab3476eb70071ed374622279f3 Mon Sep 17 00:00:00 2001 From: wvengen Date: Mon, 8 Jul 2013 22:41:06 +0200 Subject: [PATCH] proper usage of jQuery.on(), and update javascript in views as well --- app/assets/javascripts/application.js | 12 ++++++------ app/views/deliveries/_form.html.haml | 6 +++--- .../financial_transactions/new_collection.html.haml | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index f0645ea1..c5228350 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -28,19 +28,19 @@ $.fn.extend({ $(function() { // Show/Hide a specific DOM element - $('a[data-toggle-this]').on('click', function() { + $(document).on('click', 'a[data-toggle-this]', function() { $($(this).data('toggle-this')).toggle(); return false; }); // Remove this item from DOM - $('a[data-remove-this]').on('click', function() { + $(document).on('click', 'a[data-remove-this]', function() { $($(this).data('remove-this')).remove(); return false; }); // Check/Uncheck a single checkbox - $('[data-check-this]').on('click', function() { + $(document).on('click', '[data-check-this]', function() { var checkbox = $($(this).data('check-this')); checkbox.attr('checked', !checkbox.is(':checked')); highlightRow(checkbox); @@ -48,7 +48,7 @@ $(function() { }); // Check/Uncheck all checkboxes for a specific form - $('input[data-check-all]').on('click', function() { + $(document).on('click', 'input[data-check-all]', function() { var status = $(this).is(':checked'); var context = $(this).data('check-all'); var elms = $('input[type="checkbox"]', context); @@ -60,7 +60,7 @@ $(function() { }); // Submit form when changing a select menu. - $('form[data-submit-onchange] select').on('change', function() { + $(document).on('change', 'form[data-submit-onchange] select', function() { var confirmMessage = $(this).children(':selected').data('confirm'); if (confirmMessage) { if (confirm(confirmMessage)) { @@ -93,7 +93,7 @@ $(function() { }); // Remote paginations - $('div.pagination[data-remote] a').on('click', function() { + $(document).on('click', 'div.pagination[data-remote] a', function() { $.getScript($(this).attr('href')); return false; }); diff --git a/app/views/deliveries/_form.html.haml b/app/views/deliveries/_form.html.haml index 5eff702d..ba85b482 100644 --- a/app/views/deliveries/_form.html.haml +++ b/app/views/deliveries/_form.html.haml @@ -1,15 +1,15 @@ - content_for :javascript do :javascript $(function() { - $('.destroy_stock_change').live('click', function() { + $(document).on('click', '.destroy_stock_change', function() { $(this).prev('input').val('1').parent().hide(); return false; }); - $('.remove_new_stock_change').live('click', function() { + $(document).on('click', '.remove_new_stock_change', function() { $(this).parent().remove(); return false; - }) + }); }); = simple_form_for [@supplier, @delivery], validate: true do |f| diff --git a/app/views/finance/financial_transactions/new_collection.html.haml b/app/views/finance/financial_transactions/new_collection.html.haml index 324b118b..aaa67129 100644 --- a/app/views/finance/financial_transactions/new_collection.html.haml +++ b/app/views/finance/financial_transactions/new_collection.html.haml @@ -5,12 +5,12 @@ var ordergroup = "#{escape_javascript(render('ordergroup'))}" $(function() { - $('a[data-remove-transaction]').live('click', function() { + $(document).on('click', 'a[data-remove-transaction]', function() { $(this).parents('tr').remove(); return false; }); - $('a[data-add-transaction]').click(function() { + $(document).on('click', 'a[data-add-transaction]', function() { $('#ordergroups').append(ordergroup); return false; });