Merge "Update docs/hooks.txt for ShowSearchHitTitle"
[mediawiki.git] / resources / src / mediawiki / page / ready.js
blobd228f3e302255878eca07f358ad20e971df7cc15
1 ( function ( mw, $ ) {
2         var supportsPlaceholder = 'placeholder' in document.createElement( 'input' );
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         }
14         mw.hook( 'wikipage.content' ).add( function ( $content ) {
15                 var $sortableTables;
17                 // Run jquery.placeholder polyfill if placeholder is not supported
18                 if ( !supportsPlaceholder ) {
19                         $content.find( 'input[placeholder]' ).placeholder();
20                 }
22                 // Run jquery.makeCollapsible
23                 $content.find( '.mw-collapsible' ).makeCollapsible();
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                 }
33                 // Run jquery.checkboxShiftClick
34                 $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ).checkboxShiftClick();
35         } );
37         // Things outside the wikipage content
38         $( function () {
39                 var $nodes;
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                 }
46                 // Add accesskey hints to the tooltips
47                 $( '[accesskey]' ).updateTooltipAccessKeys();
49                 $nodes = $( '.catlinks[data-mw="interface"]' );
50                 if ( $nodes.length ) {
51                         /**
52                          * Fired when categories are being added to the DOM
53                          *
54                          * It is encouraged to fire it before the main DOM is changed (when $content
55                          * is still detached).  However, this order is not defined either way, so you
56                          * should only rely on $content itself.
57                          *
58                          * This includes the ready event on a page load (including post-edit loads)
59                          * and when content has been previewed with LivePreview.
60                          *
61                          * @event wikipage_categories
62                          * @member mw.hook
63                          * @param {jQuery} $content The most appropriate element containing the content,
64                          *   such as .catlinks
65                          */
66                         mw.hook( 'wikipage.categories' ).fire( $nodes );
67                 }
68         } );
70 }( mediaWiki, jQuery ) );