PluginProbe
UpdraftCentral Dashboard / trunk
UpdraftCentral Dashboard vtrunk
0.8.33 0.7.2 0.7.3 0.7.4 0.8.0 0.8.1 0.8.10 0.8.11 0.8.12 0.8.13 0.8.14 0.8.15 0.8.16 0.8.17 0.8.18 0.8.19 0.8.2 0.8.20 0.8.21 0.8.22 0.8.23 0.8.24 0.8.25 0.8.26 0.8.27 All 51 releases
updraftcentral / js / deprecated.js

deprecated.js in UpdraftCentral Dashboard trunk, at js/deprecated.js

162 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($) {
2
3 // This is to safeguard from future jQuery releases that eventually removes these functions and properties, thus,
4 // making the entire UpdraftCentral or most of its features inoperable. Also, since we don't have the liberty
5 // to edit and publish third party libraries that we used in UpdraftCentral this code block/plugin will be of
6 // great help to ensure that UpdraftCentral will continue to work if these deprecated functions and properties
7 // are removed in future jQuery releases.
8
9 // We can't extend this property dynamically, so we'll have to manually define it with the alternative value for it.
10 Object.defineProperty($.expr, ":", {
11 enumerable: true,
12 value: $.expr.pseudos,
13 });
14
15 // Overriding jQuery's functions/properties with the latest suggested alternatives.
16 // Properties: $.fn() or jQuery.fn()
17 $.extend({
18 unique: function prop() {
19 return $.uniqueSort(arguments[0]);
20 },
21 isFunction: function prop() {
22 return 'function' === typeof arguments[0];
23 },
24 isArray: function prop() {
25 return Array.isArray(arguments[0]);
26 },
27 trim: function prop() {
28 var value = arguments[0];
29 if ('string' === typeof value) {
30 return value.trim();
31 }
32 return ('undefined' !== typeof value) ? value : '';
33 },
34 isNumeric: function prop() {
35 var value = arguments[0];
36 if ('number' === typeof value) return true;
37 if ('string' !== typeof value) return false;
38
39 return !isNaN(value) && !isNaN(parseFloat(value));
40 },
41 type: function prop() {
42 var value = arguments[0];
43 var type = typeof(value);
44
45 if ('object' === type) {
46 if (value.hasOwnProperty('constructor')) {
47 return value.constructor.name.toLowerCase();
48 }
49 }
50 return type;
51 },
52 });
53
54 // Functions: $('</>').fn() or jQuery('</>').fn();
55 $.fn.extend({
56 bind: function() {
57 switch (arguments.length) {
58 case 1:
59 // events
60 return this.on(arguments[0]);
61 case 2:
62 // eventType, eventData | eventType, handler
63 return this.on(arguments[0], arguments[1]);
64 case 3:
65 // eventType, eventData, handler|preventBubble
66 return this.on(arguments[0], arguments[1], arguments[2]);
67 default:
68 return this;
69 }
70 },
71 unbind: function() {
72 switch (arguments.length) {
73 case 1:
74 // event
75 return this.off(arguments[0]);
76 case 2:
77 // eventType, handler
78 if ('function' === typeof arguments[1]) {
79 return this.off(arguments[0], arguments[1]);
80 }
81 // eventType, false - since off() does not take any boolean as second argument, thus,
82 // we only need to pass the eventType to unbind any events associated with the object.
83 return this.off(arguments[0]);
84 case 0:
85 // no arguments
86 return this.off();
87 default:
88 return this;
89 }
90 },
91 hover: function(fnOver, fnOut) {
92 return this.on('mouseenter', fnOver).on('mouseleave', fnOut);
93 },
94 removeAttr: function(attrib) {
95 if ('disabled' === attrib) {
96 return this.prop('disabled', false);
97 }
98
99 if ($(this).hasOwnProperty('length') && 0 !== $(this).length) {
100 $(this).get(0).removeAttribute(attrib);
101 }
102 return this;
103 },
104 resize: function() {
105 return _callback.call(this, 'resize', arguments);
106 },
107 click: function() {
108 return _callback.call(this, 'click', arguments);
109 },
110 dblclick: function() {
111 return _callback.call(this, 'dblclick', arguments);
112 },
113 scroll: function() {
114 return _callback.call(this, 'scroll', arguments);
115 },
116 keydown: function() {
117 return _callback.call(this, 'keydown', arguments);
118 },
119 keyup: function() {
120 return _callback.call(this, 'keyup', arguments);
121 },
122 keypress: function() {
123 return _callback.call(this, 'keypress', arguments);
124 },
125 change: function() {
126 return _callback.call(this, 'change', arguments);
127 },
128 focus: function() {
129 return _callback.call(this, 'focus', arguments);
130 },
131 });
132
133 /**
134 * A wrapper function that alter/update calls to the deprecated jQuery functions
135 *
136 * Functions passed through here basically has the same signature, thus, we wrapped everything here
137 * and let them call this handler instead of repeating them for each function to avoid redundancy.
138 *
139 * @param {string} name Name of the function
140 * @param {array} args Arguments to the function
141 *
142 * @returns {mixed}
143 */
144 function _callback(name, args) {
145 switch (args.length) {
146 case 1:
147 // Arguments index 0=handler
148 return this.on(name, args[0]);
149 case 2:
150 // Arguments index 0=data, 1=handler
151 return this.on(name, args[0], args[1]);
152 default:
153 break;
154 }
155
156 // Since we don't have any arguments then that would mean the shorthand
157 // for the event (e.g. "click", "focus", etc.) which is now deprecated has been called or triggered.
158 return this.trigger(name);
159 }
160
161 })(jQuery);
162