diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index a614cf5bbaac428a257905cb239a694e5109fdff..84129069728c14d623af32c963192a30b37c292d 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -12,26 +12,27 @@ window.disableButtonIfEmptyField = (field_selector, button_selector) -> field = $(field_selector) closest_submit = field.closest("form").find(button_selector) - closest_submit.attr("disabled", "disabled").addClass("disabled") if field.val() is "" + closest_submit.disable() if field.val() is "" field.on "keyup", -> if $(this).val() is "" - closest_submit.attr("disabled", "disabled").addClass "disabled" + closest_submit.disable() else - closest_submit.removeAttr("disabled").removeClass "disabled" + closest_submit.enable() $ -> $(".one_click_select").live 'click', -> $(this).select() + # Disable form buttons while a form is submitting $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> buttons = $('[type="submit"]', this) switch e.type when 'ajax:beforeSend', 'submit' - buttons.attr('disabled', 'disabled') + buttons.disable() else - buttons.removeAttr('disabled') + buttons.enable() # Show/Hide the profile menu when hovering the account box $('.account-box').hover -> $(this).toggleClass('hover') @@ -81,4 +82,12 @@ $ -> $.extend default_options, options _chosen.apply this, [default_options] + # Disable an element and add the 'disabled' Bootstrap class + $.fn.extend disable: -> + $(this).attr('disabled', 'disabled').addClass('disabled') + + # Enable an element and remove the 'disabled' Bootstrap class + $.fn.extend enable: -> + $(this).removeAttr('disabled').removeClass('disabled') + )(jQuery) diff --git a/app/assets/javascripts/note.js b/app/assets/javascripts/note.js index 160f75c98d410c69c434418cd66099107c9d7e0d..79ab086bfa2cd7572b387f1dabb1995e84571140 100644 --- a/app/assets/javascripts/note.js +++ b/app/assets/javascripts/note.js @@ -25,11 +25,11 @@ var NoteList = { $(this).closest('li').fadeOut(); }); $(".note-form-holder").live("ajax:before", function(){ - $(".submit_note").attr("disabled", "disabled"); + $(".submit_note").disable() }) $(".note-form-holder").live("ajax:complete", function(){ - $(".submit_note").removeAttr("disabled"); + $(".submit_note").enable() }) disableButtonIfEmptyField(".note-text", ".submit_note");