44
44
// Used for splitting on whitespace
45
45
core_rnotwhite = / \S + / g,
46
46
47
- // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
48
- rtrim = / ^ [ \s \uFEFF \xA0 ] + | [ \s \uFEFF \xA0 ] + $ / g,
49
-
50
47
// A simple way to check for HTML strings
51
48
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
52
49
// Strict HTML recognition (#11290: must start with <)
55
52
// Match a standalone tag
56
53
rsingleTag = / ^ < ( \w + ) \s * \/ ? > (?: < \/ \1> | ) $ / ,
57
54
58
- // JSON RegExp
59
- rvalidchars = / ^ [ \] , : { } \s ] * $ / ,
60
- rvalidbraces = / (?: ^ | : | , ) (?: \s * \[ ) + / g,
61
- rvalidescape = / \\ (?: [ " \\ \/ b f n r t ] | u [ \d a - f A - F ] { 4 } ) / g,
62
- rvalidtokens = / " [ ^ " \\ \r \n ] * " | t r u e | f a l s e | n u l l | - ? (?: \d + \. | ) \d + (?: [ e E ] [ + - ] ? \d + | ) / g,
63
-
64
55
// Matches dashed string for camelizing
65
56
rmsPrefix = / ^ - m s - / ,
66
57
rdashAlpha = / - ( [ \d a - z ] ) / gi,
72
63
73
64
// The ready event handler and self cleanup method
74
65
DOMContentLoaded = function ( ) {
75
- if ( document . addEventListener ) {
76
- document . removeEventListener ( "DOMContentLoaded" , DOMContentLoaded , false ) ;
77
- jQuery . ready ( ) ;
78
- } else if ( document . readyState === "complete" ) {
79
- // we're here because readyState === "complete" in oldIE
80
- // which is good enough for us to call the dom ready!
81
- document . detachEvent ( "onreadystatechange" , DOMContentLoaded ) ;
82
- jQuery . ready ( ) ;
83
- }
66
+ document . removeEventListener ( "DOMContentLoaded" , DOMContentLoaded , false ) ;
67
+ jQuery . ready ( ) ;
84
68
} ;
85
69
86
70
jQuery . fn = jQuery . prototype = {
@@ -384,11 +368,6 @@ jQuery.extend({
384
368
return ;
385
369
}
386
370
387
- // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
388
- if ( ! document . body ) {
389
- return setTimeout ( jQuery . ready ) ;
390
- }
391
-
392
371
// Remember that the DOM is ready
393
372
jQuery . isReady = true ;
394
373
@@ -413,9 +392,7 @@ jQuery.extend({
413
392
return jQuery . type ( obj ) === "function" ;
414
393
} ,
415
394
416
- isArray : Array . isArray || function ( obj ) {
417
- return jQuery . type ( obj ) === "array" ;
418
- } ,
395
+ isArray : Array . isArray ,
419
396
420
397
isWindow : function ( obj ) {
421
398
return obj != null && obj == obj . window ;
@@ -435,32 +412,29 @@ jQuery.extend({
435
412
} ,
436
413
437
414
isPlainObject : function ( obj ) {
438
- // Must be an Object.
439
- // Because of IE, we also have to check the presence of the constructor property.
440
- // Make sure that DOM nodes and window objects don't pass through, as well
441
- if ( ! obj || jQuery . type ( obj ) !== "object" || obj . nodeType || jQuery . isWindow ( obj ) ) {
415
+ // Not plain objects:
416
+ // - Any object or value whose internal [[Class]] property is not "[object Object]"
417
+ // - DOM nodes
418
+ // - window
419
+ if ( jQuery . type ( obj ) !== "object" || obj . nodeType || jQuery . isWindow ( obj ) ) {
442
420
return false ;
443
421
}
444
422
423
+ // Support: Firefox >16
424
+ // The try/catch supresses exceptions thrown when attempting to access
425
+ // the "constructor" property of certain host objects, ie. |window.location|
445
426
try {
446
- // Not own constructor property must be Object
447
427
if ( obj . constructor &&
448
- ! core_hasOwn . call ( obj , "constructor" ) &&
449
- ! core_hasOwn . call ( obj . constructor . prototype , "isPrototypeOf" ) ) {
428
+ ! core_hasOwn . call ( obj . constructor . prototype , "isPrototypeOf" ) ) {
450
429
return false ;
451
430
}
452
431
} catch ( e ) {
453
- // IE8,9 Will throw exceptions on certain host objects #9897
454
432
return false ;
455
433
}
456
434
457
- // Own properties are enumerated firstly, so to speed up,
458
- // if last one is own, then all properties are own.
459
-
460
- var key ;
461
- for ( key in obj ) { }
462
-
463
- return key === undefined || core_hasOwn . call ( obj , key ) ;
435
+ // If the function hasn't returned already, we're confident that
436
+ // |obj| is a plain object, created by {} or constructed with new Object
437
+ return true ;
464
438
} ,
465
439
466
440
isEmptyObject : function ( obj ) {
@@ -504,55 +478,24 @@ jQuery.extend({
504
478
return jQuery . merge ( [ ] , parsed . childNodes ) ;
505
479
} ,
506
480
507
- parseJSON : function ( data ) {
508
- // Attempt to parse using the native JSON parser first
509
- if ( window . JSON && window . JSON . parse ) {
510
- return window . JSON . parse ( data ) ;
511
- }
512
-
513
- if ( data === null ) {
514
- return data ;
515
- }
516
-
517
- if ( typeof data === "string" ) {
518
-
519
- // Make sure leading/trailing whitespace is removed (IE can't handle it)
520
- data = jQuery . trim ( data ) ;
521
-
522
- if ( data ) {
523
- // Make sure the incoming data is actual JSON
524
- // Logic borrowed from http://json.org/json2.js
525
- if ( rvalidchars . test ( data . replace ( rvalidescape , "@" )
526
- . replace ( rvalidtokens , "]" )
527
- . replace ( rvalidbraces , "" ) ) ) {
528
-
529
- return ( new Function ( "return " + data ) ) ( ) ;
530
- }
531
- }
532
- }
533
-
534
- jQuery . error ( "Invalid JSON: " + data ) ;
535
- } ,
481
+ parseJSON : JSON . parse ,
536
482
537
483
// Cross-browser xml parsing
538
484
parseXML : function ( data ) {
539
485
var xml , tmp ;
540
486
if ( ! data || typeof data !== "string" ) {
541
487
return null ;
542
488
}
489
+
490
+ // Support: IE9
543
491
try {
544
- if ( window . DOMParser ) { // Standard
545
- tmp = new DOMParser ( ) ;
546
- xml = tmp . parseFromString ( data , "text/xml" ) ;
547
- } else { // IE
548
- xml = new ActiveXObject ( "Microsoft.XMLDOM" ) ;
549
- xml . async = "false" ;
550
- xml . loadXML ( data ) ;
551
- }
552
- } catch ( e ) {
492
+ tmp = new DOMParser ( ) ;
493
+ xml = tmp . parseFromString ( data , "text/xml" ) ;
494
+ } catch ( e ) {
553
495
xml = undefined ;
554
496
}
555
- if ( ! xml || ! xml . documentElement || xml . getElementsByTagName ( "parsererror" ) . length ) {
497
+
498
+ if ( ! xml || xml . getElementsByTagName ( "parsererror" ) . length ) {
556
499
jQuery . error ( "Invalid XML: " + data ) ;
557
500
}
558
501
return xml ;
@@ -561,16 +504,10 @@ jQuery.extend({
561
504
noop : function ( ) { } ,
562
505
563
506
// Evaluates a script in a global context
564
- // Workarounds based on findings by Jim Driscoll
565
- // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context
566
507
globalEval : function ( data ) {
567
- if ( data && jQuery . trim ( data ) ) {
568
- // We use execScript on Internet Explorer
569
- // We use an anonymous function so that context is window
570
- // rather than jQuery in Firefox
571
- ( window . execScript || function ( data ) {
572
- window [ "eval" ] . call ( window , data ) ;
573
- } ) ( data ) ;
508
+ var indirect = eval ;
509
+ if ( jQuery . trim ( data ) ) {
510
+ indirect ( data + ";" ) ;
574
511
}
575
512
} ,
576
513
@@ -634,20 +571,9 @@ jQuery.extend({
634
571
return obj ;
635
572
} ,
636
573
637
- // Use native String.trim function wherever possible
638
- trim : core_trim && ! core_trim . call ( "\uFEFF\xA0" ) ?
639
- function ( text ) {
640
- return text == null ?
641
- "" :
642
- core_trim . call ( text ) ;
643
- } :
644
-
645
- // Otherwise use our own trimming functionality
646
- function ( text ) {
647
- return text == null ?
648
- "" :
649
- ( text + "" ) . replace ( rtrim , "" ) ;
650
- } ,
574
+ trim : function ( text ) {
575
+ return text == null ? "" : core_trim . call ( text ) ;
576
+ } ,
651
577
652
578
// results is for internal usage only
653
579
makeArray : function ( arr , results ) {
@@ -668,25 +594,7 @@ jQuery.extend({
668
594
} ,
669
595
670
596
inArray : function ( elem , arr , i ) {
671
- var len ;
672
-
673
- if ( arr ) {
674
- if ( core_indexOf ) {
675
- return core_indexOf . call ( arr , elem , i ) ;
676
- }
677
-
678
- len = arr . length ;
679
- i = i ? i < 0 ? Math . max ( 0 , len + i ) : i : 0 ;
680
-
681
- for ( ; i < len ; i ++ ) {
682
- // Skip accessing in sparse arrays
683
- if ( i in arr && arr [ i ] === elem ) {
684
- return i ;
685
- }
686
- }
687
- }
688
-
689
- return - 1 ;
597
+ return arr == null ? - 1 : core_indexOf . call ( arr , elem , i ) ;
690
598
} ,
691
599
692
600
merge : function ( first , second ) {
@@ -846,9 +754,7 @@ jQuery.extend({
846
754
length ? fn ( elems [ 0 ] , key ) : emptyGet ;
847
755
} ,
848
756
849
- now : function ( ) {
850
- return ( new Date ( ) ) . getTime ( ) ;
851
- }
757
+ now : Date . now
852
758
} ) ;
853
759
854
760
jQuery . ready . promise = function ( obj ) {
@@ -864,46 +770,12 @@ jQuery.ready.promise = function( obj ) {
864
770
setTimeout ( jQuery . ready ) ;
865
771
866
772
// Standards-based browsers support DOMContentLoaded
867
- } else if ( document . addEventListener ) {
773
+ } else {
868
774
// Use the handy event callback
869
775
document . addEventListener ( "DOMContentLoaded" , DOMContentLoaded , false ) ;
870
776
871
777
// A fallback to window.onload, that will always work
872
778
window . addEventListener ( "load" , jQuery . ready , false ) ;
873
-
874
- // If IE event model is used
875
- } else {
876
- // Ensure firing before onload, maybe late but safe also for iframes
877
- document . attachEvent ( "onreadystatechange" , DOMContentLoaded ) ;
878
-
879
- // A fallback to window.onload, that will always work
880
- window . attachEvent ( "onload" , jQuery . ready ) ;
881
-
882
- // If IE and not a frame
883
- // continually check to see if the document is ready
884
- var top = false ;
885
-
886
- try {
887
- top = window . frameElement == null && document . documentElement ;
888
- } catch ( e ) { }
889
-
890
- if ( top && top . doScroll ) {
891
- ( function doScrollCheck ( ) {
892
- if ( ! jQuery . isReady ) {
893
-
894
- try {
895
- // Use the trick by Diego Perini
896
- // http://javascript.nwbox.com/IEContentLoaded/
897
- top . doScroll ( "left" ) ;
898
- } catch ( e ) {
899
- return setTimeout ( doScrollCheck , 50 ) ;
900
- }
901
-
902
- // and execute any waiting functions
903
- jQuery . ready ( ) ;
904
- }
905
- } ) ( ) ;
906
- }
907
779
}
908
780
}
909
781
return readyList . promise ( obj ) ;
0 commit comments