From 9513eb60baff1be6cd425fbe068154647fd5f948 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Wed, 3 Dec 2014 01:04:40 -0600 Subject: [PATCH] style(jscs): code formatting --- js/angular/controller/headerBarController.js | 2 +- js/angular/controller/viewController.js | 3 +- js/angular/deprecated.js | 5 +- js/angular/directive/ngClick.js | 4 +- js/angular/directive/sideMenuContent.js | 8 +- js/angular/directive/tab.js | 8 +- js/angular/directive/tabNav.js | 2 +- js/angular/directive/tabs.js | 5 +- js/angular/service/angularOverrides.js | 16 +-- js/angular/service/attachDrag.js | 2 +- js/angular/service/backdrop.js | 4 +- js/angular/service/body.js | 8 +- js/angular/service/position.js | 12 +- js/angular/service/viewService.js | 2 +- js/utils/platform.js | 84 ++++++------ js/utils/poly.js | 6 +- js/utils/tap.js | 128 +++++++++---------- js/utils/utils.js | 10 +- js/utils/viewport.js | 46 +++---- 19 files changed, 176 insertions(+), 179 deletions(-) diff --git a/js/angular/controller/headerBarController.js b/js/angular/controller/headerBarController.js index c4e905f883..ae65e4272a 100644 --- a/js/angular/controller/headerBarController.js +++ b/js/angular/controller/headerBarController.js @@ -74,7 +74,7 @@ function($scope, $element, $attrs, $q, $ionicConfig, $ionicHistory) { self.updateBackButton = function() { - if ( (isBackShown && isNavBackShown && isBackEnabled) !== isBackElementShown) { + if ((isBackShown && isNavBackShown && isBackEnabled) !== isBackElementShown) { isBackElementShown = isBackShown && isNavBackShown && isBackEnabled; var backBtnEle = getEle(BACK_BUTTON); backBtnEle && backBtnEle.classList[ isBackElementShown ? 'remove' : 'add' ](HIDE); diff --git a/js/angular/controller/viewController.js b/js/angular/controller/viewController.js index 9ef21e7e21..ceec5af86a 100644 --- a/js/angular/controller/viewController.js +++ b/js/angular/controller/viewController.js @@ -15,7 +15,7 @@ function($scope, $element, $attrs, $compile, $rootScope, $ionicViewSwitcher) { var deregisters = []; var viewTitle; - var deregIonNavBarInit = $scope.$on('ionNavBar.init', function(ev, delegateHandle){ + var deregIonNavBarInit = $scope.$on('ionNavBar.init', function(ev, delegateHandle) { // this view has its own ion-nav-bar, remember the navBarDelegateHandle for this view ev.stopPropagation(); navBarDelegateHandle = delegateHandle; @@ -129,4 +129,3 @@ function($scope, $element, $attrs, $compile, $rootScope, $ionicViewSwitcher) { }; }]); - diff --git a/js/angular/deprecated.js b/js/angular/deprecated.js index 22d6fceeeb..bb95297919 100644 --- a/js/angular/deprecated.js +++ b/js/angular/deprecated.js @@ -8,7 +8,7 @@ var deprecated = { method: function(msg, log, fn) { var called = false; - return function deprecatedMethod(){ + return function deprecatedMethod() { if (!called) { called = true; log(msg); @@ -19,7 +19,7 @@ var deprecated = { field: function(msg, log, parent, field, val) { var called = false; - var getter = function(){ + var getter = function() { if (!called) { called = true; log(msg); @@ -42,4 +42,3 @@ var deprecated = { return; } }; - diff --git a/js/angular/directive/ngClick.js b/js/angular/directive/ngClick.js index 56951ae3d0..73598442b2 100644 --- a/js/angular/directive/ngClick.js +++ b/js/angular/directive/ngClick.js @@ -35,10 +35,10 @@ IonicModule }; }]) -.directive('ionStopEvent', function () { +.directive('ionStopEvent', function() { return { restrict: 'A', - link: function (scope, element, attr) { + link: function(scope, element, attr) { element.bind(attr.ionStopEvent, eventStopPropagation); } }; diff --git a/js/angular/directive/sideMenuContent.js b/js/angular/directive/sideMenuContent.js index 19387e4ebf..ca4127be6c 100644 --- a/js/angular/directive/sideMenuContent.js +++ b/js/angular/directive/sideMenuContent.js @@ -74,14 +74,14 @@ function($timeout, $ionicGesture, $window) { function onDragX(e) { if (!sideMenuCtrl.isDraggableTarget(e)) return; - if ( getPrimaryScrollAxis(e) == 'x') { + if (getPrimaryScrollAxis(e) == 'x') { sideMenuCtrl._handleDrag(e); e.gesture.srcEvent.preventDefault(); } } function onDragY(e) { - if ( getPrimaryScrollAxis(e) == 'x' ) { + if (getPrimaryScrollAxis(e) == 'x') { e.gesture.srcEvent.preventDefault(); } } @@ -115,9 +115,9 @@ function($timeout, $ionicGesture, $window) { var xDistance = Math.abs(endCoord.x - startCoord.x); var yDistance = Math.abs(endCoord.y - startCoord.y); - var scrollAxis = ( xDistance < yDistance ? 'y' : 'x' ); + var scrollAxis = (xDistance < yDistance ? 'y' : 'x'); - if ( Math.max(xDistance, yDistance) > 30 ) { + if (Math.max(xDistance, yDistance) > 30) { // ok, we pretty much know which way they're going // let's lock it in primaryScrollAxis = scrollAxis; diff --git a/js/angular/directive/tab.js b/js/angular/directive/tab.js index dc2356b7f0..cb8b9c1ede 100644 --- a/js/angular/directive/tab.js +++ b/js/angular/directive/tab.js @@ -42,7 +42,7 @@ IonicModule function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) { //Returns ' key="value"' if value exists - function attrStr(k,v) { + function attrStr(k, v) { return angular.isDefined(v) ? ' ' + k + '="' + v + '"' : ''; } return { @@ -83,7 +83,7 @@ function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) { tabContentEle.children[0].classList.add('view-container'); isNavView = true; } - if(childElementCount === 1) { + if (childElementCount === 1) { // make the 1 child element the primary tab content container tabContentEle = tabContentEle.children[0]; } @@ -152,7 +152,7 @@ function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) { childScope = $scope.$new(); childElement = jqLite(tabContentEle); $ionicViewSwitcher.viewEleIsActive(childElement, true); - tabsCtrl.$element.append( childElement ); + tabsCtrl.$element.append(childElement); $compile(childElement)(childScope); isTabContentAttached = true; } @@ -163,7 +163,7 @@ function($compile, $ionicConfig, $ionicBind, $ionicViewSwitcher) { } else if (isTabContentAttached && childElement) { // this tab should NOT be selected, and it is already in the DOM - if ( $ionicConfig.views.maxCache() > 0 ) { + if ($ionicConfig.views.maxCache() > 0) { // keep the tabs in the DOM, only css hide it $ionicViewSwitcher.viewEleIsActive(childElement, false); diff --git a/js/angular/directive/tabNav.js b/js/angular/directive/tabNav.js index e1e0d082ac..99e279264b 100644 --- a/js/angular/directive/tabNav.js +++ b/js/angular/directive/tabNav.js @@ -43,7 +43,7 @@ IonicModule } $scope.isHidden = function() { - if($attrs.hidden === 'true' || $attrs.hidden === true)return true; + if ($attrs.hidden === 'true' || $attrs.hidden === true) return true; return false; }; diff --git a/js/angular/directive/tabs.js b/js/angular/directive/tabs.js index 8f6cf60451..18e6bdc466 100644 --- a/js/angular/directive/tabs.js +++ b/js/angular/directive/tabs.js @@ -60,8 +60,7 @@ function($ionicTabsDelegate, $ionicConfig, $ionicHistory) { innerElement.append(tElement.contents()); tElement.append(innerElement) - .addClass( 'tabs-' + $ionicConfig.tabs.position() ) - .addClass( 'tabs-' + $ionicConfig.tabs.style() ); + .addClass('tabs-' + $ionicConfig.tabs.position() + ' tabs-' + $ionicConfig.tabs.style()); return { pre: prelink, post: postLink }; function prelink($scope, $element, $attr, tabsCtrl) { @@ -80,7 +79,7 @@ function($ionicTabsDelegate, $ionicConfig, $ionicHistory) { $scope.$hasTabsTop = isTabsTop && !isHidden; }); - $scope.$on('$destroy', function(){ + $scope.$on('$destroy', function() { // variable to inform child tabs that they're all being blown away // used so that while destorying an individual tab, each one // doesn't select the next tab as the active one, which causes unnecessary diff --git a/js/angular/service/angularOverrides.js b/js/angular/service/angularOverrides.js index bc507f8475..c6e312a533 100644 --- a/js/angular/service/angularOverrides.js +++ b/js/angular/service/angularOverrides.js @@ -2,18 +2,18 @@ jqLite.prototype.addClass = function(cssClasses) { var x, y, cssClass, el, splitClasses, existingClasses; if (cssClasses && cssClasses != 'ng-scope' && cssClasses != 'ng-isolate-scope') { - for(x=0; x 0) { + if (v.indexOf('.') > 0) { v = v.replace('.', '_'); } else { v += '_0'; @@ -136,9 +136,9 @@ this.platforms.push(platform + v.split('_')[0]); this.platforms.push(platform + v); - if(this.isAndroid() && version < 4.4) { + if (this.isAndroid() && version < 4.4) { grade = (version < 4 ? 'c' : 'b'); - } else if(this.isWindowsPhone()) { + } else if (this.isWindowsPhone()) { grade = 'b'; } } @@ -161,7 +161,7 @@ * @returns {boolean} Whether we are running on iPad. */ isIPad: function() { - if( /iPad/i.test(ionic.Platform.navigator.platform) ) { + if (/iPad/i.test(ionic.Platform.navigator.platform)) { return true; } return /iPad/i.test(this.ua); @@ -198,7 +198,7 @@ */ platform: function() { // singleton to get the platform name - if(platformName === null) this.setPlatform(this.device().platform); + if (platformName === null) this.setPlatform(this.device().platform); return platformName; }, @@ -206,13 +206,13 @@ * @private */ setPlatform: function(n) { - if(typeof n != 'undefined' && n !== null && n.length) { + if (typeof n != 'undefined' && n !== null && n.length) { platformName = n.toLowerCase(); - } else if(this.ua.indexOf('Android') > 0) { + } else if (this.ua.indexOf('Android') > 0) { platformName = ANDROID; - } else if(this.ua.indexOf('iPhone') > -1 || this.ua.indexOf('iPad') > -1 || this.ua.indexOf('iPod') > -1) { + } else if (this.ua.indexOf('iPhone') > -1 || this.ua.indexOf('iPad') > -1 || this.ua.indexOf('iPod') > -1) { platformName = IOS; - } else if(this.ua.indexOf('Windows Phone') > -1) { + } else if (this.ua.indexOf('Windows Phone') > -1) { platformName = WINDOWS_PHONE; } else { platformName = ionic.Platform.navigator.platform && navigator.platform.toLowerCase().split(' ')[0] || ''; @@ -226,7 +226,7 @@ */ version: function() { // singleton to get the platform version - if(platformVersion === null) this.setVersion(this.device().version); + if (platformVersion === null) this.setVersion(this.device().version); return platformVersion; }, @@ -234,10 +234,10 @@ * @private */ setVersion: function(v) { - if(typeof v != 'undefined' && v !== null) { + if (typeof v != 'undefined' && v !== null) { v = v.split('.'); v = parseFloat(v[0] + '.' + (v.length > 1 ? v[1] : 0)); - if(!isNaN(v)) { + if (!isNaN(v)) { platformVersion = v; return; } @@ -252,10 +252,10 @@ 'ios': /OS (\d+)_(\d+)?/, 'windowsphone': /Windows Phone (\d+).(\d+)?/ }; - if(versionMatch[pName]) { - v = this.ua.match( versionMatch[pName] ); - if(v && v.length > 2) { - platformVersion = parseFloat( v[1] + '.' + v[2] ); + if (versionMatch[pName]) { + v = this.ua.match(versionMatch[pName]); + if (v && v.length > 2) { + platformVersion = parseFloat(v[1] + '.' + v[2]); } } }, @@ -264,14 +264,14 @@ is: function(type) { type = type.toLowerCase(); // check if it has an array of platforms - if(this.platforms) { - for(var x = 0; x < this.platforms.length; x++) { - if(this.platforms[x] === type) return true; + if (this.platforms) { + for (var x = 0; x < this.platforms.length; x++) { + if (this.platforms[x] === type) return true; } } // exact match var pName = this.platform(); - if(pName) { + if (pName) { return pName === type.toLowerCase(); } @@ -285,7 +285,7 @@ * @description Exit the app. */ exitApp: function() { - this.ready(function(){ + this.ready(function() { navigator.app && navigator.app.exitApp && navigator.app.exitApp(); }); }, @@ -299,10 +299,10 @@ showStatusBar: function(val) { // Only useful when run within cordova this._showStatusBar = val; - this.ready(function(){ + this.ready(function() { // run this only when or if the platform (cordova) is ready - ionic.requestAnimationFrame(function(){ - if(ionic.Platform._showStatusBar) { + ionic.requestAnimationFrame(function() { + if (ionic.Platform._showStatusBar) { // they do not want it to be full screen window.StatusBar && window.StatusBar.show(); document.body.classList.remove('status-bar-hide'); @@ -328,22 +328,22 @@ this.isFullScreen = (showFullScreen !== false); // add/remove the fullscreen classname to the body - ionic.DomUtil.ready(function(){ + ionic.DomUtil.ready(function() { // run this only when or if the DOM is ready - ionic.requestAnimationFrame(function(){ + ionic.requestAnimationFrame(function() { // fixing pane height before we adjust this panes = document.getElementsByClassName('pane'); - for(var i = 0;i= arr.length) { var k = new_index - arr.length; while ((k--) + 1) { @@ -107,7 +107,7 @@ if (protoProps && protoProps.hasOwnProperty('constructor')) { child = protoProps.constructor; } else { - child = function(){ return parent.apply(this, arguments); }; + child = function() { return parent.apply(this, arguments); }; } // Add static properties to the constructor function, if supplied. @@ -115,7 +115,7 @@ // Set the prototype chain to inherit from `parent`, without calling // `parent`'s constructor function. - var Surrogate = function(){ this.constructor = child; }; + var Surrogate = function() { this.constructor = child; }; Surrogate.prototype = parent.prototype; child.prototype = new Surrogate(); @@ -133,7 +133,7 @@ // Extend adapted from Underscore.js extend: function(obj) { var args = Array.prototype.slice.call(arguments, 1); - for(var i = 0; i < args.length; i++) { + for (var i = 0; i < args.length; i++) { var source = args[i]; if (source) { for (var prop in source) { @@ -156,7 +156,7 @@ var index = uid.length; var digit; - while(index) { + while (index) { index--; digit = uid[index].charCodeAt(0); if (digit == 57 /*'9'*/) { diff --git a/js/utils/viewport.js b/js/utils/viewport.js index 65dd6ea1b9..897d18e0e3 100644 --- a/js/utils/viewport.js +++ b/js/utils/viewport.js @@ -14,18 +14,18 @@ ionic.viewport = { function viewportLoadTag() { var x; - for(x=0; x 1 ? keyValue[1] : '_'); } @@ -50,10 +50,10 @@ function viewportUpdate() { delete viewportProperties.height; viewportProperties.width = DEVICE_WIDTH; - if( p.isIPad() ) { + if (p.isIPad()) { // iPad - if( version > 7 ) { + if (version > 7) { // iPad >= 7.1 // https://issues.apache.org/jira/browse/CB-4323 delete viewportProperties.width; @@ -61,41 +61,41 @@ function viewportUpdate() { } else { // iPad <= 7.0 - if( p.isWebView() ) { + if (p.isWebView()) { // iPad <= 7.0 WebView - if( orientation == 90 ) { + if (orientation == 90) { // iPad <= 7.0 WebView Landscape viewportProperties.height = '0'; - } else if(version == 7) { + } else if (version == 7) { // iPad <= 7.0 WebView Portait viewportProperties.height = DEVICE_HEIGHT; } } else { // iPad <= 6.1 Browser - if(version < 7) { + if (version < 7) { viewportProperties.height = '0'; } } } - } else if( p.isIOS() ) { + } else if (p.isIOS()) { // iPhone - if( p.isWebView() ) { + if (p.isWebView()) { // iPhone WebView - if(version > 7) { + if (version > 7) { // iPhone >= 7.1 WebView delete viewportProperties.width; - } else if(version < 7) { + } else if (version < 7) { // iPhone <= 6.1 WebView // if height was set it needs to get removed with this hack for <= 6.1 - if( initHeight ) viewportProperties.height = '0'; + if (initHeight) viewportProperties.height = '0'; - } else if(version == 7) { + } else if (version == 7) { //iPhone == 7.0 WebView viewportProperties.height = DEVICE_HEIGHT; } @@ -106,23 +106,23 @@ function viewportUpdate() { if (version < 7) { // iPhone <= 6.1 Browser // if height was set it needs to get removed with this hack for <= 6.1 - if( initHeight ) viewportProperties.height = '0'; + if (initHeight) viewportProperties.height = '0'; } } } // only update the viewport tag if there was a change - if(initWidth !== viewportProperties.width || initHeight !== viewportProperties.height) { + if (initWidth !== viewportProperties.width || initHeight !== viewportProperties.height) { viewportTagUpdate(); } } function viewportTagUpdate() { var key, props = []; - for(key in viewportProperties) { - if( viewportProperties[key] ) { - props.push(key + (viewportProperties[key] == '_' ? '' : '=' + viewportProperties[key]) ); + for (key in viewportProperties) { + if (viewportProperties[key]) { + props.push(key + (viewportProperties[key] == '_' ? '' : '=' + viewportProperties[key])); } } @@ -132,7 +132,7 @@ function viewportTagUpdate() { ionic.Platform.ready(function() { viewportLoadTag(); - window.addEventListener("orientationchange", function(){ + window.addEventListener("orientationchange", function() { setTimeout(viewportUpdate, 1000); }, false); });