From f0d5b97d86353a4f9772a3cfe4adda6f23f78e98 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 19 Jul 2012 16:16:56 +0400 Subject: [PATCH] experiment almost done, next will simplify and lib-ify the code... Signed-off-by: Alex A. Naanou --- ui/experiment-ribbon-navigation-n-zoom.html | 122 +++++++++++++++----- 1 file changed, 92 insertions(+), 30 deletions(-) diff --git a/ui/experiment-ribbon-navigation-n-zoom.html b/ui/experiment-ribbon-navigation-n-zoom.html index 1ebebefc..e28b3614 100755 --- a/ui/experiment-ribbon-navigation-n-zoom.html +++ b/ui/experiment-ribbon-navigation-n-zoom.html @@ -17,9 +17,28 @@ Goals: $(document).ready(function(){ $('.square').click(squareClick) + containerSize(300, 200) + $('.current.square').click() }) +// XXX need to make this work for % values... +function containerSize(W, H){ + var oW = $('.meta-container').width() + var oH = $('.meta-container').height() + + $('.meta-container').css({ + 'width': W, + 'height': H + }) + + // shift the field... + $('.container').css({ + 'margin-top': parseFloat($('.container').css('margin-top')) + (H-oH)/2, + 'margin-left': parseFloat($('.container').css('margin-left')) + (W-oW)/2 + }) +} + function squareClick(){ // set classes... @@ -33,14 +52,17 @@ function squareClick(){ centerSquare() } -function centerSquare(zoom){ - // defaults... - if (zoom == null){ - zoom = $('.container').css('zoom') +// get the vertical offset of the center of square from center of meta-container +// NOTE: this does not account for container margins +function getCurrentVerticalOffset(square){ + if(square == null){ + square = $('.square.current') } + var zoom = $('.container').css('zoom') + var ribbons = $('.ribbon') - var ribbon = $('.ribbon.current') + var ribbon = square.parents('.ribbon') var squares = ribbon.children('.square') // vertical... @@ -56,26 +78,16 @@ function centerSquare(zoom){ // relative position to container... // XXX is there a better way to get this? var t = rn * (h - mh/2) - $('.container').css({ - 'margin-top': (-t + H/2 + h/2) - }) - - // horizontal... - alignRibbon() + + return -t + H/2 + h/2 } -function alignRibbon(square, position, zoom){ - // default values... - if(position == null){ - position = 'center' - } +// get the horizontal offset of the center of square from center of meta-container +// NOTE: this does not account for container margins +function getCurrentHorizontalOffset(square){ if(square == null){ square = $('.square.current') } - if (zoom == null){ - zoom = $('.container').css('zoom') - } - var ribbon = square.parents('.ribbon') var squares = ribbon.children('.square') @@ -89,15 +101,48 @@ function alignRibbon(square, position, zoom){ var sn = squares.index(square) + 1 var l = sn * (w - mw/2) + return -l + W/2 + w/2 +} + +function centerSquare(){ + + $('.container').css({ + 'margin-top': getCurrentVerticalOffset() + }) + + // horizontal... + alignRibbon() +} + +function alignRibbon(square, position){ + // default values... + if(square == null){ + square = $('.square.current') + } + if(position == null){ + position = 'center' + } + // account for shifted container... + // NOTE: this enables us to cheat and shift all the ribbons just + // by changing container margin-left... + var cml = parseFloat($('.container').css('margin-left')) + if(!cml){ + cml = 0 + } + + var ribbon = square.parents('.ribbon') + var h_offset = getCurrentHorizontalOffset(square) - cml + var w = $('.square').outerWidth(true) + switch(position){ case 'before': - ribbon.css({'margin-left': (-l + W/2 + w)}) + ribbon.css({'margin-left': h_offset + w/2}) return true case 'center': - ribbon.css({'margin-left': (-l + W/2 + w/2)}) + ribbon.css({'margin-left': h_offset}) return true case 'after': - ribbon.css({'margin-left': (-l + W/2)}) + ribbon.css({'margin-left': h_offset - w/2}) return true } return false @@ -107,20 +152,30 @@ function alignRibbon(square, position, zoom){ // XXX try transition-origin instead of compensating by moving... function zoom(factor){ var zoom = $('.container').css('zoom')*factor + var H = $('.meta-container').height() var W = $('.meta-container').width() $('.container').css({ 'zoom': zoom, + // this only shifts to account for zoom/scale change... + // ...we need to factor in the position of .current within the container 'top': H/2 * 1/zoom - H/2, 'left': W/2 * 1/zoom - W/2 }) } - - +Zoom:
+Size: + + + +

-
+
1