From 736e7e843afd6654dbf287334db3d135f7376633 Mon Sep 17 00:00:00 2001 From: Timo Tijhof Date: Thu, 18 Jul 2013 02:47:55 +0200 Subject: [PATCH] mediawiki.page.ready: Use wikipage.content instead of domready 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 | 2 + maintenance/jsduck/config.json | 1 + .../mediawiki.page/mediawiki.page.ready.js | 38 ++++++++++++------- .../mediawiki.page/mediawiki.page.startup.js | 5 +++ resources/mediawiki/mediawiki.js | 3 ++ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 0b1cc17953..1d5ccaee43 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -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 diff --git a/maintenance/jsduck/config.json b/maintenance/jsduck/config.json index 6d97900329..5cce68d962 100644 --- a/maintenance/jsduck/config.json +++ b/maintenance/jsduck/config.json @@ -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" ] diff --git a/resources/mediawiki.page/mediawiki.page.ready.js b/resources/mediawiki.page/mediawiki.page.ready.js index 684f582f2f..ee416d67e8 100644 --- a/resources/mediawiki.page/mediawiki.page.ready.js +++ b/resources/mediawiki.page/mediawiki.page.ready.js @@ -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 ) ); diff --git a/resources/mediawiki.page/mediawiki.page.startup.js b/resources/mediawiki.page/mediawiki.page.startup.js index 1337576135..7457e8f5e5 100644 --- a/resources/mediawiki.page/mediawiki.page.startup.js +++ b/resources/mediawiki.page/mediawiki.page.startup.js @@ -16,6 +16,11 @@ // 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' ) ); } ); diff --git a/resources/mediawiki/mediawiki.js b/resources/mediawiki/mediawiki.js index e36d9d093d..46b74f1daf 100644 --- a/resources/mediawiki/mediawiki.js +++ b/resources/mediawiki/mediawiki.js @@ -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 () { -- 2.20.1