Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.57 KB | None | 0 0
  1. // See test/unit/core.js for details concerning isFunction.
  2. // Since version 1.3, DOM methods and functions like alert
  3. // aren't supported. They return false on IE (#2968).
  4. isFunction: function( obj ) {
  5. return jQuery.type(obj) === "function";
  6. },
  7.  
  8. isArray: Array.isArray || function( obj ) {
  9. return jQuery.type(obj) === "array";
  10. },
  11.  
  12. isWindow: function( obj ) {
  13. /* jshint eqeqeq: false */
  14. return obj != null && obj == obj.window;
  15. },
  16.  
  17. isNumeric: function( obj ) {
  18. return !isNaN( parseFloat(obj) ) && isFinite( obj );
  19. },
  20.  
  21. type: function( obj ) {
  22. if ( obj == null ) {
  23. return String( obj );
  24. }
  25. return typeof obj === "object" || typeof obj === "function" ?
  26. class2type[ core_toString.call(obj) ] || "object" :
  27. typeof obj;
  28. },
  29.  
  30. isPlainObject: function( obj ) {
  31. var key;
  32.  
  33. // Must be an Object.
  34. // Because of IE, we also have to check the presence of the constructor property.
  35. // Make sure that DOM nodes and window objects don't pass through, as well
  36. if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) {
  37. return false;
  38. }
  39.  
  40. try {
  41. // Not own constructor property must be Object
  42. if ( obj.constructor &&
  43. !core_hasOwn.call(obj, "constructor") &&
  44. !core_hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) {
  45. return false;
  46. }
  47. } catch ( e ) {
  48. // IE8,9 Will throw exceptions on certain host objects #9897
  49. return false;
  50. }
  51.  
  52. // Support: IE<9
  53. // Handle iteration over inherited properties before own properties.
  54. if ( jQuery.support.ownLast ) {
  55. for ( key in obj ) {
  56. return core_hasOwn.call( obj, key );
  57. }
  58. }
  59.  
  60. // Own properties are enumerated firstly, so to speed up,
  61. // if last one is own, then all properties are own.
  62. for ( key in obj ) {}
  63.  
  64. return key === undefined || core_hasOwn.call( obj, key );
  65. },
  66.  
  67. isEmptyObject: function( obj ) {
  68. var name;
  69. for ( name in obj ) {
  70. return false;
  71. }
  72. return true;
  73. },
  74.  
  75. error: function( msg ) {
  76. throw new Error( msg );
  77. },
  78.  
  79. // data: string of html
  80. // context (optional): If specified, the fragment will be created in this context, defaults to document
  81. // keepScripts (optional): If true, will include scripts passed in the html string
  82. parseHTML: function( data, context, keepScripts ) {
  83. if ( !data || typeof data !== "string" ) {
  84. return null;
  85. }
  86. if ( typeof context === "boolean" ) {
  87. keepScripts = context;
  88. context = false;
  89. }
  90. context = context || document;
  91.  
  92. var parsed = rsingleTag.exec( data ),
  93. scripts = !keepScripts && [];
  94.  
  95. // Single tag
  96. if ( parsed ) {
  97. return [ context.createElement( parsed[1] ) ];
  98. }
  99.  
  100. parsed = jQuery.buildFragment( [ data ], context, scripts );
  101. if ( scripts ) {
  102. jQuery( scripts ).remove();
  103. }
  104. return jQuery.merge( [], parsed.childNodes );
  105. },
  106.  
  107. parseJSON: function( data ) {
  108. // Attempt to parse using the native JSON parser first
  109. if ( window.JSON && window.JSON.parse ) {
  110. return window.JSON.parse( data );
  111. }
  112.  
  113. if ( data === null ) {
  114. return data;
  115. }
  116.  
  117. if ( typeof data === "string" ) {
  118.  
  119. // Make sure leading/trailing whitespace is removed (IE can't handle it)
  120. data = jQuery.trim( data );
  121.  
  122. if ( data ) {
  123. // Make sure the incoming data is actual JSON
  124. // Logic borrowed from http://json.org/json2.js
  125. if ( rvalidchars.test( data.replace( rvalidescape, "@" )
  126. .replace( rvalidtokens, "]" )
  127. .replace( rvalidbraces, "")) ) {
  128.  
  129. return ( new Function( "return " + data ) )();
  130. }
  131. }
  132. }
  133.  
  134. jQuery.error( "Invalid JSON: " + data );
  135. },
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement