Mercurial > hg > digilib
changeset 1270:3ab98c1847b7
draggable measuring bar
author | hertzhaft |
---|---|
date | Fri, 24 Jan 2014 18:03:20 +0100 |
parents | a08a513f711c |
children | 5d02e7f08917 |
files | webapp/src/main/webapp/jquery/jquery.digilib.measure.js |
diffstat | 1 files changed, 24 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Fri Jan 24 15:26:42 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.measure.js Fri Jan 24 18:03:20 2014 +0100 @@ -893,6 +893,7 @@ $u2.children(':not(:disabled)')[data.settings.unitTo].selected = true; }; + // initial position of measure bar (bottom left of browser window) var setScreenPosition = function(data, $div) { if ($div == null) return; var h = geom.rectangle($div).height; @@ -900,6 +901,22 @@ geom.position(0, s.height - h).adjustDiv($div); }; + // drag measureBar around + var dragMeasureBar = function(event) { + var $t = $(this); + var x = $t.offset().left - event.pageX; + var y = $t.offset().top - event.pageY; + $(document.body).on('mousemove.measure', function(event) { + $t.offset({ + left : event.pageX + x, + top : event.pageY + y + }); + }).on('mouseup.measure', function(event) { + $(document.body).off('mousemove.measure').off('mouseup.measure'); + }); + return true; + }; + // setup a div for accessing the measure functionality var setupMeasureBar = function(data) { console.debug('measure: setupMeasureBar'); @@ -935,6 +952,7 @@ loadShapeTypes(data); loadSections(data); setupMeasureWidgets(data); + $measureBar.on('mousedown.measure', dragMeasureBar); return $measureBar; }; @@ -949,19 +967,19 @@ var tooltip = buttonConfig.tooltip; $draw.attr('title', tooltip); $elem = data.$elem; - $draw.on('click.digilib', function(evt) { - // the handler function calls digilib with action - console.debug('click action=', action, ' evt=', evt); + $draw.on('mousedown.measure', function(evt) { + // prevent mousedown event ot bubble up to measureBar (no dragging!) + console.debug('mousedown=', action, ' evt=', evt); $elem.digilib(action); return false; }); - $t.value1.on('change.digilib', function(evt) { + $t.value1.on('change.measure', function(evt) { updateFactor(data); }); - $t.unit1.on('change.digilib', function(evt) { + $t.unit1.on('change.measure', function(evt) { updateUnits(data); }); - $t.unit2.on('change.digilib', function(evt) { + $t.unit2.on('change.measure', function(evt) { updateUnits(data); });