123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- (function($){
- Drupal.behaviors.CToolsAutoSubmit = {
- attach: function(context) {
-
- function triggerSubmit (e) {
- if ($.contains(document.body, this)) {
- var $this = $(this);
- if (!$this.hasClass('ctools-ajaxing')) {
- $this.find('.ctools-auto-submit-click').click();
- }
- }
- }
-
- $('form.ctools-auto-submit-full-form', context)
- .add('.ctools-auto-submit', context)
- .filter('form, select, input:not(:text, :submit)')
- .once('ctools-auto-submit')
- .change(function (e) {
-
- if ($(e.target).is(':not(:text, :submit, .ctools-auto-submit-exclude)')) {
- triggerSubmit.call(e.target.form);
- }
- });
-
- var discardKeyCode = [
- 16,
- 17,
- 18,
- 20,
- 33,
- 34,
- 35,
- 36,
- 37,
- 38,
- 39,
- 40,
- 9,
- 13,
- 27
- ];
-
- $('.ctools-auto-submit-full-form input:text, input:text.ctools-auto-submit', context)
- .filter(':not(.ctools-auto-submit-exclude)')
- .once('ctools-auto-submit', function () {
-
- var timeoutID = 0;
- $(this)
- .bind('keydown keyup', function (e) {
- if ($.inArray(e.keyCode, discardKeyCode) === -1) {
- timeoutID && clearTimeout(timeoutID);
- }
- })
- .keyup(function(e) {
- if ($.inArray(e.keyCode, discardKeyCode) === -1) {
- timeoutID = setTimeout($.proxy(triggerSubmit, this.form), 500);
- }
- })
- .bind('change', function (e) {
- if ($.inArray(e.keyCode, discardKeyCode) === -1) {
- timeoutID = setTimeout($.proxy(triggerSubmit, this.form), 500);
- }
- });
- });
- }
- }
- })(jQuery);
|