Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Toggle Drawer Option and Semicolon Bug Fix #4

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<drawer side="left">
<ion-content>
<h2>Menu</h2>
<button ng-click="closeDrawer()">Close</button>
<button ng-click="toggleDrawer()">Close</button>
<ion-list>
<ion-item>Friends</ion-item>
<ion-item>Favorites</ion-item>
Expand Down
30 changes: 28 additions & 2 deletions ionic.contrib.drawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
};
Expand Down Expand Up @@ -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';
}
});
};
Expand Down Expand Up @@ -132,6 +137,9 @@ angular.module('ionic.contrib.drawer', ['ionic'])
doEndDrag(e);
}, $document);

this.setState = function(value) {
drawerState = value;
};

this.close = function() {
enableAnimation();
Expand All @@ -142,6 +150,7 @@ angular.module('ionic.contrib.drawer', ['ionic'])
el.style.transform = el.style.webkitTransform = 'translate3d(100%, 0, 0)';
}
});
drawerState = 'close';
};

this.open = function() {
Expand All @@ -153,6 +162,15 @@ angular.module('ionic.contrib.drawer', ['ionic'])
el.style.transform = el.style.webkitTransform = 'translate3d(0%, 0, 0)';
}
});
drawerState = 'open';
};

this.isOpen = function() {
if(drawerState === 'close') {
return false;
} else {
return true;
}
};
}])

Expand All @@ -170,9 +188,17 @@ angular.module('ionic.contrib.drawer', ['ionic'])
console.log('close');
ctrl.close();
};
$scope.toggleDrawer = function() {
if(ctrl.isOpen()) {
ctrl.close();
} else {
ctrl.open();
}
console.log(ctrl.isOpen());
};
}
}
}]);
}])

.directive('drawerClose', ['$rootScope', function($rootScope) {
return {
Expand All @@ -186,4 +212,4 @@ angular.module('ionic.contrib.drawer', ['ionic'])
}
}]);

})();
})();