Skip to content

Commit

Permalink
ES6 conversion (#4)
Browse files Browse the repository at this point in the history
* Convert to ES6, module syntax

* modify precommit hook

* modify export

* finalize 2.0.0
  • Loading branch information
tjsail33 authored Nov 8, 2016
1 parent 2f3a772 commit 245ca30
Show file tree
Hide file tree
Showing 9 changed files with 405 additions and 443 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-indeterminate",
"version": "1.1.0",
"version": "2.0.0",
"description": "Tri-state indeterminate checkboxes in Angular",
"main": "dist/angular-indeterminate.js",
"authors": [
Expand Down
80 changes: 0 additions & 80 deletions dist/angular-indeterminate.js

This file was deleted.

7 changes: 0 additions & 7 deletions gulp-tasks/default.js

This file was deleted.

53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
angular.module('ngIndeterminate', [])
.directive('indeterminate', ($parse) => {
return {
restrict: 'AE',
link: (scope, elem, attrs) => {
let propKey = attrs.indeterminateKey || 'enabled';
let disabledKey = attrs.indeterminateDisabled || 'adminDisabled';
let trueValue = true;
let falseValue = false;
if (attrs.ngTrueValue && attrs.ngFalseValue) {
trueValue = $parse(attrs.ngTrueValue)(scope);
falseValue = $parse(attrs.ngFalseValue)(scope);
}
else if (attrs.ngTrueValue || attrs.ngFalseValue) {
throw new Error('Must have both ngTrueValue and ngFalseValue set');
}

// Watch for changes to the list that comprises the indeterminate checkbox
scope.$watch(() => {
const values = scope.$eval(attrs.indeterminate);
return values.filter(v => !v[disabledKey]).filter(v => v[propKey] === trueValue).length + values.length;
}, () => {
const values = scope.$eval(attrs.indeterminate).filter(v => !v[disabledKey]);
const enabled = values.filter(v => v[propKey] === trueValue);
elem[0].indeterminate = 0 < enabled.length && enabled.length < values.length;
if (enabled.length === values.length) {
elem[0].checked = true;
} else {
elem[0].checked = false;
}
});

// Update the list when the indeterminate is clicked
elem.on('click', (e) => {
scope.$apply(() => {
const values = scope.$eval(attrs.indeterminate).filter(v => !v[disabledKey]);
const enabled = values.filter(v => v[propKey] === trueValue);
let setValue;
if (enabled.length < values.length) {
setValue = trueValue;
} else {
setValue = falseValue;
}
for (let i = 0; i < values.length; i++) {
if (!values[i][disabledKey]) values[i][propKey] = setValue;
}
});
});
},
};
});

if (typeof exports !== 'undefined' && typeof module !== 'undefined') module.exports = exports = 'ngIndeterminate';
24 changes: 12 additions & 12 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,23 @@ module.exports = function(config) {
'node_modules/jquery/dist/jquery.js',
'node_modules/angular/angular.js',
'node_modules/angular-mocks/angular-mocks.js',
'src/*.coffee',
'tests/*.coffee'
'index.js',
'spec.js'
],
reporters: ['coverage','spec','junit'],
preprocessors: {
'src/*.coffee': ['coverage'],
'tests/*.coffee': ['coffee']
'*.js': ['coverage', 'babel'],
},
coffeePreprocessor: {
babelPreprocessor: {
options: {
sourceMap: true
presets: ['es2015'],
sourceMap: 'inline'
},
filename: function (file) {
return file.originalPath.replace(/\.js$/, '.es5.js');
},
sourceFileName: function (file) {
return file.originalPath;
}
},
junitReporter: {
Expand All @@ -27,12 +33,6 @@ module.exports = function(config) {
},
coverageReporter: {
dir : 'coverage',
instrumenters: {
ibrik: require('ibrik')
},
instrumenter: {
'**/*.coffee': 'ibrik'
},
reporters: [
{ type: 'cobertura', subdir: '.'},
{ type: 'html', subdir: '.' }
Expand Down
10 changes: 7 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "angular-indeterminate",
"version": "1.1.0",
"version": "2.0.0",
"description": "Tri-state indeterminate checkboxes in Angular",
"scripts": {
"test": "gulp unit",
"precommit": "echo 'Running pre-commit tasks...'; gulp unit && gulp && git add dist"
"precommit": "echo 'Running pre-commit tasks...'; gulp unit"
},
"pre-commit": ["precommit"],
"pre-commit": [
"precommit"
],
"repository": {
"type": "git",
"url": "git+https://github.com/tjsail33/angular-indeterminate.git"
Expand All @@ -28,6 +30,7 @@
"devDependencies": {
"angular": "^1.5.8",
"angular-mocks": "^1.5.8",
"babel-preset-es2015": "^6.18.0",
"gulp": "^3.9.1",
"gulp-bump": "^2.4.0",
"gulp-coffee": "^2.3.2",
Expand All @@ -37,6 +40,7 @@
"jasmine": "^2.5.1",
"jquery": "^3.1.0",
"karma": "^1.3.0",
"karma-babel-preprocessor": "^6.0.1",
"karma-coffee-preprocessor": "^1.0.1",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
Expand Down
Loading

0 comments on commit 245ca30

Please sign in to comment.