UNPKG

2.37 kBJavaScriptView Raw
1import $ from './jquery';
2import './spinner';
3import skate from './internal/skate';
4import { fn } from './internal/deprecation';
5
6/**
7 * @typedef {Object} jQuerySpinnerConfig
8 * @property {SpinnerSize} size - the size of the spinner.
9 */
10
11/**
12 * @param {jQuerySpinnerConfig|String|Boolean} [firstArgs]
13 * - when an object, it is a {jQuerySpinnerConfig}
14 * - when a string, it represents the `size` the spinner should take.
15 * - when boolean, the argument can take only FALSE, in this case, the spinner will be stopped.
16 * @param {jQuerySpinnerConfig} [maybeArgs]
17 * @deprecated since AUI 7.9.4. Use the `<aui-spinner>` web component directly.
18 */
19$.fn.spin = fn(function spinStart(firstArgs, maybeArgs) {
20 let args = { size: 'small' };
21 if (typeof maybeArgs === 'object') {
22 args = $.extend(args, maybeArgs)
23 }
24 if (typeof firstArgs === 'object') {
25 args = $.extend(args, firstArgs);
26 }
27 if (typeof firstArgs === 'string') {
28 args.size = firstArgs;
29 }
30 if (typeof firstArgs === 'boolean' && firstArgs === false) {
31 return this.spinStop();
32 }
33
34 return this.each(function() {
35 if (!this || !this.nodeType) { return; }
36 const $this = $(this);
37 const data = $this.data();
38 if (data) {
39 const $spinnerDom = $('<aui-spinner filled></aui-spinner>');
40 $spinnerDom.attr('size', args.size); // the web component handles validation
41 $spinnerDom.css('color', args.color);
42
43 $this.spinStop();
44 $this.append($spinnerDom);
45 // AUI-4819 - ensure web component is initialised synchronously.
46 skate.init(this);
47
48 data.spinner = $spinnerDom;
49 }
50 });
51}, 'jQuery.fn.spin', {
52 sinceVersion: '7.9.4',
53 removeInVersion: '10.0.0',
54 alternativeName: '<aui-spinner>'
55});
56
57/**
58 * @deprecated since AUI 7.9.4. Use the `<aui-spinner>` web component directly.
59 */
60$.fn.spinStop = fn(function spinStop() {
61 return this.each(function() {
62 if (!this || !this.nodeType) { return; }
63 const $this = $(this);
64 const data = $this.data();
65 if (data && data.spinner) {
66 data.spinner.remove();
67
68 delete data.spinner;
69 }
70 });
71}, 'jQuery.fn.spinStop', {
72 sinceVersion: '7.9.4',
73 removeInVersion: '10.0.0',
74 alternativeName: '<aui-spinner>'
75});