pre-api-script.js
64 lines
| 1 | ;var gglcptch_pre = gglcptch_pre || {}; |
| 2 | gglcptch_pre.is_loaded = false; |
| 3 | |
| 4 | function gglcptch_alert_fail_message( e ) { |
| 5 | if ( ! gglcptch_pre.is_loaded ) { |
| 6 | e.preventDefault(); |
| 7 | e.stopImmediatePropagation(); |
| 8 | alert( gglcptch_pre.messages.timeout ); |
| 9 | } |
| 10 | } |
| 11 | |
| 12 | function gglcptch_onload_callback() { |
| 13 | ( function( $ ) { |
| 14 | if ( '' != gglcptch_pre.custom_callback ) { |
| 15 | eval( gglcptch_pre.custom_callback ); |
| 16 | } |
| 17 | gglcptch_pre.is_loaded = true; |
| 18 | $( document ).ready( function() { |
| 19 | $( 'form input:submit, form button' ).filter('[data-gglcptch_disabled]') |
| 20 | .removeAttr( 'disabled' ) |
| 21 | .removeAttr( 'data-gglcptch_disabled' ) |
| 22 | .each( function() { |
| 23 | $( this ).restoreTitle(); |
| 24 | } ); |
| 25 | } ); |
| 26 | } )( jQuery ); |
| 27 | } |
| 28 | |
| 29 | ( function( $ ) { |
| 30 | $.fn.storeTitle = function() { |
| 31 | var title = ( typeof $( this ).attr( 'title' ) != 'undefined' ) ? $( this ).attr( 'title' ) : ''; |
| 32 | this.attr( 'data-storedTitle', title ); |
| 33 | } |
| 34 | |
| 35 | $.fn.restoreTitle = function() { |
| 36 | var title = this.attr( 'data-storedTitle' ); |
| 37 | if ( '' != title ) { |
| 38 | this.attr( 'title' ) = title; |
| 39 | } else { |
| 40 | this.removeAttr( 'title' ); |
| 41 | } |
| 42 | this.removeAttr( 'data-storedTitle' ); |
| 43 | } |
| 44 | |
| 45 | $( document ).ready( function() { |
| 46 | if ( ! gglcptch_pre.is_loaded ) { |
| 47 | $( '.gglcptch_v2, .gglcptch_invisible' ).each( function() { |
| 48 | $( this ).closest( 'form' ) |
| 49 | .find( 'input:submit, button' ).filter( ':not(:disabled)' ) |
| 50 | .attr( 'disabled', 'disabled' ).attr( 'data-gglcptch_disabled', 'true' ) |
| 51 | .each( function() { |
| 52 | $( this ).storeTitle(); |
| 53 | $( this ).attr( 'title', gglcptch_pre.messages.in_progress ); |
| 54 | } ); |
| 55 | } ); |
| 56 | } |
| 57 | } ); |
| 58 | |
| 59 | $( window ).on( 'load', function() { |
| 60 | if ( ! gglcptch_pre.is_loaded ) { |
| 61 | $( '[data-gglcptch_disabled]' ).removeAttr( 'disabled' ).one( 'click', gglcptch_alert_fail_message ); |
| 62 | } |
| 63 | } ); |
| 64 | } )( jQuery ); |