mediawiki.page.ready: Use wikipage.content instead of domready
authorTimo Tijhof <krinklemail@gmail.com>
Thu, 18 Jul 2013 00:47:55 +0000 (02:47 +0200)
committerTimo Tijhof <krinklemail@gmail.com>
Fri, 26 Jul 2013 00:08:23 +0000 (02:08 +0200)
Restructure mediawiki.page.ready to add to the "wikipage.content"
hook instead of using document-ready.

Except for parts that aren't inside the wikipage content.
Portlet links are outside content entirely and should run only
once from document-ready still. Inputs with placeholders can be
both inside and outside (inside with e.g. InputBox extension,
outside in e.g. search bar of skin) so it needs to be in both.
The one in document-ready needs to exclude ones in content to
avoid applying the placeholder polyfill twice.

This also opens up the doors for extensions and gadgets to
reliably both fire and add to this hook:
- Code can fire this hook when rendering a new DOM (such as
  LivePreview, VisualEditor, ..).
- Code can add to this hook to enhance page content and have it
  properly re-run when there is a new DOM (e.g. gadgets like
  Navigation popups, Reference Tooltips, ..).

Also added release notes for 2e97025.

Bug: 30713
Bug: 33399
Bug: 51565
Change-Id: Icb0eda9edf2aeb3d612ff1d9bfea4859d33e1fbb

RELEASE-NOTES-1.22
maintenance/jsduck/config.json
resources/mediawiki.page/mediawiki.page.ready.js
resources/mediawiki.page/mediawiki.page.startup.js
resources/mediawiki/mediawiki.js

index 0b1cc17..1d5ccae 100644 (file)
@@ -158,6 +158,8 @@ production.
   titles. Given a list of articles named Bug1, Bug2, you can now transclude the
   list of bug numbers using: {{Special:PrefixIndex/Bug|stripprefix=1}}.
   The special page form received a new checkbox matching that option.
+* (bug 23580) Implement javascript callback interface "mw.hook".
+* (bug 30713) New mw.hook "wikipage.content".
 
 === Bug fixes in 1.22 ===
 * Disable Special:PasswordReset when $wgEnableEmail is false. Previously one
index 6d97900..5cce68d 100644 (file)
@@ -18,6 +18,7 @@
                "../../resources/mediawiki/mediawiki.user.js",
                "../../resources/mediawiki.action/mediawiki.action.edit.js",
                "../../resources/mediawiki.action/mediawiki.action.view.postEdit.js",
+               "../../resources/mediawiki.page/mediawiki.page.startup.js",
                "../../resources/mediawiki.api",
                "../../resources/jquery/jquery.localize.js"
        ]
index 684f582..ee416d6 100644 (file)
@@ -1,28 +1,40 @@
-( function ( mw, $ ) {
-       $( function () {
+( function ( mw , $ ) {
+       var supportsPlaceholder = 'placeholder' in document.createElement( 'input' );
+
+       mw.hook( 'wikipage.content' ).add( function ( $content ) {
                var $sortableTables;
 
-               /* Emulate placeholder if not supported by browser */
-               if ( !( 'placeholder' in document.createElement( 'input' ) ) ) {
-                       $( 'input[placeholder]' ).placeholder();
+               // Run jquery.placeholder polyfill if placeholder is not supported
+               if ( !supportsPlaceholder ) {
+                       $content.find( 'input[placeholder]' ).placeholder();
                }
 
-               /* Enable makeCollapsible */
-               $( '.mw-collapsible' ).makeCollapsible();
+               // Run jquery.makeCollapsible
+               $content.find( '.mw-collapsible' ).makeCollapsible();
 
-               /* Lazy load jquery.tablesorter */
-               $sortableTables = $( 'table.sortable' );
+               // Lazy load jquery.tablesorter
+               $sortableTables = $content.find( 'table.sortable' );
                if ( $sortableTables.length ) {
                        mw.loader.using( 'jquery.tablesorter', function () {
                                $sortableTables.tablesorter();
-                       });
+                       } );
                }
 
-               /* Enable CheckboxShiftClick */
-               $( 'input[type=checkbox]:not(.noshiftselect)' ).checkboxShiftClick();
+               // Run jquery.checkboxShiftClick
+               $content.find( 'input[type="checkbox"]:not(.noshiftselect)' ).checkboxShiftClick();
+       } );
+
+       // Things outside the wikipage content
+       $( function () {
+
+               if ( !supportsPlaceholder ) {
+                       // Exclude content to avoid hitting it twice for the (first) wikipage content
+                       $( 'input[placeholder]' ).not( '#mw-content-text input' ).placeholder();
+               }
 
-               /* Add accesskey hints to the tooltips */
+               // Add accesskey hints to the tooltips
                mw.util.updateTooltipAccessKeys();
 
        } );
+
 }( mediaWiki, jQuery ) );
index 1337576..7457e8f 100644 (file)
                // mw.util.init), is defined for them.
                mw.util.init();
 
+               /**
+                * @event wikpage_content
+                * @member mw.hook
+                * @param {jQuery} $content
+                */
                mw.hook( 'wikipage.content' ).fire( $( '#mw-content-text' ) );
        } );
 
index e36d9d0..46b74f1 100644 (file)
@@ -1839,6 +1839,9 @@ var mw = ( function ( $, undefined ) {
                 *     var h = mw.hook( 'bar.ready' );
                 *     new mw.Foo( .. ).fetch( { callback: h.fire } );
                 *
+                * Note: Events are documented with an underscore instead of a dot in the event
+                * name due to jsduck not supporting dots in that position.
+                *
                 * @class mw.hook
                 */
                hook: ( function () {