Merge "TableDiffFormatter: Don't repeatedly call array_shift()"
[lhc/web/wiklou.git] / resources / src / mediawiki / page / ready.js
1 ( function ( mw, $ ) {
2 var supportsPlaceholder = 'placeholder' in document.createElement( 'input' );
3
4 // Break out of framesets
5 if ( mw.config.get( 'wgBreakFrames' ) ) {
6 // Note: In IE < 9 strict comparison to window is non-standard (the standard didn't exist yet)
7 // it works only comparing to window.self or window.window (http://stackoverflow.com/q/4850978/319266)
8 if ( window.top !== window.self ) {
9 // Un-trap us from framesets
10 window.top.location.href = location.href;
11 }
12 }
13
14 mw.hook( 'wikipage.content' ).add( function ( $content ) {
15 var $sortableTables;
16
17 // Run jquery.placeholder polyfill if placeholder is not supported
18 if ( !supportsPlaceholder ) {
19 $content.find( 'input[placeholder]' ).placeholder();
20 }
21
22 // Run jquery.makeCollapsible
23 $content.find( '.mw-collapsible' ).makeCollapsible();
24
25 // Lazy load jquery.tablesorter
26 $sortableTables = $content.find( 'table.sortable' );
27 if ( $sortableTables.length ) {
28 mw.loader.using( 'jquery.tablesorter', function () {
29 $sortableTables.tablesorter();
30 } );
31 }
32
33 // Run jquery.checkboxShiftClick
34 $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ).checkboxShiftClick();
35 } );
36
37 // Things outside the wikipage content
38 $( function () {
39 var $nodes, $oouiNodes;
40
41 if ( !supportsPlaceholder ) {
42 // Exclude content to avoid hitting it twice for the (first) wikipage content
43 $( 'input[placeholder]' ).not( '#mw-content-text input' ).placeholder();
44 }
45
46 // Add accesskey hints to the tooltips
47 if ( document.querySelectorAll ) {
48 // If we're running on a browser where we can do this efficiently,
49 // just find all elements that have accesskeys. We can't use jQuery's
50 // polyfill for the selector since looping over all elements on page
51 // load might be too slow.
52 $nodes = $( document.querySelectorAll( '[accesskey]' ) );
53 } else {
54 // Otherwise go through some elements likely to have accesskeys rather
55 // than looping over all of them. Unfortunately this will not fully
56 // work for custom skins with different HTML structures. Input, label
57 // and button should be rare enough that no optimizations are needed.
58 $nodes = $( '#column-one a, #mw-head a, #mw-panel a, #p-logo a, input, label, button' );
59 }
60 $nodes.updateTooltipAccessKeys();
61
62 // Infuse OOUI widgets, if any are present
63 $oouiNodes = $( '[data-ooui]' );
64 if ( $oouiNodes.length ) {
65 // FIXME: We should only load the widgets that are being infused
66 mw.loader.using( [
67 'mediawiki.widgets',
68 'mediawiki.widgets.UserInputWidget',
69 'mediawiki.widgets.SearchInputWidget'
70 ] ).done( function () {
71 $oouiNodes.each( function () {
72 OO.ui.infuse( this );
73 } );
74 } );
75 }
76
77 $nodes = $( '.catlinks[data-mw="interface"]' );
78 if ( $nodes.length ) {
79 /**
80 * Fired when categories are being added to the DOM
81 *
82 * It is encouraged to fire it before the main DOM is changed (when $content
83 * is still detached). However, this order is not defined either way, so you
84 * should only rely on $content itself.
85 *
86 * This includes the ready event on a page load (including post-edit loads)
87 * and when content has been previewed with LivePreview.
88 *
89 * @event wikipage_categories
90 * @member mw.hook
91 * @param {jQuery} $content The most appropriate element containing the content,
92 * such as .catlinks
93 */
94 mw.hook( 'wikipage.categories' ).fire( $nodes );
95 }
96 } );
97
98 }( mediaWiki, jQuery ) );