Plugin Directory

Changeset 1640733


Ignore:
Timestamp:
04/19/2017 04:10:27 PM (9 years ago)
Author:
Zuige
Message:

Test

Location:
wp-libre-form
Files:
6 edited
1 copied

Legend:

Unmodified
Added
Removed
  • wp-libre-form/tags/1.2.2/assets/scripts/wplf-form.js

    r1538409 r1640733  
    99!function(t){function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function o(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function r(t,e){for(;3===t._state;)t=t._value;return 0===t._state?void t._deferreds.push(e):(t._handled=!0,void a(function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?i:f)(e.promise,t._value);var o;try{o=n(t._value)}catch(r){return void f(e.promise,r)}i(e.promise,o)}))}function i(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if(e instanceof o)return t._state=3,t._value=e,void u(t);if("function"==typeof r)return void s(n(r,e),t)}t._state=1,t._value=e,u(t)}catch(i){f(t,i)}}function f(t,e){t._state=2,t._value=e,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&a(function(){t._handled||d(t._value)});for(var e=0,n=t._deferreds.length;n>e;e++)r(t,t._deferreds[e]);t._deferreds=null}function c(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function s(t,e){var n=!1;try{t(function(t){n||(n=!0,i(e,t))},function(t){n||(n=!0,f(e,t))})}catch(o){if(n)return;n=!0,f(e,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(t){l(t,0)},d=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};o.prototype["catch"]=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var o=new this.constructor(e);return r(this,new c(t,n,o)),o},o.all=function(t){var e=Array.prototype.slice.call(t);return new o(function(t,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(t){o(i,t)},n)}e[i]=f,0===--r&&t(e)}catch(c){n(c)}}if(0===e.length)return t([]);for(var r=e.length,i=0;i<e.length;i++)o(i,e[i])})},o.resolve=function(t){return t&&"object"==typeof t&&t.constructor===o?t:new o(function(e){e(t)})},o.reject=function(t){return new o(function(e,n){n(t)})},o.race=function(t){return new o(function(e,n){for(var o=0,r=t.length;r>o;o++)t[o].then(e,n)})},o._setImmediateFn=function(t){a=t},o._setUnhandledRejectionFn=function(t){d=t},"undefined"!=typeof module&&module.exports?module.exports=o:t.Promise||(t.Promise=o)}(this);
    1010
     11(function() {
    1112
    12 (function(){
    13 
    14 window.wplf = {
    15   successCallbacks: [],
    16   errorCallbacks: [],
    17   attach: function(form){
    18     // form is a selector
    19     if (typeof form == 'string')
    20       form = document.querySelectorAll(form);
    21 
    22     // form is an array of elements or a node list
    23     if (form.constructor === Array || form.constructor === NodeList){
    24       [].forEach.call(form, function(form){
    25         window.wplf.attach(form);
    26       });
    27       return;
    28     }
    29 
    30     form.addEventListener("submit", function(e){
    31 
     13  window.wplf = {
     14    successCallbacks: [],
     15    errorCallbacks: [],
     16    submitHandler: function (e) {
     17      var form = e.target;
     18      var data = new FormData(form);
    3219      // add class to enable css changes to indicate ajax loading
    3320      form.classList.add("sending");
    3421
    35       [].forEach.call(form.querySelectorAll(".wplf-error"), function(error){
     22      [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) {
    3623        // reset errors
    3724        error.parentNode.removeChild(error);
    3825      });
    3926
    40       var data = new FormData(form);
    41 
    42       window.data = data;
    43 
    4427      fetch(ajax_object.ajax_url  + '?action=wplf_submit', {
    4528        method: "POST",
     29        credentials: ajax_object.ajax_credentials || 'same-origin',
    4630        body: data
    47       }).then(function(response){
    48 
     31      }).then(function(response) {
    4932        return response.text();
    50 
    51       }).then(function(response){
    52 
     33      }).then(function(response) {
    5334        response = JSON.parse(response);
    5435
    5536        if( 'success' in response ) {
    5637          // show success message if one exists
    57 
    5838          var success = document.createElement("p");
    5939          success.className = "wplf-success";
     
    6747          form.parentNode.removeChild(form);
    6848
    69           window.wplf.successCallbacks.forEach(function(func){
     49          window.wplf.successCallbacks.forEach(function(func) {
    7050            func(response);
    7151          });
     
    7454        if( 'error' in response ) {
    7555          // show error message in form
    76 
    7756          var error = document.createElement("p");
    7857          error.className = "wplf-error error";
     
    8160          form.appendChild(error);
    8261
    83           window.wplf.errorCallbacks.forEach(function(func){
     62          window.wplf.errorCallbacks.forEach(function(func) {
    8463            func(response);
    8564          });
     
    8766
    8867        form.classList.remove('sending');
    89 
    90       }).catch(function(error){
    91 
    92         console.warn("Fetch error: ", error);
     68      }).catch(function(error) {
    9369        form.classList.remove("sending");
    9470
     71        if (window.wplf.errorCallbacks.length > 0) {
     72          window.wplf.errorCallbacks.forEach(function(func) {
     73            func(error);
     74          });
     75        } else {
     76          console.warn("Fetch error: ", error);
     77        }
    9578      });
    9679
    9780      // don't actually submit the form, causing a page reload
     81      e.preventDefault();
     82    },
     83    attach: function(form) {
     84      // form is a selector
     85      if (typeof form == 'string') {
     86        form = document.querySelectorAll(form);
     87      }
    9888
    99       e.preventDefault();
    100     });
     89      // form is an array of elements or a node list
     90      if (form.constructor === Array || form.constructor === NodeList) {
     91        [].forEach.call(form, function(form){
     92          window.wplf.attach(form);
     93        });
     94        return;
     95      }
    10196
    102   }
    103 }
     97      form.addEventListener("submit", window.wplf.submitHandler);
     98    }
     99  };
    104100
    105 document.addEventListener("DOMContentLoaded", function(){
    106   [].forEach.call(document.querySelectorAll(".libre-form"), wplf.attach);
    107 });
     101  document.addEventListener("DOMContentLoaded", function() {
     102    [].forEach.call(document.querySelectorAll(".libre-form"), window.wplf.attach);
     103  });
    108104})();
  • wp-libre-form/tags/1.2.2/classes/class-cpt-wplf-form.php

    r1538409 r1640733  
    513513
    514514    // register the script, but only enqueue it if the current post contains a form in it
    515     wp_register_script( 'wplf-form-js', plugins_url( 'assets/scripts/wplf-form.js', dirname(__FILE__) ), array(), WPLF_VERSION, true );
     515    wp_register_script(
     516      'wplf-form-js',
     517      plugins_url( 'assets/scripts/wplf-form.js', dirname(__FILE__) ),
     518      apply_filters( 'wplf_frontend_script_dependencies', array() ),
     519      WPLF_VERSION,
     520      true
     521    );
    516522
    517523    if( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'libre-form') || $post->post_type === 'wplf-form') ) {
    518524      wp_enqueue_script( 'wplf-form-js' );
    519       wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
     525      wp_localize_script( 'wplf-form-js', 'ajax_object', array(
     526        'ajax_url' => admin_url( 'admin-ajax.php' ),
     527        'ajax_credentials' => apply_filters('wplf_ajax_fetch_credentials_mode', 'same-origin')
     528      ) );
    520529    }
    521530  }
  • wp-libre-form/tags/1.2.2/readme.md

    r1538409 r1640733  
    8888```php
    8989wp_enqueue_script('wplf-form-js');
    90 wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
     90wp_localize_script( 'wplf-form-js', 'ajax_object', array(
     91  'ajax_url' => admin_url( 'admin-ajax.php' ),
     92  'ajax_credentials' => apply_filters('wplf_frontend_script_credentials', 'same-origin')
     93) );
    9194```
    9295
  • wp-libre-form/trunk/assets/scripts/wplf-form.js

    r1538409 r1640733  
    99!function(t){function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function o(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function r(t,e){for(;3===t._state;)t=t._value;return 0===t._state?void t._deferreds.push(e):(t._handled=!0,void a(function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?i:f)(e.promise,t._value);var o;try{o=n(t._value)}catch(r){return void f(e.promise,r)}i(e.promise,o)}))}function i(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if(e instanceof o)return t._state=3,t._value=e,void u(t);if("function"==typeof r)return void s(n(r,e),t)}t._state=1,t._value=e,u(t)}catch(i){f(t,i)}}function f(t,e){t._state=2,t._value=e,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&a(function(){t._handled||d(t._value)});for(var e=0,n=t._deferreds.length;n>e;e++)r(t,t._deferreds[e]);t._deferreds=null}function c(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function s(t,e){var n=!1;try{t(function(t){n||(n=!0,i(e,t))},function(t){n||(n=!0,f(e,t))})}catch(o){if(n)return;n=!0,f(e,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(t){l(t,0)},d=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};o.prototype["catch"]=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var o=new this.constructor(e);return r(this,new c(t,n,o)),o},o.all=function(t){var e=Array.prototype.slice.call(t);return new o(function(t,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(t){o(i,t)},n)}e[i]=f,0===--r&&t(e)}catch(c){n(c)}}if(0===e.length)return t([]);for(var r=e.length,i=0;i<e.length;i++)o(i,e[i])})},o.resolve=function(t){return t&&"object"==typeof t&&t.constructor===o?t:new o(function(e){e(t)})},o.reject=function(t){return new o(function(e,n){n(t)})},o.race=function(t){return new o(function(e,n){for(var o=0,r=t.length;r>o;o++)t[o].then(e,n)})},o._setImmediateFn=function(t){a=t},o._setUnhandledRejectionFn=function(t){d=t},"undefined"!=typeof module&&module.exports?module.exports=o:t.Promise||(t.Promise=o)}(this);
    1010
     11(function() {
    1112
    12 (function(){
    13 
    14 window.wplf = {
    15   successCallbacks: [],
    16   errorCallbacks: [],
    17   attach: function(form){
    18     // form is a selector
    19     if (typeof form == 'string')
    20       form = document.querySelectorAll(form);
    21 
    22     // form is an array of elements or a node list
    23     if (form.constructor === Array || form.constructor === NodeList){
    24       [].forEach.call(form, function(form){
    25         window.wplf.attach(form);
    26       });
    27       return;
    28     }
    29 
    30     form.addEventListener("submit", function(e){
    31 
     13  window.wplf = {
     14    successCallbacks: [],
     15    errorCallbacks: [],
     16    submitHandler: function (e) {
     17      var form = e.target;
     18      var data = new FormData(form);
    3219      // add class to enable css changes to indicate ajax loading
    3320      form.classList.add("sending");
    3421
    35       [].forEach.call(form.querySelectorAll(".wplf-error"), function(error){
     22      [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) {
    3623        // reset errors
    3724        error.parentNode.removeChild(error);
    3825      });
    3926
    40       var data = new FormData(form);
    41 
    42       window.data = data;
    43 
    4427      fetch(ajax_object.ajax_url  + '?action=wplf_submit', {
    4528        method: "POST",
     29        credentials: ajax_object.ajax_credentials || 'same-origin',
    4630        body: data
    47       }).then(function(response){
    48 
     31      }).then(function(response) {
    4932        return response.text();
    50 
    51       }).then(function(response){
    52 
     33      }).then(function(response) {
    5334        response = JSON.parse(response);
    5435
    5536        if( 'success' in response ) {
    5637          // show success message if one exists
    57 
    5838          var success = document.createElement("p");
    5939          success.className = "wplf-success";
     
    6747          form.parentNode.removeChild(form);
    6848
    69           window.wplf.successCallbacks.forEach(function(func){
     49          window.wplf.successCallbacks.forEach(function(func) {
    7050            func(response);
    7151          });
     
    7454        if( 'error' in response ) {
    7555          // show error message in form
    76 
    7756          var error = document.createElement("p");
    7857          error.className = "wplf-error error";
     
    8160          form.appendChild(error);
    8261
    83           window.wplf.errorCallbacks.forEach(function(func){
     62          window.wplf.errorCallbacks.forEach(function(func) {
    8463            func(response);
    8564          });
     
    8766
    8867        form.classList.remove('sending');
    89 
    90       }).catch(function(error){
    91 
    92         console.warn("Fetch error: ", error);
     68      }).catch(function(error) {
    9369        form.classList.remove("sending");
    9470
     71        if (window.wplf.errorCallbacks.length > 0) {
     72          window.wplf.errorCallbacks.forEach(function(func) {
     73            func(error);
     74          });
     75        } else {
     76          console.warn("Fetch error: ", error);
     77        }
    9578      });
    9679
    9780      // don't actually submit the form, causing a page reload
     81      e.preventDefault();
     82    },
     83    attach: function(form) {
     84      // form is a selector
     85      if (typeof form == 'string') {
     86        form = document.querySelectorAll(form);
     87      }
    9888
    99       e.preventDefault();
    100     });
     89      // form is an array of elements or a node list
     90      if (form.constructor === Array || form.constructor === NodeList) {
     91        [].forEach.call(form, function(form){
     92          window.wplf.attach(form);
     93        });
     94        return;
     95      }
    10196
    102   }
    103 }
     97      form.addEventListener("submit", window.wplf.submitHandler);
     98    }
     99  };
    104100
    105 document.addEventListener("DOMContentLoaded", function(){
    106   [].forEach.call(document.querySelectorAll(".libre-form"), wplf.attach);
    107 });
     101  document.addEventListener("DOMContentLoaded", function() {
     102    [].forEach.call(document.querySelectorAll(".libre-form"), window.wplf.attach);
     103  });
    108104})();
  • wp-libre-form/trunk/classes/class-cpt-wplf-form.php

    r1538409 r1640733  
    513513
    514514    // register the script, but only enqueue it if the current post contains a form in it
    515     wp_register_script( 'wplf-form-js', plugins_url( 'assets/scripts/wplf-form.js', dirname(__FILE__) ), array(), WPLF_VERSION, true );
     515    wp_register_script(
     516      'wplf-form-js',
     517      plugins_url( 'assets/scripts/wplf-form.js', dirname(__FILE__) ),
     518      apply_filters( 'wplf_frontend_script_dependencies', array() ),
     519      WPLF_VERSION,
     520      true
     521    );
    516522
    517523    if( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'libre-form') || $post->post_type === 'wplf-form') ) {
    518524      wp_enqueue_script( 'wplf-form-js' );
    519       wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
     525      wp_localize_script( 'wplf-form-js', 'ajax_object', array(
     526        'ajax_url' => admin_url( 'admin-ajax.php' ),
     527        'ajax_credentials' => apply_filters('wplf_ajax_fetch_credentials_mode', 'same-origin')
     528      ) );
    520529    }
    521530  }
  • wp-libre-form/trunk/readme.md

    r1538409 r1640733  
    8888```php
    8989wp_enqueue_script('wplf-form-js');
    90 wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
     90wp_localize_script( 'wplf-form-js', 'ajax_object', array(
     91  'ajax_url' => admin_url( 'admin-ajax.php' ),
     92  'ajax_credentials' => apply_filters('wplf_frontend_script_credentials', 'same-origin')
     93) );
    9194```
    9295
Note: See TracChangeset for help on using the changeset viewer.