rails-angulate 0.0.3.rc5 → 0.0.3.rc6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/assets/javascripts/rails/angulate/directives/form_extensions.js.coffee +47 -0
- data/app/assets/javascripts/rails/angulate/directives/is_length.js.coffee +17 -0
- data/app/assets/javascripts/rails/angulate/directives/module.js.coffee +1 -0
- data/app/assets/javascripts/rails/angulate/directives/validator.js.coffee +37 -0
- data/app/assets/javascripts/rails/angulate/module.js.coffee +5 -0
- data/app/assets/javascripts/rails/angulate.js.coffee +6 -0
- data/lib/rails/angulate/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9cee89dda57048056c176f750c2b292d1f71db9f
|
4
|
+
data.tar.gz: 6d9d4482bc62bf84db08b1d532937b47dcd6ce1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e93a9aa6087dbf45109bba3a8752500e18e62d0e8f2f2f8de7a1278adc765553a7574b120c326e81041d2a2c2a7f431140424a9100c411346c8eb48d3bb40be
|
7
|
+
data.tar.gz: cf932fe7780e0d1ba0241f0c462a55e22de024b3ab5c07466d0ec6a533ac751c0cca72c749c61ddc23ed80e382d134df3f1f2f612902c6648849ed4e64a36974
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# Add $blur flag to form controller
|
2
|
+
blurifyDirective = ['$timeout', ($timeout) ->
|
3
|
+
restrict: 'E',
|
4
|
+
require: '^form'
|
5
|
+
link: (scope, element, attrs, form) ->
|
6
|
+
return unless attrs.name
|
7
|
+
form.$blur = false
|
8
|
+
|
9
|
+
element.on 'blur', handler = ->
|
10
|
+
field = form[attrs.name]
|
11
|
+
if field?
|
12
|
+
$timeout ->
|
13
|
+
field.$blur = true
|
14
|
+
|
15
|
+
scope.$on '$destroy', ->
|
16
|
+
element.off 'blur', handler
|
17
|
+
]
|
18
|
+
|
19
|
+
formExtensions = ['$timeout', ($timeout) ->
|
20
|
+
restrict: 'E',
|
21
|
+
require: 'form',
|
22
|
+
link: (scope, element, attrs, form) ->
|
23
|
+
element.attr('novalidate', 'novalidate')
|
24
|
+
form.$submitted = false
|
25
|
+
_submit = (e) ->
|
26
|
+
if form.$invalid
|
27
|
+
e.preventDefault()
|
28
|
+
$timeout ->
|
29
|
+
form.$submit_attempt = true
|
30
|
+
else
|
31
|
+
$timeout ->
|
32
|
+
form.$submitted = true
|
33
|
+
|
34
|
+
element.on 'submit', _submit
|
35
|
+
|
36
|
+
scope.$on '$destroy', ->
|
37
|
+
element.off 'submit', _submit
|
38
|
+
]
|
39
|
+
|
40
|
+
angular.module 'angulate.directives'
|
41
|
+
|
42
|
+
.directive('input', blurifyDirective)
|
43
|
+
.directive('textarea', blurifyDirective)
|
44
|
+
.directive('select', blurifyDirective)
|
45
|
+
.directive('blurify', blurifyDirective)
|
46
|
+
|
47
|
+
.directive('form', formExtensions)
|
@@ -0,0 +1,17 @@
|
|
1
|
+
angular.module 'angulate.directives'
|
2
|
+
|
3
|
+
# Using ng qualifier because this "goes" with ng-maxlength and ng-minlength
|
4
|
+
.directive 'ngIslength', ->
|
5
|
+
restrict: 'AC',
|
6
|
+
require: 'ngModel'
|
7
|
+
link: (scope, element, attrs, ctrl) ->
|
8
|
+
length = +attrs.ngIslength
|
9
|
+
|
10
|
+
isLengthValidator = (value) ->
|
11
|
+
validity = ctrl.$isEmpty(value) || value.length == length
|
12
|
+
ctrl.$setValidity('islength', validity)
|
13
|
+
return value if validity
|
14
|
+
|
15
|
+
ctrl.$parsers.push(isLengthValidator)
|
16
|
+
ctrl.$formatters.push(isLengthValidator)
|
17
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
angular.module 'angulate.directives', []
|
@@ -0,0 +1,37 @@
|
|
1
|
+
angular.module 'angulate.directives'
|
2
|
+
|
3
|
+
# Generic validator
|
4
|
+
.directive 'angValidator', ->
|
5
|
+
restrict: 'AC',
|
6
|
+
require: '?ngModel'
|
7
|
+
scope:
|
8
|
+
validIf: '&angValidIf'
|
9
|
+
link: (scope, element, attrs, ctrl) ->
|
10
|
+
return unless ctrl?
|
11
|
+
|
12
|
+
validationType = attrs.angValidator || 'validator'
|
13
|
+
|
14
|
+
validate_each = (value, validationExpr) ->
|
15
|
+
boolOrValidations = scope.$eval(validationExpr, value: value)
|
16
|
+
return boolOrValidations if typeof valid is 'boolean'
|
17
|
+
|
18
|
+
result = true
|
19
|
+
for type, condition of boolOrValidations
|
20
|
+
valid = scope.$eval(condition, value: value)
|
21
|
+
ctrl.$setValidity(type, valid)
|
22
|
+
result &&= valid
|
23
|
+
|
24
|
+
result
|
25
|
+
|
26
|
+
validator = (value) ->
|
27
|
+
return unless value?
|
28
|
+
|
29
|
+
if attrs.angValidIf
|
30
|
+
valid = validate_each(value, attrs.angValidIf)
|
31
|
+
|
32
|
+
ctrl.$setValidity(validationType, valid)
|
33
|
+
return value if valid
|
34
|
+
|
35
|
+
ctrl.$parsers.push(validator)
|
36
|
+
ctrl.$formatters.push(validator)
|
37
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-angulate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.3.
|
4
|
+
version: 0.0.3.rc6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stan Bondi
|
@@ -78,6 +78,12 @@ files:
|
|
78
78
|
- LICENSE.txt
|
79
79
|
- README.md
|
80
80
|
- Rakefile
|
81
|
+
- app/assets/javascripts/rails/angulate.js.coffee
|
82
|
+
- app/assets/javascripts/rails/angulate/directives/form_extensions.js.coffee
|
83
|
+
- app/assets/javascripts/rails/angulate/directives/is_length.js.coffee
|
84
|
+
- app/assets/javascripts/rails/angulate/directives/module.js.coffee
|
85
|
+
- app/assets/javascripts/rails/angulate/directives/validator.js.coffee
|
86
|
+
- app/assets/javascripts/rails/angulate/module.js.coffee
|
81
87
|
- lib/rails-angulate.rb
|
82
88
|
- lib/rails/angulate.rb
|
83
89
|
- lib/rails/angulate/configuration.rb
|