hooch 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/hooch.js +27 -13
- data/jasmine/spec/hoochSpec.js +45 -3
- data/lib/hooch/hooch_helper.rb +3 -1
- data/lib/hooch/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9e66bf94543b7f6e7e5e759eff4e5e2796894a4
|
4
|
+
data.tar.gz: 1be8f61352c852e60eca3f02a73871e6a9edcd73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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(
|
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
|
-
|
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(
|
163
|
+
this.$expandable.hide();
|
161
164
|
}
|
165
|
+
this.state = 'collapsed'
|
162
166
|
},
|
163
167
|
toggle: function(){
|
164
|
-
this
|
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
|
-
|
180
|
-
target.expand();
|
181
|
-
} else {
|
182
|
-
target.toggle();
|
183
|
-
}
|
189
|
+
target.toggle();
|
184
190
|
})
|
185
191
|
},
|
186
192
|
hide: function(){
|
187
|
-
this
|
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
|
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({
|
data/jasmine/spec/hoochSpec.js
CHANGED
@@ -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
|
});
|
data/lib/hooch/hooch_helper.rb
CHANGED
@@ -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
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
|
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-
|
11
|
+
date: 2015-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|