blob: cc13c3c825dd91d1430fa757e0c27ab99342b7b1 [file] [log] [blame]
Copybara botbe50d492023-11-30 00:16:42 +01001define( [
2 "./core",
3 "./core/nodeName",
4 "./core/camelCase",
5 "./core/toType",
6 "./var/isFunction",
7 "./var/isWindow",
8 "./var/slice",
9
Renovate botf591dcf2023-12-30 14:13:54 +000010 "./deprecated/ajax-event-alias",
11 "./deprecated/event"
Copybara botbe50d492023-11-30 00:16:42 +010012], function( jQuery, nodeName, camelCase, toType, isFunction, isWindow, slice ) {
13
14"use strict";
15
Renovate botf591dcf2023-12-30 14:13:54 +000016// Support: Android <=4.0 only
17// Make sure we trim BOM and NBSP
18var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
Copybara botbe50d492023-11-30 00:16:42 +010019
20// Bind a function to a context, optionally partially applying any
21// arguments.
22// jQuery.proxy is deprecated to promote standards (specifically Function#bind)
23// However, it is not slated for removal any time soon
24jQuery.proxy = function( fn, context ) {
25 var tmp, args, proxy;
26
27 if ( typeof context === "string" ) {
28 tmp = fn[ context ];
29 context = fn;
30 fn = tmp;
31 }
32
33 // Quick check to determine if target is callable, in the spec
34 // this throws a TypeError, but we will just return undefined.
35 if ( !isFunction( fn ) ) {
36 return undefined;
37 }
38
39 // Simulated bind
40 args = slice.call( arguments, 2 );
41 proxy = function() {
42 return fn.apply( context || this, args.concat( slice.call( arguments ) ) );
43 };
44
45 // Set the guid of unique handler to the same of original handler, so it can be removed
46 proxy.guid = fn.guid = fn.guid || jQuery.guid++;
47
48 return proxy;
49};
50
51jQuery.holdReady = function( hold ) {
52 if ( hold ) {
53 jQuery.readyWait++;
54 } else {
55 jQuery.ready( true );
56 }
57};
58jQuery.isArray = Array.isArray;
59jQuery.parseJSON = JSON.parse;
60jQuery.nodeName = nodeName;
61jQuery.isFunction = isFunction;
62jQuery.isWindow = isWindow;
63jQuery.camelCase = camelCase;
64jQuery.type = toType;
65
66jQuery.now = Date.now;
67
68jQuery.isNumeric = function( obj ) {
69
70 // As of jQuery 3.0, isNumeric is limited to
71 // strings and numbers (primitives or objects)
72 // that can be coerced to finite numbers (gh-2662)
73 var type = jQuery.type( obj );
74 return ( type === "number" || type === "string" ) &&
75
76 // parseFloat NaNs numeric-cast false positives ("")
77 // ...but misinterprets leading-number strings, particularly hex literals ("0x...")
78 // subtraction forces infinities to NaN
79 !isNaN( obj - parseFloat( obj ) );
80};
81
Renovate botf591dcf2023-12-30 14:13:54 +000082jQuery.trim = function( text ) {
83 return text == null ?
84 "" :
85 ( text + "" ).replace( rtrim, "" );
86};
Copybara botbe50d492023-11-30 00:16:42 +010087} );