hooch 0.0.8 → 0.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 087922e7a4513efd847e0321155931c9d6442c6a
4
- data.tar.gz: 4dc2f8b767b6b8eb79f6b7bc7f81b824aca45fc1
3
+ metadata.gz: d9e66bf94543b7f6e7e5e759eff4e5e2796894a4
4
+ data.tar.gz: 1be8f61352c852e60eca3f02a73871e6a9edcd73
5
5
  SHA512:
6
- metadata.gz: 1e2e952e4df0ba29f958e0fe58b8c96762f149bb7dbb6dbda6d8c02f17ba24ac4f10050f3ddb7646d5ff3e3d2ffacbd605b796f0ecc433898f2070919aa33ad1
7
- data.tar.gz: c49766adf8ab37ce56a926e35c9cf25bfc785e9d813c0d374d96bcfefee08f5ed2f48fe29abff31d0633fc188ce7134b701090de888a94b844c4d2e98fa3ee89
6
+ metadata.gz: 275448fc8402520410d89412902126152d4fd3f40772c5f7e8e6b4fc8a9fb056b76675ea3f774e41a0935096f131a1b9d49c46c93922a2cb89c7efca35e3488f
7
+ data.tar.gz: 57a6d9f6ea03864adfa87e5b754ecea5707bab0bd4833105b41467f36f63fd909706fd1ec5df40074cfd8751beea87785505f8d125f6f25f9f5b1306f54211c7
@@ -140,33 +140,43 @@ var initHooch = function(){
140
140
  expand: function(){
141
141
  if(this.collapsers.length > 0){
142
142
 
143
- this.hide_expanders();
144
143
  this.show_collapsers();
145
144
  }
145
+ this.hide_expanders();
146
146
  if(this.expand_class){
147
147
  this.$expandable.addClass(this.expand_class)
148
+ this.$expandable.removeClass(this.collapse_class)
148
149
  }else{
149
- this.$expandable.show(10);
150
+ this.$expandable.show();
150
151
  }
152
+ this.state = 'expanded'
151
153
  },
152
154
  collapse: function(){
153
155
  if(this.collapsers.length > 0){
154
156
  this.hide_collapsers();
155
- this.show_expanders();
156
157
  }
157
- if(this.collapse_class){
158
+ this.show_expanders();
159
+ if(this.collapse_class || this.expand_class){
158
160
  this.$expandable.addClass(this.collapse_class)
161
+ this.$expandable.removeClass(this.expand_class)
159
162
  }else{
160
- this.$expandable.hide(10);
163
+ this.$expandable.hide();
161
164
  }
165
+ this.state = 'collapsed'
162
166
  },
163
167
  toggle: function(){
164
- this.$expandable.toggle(10);
168
+ if(this.state == 'collapsed'){
169
+ this.expand();
170
+ } else {
171
+ this.collapse();
172
+ }
165
173
  }
166
174
  }),
167
175
  Expander: Class.extend({
168
176
  init: function($expander,target){
169
177
  this.$expander = $expander;
178
+ this.target = target;
179
+ this.expand_class = $expander.data('expand-class')
170
180
  if($expander.data('fake-dropdown')){
171
181
  target.$expandable.on('click',function(){
172
182
  target.toggle();
@@ -176,18 +186,22 @@ var initHooch = function(){
176
186
  })
177
187
  }
178
188
  $expander.bind('click',function(){
179
- if(target.collapsers.length > 0){
180
- target.expand();
181
- } else {
182
- target.toggle();
183
- }
189
+ target.toggle();
184
190
  })
185
191
  },
186
192
  hide: function(){
187
- this.$expander.hide();
193
+ if(this.expand_class){
194
+ this.$expander.addClass(this.expand_class)
195
+ } else if(this.target.collapsers.length > 0) {
196
+ this.$expander.hide();
197
+ }
188
198
  },
189
199
  show: function(){
190
- this.$expander.show();
200
+ if(this.expand_class){
201
+ this.$expander.removeClass(this.expand_class)
202
+ } else if(this.target.collapsers.length > 0) {
203
+ this.$expander.show();
204
+ }
191
205
  }
192
206
  }),
193
207
  Collapser: Class.extend({
@@ -17,9 +17,51 @@ describe("hooch", function() {
17
17
  var remover_div = affix('[data-remover="true"][data-target="#my_div"]')
18
18
  var remover_target = affix('#my_div')
19
19
  $('[data-remover]').each(function(){new hooch.Remover($(this))})
20
- expect($('#my_div').length).toEqual(1)
21
- $('[data-remover]').click()
22
- expect($('#my_div').length).toEqual(0)
20
+ expect($('#my_div').length).toEqual(1);
21
+ $('[data-remover]').click();
22
+ expect($('#my_div').length).toEqual(0);
23
23
  });
24
24
 
25
+ it('expands and collapses an element', function(){
26
+ var expander = affix('[data-expander="true"][data-expand-id="my_expander"]')
27
+ var expandable = affix('[data-expand-state="collapsed"][data-expand-id="my_expander"]')
28
+ $('[data-expand-state]').each(function(){new hooch.Expandable($(this))});
29
+ expect($('[data-expand-state]').css('display')).toEqual('none');
30
+ $('[data-expander]').click()
31
+ expect($('[data-expand-state]').css('display')).not.toEqual('none');
32
+ expect($('[data-expander]').css('display')).not.toEqual('none');
33
+ $('[data-expander]').click()
34
+ expect($('[data-expand-state]').css('display')).toEqual('none');
35
+ })
36
+
37
+ it('expands an element with a class and modifies trigger with a class', function(){
38
+ var expander = affix('[data-expander="true"][data-expand-id="my_expander"][data-expand-class="test-class-trigger"]')
39
+ var expandable = affix('[data-expand-state="collapsed"][data-expand-id="my_expander"][data-expand-class="test-class-content"]')
40
+ $('[data-expand-state]').each(function(){new hooch.Expandable($(this))});
41
+ expect($('[data-expand-state]').hasClass("test-class-content")).toBe(false);
42
+ expect($('[data-expander]').hasClass("test-class-trigger")).toBe(false);
43
+ $('[data-expander]').click()
44
+ expect($('[data-expand-state]').hasClass("test-class-content")).toBe(true);
45
+ expect($('[data-expander]').hasClass("test-class-trigger")).toBe(true);
46
+ $('[data-expander]').click()
47
+ expect($('[data-expand-state]').hasClass("test-class-content")).toBe(false);
48
+ expect($('[data-expander]').hasClass("test-class-trigger")).toBe(false);
49
+ })
50
+
51
+ it('expands and collapses an element with separate triggers', function(){
52
+ var expander = affix('[data-expander="true"][data-expand-id="my_expander"]')
53
+ var collapser = affix('[data-collapser="true"][data-expand-id="my_expander"]')
54
+ var expandable = affix('[data-expand-state="collapsed"][data-expand-id="my_expander"]')
55
+ $('[data-expand-state]').each(function(){new hooch.Expandable($(this))});
56
+ expect($('[data-expand-state]').css('display')).toEqual('none');
57
+ $('[data-expander]').click()
58
+ expect($('[data-expand-state]').css('display')).not.toEqual('none');
59
+ expect($('[data-collapser]').css('display')).not.toEqual('none');
60
+ expect($('[data-expander]').css('display')).toEqual('none');
61
+ $('[data-collapser]').click()
62
+ expect($('[data-expand-state]').css('display')).toEqual('none');
63
+ expect($('[data-collapser]').css('display')).toEqual('none');
64
+ expect($('[data-expander]').css('display')).not.toEqual('none');
65
+ })
66
+
25
67
  });
@@ -20,8 +20,10 @@ module Hooch
20
20
  attrs = 'data-tab-id=' + id
21
21
  end
22
22
 
23
- def expander(id)
23
+ def expander(id, expand_class: nil)
24
24
  attrs = "data-expander=true data-expand-id=" + id
25
+ attrs += "data-expand-class=" + expand_class if expand_class.present?
26
+ attrs
25
27
  end
26
28
 
27
29
  def collapser(id)
data/lib/hooch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hooch
2
- VERSION = "0.0.8"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hooch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails