swipe to change pages and swipe to show or hide sidebar menu

This commit is contained in:
Gustavo Maximiliano Cortez 2014-12-08 05:34:59 -03:00
parent 6553d43da7
commit aad053daec
3 changed files with 62 additions and 1 deletions

View File

@ -20,7 +20,10 @@
</style>
<link rel="shortcut icon" href="img/favicon.ico">
</head>
<body>
<body
ng-controller="IndexController"
ng-swipe-left="swipe()"
ng-swipe-right="swipe(true)">
<div id="loading" class="loadingpage">
<img src="img/ajax-loader.gif" alt="Loading...">

12
js/controllers/index.js Normal file
View File

@ -0,0 +1,12 @@
'use strict';
angular.module('copayApp.controllers').controller('IndexController', function($scope, go) {
$scope.init = function() {
};
$scope.swipe = function(invert) {
go.swipe(invert);
};
});

View File

@ -14,6 +14,21 @@ angular.module('copayApp.services').factory('go', function($window, $location) {
elem.removeClass('move-left');
};
var showSidebar = function(invert) {
if (typeof document === 'undefined')
return;
// hack to hide sidebars and use ng-click (no href=)
var win = angular.element($window);
var elem = angular.element(document.querySelector('#off-canvas-wrap'))
if (invert) {
elem.addClass('move-right');
}
else {
elem.addClass('move-left');
}
};
root.go = function(path) {
var parts = path.split('#');
$location.path(parts[0]);
@ -22,5 +37,36 @@ angular.module('copayApp.services').factory('go', function($window, $location) {
hideSidebars();
};
var pages = [
'/homeWallet',
'/receive',
'/send',
'/history'
];
var sidebarActive = false;
root.swipe = function(invert) {
var currentPage = $location.path();
var pageIndex;
if (!sidebarActive) {
pageIndex = invert ? pages.indexOf(currentPage) - 1 : pages.indexOf(currentPage) + 1;
}
else {
pageIndex = pages.indexOf(currentPage);
}
var page = pages[pageIndex];
if (pageIndex === -1 || pageIndex === 4) {
sidebarActive = true;
showSidebar(invert);
}
else if (pageIndex >= 0 && pageIndex <= 3) {
var goTo = pages[pageIndex];
sidebarActive = false;
root.go(goTo);
}
};
return root;
});