jquery.spin.js 1.7 KB

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