material_raingular 0.0.2.7.1 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99e3d851c4221a249aa53f03ae38fdd28f763eb5
4
- data.tar.gz: 0205913549c975f6e6fc32f4ad6077e3a84b767e
3
+ metadata.gz: cbdd155f510682affee2271e8eb83df2446ad959
4
+ data.tar.gz: b1ee0aed082d80b1f9145cd3d00fdacb178bd1a9
5
5
  SHA512:
6
- metadata.gz: 7335a21dfe39742874e348a577e7abb9eaced116d6c23466e8ba16d9a2b50033ed433eb497bc10a3729d0ef7e9b15416b799b52c73e447194f0d26d5cd766005
7
- data.tar.gz: 6c6c88098a7d7f276d518356f13216487950edbb79ea9b236b8f0a0712c11da57b33e0adcdf5f2f67324cbe06f7eeb4093123c5f694b0c578cb441b3e94f384a
6
+ metadata.gz: ae067161369d177749ee9767d0e490d0522c58c33eff3d94f6eb24bce45bde3ce446649b9155f5846bd852e07375bb4c04ba45452a9fc23728a9520050d80c4f
7
+ data.tar.gz: 4a15effbbd28995118f464612fcd0effab1cd5c96d126ef23edf9ec564b8f0544929c0d92bd6955be3a9dc14dcbd2aa11904e251e1ccbcc09201e6baf9d26335
@@ -0,0 +1,133 @@
1
+ REGEXP = /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+disable\s+when\s+([\s\S]+?))?\s+for\s+(?:([\$\w][\$\w]*)|(?:\(\s*([\$\w][\$\w]*)\s*,\s*([\$\w][\$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/;
2
+ # 1: Model Value
3
+ # 2: Display Value
4
+ # 3: group by expression (groupByFn)
5
+ # 4: disable when expression (disableWhenFn)
6
+ # 5: Repeater
7
+ # 6: object item key variable name
8
+ # 7: object item value variable name
9
+ # 8: collection
10
+ # 9: track by expressionj
11
+
12
+ angular.module('FilteredSelect', [])
13
+ .directive 'ngFilteredSelect', ($parse,$filter,$timeout)->
14
+ require: 'ngModel'
15
+ link: (scope,element,attrs,ngModel) ->
16
+ filters = attrs.ngSelectOptions.split('|')
17
+ options = filters.shift()
18
+ match = options.match(REGEXP);
19
+ if !match
20
+ throw new Error(
21
+ "Expected expression in form of " +
22
+ "'_select_ (as _label_)? for (_key_,)?_value_ in _collection_'" +
23
+ " but got '" + attrs.ngSelectOptions + "'. Element: " + element[0].outerHTML)
24
+ collection = $parse(match[8])
25
+ modelValue = match[1].replace(match[5] + '.','')
26
+ viewValue = if match[2] then match[2].replace(match[5] + '.','') else modelValue
27
+ template = angular.element("<ul> </ul>")
28
+ search = angular.element "<input type='search' placeholder='Search'>"
29
+ tempHolder = angular.element("<div class='filtered-select' ></div>")
30
+ viewValueFn = $parse(viewValue || modelValue)
31
+ modelValueFn = $parse(modelValue || viewValue)
32
+ tempHolder.addClass('bottom') if element.hasClass('bottom')
33
+ template.bind 'mousewheel DOMMouseScroll', (event)->
34
+ delta = event.wheelDelta or event.originalEvent and event.originalEvent.wheelDelta or -event.detail
35
+ bottomOverflow = template[0].scrollTop + template.outerHeight() - template[0].scrollHeight >= 0
36
+ topOverflow = template[0].scrollTop <= 0
37
+ if delta < 0 and bottomOverflow or delta > 0 and topOverflow
38
+ event.preventDefault()
39
+ scrollStart = null
40
+ scrollTop = null
41
+ template.bind 'touchstart', (event)->
42
+ event.stopPropagation()
43
+ scrollStart = event.originalEvent.touches[0].clientY
44
+ template.bind 'touchmove', (event) ->
45
+ event.stopPropagation()
46
+ scroll = event.originalEvent.touches[0].clientY
47
+ scrollStart = scroll unless scrollStart
48
+ if scroll > scrollStart
49
+ event.preventDefault() if template.scrollTop() == 0
50
+ else if scroll < scrollStart
51
+ newScrollTop = template.scrollTop()
52
+ event.preventDefault() if scrollTop == newScrollTop
53
+ scrollTop = newScrollTop
54
+ scrollStart = scroll
55
+ return true
56
+ template.bind 'touchend', ->
57
+ event.stopPropagation()
58
+ scrollStart = null
59
+ body = angular.element('body')
60
+ body.bind 'keydown', (event) ->
61
+ tempHolder.removeClass('active') if event.keyCode == 27
62
+ tempHolder.append search
63
+ tempHolder.append template
64
+ body.append tempHolder
65
+ ulHeight = ->
66
+ full = window.innerHeight
67
+ full = full/3 if element.hasClass('bottom')
68
+ full - search[0].offsetHeight + 'px'
69
+ template.css('height',ulHeight())
70
+ scope.$watch collection, (newVal,oldVal) ->
71
+ return if newVal == oldVal
72
+ setInitialValue()
73
+ buildTemplate()
74
+ scope.$watch attrs.ngModel, (newVal,oldVal) ->
75
+ return if newVal == oldVal
76
+ setInitialValue()
77
+ search.bind 'input', ->
78
+ buildTemplate()
79
+ buildTemplate = ->
80
+ list= []
81
+ obj={}
82
+ obj[viewValue] = search.val() || ''
83
+ return unless collection(scope)
84
+ filteredList = $filter('orderBy')($filter('filter')(collection(scope), obj), viewValue)
85
+ for filter in filters
86
+ [filterType,value] = filter.replace(/\s+/,'').split(':')
87
+ filteredList = $filter(filterType)(filteredList, value)
88
+ for item in filteredList
89
+ li = angular.element '<li ng-model-value="' + modelValueFn(item) + '">' + viewValueFn(item) + '</li>'
90
+ li.bind 'mousedown', ($event)->
91
+ updateValue($event.target.attributes['ng-model-value'].value)
92
+ list.push li
93
+ template.empty()
94
+ template.append(list)
95
+ setInitialValue = ->
96
+ unless model = ngModel.$modelValue
97
+ view = attrs.placeholder
98
+ element.css('color','rgba(0,0,0,0.4)')
99
+ else
100
+ element.css('color','')
101
+ obj = {}
102
+ obj[modelValue] = model
103
+ list = $filter('filter')(collection(scope), obj)
104
+ viewScope = list[0] if list
105
+ view = if viewScope then viewValueFn(viewScope) else attrs.placeholder
106
+ element.html('')
107
+ element.html(view)
108
+ setInitialValue()
109
+ buildTemplate()
110
+ updateValue = (model) ->
111
+ ngModel.$setViewValue(model)
112
+ tempHolder.removeClass('active')
113
+ done = false
114
+ fieldset = element
115
+ until done
116
+ fieldset = fieldset.parent()
117
+ unless done = typeof fieldset[0] == 'undefined'
118
+ done = fieldset[0].tagName == 'FIELDSET'
119
+ element.parent('fieldset')
120
+ element.bind 'mousedown', (event)->
121
+ return if tempHolder.hasClass('active')
122
+ return if attrs.disabled || $parse(attrs.ngDisabled)(scope)
123
+ if fieldset
124
+ ngdis = if fieldset[0].attributes.ngDisabled then fieldset[0].attributes.ngDisabled.value else ''
125
+ return if fieldset[0].attributes.disabled || $parse(ngdis)(scope)
126
+ search.val('')
127
+ buildTemplate()
128
+ tempHolder.css('top',event.clientY)
129
+ tempHolder.css('transition','none')
130
+ $timeout ->
131
+ tempHolder.css('transition','')
132
+ tempHolder.css('top','')
133
+ tempHolder.addClass('active')
@@ -1,10 +1,11 @@
1
1
  class ElementUpdate
2
- constructor: (scope,element,attributes,controllers,RailsUpdater,timeout) ->
2
+ constructor: (scope,element,attributes,controllers,RailsUpdater,timeout,parse) ->
3
3
  [@ngModelCtrl,@ngCallbackCtrl,@ngTrackByCtrl] = controllers
4
4
  @updater = RailsUpdater.new(scope,controllers,attributes.ngModel,attributes.ngOverride)
5
5
  @type = attributes.type
6
6
  @tagName = element[0].tagName
7
7
  @modelName = attributes.ngModel
8
+ @modelVal = parse(attributes.ngModel)
8
9
  @isInput = @tagName == 'INPUT'
9
10
  @scope = scope
10
11
  @element = element
@@ -15,7 +16,7 @@ class ElementUpdate
15
16
  @setPlaceholder() unless @placeholder
16
17
  watcher: ->
17
18
  eu = @
18
- @scope.$watch @modelName, (updated,old) ->
19
+ @scope.$watch @modelVal, (updated,old) ->
19
20
  eu.updater.update(updated) unless updated == old
20
21
  bindInput: ->
21
22
  eu = @
@@ -58,9 +59,9 @@ class ElementUpdate
58
59
  @element.attr('placeholder',placeholder)
59
60
 
60
61
  angular.module 'MdUpdate', ['Factories', 'FactoryName','RailsUpdater']
61
- .directive 'mdUpdate', ($timeout, factoryName, $injector, RailsUpdater) ->
62
+ .directive 'mdUpdate', ($timeout, factoryName, $injector, RailsUpdater,$parse) ->
62
63
  restrict: 'A'
63
64
  require: ['ngModel','?ngCallback','?ngTrackBy']
64
65
 
65
66
  link: (scope, element, attributes, ngControllers) ->
66
- new ElementUpdate(scope,element,attributes,ngControllers, RailsUpdater,$timeout)
67
+ new ElementUpdate(scope,element,attributes,ngControllers, RailsUpdater,$timeout,$parse)
@@ -7,4 +7,9 @@ angular.module 'NgBoolean', ['Factories', 'FactoryName','RailsUpdater']
7
7
  link: (scope, element, attributes, ngControllers) ->
8
8
  updater = RailsUpdater.new(scope,ngControllers,attributes.ngModel,attributes.ngOverride)
9
9
  element.bind 'click', ->
10
- updater.update(element.val())
10
+ if element[0].tagName == 'INPUT'
11
+ updater.update(element.val())
12
+ else
13
+ bool = !ngControllers[0].$modelValue
14
+ updater.update(bool)
15
+ ngControllers[0].$setViewValue(bool)
@@ -7,8 +7,9 @@ angular.module 'NgCallback', ['Factories', 'FactoryName']
7
7
  for callback in $element[0].attributes['ng-callback'].value.split(';')
8
8
  [match,func,args] = callback.match(/(.*)\((.*)\)/)
9
9
  data = []
10
- for arg in args.split(',')
11
- data.push $scope.$eval(arg)
10
+ if !!args
11
+ for arg in args.split(',')
12
+ data.push $scope.$eval(arg)
12
13
  data.push returnData
13
14
  if typeof $scope[func] == 'function'
14
15
  $scope[func] data...
@@ -65,3 +65,18 @@ String.prototype.to_f = ->
65
65
  return parseFloat(this)
66
66
  String.prototype.to_i = ->
67
67
  return parseInt(this)
68
+ Array.prototype.dup = ->
69
+ return @.slice(0)
70
+ Array.prototype.where = (obj) ->
71
+ equiv = (first,second) ->
72
+ return true if first == second
73
+ if !isNaN(first) && !isNaN(second)
74
+ return true if parseFloat(first) == parseFloat(second)
75
+ return false
76
+ result = []
77
+ for entry in @
78
+ addEntry = true
79
+ for key,value of obj
80
+ addEntry = addEntry && equiv(entry[key], value)
81
+ result.push(entry) if addEntry
82
+ result
@@ -21,4 +21,4 @@ angular.module('materialRaingular', ['AutoComplete', 'NgDownload', 'NgChangeOnBl
21
21
  'NgUpload', 'NgDestroy', 'NgCreate', 'Video','NgAuthorize', 'TextArea', 'MdUpdate'
22
22
  'NgSlide', 'NgMatches','NgFade','NgSwipe', 'NgLoad', 'NgWatchContent', 'RailsUpdater'
23
23
  'ngRoute', 'ngMaterial', 'ngMessages', 'ngResource', 'materialFilters', 'NgCallback'
24
- 'NgSortable'])
24
+ 'NgSortable', 'FilteredSelect'])
@@ -1,24 +1,29 @@
1
1
  class RailsUpdate
2
- constructor: ($injector,factoryName,scope,controllers,model,override)->
2
+ constructor: ($injector,$parse,factoryName,scope,controllers,model,override)->
3
3
  @injector = $injector
4
4
  @factoryName = factoryName
5
5
  @scope = scope
6
- @modelName = (override || model).split('.')[0]
7
- @atomName = (override || model).split('.')[1]
6
+ modelName = (override || model)
7
+ if parts = modelName.match(/(.+)\[(.+)\]/)
8
+ @modelName = parts[1]
9
+ @atomName = $parse(parts[2])
10
+ else
11
+ [@modelName,@atomName] = modelName.split('.')
8
12
  @override = !!override
9
13
  @factory = @injector.get(@factoryName(@modelName))
10
- @ngModelCtrl = controllers.shift()
11
- @controllers = controllers
14
+ @controllers = controllers.slice(0)
15
+ @ngModelCtrl = @controllers.shift()
12
16
  return @
13
17
  equiv: (left,right) ->
14
18
  return true if left == right
15
19
  return true if (!!left && !!right) == false
16
20
  false
17
21
  update: (value) ->
18
- @value = if @override then scope.$eval(@atomName) else value
22
+ atomName = if typeof @atomName == 'function' then @atomName(@scope) else @atomName
23
+ @value = if @override then scope.$eval(atomName) else value
19
24
  object = {id: @scope.$eval(@modelName).id}
20
25
  object[@modelName] = {}
21
- object[@modelName][@atomName] = value
26
+ object[@modelName][atomName] = value
22
27
  unless @scope[@modelName].currently_updating
23
28
  @scope[@modelName].currently_updating = true
24
29
  up = @
@@ -30,6 +35,6 @@ class RailsUpdate
30
35
  for controller in up.controllers
31
36
  controller.evaluate(returnData) if !!controller
32
37
  angular.module 'RailsUpdater', ['Factories', 'FactoryName']
33
- .factory 'RailsUpdater', ($injector,factoryName) ->
38
+ .factory 'RailsUpdater', ($injector,factoryName,$parse) ->
34
39
  new: (scope,controllers,model,override)->
35
- return new RailsUpdate($injector,factoryName,scope,controllers,model,override)
40
+ return new RailsUpdate($injector,$parse,factoryName,scope,controllers,model,override)
@@ -0,0 +1,44 @@
1
+ div.filtered-select
2
+ position: fixed
3
+ z-index: 1001
4
+ background-color: white
5
+ margin: 0
6
+ padding: 0
7
+ width: 100%
8
+ height: 0
9
+ overflow: hidden
10
+ left: 0
11
+ top: 0
12
+ transition: all 0.5s cubic-bezier(0.25, 0.8, 0.25, 1)
13
+ &.active
14
+ height: 100%
15
+ input
16
+ width: 100%
17
+ ul
18
+ overflow: hidden
19
+ overflow-y: auto
20
+ list-style: none
21
+ width: 100%
22
+ margin: 0
23
+ padding: 0
24
+ li
25
+ padding-left: 5%
26
+ padding-right: 5%
27
+ overflow: hidden
28
+ text-overflow: ellipsis
29
+ line-height: 48px
30
+ height: 48px
31
+ font-size: 14px
32
+ white-space: nowrap
33
+ cursor: pointer
34
+ box-shadow: 0 4px 2px -2px rgba(0,0,0,0.14)
35
+ &.bottom
36
+ top: 67%
37
+ z-index: 1000
38
+ &.active
39
+ height: 33%
40
+ ng-filtered-select
41
+ display: block
42
+ width: 100%
43
+ overflow: hidden
44
+ text-overflow: ellipsis
@@ -1,3 +1,3 @@
1
1
  module MaterialRaingular
2
- VERSION = "0.0.2.7.1"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: material_raingular
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2.7.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Moody
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-23 00:00:00.000000000 Z
11
+ date: 2015-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - lib/assets/javascripts/dateconverter.coffee
72
72
  - lib/assets/javascripts/dateparser.coffee
73
73
  - lib/assets/javascripts/directives/acomplete.js.coffee
74
+ - lib/assets/javascripts/directives/filteredselect.js.coffee
74
75
  - lib/assets/javascripts/directives/mdupdate.coffee
75
76
  - lib/assets/javascripts/directives/ngauthorize.js.coffee
76
77
  - lib/assets/javascripts/directives/ngautocomplete.js.coffee
@@ -103,6 +104,7 @@ files:
103
104
  - lib/assets/javascripts/material_filters.coffee
104
105
  - lib/assets/javascripts/material_raingular.js.coffee
105
106
  - lib/assets/javascripts/rails_updater.coffee
107
+ - lib/assets/stylesheets/material-raingular.sass
106
108
  - lib/material_raingular.rb
107
109
  - lib/material_raingular/version.rb
108
110
  - lib/tasks/material_raingular.rake
@@ -142,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
142
144
  version: '0'
143
145
  requirements: []
144
146
  rubyforge_project:
145
- rubygems_version: 2.2.1
147
+ rubygems_version: 2.4.3
146
148
  signing_key:
147
149
  specification_version: 4
148
150
  summary: Angular v1.4 for rails. Angular Material v0.9.8.