From ce06f6e40bdb2bc560d9241aa1ef23db4fff065f Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Apr 2015 16:27:20 -0600 Subject: [PATCH] style(): move from jshint to eslint --- .agignore | 1 + .eslintrc | 36 ++++ .jshintrc | 3 - gulpfile.js | 17 +- .../controller/infiniteScrollController.js | 8 +- js/angular/controller/listController.js | 4 +- js/angular/controller/navBarController.js | 2 +- js/angular/controller/navViewController.js | 5 +- js/angular/controller/refresherController.js | 36 ++-- js/angular/controller/scrollController.js | 2 +- js/angular/controller/sideMenuController.js | 6 +- js/angular/controller/spinnerController.js | 6 +- js/angular/controller/viewController.js | 3 +- js/angular/deprecated.js | 44 ---- js/angular/directive/collectionRepeat.js | 29 ++- js/angular/directive/content.js | 6 +- js/angular/directive/exposeAsideWhen.js | 2 +- js/angular/directive/headerFooterBar.js | 4 +- js/angular/directive/infiniteScroll.js | 2 +- js/angular/directive/item.js | 2 - js/angular/directive/itemOptionButton.js | 3 +- js/angular/directive/itemReorderButton.js | 5 +- js/angular/directive/keyboardAttach.js | 2 +- js/angular/directive/modalView.js | 2 +- js/angular/directive/ngClick.js | 2 +- js/angular/directive/pane.js | 2 +- js/angular/directive/scroll.js | 9 +- js/angular/directive/sideMenuContent.js | 8 +- js/angular/directive/slideBox.js | 6 +- js/angular/directive/tabNav.js | 56 +++-- js/angular/directive/tabs.js | 3 +- js/angular/main.js | 1 + js/angular/service/actionSheet.js | 5 +- js/angular/service/backdrop.js | 5 +- js/angular/service/decorators/location.js | 3 +- js/angular/service/history.js | 14 +- js/angular/service/loading.js | 24 ++- js/angular/service/modal.js | 11 +- js/angular/service/platform.js | 20 +- js/angular/service/popup.js | 17 +- js/angular/service/templateCache.js | 1 + js/angular/service/viewSwitcher.js | 6 +- js/utils/activator.js | 2 - js/utils/dom.js | 4 +- js/utils/events.js | 2 +- js/utils/gestures.js | 196 +++++++++--------- js/utils/keyboard.js | 5 +- js/utils/platform.js | 6 +- js/utils/poly.js | 2 +- js/utils/tap.js | 10 +- js/utils/utils.js | 41 +--- js/views/listView.js | 38 +--- js/views/scrollView.js | 43 ++-- js/views/scrollViewNative.js | 20 +- js/views/sideMenuView.js | 4 +- js/views/sliderView.js | 67 +++--- js/views/toggleView.js | 12 +- package.json | 2 +- .../controller/sideMenuController.unit.js | 4 +- test/unit/angular/service/loading.unit.js | 4 +- test/unit/angular/service/modal.unit.js | 7 +- test/unit/angular/service/popover.unit.js | 7 +- test/unit/angular/service/popup.unit.js | 4 +- 63 files changed, 417 insertions(+), 486 deletions(-) create mode 100644 .agignore create mode 100644 .eslintrc delete mode 100644 .jshintrc delete mode 100644 js/angular/deprecated.js diff --git a/.agignore b/.agignore new file mode 100644 index 00000000000..30b81dbfd01 --- /dev/null +++ b/.agignore @@ -0,0 +1 @@ +release \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 00000000000..0c6255fc0a6 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,36 @@ +{ + "env": { + "browser": true + }, + "globals": { + "ionic": true, + "IonicModule": true, + "angular": true, + "jqLite": true, + "forEach": true, + "isDefined": true, + "isNumber": true, + "isString": true, + "noop": true, + "extend": true, + "deprecated": true, + "cordova": true, + "DocumentTouch": true + }, + "rules": { + "quotes": false, + "no-underscore-dangle": false, + "no-unused-expressions": false, + "curly": [2, "multi-line"], + "strict": false, + "no-use-before-define": false, + "eqeqeq": false, + "new-cap": [2, {"capIsNew": false}], + "dot-notation": [2, {"allowKeywords": false}], + "no-console": false, + "no-return-assign": false, + "no-shadow": false, + "comma-dangle": false, + "camelcase": [2, {"properties": "never"}] + } +} \ No newline at end of file diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index fe01d3d406d..00000000000 --- a/.jshintrc +++ /dev/null @@ -1,3 +0,0 @@ -{ - "expr": true -} diff --git a/gulpfile.js b/gulpfile.js index d3d591ccf7e..10e0c9f40a7 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -25,7 +25,7 @@ var concat = require('gulp-concat'); var footer = require('gulp-footer'); var gulpif = require('gulp-if'); var header = require('gulp-header'); -var jshint = require('gulp-jshint'); +var eslint = require('gulp-eslint'); var jscs = require('gulp-jscs'); var minifyCss = require('gulp-minify-css'); var rename = require('gulp-rename'); @@ -61,7 +61,7 @@ if (argv.dist) { gulp.task('default', ['build']); gulp.task('build', ['bundle', 'sass']); -gulp.task('validate', ['jshint', 'ddescribe-iit', 'karma']); +gulp.task('validate', ['eslint', 'ddescribe-iit', 'karma']); var IS_WATCH = false; gulp.task('watch', ['build'], function() { @@ -135,16 +135,11 @@ gulp.task('jscs', function() { })); }); -gulp.task('jshint', function() { +gulp.task('eslint', function() { return gulp.src(['js/**/*.js']) - .pipe(jshint('.jshintrc')) - .pipe(jshint.reporter(require('jshint-summary')({ - fileColCol: ',bold', - positionCol: ',bold', - codeCol: 'green,bold', - reasonCol: 'cyan' - }))) - .pipe(jshint.reporter('fail')); + .pipe(eslint()) + .pipe(eslint.format()) + .pipe(eslint.failOnError()); }); gulp.task('ddescribe-iit', function() { diff --git a/js/angular/controller/infiniteScrollController.js b/js/angular/controller/infiniteScrollController.js index 3e6d8b561a1..113be8a28bc 100644 --- a/js/angular/controller/infiniteScrollController.js +++ b/js/angular/controller/infiniteScrollController.js @@ -4,7 +4,7 @@ IonicModule '$attrs', '$element', '$timeout', - function($scope, $attrs, $element, $timeout) { +function($scope, $attrs, $element, $timeout) { var self = this; self.isLoading = false; @@ -92,7 +92,7 @@ IonicModule self.getNativeMaxScroll = function() { var maxValues = { left: self.scrollEl.scrollWidth, - top: self.scrollEl.scrollHeight + top: self.scrollEl.scrollHeight }; var computedStyle = window.getComputedStyle(self.scrollEl) || {}; return { @@ -109,8 +109,8 @@ IonicModule // determine pixel refresh distance based on % or value function calculateMaxValue(maximum) { - distance = ($attrs.distance || '2.5%').trim(); - isPercent = distance.indexOf('%') !== -1; + var distance = ($attrs.distance || '2.5%').trim(); + var isPercent = distance.indexOf('%') !== -1; return isPercent ? maximum * (1 - parseFloat(distance) / 100) : maximum - parseFloat(distance); diff --git a/js/angular/controller/listController.js b/js/angular/controller/listController.js index 9d7dd277e66..48e7c8f66c7 100644 --- a/js/angular/controller/listController.js +++ b/js/angular/controller/listController.js @@ -1,4 +1,3 @@ - /** * @ngdoc service * @name $ionicListDelegate @@ -32,8 +31,7 @@ * } * ``` */ -IonicModule -.service('$ionicListDelegate', ionic.DelegateService([ +IonicModule.service('$ionicListDelegate', ionic.DelegateService([ /** * @ngdoc method * @name $ionicListDelegate#showReorder diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index 1dd229922ca..0555816f44a 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -43,7 +43,7 @@ function($scope, $element, $attrs, $compile, $timeout, $ionicNavBarDelegate, $io }; - self.createHeaderBar = function(isActive, navBarClass) { + self.createHeaderBar = function(isActive) { var containerEle = jqLite('' + '', - link: function($scope, $element, $attr, slideBoxCtrl) { + link: function($scope, $element, $attr) { // if showPager is undefined, show the pager if (!isDefined($attr.showPager)) { $scope.showPager = true; @@ -181,10 +181,8 @@ function($timeout, $compile, $ionicSlideBoxDelegate, $ionicHistory, $ionicScroll return { restrict: 'E', require: '^ionSlideBox', - compile: function(element, attr) { + compile: function(element) { element.addClass('slider-slide'); - return function($scope, $element, $attr) { - }; } }; }) diff --git a/js/angular/directive/tabNav.js b/js/angular/directive/tabNav.js index cde1260f305..e56ee5c774b 100644 --- a/js/angular/directive/tabNav.js +++ b/js/angular/directive/tabNav.js @@ -23,41 +23,39 @@ IonicModule badgeStyle: '@', 'class': '@' }, - compile: function(element, attr, transclude) { - return function link($scope, $element, $attrs, ctrls) { - var tabsCtrl = ctrls[0], - tabCtrl = ctrls[1]; + link: function($scope, $element, $attrs, ctrls) { + var tabsCtrl = ctrls[0], + tabCtrl = ctrls[1]; - //Remove title attribute so browser-tooltip does not apear - $element[0].removeAttribute('title'); + //Remove title attribute so browser-tooltip does not apear + $element[0].removeAttribute('title'); - $scope.selectTab = function(e) { - e.preventDefault(); - tabsCtrl.select(tabCtrl.$scope, true); - }; - if (!$attrs.ngClick) { - $element.on('click', function(event) { - $scope.$apply(function() { - $scope.selectTab(event); - }); + $scope.selectTab = function(e) { + e.preventDefault(); + tabsCtrl.select(tabCtrl.$scope, true); + }; + if (!$attrs.ngClick) { + $element.on('click', function(event) { + $scope.$apply(function() { + $scope.selectTab(event); }); - } + }); + } - $scope.isHidden = function() { - if ($attrs.hidden === 'true' || $attrs.hidden === true) return true; - return false; - }; + $scope.isHidden = function() { + if ($attrs.hidden === 'true' || $attrs.hidden === true) return true; + return false; + }; - $scope.getIconOn = function() { - return $scope.iconOn || $scope.icon; - }; - $scope.getIconOff = function() { - return $scope.iconOff || $scope.icon; - }; + $scope.getIconOn = function() { + return $scope.iconOn || $scope.icon; + }; + $scope.getIconOff = function() { + return $scope.iconOff || $scope.icon; + }; - $scope.isTabActive = function() { - return tabsCtrl.selectedTab() === tabCtrl.$scope; - }; + $scope.isTabActive = function() { + return tabsCtrl.selectedTab() === tabCtrl.$scope; }; } }; diff --git a/js/angular/directive/tabs.js b/js/angular/directive/tabs.js index dbee465b5ee..71535ff228d 100644 --- a/js/angular/directive/tabs.js +++ b/js/angular/directive/tabs.js @@ -50,8 +50,7 @@ IonicModule .directive('ionTabs', [ '$ionicTabsDelegate', '$ionicConfig', - '$ionicHistory', -function($ionicTabsDelegate, $ionicConfig, $ionicHistory) { +function($ionicTabsDelegate, $ionicConfig) { return { restrict: 'E', scope: true, diff --git a/js/angular/main.js b/js/angular/main.js index 40b363c4623..588efbb512b 100644 --- a/js/angular/main.js +++ b/js/angular/main.js @@ -1,3 +1,4 @@ +/* eslint no-unused-vars:0 */ var IonicModule = angular.module('ionic', ['ngAnimate', 'ngSanitize', 'ui.router']), extend = angular.extend, forEach = angular.forEach, diff --git a/js/angular/service/actionSheet.js b/js/angular/service/actionSheet.js index 4de466c4c08..ea054b8da49 100644 --- a/js/angular/service/actionSheet.js +++ b/js/angular/service/actionSheet.js @@ -57,7 +57,8 @@ IonicModule '$ionicTemplateLoader', '$ionicPlatform', '$ionicBody', -function($rootScope, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform, $ionicBody) { + 'IONIC_BACK_PRIORITY', +function($rootScope, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicPlatform, $ionicBody, IONIC_BACK_PRIORITY) { return { show: actionSheet @@ -169,7 +170,7 @@ function($rootScope, $compile, $animate, $timeout, $ionicTemplateLoader, $ionicP function() { $timeout(scope.cancel); }, - PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET + IONIC_BACK_PRIORITY.actionSheet ); // called when the user presses the cancel button diff --git a/js/angular/service/backdrop.js b/js/angular/service/backdrop.js index 8433a63c4f8..4b89bddbc8c 100644 --- a/js/angular/service/backdrop.js +++ b/js/angular/service/backdrop.js @@ -34,12 +34,11 @@ */ IonicModule .factory('$ionicBackdrop', [ - '$document', '$timeout', '$$rAF', '$$q', -function($document, $timeout, $$rAF, $$q) { + '$document', '$timeout', '$$rAF', +function($document, $timeout, $$rAF) { var el = jqLite('
'); var backdropHolds = 0; - var backdropIsActive = false; $document[0].body.appendChild(el[0]); diff --git a/js/angular/service/decorators/location.js b/js/angular/service/decorators/location.js index bb25412c6b6..aab17af0509 100644 --- a/js/angular/service/decorators/location.js +++ b/js/angular/service/decorators/location.js @@ -14,8 +14,9 @@ function($provide) { if (isDefined(value)) { $timeout(function() { var scroll = document.querySelector('.scroll-content'); - if (scroll) + if (scroll) { scroll.scrollTop = 0; + } }, 0, false); } return $location.__hash(value); diff --git a/js/angular/service/history.js b/js/angular/service/history.js index d285e4e5021..6060a99bde0 100644 --- a/js/angular/service/history.js +++ b/js/angular/service/history.js @@ -75,7 +75,6 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ } $location.url(this.url); - return; } return null; @@ -313,8 +312,8 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ // the forward has a history for (x = tmp.stack.length - 1; x >= forwardView.index; x--) { // starting from the end destroy all forwards in this history from this point - var stack_x = tmp.stack[x]; - stack_x && stack_x.destroy && stack_x.destroy(); + var stackItem = tmp.stack[x]; + stackItem && stackItem.destroy && stackItem.destroy(); tmp.stack.splice(x); } historyId = forwardView.historyId; @@ -664,7 +663,7 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ }, isAbstractEle: function(ele, viewLocals) { - if (viewLocals && viewLocals.$$state && viewLocals.$$state.self.abstract) { + if (viewLocals && viewLocals.$$state && viewLocals.$$state.self['abstract']) { return true; } return !!(ele && (isAbstractTag(ele) || isAbstractTag(ele.children()))); @@ -727,7 +726,8 @@ function($rootScope, $state, $location, $window, $timeout, $ionicViewSwitcher, $ '$document', '$ionicPlatform', '$ionicHistory', -function($rootScope, $state, $location, $document, $ionicPlatform, $ionicHistory) { + 'IONIC_BACK_PRIORITY', +function($rootScope, $state, $location, $document, $ionicPlatform, $ionicHistory, IONIC_BACK_PRIORITY) { // always reset the keyboard state when change stage $rootScope.$on('$ionicView.beforeEnter', function() { @@ -735,7 +735,7 @@ function($rootScope, $state, $location, $document, $ionicPlatform, $ionicHistory }); $rootScope.$on('$ionicHistory.change', function(e, data) { - if (!data) return; + if (!data) return null; var viewHistory = $ionicHistory.viewHistory(); @@ -792,7 +792,7 @@ function($rootScope, $state, $location, $document, $ionicPlatform, $ionicHistory } $ionicPlatform.registerBackButtonAction( onHardwareBackButton, - PLATFORM_BACK_BUTTON_PRIORITY_VIEW + IONIC_BACK_PRIORITY.view ); }]); diff --git a/js/angular/service/loading.js b/js/angular/service/loading.js index 8ce29a29e8e..9223089079b 100644 --- a/js/angular/service/loading.js +++ b/js/angular/service/loading.js @@ -67,7 +67,8 @@ IonicModule '$compile', '$ionicPlatform', '$rootScope', -function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform, $rootScope) { + 'IONIC_BACK_PRIORITY', +function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, $timeout, $q, $log, $compile, $ionicPlatform, $rootScope, IONIC_BACK_PRIORITY) { var loaderInstance; //default values @@ -142,7 +143,7 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, //Disable hardware back button while loading deregisterBackAction = $ionicPlatform.registerBackButtonAction( noop, - PLATFORM_BACK_BUTTON_PRIORITY_LOADING + IONIC_BACK_PRIORITY.loading ); templatePromise.then(function(html) { @@ -209,15 +210,20 @@ function($ionicLoadingConfig, $ionicBody, $ionicTemplateLoader, $ionicBackdrop, }); return { - hide: deprecated.method(LOADING_HIDE_DEPRECATED, $log.error, hideLoader), - show: deprecated.method(LOADING_SHOW_DEPRECATED, $log.error, function() { - showLoader(options); - }), - setContent: deprecated.method(LOADING_SET_DEPRECATED, $log.error, function(content) { - getLoader().then(function(loader) { + hide: function deprecatedHide() { + $log.error(LOADING_HIDE_DEPRECATED); + return hideLoader.apply(this, arguments); + }, + show: function deprecatedShow() { + $log.error(LOADING_SHOW_DEPRECATED); + return showLoader.apply(this, arguments); + }, + setContent: function deprecatedSetContent(content) { + $log.error(LOADING_SET_DEPRECATED); + return getLoader().then(function(loader) { loader.show({ template: content }); }); - }) + } }; } diff --git a/js/angular/service/modal.js b/js/angular/service/modal.js index 8ed1f8dce4f..181a1638ee0 100644 --- a/js/angular/service/modal.js +++ b/js/angular/service/modal.js @@ -74,7 +74,8 @@ IonicModule '$log', '$ionicClickBlock', '$window', -function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTemplateLoader, $$q, $log, $ionicClickBlock, $window) { + 'IONIC_BACK_PRIORITY', +function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTemplateLoader, $$q, $log, $ionicClickBlock, $window, IONIC_BACK_PRIORITY) { /** * @ngdoc controller @@ -122,7 +123,7 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl var self = this; if (self.scope.$$destroyed) { - $log.error('Cannot call ' + self.viewType + '.show() after remove(). Please create a new ' + self.viewType + ' instance.'); + $log.error('Cannot call ' + self.viewType + '.show() after remove(). Please create a new ' + self.viewType + ' instance.'); return $$q.when(); } @@ -148,8 +149,8 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl self.positionView(target, modalEl); // set up a listener for in case the window size changes - self._onWindowResize = function(ev) { - if (self._isShown) self.positionView(target,modalEl); + self._onWindowResize = function() { + if (self._isShown) self.positionView(target, modalEl); }; $window.addEventListener('resize', self._onWindowResize); } @@ -161,7 +162,7 @@ function($rootScope, $ionicBody, $compile, $timeout, $ionicPlatform, $ionicTempl self._isShown = true; self._deregisterBackButton = $ionicPlatform.registerBackButtonAction( self.hardwareBackButtonClose ? angular.bind(self, self.hide) : noop, - PLATFORM_BACK_BUTTON_PRIORITY_MODAL + IONIC_BACK_PRIORITY.modal ); ionic.views.Modal.prototype.show.call(self); diff --git a/js/angular/service/platform.js b/js/angular/service/platform.js index 4bbd54ecd00..205b27f3c89 100644 --- a/js/angular/service/platform.js +++ b/js/angular/service/platform.js @@ -1,9 +1,3 @@ -var PLATFORM_BACK_BUTTON_PRIORITY_VIEW = 100; -var PLATFORM_BACK_BUTTON_PRIORITY_SIDE_MENU = 150; -var PLATFORM_BACK_BUTTON_PRIORITY_MODAL = 200; -var PLATFORM_BACK_BUTTON_PRIORITY_ACTION_SHEET = 300; -var PLATFORM_BACK_BUTTON_PRIORITY_POPUP = 400; -var PLATFORM_BACK_BUTTON_PRIORITY_LOADING = 500; /** * @ngdoc service @@ -16,9 +10,17 @@ var PLATFORM_BACK_BUTTON_PRIORITY_LOADING = 500; * Android back button in PhoneGap/Cordova. */ IonicModule +.constant('IONIC_BACK_PRIORITY', { + view: 100, + sideMenu: 150, + modal: 200, + actionSheet: 300, + popup: 400, + loading: 500 +}) .provider('$ionicPlatform', function() { return { - $get: ['$q', '$rootScope', function($q, $rootScope) { + $get: ['$q', function($q) { var self = { /** @@ -68,12 +70,12 @@ IonicModule * Close action sheet = 300 * Dismiss popup = 400 * Dismiss loading overlay = 500 - * + * * Your back button action will override each of the above actions * whose priority is less than the priority you provide. For example, * an action assigned a priority of 101 will override the 'return to * previous view' action, but not any of the other actions. - * + * * @param {function} callback Called when the back button is pressed, * if this listener is the highest priority. * @param {number} priority Only the highest priority will execute. diff --git a/js/angular/service/popup.js b/js/angular/service/popup.js index 8a75b46b8c1..dd07a1dd5ce 100644 --- a/js/angular/service/popup.js +++ b/js/angular/service/popup.js @@ -113,7 +113,8 @@ IonicModule '$ionicBody', '$compile', '$ionicPlatform', -function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicBody, $compile, $ionicPlatform) { + 'IONIC_BACK_PRIORITY', +function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicBody, $compile, $ionicPlatform, IONIC_BACK_PRIORITY) { //TODO allow this to be configured var config = { stackPushDelay: 75 @@ -360,7 +361,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB }); } - function onHardwareBackButton(e) { + function onHardwareBackButton() { var last = popupStack[popupStack.length - 1]; last && last.responseDeferred.resolve(); } @@ -379,7 +380,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB //only show the backdrop on the first popup $ionicPopup._backButtonActionDone = $ionicPlatform.registerBackButtonAction( onHardwareBackButton, - PLATFORM_BACK_BUTTON_PRIORITY_POPUP + IONIC_BACK_PRIORITY.popup ); resultDeferred = doShowPopup(); } @@ -448,7 +449,7 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB buttons: [{ text: opts.okText || 'OK', type: opts.okType || 'button-positive', - onTap: function(e) { + onTap: function() { return true; } }] @@ -460,11 +461,11 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB buttons: [{ text: opts.cancelText || 'Cancel', type: opts.cancelType || 'button-default', - onTap: function(e) { return false; } + onTap: function() { return false; } }, { text: opts.okText || 'OK', type: opts.okType || 'button-positive', - onTap: function(e) { return true; } + onTap: function() { return true; } }] }, opts || {})); } @@ -484,11 +485,11 @@ function($ionicTemplateLoader, $ionicBackdrop, $q, $timeout, $rootScope, $ionicB buttons: [{ text: opts.cancelText || 'Cancel', type: opts.cancelType || 'button-default', - onTap: function(e) {} + onTap: function() {} }, { text: opts.okText || 'OK', type: opts.okType || 'button-positive', - onTap: function(e) { + onTap: function() { return scope.data.response || ''; } }] diff --git a/js/angular/service/templateCache.js b/js/angular/service/templateCache.js index 4079bd7b266..020484a7e05 100644 --- a/js/angular/service/templateCache.js +++ b/js/angular/service/templateCache.js @@ -71,6 +71,7 @@ function($http, $templateCache, $timeout) { // run through methods - internal method function run() { + var template; $ionicTemplateCache._runCount++; hasRun = true; diff --git a/js/angular/service/viewSwitcher.js b/js/angular/service/viewSwitcher.js index 0629459e7c9..f000a264e3d 100644 --- a/js/angular/service/viewSwitcher.js +++ b/js/angular/service/viewSwitcher.js @@ -3,8 +3,7 @@ * TODO document */ -IonicModule -.factory('$ionicViewSwitcher',[ +IonicModule.factory('$ionicViewSwitcher', [ '$timeout', '$document', '$q', @@ -21,7 +20,6 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe var DATA_FALLBACK_TIMER = '$fallbackTimer'; var DATA_VIEW = '$viewData'; var NAV_VIEW_ATTR = 'nav-view'; - var HISTORY_CURSOR_ATTR = 'history-cursor'; var VIEW_STATUS_ACTIVE = 'active'; var VIEW_STATUS_CACHED = 'cached'; var VIEW_STATUS_STAGED = 'stage'; @@ -425,7 +423,7 @@ function($timeout, $document, $q, $ionicClickBlock, $ionicConfig, $ionicNavBarDe function getViewElementIdentifier(locals, view) { - if (viewState(locals).abstract) return viewState(locals).name; + if (viewState(locals)['abstract']) return viewState(locals).name; if (view) return view.stateId || view.viewId; return ionic.Utils.nextUid(); } diff --git a/js/utils/activator.js b/js/utils/activator.js index 1d832d34247..0709064c30d 100644 --- a/js/utils/activator.js +++ b/js/utils/activator.js @@ -9,8 +9,6 @@ ionic.activator = { start: function(e) { - var self = this; - var hitX = ionic.tap.pointerCoord(e).x; if (hitX > 0 && hitX < 30) { return; diff --git a/js/utils/dom.js b/js/utils/dom.js index e84d7f80cdb..aed79406c18 100644 --- a/js/utils/dom.js +++ b/js/utils/dom.js @@ -21,9 +21,9 @@ // Put it on window just to preserve its context // without having to use .call window._rAF = (function() { - return window.requestAnimationFrame || + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || - window.mozRequestAnimationFrame || + window.mozRequestAnimationFrame || function(callback) { window.setTimeout(callback, 16); }; diff --git a/js/utils/events.js b/js/utils/events.js index 27c86057431..be1886764bb 100644 --- a/js/utils/events.js +++ b/js/utils/events.js @@ -150,7 +150,7 @@ gesture && gesture.off(type, callback); }, - handlePopState: function(event) {} + handlePopState: function() {} }; diff --git a/js/utils/gestures.js b/js/utils/gestures.js index 4af6bde2614..17caa028c83 100644 --- a/js/utils/gestures.js +++ b/js/utils/gestures.js @@ -1,3 +1,4 @@ +/* eslint camelcase:0 */ /** * Simple gesture controllers with some common gestures that emit * gesture events. @@ -109,7 +110,7 @@ // so we can't listen for events on it. if(element === null) { console.error('Null element passed to gesture (element does not exist). Not listening for gesture'); - return; + return this; } // setup ionic.GesturesJS window events and register all gestures @@ -152,7 +153,7 @@ */ on: function onEvent(gesture, handler){ var gestures = gesture.split(' '); - for(var t=0; t drag_lock_min_distance // This way, locking occurs only when the distance has become large enough to reliably determine the direction - drag_lock_min_distance : 25, + drag_lock_min_distance: 25, // prevent default if the gesture is going the given direction - prevent_default_directions : [] + prevent_default_directions: [] }, triggered: false, handler: function dragGesture(ev, inst) { @@ -1179,7 +1179,7 @@ // current gesture isnt drag, but dragged is true // this means an other gesture is busy. now call dragend if(ionic.Gestures.detection.current.name != this.name && this.triggered) { - inst.trigger(this.name +'end', ev); + inst.trigger(this.name + 'end', ev); this.triggered = false; return; } @@ -1210,7 +1210,7 @@ // When a drag is triggered, set the event center to drag_min_distance pixels from the original event center. // Without this correction, the dragged distance would jumpstart at drag_min_distance pixels instead of at 0. // It might be useful to save the original start point somewhere - var factor = Math.abs(inst.options.drag_min_distance/ev.distance); + var factor = Math.abs(inst.options.drag_min_distance / ev.distance); ionic.Gestures.detection.current.startEvent.center.pageX += ev.deltaX * factor; ionic.Gestures.detection.current.startEvent.center.pageY += ev.deltaY * factor; @@ -1220,7 +1220,7 @@ } // lock drag to axis? - if(ionic.Gestures.detection.current.lastEvent.drag_locked_to_axis || (inst.options.drag_lock_to_axis && inst.options.drag_lock_min_distance<=ev.distance)) { + if(ionic.Gestures.detection.current.lastEvent.drag_locked_to_axis || (inst.options.drag_lock_to_axis && inst.options.drag_lock_min_distance <= ev.distance)) { ev.drag_locked_to_axis = true; } var last_direction = ionic.Gestures.detection.current.lastEvent.direction; @@ -1236,7 +1236,7 @@ // first time, trigger dragstart event if(!this.triggered) { - inst.trigger(this.name +'start', ev); + inst.trigger(this.name + 'start', ev); this.triggered = true; } @@ -1256,7 +1256,7 @@ case ionic.Gestures.EVENT_END: // trigger dragend if(this.triggered) { - inst.trigger(this.name +'end', ev); + inst.trigger(this.name + 'end', ev); } this.triggered = false; @@ -1276,20 +1276,20 @@ index: 45, defaults: { // factor, no scale is 1, zoomin is to 0 and zoomout until higher then 1 - transform_min_scale : 0.01, + transform_min_scale: 0.01, // rotation in degrees - transform_min_rotation : 1, + transform_min_rotation: 1, // prevent default browser behavior when two touches are on the screen // but it makes the element a blocking element // when you are using the transform gesture, it is a good practice to set this true - transform_always_block : false + transform_always_block: false }, triggered: false, handler: function transformGesture(ev, inst) { // current gesture isnt drag, but dragged is true // this means an other gesture is busy. now call dragend if(ionic.Gestures.detection.current.name != this.name && this.triggered) { - inst.trigger(this.name +'end', ev); + inst.trigger(this.name + 'end', ev); this.triggered = false; return; } @@ -1310,7 +1310,7 @@ break; case ionic.Gestures.EVENT_MOVE: - var scale_threshold = Math.abs(1-ev.scale); + var scale_threshold = Math.abs(1 - ev.scale); var rotation_threshold = Math.abs(ev.rotation); // when the distance we moved is too small we skip this gesture @@ -1325,7 +1325,7 @@ // first time, trigger dragstart event if(!this.triggered) { - inst.trigger(this.name +'start', ev); + inst.trigger(this.name + 'start', ev); this.triggered = true; } @@ -1339,14 +1339,14 @@ // trigger pinch event if(scale_threshold > inst.options.transform_min_scale) { inst.trigger('pinch', ev); - inst.trigger('pinch'+ ((ev.scale < 1) ? 'in' : 'out'), ev); + inst.trigger('pinch' + ((ev.scale < 1) ? 'in' : 'out'), ev); } break; case ionic.Gestures.EVENT_END: // trigger dragend if(this.triggered) { - inst.trigger(this.name +'end', ev); + inst.trigger(this.name + 'end', ev); } this.triggered = false; @@ -1385,7 +1385,7 @@ ev.preventDefault(); } - if(ev.eventType == ionic.Gestures.EVENT_START) { + if(ev.eventType == ionic.Gestures.EVENT_START) { inst.trigger(this.name, ev); } } @@ -1401,7 +1401,7 @@ name: 'release', index: Infinity, handler: function releaseGesture(ev, inst) { - if(ev.eventType == ionic.Gestures.EVENT_END) { + if(ev.eventType == ionic.Gestures.EVENT_END) { inst.trigger(this.name, ev); } } diff --git a/js/utils/keyboard.js b/js/utils/keyboard.js index 8d62c251437..204f9869650 100644 --- a/js/utils/keyboard.js +++ b/js/utils/keyboard.js @@ -286,7 +286,7 @@ function keyboardFocusIn(e) { // an exact keyboard height // if the keyboard is already open, go ahead and scroll the input into view // if necessary - if (!ionic.keyboard.isOpen && !keyboardHasPlugin()) { + if (!ionic.keyboard.isOpen && !keyboardHasPlugin()) { keyboardWaitForResize(keyboardShow, true); } else if (ionic.keyboard.isOpen) { @@ -299,7 +299,7 @@ function keyboardFocusIn(e) { * calls keyboardWaitForResize with keyboardHide as the callback after a small * timeout. */ -function keyboardFocusOut(e) { +function keyboardFocusOut() { clearTimeout(keyboardFocusOutTimer); //console.log("keyboardFocusOut fired at: " + Date.now()); //console.log("keyboardFocusOut event type: " + e.type); @@ -537,6 +537,7 @@ function keyboardShow() { return details; } +/* eslint no-unused-vars:0 */ function keyboardGetHeight() { // check if we already have a keyboard height from the plugin or resize calculations if ( ionic.keyboard.height ) { diff --git a/js/utils/platform.js b/js/utils/platform.js index 6f3630827af..d26b968c0be 100644 --- a/js/utils/platform.js +++ b/js/utils/platform.js @@ -150,9 +150,9 @@ if (self.isWebView()) { self.platforms.push('webview'); - if(!(!window.cordova && !window.PhoneGap && !window.phonegap)) { + if (!(!window.cordova && !window.PhoneGap && !window.phonegap)) { self.platforms.push('cordova'); - } else if(!!window.forge) { + } else if (window.forge) { self.platforms.push('trigger'); } } else { @@ -295,7 +295,7 @@ }; if (versionMatch[pName]) { v = self.ua.match(versionMatch[pName]); - if (v && v.length > 2) { + if (v && v.length > 2) { platformVersion = parseFloat(v[1] + '.' + v[2]); } } diff --git a/js/utils/poly.js b/js/utils/poly.js index ac6c915251e..c716289a185 100644 --- a/js/utils/poly.js +++ b/js/utils/poly.js @@ -33,7 +33,7 @@ ionic.CSS.TRANSITION_DURATION = (isWebkit ? '-webkit-' : '') + 'transition-duration'; // To be sure transitionend works everywhere, include *both* the webkit and non-webkit events - ionic.CSS.TRANSITIONEND = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend'; + ionic.CSS.TRANSITIONEND = (isWebkit ? 'webkitTransitionEnd ' : '') + 'transitionend'; })(); // classList polyfill for them older Androids diff --git a/js/utils/tap.js b/js/utils/tap.js index 21dcba9f37b..73aca5dcded 100644 --- a/js/utils/tap.js +++ b/js/utils/tap.js @@ -277,7 +277,7 @@ ionic.tap = { pointerCoord: function(event) { // This method can get coordinates for both a mouse click // or a touch depending on the given event - var c = { x:0, y:0 }; + var c = { x: 0, y: 0 }; if (event) { var touches = event.touches && event.touches.length ? event.touches : [event]; var e = (event.changedTouches && event.changedTouches[0]) || touches[0]; @@ -327,7 +327,7 @@ function tapClickGateKeeper(e) { //console.log('click ' + Date.now() + ' isIonicTap: ' + (e.isIonicTap ? true : false)); if (e.target.type == 'submit' && e.detail === 0) { // do not prevent click if it came from an "Enter" or "Go" keypress submit - return; + return null; } // do not allow through any click events that were not created by ionic.tap @@ -347,7 +347,7 @@ function tapClickGateKeeper(e) { // MOUSE function tapMouseDown(e) { //console.log('mousedown ' + Date.now()); - if (e.isIonicTap || tapIgnoreEvent(e)) return; + if (e.isIonicTap || tapIgnoreEvent(e)) return null; if (tapEnabledTouchEvents) { console.log('mousedown', 'stop event'); @@ -452,7 +452,7 @@ function tapTouchMove(e) { } } -function tapTouchCancel(e) { +function tapTouchCancel() { tapEventListener(tapTouchMoveListener, false); ionic.activator.end(); tapPointerMoved = false; @@ -542,7 +542,7 @@ function tapFocusIn(e) { ionic.scroll.isScrolling = false; } -function tapFocusOut(e) { +function tapFocusOut() { //console.log("focusout"); tapActiveElement(null); } diff --git a/js/utils/utils.js b/js/utils/utils.js index 2058b96971f..24681671263 100644 --- a/js/utils/utils.js +++ b/js/utils/utils.js @@ -1,7 +1,6 @@ (function(ionic) { - - /* for nextUid() function below */ - var uid = ['0','0','0']; + /* for nextUid function below */ + var nextId = 0; /** * Various utilities used throughout Ionic @@ -10,14 +9,14 @@ */ ionic.Utils = { - arrayMove: function(arr, old_index, new_index) { - if (new_index >= arr.length) { - var k = new_index - arr.length; + arrayMove: function(arr, oldIndex, newIndex) { + if (newIndex >= arr.length) { + var k = newIndex - arr.length; while ((k--) + 1) { arr.push(undefined); } } - arr.splice(new_index, 0, arr.splice(old_index, 1)[0]); + arr.splice(newIndex, 0, arr.splice(oldIndex, 1)[0]); return arr; }, @@ -144,34 +143,8 @@ return obj; }, - /** - * A consistent way of creating unique IDs in angular. The ID is a sequence of alpha numeric - * characters such as '012ABC'. The reason why we are not using simply a number counter is that - * the number string gets longer over time, and it can also overflow, where as the nextId - * will grow much slower, it is a string, and it will never overflow. - * - * @returns an unique alpha-numeric string - */ nextUid: function() { - var index = uid.length; - var digit; - - while (index) { - index--; - digit = uid[index].charCodeAt(0); - if (digit == 57 /*'9'*/) { - uid[index] = 'A'; - return uid.join(''); - } - if (digit == 90 /*'Z'*/) { - uid[index] = '0'; - } else { - uid[index] = String.fromCharCode(digit + 1); - return uid.join(''); - } - } - uid.unshift('0'); - return uid.join(''); + return 'ion' + (nextId++); }, disconnectScope: function disconnectScope(scope) { diff --git a/js/views/listView.js b/js/views/listView.js index 6103f1390f1..442daddb12b 100644 --- a/js/views/listView.js +++ b/js/views/listView.js @@ -11,13 +11,10 @@ var DragOp = function() {}; DragOp.prototype = { - start: function(e) { - }, - drag: function(e) { - }, - end: function(e) { - }, - isSameItem: function(item) { + start: function(){}, + drag: function(){}, + end: function(){}, + isSameItem: function() { return false; } }; @@ -233,7 +230,6 @@ }; ReorderDrag.prototype.start = function(e) { - var content; var startIndex = ionic.DomUtil.getChildIndex(this.el, this.el.nodeName.toLowerCase()); var elementHeight = this.el.scrollHeight; @@ -313,7 +309,6 @@ ReorderDrag.prototype._getReorderIndex = function() { var self = this; - var placeholder = self._currentDrag.placeholder; var siblings = Array.prototype.slice.call(self._currentDrag.placeholder.parentNode.children) .filter(function(el) { return el.nodeName === self.el.nodeName && el !== self.el; @@ -376,7 +371,7 @@ var self = this; opts = ionic.extend({ - onReorder: function(el, oldIndex, newIndex) {}, + onReorder: function() {}, virtualRemoveThreshold: -200, virtualAddThreshold: 200, canSwipe: function() { @@ -396,8 +391,8 @@ var gestureOpts = {}; // don't prevent native scrolling - if (ionic.DomUtil.getParentOrSelfWithClass(self.el,'overflow-scroll')) { - gestureOpts.prevent_default_directions = ['left','right']; + if (ionic.DomUtil.getParentOrSelfWithClass(self.el, 'overflow-scroll')) { + gestureOpts.prevent_default_directions = ['left', 'right']; } window.ionic.onGesture('release', function(e) { @@ -442,18 +437,12 @@ if (self.isVirtual) { var itemHeight = self.itemHeight; - // TODO: This would be inaccurate if we are windowed - var totalItems = self.listEl.children.length; - // Grab the total height of the list var scrollHeight = e.target.scrollHeight; // Get the viewport height var viewportHeight = self.el.parentNode.offsetHeight; - // scrollTop is the current scroll position - var scrollTop = e.scrollTop; - // High water is the pixel position of the first element to include (everything before // that will be removed) var highWater = Math.max(0, e.scrollTop + self.virtualRemoveThreshold); @@ -462,9 +451,6 @@ // that will be removed) var lowWater = Math.min(scrollHeight, Math.abs(e.scrollTop) + viewportHeight + self.virtualAddThreshold); - // Compute how many items per viewport size can show - var itemsPerViewport = Math.floor((lowWater - highWater) / itemHeight); - // Get the first and last elements in the list based on how many can fit // between the pixel range of lowWater and highWater var first = parseInt(Math.abs(highWater / itemHeight), 10); @@ -473,17 +459,13 @@ // Get the items we need to remove self._virtualItemsToRemove = Array.prototype.slice.call(self.listEl.children, 0, first); - // Grab the nodes we will be showing - var nodes = Array.prototype.slice.call(self.listEl.children, first, first + itemsPerViewport); - self.renderViewport && self.renderViewport(highWater, lowWater, first, last); } }, - didStopScrolling: function(e) { + didStopScrolling: function() { if (this.isVirtual) { for (var i = 0; i < this._virtualItemsToRemove.length; i++) { - var el = this._virtualItemsToRemove[i]; //el.parentNode.removeChild(el); this.didHideItem && this.didHideItem(i); } @@ -528,8 +510,6 @@ _startDrag: function(e) { var self = this; - var didStart = false; - self._isDragging = false; var lastDragOp = self._lastDragOp; @@ -605,7 +585,7 @@ * Process the drag event to move the item to the left or right. */ _handleDrag: function(e) { - var self = this, content, buttons; + var self = this; if (Math.abs(e.gesture.deltaY) > 5) { self._didDragUpOrDown = true; diff --git a/js/views/scrollView.js b/js/views/scrollView.js index 2879a8e2bb4..a1d5333e498 100644 --- a/js/views/scrollView.js +++ b/js/views/scrollView.js @@ -65,7 +65,7 @@ var zyngaCore = { effect: {} }; var intervalHandle = null; var lastActive = +new Date(); - return function(callback, root) { + return function(callback) { var callbackHandle = rafHandle++; // Store callback @@ -246,8 +246,6 @@ var zyngaCore = { effect: {} }; * License: MIT + Apache (V2) */ -var Scroller; - (function(ionic) { var NOOP = function(){}; @@ -369,10 +367,10 @@ ionic.views.Scroll = ionic.views.View.inherit({ scrollingComplete: NOOP, /** This configures the amount of change applied to deceleration when reaching boundaries **/ - penetrationDeceleration : 0.03, + penetrationDeceleration: 0.03, /** This configures the amount of change applied to acceleration when reaching boundaries **/ - penetrationAcceleration : 0.08, + penetrationAcceleration: 0.08, // The ms interval for triggering scroll events scrollEventInterval: 10, @@ -750,7 +748,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ e.stopPropagation(); }; - self.resetScrollView = function(e) { + self.resetScrollView = function() { //return scrollview to original height once keyboard has hidden if ( self.isShrunkForKeyboard ) { self.isShrunkForKeyboard = false; @@ -1096,7 +1094,8 @@ ionic.views.Scroll = ionic.views.View.inherit({ * Move and scale the scrollbars as the page scrolls. */ __repositionScrollbars: function() { - var self = this, width, heightScale, + var self = this, + heightScale, widthScale, widthDiff, heightDiff, x, y, xstop = 0, ystop = 0; @@ -1107,7 +1106,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ // Don't go all the way to the right if we have a vertical scrollbar as well if (self.__indicatorY) xstop = 10; - x = Math.round(self.__indicatorX.sizeRatio * self.__scrollLeft) || 0, + x = Math.round(self.__indicatorX.sizeRatio * self.__scrollLeft) || 0; // The the difference between the last content X position, and our overscrolled one widthDiff = self.__scrollLeft - (self.__maxScrollLeft - xstop); @@ -1310,8 +1309,8 @@ ionic.views.Scroll = ionic.views.View.inherit({ } else { return function(left, top, zoom, wasResize) { - content.style.marginLeft = left ? (-left/zoom) + 'px' : ''; - content.style.marginTop = top ? (-top/zoom) + 'px' : ''; + content.style.marginLeft = left ? (-left / zoom) + 'px' : ''; + content.style.marginTop = top ? (-top / zoom) + 'px' : ''; content.style.zoom = zoom || ''; self.__repositionScrollbars(); if (!wasResize) { @@ -1412,12 +1411,12 @@ ionic.views.Scroll = ionic.views.View.inherit({ var self = this; self.__refreshHeight = height; - self.__refreshActivate = function() {ionic.requestAnimationFrame(refresherMethods.activate);}; - self.__refreshDeactivate = function() {ionic.requestAnimationFrame(refresherMethods.deactivate);}; - self.__refreshStart = function() {ionic.requestAnimationFrame(refresherMethods.start);}; - self.__refreshShow = function() {ionic.requestAnimationFrame(refresherMethods.show);}; - self.__refreshHide = function() {ionic.requestAnimationFrame(refresherMethods.hide);}; - self.__refreshTail = function() {ionic.requestAnimationFrame(refresherMethods.tail);}; + self.__refreshActivate = function() { ionic.requestAnimationFrame(refresherMethods.activate); }; + self.__refreshDeactivate = function() { ionic.requestAnimationFrame(refresherMethods.deactivate); }; + self.__refreshStart = function() { ionic.requestAnimationFrame(refresherMethods.start); }; + self.__refreshShow = function() { ionic.requestAnimationFrame(refresherMethods.show); }; + self.__refreshHide = function() { ionic.requestAnimationFrame(refresherMethods.hide); }; + self.__refreshTail = function() { ionic.requestAnimationFrame(refresherMethods.tail); }; self.__refreshTailTime = 100; self.__minSpinTime = 600; }, @@ -1465,8 +1464,8 @@ ionic.views.Scroll = ionic.views.View.inherit({ } self.scrollTo(self.__scrollLeft, self.__scrollTop, true); - },self.__refreshTailTime); - },delay); + }, self.__refreshTailTime); + }, delay); }, @@ -1861,7 +1860,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ // Slow down on the edges if (self.options.bouncing) { - scrollLeft += (moveX / 2 * self.options.speedMultiplier); + scrollLeft += (moveX / 2 * self.options.speedMultiplier); } else if (scrollLeft > maxScrollLeft) { @@ -2244,7 +2243,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ * Called when a touch sequence end and the speed of the finger was high enough * to switch into deceleration mode. */ - __startDeceleration: function(timeStamp) { + __startDeceleration: function() { var self = this; if (self.options.paging) { @@ -2299,7 +2298,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ return shouldContinue; }; - var completed = function(renderedFramesPerSecond, animationId, wasFinished) { + var completed = function() { self.__isDecelerating = false; if (self.__didDecelerationComplete) { self.__scrollingComplete(); @@ -2453,7 +2452,7 @@ ionic.views.Scroll = ionic.views.View.inherit({ __getDistance: function getDistance(touch1, touch2) { var x = touch2.pageX - touch1.pageX, y = touch2.pageY - touch1.pageY; - return Math.sqrt((x*x) + (y*y)); + return Math.sqrt((x * x) + (y * y)); }, diff --git a/js/views/scrollViewNative.js b/js/views/scrollViewNative.js index 3503d4d4bd5..6567854aea8 100644 --- a/js/views/scrollViewNative.js +++ b/js/views/scrollViewNative.js @@ -13,10 +13,10 @@ self.__scrollTop = self.el.scrollTop; self.__scrollLeft = self.el.scrollLeft; - self.__clientHeight = self.__content.clientHeight, - self.__clientWidth = self.__content.clientWidth, - self.__maxScrollTop = Math.max((self.__contentHeight) - self.__clientHeight, 0), - self.__maxScrollLeft = Math.max((self.__contentWidth) - self.__clientWidth, 0), + self.__clientHeight = self.__content.clientHeight; + self.__clientWidth = self.__content.clientWidth; + self.__maxScrollTop = Math.max((self.__contentHeight) - self.__clientHeight, 0); + self.__maxScrollLeft = Math.max((self.__contentWidth) - self.__clientWidth, 0); self.options = { @@ -39,7 +39,7 @@ /** * Sets isScrolling to true, and automatically deactivates if not called again in 80ms. */ - self.onScroll = function(event) { + self.onScroll = function() { if (!ionic.scroll.isScrolling) { ionic.scroll.isScrolling = true; } @@ -56,10 +56,10 @@ }, /** Methods not used in native scrolling */ - __callback: function() {depreciated('__callback');}, - zoomTo: function() {depreciated('zoomTo');}, - zoomBy: function() {depreciated('zoomBy');}, - activatePullToRefresh: function() {depreciated('activatePullToRefresh');}, + __callback: function() { depreciated('__callback'); }, + zoomTo: function() { depreciated('zoomTo'); }, + zoomBy: function() { depreciated('zoomBy'); }, + activatePullToRefresh: function() { depreciated('activatePullToRefresh'); }, /** * Returns the scroll position and zooming values @@ -297,7 +297,7 @@ // should be unnecessary in native scrolling, but keep in case bugs show up self.scrollChildIntoView = NOOP; - self.resetScrollView = function(e) { + self.resetScrollView = function() { //return scrollview to original height once keyboard has hidden if (self.isScrolledIntoView) { self.isScrolledIntoView = false; diff --git a/js/views/sideMenuView.js b/js/views/sideMenuView.js index 3e772b343c8..0bb600d226c 100644 --- a/js/views/sideMenuView.js +++ b/js/views/sideMenuView.js @@ -38,8 +38,8 @@ initialize: function(opts) { ionic.extend(this, { animationClass: 'menu-animated', - onDrag: function(e) {}, - onEndDrag: function(e) {} + onDrag: function() {}, + onEndDrag: function() {} }, opts); ionic.onGesture('drag', ionic.proxy(this._onDrag, this), this.el); diff --git a/js/views/sliderView.js b/js/views/sliderView.js index c239e345f6e..d9300816086 100644 --- a/js/views/sliderView.js +++ b/js/views/sliderView.js @@ -87,8 +87,8 @@ ionic.views.Slider = ionic.views.View.inherit({ // reposition elements before and after index if (options.continuous && browser.transitions) { - move(circle(index-1), -width, 0); - move(circle(index+1), width, 0); + move(circle(index - 1), -width, 0); + move(circle(index + 1), width, 0); } if (!browser.transitions) element.style.left = (index * -width) + 'px'; @@ -100,15 +100,15 @@ ionic.views.Slider = ionic.views.View.inherit({ function prev(slideSpeed) { - if (options.continuous) slide(index-1, slideSpeed); - else if (index) slide(index-1, slideSpeed); + if (options.continuous) slide(index - 1, slideSpeed); + else if (index) slide(index - 1, slideSpeed); } function next(slideSpeed) { - if (options.continuous) slide(index+1, slideSpeed); - else if (index < slides.length - 1) slide(index+1, slideSpeed); + if (options.continuous) slide(index + 1, slideSpeed); + else if (index < slides.length - 1) slide(index + 1, slideSpeed); } @@ -126,20 +126,20 @@ ionic.views.Slider = ionic.views.View.inherit({ if (browser.transitions) { - var direction = Math.abs(index-to) / (index-to); // 1: backward, -1: forward + var direction = Math.abs(index - to) / (index - to); // 1: backward, -1: forward // get the actual position of the slide if (options.continuous) { - var natural_direction = direction; + var naturalDirection = direction; direction = -slidePos[circle(to)] / width; // if going forward but to < index, use to = slides.length + to // if going backward but to > index, use to = -slides.length + to - if (direction !== natural_direction) to = -direction * slides.length + to; + if (direction !== naturalDirection) to = -direction * slides.length + to; } - var diff = Math.abs(index-to) - 1; + var diff = Math.abs(index - to) - 1; // move all the slides between index and to in the right direction while (diff--) move( circle((to > index ? to : index) - diff - 1), width * direction, 0); @@ -345,9 +345,9 @@ ionic.views.Slider = ionic.views.View.inherit({ // increase resistance if first or last slide if (options.continuous) { // we don't add resistance at the end - translate(circle(index-1), delta.x + slidePos[circle(index-1)], 0); + translate(circle(index - 1), delta.x + slidePos[circle(index - 1)], 0); translate(index, delta.x + slidePos[index], 0); - translate(circle(index+1), delta.x + slidePos[circle(index+1)], 0); + translate(circle(index + 1), delta.x + slidePos[circle(index + 1)], 0); } else { @@ -361,16 +361,16 @@ ionic.views.Slider = ionic.views.View.inherit({ : 1 ); // no resistance if false // translate 1:1 - translate(index-1, delta.x + slidePos[index-1], 0); + translate(index - 1, delta.x + slidePos[index - 1], 0); translate(index, delta.x + slidePos[index], 0); - translate(index+1, delta.x + slidePos[index+1], 0); + translate(index + 1, delta.x + slidePos[index + 1], 0); } options.onDrag && options.onDrag(); } }, - end: function(event) { + end: function() { // measure duration var duration = +new Date() - start.time; @@ -379,7 +379,7 @@ ionic.views.Slider = ionic.views.View.inherit({ var isValidSlide = Number(duration) < 250 && // if slide duration is less than 250ms Math.abs(delta.x) > 20 || // and if slide amt is greater than 20px - Math.abs(delta.x) > width/2; // or if slide amt is greater than half the width + Math.abs(delta.x) > width / 2; // or if slide amt is greater than half the width // determine if slide attempt is past start and end var isPastBounds = (!index && delta.x > 0) || // if first slide and slide amt is greater than 0 @@ -399,30 +399,30 @@ ionic.views.Slider = ionic.views.View.inherit({ if (options.continuous) { // we need to get the next in this direction in place - move(circle(index-1), -width, 0); - move(circle(index+2), width, 0); + move(circle(index - 1), -width, 0); + move(circle(index + 2), width, 0); } else { - move(index-1, -width, 0); + move(index - 1, -width, 0); } - move(index, slidePos[index]-width, speed); - move(circle(index+1), slidePos[circle(index+1)]-width, speed); - index = circle(index+1); + move(index, slidePos[index] - width, speed); + move(circle(index + 1), slidePos[circle(index + 1)] - width, speed); + index = circle(index + 1); } else { if (options.continuous) { // we need to get the next in this direction in place - move(circle(index+1), width, 0); - move(circle(index-2), -width, 0); + move(circle(index + 1), width, 0); + move(circle(index - 2), -width, 0); } else { - move(index+1, width, 0); + move(index + 1, width, 0); } - move(index, slidePos[index]+width, speed); - move(circle(index-1), slidePos[circle(index-1)]+width, speed); - index = circle(index-1); + move(index, slidePos[index] + width, speed); + move(circle(index - 1), slidePos[circle(index - 1)] + width, speed); + index = circle(index - 1); } @@ -432,15 +432,15 @@ ionic.views.Slider = ionic.views.View.inherit({ if (options.continuous) { - move(circle(index-1), -width, speed); + move(circle(index - 1), -width, speed); move(index, 0, speed); - move(circle(index+1), width, speed); + move(circle(index + 1), width, speed); } else { - move(index-1, -width, speed); + move(index - 1, -width, speed); move(index, 0, speed); - move(index+1, width, speed); + move(index + 1, width, speed); } } @@ -491,7 +491,8 @@ ionic.views.Slider = ionic.views.View.inherit({ this.slideIsDisabled = !shouldEnable; } return !this.slideIsDisabled; - }, + }; + this.slide = this.select = function(to, speed) { // cancel slideshow stop(); diff --git a/js/views/toggleView.js b/js/views/toggleView.js index 7f9dabb6b8e..99f5c96df63 100644 --- a/js/views/toggleView.js +++ b/js/views/toggleView.js @@ -40,7 +40,7 @@ ionic.offGesture(this.dragReleaseGesture, 'release', this.releaseHandler); }, - tap: function(e) { + tap: function() { if(this.el.getAttribute('disabled') !== 'disabled') { this.val( !this.checkbox.checked ); } @@ -71,13 +71,9 @@ // Stop any parent dragging e.gesture.srcEvent.preventDefault(); - ionic.requestAnimationFrame(function(amount) { + ionic.requestAnimationFrame(function () { if (!self._dragInfo) { return; } - var slidePageLeft = self.track.offsetLeft + (self.handle.offsetWidth / 2); - var slidePageRight = self.track.offsetLeft + self.track.offsetWidth - (self.handle.offsetWidth / 2); - var dx = e.gesture.deltaX; - var px = e.gesture.touches[0].pageX - self._dragInfo.left; var mx = self._dragInfo.width - self.triggerThreshold; @@ -99,11 +95,11 @@ }); }, - endDrag: function(e) { + endDrag: function() { this._dragInfo = null; }, - hold: function(e) { + hold: function() { this.el.classList.add('dragging'); }, release: function(e) { diff --git a/package.json b/package.json index 3e4dac188a4..29054ecbe45 100644 --- a/package.json +++ b/package.json @@ -18,11 +18,11 @@ "github": "^0.2.1", "gulp": "^3.7.0", "gulp-concat": "^2.1.7", + "gulp-eslint": "^0.9.0", "gulp-footer": "^1.0.4", "gulp-header": "^1.0.2", "gulp-if": "0.0.5", "gulp-jscs": "^1.3.0", - "gulp-jshint": "^1.5.0", "gulp-minify-css": "^0.3.0", "gulp-rename": "^1.1.0", "gulp-sass": "^0.7.1", diff --git a/test/unit/angular/controller/sideMenuController.unit.js b/test/unit/angular/controller/sideMenuController.unit.js index a19e5f4ebff..fbdf7103e87 100644 --- a/test/unit/angular/controller/sideMenuController.unit.js +++ b/test/unit/angular/controller/sideMenuController.unit.js @@ -302,7 +302,7 @@ describe('$ionicSideMenus controller', function() { expect(ctrl.getOpenPercentage()).toEqual(-100); }); - it('should register with backButton on open and dereg on close', inject(function($ionicPlatform) { + it('should register with backButton on open and dereg on close', inject(function($ionicPlatform, IONIC_BACK_PRIORITY) { var openAmount = 0; var deregSpy = jasmine.createSpy('deregister'); spyOn($ionicPlatform, 'registerBackButtonAction').andReturn(deregSpy); @@ -314,7 +314,7 @@ describe('$ionicSideMenus controller', function() { ctrl.$scope.$apply(); expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith( jasmine.any(Function), - PLATFORM_BACK_BUTTON_PRIORITY_SIDE_MENU + IONIC_BACK_PRIORITY.sideMenu ); expect(deregSpy).not.toHaveBeenCalled(); openAmount = 0; diff --git a/test/unit/angular/service/loading.unit.js b/test/unit/angular/service/loading.unit.js index e3dee335fc1..503740e97f8 100644 --- a/test/unit/angular/service/loading.unit.js +++ b/test/unit/angular/service/loading.unit.js @@ -159,13 +159,13 @@ describe('$ionicLoading service', function() { })); describe("back button", function() { - it('.show() should register back button action', inject(function($ionicLoading, $ionicPlatform, $timeout) { + it('.show() should register back button action', inject(function($ionicLoading, $ionicPlatform, $timeout, IONIC_BACK_PRIORITY) { spyOn($ionicPlatform, 'registerBackButtonAction'); $ionicLoading.show(); $timeout.flush(); expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith( angular.noop, - PLATFORM_BACK_BUTTON_PRIORITY_LOADING + IONIC_BACK_PRIORITY.loading ); })); it('.hide() should deregister back button action', inject(function($ionicLoading, $ionicPlatform, $timeout) { diff --git a/test/unit/angular/service/modal.unit.js b/test/unit/angular/service/modal.unit.js index dc722c9805a..c1bfd4ad968 100644 --- a/test/unit/angular/service/modal.unit.js +++ b/test/unit/angular/service/modal.unit.js @@ -109,7 +109,7 @@ describe('Ionic Modal', function() { expect(instance.isShown()).toBe(false); })); - it('should not close on hardware back button if option', inject(function($ionicPlatform) { + it('should not close on hardware back button if option', inject(function($ionicPlatform, IONIC_BACK_PRIORITY) { var template = ''; var instance = modal.fromTemplate(template, { hardwareBackButtonClose: false @@ -117,7 +117,10 @@ describe('Ionic Modal', function() { spyOn($ionicPlatform, 'registerBackButtonAction').andCallThrough(); instance.show(); timeout.flush(); - expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith(jasmine.any(Function), PLATFORM_BACK_BUTTON_PRIORITY_MODAL); + expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith( + jasmine.any(Function), + IONIC_BACK_PRIORITY.modal + ); ionicPlatform.hardwareBackButtonClick(); diff --git a/test/unit/angular/service/popover.unit.js b/test/unit/angular/service/popover.unit.js index 65c9f3d9156..1bb7b2bce3a 100644 --- a/test/unit/angular/service/popover.unit.js +++ b/test/unit/angular/service/popover.unit.js @@ -128,7 +128,7 @@ describe('Ionic Popover', function() { expect(instance.isShown()).toBe(false); })); - it('should not close on hardware back button if option', inject(function($ionicPlatform) { + it('should not close on hardware back button if option', inject(function($ionicPlatform, IONIC_BACK_PRIORITY) { var template = '
'; var instance = popover.fromTemplate(template, { hardwareBackButtonClose: false @@ -136,7 +136,10 @@ describe('Ionic Popover', function() { spyOn($ionicPlatform, 'registerBackButtonAction').andCallThrough(); instance.show(); timeout.flush(); - expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith(jasmine.any(Function), PLATFORM_BACK_BUTTON_PRIORITY_MODAL); + expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith( + jasmine.any(Function), + IONIC_BACK_PRIORITY.modal + ); ionicPlatform.hardwareBackButtonClick(); diff --git a/test/unit/angular/service/popup.unit.js b/test/unit/angular/service/popup.unit.js index fcf33be056a..89cf178c4ce 100644 --- a/test/unit/angular/service/popup.unit.js +++ b/test/unit/angular/service/popup.unit.js @@ -174,7 +174,7 @@ describe('$ionicPopup service', function() { document.body.classList.remove('popup-open'); }); - it('should add popup-open and retain backdrop and register back button action if no previous popup', inject(function($ionicBackdrop, $timeout, $ionicPlatform) { + it('should add popup-open and retain backdrop and register back button action if no previous popup', inject(function($ionicBackdrop, $timeout, $ionicPlatform, IONIC_BACK_PRIORITY) { spyOn($ionicPlatform, 'registerBackButtonAction').andReturn('actionReturn'); spyOn($ionicBackdrop, 'retain'); $ionicPopup.show(); @@ -183,7 +183,7 @@ describe('$ionicPopup service', function() { expect($ionicBackdrop.retain).toHaveBeenCalled(); expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith( jasmine.any(Function), - PLATFORM_BACK_BUTTON_PRIORITY_POPUP + IONIC_BACK_PRIORITY.popup ); expect($ionicPopup._backButtonActionDone).toBe('actionReturn'); }));