# HG changeset patch # User hertzhaft # Date 1333298622 -7200 # Node ID 41991d1598f1e14bb1bd806138c32402e62c3ef6 # Parent 4f5c5c578aa41a8f89159f02358a0293ed90f859 rgb slider: reset now functional, minor refactoring diff -r 4f5c5c578aa4 -r 41991d1598f1 webapp/src/main/webapp/jquery/jquery.digilib.css --- a/webapp/src/main/webapp/jquery/jquery.digilib.css Sat Mar 31 22:34:50 2012 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.css Sun Apr 01 18:43:42 2012 +0200 @@ -153,6 +153,12 @@ background: transparent; } +div.dl-digilib table.dl-rgbslider td.dl-rgb { + width: 40%; + padding: 6px; + border: 2px solid lightcyan; +} + div.dl-digilib div.dl-rgbslider { display: none; border: 2px solid lightcyan; @@ -163,9 +169,21 @@ top: 0px; } -div.dl-digilib div.dl-rgbslidergrey span, -div.dl-digilib div.dl-rgbsliderindicator span { - padding: 0px 20px; +div.dl-digilib div.dl-rgbsliderindicator { + border: 2px solid lightcyan; + margin: 10px 0px; + } + +div.dl-digilib table.dl-rgbslider, +div.dl-digilib table.dl-rgbslidergrey, +div.dl-digilib table.dl-rgbsliderindicator { + width: 100%; + border-collapse: collapse; + } + +div.dl-digilib table.dl-rgbslidergrey td, +div.dl-digilib table.dl-rgbsliderindicator td { + height: 20px; } div.dl-digilib td.dl-color div { @@ -173,7 +191,7 @@ border: 2px solid lightcyan; text-align: center; padding: 20px 0px; - margin: 10px; + margin: 0px 20px 20px 0px; } div.dl-digilib td.dl-r div { @@ -260,16 +278,6 @@ opacity: 1; } -div.dl-digilib table.dl-rgbslider { - width: 100%; -} - -div.dl-digilib table.dl-rgbslider td.dl-rgb { - width: 40%; - padding: 6px; - border: 2px solid lightcyan; -} - /* special definitions for fullscreen */ div.dl-digilib.dl-fullscreen div.dl-buttons { position: fixed; diff -r 4f5c5c578aa4 -r 41991d1598f1 webapp/src/main/webapp/jquery/jquery.digilib.sliders.js --- a/webapp/src/main/webapp/jquery/jquery.digilib.sliders.js Sat Mar 31 22:34:50 2012 +0200 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.sliders.js Sun Apr 01 18:43:42 2012 +0200 @@ -159,6 +159,7 @@ var setupFormDiv = function (data, $content, cssSuffix, onSubmit) { var cssPrefix = data.settings.cssPrefix; var cls = cssPrefix + cssSuffix; + var tiny = cssPrefix + 'tinyslider'; var $elem = data.$elem; var sliderSelector = '#'+cssPrefix+'slider'; if (fn.isOnScreen(data, sliderSelector)) return; // already onscreen @@ -166,7 +167,7 @@
\
\ \ - \ + \ \
\
'; @@ -179,6 +180,15 @@ fn.withdraw($div); return false; }); + // handle reset + $form.find('.'+cls+'reset').on('click', function () { + var sliders = $form.find('div.'+tiny); + sliders.each(function () { + var reset = $(this).data('reset'); + reset(); + }); + // TODO: update indicator + }); // handle cancel $form.find('.'+cls+'cancel').on('click', function () { fn.withdraw($div); @@ -186,7 +196,6 @@ // show div $div.fadeIn(); // fix non-HTML5 slider - var tiny = cssPrefix + 'tinyslider'; var $range = $form.find('input.'+tiny+'range'); var HTML5 = $range.prop('type') === 'range'; if (!HTML5) { @@ -208,7 +217,7 @@ var cssPrefix = data.settings.cssPrefix; var cls = cssPrefix + 'tinyslider'; var html = '\ -
\ +
\ '+opts.label+'\ \ \ @@ -216,17 +225,15 @@ var $slider = $(html); var $range = $slider.find('input.'+cls+'range'); var $text = $slider.find('input.'+cls+'text'); - $slider.data({'$text' : $text, '$range' : $range}); - // connect slider and input - $range.on('change', function () { + var rangeChange = function () { // crop floating point imprecision var val = parseFloat($range.val()).toFixed(4); $text.val(parseFloat(val)); if ($.isFunction(onChange)) { onChange($slider, val); } - }); - $text.on('change', function () { + }; + var textChange = function () { var val = $text.val(); $range.val(val); // val doesn't change the slider handle position in Tinyrange @@ -238,6 +245,18 @@ if ($.isFunction(onChange)) { onChange($slider, val); } + }; + var reset = function () { + $text.val(param); + textChange(); + }; + // connect slider and input + $range.on('change', rangeChange); + $text.on('change', textChange); + $slider.data({ + '$text' : $text, + '$range' : $range, + 'reset' : reset }); return $slider; }; @@ -265,15 +284,21 @@ var html = '\
\ \ -
\ - \ -
\ -
\ - \ +
\ +
\ + \ + \ +
\ +
\ + \ + \ + \ +
\ +
\
\
'; var $div = $(html); - var $table = $div.find('table'); + var $table = $div.find('table.'+cls); var onChange = function () { // show effects of color brightness/contrast on a grey scale var input = $table.data(); @@ -290,9 +315,9 @@ var b = Math.min(Math.max(Math.round(Math.pow(2, bm) * val + ba), 0), 255); $(this).css('background-color', 'rgb('+r+','+g+','+b+')'); }; - $div.find('div.'+cls+'indicator span').each(setRGBValue); + $div.find('table.'+cls+'indicator td').each(setRGBValue); }; - var setupTableRow = function(index, value) { + var insertTableRow = function(index, value) { var color = rgb[value]; // start values are set in "handleSetup" var $tr = $('').appendTo($table); @@ -320,8 +345,8 @@ var rgbm = input['rm'].val() + '/' + input['gm'].val() + '/' + input['bm'].val(); onSubmit(rgbm, rgba); }; - $.each(primaryColors, setupTableRow); - $div.find('div.'+cls+'grey span').each(setGreyScale); + $.each(primaryColors, insertTableRow); + $div.find('table.'+cls+'grey td').each(setGreyScale); setupFormDiv(data, $div, 'rgbslider', getValues); onChange(); };