From 636f8c35b556c67e96ff2a5c6c06045e0d4735ea Mon Sep 17 00:00:00 2001 From: Indermohan Singh Date: Sat, 10 Jan 2015 15:37:12 +0530 Subject: [PATCH 1/3] Toggle Drawer Option and Semicolon Bug Fix --- index.html | 2 +- ionic.contrib.drawer.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/index.html b/index.html index 0382143..beaf20f 100644 --- a/index.html +++ b/index.html @@ -44,7 +44,7 @@

Menu

- + Friends Favorites diff --git a/ionic.contrib.drawer.js b/ionic.contrib.drawer.js index b2f5815..e3033ad 100644 --- a/ionic.contrib.drawer.js +++ b/ionic.contrib.drawer.js @@ -27,6 +27,9 @@ angular.module('ionic.contrib.drawer', ['ionic']) var width = $element[0].clientWidth; + // Current State of Drawer + var drawerState = 'close'; + var enableAnimation = function() { $element.addClass('animate'); }; @@ -81,8 +84,10 @@ angular.module('ionic.contrib.drawer', ['ionic']) ionic.requestAnimationFrame(function() { if(newX < (-width / 2)) { el.style.transform = el.style.webkitTransform = 'translate3d(' + -width + 'px, 0, 0)'; + drawerState = 'close'; } else { el.style.transform = el.style.webkitTransform = 'translate3d(0px, 0, 0)'; + drawerState = 'open'; } }); }; @@ -154,6 +159,18 @@ angular.module('ionic.contrib.drawer', ['ionic']) } }); }; + + this.isOpen = function() { + if(drawerState === 'close') { + return false; + } else { + return true; + } + }; + + this.setState = function(value) { + drawerState = value; + }; }]) .directive('drawer', ['$rootScope', '$ionicGesture', function($rootScope, $ionicGesture) { @@ -165,14 +182,25 @@ angular.module('ionic.contrib.drawer', ['ionic']) $scope.openDrawer = function() { console.log('open'); ctrl.open(); + ctrl.setState('open'); }; $scope.closeDrawer = function() { console.log('close'); ctrl.close(); + ctrl.setState('close'); + }; + $scope.toggleDrawer = function() { + if(ctrl.isOpen()) { + ctrl.close(); + ctrl.setState('close'); + } else { + ctrl.open(); + ctrl.setState('open'); + } }; } } -}]); +}]) .directive('drawerClose', ['$rootScope', function($rootScope) { return { @@ -186,4 +214,4 @@ angular.module('ionic.contrib.drawer', ['ionic']) } }]); -})(); +})(); \ No newline at end of file From 0bd14c0514361cd844a45b6de0ff31a6e92e86e6 Mon Sep 17 00:00:00 2001 From: Indermohan Singh Date: Mon, 19 Jan 2015 17:46:28 +0530 Subject: [PATCH 2/3] Changing State in Controller --- ionic.contrib.drawer.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ionic.contrib.drawer.js b/ionic.contrib.drawer.js index e3033ad..2071f77 100644 --- a/ionic.contrib.drawer.js +++ b/ionic.contrib.drawer.js @@ -147,6 +147,7 @@ angular.module('ionic.contrib.drawer', ['ionic']) el.style.transform = el.style.webkitTransform = 'translate3d(100%, 0, 0)'; } }); + ctrl.setState('close'); }; this.open = function() { @@ -158,6 +159,7 @@ angular.module('ionic.contrib.drawer', ['ionic']) el.style.transform = el.style.webkitTransform = 'translate3d(0%, 0, 0)'; } }); + ctrl.setState('open'); }; this.isOpen = function() { @@ -182,20 +184,16 @@ angular.module('ionic.contrib.drawer', ['ionic']) $scope.openDrawer = function() { console.log('open'); ctrl.open(); - ctrl.setState('open'); }; $scope.closeDrawer = function() { console.log('close'); ctrl.close(); - ctrl.setState('close'); }; $scope.toggleDrawer = function() { if(ctrl.isOpen()) { ctrl.close(); - ctrl.setState('close'); } else { ctrl.open(); - ctrl.setState('open'); } }; } From 1fdf14104ef3a0c8110e1780aea05a7d99e92e66 Mon Sep 17 00:00:00 2001 From: Indermohan Singh Date: Mon, 19 Jan 2015 19:26:18 +0530 Subject: [PATCH 3/3] State consistent with Dragging --- ionic.contrib.drawer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ionic.contrib.drawer.js b/ionic.contrib.drawer.js index 2071f77..dab95e2 100644 --- a/ionic.contrib.drawer.js +++ b/ionic.contrib.drawer.js @@ -137,6 +137,9 @@ angular.module('ionic.contrib.drawer', ['ionic']) doEndDrag(e); }, $document); + this.setState = function(value) { + drawerState = value; + }; this.close = function() { enableAnimation(); @@ -147,7 +150,7 @@ angular.module('ionic.contrib.drawer', ['ionic']) el.style.transform = el.style.webkitTransform = 'translate3d(100%, 0, 0)'; } }); - ctrl.setState('close'); + drawerState = 'close'; }; this.open = function() { @@ -159,7 +162,7 @@ angular.module('ionic.contrib.drawer', ['ionic']) el.style.transform = el.style.webkitTransform = 'translate3d(0%, 0, 0)'; } }); - ctrl.setState('open'); + drawerState = 'open'; }; this.isOpen = function() { @@ -169,10 +172,6 @@ angular.module('ionic.contrib.drawer', ['ionic']) return true; } }; - - this.setState = function(value) { - drawerState = value; - }; }]) .directive('drawer', ['$rootScope', '$ionicGesture', function($rootScope, $ionicGesture) { @@ -195,6 +194,7 @@ angular.module('ionic.contrib.drawer', ['ionic']) } else { ctrl.open(); } + console.log(ctrl.isOpen()); }; } }