evrobone 0.1.1 → 0.2.0

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: 75c1132d4f4e63addfed63de2ce82b163419bb64
4
- data.tar.gz: 3e65a01494644d735fa8bf5ee82429725f899b67
3
+ metadata.gz: d3863ddda85ac2654aec7e76c4239c8678c59feb
4
+ data.tar.gz: c152a7a0be3c7e22cff207c27b7bf5f1bbc5e76a
5
5
  SHA512:
6
- metadata.gz: 680e88fb5d1839311bb3392dabc724d39d6d348cf523a6eaa564f2c27a6abca1d026daf1981a737d90eb224da3db1e89c2701aced941f70351e9c3d04d170092
7
- data.tar.gz: 1e52b7060ef84d01c28cb2bde406ee0ac74cda5c93da798baed4556e59a7934561dd0020c738502205cc3353c1a50ed7d203c5d299a84d8e284270c191760996
6
+ metadata.gz: 482ca778bc56de3e5d28d0c9a3f2fdab11a555b8a95f3e6a82560c3104701985d82b847d3e4b704e69e5cbf69cb4dcd7356a3e1264f3cc21c686c166f8165f40
7
+ data.tar.gz: ec047fc8af6bec9181af5831b6d3939f887350dd98111fa0d66f6518089ff14379f4597deb9043bfd3621ee3849d94d172402b5916385a8f8531909943c2b3eb
@@ -7,14 +7,15 @@ Evrobone.AppMixins.ViewsManagement =
7
7
  ProtoViews: {}
8
8
  Views: {}
9
9
 
10
+ preventMultibind: true
10
11
  warnOnMultibind: true
11
- preventMultibind: false
12
12
  groupBindingLog: true
13
13
 
14
14
  viewInstances: null
15
15
 
16
16
  viewsManagementInitialize: ->
17
17
  @viewInstances = []
18
+ @warnOnMultibind = DEBUG_MODE and @warnOnMultibind
18
19
  @on 'start', @viewsManagementStart, @
19
20
  @on 'stop', @viewsManagementStop, @
20
21
  return
@@ -24,46 +25,52 @@ Evrobone.AppMixins.ViewsManagement =
24
25
  @performancePoint('Bound %count% view%s%', boundViews.length) if @performanceReport
25
26
  return
26
27
 
27
- viewsManagementStop: (initial) ->
28
+ viewsManagementStop: ->
28
29
  @unbindViews @viewInstances
29
30
  return
30
31
 
31
32
  bindViews: ($root = $('html'), checkRoot = true) ->
32
33
  if @groupBindingLog
33
34
  console?.groupCollapsed? 'bindViews on', $root
34
- boundViews = []
35
+ allBoundViews = []
35
36
  sortedViews = _.sortBy(_.pairs(@Views), (p) -> -p[1].priority or 0)
36
37
  for [viewName, viewClass] in sortedViews when viewClass::el
37
- if checkRoot
38
- @_bindViews boundViews, $root.filter(viewClass::el), viewClass, viewName
39
- @_bindViews boundViews, $root.find(viewClass::el), viewClass, viewName
38
+ $elements = $root.find(viewClass::el)
39
+ $elements = $root.filter(viewClass::el).add($elements) if checkRoot
40
+ if $elements.length
41
+ boundViews = @_bindViews($elements, viewClass, viewName)
42
+ if boundViews.length > 0
43
+ @_boundInfo(boundViews, viewClass, viewName) if DEBUG_MODE and viewName and viewClass.silent isnt true
44
+ allBoundViews = allBoundViews.concat(boundViews)
40
45
  if @groupBindingLog
41
46
  console?.groupEnd?()
42
- boundViews
47
+ allBoundViews
43
48
 
44
- _bindViews: (boundViews, $elements, viewClass, viewName) ->
45
- $elements.each (index, el) =>
46
- if view = @bindView(el, viewClass, viewName)
47
- boundViews.push view
48
- return
49
+ _bindViews: ($elements, viewClass, viewName) ->
50
+ view for el in $elements.get() when view = @bindView(el, viewClass, viewName)
49
51
 
50
- bindView: (element, viewClass, viewName) ->
52
+ bindView: (element, viewClass) ->
51
53
  if @canBind(element, viewClass)
52
- options = _.defaults( el: element, $(element).data() )
53
- view = new viewClass(options)
54
- if viewName
55
- cout 'info', "Bound view #{viewName}:", view
54
+ view = new viewClass(el: element)
56
55
  @viewInstances.push view
57
56
  view
58
57
 
58
+ _boundInfo: (views, viewClass, viewName) ->
59
+ instancesInfo = 'silent instances' if viewClass.silent is 'instances'
60
+ if views.length > 1
61
+ cout 'info', @_plurMessage("Bound view #{viewName} %count% time%s%:", views.length), instancesInfo or views
62
+ else
63
+ cout 'info', "Bound view #{viewName}:", instancesInfo or views[0]
64
+ return
65
+
59
66
  canBind: (element, viewClass) ->
60
- if @warnOnMultibind or @preventMultibind
67
+ if @preventMultibind or @warnOnMultibind
61
68
  views = @getViewsOnElement(element)
62
69
  l = views.length
63
70
  if l > 0
64
71
  if @warnOnMultibind
65
72
  cout 'warn', @_plurMessage('Element already has bound %count% view%s%', l), element, viewClass, views
66
- not @preventMultibind
73
+ not ( @preventMultibind and _.findWhere(views, constructor: viewClass) )
67
74
  else
68
75
  true
69
76
  else
@@ -75,7 +82,9 @@ Evrobone.AppMixins.ViewsManagement =
75
82
  view.undelegateEvents()
76
83
  view.leave context
77
84
  @viewInstances = _.without(@viewInstances, views...)
78
- cout 'info', @_plurMessage('Unbound %count% view%s%:', views.length), views
85
+ if DEBUG_MODE
86
+ cout 'info', @_plurMessage('Unbound %count% view%s%:', views.length),
87
+ _.filter(views, (v) -> not v.constructor.silent)
79
88
  return
80
89
 
81
90
  getViewsOnElement: (element) ->
@@ -1,10 +1,10 @@
1
1
  Evrobone.AppMixins.WindowNavigation =
2
2
 
3
- changeLocation: (url, push = false) ->
3
+ changeLocation: (url, push = false, title = '', options) ->
4
4
  #cout '!> changeLocation', url
5
5
  historyMethod = window.history[if push then 'pushState' else 'replaceState']
6
6
  if historyMethod
7
- historyMethod.call window.history, { turbolinks: Turbolinks?, url: url }, '', url
7
+ historyMethod.call window.history, _.extend({ turbolinks: Turbolinks?, url: url }, options), title, url
8
8
  else
9
9
  window.location.hash = url
10
10
  return
@@ -22,7 +22,7 @@ window.todo = (subject, location = null, numberOrString = null) =>
22
22
  cout 'warn', "TODO: #{subject}#{if location then " ### #{location}" else ''}#{if numberOrString then (if _.isNumber(numberOrString) then ":#{numberOrString}" else " > #{numberOrString}") else ''}"
23
23
 
24
24
  window.getParams = (searchString = location.search) ->
25
- q = searchString.replace(/^\?/, '').split('&')
25
+ q = searchString.replace(/^.*\?/, '').split('&')
26
26
  r = {}
27
27
  for e in q
28
28
  t = e.split('=')
@@ -71,7 +71,7 @@ do ($ = jQuery) =>
71
71
  callback $(element)
72
72
 
73
73
  $.fn.closestScrollable = ->
74
- $(_.find(@parents().get(), (p) -> $(p).css('overflowY') is 'auto') or window)
74
+ $(_.find(@.get().concat(@parents().get()), (p) -> $(p).css('overflowY') is 'auto') or window)
75
75
 
76
76
  # RESEARCH
77
77
  # $.fn.blockHide = ->
@@ -6,9 +6,10 @@ class Evrobone.View extends Backbone.View
6
6
 
7
7
  @mixinNames: null
8
8
 
9
- constructor: (options) ->
10
- @reflectOptions options
9
+ setElement: ->
11
10
  super
11
+ @reflectOptions()
12
+ @
12
13
 
13
14
  reflectOptions: (options = @$el.data()) ->
14
15
  @[attr] = value for attr, value of options when not _.isUndefined(@[attr])
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency 'bundler', '~> 1.10'
22
22
  spec.add_development_dependency 'rake', '~> 10.0'
23
+ spec.add_development_dependency 'backbone-rails'
24
+ spec.add_development_dependency 'turbolinks'
23
25
  spec.add_development_dependency 'rubocop'
24
26
  spec.add_development_dependency 'coffeelint'
25
27
  end
@@ -1,3 +1,3 @@
1
1
  module Evrobone
2
- VERSION = '0.1.1'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evrobone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry KODer Karpunin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-28 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,34 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: backbone-rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turbolinks
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rubocop
43
71
  requirement: !ruby/object:Gem::Requirement