diff --git a/e107_web/js/core/all.jquery.js b/e107_web/js/core/all.jquery.js index cd8179c33..061635c4a 100644 --- a/e107_web/js/core/all.jquery.js +++ b/e107_web/js/core/all.jquery.js @@ -331,6 +331,52 @@ var e107 = e107 || {'settings': {}, 'behaviors': {}}; } }; + /** + * Behavior to initialize submit buttons. + * + * @type {{attach: e107.behaviors.buttonSubmit.attach}} + */ + e107.behaviors.buttonSubmit = { + attach: function (context, settings) + { + $(context).find('button[type=submit]').once('button-submit').each(function () + { + $(this).on('click', function () + { + var $button = $(this); + var $form = $button.closest('form'); + + var type = $button.data('loading-icon'); + + if(type === undefined || $form.length === 0) + { + return true; + } + + $form.submit(function () + { + if ($form.find('.has-error').length > 0) { + return false; + } + + var caption = "<i class='fa fa-spin " + type + " fa-fw'></i>"; + caption += "<span>" + $button.text() + "</span>"; + + $button.html(caption); + + if($button.attr('data-disable') == 'true') + { + $button.addClass('disabled'); + } + }); + + return true; + } + ); + }); + } + }; + /** * Check if the selector is valid. * @@ -851,42 +897,7 @@ $(document).ready(function() $(id).hide("slow"); return false; - }); - - - - $('button[type=submit]').on('click', function() - { - var caption = $(this).text(); - var type = $(this).attr('data-loading-icon'); - var formid = $(this).closest('form').attr('id'); - var but = $(this); - - if(type === undefined || (formid === undefined)) - { - return true; - } - - $('#'+formid).submit(function(){ // only animate on successful submission. - - caption = "<i class='fa fa-spin " + type + " fa-fw'></i><span>" + caption + "</span>"; - - $(but).html(caption); - - if( $(but).attr('data-disable') == 'true') - { - - $(but).addClass('disabled'); - } - - }); - - - return true; - } - ); - - + }); // Dates --------------------------------------------------