Merge "Fix call to function applyPatch in MysqlUpdater"
[lhc/web/wiklou.git] / resources / jquery / jquery.spinner.js
1 /**
2 * jQuery Spinner
3 *
4 * Simple jQuery plugin to create, inject and remove spinners.
5 *
6 * @class jQuery.plugin.spinner
7 */
8 ( function ( $ ) {
9
10 // Default options for new spinners,
11 // stored outside the function to share between calls.
12 var defaults = {
13 id: undefined,
14 size: 'small',
15 type: 'inline'
16 };
17
18 $.extend({
19 /**
20 * Create a spinner element
21 *
22 * The argument is an object with options used to construct the spinner. These can be:
23 *
24 * It is a good practice to keep a reference to the created spinner to be able to remove it later.
25 * Alternatively one can use the id option and #removeSpinner (but make sure to choose an id
26 * that's unlikely to cause conflicts, e.g. with extensions, gadgets or user scripts).
27 *
28 * CSS classes used:
29 * - .mw-spinner for every spinner
30 * - .mw-spinner-small / .mw-spinner-large for size
31 * - .mw-spinner-block / .mw-spinner-inline for display types
32 *
33 * // Create a large spinner reserving all available horizontal space.
34 * var $spinner = $.createSpinner({ size: 'large', type: 'block' });
35 * // Insert above page content.
36 * $( '#mw-content-text' ).prepend( $spinner );
37 *
38 * // Place a small inline spinner next to the "Save" button
39 * var $spinner = $.createSpinner({ size: 'small', type: 'inline' });
40 * // Alternatively, just `$.createSpinner();` as these are the default options.
41 * $( '#wpSave' ).after( $spinner );
42 *
43 * // The following two are equivalent:
44 * $.createSpinner( 'magic' );
45 * $.createSpinner({ id: 'magic' });
46 *
47 * @static
48 * @inheritable
49 * @param {Object|string} [opts] ID string or options:
50 * - id: If given, spinner will be given an id of "mw-spinner-{id}"
51 * - size: 'small' (default) or 'large' for a 20-pixel or 32-pixel spinner
52 * - type: 'inline' (default) or 'block'. Inline creates an inline-block with width and
53 * height equal to spinner size. Block is a block-level element with width 100%, height
54 * equal to spinner size.
55 * @return {jQuery}
56 */
57 createSpinner: function ( opts ) {
58 if ( opts !== undefined && $.type( opts ) !== 'object' ) {
59 opts = {
60 id: opts
61 };
62 }
63
64 opts = $.extend( {}, defaults, opts );
65
66 var $spinner = $( '<div>', { 'class': 'mw-spinner', 'title': '...' } );
67 if ( opts.id !== undefined ) {
68 $spinner.attr( 'id', 'mw-spinner-' + opts.id );
69 }
70
71 $spinner.addClass( opts.size === 'large' ? 'mw-spinner-large' : 'mw-spinner-small' );
72 $spinner.addClass( opts.type === 'block' ? 'mw-spinner-block' : 'mw-spinner-inline' );
73
74 return $spinner;
75 },
76
77 /**
78 * Remove a spinner element
79 *
80 * @static
81 * @inheritable
82 * @param {string} id Id of the spinner, as passed to #createSpinner
83 * @return {jQuery} The (now detached) spinner element
84 */
85 removeSpinner: function ( id ) {
86 return $( '#mw-spinner-' + id ).remove();
87 }
88 });
89
90 /**
91 * Inject a spinner after each element in the collection
92 *
93 * Inserts spinner as siblings, not children, of the target elements.
94 * Collection contents remain unchanged.
95 *
96 * @param {Object|string} [opts] See #createSpinner
97 * @return {jQuery}
98 */
99 $.fn.injectSpinner = function ( opts ) {
100 return this.after( $.createSpinner( opts ) );
101 };
102
103 /**
104 * @class jQuery
105 * @mixins jQuery.plugin.spinner
106 */
107
108 }( jQuery ) );