diff options
Diffstat (limited to 'src/ng/directive')
| -rw-r--r-- | src/ng/directive/a.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/directives.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/form.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/input.js | 39 | ||||
| -rw-r--r-- | src/ng/directive/ngBind.js | 5 | ||||
| -rw-r--r-- | src/ng/directive/ngClass.js | 5 | ||||
| -rw-r--r--[-rwxr-xr-x] | src/ng/directive/ngIf.js | 4 | ||||
| -rw-r--r-- | src/ng/directive/ngInit.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/ngRepeat.js | 14 | ||||
| -rw-r--r-- | src/ng/directive/ngSwitch.js | 2 | ||||
| -rw-r--r-- | src/ng/directive/select.js | 43 |
11 files changed, 73 insertions, 47 deletions
diff --git a/src/ng/directive/a.js b/src/ng/directive/a.js index 25cd9105..b3e9ad6d 100644 --- a/src/ng/directive/a.js +++ b/src/ng/directive/a.js @@ -39,6 +39,6 @@ var htmlAnchorDirective = valueFn({ event.preventDefault(); } }); - } + }; } }); diff --git a/src/ng/directive/directives.js b/src/ng/directive/directives.js index aa316533..b97408e6 100644 --- a/src/ng/directive/directives.js +++ b/src/ng/directive/directives.js @@ -4,7 +4,7 @@ function ngDirective(directive) { if (isFunction(directive)) { directive = { link: directive - } + }; } directive.restrict = directive.restrict || 'AC'; return valueFn(directive); diff --git a/src/ng/directive/form.js b/src/ng/directive/form.js index 455ad15f..6b5c52f4 100644 --- a/src/ng/directive/form.js +++ b/src/ng/directive/form.js @@ -1,6 +1,6 @@ 'use strict'; - +/* global -nullFormCtrl */ var nullFormCtrl = { $addControl: noop, $removeControl: noop, diff --git a/src/ng/directive/input.js b/src/ng/directive/input.js index 87afc328..07b5f997 100644 --- a/src/ng/directive/input.js +++ b/src/ng/directive/input.js @@ -1,5 +1,13 @@ 'use strict'; +/* global + + -VALID_CLASS, + -INVALID_CLASS, + -PRISTINE_CLASS, + -DIRTY_CLASS +*/ + var URL_REGEXP = /^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?$/; var EMAIL_REGEXP = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}$/; var NUMBER_REGEXP = /^\s*(\-|\+)?(\d+|(\d*(\.\d*)))\s*$/; @@ -939,22 +947,22 @@ var VALID_CLASS = 'ng-valid', * <example module="badIsolatedDirective"> <file name="script.js"> angular.module('badIsolatedDirective', []).directive('bad', function() { - return { - require: 'ngModel', - scope: { }, - template: '<input ng-model="innerModel">', - link: function(scope, element, attrs, ngModel) { - scope.$watch('innerModel', function(value) { - console.log(value); - ngModel.$setViewValue(value); - }); - } - }; + return { + require: 'ngModel', + scope: { }, + template: '<input ng-model="innerModel">', + link: function(scope, element, attrs, ngModel) { + scope.$watch('innerModel', function(value) { + console.log(value); + ngModel.$setViewValue(value); + }); + } + }; }); </file> <file name="index.html"> - <input ng-model="someModel"> - <div bad ng-model="someModel"></div> + <input ng-model="someModel"> + <div bad ng-model="someModel"></div> </file> * </example> * @@ -1047,7 +1055,10 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ * @param {boolean} isValid Whether the current state is valid (true) or invalid (false). */ this.$setValidity = function(validationErrorKey, isValid) { + // Purposeful use of ! here to cast isValid to boolean in case it is undefined + // jshint -W018 if ($error[validationErrorKey] === !isValid) return; + // jshint +W018 if (isValid) { if ($error[validationErrorKey]) invalidCount--; @@ -1127,7 +1138,7 @@ var NgModelController = ['$scope', '$exceptionHandler', '$attrs', '$element', '$ } catch(e) { $exceptionHandler(e); } - }) + }); } }; diff --git a/src/ng/directive/ngBind.js b/src/ng/directive/ngBind.js index c55ab076..82ff505a 100644 --- a/src/ng/directive/ngBind.js +++ b/src/ng/directive/ngBind.js @@ -50,6 +50,9 @@ var ngBindDirective = ngDirective(function(scope, element, attr) { element.addClass('ng-binding').data('$binding', attr.ngBind); scope.$watch(attr.ngBind, function ngBindWatchAction(value) { + // We are purposefully using == here rather than === because we want to + // catch when value is "null or undefined" + // jshint -W041 element.text(value == undefined ? '' : value); }); }); @@ -111,7 +114,7 @@ var ngBindTemplateDirective = ['$interpolate', function($interpolate) { attr.$observe('ngBindTemplate', function(value) { element.text(value); }); - } + }; }]; diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 7fcdcfec..39568f6a 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -6,7 +6,7 @@ function classDirective(name, selector) { return { restrict: 'AC', link: function(scope, element, attr) { - var oldVal = undefined; + var oldVal; scope.$watch(attr[name], ngClassWatchAction, true); @@ -17,6 +17,7 @@ function classDirective(name, selector) { if (name !== 'ngClass') { scope.$watch('$index', function($index, old$index) { + // jshint bitwise: false var mod = $index & 1; if (mod !== old$index & 1) { if (mod === selector) { @@ -63,7 +64,7 @@ function classDirective(name, selector) { } return classVal; - }; + } } }; }; diff --git a/src/ng/directive/ngIf.js b/src/ng/directive/ngIf.js index dc95d170..00556539 100755..100644 --- a/src/ng/directive/ngIf.js +++ b/src/ng/directive/ngIf.js @@ -104,7 +104,7 @@ var ngIfDirective = ['$animate', function($animate) { }); } }); - } + }; } - } + }; }]; diff --git a/src/ng/directive/ngInit.js b/src/ng/directive/ngInit.js index 854f5c35..36f130c7 100644 --- a/src/ng/directive/ngInit.js +++ b/src/ng/directive/ngInit.js @@ -52,6 +52,6 @@ var ngInitDirective = ngDirective({ pre: function(scope, element, attrs) { scope.$eval(attrs.ngInit); } - } + }; } }); diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index bce76411..e3ff1b8e 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -243,10 +243,10 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { } else { trackByIdArrayFn = function(key, value) { return hashKey(value); - } + }; trackByIdObjFn = function(key) { return key; - } + }; } match = lhs.match(/^(?:([\$\w]+)|\(([\$\w]+)\s*,\s*([\$\w]+)\))$/); @@ -308,7 +308,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { trackById = trackByIdFn(key, value, index); assertNotHasOwnProperty(trackById, '`track by` id'); if(lastBlockMap.hasOwnProperty(trackById)) { - block = lastBlockMap[trackById] + block = lastBlockMap[trackById]; delete lastBlockMap[trackById]; nextBlockMap[trackById] = block; nextBlockOrder[index] = block; @@ -356,9 +356,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { nextNode = nextNode.nextSibling; } while(nextNode && nextNode[NG_REMOVED]); - if (block.startNode == nextNode) { - // do nothing - } else { + if (block.startNode != nextNode) { // existing item which got moved $animate.move(getBlockElements(block), null, jqLite(previousNode)); } @@ -374,7 +372,9 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) { childScope.$first = (index === 0); childScope.$last = (index === (arrayLength - 1)); childScope.$middle = !(childScope.$first || childScope.$last); - childScope.$odd = !(childScope.$even = index%2==0); + // jshint bitwise: false + childScope.$odd = !(childScope.$even = (index&1) === 0); + // jshint bitwise: true if (!block.startNode) { linker(childScope, function(clone) { diff --git a/src/ng/directive/ngSwitch.js b/src/ng/directive/ngSwitch.js index 320400d9..b67aa904 100644 --- a/src/ng/directive/ngSwitch.js +++ b/src/ng/directive/ngSwitch.js @@ -161,7 +161,7 @@ var ngSwitchDirective = ['$animate', function($animate) { } }); } - } + }; }]; var ngSwitchWhenDirective = ngDirective({ diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index fb03e0ca..83148e22 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -126,10 +126,12 @@ var ngOptionsMinErr = minErr('ngOptions'); */ var ngOptionsDirective = valueFn({ terminal: true }); +// jshint maxlen: false var selectDirective = ['$compile', '$parse', function($compile, $parse) { //0000111110000000000022220000000000000000000000333300000000000000444444444444444000000000555555555555555000000066666666666666600000000000000007777000000000000000000088888 var NG_OPTIONS_REGEXP = /^\s*(.*?)(?:\s+as\s+(.*?))?(?:\s+group\s+by\s+(.*))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+(.*?)(?:\s+track\s+by\s+(.*?))?$/, nullModelCtrl = {$setViewValue: noop}; +// jshint maxlen: 100 return { restrict: 'E', @@ -210,7 +212,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { // find "null" option for(var i = 0, children = element.children(), ii = children.length; i < ii; i++) { - if (children[i].value == '') { + if (children[i].value === '') { emptyOption = nullOption = children.eq(i); break; } @@ -233,16 +235,16 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { }); } - if (optionsExp) Options(scope, element, ngModelCtrl); - else if (multiple) Multiple(scope, element, ngModelCtrl); - else Single(scope, element, ngModelCtrl, selectCtrl); + if (optionsExp) setupAsOptions(scope, element, ngModelCtrl); + else if (multiple) setupAsMultiple(scope, element, ngModelCtrl); + else setupAsSingle(scope, element, ngModelCtrl, selectCtrl); //////////////////////////// - function Single(scope, selectElement, ngModelCtrl, selectCtrl) { + function setupAsSingle(scope, selectElement, ngModelCtrl, selectCtrl) { ngModelCtrl.$render = function() { var viewValue = ngModelCtrl.$viewValue; @@ -267,7 +269,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { }); } - function Multiple(scope, selectElement, ctrl) { + function setupAsMultiple(scope, selectElement, ctrl) { var lastView; ctrl.$render = function() { var items = new HashMap(ctrl.$viewValue); @@ -298,12 +300,14 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { }); } - function Options(scope, selectElement, ctrl) { + function setupAsOptions(scope, selectElement, ctrl) { var match; if (! (match = optionsExp.match(NG_OPTIONS_REGEXP))) { throw ngOptionsMinErr('iexp', - "Expected expression in form of '_select_ (as _label_)? for (_key_,)?_value_ in _collection_' but got '{0}'. Element: {1}", + "Expected expression in form of " + + "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" + + " but got '{0}'. Element: {1}", optionsExp, startingTag(selectElement)); } @@ -315,9 +319,10 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { valuesFn = $parse(match[7]), track = match[8], trackFn = track ? $parse(match[8]) : null, - // This is an array of array of existing option groups in DOM. We try to reuse these if possible - // optionGroupsCache[0] is the options with no option group - // optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element + // This is an array of array of existing option groups in DOM. + // We try to reuse these if possible + // - optionGroupsCache[0] is the options with no option group + // - optionGroupsCache[?][0] is the parent: either the SELECT or OPTGROUP element optionGroupsCache = [[{element: selectElement, label:''}]]; if (nullOption) { @@ -371,7 +376,7 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { key = selectElement.val(); if (key == '?') { value = undefined; - } else if (key == ''){ + } else if (key === ''){ value = null; } else { if (trackFn) { @@ -399,7 +404,8 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { scope.$watch(render); function render() { - var optionGroups = {'':[]}, // Temporary location for the option groups before we render them + // Temporary location for the option groups before we render them + var optionGroups = {'':[]}, optionGroupNames = [''], optionGroupName, optionGroup, @@ -448,7 +454,9 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { optionGroupNames.push(optionGroupName); } if (multiple) { - selected = selectedSet.remove(trackFn ? trackFn(scope, locals) : valueFn(scope, locals)) !== undefined; + selected = isDefined( + selectedSet.remove(trackFn ? trackFn(scope, locals) : valueFn(scope, locals)) + ); } else { if (trackFn) { var modelCast = {}; @@ -460,9 +468,12 @@ var selectDirective = ['$compile', '$parse', function($compile, $parse) { selectedSet = selectedSet || selected; // see if at least one item is selected } label = displayFn(scope, locals); // what will be seen by the user - label = label === undefined ? '' : label; // doing displayFn(scope, locals) || '' overwrites zero values + + // doing displayFn(scope, locals) || '' overwrites zero values + label = isDefined(label) ? label : ''; optionGroup.push({ - id: trackFn ? trackFn(scope, locals) : (keyName ? keys[index] : index), // either the index into array or key from object + // either the index into array or key from object + id: trackFn ? trackFn(scope, locals) : (keyName ? keys[index] : index), label: label, selected: selected // determine if we should be selected }); |
