Changeset 1640733
- Timestamp:
- 04/19/2017 04:10:27 PM (9 years ago)
- Location:
- wp-libre-form
- Files:
-
- 6 edited
- 1 copied
-
tags/1.2.2 (copied) (copied from wp-libre-form/trunk)
-
tags/1.2.2/assets/scripts/wplf-form.js (modified) (5 diffs)
-
tags/1.2.2/classes/class-cpt-wplf-form.php (modified) (1 diff)
-
tags/1.2.2/readme.md (modified) (1 diff)
-
trunk/assets/scripts/wplf-form.js (modified) (5 diffs)
-
trunk/classes/class-cpt-wplf-form.php (modified) (1 diff)
-
trunk/readme.md (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
wp-libre-form/tags/1.2.2/assets/scripts/wplf-form.js
r1538409 r1640733 9 9 !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); 10 10 11 (function() { 11 12 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); 32 19 // add class to enable css changes to indicate ajax loading 33 20 form.classList.add("sending"); 34 21 35 [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) {22 [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) { 36 23 // reset errors 37 24 error.parentNode.removeChild(error); 38 25 }); 39 26 40 var data = new FormData(form);41 42 window.data = data;43 44 27 fetch(ajax_object.ajax_url + '?action=wplf_submit', { 45 28 method: "POST", 29 credentials: ajax_object.ajax_credentials || 'same-origin', 46 30 body: data 47 }).then(function(response){ 48 31 }).then(function(response) { 49 32 return response.text(); 50 51 }).then(function(response){ 52 33 }).then(function(response) { 53 34 response = JSON.parse(response); 54 35 55 36 if( 'success' in response ) { 56 37 // show success message if one exists 57 58 38 var success = document.createElement("p"); 59 39 success.className = "wplf-success"; … … 67 47 form.parentNode.removeChild(form); 68 48 69 window.wplf.successCallbacks.forEach(function(func) {49 window.wplf.successCallbacks.forEach(function(func) { 70 50 func(response); 71 51 }); … … 74 54 if( 'error' in response ) { 75 55 // show error message in form 76 77 56 var error = document.createElement("p"); 78 57 error.className = "wplf-error error"; … … 81 60 form.appendChild(error); 82 61 83 window.wplf.errorCallbacks.forEach(function(func) {62 window.wplf.errorCallbacks.forEach(function(func) { 84 63 func(response); 85 64 }); … … 87 66 88 67 form.classList.remove('sending'); 89 90 }).catch(function(error){ 91 92 console.warn("Fetch error: ", error); 68 }).catch(function(error) { 93 69 form.classList.remove("sending"); 94 70 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 } 95 78 }); 96 79 97 80 // 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 } 98 88 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 } 101 96 102 } 103 } 97 form.addEventListener("submit", window.wplf.submitHandler); 98 } 99 }; 104 100 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 }); 108 104 })(); -
wp-libre-form/tags/1.2.2/classes/class-cpt-wplf-form.php
r1538409 r1640733 513 513 514 514 // 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 ); 516 522 517 523 if( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'libre-form') || $post->post_type === 'wplf-form') ) { 518 524 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 ) ); 520 529 } 521 530 } -
wp-libre-form/tags/1.2.2/readme.md
r1538409 r1640733 88 88 ```php 89 89 wp_enqueue_script('wplf-form-js'); 90 wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); 90 wp_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 ) ); 91 94 ``` 92 95 -
wp-libre-form/trunk/assets/scripts/wplf-form.js
r1538409 r1640733 9 9 !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); 10 10 11 (function() { 11 12 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); 32 19 // add class to enable css changes to indicate ajax loading 33 20 form.classList.add("sending"); 34 21 35 [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) {22 [].forEach.call(form.querySelectorAll(".wplf-error"), function(error) { 36 23 // reset errors 37 24 error.parentNode.removeChild(error); 38 25 }); 39 26 40 var data = new FormData(form);41 42 window.data = data;43 44 27 fetch(ajax_object.ajax_url + '?action=wplf_submit', { 45 28 method: "POST", 29 credentials: ajax_object.ajax_credentials || 'same-origin', 46 30 body: data 47 }).then(function(response){ 48 31 }).then(function(response) { 49 32 return response.text(); 50 51 }).then(function(response){ 52 33 }).then(function(response) { 53 34 response = JSON.parse(response); 54 35 55 36 if( 'success' in response ) { 56 37 // show success message if one exists 57 58 38 var success = document.createElement("p"); 59 39 success.className = "wplf-success"; … … 67 47 form.parentNode.removeChild(form); 68 48 69 window.wplf.successCallbacks.forEach(function(func) {49 window.wplf.successCallbacks.forEach(function(func) { 70 50 func(response); 71 51 }); … … 74 54 if( 'error' in response ) { 75 55 // show error message in form 76 77 56 var error = document.createElement("p"); 78 57 error.className = "wplf-error error"; … … 81 60 form.appendChild(error); 82 61 83 window.wplf.errorCallbacks.forEach(function(func) {62 window.wplf.errorCallbacks.forEach(function(func) { 84 63 func(response); 85 64 }); … … 87 66 88 67 form.classList.remove('sending'); 89 90 }).catch(function(error){ 91 92 console.warn("Fetch error: ", error); 68 }).catch(function(error) { 93 69 form.classList.remove("sending"); 94 70 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 } 95 78 }); 96 79 97 80 // 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 } 98 88 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 } 101 96 102 } 103 } 97 form.addEventListener("submit", window.wplf.submitHandler); 98 } 99 }; 104 100 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 }); 108 104 })(); -
wp-libre-form/trunk/classes/class-cpt-wplf-form.php
r1538409 r1640733 513 513 514 514 // 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 ); 516 522 517 523 if( is_a( $post, 'WP_Post' ) && ( has_shortcode( $post->post_content, 'libre-form') || $post->post_type === 'wplf-form') ) { 518 524 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 ) ); 520 529 } 521 530 } -
wp-libre-form/trunk/readme.md
r1538409 r1640733 88 88 ```php 89 89 wp_enqueue_script('wplf-form-js'); 90 wp_localize_script( 'wplf-form-js', 'ajax_object', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) ); 90 wp_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 ) ); 91 94 ``` 92 95
Note: See TracChangeset
for help on using the changeset viewer.