PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / assets / js / campaign-builder / utils.js

utils.js in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11, at assets/js/campaign-builder/utils.js

134 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 'use strict';
2
3 // eslint-disable-next-line no-unused-vars
4 const CharitableUtils = window.CharitableUtils || ( function( document, window, $ ) {
5
6 /**
7 * Public functions and properties.
8 *
9 * @since 1.8.0
10 *
11 * @type {object}
12 */
13 const app = {
14
15 /**
16 * function that prevents certain HTML/JS/etc characters from being inputted into headlines, campaign titles, etc.
17 *
18 * @since 1.8.0
19 *
20 * @param {string} stringValue The text, usually coming from user input.
21 *
22 * @returns {Event} Event object.
23 */
24 santitizeTitle: function ( stringValue ) {
25
26 return stringValue.replace(/[^\w\s\u00C0-\u024F\u1E00-\u1EFF\u2C60-\u2C7F\uA720-\uA7FF _.,!"()'\/$[\]:@#%-]/gi, '');
27
28 },
29
30
31 /**
32 * function that prevents certain HTML/JS/etc characters from being inputted into generic text input areas/boxes.
33 *
34 * @since 1.8.0
35 *
36 * @param {string} stringValue The text, usually coming from user input.
37 *
38 * @returns {Event} Event object.
39 */
40 santitizeTextInput: function ( stringValue ) {
41
42 return stringValue.replace(/[^\w\s\u00C0-\u024F\u1E00-\u1EFF\u2C60-\u2C7F\uA720-\uA7FF _.,!"()'\/$[\]:@#%-]/gi, '');
43
44 },
45
46 /**
47 * function that prevents certain HTML/JS/etc characters from being inputted into CSS class input areas/boxes.
48 *
49 * @since 1.8.0
50 *
51 * @param {string} stringValue The text, usually coming from user input.
52 *
53 * @returns {Event} Event object.
54 */
55 santitizeCSSInput: function ( stringValue ) {
56
57 return stringValue.replace(/[^a-zA-Z0-9_,\/$:\-\.!;]/g, ''); //eslint-disable-line
58
59 },
60
61 /**
62 * Wrapper to trigger a native or custom event and return the event object.
63 *
64 * @since 1.8.0
65 *
66 * @param {jQuery} $element Element to trigger event on.
67 * @param {string} eventName Event name to trigger (custom or native).
68 * @param {Array} args Trigger arguments.
69 *
70 * @returns {Event} Event object.
71 */
72 triggerEvent: function( $element, eventName, args = [] ) {
73
74 let eventObject = new $.Event( eventName );
75
76 $element.trigger( eventObject, args );
77
78 return eventObject;
79 },
80
81 /**
82 * Debounce.
83 *
84 * This function comes directly from underscore.js:
85 *
86 * Returns a function, that, as long as it continues to be invoked, will not
87 * be triggered. The function will be called after it stops being called for
88 * N milliseconds. If `immediate` is passed, trigger the function on the
89 * leading edge, instead of the trailing.
90 *
91 * Debouncing is removing unwanted input noise from buttons, switches or other user input.
92 * Debouncing prevents extra activations or slow functions from triggering too often.
93 *
94 * @param {Function} func The function to be debounced.
95 * @param {int} wait The amount of time to delay calling func.
96 * @param {bool} immediate Whether or not to trigger the function on the leading edge.
97 *
98 * @returns {Function} Returns a function that, as long as it continues to be invoked, will not be triggered.
99 */
100 debounce: function( func, wait, immediate ) {
101
102 var timeout;
103
104 return function() {
105
106 var context = this,
107 args = arguments;
108 var later = function() {
109
110 timeout = null;
111
112 if ( ! immediate ) {
113 func.apply( context, args );
114 }
115 };
116
117 var callNow = immediate && ! timeout;
118
119 clearTimeout( timeout );
120
121 timeout = setTimeout( later, wait );
122
123 if ( callNow ) {
124 func.apply( context, args );
125 }
126 };
127 },
128 };
129
130 // Provide access to public functions/properties.
131 return app;
132
133 }( document, window, jQuery ) ); // eslint-disable-line
134