r94778 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94777‎ | r94778 | r94779 >
Date:17:14, 17 August 2011
Author:salvatoreingala
Status:deferred
Tags:
Comment:
Added a tooltip to show values of sliders on mouseover and during sliding.
Modified paths:
  • /branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css (modified) (history)
  • /branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js (modified) (history)

Diff [purge]

Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.css
@@ -26,6 +26,16 @@
2727 width: 50%;
2828 }
2929
 30+.formBuilder-slider-tooltip {
 31+ padding: 2px;
 32+ min-width: 20px;
 33+ text-align: center;
 34+ -o-box-shadow: 0 0 3px #aaa;
 35+ -moz-box-shadow: 0 0 3px #aaa;
 36+ -webkit-box-shadow: 0 0 3px #aaa;
 37+ box-shadow: 0 0 3px #aaa;
 38+}
 39+
3040 .formbuilder select {
3141 width: 40%;
3242 }
Index: branches/salvatoreingala/Gadgets/ui/resources/jquery.formBuilder.js
@@ -979,15 +979,86 @@
980980 };
981981
982982 if ( typeof value != 'undefined' ) {
983 - rangeOptions['value'] = value;
 983+ rangeOptions.value = value;
984984 }
985985
986986 if ( typeof this.desc.step != 'undefined' ) {
987 - rangeOptions['step'] = this.desc.step;
 987+ rangeOptions.step = this.desc.step;
988988 }
989989
 990+ //A tooltip to show current value.
 991+ //TODO: use jQuery UI tooltips when they are released (in 1.9)
 992+ var $tooltip = $( '<div/>' )
 993+ .addClass( 'formBuilder-slider-tooltip ui-widget ui-corner-all ui-widget-content' )
 994+ .css( {
 995+ position: 'absolute',
 996+ display: 'none'
 997+ } )
 998+ .appendTo( this.$div );
 999+
 1000+ var tooltipShown = false, sliding = false, mouseOver = false;
 1001+
 1002+ function refreshTooltip( visible, handle, value ) {
 1003+ if ( !tooltipShown && visible ) {
 1004+ $tooltip.fadeIn( 'fast' );
 1005+ tooltipShown = true;
 1006+ } else if ( tooltipShown && !visible ) {
 1007+ $tooltip.fadeOut( 'fast' );
 1008+ tooltipShown = false;
 1009+ }
 1010+
 1011+ $tooltip
 1012+ .zIndex( $( handle ).parent().zIndex() + 1 )
 1013+ .text( value )
 1014+ .position( {
 1015+ my: "bottom",
 1016+ at: "top",
 1017+ of: handle
 1018+ } );
 1019+ }
 1020+
 1021+ $.extend( rangeOptions, {
 1022+ start: function( event, ui ) {
 1023+ sliding = true;
 1024+ },
 1025+ slide: function( event, ui ) {
 1026+ //Deferring to allow the widget to refresh his position
 1027+ setTimeout( function() {
 1028+ refreshTooltip( true, $slider.find( '.ui-slider-handle' ), ui.value );
 1029+ }, 1 );
 1030+ },
 1031+ stop: function( event, ui ) {
 1032+ setTimeout( function() {
 1033+ if ( !$handle.is( ':focus' ) && !mouseOver) {
 1034+ refreshTooltip( false, $slider.find( '.ui-slider-handle' ), ui.value );
 1035+ }
 1036+ }, 300 );
 1037+ sliding = false;
 1038+ }
 1039+ } );
 1040+
9901041 $slider.slider( rangeOptions );
991 -
 1042+
 1043+ var $handle = $slider.find( '.ui-slider-handle' )
 1044+ .focus( function( event ) {
 1045+ refreshTooltip( true, $handle, $slider.slider( 'value' ) );
 1046+ } )
 1047+ .blur( function( event ) {
 1048+ refreshTooltip( false, $handle, $slider.slider( 'value' ) );
 1049+ } )
 1050+ .mouseenter( function( event ) {
 1051+ mouseOver = true;
 1052+ refreshTooltip( true, $handle, $slider.slider( 'value' ) );
 1053+ } )
 1054+ .mouseleave( function( event ) {
 1055+ setTimeout( function() {
 1056+ if ( !$handle.is( ':focus' ) && !sliding ) {
 1057+ refreshTooltip( false, $handle, $slider.slider( 'value' ) );
 1058+ }
 1059+ }, 1 );
 1060+ mouseOver = false;
 1061+ } );
 1062+
9921063 this.$div.append( $slider );
9931064 }
9941065

Status & tagging log