Krinkle has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/74313


Change subject: mediawiki.page.ready: Use wikipage.content instead of domready
......................................................................

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
---
M RELEASE-NOTES-1.22
M maintenance/jsduck/config.json
M resources/mediawiki.page/mediawiki.page.ready.js
M resources/mediawiki.page/mediawiki.page.startup.js
M resources/mediawiki/mediawiki.js
5 files changed, 36 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/13/74313/1

diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22
index 8ed4622..bcead8a 100644
--- a/RELEASE-NOTES-1.22
+++ b/RELEASE-NOTES-1.22
@@ -149,6 +149,8 @@
   right?" check is used to avoid more expensive checks.
 * Display "(No difference)" instead of an empty diff (when comparing revisions
   in the history or when previewing changes while editing).
+* (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 6d97900..5cce68d 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 684f582..5517492 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 supportPlaceholder = '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 ( !supportPlaceholder ) {
+                       $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();
+       } );
 
-               /* Add accesskey hints to the tooltips */
+       // Things outside the wikipage content
+       $( function () {
+
+               if ( !supportPlaceholder ) {
+                       // 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
                mw.util.updateTooltipAccessKeys();
 
        } );
+
 }( mediaWiki, jQuery ) );
diff --git a/resources/mediawiki.page/mediawiki.page.startup.js 
b/resources/mediawiki.page/mediawiki.page.startup.js
index f0b38c6..c264abd 100644
--- a/resources/mediawiki.page/mediawiki.page.startup.js
+++ b/resources/mediawiki.page/mediawiki.page.startup.js
@@ -13,6 +13,11 @@
                // messageBoxNew, profile, tooltip access keys, Table of 
contents toggle, ..).
                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 e36d9d0..46b74f1 100644
--- a/resources/mediawiki/mediawiki.js
+++ b/resources/mediawiki/mediawiki.js
@@ -1839,6 +1839,9 @@
                 *     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 () {

-- 
To view, visit https://gerrit.wikimedia.org/r/74313
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Icb0eda9edf2aeb3d612ff1d9bfea4859d33e1fbb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to