Throbber.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * Throbber.js
  3. *
  4. * Copyright, Moxiecode Systems AB
  5. * Released under LGPL License.
  6. *
  7. * License: http://www.tinymce.com/license
  8. * Contributing: http://www.tinymce.com/contributing
  9. */
  10. /**
  11. * This class enables you to display a Throbber for any element.
  12. *
  13. * @-x-less Throbber.less
  14. * @class tinymce.ui.Throbber
  15. */
  16. define("tinymce/ui/Throbber", [
  17. "tinymce/ui/DomUtils",
  18. "tinymce/ui/Control"
  19. ], function(DomUtils, Control) {
  20. "use strict";
  21. /**
  22. * Constructs a new throbber.
  23. *
  24. * @constructor
  25. * @param {Element} elm DOM Html element to display throbber in.
  26. * @param {Boolean} inline Optional true/false state if the throbber should be appended to end of element for infinite scroll.
  27. */
  28. return function(elm, inline) {
  29. var self = this, state, classPrefix = Control.classPrefix;
  30. /**
  31. * Shows the throbber.
  32. *
  33. * @method show
  34. * @param {Number} [time] Time to wait before showing.
  35. * @return {tinymce.ui.Throbber} Current throbber instance.
  36. */
  37. self.show = function(time) {
  38. self.hide();
  39. state = true;
  40. window.setTimeout(function() {
  41. if (state) {
  42. elm.appendChild(DomUtils.createFragment(
  43. '<div class="' + classPrefix + 'throbber' + (inline ? ' ' + classPrefix + 'throbber-inline' : '') + '"></div>'
  44. ));
  45. }
  46. }, time || 0);
  47. return self;
  48. };
  49. /**
  50. * Hides the throbber.
  51. *
  52. * @method hide
  53. * @return {tinymce.ui.Throbber} Current throbber instance.
  54. */
  55. self.hide = function() {
  56. var child = elm.lastChild;
  57. if (child && child.className.indexOf('throbber') != -1) {
  58. child.parentNode.removeChild(child);
  59. }
  60. state = false;
  61. return self;
  62. };
  63. };
  64. });