r104307 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104306‎ | r104307 | r104308 >
Date:21:26, 26 November 2011
Author:btongminh
Status:ok
Tags:
Comment:
Rename the cryptic variable names in jquery.ucompare
Make the CSS file look less like it was typed on a keyboard without spacebar and enter key
Add comments
Fix an HTML escaping bug
Modified paths:
  • /trunk/extensions/VipsScaler/modules/jquery.ucompare/css/jquery.ucompare.css (modified) (history)
  • /trunk/extensions/VipsScaler/modules/jquery.ucompare/js/jquery.ucompare.js (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/modules/jquery.ucompare/css/jquery.ucompare.css
@@ -7,6 +7,45 @@
88 * Version 1.0.0
99 *
1010 */
11 - .uc-mask {position:absolute; top:0; left:0; z-index:100; border-right:3px solid #333; overflow:hidden; box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6); -webkit-box-shadow: 5px 5px 7px rgba(0, 0, 0, 0.6); -moz-box-shadow: 5px 0 7px rgba(0, 0, 0, 0.6);}
12 -.uc-bg {position:absolute; top:0; left:0; z-index:0;}
13 -.uc-caption {position:absolute; bottom:10px; left:10px; z-index:120; background:#000; filter:alpha(opacity=80);-moz-opacity:0.8;-khtml-opacity: 0.8;opacity: 0.8; color:#fff; text-align:center;-webkit-border-radius:5px; -moz-border-radius:5px; border-radius:5px; padding:5px; font-size:12px; font-family:arial; display:none;}
\ No newline at end of file
 11+ .uc-mask {
 12+ position: absolute;
 13+ top: 0;
 14+ left: 0;
 15+ z-index: 100;
 16+ border-right: 3px solid #333;
 17+ overflow: hidden;
 18+ box-shadow: 3px 5px 5px rgba(0, 0, 0, 0.6);
 19+ box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6);
 20+ -webkit-box-shadow: 5px 5px 7px rgba(0, 0, 0, 0.6);
 21+ -moz-box-shadow: 5px 0 7px rgba(0, 0, 0, 0.6);
 22+}
 23+.uc-bg {
 24+ position: absolute;
 25+ top: 0;
 26+ left: 0;
 27+ z-index: 0;
 28+}
 29+.uc-caption {
 30+ position: absolute;
 31+ bottom: 10px;
 32+ left: 10px;
 33+ z-index: 120;
 34+
 35+ background: #000;
 36+ filter: alpha(opacity=80);
 37+ -moz-opacity:0.8;
 38+ -khtml-opacity: 0.8;
 39+ opacity: 0.8;
 40+
 41+ color: #fff;
 42+ text-align: center;
 43+ font-size: 12px;
 44+ font-family: arial;
 45+
 46+ -webkit-border-radius: 5px;
 47+ -moz-border-radius: 5px;
 48+ border-radius: 5px;
 49+
 50+ padding: 5px;
 51+ display: none;
 52+}
Index: trunk/extensions/VipsScaler/modules/jquery.ucompare/js/jquery.ucompare.js
@@ -7,27 +7,32 @@
88 * Version 1.0.0
99 *
1010 */
11 -(function ($) {
12 - $.fn.extend({
13 - ucompare: function (b) {
14 - var c = {
 11+( function ( $ ) {
 12+ $.fn.extend( {
 13+ // Hook into jquery.ucompage
 14+ ucompare: function ( localConfig ) {
 15+ // Configuration variable
 16+ var config = {
1517 defaultgap: 50,
1618 leftgap: 10,
1719 rightgap: 10,
1820 caption: false,
1921 reveal: .5
2022 };
21 - var b = $.extend(c, b);
22 - return this.each(function () {
23 - var c = b;
24 - var d = $(this);
25 - var e = d.children("img:eq(0)").attr("src");
26 - var f = d.children("img:eq(1)").attr("src");
27 - var g = d.children("img:eq(0)").attr("alt");
28 - var h = d.children("img:eq(0)").width();
29 - var i = d.children("img:eq(0)").height();
30 - d.children("img").hide();
31 - d.css({
 23+ $.extend( config, localConfig );
 24+ return this.each( function () {
 25+ /** Initialization function */
 26+
 27+ var container = $(this);
 28+ // Extract image attributes
 29+ var imageLeftSource = container.children("img:eq(0)").attr("src");
 30+ var imageRightSource = container.children("img:eq(1)").attr("src");
 31+ var caption = container.children("img:eq(0)").attr("alt");
 32+ var width = container.children("img:eq(0)").width();
 33+ var height = container.children("img:eq(0)").height();
 34+ // Hide both images
 35+ container.children("img").hide();
 36+ container.css({
3237 overflow: "hidden",
3338 position: "relative"
3439 });
@@ -36,38 +41,57 @@
3742 * MediaWiki hack:
3843 * Parent element height can still be 0px after hiding the images
3944 * so we really want to update its dimensions.
40 - */
41 - d.width(h); d.height(i);
 45+ */
 46+ container.width(width); container.height(height);
4247
43 - d.append('<div class="uc-mask"></div>');
44 - d.append('<div class="uc-bg"></div>');
45 - d.append('<div class="uc-caption">' + g + "</div>");
46 - d.children(".uc-mask, .uc-bg").width(h);
47 - d.children(".uc-mask, .uc-bg").height(i);
48 - d.children(".uc-mask").animate({
49 - width: h - c.defaultgap
 48+ // The left part is the foreground image
 49+ container.append('<div class="uc-mask"></div>');
 50+ // The right part is the background image
 51+ container.append('<div class="uc-bg"></div>');
 52+ // Caption
 53+ container.append( $( '<div class="uc-caption" />' ).text( caption ) );
 54+ // Set the foreground and background image dimensions
 55+ container.children(".uc-mask, .uc-bg").width(width);
 56+ container.children(".uc-mask, .uc-bg").height(height);
 57+ // Fancy initial animation
 58+ container.children(".uc-mask").animate({
 59+ width: width - config.defaultgap
5060 }, 1e3);
51 - d.children(".uc-mask").css("backgroundImage", "url(" + e + ")");
52 - d.children(".uc-bg").css("backgroundImage", "url(" + f + ")");
53 - if (c.caption) d.children(".uc-caption").show()
54 - }).mousemove(function (c) {
55 - var d = b;
56 - var e = $(this);
57 - pos_img = e.position()["left"];
58 - pos_mouse = c.pageX - e.children(".uc-mask").offset().left;
59 - new_width = pos_mouse - pos_img;
60 - img_width = e.width();
61 - img_cap_one = e.children("img:eq(0)").attr("alt");
62 - img_cap_two = e.children("img:eq(1)").attr("alt");
63 - if (new_width > d.leftgap && new_width < img_width - d.rightgap) {
64 - e.children(".uc-mask").width(new_width)
 61+ // Set the images
 62+ container.children(".uc-mask").css("backgroundImage", "url(" + imageLeftSource + ")");
 63+ container.children(".uc-bg").css("backgroundImage", "url(" + imageRightSource + ")");
 64+ if ( config.caption ) {
 65+ container.children(".uc-caption").show()
 66+ }
 67+ }).mousemove(function (event) {
 68+ /** Mouse movent event handler */
 69+
 70+ // Create a jQuery object of the container
 71+ var container = $(this);
 72+
 73+ // Calculate mouse position relative to the left of the image
 74+ var mousePosition = event.pageX - container.children(".uc-mask").offset().left;
 75+
 76+ // Extract image width
 77+ var imageWidth = container.width();
 78+
 79+ // Extract caption
 80+ var captionLeft = container.children("img:eq(0)").attr("alt");
 81+ var captionRight = container.children("img:eq(1)").attr("alt");
 82+
 83+ if ( mousePosition > config.leftgap &&
 84+ mousePosition < imageWidth - config.rightgap ) {
 85+ // Set the width of the left image
 86+ container.children(".uc-mask").width( mousePosition );
6587 }
66 - if (new_width < img_width * d.reveal) {
67 - e.children(".uc-caption").html(img_cap_two)
 88+
 89+ // Set caption
 90+ if ( mousePosition < imageWidth * config.reveal ) {
 91+ container.children(".uc-caption").text( captionRight );
6892 } else {
69 - e.children(".uc-caption").html(img_cap_one)
 93+ container.children(".uc-caption").text( captionLeft );
7094 }
71 - })
72 - }
73 - })
74 -})(jQuery)
 95+ } ); // End of return statement
 96+ } // End of ucompare function
 97+ } );
 98+} )( jQuery );

Status & tagging log