Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
m59peacemaker committed Aug 21, 2014
0 parents commit 431c6e9
Show file tree
Hide file tree
Showing 45 changed files with 886 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory": "vendor"
}
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
bower_components
vendor
temp
tmp
*.log
3 changes: 3 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# AUTHORS

* Johnny Hauser (https://github.com/m59peacemaker)
Empty file added CHANGELOG.md
Empty file.
19 changes: 19 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Angular Components
28 changes: 28 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "angular-pmkr-components",
"author": {
"name": "Johnny Hauser",
"email": "[email protected]",
"url": "https://github.com/m59peacemaker"
},
"keywords": [
"Angular",
"Components",
"Filters",
"Services",
"Directives"
],
"repository": {
"type": "git",
"url": "https://github.com/m59peacemaker/angular-pmkr-components"
},
"version": "0.0.0",
"license": "MIT",
"ignore": [
".*",
"gulpfile.js"
],
"dependencies": {
"angular": "1.3.0-beta.18"
}
}
9 changes: 9 additions & 0 deletions build/components.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions build/directives.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions build/filters.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions build/services.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 88 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
var gulp = require('gulp');
var gutil = require('gulp-util');
var clean = require('gulp-clean');
var rename = require('gulp-rename');
var concat = require('gulp-concat');
var header = require('gulp-header');
var uglify = require('gulp-uglify');

var pkg = require('./package.json');

var banner = (function() {
var tmpl = [
'pmkr.components v<%= pkg.version %>',
'<%= pkg.repository.url %>',
'License: <%= pkg.license %>',
'Author: <%= pkg.author.name %>',
'File created: <%= gutil.date(now, "m.d.yyyy") %>'
].join('\n');
var obj = {
tmpl : tmpl,
ml : ['/*',tmpl,'*/','\n'].join('\n'),
html : ['<!--',tmpl,'-->','\n'].join('\n'),
data : {pkg:pkg, gutil:gutil, now:new Date()}
};
return obj;
}());

gulp.task('default', ['build']);

gulp.task('build', [
'components',
'banner'
]);

gulp.task('clean-build', function() {
return gulp.src('build/**')
.pipe(clean())
});

gulp.task('banner', [
'components'
], function() {
return gulp.src('**/*.js', {
cwd: 'build',
base:'build'
})
.pipe(header(banner.ml, banner.data))
.pipe(gulp.dest('build'))
});

gulp.task('services', function() {
return gulp.src('src/services/**/*.js')
.pipe(concat('services.js'))
.pipe(uglify())
.pipe(rename('services.min.js'))
.pipe(gulp.dest('build'))
;
});

gulp.task('filters', function() {
return gulp.src('src/filters/**/*.js')
.pipe(concat('filters.js'))
.pipe(uglify())
.pipe(rename('filters.min.js'))
.pipe(gulp.dest('build'))
;
});

gulp.task('directives', function() {
return gulp.src('src/directives/**/*.js')
.pipe(concat('directives.js'))
.pipe(uglify())
.pipe(rename('directives.min.js'))
.pipe(gulp.dest('build'))
;
});

gulp.task('components', [
'filters',
'services',
'directives'
], function() {
return gulp.src(['src/components.js', 'build/**/*.min.js'])
.pipe(concat('components.js'))
.pipe(uglify())
.pipe(rename('components.min.js'))
.pipe(gulp.dest('build'))
});
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "angular-pmkr-components",
"author": {
"name": "Johnny Hauser",
"email": "[email protected]",
"url": "https://github.com/m59peacemaker"
},
"keywords": [
"news"
],
"private": "true",
"repository": {
"type": "git",
"url": "https://github.com/m59peacemaker/angular-pmkr-components"
},
"version": "0.0.0",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"gulp": "^3.7.0",
"gulp-clean": "^0.3.0",
"gulp-concat": "^2.2.0",
"gulp-header": "^1.0.2",
"gulp-rename": "^1.2.0",
"gulp-uglify": "^0.3.0",
"gulp-util": "^2.2.16"
}
}
5 changes: 5 additions & 0 deletions src/components.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
angular.module('pmkr.components', [
'pmkr.components.filters',
'pmkr.components.services',
'pmkr.components.directives'
]);
4 changes: 4 additions & 0 deletions src/directives/directives.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
angular.module('pmkr.components.directives', [
'pmkr.pristineOriginal',
'pmkr.validateCustom'
]);
Empty file.
9 changes: 9 additions & 0 deletions src/directives/pristineOriginal/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Pristine Original

This directive returns an input element to `$pristine` state when its current value matches its original value.

## Usage:

```html
<input ng-model="myModel" pmkr-pristine-original>
```
36 changes: 36 additions & 0 deletions src/directives/pristineOriginal/pristineOriginal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
angular.module('pmkr.pristineOriginal', [])

.directive('pmkrPristineOriginal', [
function() {

var directive = {
restrict : 'A',
require : 'ngModel',
link: function($scope, $element, $atts, $ngModel) {

var pristineVal = null;

$scope.$watch(function() {
return $ngModel.$viewValue;
}, function(val) {
// set pristineVal to newVal the first time this function runs
if (pristineVal === null) {
pristineVal = $ngModel.$isEmpty(val) ? '' : val.toString();
}

// newVal is the original value - set input to pristine state
if (pristineVal === val) {
$ngModel.$setPristine();
}

});

}
};

return directive;

}
])

;
Empty file.
78 changes: 78 additions & 0 deletions src/directives/validateCustom/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Validate Custom

A configurable directive to validate an input field using an asynchronous or synchronous function (service).

Directive priority: 1

Runs at priority 1 so that default priority (0) directives can set `ngModel` state before `gate` function runs.

## Dependencies

[pmkr.debounce][1]

## Usage

```html
<input
name="my_input"
ng-model="myInput"
pmkr-validate-custom="{name:'my-validation', fn:validationFn, gate:validationGate, wait:500, props:'validationProps'}"
>
```

```javascript
// Note that this ought to be in a service and referenced to $scope. This is just for demonstration.
$scope.validationFn = function(value) {
return $http.get(validationUrl+value).then(function(resp) {
// use resp to determine if value valid
return isValid; // true or false
});
}

// The directive is gated off when this function returns true.
$scope.validationGate = function(value, $ngModel) {
return !value || $ngModel.$pristine;
};
```

### Parameters

#### name

Type: `String`

The validation name. `$error._____`, `ng-invalid-_____`, etc.

#### fn

Type: `Function`
Parameters: value

Asynchronous or synchronous funcion that returns `true` or `false`. Return true if `value` is valid or false if invalid.

#### gate

Type: `Function`
Parameters: value, ngModel

Synchronous function that returns true or false. Return true if validation should be skipped.

#### wait

Type: `Number`

Amount of `ms` to debounce validation.

#### props

Type: 'String'

Name of the `$scope` property to which the directive will assign useful properties for updating the view.

- `pending` - `true` while debounce and validation are in progress.
- `validating` - `true` while the validation `fn` is in progress.
- `valid` - `true` when the field is valid AND `pending` is `false`.
- `invalid` - `true` when the field is invalid AND `pending` is `false`.
- `checkedValue` - the value that was validated

[1]: https://github.com/m59peacemaker/angular-pmkr-components/tree/master/services/debounce
Loading

0 comments on commit 431c6e9

Please sign in to comment.