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

access.js 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. define( [
  2. "../core",
  3. "../core/toType",
  4. "../var/isFunction"
  5. ], function( jQuery, toType, isFunction ) {
  6. "use strict";
  7. // Multifunctional method to get and set values of a collection
  8. // The value/s can optionally be executed if it's a function
  9. var access = function( elems, fn, key, value, chainable, emptyGet, raw ) {
  10. var i = 0,
  11. len = elems.length,
  12. bulk = key == null;
  13. // Sets many values
  14. if ( toType( key ) === "object" ) {
  15. chainable = true;
  16. for ( i in key ) {
  17. access( elems, fn, i, key[ i ], true, emptyGet, raw );
  18. }
  19. // Sets one value
  20. } else if ( value !== undefined ) {
  21. chainable = true;
  22. if ( !isFunction( value ) ) {
  23. raw = true;
  24. }
  25. if ( bulk ) {
  26. // Bulk operations run against the entire set
  27. if ( raw ) {
  28. fn.call( elems, value );
  29. fn = null;
  30. // ...except when executing function values
  31. } else {
  32. bulk = fn;
  33. fn = function( elem, key, value ) {
  34. return bulk.call( jQuery( elem ), value );
  35. };
  36. }
  37. }
  38. if ( fn ) {
  39. for ( ; i < len; i++ ) {
  40. fn(
  41. elems[ i ], key, raw ?
  42. value :
  43. value.call( elems[ i ], i, fn( elems[ i ], key ) )
  44. );
  45. }
  46. }
  47. }
  48. if ( chainable ) {
  49. return elems;
  50. }
  51. // Gets
  52. if ( bulk ) {
  53. return fn.call( elems );
  54. }
  55. return len ? fn( elems[ 0 ], key ) : emptyGet;
  56. };
  57. return access;
  58. } );