1/** 2 * @file 3 * A JavaScript file for the theme. 4 * This file should be used as a template for your other js files. 5 * It defines a drupal behavior the "Drupal way". 6 * 7 */ 8 9// JavaScript should be made compatible with libraries other than jQuery by 10// wrapping it with an "anonymous closure". See: 11// - https://drupal.org/node/1446420 12// - http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth 13 14(function ($, Drupal, window, document, undefined) { 15 'use strict'; 16 17 // To understand behaviors, see https://drupal.org/node/756722#behaviors 18 Drupal.behaviors.hideSubmitBlockit = { 19 attach: function(context) { 20 var timeoutId = null; 21 $('form', context).once('hideSubmitButton', function () { 22 var $form = $(this); 23 24 // Bind to input elements. 25 if (Drupal.settings.hide_submit.hide_submit_method === 'indicator') { 26 // Replace input elements with buttons. 27 $('input.form-submit', $form).each(function(index, el) { 28 var attrs = {}; 29 30 $.each($(this)[0].attributes, function(idx, attr) { 31 attrs[attr.nodeName] = attr.nodeValue; 32 }); 33 34 $(this).replaceWith(function() { 35 return $("<button/>", attrs).append($(this).attr('value')); 36 }); 37 }); 38 // Add needed attributes to the submit buttons. 39 $('button.form-submit', $form).each(function(index, el) { 40 $(this).addClass('ladda-button button').attr({ 41 'data-style': Drupal.settings.hide_submit.hide_submit_indicator_style, 42 'data-spinner-color': Drupal.settings.hide_submit.hide_submit_spinner_color, 43 'data-spinner-lines': Drupal.settings.hide_submit.hide_submit_spinner_lines 44 }); 45 }); 46 Ladda.bind('.ladda-button', $form, { 47 timeout: Drupal.settings.hide_submit.hide_submit_reset_time 48 }); 49 } 50 else { 51 $('input.form-submit, button.form-submit', $form).click(function (e) { 52 var el = $(this); 53 el.after('<input type="hidden" name="' + el.attr('name') + '" value="' + el.attr('value') + '" />'); 54 return true; 55 }); 56 } 57 58 // Bind to form submit. 59 $('form', context).submit(function (e) { 60 var $inp; 61 if (!e.isPropagationStopped()) { 62 if (Drupal.settings.hide_submit.hide_submit_method === 'disable') { 63 $('input.form-submit, button.form-submit', $form).attr('disabled', 'disabled').each(function (i) { 64 var $button = $(this); 65 if (Drupal.settings.hide_submit.hide_submit_css) { 66 $button.addClass(Drupal.settings.hide_submit.hide_submit_css); 67 } 68 if (Drupal.settings.hide_submit.hide_submit_abtext) { 69 $button.val($button.val() + ' ' + Drupal.settings.hide_submit.hide_submit_abtext); 70 } 71 $inp = $button; 72 }); 73 74 if ($inp && Drupal.settings.hide_submit.hide_submit_atext) { 75 $inp.after('<span class="hide-submit-text">' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_atext) + '</span>'); 76 } 77 } 78 else if (Drupal.settings.hide_submit.hide_submit_method !== 'indicator'){ 79 var pdiv = '<div class="hide-submit-text' + (Drupal.settings.hide_submit.hide_submit_hide_css ? ' ' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_hide_css) + '"' : '') + '>' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_hide_text) + '</div>'; 80 if (Drupal.settings.hide_submit.hide_submit_hide_fx) { 81 $('input.form-submit, button.form-submit', $form).addClass(Drupal.settings.hide_submit.hide_submit_css).fadeOut(100).eq(0).after(pdiv); 82 $('input.form-submit, button.form-submit', $form).next().fadeIn(100); 83 } 84 else { 85 $('input.form-submit, button.form-submit', $form).addClass(Drupal.settings.hide_submit.hide_submit_css).hide().eq(0).after(pdiv); 86 } 87 } 88 // Add a timeout to reset the buttons (if needed). 89 if (Drupal.settings.hide_submit.hide_submit_reset_time) { 90 timeoutId = window.setTimeout(function() { 91 hideSubmitResetButtons(null, $form); 92 }, Drupal.settings.hide_submit.hide_submit_reset_time); 93 } 94 } 95 return true; 96 }); 97 }); 98 99 // Bind to clientsideValidationFormHasErrors to support clientside validation. 100 // $(document).bind('clientsideValidationFormHasErrors', function(event, form) { 101 //hideSubmitResetButtons(event, form.form); 102 // }); 103 104 // Reset all buttons. 105 function hideSubmitResetButtons(event, form) { 106 // Clear timer. 107 window.clearTimeout(timeoutId); 108 timeoutId = null; 109 switch (Drupal.settings.hide_submit.hide_submit_method) { 110 case 'disable': 111 $('input.' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_css) + ', button.' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_css), form) 112 .each(function (i, el) { 113 $(el).removeClass(Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_hide_css)) 114 .removeAttr('disabled'); 115 }); 116 $('.hide-submit-text', form).remove(); 117 break; 118 119 case 'indicator': 120 Ladda.stopAll(); 121 break; 122 123 default: 124 $('input.' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_css) + ', button.' + Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_css), form) 125 .each(function (i, el) { 126 $(el).stop() 127 .removeClass(Drupal.checkPlain(Drupal.settings.hide_submit.hide_submit_hide_css)) 128 .show(); 129 }); 130 $('.hide-submit-text', form).remove(); 131 } 132 } 133 } 134 }; 135 136})(jQuery, Drupal, window, this.document);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.