r107982 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107981‎ | r107982 | r107983 >
Date:01:28, 4 January 2012
Author:krinkle
Status:resolved (Comments)
Tags:core, johnduhart 
Comment:
[jquery.footHovzer] new plugin for mw-log-console and mw-debug-toolbar
* Previously mw.log and mw.Debug both were in a fixed container on the bottom, overlapping each other. mw.log did increase the body's padding-bottom to account for the height so that all content is still visible, but it was still a problem when mw.Debug came along.
* This plugin adds a single fixed position element to bottom of the body, to which other stuff like mw.log and mw.Debug can append a non-fixed position container. That will take care of it.
* Method update() will re-check the padding and scroll position and fix where needed
* Reduces code a little bit
Modified paths:
  • /trunk/phase3/resources/Resources.php (modified) (history)
  • /trunk/phase3/resources/jquery/jquery.footHovzer.css (added) (history)
  • /trunk/phase3/resources/jquery/jquery.footHovzer.js (added) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.debug.css (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.debug.js (modified) (history)
  • /trunk/phase3/resources/mediawiki/mediawiki.log.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/jquery/jquery.footHovzer.js
@@ -0,0 +1,50 @@
 2+/**
 3+ * Utility to stack stuff in an overlay fixed on the bottom of the page.
 4+ *
 5+ * Usage:
 6+ * <code>
 7+ * var hovzer = $.getFootHovzer();
 8+ * hovzer.$.append( $myCollection );
 9+ * hovzer.update();
 10+ * </code>
 11+ *
 12+ * @author Timo Tijhof, 2012
 13+ */
 14+( function ( $ ) {
 15+ var $hovzer, footHovzer, prevHeight, newHeight;
 16+
 17+ function getHovzer() {
 18+ if ( $hovzer === undefined ) {
 19+ $hovzer = $( '<div id="jquery-foot-hovzer"></div>' ).appendTo( 'body' );
 20+ }
 21+ return $hovzer;
 22+ }
 23+
 24+ footHovzer = {
 25+ update: function () {
 26+ var $body, winTop;
 27+
 28+ $body = $( 'body' );
 29+ if ( prevHeight === undefined ) {
 30+ prevHeight = getHovzer().outerHeight( /*includeMargin=*/true );
 31+ $body.css( 'paddingBottom', '+=' + prevHeight + 'px' );
 32+ } else {
 33+ newHeight = getHovzer().outerHeight( true );
 34+ $body.css( 'paddingBottom', ( parseFloat( $body.css( 'paddingBottom' ) ) - prevHeight ) + newHeight );
 35+ // Update scroll so that page stays focusses on same area
 36+ winTop = $(window).scrollTop();
 37+ if ( $(document).height() - $(window).height() > winTop ) {
 38+ $(window).scrollTop( winTop + ( newHeight - prevHeight ) );
 39+ }
 40+
 41+ prevHeight = newHeight;
 42+ }
 43+ }
 44+ };
 45+
 46+ $.getFootHovzer = function () {
 47+ footHovzer.$ = getHovzer();
 48+ return footHovzer;
 49+ };
 50+
 51+}( jQuery ) );
Property changes on: trunk/phase3/resources/jquery/jquery.footHovzer.js
___________________________________________________________________
Added: svn:eol-style
152 + native
Index: trunk/phase3/resources/jquery/jquery.footHovzer.css
@@ -0,0 +1,6 @@
 2+#jquery-foot-hovzer {
 3+ position: fixed;
 4+ bottom: 0;
 5+ width: 100%;
 6+ z-index: 1000;
 7+}
Property changes on: trunk/phase3/resources/jquery/jquery.footHovzer.css
___________________________________________________________________
Added: svn:eol-style
18 + native
Index: trunk/phase3/resources/Resources.php
@@ -127,6 +127,10 @@
128128 'styles' => 'resources/jquery/jquery.farbtastic.css',
129129 'dependencies' => 'jquery.colorUtil',
130130 ),
 131+ 'jquery.footHovzer' => array(
 132+ 'scripts' => 'resources/jquery/jquery.footHovzer.js',
 133+ 'styles' => 'resources/jquery/jquery.footHovzer.css',
 134+ ),
131135 'jquery.form' => array(
132136 'scripts' => 'resources/jquery/jquery.form.js',
133137 ),
@@ -533,6 +537,7 @@
534538 'mediawiki.debug' => array(
535539 'scripts' => 'resources/mediawiki/mediawiki.debug.js',
536540 'styles' => 'resources/mediawiki/mediawiki.debug.css',
 541+ 'dependencies' => 'jquery.footHovzer',
537542 ),
538543 'mediawiki.feedback' => array(
539544 'scripts' => 'resources/mediawiki/mediawiki.feedback.js',
Index: trunk/phase3/resources/mediawiki/mediawiki.debug.css
@@ -1,8 +1,6 @@
22 .mw-debug {
33 width: 100%;
44 text-align: left;
5 - position: fixed;
6 - bottom: 0;
75 background-color: #eee;
86 border-top: 1px solid #aaa;
97 }
Index: trunk/phase3/resources/mediawiki/mediawiki.log.js
@@ -6,7 +6,7 @@
77 * @author Trevor Parscal <tparscal@wikimedia.org>
88 */
99
10 -(function( $ ) {
 10+( function ( $ ) {
1111
1212 /**
1313 * Logs a message to the console.
@@ -31,6 +31,7 @@
3232 }
3333
3434 // If there is no console, use our own log box
 35+ mw.loader.using( 'jquery.footHovzer', function () {
3536
3637 var d = new Date(),
3738 // Create HH:MM:SS.MIL timestamp
@@ -42,21 +43,14 @@
4344
4445 if ( !$log.length ) {
4546 $log = $( '<div id="mw-log-console"></div>' ).css( {
46 - position: 'fixed',
4747 overflow: 'auto',
48 - zIndex: 500,
49 - bottom: '0px',
50 - left: '0px',
51 - right: '0px',
5248 height: '150px',
5349 backgroundColor: 'white',
5450 borderTop: 'solid 2px #ADADAD'
5551 } );
56 - $( 'body' )
57 - // Since the position is fixed, make sure we don't hide any actual content.
58 - // Increase padding to account for #mw-log-console.
59 - .css( 'paddingBottom', '+=150px' )
60 - .append( $log );
 52+ var hovzer = $.getFootHovzer();
 53+ hovzer.$.append( $log );
 54+ hovzer.update();
6155 }
6256 $log.append(
6357 $( '<div></div>' )
@@ -69,7 +63,8 @@
7064 } )
7165 .text( prefix + args.join( ', ' ) )
7266 .prepend( '<span style="float: right;">[' + time + ']</span>' )
73 - );
 67+ );
 68+ } );
7469 };
7570
7671 })( jQuery );
Index: trunk/phase3/resources/mediawiki/mediawiki.debug.js
@@ -8,6 +8,8 @@
99 ( function ( $, mw, undefined ) {
1010 "use strict";
1111
 12+ var hovzer = $.getFootHovzer();
 13+
1214 var debug = mw.Debug = {
1315 /**
1416 * Toolbar container element
@@ -29,11 +31,13 @@
3032 * @param {Object} data
3133 */
3234 init: function ( data ) {
 35+
3336 this.data = data;
3437 this.buildHtml();
3538
3639 // Insert the container into the DOM
37 - $( 'body' ).append( this.$container );
 40+ hovzer.$.append( this.$container );
 41+ hovzer.update();
3842
3943 $( '.mw-debug-panelink' ).click( this.switchPane );
4044 },
@@ -49,15 +53,22 @@
5054 var currentPaneId = debug.$container.data( 'currentPane' ),
5155 requestedPaneId = $(this).prop( 'id' ).substr( 9 ),
5256 $currentPane = $( '#mw-debug-pane-' + currentPaneId ),
53 - $requestedPane = $( '#mw-debug-pane-' + requestedPaneId );
 57+ $requestedPane = $( '#mw-debug-pane-' + requestedPaneId ),
 58+ hovDone = false;
5459
 60+ function updateHov() {
 61+ if ( !hovDone ) {
 62+ hovzer.update();
 63+ hovDone = true;
 64+ }
 65+ }
 66+
5567 $( this ).addClass( 'current ')
5668 $( '.mw-debug-panelink' ).not( this ).removeClass( 'current ');
5769
58 -
5970 // Hide the current pane
6071 if ( requestedPaneId === currentPaneId ) {
61 - $currentPane.slideUp();
 72+ $currentPane.slideUp( updateHov );
6273 debug.$container.data( 'currentPane', null );
6374 return;
6475 }
@@ -65,10 +76,11 @@
6677 debug.$container.data( 'currentPane', requestedPaneId );
6778
6879 if ( currentPaneId === undefined || currentPaneId === null ) {
69 - $requestedPane.slideDown();
 80+ $requestedPane.slideDown( updateHov );
7081 } else {
7182 $currentPane.hide();
7283 $requestedPane.show();
 84+ updateHov();
7385 }
7486 },
7587
@@ -78,7 +90,7 @@
7991 buildHtml: function () {
8092 var $container, $bits, panes, id;
8193
82 - $container = $( '<div id="mw-debug-container" class="mw-debug"></div>' );
 94+ $container = $( '<div id="mw-debug-toolbar" class="mw-debug"></div>' );
8395
8496 $bits = $( '<div class="mw-debug-bits"></div>' );
8597

Sign-offs

UserFlagDate
Nikerabbitinspected10:30, 4 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r109166[jquery.footHovzer] Remove buggy scrollstate preserver...krinkle17:39, 17 January 2012
r109354dbg toolbar: prevents screen jumping...hashar10:36, 18 January 2012

Comments

#Comment by Nikerabbit (talk | contribs)   10:28, 4 January 2012

I'm interested how you came up with the module name.

#Comment by Nikerabbit (talk | contribs)   15:32, 11 January 2012

Typo: focused

+				// Update scroll so that page stays focusses on same area
#Comment by Hashar (talk | contribs)   15:33, 16 January 2012

This has a really strange behavior which make the text jump in an unattended way anytime I click on a bar. It looks like the main content bottom is aligned to the top of the toolbar. Whenever the toolbar change of size (when a tab is hidden, tab content differs in height), that make the text jump up or down.

That makes the whole window move which is really tiring to the eye. I would expect the main content to stick to the top of the window. Much like when Firebug toolbar is shown / hidden.

Here what I did using wgDebugToolbar on a long page:

  • first click on a tab : jump the text to the top (likely a bug)
  • I then scroll down the text back to the original position, click another tab with longer content : the text jump up :b


The following code in jquery/jquery.footHovzer.js causes the screen to jump in an unattended way. By commenting it out, the text stop moving up/down :-)

              // Update scroll so that page stays focusses on same area
               winTop = $(window).scrollTop();
               if ( $(document).height() - $(window).height() > winTop ) {
                   $(window).scrollTop( winTop + ( newHeight - prevHeight ) );
               }
#Comment by Krinkle (talk | contribs)   17:40, 17 January 2012

The use case for it was valid imho, but the side affects were worse than the gain in the utility. Removed in r109166.

#Comment by Hashar (talk | contribs)   14:36, 19 January 2012

> The use case for it was valid imho, but the side affects were worse than the gain in the utility. Removed in r109166.

Maybe it can be made a plugin option?

#Comment by Hashar (talk | contribs)   10:37, 18 January 2012

Last jumping solved by r109354.

#Comment by Hashar (talk | contribs)   10:37, 18 January 2012

Looks fine to me :-) Marking resolved.

Status & tagging log