Merge "Vector: Update comments in vector.js"
[mediawiki.git] / skins / common / wikibits.js
blobfdfca0afe3118138a63b500cc6289e9f1ab514f7
1 /**
2  * MediaWiki legacy wikibits
3  */
4 ( function ( mw, $ ) {
5         var msg,
6                 win = window,
7                 ua = navigator.userAgent.toLowerCase(),
8                 isIE6 = ( /msie ([0-9]{1,}[\.0-9]{0,})/.exec( ua ) && parseFloat( RegExp.$1 ) <= 6.0 ),
9                 onloadFuncts = [];
11 if ( mw.config.get( 'wgBreakFrames' ) ) {
12         // Note: In IE < 9 strict comparison to window is non-standard (the standard didn't exist yet)
13         // it works only comparing to window.self or window.window (http://stackoverflow.com/q/4850978/319266)
14         if ( win.top !== win.self ) {
15                 // Un-trap us from framesets
16                 win.top.location = win.location;
17         }
20 /**
21  * User-agent sniffing.
22  *
23  * @deprecated since 1.17 Use jquery.client instead
24  */
26 msg = 'Use feature detection or module jquery.client instead.';
28 mw.log.deprecate( win, 'clientPC', ua, msg );
30 // Ignored dummy values
31 mw.log.deprecate( win, 'is_gecko', false, msg );
32 mw.log.deprecate( win, 'is_chrome_mac', false, msg );
33 mw.log.deprecate( win, 'is_chrome', false, msg );
34 mw.log.deprecate( win, 'webkit_version', false, msg );
35 mw.log.deprecate( win, 'is_safari_win', false, msg );
36 mw.log.deprecate( win, 'is_safari', false, msg );
37 mw.log.deprecate( win, 'webkit_match', false, msg );
38 mw.log.deprecate( win, 'is_ff2', false, msg );
39 mw.log.deprecate( win, 'ff2_bugs', false, msg );
40 mw.log.deprecate( win, 'is_ff2_win', false, msg );
41 mw.log.deprecate( win, 'is_ff2_x11', false, msg );
42 mw.log.deprecate( win, 'opera95_bugs', false, msg );
43 mw.log.deprecate( win, 'opera7_bugs', false, msg );
44 mw.log.deprecate( win, 'opera6_bugs', false, msg );
45 mw.log.deprecate( win, 'is_opera_95', false, msg );
46 mw.log.deprecate( win, 'is_opera_preseven', false, msg );
47 mw.log.deprecate( win, 'is_opera', false, msg );
48 mw.log.deprecate( win, 'ie6_bugs', false, msg );
50 /**
51  * DOM utilities for handling of events, text nodes and selecting elements
52  *
53  * @deprecated since 1.17 Use jQuery instead
54  */
55 msg = 'Use jQuery instead.';
57 // Ignored dummy values
58 mw.log.deprecate( win, 'doneOnloadHook', undefined, msg );
59 mw.log.deprecate( win, 'onloadFuncts', [], msg );
60 mw.log.deprecate( win, 'runOnloadHook', $.noop, msg );
61 mw.log.deprecate( win, 'changeText', $.noop, msg );
62 mw.log.deprecate( win, 'killEvt', $.noop, msg );
63 mw.log.deprecate( win, 'addHandler', $.noop, msg );
64 mw.log.deprecate( win, 'hookEvent', $.noop, msg );
65 mw.log.deprecate( win, 'addClickHandler', $.noop, msg );
66 mw.log.deprecate( win, 'removeHandler', $.noop, msg );
67 mw.log.deprecate( win, 'getElementsByClassName', function () { return []; }, msg );
68 mw.log.deprecate( win, 'getInnerText', function () { return ''; }, msg );
70 // Run a function after the window onload event is fired
71 mw.log.deprecate( win, 'addOnloadHook', function ( hookFunct ) {
72         if ( onloadFuncts ) {
73                 onloadFuncts.push(hookFunct);
74         } else {
75                 // If func queue is gone the event has happened already,
76                 // run immediately instead of queueing.
77                 hookFunct();
78         }
79 }, msg );
81 $( win ).on( 'load', function () {
82         var i, functs;
84         // Don't run twice
85         if ( !onloadFuncts ) {
86                 return;
87         }
89         // Deference and clear onloadFuncts before running any
90         // hooks to make sure we don't miss any addOnloadHook
91         // calls.
92         functs = onloadFuncts.slice();
93         onloadFuncts = undefined;
95         // Execute the queued functions
96         for ( i = 0; i < functs.length; i++ ) {
97                 functs[i]();
98         }
99 } );
102  * Toggle checkboxes with shift selection
104  * @deprecated since 1.17 Use jquery.checkboxShiftClick instead
105  */
106 msg = 'Use jquery.checkboxShiftClick instead.';
107 mw.log.deprecate( win, 'checkboxes', [], msg );
108 mw.log.deprecate( win, 'lastCheckbox', null, msg );
109 mw.log.deprecate( win, 'setupCheckboxShiftClick', $.noop, msg );
110 mw.log.deprecate( win, 'addCheckboxClickHandlers', $.noop, msg );
111 mw.log.deprecate( win, 'checkboxClickHandler', $.noop, msg );
114  * Add a button to the default editor toolbar
116  * @deprecated since 1.17 Use mw.toolbar instead
117  */
118 mw.log.deprecate( win, 'mwEditButtons', [], 'Use mw.toolbar instead.' );
119 mw.log.deprecate( win, 'mwCustomEditButtons', [], 'Use mw.toolbar instead.' );
122  * Spinner creation, injection and removal
124  * @deprecated since 1.18 Use jquery.spinner instead
125  */
126 mw.log.deprecate( win, 'injectSpinner', $.noop, 'Use jquery.spinner instead.' );
127 mw.log.deprecate( win, 'removeSpinner', $.noop, 'Use jquery.spinner instead.' );
130  * Escape utilities
132  * @deprecated since 1.18 Use mw.html instead
133  */
134 mw.log.deprecate( win, 'escapeQuotes', $.noop, 'Use mw.html instead.' );
135 mw.log.deprecate( win, 'escapeQuotesHTML', $.noop, 'Use mw.html instead.' );
138  * Display a message to the user
140  * @deprecated since 1.17 Use mediawiki.notify instead
141  * @param {string|HTMLElement} message To be put inside the message box
142  */
143 mw.log.deprecate( win, 'jsMsg', function ( message ) {
144         if ( !arguments.length || message === '' || message === null ) {
145                 return true;
146         }
147         if ( typeof message !== 'object' ) {
148                 message = $.parseHTML( message );
149         }
150         mw.notify( message, { autoHide: true, tag: 'legacy' } );
151         return true;
152 }, 'Use mediawiki.notify instead.' );
155  * Misc. utilities
157  * @deprecated since 1.17 Use mediawiki.util instead
158  */
159 msg = 'Use mediawiki.util instead.';
160 mw.log.deprecate( win, 'updateTooltipAccessKeys', mw.util.updateTooltipAccessKeys, msg );
161 mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg );
162 mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg );
163 msg = 'Use jquery.accessKeyLabel instead.';
164 mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg );
165 mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg );
168  * Wikipage import methods
169  */
171 // included-scripts tracker
172 win.loadedScripts = {};
174 win.importScript = function ( page ) {
175         var uri = mw.config.get( 'wgScript' ) + '?title=' +
176                 mw.util.wikiUrlencode( page ) +
177                 '&action=raw&ctype=text/javascript';
178         return win.importScriptURI( uri );
181 win.importScriptURI = function ( url ) {
182         if ( win.loadedScripts[url] ) {
183                 return null;
184         }
185         win.loadedScripts[url] = true;
186         var s = document.createElement( 'script' );
187         s.setAttribute( 'src', url );
188         s.setAttribute( 'type', 'text/javascript' );
189         document.getElementsByTagName( 'head' )[0].appendChild( s );
190         return s;
193 win.importStylesheet = function ( page ) {
194         var uri = mw.config.get( 'wgScript' ) + '?title=' +
195                 mw.util.wikiUrlencode( page ) +
196                 '&action=raw&ctype=text/css';
197         return win.importStylesheetURI( uri );
200 win.importStylesheetURI = function ( url, media ) {
201         var l = document.createElement( 'link' );
202         l.rel = 'stylesheet';
203         l.href = url;
204         if ( media ) {
205                 l.media = media;
206         }
207         document.getElementsByTagName('head')[0].appendChild( l );
208         return l;
211 if ( isIE6 ) {
212         win.importScriptURI( mw.config.get( 'stylepath' ) + '/common/IEFixes.js' );
215 }( mediaWiki, jQuery ) );