From 797b6b17c12ed096ae5fc80364fa1502e7d39862 Mon Sep 17 00:00:00 2001 From: Marcel Pociot Date: Fri, 30 Dec 2011 16:34:09 +0100 Subject: [PATCH] added "path" like option - so it now supports both directions and two menu windows --- Resources/app.js | 79 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/Resources/app.js b/Resources/app.js index 2d1d0ff..d581b27 100644 --- a/Resources/app.js +++ b/Resources/app.js @@ -1,19 +1,34 @@ +// ALPHABYTES + // Facebook like menu window -var menu = Ti.UI.createWindow({ +var leftMenu = Ti.UI.createWindow({ backgroundColor: 'red', top: 0, left: 0, - width: 250, + width: 150, + zIndex: 1 +}); +var data = [{title:"Row 1"},{title:"Row 2"},{title:"Row 3"},{title:"Row 4"}]; +var tableView = Ti.UI.createTableView({ data: data }); +leftMenu.add(tableView); +leftMenu.open(); + +// Facebook like menu window +var rightMenu = Ti.UI.createWindow({ + backgroundColor: 'red', + top: 0, + right: 0, + width: 150, zIndex: 1 }); var data = [{title:"Row 1"},{title:"Row 2"},{title:"Row 3"},{title:"Row 4"}]; var tableView = Ti.UI.createTableView({ data: data }); -menu.add(tableView); -menu.open(); +rightMenu.add(tableView); +rightMenu.open(); // animations var animateLeft = Ti.UI.createAnimation({ - left: 250, + left: 150, curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT, duration: 500 }); @@ -22,6 +37,13 @@ var animateRight = Ti.UI.createAnimation({ curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT, duration: 500 }); +var animateNegativeLeft = Ti.UI.createAnimation({ + left: -150, + curve: Ti.UI.iOS.ANIMATION_CURVE_EASE_OUT, + duration: 500 +}); + + var win = Titanium.UI.createWindow({ left: 0, zIndex: 10 @@ -44,6 +66,13 @@ var button = Ti.UI.createButton({ height: 30, top: 10 }); +var button2 = Ti.UI.createButton({ + title: 'm', + right: 10, + width: 30, + height: 30, + top: 10 +}); var touchStartX = 0; var touchStarted = false; win1.addEventListener('touchstart',function(e){ @@ -51,28 +80,38 @@ win1.addEventListener('touchstart',function(e){ }); win1.addEventListener('touchend',function(e){ touchStarted = false; - if( win.left >= 140 ){ - win.animate(animateLeft); - isToggled = true; + if( win.left < 0 ){ + if( win.left <= -140 ){ + win.animate(animateNegativeLeft); + isToggled = true; + } else { + win.animate(animateRight); + isToggled = false; + } } else { - win.animate(animateRight); - isToggled = false; + if( win.left >= 140 ){ + win.animate(animateLeft); + isToggled = true; + } else { + win.animate(animateRight); + isToggled = false; + } } }); win1.addEventListener('touchmove',function(e){ var x = parseInt(e.globalPoint.x, 10); var newLeft = x - touchStartX; - if( newLeft >= 0 ){ - if( touchStarted ){ - win.left = newLeft; - } + if( touchStarted ){ + if( newLeft <= 150 && newLeft >= -150) + win.left = newLeft; } // Minimum movement is 30 - if( newLeft > 30 ){ + if( newLeft > 30 || newLeft < -30 ){ touchStarted = true; } }); nav.add(button); +nav.add(button2); win.add(nav); win.open(); @@ -86,4 +125,14 @@ button.addEventListener('click',function(e){ win.animate(animateRight); isToggled = false; } +}); + +button2.addEventListener('click',function(e){ + if( !isToggled ){ + win.animate(animateNegativeLeft); + isToggled = true; + } else { + win.animate(animateRight); + isToggled = false; + } }); \ No newline at end of file