Repositorio del curso CCOM4030 el semestre B91 del proyecto Artesanías con el Instituto de Cultura

init.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Initialize a jQuery object
  2. define( [
  3. "../core",
  4. "../var/document",
  5. "../var/isFunction",
  6. "./var/rsingleTag",
  7. "../traversing/findFilter"
  8. ], function( jQuery, document, isFunction, rsingleTag ) {
  9. "use strict";
  10. // A central reference to the root jQuery(document)
  11. var rootjQuery,
  12. // A simple way to check for HTML strings
  13. // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
  14. // Strict HTML recognition (#11290: must start with <)
  15. // Shortcut simple #id case for speed
  16. rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]+))$/,
  17. init = jQuery.fn.init = function( selector, context, root ) {
  18. var match, elem;
  19. // HANDLE: $(""), $(null), $(undefined), $(false)
  20. if ( !selector ) {
  21. return this;
  22. }
  23. // Method init() accepts an alternate rootjQuery
  24. // so migrate can support jQuery.sub (gh-2101)
  25. root = root || rootjQuery;
  26. // Handle HTML strings
  27. if ( typeof selector === "string" ) {
  28. if ( selector[ 0 ] === "<" &&
  29. selector[ selector.length - 1 ] === ">" &&
  30. selector.length >= 3 ) {
  31. // Assume that strings that start and end with <> are HTML and skip the regex check
  32. match = [ null, selector, null ];
  33. } else {
  34. match = rquickExpr.exec( selector );
  35. }
  36. // Match html or make sure no context is specified for #id
  37. if ( match && ( match[ 1 ] || !context ) ) {
  38. // HANDLE: $(html) -> $(array)
  39. if ( match[ 1 ] ) {
  40. context = context instanceof jQuery ? context[ 0 ] : context;
  41. // Option to run scripts is true for back-compat
  42. // Intentionally let the error be thrown if parseHTML is not present
  43. jQuery.merge( this, jQuery.parseHTML(
  44. match[ 1 ],
  45. context && context.nodeType ? context.ownerDocument || context : document,
  46. true
  47. ) );
  48. // HANDLE: $(html, props)
  49. if ( rsingleTag.test( match[ 1 ] ) && jQuery.isPlainObject( context ) ) {
  50. for ( match in context ) {
  51. // Properties of context are called as methods if possible
  52. if ( isFunction( this[ match ] ) ) {
  53. this[ match ]( context[ match ] );
  54. // ...and otherwise set as attributes
  55. } else {
  56. this.attr( match, context[ match ] );
  57. }
  58. }
  59. }
  60. return this;
  61. // HANDLE: $(#id)
  62. } else {
  63. elem = document.getElementById( match[ 2 ] );
  64. if ( elem ) {
  65. // Inject the element directly into the jQuery object
  66. this[ 0 ] = elem;
  67. this.length = 1;
  68. }
  69. return this;
  70. }
  71. // HANDLE: $(expr, $(...))
  72. } else if ( !context || context.jquery ) {
  73. return ( context || root ).find( selector );
  74. // HANDLE: $(expr, context)
  75. // (which is just equivalent to: $(context).find(expr)
  76. } else {
  77. return this.constructor( context ).find( selector );
  78. }
  79. // HANDLE: $(DOMElement)
  80. } else if ( selector.nodeType ) {
  81. this[ 0 ] = selector;
  82. this.length = 1;
  83. return this;
  84. // HANDLE: $(function)
  85. // Shortcut for document ready
  86. } else if ( isFunction( selector ) ) {
  87. return root.ready !== undefined ?
  88. root.ready( selector ) :
  89. // Execute immediately if ready is not present
  90. selector( jQuery );
  91. }
  92. return jQuery.makeArray( selector, this );
  93. };
  94. // Give the init function the jQuery prototype for later instantiation
  95. init.prototype = jQuery.fn;
  96. // Initialize central reference
  97. rootjQuery = jQuery( document );
  98. return init;
  99. } );