global.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // TODO: Fix error collecting.
  2. //window.onerror = function(message, url, lineNumber) {
  3. // var data;
  4. //
  5. // data = {
  6. // 'action': 'nf_log_js_error',
  7. // 'security': nfFrontEnd.ajaxNonce,
  8. // 'message': message,
  9. // 'url': url,
  10. // 'lineNumber': lineNumber
  11. // };
  12. //
  13. // jQuery.ajax({
  14. // url: nfFrontEnd.adminAjax,
  15. // type: 'POST',
  16. // data: data,
  17. // cache: false,
  18. // success: function( data, textStatus, jqXHR ) {
  19. // try {
  20. //
  21. // } catch( e ) {
  22. // console.log( e );
  23. // console.log( 'Parse Error' );
  24. // console.log( e );
  25. // }
  26. //
  27. // },
  28. // error: function( jqXHR, textStatus, errorThrown ) {
  29. // // Handle errors here
  30. // console.log('ERRORS: ' + errorThrown);
  31. // console.log( jqXHR );
  32. //
  33. // try {
  34. //
  35. // } catch( e ) {
  36. // console.log( 'Parse Error' );
  37. // }
  38. // }
  39. // });
  40. // return false;
  41. //};
  42. var nfRadio = Backbone.Radio;
  43. nfRadio.channel( 'form' ).on( 'render:view', function() {
  44. jQuery( '.g-recaptcha' ).each( function() {
  45. var callback = jQuery( this ).data( 'callback' );
  46. var fieldID = jQuery( this ).data( 'fieldid' );
  47. if ( typeof window[ callback ] !== 'function' ){
  48. window[ callback ] = function( response ) {
  49. nfRadio.channel( 'recaptcha' ).request( 'update:response', response, fieldID );
  50. };
  51. }
  52. } );
  53. } );
  54. var nfRecaptcha = Marionette.Object.extend( {
  55. initialize: function() {
  56. /*
  57. * If we've already rendered our form view, render our recaptcha fields.
  58. */
  59. if ( 0 != jQuery( '.g-recaptcha' ).length ) {
  60. this.renderCaptcha();
  61. }
  62. /*
  63. * We haven't rendered our form view, so hook into the view render radio message, and then render.
  64. */
  65. this.listenTo( nfRadio.channel( 'form' ), 'render:view', this.renderCaptcha );
  66. this.listenTo( nfRadio.channel( 'captcha' ), 'reset', this.renderCaptcha );
  67. },
  68. renderCaptcha: function() {
  69. jQuery( '.g-recaptcha' ).each( function() {
  70. var opts = {
  71. fieldid: jQuery( this ).data( 'fieldid' ),
  72. size: jQuery( this ).data( 'size' ),
  73. theme: jQuery( this ).data( 'theme' ),
  74. sitekey: jQuery( this ).data( 'sitekey' ),
  75. callback: jQuery( this ).data( 'callback' )
  76. };
  77. var grecaptchaID = grecaptcha.render( jQuery( this )[0], opts );
  78. if ( opts.size === 'invisible' ) {
  79. try {
  80. grecaptcha.execute( grecaptchaID );
  81. } catch( e ){
  82. console.log( 'Notice: Error trying to execute grecaptcha.' );
  83. }
  84. }
  85. } );
  86. }
  87. } );
  88. var nfRenderRecaptcha = function() {
  89. new nfRecaptcha();
  90. }