From 946672cd847aa23636eaf70a6dd21421e9471aef Mon Sep 17 00:00:00 2001 From: Max Lynch Date: Sun, 22 Sep 2013 23:30:53 -0500 Subject: [PATCH] Renamed JS files, removed ionic- prefix. --- js/controllers/tabBarViewController.js | 122 ++++++++++++++++++ js/{ionic-events.js => events.js} | 0 js/{ionic-gestures.js => gestures.js} | 0 js/{ionic-init.js => ionic.js} | 0 js/{ionic-utils.js => utils.js} | 0 ...ic-viewcontroller.js => viewController.js} | 0 6 files changed, 122 insertions(+) create mode 100644 js/controllers/tabBarViewController.js rename js/{ionic-events.js => events.js} (100%) rename js/{ionic-gestures.js => gestures.js} (100%) rename js/{ionic-init.js => ionic.js} (100%) rename js/{ionic-utils.js => utils.js} (100%) rename js/{ionic-viewcontroller.js => viewController.js} (100%) diff --git a/js/controllers/tabBarViewController.js b/js/controllers/tabBarViewController.js new file mode 100644 index 0000000000..4d16eea3de --- /dev/null +++ b/js/controllers/tabBarViewController.js @@ -0,0 +1,122 @@ +(function(window, document, ionic) { + +TabBarController = function(options) { + this.tabBar = options.tabBar; + + this._bindEvents(); + + this.controllers = []; + + var controllers = options.controllers || []; + + for(var i = 0; i < controllers.length; i++) { + this.addController(controllers[i]); + } + + // Bind or set our tabWillChange callback + this.controllerWillChange = options.controllerWillChange || function(controller) {}; + this.controllerChanged = options.controllerChanged || function(controller) {}; + + this.setSelectedController(0); +}; + +TabBarController.prototype = { + // Start listening for events on our tab bar + _bindEvents: function() { + var _this = this; + + this.tabBar.tryTabSelect = function(index) { + _this.setSelectedController(index); + }; + }, + + + selectController: function(index) { + var shouldChange = true; + + // Check if we should switch to this tab. This lets the app + // cancel tab switches if the context isn't right, for example. + if(this.controllerWillChange) { + if(this.controllerWillChange(this.controllers[index], index) === false) { + shouldChange = false; + } + } + + if(shouldChange) { + this.setSelectedController(index); + this.controllerChanged && this.controllerChanged(this.selectedController, this.selectedIndex); + } + }, + + // Force the selection of a controller at the given index + setSelectedController: function(index) { + if(index >= this.controllers.length) { + return; + } + this.selectedController = this.controllers[index]; + this.selectedIndex = index; + + this._showController(index); + this.tabBar.setSelectedItem(index); + }, + + _showController: function(index) { + var c; + + for(var i = 0, j = this.controllers.length; i < j; i ++) { + c = this.controllers[i]; + //c.detach && c.detach(); + c.isVisible = false; + c.visibilityChanged && c.visibilityChanged(); + } + + c = this.controllers[index]; + //c.attach && c.attach(); + c.isVisible = true; + c.visibilityChanged && c.visibilityChanged(); + }, + + _clearSelected: function() { + this.selectedController = null; + this.selectedIndex = -1; + }, + + // Return the tab at the given index + getController: function(index) { + return this.controllers[index]; + }, + + // Return the current tab list + getControllers: function() { + return this.controllers; + }, + + // Get the currently selected tab + getSelectedController: function() { + return this.selectedController; + }, + + // Add a tab + addController: function(controller) { + this.controllers.push(controller); + + this.tabBar.addItem({ + title: controller.title, + icon: controller.icon + }); + + // If we don't have a selected controller yet, select the first one. + if(!this.selectedController) { + this.setSelectedController(0); + } + }, + + // Set the tabs and select the first + setControllers: function(controllers) { + this.controllers = controllers; + this._clearSelected(); + this.selectController(0); + }, +} + +})(this, document, ion = this.ionic || {}); diff --git a/js/ionic-events.js b/js/events.js similarity index 100% rename from js/ionic-events.js rename to js/events.js diff --git a/js/ionic-gestures.js b/js/gestures.js similarity index 100% rename from js/ionic-gestures.js rename to js/gestures.js diff --git a/js/ionic-init.js b/js/ionic.js similarity index 100% rename from js/ionic-init.js rename to js/ionic.js diff --git a/js/ionic-utils.js b/js/utils.js similarity index 100% rename from js/ionic-utils.js rename to js/utils.js diff --git a/js/ionic-viewcontroller.js b/js/viewController.js similarity index 100% rename from js/ionic-viewcontroller.js rename to js/viewController.js