unique-id.js 979 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*!
  2. * jQuery UI Unique ID 1.14.1
  3. * https://jqueryui.com
  4. *
  5. * Copyright OpenJS Foundation and other contributors
  6. * Released under the MIT license.
  7. * https://jquery.org/license
  8. */
  9. //>>label: uniqueId
  10. //>>group: Core
  11. //>>description: Functions to generate and remove uniqueId's
  12. //>>docs: https://api.jqueryui.com/uniqueId/
  13. ( function( factory ) {
  14. "use strict";
  15. if ( typeof define === "function" && define.amd ) {
  16. // AMD. Register as an anonymous module.
  17. define( [ "jquery", "./version" ], factory );
  18. } else {
  19. // Browser globals
  20. factory( jQuery );
  21. }
  22. } )( function( $ ) {
  23. "use strict";
  24. return $.fn.extend( {
  25. uniqueId: ( function() {
  26. var uuid = 0;
  27. return function() {
  28. return this.each( function() {
  29. if ( !this.id ) {
  30. this.id = "ui-id-" + ( ++uuid );
  31. }
  32. } );
  33. };
  34. } )(),
  35. removeUniqueId: function() {
  36. return this.each( function() {
  37. if ( /^ui-id-\d+$/.test( this.id ) ) {
  38. $( this ).removeAttr( "id" );
  39. }
  40. } );
  41. }
  42. } );
  43. } );