jquery.spin.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * Copyright (c) 2011-2014 Felix Gnass
  3. * Licensed under the MIT license
  4. */
  5. /*
  6. Basic Usage:
  7. ============
  8. $('#el').spin(); // Creates a default Spinner using the text color of #el.
  9. $('#el').spin({ ... }); // Creates a Spinner using the provided options.
  10. $('#el').spin(false); // Stops and removes the spinner.
  11. Using Presets:
  12. ==============
  13. $('#el').spin('small'); // Creates a 'small' Spinner using the text color of #el.
  14. $('#el').spin('large', '#fff'); // Creates a 'large' white Spinner.
  15. Adding a custom preset:
  16. =======================
  17. $.fn.spin.presets.flower = {
  18. lines: 9,
  19. length: 10,
  20. width: 20,
  21. radius: 0
  22. }
  23. $('#el').spin('flower', 'red');
  24. */
  25. (function(factory) {
  26. if (typeof exports == 'object') {
  27. // CommonJS
  28. factory(require('jquery'), require('spin.js'))
  29. }
  30. else if (typeof define == 'function' && define.amd) {
  31. // AMD, register as anonymous module
  32. define(['jquery', 'spin'], factory)
  33. }
  34. else {
  35. // Browser globals
  36. if (!window.Spinner) throw new Error('Spin.js not present')
  37. factory(window.jQuery, window.Spinner)
  38. }
  39. }(function($, Spinner) {
  40. $.fn.spin = function(opts, color) {
  41. return this.each(function() {
  42. var $this = $(this),
  43. data = $this.data();
  44. if (data.spinner) {
  45. data.spinner.stop();
  46. delete data.spinner;
  47. }
  48. if (opts !== false) {
  49. opts = $.extend(
  50. { color: color || $this.css('color') },
  51. $.fn.spin.presets[opts] || opts
  52. )
  53. data.spinner = new Spinner(opts).spin(this)
  54. }
  55. })
  56. }
  57. $.fn.spin.presets = {
  58. tiny: { lines: 8, length: 2, width: 2, radius: 3 },
  59. small: { lines: 8, length: 4, width: 3, radius: 5 },
  60. large: { lines: 10, length: 8, width: 4, radius: 8 }
  61. }
  62. }));