diff --git a/js/controllers/routeController.js b/js/controllers/routeController.js deleted file mode 100644 index 486bc82653..0000000000 --- a/js/controllers/routeController.js +++ /dev/null @@ -1,115 +0,0 @@ -/** - * Adapted from Backbone.js - */ -(function(ionic) { -'use strict'; - var optionalParam = /\((.*?)\)/g; - var namedParam = /(\(\?)?:\w+/g; - var splatParam = /\*\w+/g; - var escapeRegExp = /[\-{}\[\]+?.,\\\^$|#\s]/g; - - // Cached regex for stripping a leading hash/slash and trailing space. - var routeStripper = /^[#\/]|\s+$/g; - - // Cached regex for stripping leading and trailing slashes. - var rootStripper = /^\/+|\/+$/g; - - // Cached regex for removing a trailing slash. - var trailingSlash = /\/$/; - - ionic.controllers.RouteViewController = ionic.controllers.ViewController.inherit({ - initialize: function(options) { - this.options = options; - - this.root = this.options.root || '/'; - this.root = ('/' + this.root + '/').replace(rootStripper, '/'); - - this.handlers = []; - - this._bindEvents(); - - this.location = window.location; - this.history = window.history; - }, - - when: function(route, callback) { - var _this = this; - - route = this._routeToRegExp(route); - - this.handlers.unshift({ - route: route, - callback: function(fragment) { - var args = _this._extractParameters(route, fragment); - callback && callback.apply(_this, args); - } - }); - }, - - // Convert a route string into a regular expression, suitable for matching - // against the current location hash. - _routeToRegExp: function(route) { - route = route.replace(escapeRegExp, '\\$&') - .replace(optionalParam, '(?:$1)?') - .replace(namedParam, function(match, optional){ - return optional ? match : '([^\/]+)'; - }) - .replace(splatParam, '(.*?)'); - return new RegExp('^' + route + '$'); - }, - - // Given a route, and a URL fragment that it matches, return the array of - // extracted decoded parameters. Empty or unmatched parameters will be - // treated as `null` to normalize cross-browser behavior. - _extractParameters: function(route, fragment) { - var params = route.exec(fragment).slice(1); - var extracted = []; - for(var i = 0; i < params.length; i++) { - if(param) { - extracted.push(decodeURIComponent(param)); - } - } - }, - - _bindEvents: function() { - var _this = this; - - window.addEventListener('popstate', function(event) { - _this.checkUrl(event); - }); - }, - checkUrl: function(e) { - var current = this.getFragment(); - if (current === this.fragment) return false; - this.loadUrl() || this.loadUrl(this.getHash()); - }, - getFragment: function(fragment, forcePushState) { - if (fragment === null) { - fragment = this.location.pathname; - var root = this.root.replace(this.trailingSlash, ''); - if (!fragment.indexOf(root)) fragment = fragment.substr(root.length); - } - return fragment.replace(routeStripper, ''); - }, - getHash: function(window) { - var match = (window || this).location.href.match(/#(.*)$/); - return match ? match[1] : ''; - }, - - // Attempt to load the current URL fragment. If a route succeeds with a - // match, returns `true`. If no defined routes matches the fragment, - // returns `false`. - loadUrl: function(fragmentOverride) { - var fragment = this.fragment = this.getFragment(fragmentOverride); - var matched = false; - for(var i = 0; i < this.handlers.length; i++) { - var h = this.handlers[i]; - if (h.route.test(fragment)) { - h.callback(fragment); - matched = true; - } - } - return matched; - }, - }); -})(window.ionic); diff --git a/js/ext/angular/src/directive/ionicNavRouter.js b/js/ext/angular/src/directive/ionicNavRouter.js deleted file mode 100644 index ff72957df4..0000000000 --- a/js/ext/angular/src/directive/ionicNavRouter.js +++ /dev/null @@ -1,412 +0,0 @@ -(function() { -'use strict'; - -/** - * @description - * The NavController is a navigation stack View Controller modelled off of - * UINavigationController from Cocoa Touch. With the Nav Controller, you can - * "push" new "pages" on to the navigation stack, and then pop them off to go - * back. The NavController controls a navigation bar with a back button and title - * which updates as the pages switch. - * - * The NavController makes sure to not recycle scopes of old pages - * so that a pop will still show the same state that the user left. - * - * However, once a page is popped, its scope is destroyed and will have to be - * recreated then next time it is pushed. - * - */ - -var actualLocation = null; - -angular.module('ionic.ui.navRouter', ['ionic.service.gesture']) - -.run(['$rootScope', function($rootScope) { - $rootScope.stackCursorPosition = 0; -}]) - -.directive('navRouter', ['$rootScope', '$timeout', '$location', '$window', '$route', function($rootScope, $timeout, $location, $window, $route) { - return { - restrict: 'AC', - // So you can require being under this - controller: ['$scope', '$element', function($scope, $element) { - this.navBar = { - isVisible: false - }; - $scope.navController = this; - - this.goBack = function() { - $scope.direction = 'back'; - }; - }], - - link: function($scope, $element, $attr, ctrl) { - if(!$element.length) return; - - $scope.animation = $attr.animation; - - $element[0].classList.add('noop-animation'); - - var isFirst = true; - // Store whether we did an animation yet, to know if - // we should let the first state animate - var didAnimate = false; - - var initTransition = function() { - //$element.addClass($scope.animation); - }; - - var reverseTransition = function() { - $element[0].classList.remove('noop-animation'); - $element[0].classList.add($scope.animation); - $element[0].classList.add('reverse'); - }; - - var forwardTransition = function() { - $element[0].classList.remove('noop-animation'); - $element[0].classList.remove('reverse'); - $element[0].classList.add($scope.animation); - }; - - $scope.$on('$routeChangeSuccess', function(e, a) { - }); - $scope.$on('$routeChangeStart', function(e, next, current) { - var back, historyState = $window.history.state; - - back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition)); - - if(isFirst || (next && next.$$route && next.$$route.originalPath === "")) { - // Don't animate - isFirst = false; - return; - } - - if(didAnimate || $rootScope.stackCursorPosition > 0) { - didAnimate = true; - if(back) { - reverseTransition(); - } else { - forwardTransition(); - } - } - }); - - $scope.$on('$locationChangeSuccess', function(a, b, c) { - // Store the new location - $rootScope.actualLocation = $location.path(); - if(isFirst && $location.path() !== '/') { - isFirst = false; - } - }); - - $scope.$on('navRouter.goBack', function(e) { - ctrl.goBack(); - }); - - - // Keep track of location changes and update a stack pointer that tracks whether we are - // going forwards or back - $scope.$watch(function () { return $location.path(); }, function (newLocation, oldLocation) { - if($rootScope.actualLocation === newLocation) { - if(oldLocation === '') {// || newLocation == '/') { - // initial route, skip this - return; - } - - var back, historyState = $window.history.state; - - back = $scope.direction == 'back' || (!!(historyState && historyState.position <= $rootScope.stackCursorPosition)); - - if (back) { - //back button - $rootScope.stackCursorPosition--; - } else { - //forward button - $rootScope.stackCursorPosition++; - } - - $scope.direction = 'forwards'; - - } else { - var currentRouteBeforeChange = $route.current; - - if (currentRouteBeforeChange) { - - $window.history.replaceState({ - position: $rootScope.stackCursorPosition - }); - - $rootScope.stackCursorPosition++; - } - } - }); - } - }; -}]) - -/** - * Our Nav Bar directive which updates as the controller state changes. - */ -.directive('navBar', ['$rootScope', '$animate', '$compile', function($rootScope, $animate, $compile) { - - /** - * Perform an animation between one tab bar state and the next. - * Right now this just animates the titles. - */ - var animate = function($scope, $element, oldTitle, data, cb) { - var title, nTitle, oTitle, titles = $element[0].querySelectorAll('.title'); - - var newTitle = data.title; - if(!oldTitle || oldTitle === newTitle) { - cb(); - return; - } - - // Clone the old title and add a new one so we can show two animating in and out - // add ng-leave and ng-enter during creation to prevent flickering when they are swapped during animation - title = angular.element(titles[0]); - oTitle = $compile('
')($scope); - title.replaceWith(oTitle); - nTitle = $compile('')($scope); - - var insert = $element[0].firstElementChild || null; - - // Insert the new title - $animate.enter(nTitle, $element, insert && angular.element(insert), function() { - cb(); - }); - - // Remove the old title - $animate.leave(angular.element(oTitle), function() { - }); - }; - - return { - restrict: 'E', - require: '^navRouter', - replace: true, - scope: { - type: '@', - backButtonType: '@', - backButtonLabel: '@', - backButtonIcon: '@', - alignTitle: '@' - }, - template: '