jenkins-bot has submitted this change and it was merged.

Change subject: mw.ViewPageTarget.init: Move edit section to top init
......................................................................


mw.ViewPageTarget.init: Move edit section to top init

Since we're now only loading the light-weight init on page load,
the section editing wasn't just deferred to after page load (like
it was before), but wasn't happening at all until you clicked
"Edit" (at which point the library loads). It only worked when
going back to "View" after "Edit".

Contrary to tab layout, edit section handling needs to be
accessible both in the top init and in the main target class
because we need to run it both at run time and after the user
has saved a page when we show them the updated page without
refresh. This is why we need to transfer the method at run time
and give the main class access to it as well.
Can't wait for bug 50707 to get rid of this mess...

Bug: 50731
Bug: 49993
Change-Id: Iab9c81222df7f1084179c3643d158374a89ca14b
---
M VisualEditor.php
M modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.css
A modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.init.css
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js
M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
5 files changed, 182 insertions(+), 170 deletions(-)

Approvals:
  Catrope: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/VisualEditor.php b/VisualEditor.php
index 3348972..f107715 100644
--- a/VisualEditor.php
+++ b/VisualEditor.php
@@ -153,22 +153,23 @@
                ),
        ),
        'ext.visualEditor.viewPageTarget.init' => 
$wgVisualEditorResourceTemplate + array(
-               'scripts' => array(
-                       've-mw/init/targets/ve.init.mw.ViewPageTarget.init.js',
-               ),
+               'scripts' => 
've-mw/init/targets/ve.init.mw.ViewPageTarget.init.js',
+               'styles' => 
've-mw/init/styles/ve.init.mw.ViewPageTarget.init.css',
                'dependencies' => array(
                        'jquery.client',
                        'mediawiki.Uri',
                        'mediawiki.util',
                ),
                'messages' => array(
-                       'accesskey-ca-ve-edit',
                        'accesskey-ca-editsource',
+                       'accesskey-ca-ve-edit',
+                       'pipe-separator',
                        'tooltip-ca-createsource',
                        'tooltip-ca-editsource',
                        'tooltip-ca-ve-edit',
                        'visualeditor-ca-createsource',
                        'visualeditor-ca-editsource',
+                       'visualeditor-ca-editsource-section',
                        'visualeditor-ca-ve-create',
                        'visualeditor-ca-ve-edit',
                ),
@@ -218,8 +219,6 @@
                        'editing',
 
                        // Messages needed by VE in init phase only (rest go 
below)
-                       'pipe-separator',
-                       'visualeditor-ca-editsource-section',
                        'visualeditor-loadwarning',
                        'visualeditor-loadwarning-token',
                        'visualeditor-notification-created',
diff --git a/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.css 
b/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.css
index afa3baf..4b67376 100644
--- a/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.css
+++ b/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.css
@@ -322,45 +322,6 @@
        outline: none;
 }
 
-/* Section edit links */
-
-.mw-editsection {
-       white-space: nowrap;
-       padding-right: 0.25em;
-       /* bidi isolation: */
-       unicode-bidi: -moz-isolate;
-       unicode-bidi: -webkit-isolate;
-       unicode-bidi: isolate;
-}
-
-.mw-editsection-divider {
-       color: #ccc;
-}
-
-.mw-editsection-bracket {
-       -webkit-transition: color 100ms ease-out, margin 100ms ease-out;
-       -moz-transition: color 100ms ease-out, margin 100ms ease-out;
-       -ms-transition: color 100ms ease-out, margin 100ms ease-out;
-       -o-transition: color 100ms ease-out, margin 100ms ease-out;
-       transition: color 100ms ease-out, margin 100ms ease-out;
-}
-
-/* @noflip */
-.mw-content-ltr .mw-editsection-expanded .mw-editsection-bracket:first-of-type,
-.mw-content-rtl .mw-editsection-expanded 
.mw-editsection-bracket:not(:first-of-type) {
-       margin-left: -0.25em;
-       margin-right: 0.25em;
-       color: #ccc;
-}
-
-/* @noflip */
-.mw-content-rtl .mw-editsection-expanded .mw-editsection-bracket:first-of-type,
-.mw-content-ltr .mw-editsection-expanded 
.mw-editsection-bracket:not(:first-of-type) {
-       margin-right: -0.25em;
-       margin-left: 0.25em;
-       color: #ccc;
-}
-
 /* Images */
 
 .ve-init-mw-viewPageTarget-loading,
diff --git a/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.init.css 
b/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.init.css
new file mode 100644
index 0000000..ac43b05
--- /dev/null
+++ b/modules/ve-mw/init/styles/ve.init.mw.ViewPageTarget.init.css
@@ -0,0 +1,45 @@
+/*!
+ * VisualEditor MediaWiki ViewPageTarget init styles.
+ *
+ * @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
+ * @license The MIT License (MIT); see LICENSE.txt
+ */
+
+/* Section edit links */
+
+.mw-editsection {
+       white-space: nowrap;
+       padding-right: 0.25em;
+       /* bidi isolation: */
+       unicode-bidi: -moz-isolate;
+       unicode-bidi: -webkit-isolate;
+       unicode-bidi: isolate;
+}
+
+.mw-editsection-divider {
+       color: #ccc;
+}
+
+.mw-editsection-bracket {
+       -webkit-transition: color 100ms ease-out, margin 100ms ease-out;
+       -moz-transition: color 100ms ease-out, margin 100ms ease-out;
+       -ms-transition: color 100ms ease-out, margin 100ms ease-out;
+       -o-transition: color 100ms ease-out, margin 100ms ease-out;
+       transition: color 100ms ease-out, margin 100ms ease-out;
+}
+
+/* @noflip */
+.mw-content-ltr .mw-editsection-expanded .mw-editsection-bracket:first-of-type,
+.mw-content-rtl .mw-editsection-expanded 
.mw-editsection-bracket:not(:first-of-type) {
+       margin-left: -0.25em;
+       margin-right: 0.25em;
+       color: #ccc;
+}
+
+/* @noflip */
+.mw-content-rtl .mw-editsection-expanded .mw-editsection-bracket:first-of-type,
+.mw-content-ltr .mw-editsection-expanded 
.mw-editsection-bracket:not(:first-of-type) {
+       margin-right: -0.25em;
+       margin-left: 0.25em;
+       color: #ccc;
+}
diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js 
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js
index 72512df..adf762a 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js
@@ -34,6 +34,10 @@
                                .done( function () {
                                        var target = new 
ve.init.mw.ViewPageTarget();
                                        ve.init.mw.targets.push( target );
+
+                                       // Transfer methods
+                                       
ve.init.mw.ViewPageTarget.prototype.setupSectionEditLinks = 
init.setupSectionEditLinks;
+
                                        getTargetDeferred.resolve( target );
                                } )
                                .fail( getTargetDeferred.reject );
@@ -93,6 +97,11 @@
                },
 
                skinSetup: function () {
+                       init.setupTabLayout();
+                       init.setupSectionEditLinks();
+               },
+
+               setupTabLayout: function () {
                        var caVeEdit, caVeEditSource,
                                action = pageExists ? 'edit' : 'create',
                                pTabsId = $( '#p-views' ).length ? 'p-views' : 
'p-cactions',
@@ -119,8 +128,8 @@
                                        // 2) when onEditTabClick is not bound 
(!isViewPage) it will
                                        // just work.
                                        veEditUri,
-                                       // visualeditor-ca-ve-edit
                                        // visualeditor-ca-ve-create
+                                       // visualeditor-ca-ve-edit
                                        mw.msg( 'visualeditor-ca-ve-' + action 
),
                                        'ca-ve-edit',
                                        mw.msg( 'tooltip-ca-ve-edit' ),
@@ -136,8 +145,8 @@
                                        pTabsId,
                                        // Use original href to preserve oldid 
etc. (bug 38125)
                                        $caEditLink.attr( 'href' ),
-                                       // visualeditor-ca-editsource
                                        // visualeditor-ca-createsource
+                                       // visualeditor-ca-editsource
                                        mw.msg( 'visualeditor-ca-' + action + 
'source' ),
                                        'ca-editsource',
                                        // tooltip-ca-editsource
@@ -169,23 +178,125 @@
 
                        if ( isViewPage ) {
                                // Allow instant switching to edit mode, 
without refresh
-                               $( caVeEdit ).click( function ( e ) {
-                                       // Default mouse button is normalised 
by jQuery to key code 1.
-                                       // Only do our handling if no keys are 
pressed, mouse button is 1
-                                       // (e.g. not middle click or right 
click) and no modifier keys
-                                       // (e.g. cmd-click to open in new tab).
-                                       if ( ( e.which && e.which !== 1 ) || 
e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) {
-                                               return;
-                                       }
-                                       // Prevent the edit tab's normal 
behavior
-                                       e.preventDefault();
-
-                                       getTarget().done( function ( target ) {
-                                               target.logEvent( 'Edit', { 
action: 'edit-link-click' } );
-                                               target.activate();
-                                       } );
-                               } );
+                               $( caVeEdit ).click( init.onEditTabClick );
                        }
+               },
+
+               setupSectionEditLinks: function () {
+                       var $editsections = $( '#mw-content-text 
.mw-editsection' );
+
+                       // match direction to the user interface
+                       $editsections.css( 'direction', $( 'body' ).css( 
'direction' ) );
+                       // The "visibility" css construct ensures we always 
occupy the same space in the layout.
+                       // This prevents the heading from changing its wrap 
when the user toggles editSourceLink.
+                       $editsections.each( function () {
+                               var $closingBracket, $expandedOnly, 
$hiddenBracket, $outerClosingBracket,
+                                       expandTimeout, shrinkTimeout,
+                                       $editsection = $( this ),
+                                       $heading = $editsection.closest( 'h1, 
h2, h3, h4, h5, h6' ),
+                                       $editLink = $editsection.find( 'a' 
).eq( 0 ),
+                                       $editSourceLink = $editLink.clone(),
+                                       $links = $editLink.add( $editSourceLink 
),
+                                       $divider = $( '<span>' ),
+                                       dividerText = $.trim( mw.msg( 
'pipe-separator' ) ),
+                                       $brackets = $( [ this.firstChild, 
this.lastChild ] );
+
+                               function expandSoon() {
+                                       // Cancel pending shrink, schedule 
expansion instead
+                                       clearTimeout( shrinkTimeout );
+                                       expandTimeout = setTimeout( expand, 100 
);
+                               }
+
+                               function expand() {
+                                       clearTimeout( shrinkTimeout );
+                                       $closingBracket.css( 'visibility', 
'hidden' );
+                                       $expandedOnly.css( 'visibility', 
'visible' );
+                                       $heading.addClass( 
'mw-editsection-expanded' );
+                               }
+
+                               function shrinkSoon() {
+                                       // Cancel pending expansion, schedule 
shrink instead
+                                       clearTimeout( expandTimeout );
+                                       shrinkTimeout = setTimeout( shrink, 100 
);
+                               }
+
+                               function shrink() {
+                                       clearTimeout( expandTimeout );
+                                       if ( !$links.is( ':focus' ) ) {
+                                               $closingBracket.css( 
'visibility', 'visible' );
+                                               $expandedOnly.css( 
'visibility', 'hidden' );
+                                               $heading.removeClass( 
'mw-editsection-expanded' );
+                                       }
+                               }
+
+                               // TODO: Remove this (see Id27555c6 in 
mediawiki/core)
+                               if ( !$brackets.hasClass( 
'mw-editsection-bracket' ) ) {
+                                       $brackets = $brackets
+                                               .wrap( $( '<span>' ).addClass( 
'mw-editsection-bracket' ) )
+                                               .parent();
+                               }
+
+                               $closingBracket = $brackets.last();
+                               $outerClosingBracket = $closingBracket.clone();
+                               $expandedOnly = $divider.add( $editSourceLink 
).add( $outerClosingBracket )
+                                       .css( 'visibility', 'hidden' );
+                               // The hidden bracket after the devider ensures 
we have balanced space before and after
+                               // divider. The space before the devider is 
provided by the original closing bracket.
+                               $hiddenBracket = $closingBracket.clone().css( 
'visibility', 'hidden' );
+
+                               // Events
+                               $heading.on( { 'mouseenter': expandSoon, 
'mouseleave': shrinkSoon } );
+                               $links.on( { 'focus': expand, 'blur': 
shrinkSoon } );
+                               $editLink.click( init.onEditSectionLinkClick );
+
+                               // Initialization
+                               $editSourceLink
+                                       .addClass( 
'mw-editsection-link-secondary' )
+                                       .text( mw.msg( 
'visualeditor-ca-editsource-section' ) );
+                               $divider
+                                       .addClass( 'mw-editsection-divider' )
+                                       .text( dividerText );
+                               $editLink
+                                       .attr( 'href', function ( i, val ) {
+                                               return new mw.Uri( veEditUri 
).extend( {
+                                                       'vesection': new 
mw.Uri( val ).query.section
+                                               } );
+                                       } )
+                                       .addClass( 
'mw-editsection-link-primary' );
+                               $closingBracket
+                                       .after( $divider, $hiddenBracket, 
$editSourceLink, $outerClosingBracket );
+                       } );
+               },
+
+               onEditTabClick: function ( e ) {
+                       // Default mouse button is normalised by jQuery to key 
code 1.
+                       // Only do our handling if no keys are pressed, mouse 
button is 1
+                       // (e.g. not middle click or right click) and no 
modifier keys
+                       // (e.g. cmd-click to open in new tab).
+                       if ( ( e.which && e.which !== 1 ) || e.shiftKey || 
e.altKey || e.ctrlKey || e.metaKey ) {
+                               return;
+                       }
+
+                       e.preventDefault();
+
+                       getTarget().done( function ( target ) {
+                               target.logEvent( 'Edit', { action: 
'edit-link-click' } );
+                               target.activate();
+                       } );
+               },
+
+               onEditSectionLinkClick: function ( e ) {
+                       if ( ( e.which && e.which !== 1 ) || e.shiftKey || 
e.altKey || e.ctrlKey || e.metaKey ) {
+                               return;
+                       }
+
+                       e.preventDefault();
+
+                       getTarget().done( function ( target ) {
+                               target.logEvent( 'Edit', { action: 
'section-edit-link-click' } );
+                               target.saveEditSection( $( e.target ).closest( 
'h1, h2, h3, h4, h5, h6' ).get( 0 ) );
+                               target.activate();
+                       } );
                }
        };
 
diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js 
b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
index 7548800..2e44db6 100644
--- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
+++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.js
@@ -135,7 +135,6 @@
        }
 
        this.setupSkinTabs();
-       this.setupSectionEditLinks();
 
        window.addEventListener( 'popstate', ve.bind( this.onWindowPopState, 
this ) ) ;
 };
@@ -570,23 +569,6 @@
 ve.init.mw.ViewPageTarget.prototype.onNoChanges = function () {
        this.$saveDialogLoadingIcon.hide();
        this.swapSaveDialog( 'nochanges' );
-};
-
-/**
- * Handle clicks on a section edit link.
- *
- * @method
- * @param {jQuery.Event} e Mouse click event
- */
-ve.init.mw.ViewPageTarget.prototype.onEditSectionLinkClick = function ( e ) {
-       if ( ( e.which && e.which !== 1 ) || e.shiftKey || e.altKey || 
e.ctrlKey || e.metaKey ) {
-               return;
-       }
-       this.logEvent( 'Edit', { action: 'section-edit-link-click' } );
-       this.saveEditSection( $( e.target ).closest( 'h1, h2, h3, h4, h5, h6' 
).get( 0 ) );
-       this.activate();
-       // Prevent the edit tab's normal behavior
-       e.preventDefault();
 };
 
 /**
@@ -1097,96 +1079,10 @@
 
 /**
  * Modify page content to make section edit links activate the editor.
- *
- * @method
+ * Dummy replaced by init.js so that we can call it again from #onSave after
+ * replacing the page contents with the new html.
  */
-ve.init.mw.ViewPageTarget.prototype.setupSectionEditLinks = function () {
-       var veEditUri = this.veEditUri,
-               $editsections = $( '#mw-content-text .mw-editsection' ),
-               handler = ve.bind( this.onEditSectionLinkClick, this );
-
-       // match direction to the user interface
-       $editsections.css( 'direction', $( 'body' ).css( 'direction' ) );
-       // The "visibility" css construct ensures we always occupy the same 
space in the layout.
-       // This prevents the heading from changing its wrap when the user 
toggles editSourceLink.
-       $editsections.each( function () {
-               var $closingBracket, $expandedOnly, $hiddenBracket, 
$outerClosingBracket,
-                       expandTimeout, shrinkTimeout,
-                       $editsection = $( this ),
-                       $heading = $editsection.closest( 'h1, h2, h3, h4, h5, 
h6' ),
-                       $editLink = $editsection.find( 'a' ).eq( 0 ),
-                       $editSourceLink = $editLink.clone(),
-                       $links = $editLink.add( $editSourceLink ),
-                       $divider = $( '<span>' ),
-                       dividerText = $.trim( ve.msg( 'pipe-separator' ) ),
-                       $brackets = $( [ this.firstChild, this.lastChild ] );
-
-               function expandSoon() {
-                       // Cancel pending shrink, schedule expansion instead
-                       clearTimeout( shrinkTimeout );
-                       expandTimeout = setTimeout( expand, 100 );
-               }
-
-               function expand() {
-                       clearTimeout( shrinkTimeout );
-                       $closingBracket.css( 'visibility', 'hidden' );
-                       $expandedOnly.css( 'visibility', 'visible' );
-                       $heading.addClass( 'mw-editsection-expanded' );
-               }
-
-               function shrinkSoon() {
-                       // Cancel pending expansion, schedule shrink instead
-                       clearTimeout( expandTimeout );
-                       shrinkTimeout = setTimeout( shrink, 100 );
-               }
-
-               function shrink() {
-                       clearTimeout( expandTimeout );
-                       if ( !$links.is( ':focus' ) ) {
-                               $closingBracket.css( 'visibility', 'visible' );
-                               $expandedOnly.css( 'visibility', 'hidden' );
-                               $heading.removeClass( 'mw-editsection-expanded' 
);
-                       }
-               }
-
-               // TODO: Remove this (see Id27555c6 in mediawiki/core)
-               if ( !$brackets.hasClass( 'mw-editsection-bracket' ) ) {
-                       $brackets = $brackets
-                               .wrap( $( '<span>' ).addClass( 
'mw-editsection-bracket' ) )
-                               .parent();
-               }
-
-               $closingBracket = $brackets.last();
-               $outerClosingBracket = $closingBracket.clone();
-               $expandedOnly = $divider.add( $editSourceLink ).add( 
$outerClosingBracket )
-                       .css( 'visibility', 'hidden' );
-               // The hidden bracket after the devider ensures we have 
balanced space before and after
-               // divider. The space before the devider is provided by the 
original closing bracket.
-               $hiddenBracket = $closingBracket.clone().css( 'visibility', 
'hidden' );
-
-               // Events
-               $heading.on( { 'mouseenter': expandSoon, 'mouseleave': 
shrinkSoon } );
-               $links.on( { 'focus': expand, 'blur': shrinkSoon } );
-               $editLink.click( handler );
-
-               // Initialization
-               $editSourceLink
-                       .addClass( 'mw-editsection-link-secondary' )
-                       .text( mw.msg( 'visualeditor-ca-editsource-section' ) );
-               $divider
-                       .addClass( 'mw-editsection-divider' )
-                       .text( dividerText );
-               $editLink
-                       .attr( 'href', function ( i, val ) {
-                               return new mw.Uri( veEditUri ).extend( {
-                                       'vesection': new mw.Uri( val 
).query.section
-                               } );
-                       } )
-                       .addClass( 'mw-editsection-link-primary' );
-               $closingBracket
-                       .after( $divider, $hiddenBracket, $editSourceLink, 
$outerClosingBracket );
-       } );
-};
+ve.init.mw.ViewPageTarget.prototype.setupSectionEditLinks = null;
 
 /**
  * Add content and event bindings to toolbar buttons.

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Iab9c81222df7f1084179c3643d158374a89ca14b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/VisualEditor
Gerrit-Branch: master
Gerrit-Owner: Krinkle <[email protected]>
Gerrit-Reviewer: Catrope <[email protected]>
Gerrit-Reviewer: Jforrester <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to