copay/js/services/go.js

99 lines
2.2 KiB
JavaScript
Raw Normal View History

2014-12-07 07:44:50 -08:00
'use strict';
angular.module('copayApp.services').factory('go', function($window, $rootScope, $location) {
2014-12-07 07:44:50 -08:00
var root = {};
var hideSidebars = function() {
2014-12-07 09:12:58 -08:00
if (typeof document === 'undefined')
return;
2014-12-07 07:44:50 -08:00
// hack to hide sidebars and use ng-click (no href=)
var win = angular.element($window);
2014-12-07 09:12:58 -08:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'))
2014-12-07 07:44:50 -08:00
elem.removeClass('move-right');
elem.removeClass('move-left');
};
2014-12-08 07:45:12 -08:00
var toggleSidebar = function(invert) {
if (typeof document === 'undefined')
return;
2014-12-08 07:45:12 -08:00
var elem = angular.element(document.querySelector('#off-canvas-wrap'));
var leftbarActive = angular.element(document.getElementsByClassName('move-right')).length;
if (invert) {
2014-12-18 13:58:35 -08:00
if ($rootScope.iden && !$rootScope.hideNavigation) {
elem.addClass('move-right');
2014-12-08 07:45:12 -08:00
}
}
2014-12-08 07:45:12 -08:00
else {
if (leftbarActive) {
hideSidebars();
}
}
};
2014-12-09 11:11:56 -08:00
root.openExternalLink = function(url) {
var ref = window.open(url, '_blank', 'location=no');
};
root.path = function(path) {
2014-12-07 07:44:50 -08:00
var parts = path.split('#');
$location.path(parts[0]);
if (parts[1])
$location.hash(parts[1]);
hideSidebars();
};
root.swipe = function(invert) {
2014-12-08 07:45:12 -08:00
toggleSidebar(invert);
};
root.walletHome = function() {
var w = $rootScope.wallet;
preconditions.checkState(w);
$rootScope.starting = false;
2014-12-09 06:52:01 -08:00
if (!w.isComplete()) {
root.path('copayers');
} else {
if ($rootScope.pendingPayment) {
2014-12-10 15:30:36 -08:00
if ($rootScope.walletForPaymentSet) {
root.path('send');
} else {
root.path('selectWalletForPayment');
}
} else {
root.path('homeWallet');
}
}
};
root.home = function() {
if ($rootScope.iden)
root.walletHome();
else
root.path('/');
};
root.send = function() {
$location.path('send');
};
2014-12-10 07:07:26 -08:00
// Global go. This should be in a better place TODO
// We dont do a 'go' directive, to use the benefits of ng-touch with ng-click
$rootScope.go = function (path) {
root.path(path);
};
$rootScope.openExternalLink = function (url) {
root.openExternalLink(url);
};
2014-12-07 07:44:50 -08:00
return root;
});