r104414 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104413‎ | r104414 | r104415 >
Date:09:53, 28 November 2011
Author:hashar
Status:ok
Tags:tstarling 
Comment:
Add a checkbox to switch between thumbnails

Tim Starling, on CR of r103658,raised a possible issue whereas on some
laptop it might be hard to click without moving the comparaison bar.
Switching the thumbnails using keyboard would trivially solve the issue,
hence this new checkbox.
Modified paths:
  • /trunk/extensions/VipsScaler/SpecialVipsTest.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsScaler.i18n.php (modified) (history)
  • /trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.css (modified) (history)
  • /trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsScaler.i18n.php
@@ -24,7 +24,10 @@
2525 'vipsscaler-form-sharpen-radius' => 'Amount of sharpening:',
2626 'vipsscaler-form-bilinear' => 'Bilinear scaling',
2727 'vipsscaler-form-submit' => 'Generate thumbnails',
28 -
 28+
 29+ 'vipsscaler-thumbs-legend' => 'Generated thumbnails',
 30+ 'vipsscaler-thumbs-help' => 'The thumbnail shown below was generated with the default scaler. Move your mouse over the thumbnail to compare it with the one generated by VIPS. Alternatively, you can click / unclick the checkbox below to switch between thumbnails.',
 31+ 'vipsscaler-thumbs-switch-label' => 'Click to switch between default and VIPS scaling output.',
2932 'vipsscaler-default-thumb' => 'Thumbnail generated with default scaler',
3033 'vipsscaler-vips-thumb' => 'Thumbnail generated with VIPS',
3134
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php
@@ -98,8 +98,8 @@
9999 # Make url to the vips thumbnail
100100 $vipsThumbUrl = $this->getTitle()->getLocalUrl( $vipsUrlOptions );
101101
102 - # Add to output
103 - $html = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ),
 102+ # HTML for the thumbnails
 103+ $thumbs = Html::rawElement( 'div', array( 'id' => 'mw-vipstest-thumbnails' ),
104104 Html::element( 'img', array(
105105 'src' => $normalThumbUrl,
106106 'alt' => wfMessage( 'vipsscaler-default-thumb' ),
@@ -109,6 +109,24 @@
110110 'alt' => wfMessage( 'vipsscaler-vips-thumb' ),
111111 ) )
112112 );
 113+
 114+ # Helper messages shown above the thumbnails rendering
 115+ $help = wfMessage( 'vipsscaler-thumbs-help' )->parseAsBlock();
 116+
 117+ # A checkbox to easily alternate between both views:
 118+ $checkbox = Xml::checkLabel(
 119+ wfMessage( 'vipsscaler-thumbs-switch-label' ),
 120+ 'mw-vipstest-thumbs-switch',
 121+ 'mw-vipstest-thumbs-switch'
 122+ );
 123+
 124+ # Wrap the three HTML snippets above in a fieldset:
 125+ $html = Xml::fieldset(
 126+ wfMessage( 'vipsscaler-thumbs-legend' ),
 127+ $help . $checkbox . $thumbs
 128+ );
 129+
 130+ # Finally output all of the above
113131 $this->getOutput()->addHTML( $html );
114132 $this->getOutput()->addModules( array(
115133 'ext.vipsscaler',
Index: trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.css
@@ -3,6 +3,9 @@
44 margin-top: 1em;
55 margin-right: 1em;
66 }
 7+#mw-vipstest-thumbs-switch{
 8+ margin-bottom: 2em;
 9+}
710 .uc-caption {
811 /** Overrides ucompare caption position from bottom (bottom:10px) to top */
912 top:10px;
Index: trunk/extensions/VipsScaler/modules/ext.vipsScaler/ext.vipsScaler.js
@@ -1,4 +1,25 @@
22 jQuery( function( $ ) {
 3+ $.vipsScaler = {
 4+ /** function to alternate between both thumbnails */
 5+ switchThumbs: function() {
 6+ var e = $('#mw-vipstest-thumbnails')
 7+ var mask = e.children(".uc-mask")
 8+ var caption = e.children(".uc-caption")
 9+
 10+ width = e.width();
 11+ maskWidth = mask.width();
 12+
 13+ if( maskWidth < width / 2 ) {
 14+ /** Bar is 3 pixels width. We want to show it on the right */
 15+ mask.width( width - 3);
 16+ caption.html( e.children("img:eq(0)").attr("alt") );
 17+ } else {
 18+ mask.width( 0 );
 19+ caption.html( e.children("img:eq(1)").attr("alt") );
 20+ }
 21+ },
 22+ };
 23+
324 var container = document.getElementById( 'mw-vipstest-thumbnails' );
425 if ( container ) {
526 /*
@@ -53,23 +74,14 @@
5475 reveal: 0.5
5576 });
5677
57 - /** Also add a click handler to instantly switch beetween pics */
58 - $('#mw-vipstest-thumbnails').click( function() {
59 - var e = $(this)
60 - var mask = e.children(".uc-mask")
61 - var caption = e.children(".uc-caption")
62 -
63 - width = e.width();
64 - maskWidth = mask.width();
65 -
66 - if( maskWidth < width / 2 ) {
67 - mask.width( width );
68 - caption.html( e.children("img:eq(0)").attr("alt") );
69 - } else {
70 - mask.width( 0 );
71 - caption.html( e.children("img:eq(1)").attr("alt") );
72 - }
73 - });
 78+ /**
 79+ * Also add a click handler to instantly switch beetween pics
 80+ * This can be done by clicking the thumbnail or using a checkbox
 81+ */
 82+ $('#mw-vipstest-thumbs-switch')
 83+ .click( function() { $.vipsScaler.switchThumbs() } );
 84+ $('#mw-vipstest-thumbnails')
 85+ .click( function() { $.vipsScaler.switchThumbs() } );
7486 }
75 -}
 87+}
7688 );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r103658add click handler to switch instantly between pics...hashar11:01, 19 November 2011

Status & tagging log