Skip to content

Commit 431c6e9

Browse files
committed
Initial commit.
0 parents  commit 431c6e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+886
-0
lines changed

.bowerrc

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory": "vendor"
3+
}

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules
2+
bower_components
3+
vendor
4+
temp
5+
tmp
6+
*.log

AUTHORS.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# AUTHORS
2+
3+
* Johnny Hauser (https://github.com/m59peacemaker)

CHANGELOG.md

Whitespace-only changes.

LICENSE-MIT

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
The MIT License (MIT)
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Angular Components

bower.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "angular-pmkr-components",
3+
"author": {
4+
"name": "Johnny Hauser",
5+
"email": "[email protected]",
6+
"url": "https://github.com/m59peacemaker"
7+
},
8+
"keywords": [
9+
"Angular",
10+
"Components",
11+
"Filters",
12+
"Services",
13+
"Directives"
14+
],
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/m59peacemaker/angular-pmkr-components"
18+
},
19+
"version": "0.0.0",
20+
"license": "MIT",
21+
"ignore": [
22+
".*",
23+
"gulpfile.js"
24+
],
25+
"dependencies": {
26+
"angular": "1.3.0-beta.18"
27+
}
28+
}

build/components.min.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/directives.min.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/filters.min.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/services.min.js

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var gulp = require('gulp');
2+
var gutil = require('gulp-util');
3+
var clean = require('gulp-clean');
4+
var rename = require('gulp-rename');
5+
var concat = require('gulp-concat');
6+
var header = require('gulp-header');
7+
var uglify = require('gulp-uglify');
8+
9+
var pkg = require('./package.json');
10+
11+
var banner = (function() {
12+
var tmpl = [
13+
'pmkr.components v<%= pkg.version %>',
14+
'<%= pkg.repository.url %>',
15+
'License: <%= pkg.license %>',
16+
'Author: <%= pkg.author.name %>',
17+
'File created: <%= gutil.date(now, "m.d.yyyy") %>'
18+
].join('\n');
19+
var obj = {
20+
tmpl : tmpl,
21+
ml : ['/*',tmpl,'*/','\n'].join('\n'),
22+
html : ['<!--',tmpl,'-->','\n'].join('\n'),
23+
data : {pkg:pkg, gutil:gutil, now:new Date()}
24+
};
25+
return obj;
26+
}());
27+
28+
gulp.task('default', ['build']);
29+
30+
gulp.task('build', [
31+
'components',
32+
'banner'
33+
]);
34+
35+
gulp.task('clean-build', function() {
36+
return gulp.src('build/**')
37+
.pipe(clean())
38+
});
39+
40+
gulp.task('banner', [
41+
'components'
42+
], function() {
43+
return gulp.src('**/*.js', {
44+
cwd: 'build',
45+
base:'build'
46+
})
47+
.pipe(header(banner.ml, banner.data))
48+
.pipe(gulp.dest('build'))
49+
});
50+
51+
gulp.task('services', function() {
52+
return gulp.src('src/services/**/*.js')
53+
.pipe(concat('services.js'))
54+
.pipe(uglify())
55+
.pipe(rename('services.min.js'))
56+
.pipe(gulp.dest('build'))
57+
;
58+
});
59+
60+
gulp.task('filters', function() {
61+
return gulp.src('src/filters/**/*.js')
62+
.pipe(concat('filters.js'))
63+
.pipe(uglify())
64+
.pipe(rename('filters.min.js'))
65+
.pipe(gulp.dest('build'))
66+
;
67+
});
68+
69+
gulp.task('directives', function() {
70+
return gulp.src('src/directives/**/*.js')
71+
.pipe(concat('directives.js'))
72+
.pipe(uglify())
73+
.pipe(rename('directives.min.js'))
74+
.pipe(gulp.dest('build'))
75+
;
76+
});
77+
78+
gulp.task('components', [
79+
'filters',
80+
'services',
81+
'directives'
82+
], function() {
83+
return gulp.src(['src/components.js', 'build/**/*.min.js'])
84+
.pipe(concat('components.js'))
85+
.pipe(uglify())
86+
.pipe(rename('components.min.js'))
87+
.pipe(gulp.dest('build'))
88+
});

package.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "angular-pmkr-components",
3+
"author": {
4+
"name": "Johnny Hauser",
5+
"email": "[email protected]",
6+
"url": "https://github.com/m59peacemaker"
7+
},
8+
"keywords": [
9+
"news"
10+
],
11+
"private": "true",
12+
"repository": {
13+
"type": "git",
14+
"url": "https://github.com/m59peacemaker/angular-pmkr-components"
15+
},
16+
"version": "0.0.0",
17+
"license": "MIT",
18+
"dependencies": {},
19+
"devDependencies": {
20+
"gulp": "^3.7.0",
21+
"gulp-clean": "^0.3.0",
22+
"gulp-concat": "^2.2.0",
23+
"gulp-header": "^1.0.2",
24+
"gulp-rename": "^1.2.0",
25+
"gulp-uglify": "^0.3.0",
26+
"gulp-util": "^2.2.16"
27+
}
28+
}

src/components.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
angular.module('pmkr.components', [
2+
'pmkr.components.filters',
3+
'pmkr.components.services',
4+
'pmkr.components.directives'
5+
]);

src/directives/directives.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
angular.module('pmkr.components.directives', [
2+
'pmkr.pristineOriginal',
3+
'pmkr.validateCustom'
4+
]);

src/directives/pristineOriginal/CHANGELOG.md

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Pristine Original
2+
3+
This directive returns an input element to `$pristine` state when its current value matches its original value.
4+
5+
## Usage:
6+
7+
```html
8+
<input ng-model="myModel" pmkr-pristine-original>
9+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
angular.module('pmkr.pristineOriginal', [])
2+
3+
.directive('pmkrPristineOriginal', [
4+
function() {
5+
6+
var directive = {
7+
restrict : 'A',
8+
require : 'ngModel',
9+
link: function($scope, $element, $atts, $ngModel) {
10+
11+
var pristineVal = null;
12+
13+
$scope.$watch(function() {
14+
return $ngModel.$viewValue;
15+
}, function(val) {
16+
// set pristineVal to newVal the first time this function runs
17+
if (pristineVal === null) {
18+
pristineVal = $ngModel.$isEmpty(val) ? '' : val.toString();
19+
}
20+
21+
// newVal is the original value - set input to pristine state
22+
if (pristineVal === val) {
23+
$ngModel.$setPristine();
24+
}
25+
26+
});
27+
28+
}
29+
};
30+
31+
return directive;
32+
33+
}
34+
])
35+
36+
;

src/directives/validateCustom/CHANGELOG.md

Whitespace-only changes.
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Validate Custom
2+
3+
A configurable directive to validate an input field using an asynchronous or synchronous function (service).
4+
5+
Directive priority: 1
6+
7+
Runs at priority 1 so that default priority (0) directives can set `ngModel` state before `gate` function runs.
8+
9+
## Dependencies
10+
11+
[pmkr.debounce][1]
12+
13+
## Usage
14+
15+
```html
16+
<input
17+
name="my_input"
18+
ng-model="myInput"
19+
pmkr-validate-custom="{name:'my-validation', fn:validationFn, gate:validationGate, wait:500, props:'validationProps'}"
20+
>
21+
```
22+
23+
```javascript
24+
// Note that this ought to be in a service and referenced to $scope. This is just for demonstration.
25+
$scope.validationFn = function(value) {
26+
return $http.get(validationUrl+value).then(function(resp) {
27+
// use resp to determine if value valid
28+
return isValid; // true or false
29+
});
30+
}
31+
32+
// The directive is gated off when this function returns true.
33+
$scope.validationGate = function(value, $ngModel) {
34+
return !value || $ngModel.$pristine;
35+
};
36+
```
37+
38+
### Parameters
39+
40+
#### name
41+
42+
Type: `String`
43+
44+
The validation name. `$error._____`, `ng-invalid-_____`, etc.
45+
46+
#### fn
47+
48+
Type: `Function`
49+
Parameters: value
50+
51+
Asynchronous or synchronous funcion that returns `true` or `false`. Return true if `value` is valid or false if invalid.
52+
53+
#### gate
54+
55+
Type: `Function`
56+
Parameters: value, ngModel
57+
58+
Synchronous function that returns true or false. Return true if validation should be skipped.
59+
60+
#### wait
61+
62+
Type: `Number`
63+
64+
Amount of `ms` to debounce validation.
65+
66+
#### props
67+
68+
Type: 'String'
69+
70+
Name of the `$scope` property to which the directive will assign useful properties for updating the view.
71+
72+
- `pending` - `true` while debounce and validation are in progress.
73+
- `validating` - `true` while the validation `fn` is in progress.
74+
- `valid` - `true` when the field is valid AND `pending` is `false`.
75+
- `invalid` - `true` when the field is invalid AND `pending` is `false`.
76+
- `checkedValue` - the value that was validated
77+
78+
[1]: https://github.com/m59peacemaker/angular-pmkr-components/tree/master/services/debounce

0 commit comments

Comments
 (0)