hooch 0.0.3 → 0.0.4

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: 425e8e9996820877bf0ef97a786bc9092a82c4b3
4
- data.tar.gz: e008d306a17d7abc57879f692ed3f07c28bdbcde
3
+ metadata.gz: 9f5d340b61453c7779d4c652427d934d97b7eb35
4
+ data.tar.gz: 7436f2734625d6d03764cfb97057d9e42ffca258
5
5
  SHA512:
6
- metadata.gz: 0e43be232b6648814239b03c193414a7325696c43dc2dadd9c82e37f63726d286504d96d231564822c4932ae0bf8b23f4a700aa6700c4eb61a4f58d8df24bee3
7
- data.tar.gz: 6923b1d87eadf0376acac23631fead26fb607efd59c7d21669806e7b25c7d88a1a7e8aef3a51233f8c140476efc5669d87179d87d3106fe1ee677109f2966977
6
+ metadata.gz: ff1892a00559ecb9436cf8f49ac0f761dde648a8e680b8968876f05a3c6c3c843265f2328638c1cdee11ef04ff6341ab0008a1044d26aed1ee431d6a1be15a2e
7
+ data.tar.gz: 863e5332edfb2077382d8312f2411f0d63932380fc9cfb79bf065d0e4be363d5604bed1d8ddfa82ce0e4a065b616ba7da41bed46cbf6c9ddbb988e4bec4d6b72
@@ -1,686 +1,640 @@
1
- /* Simple JavaScript Inheritance
2
- * By John Resig http://ejohn.org/
3
- * MIT Licensed.
4
- */
5
- // Inspired by base2 and Prototype
6
- (function(){
7
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
8
- // The base Class implementation (does nothing)
9
- this.Class = function(){};
10
-
11
- // Create a new Class that inherits from this class
12
- Class.extend = function(prop) {
13
- var _super = this.prototype;
14
-
15
- // Instantiate a base class (but only create the instance,
16
- // don't run the init constructor)
17
- initializing = true;
18
- var prototype = new this();
19
- initializing = false;
20
-
21
- // Copy the properties over onto the new prototype
22
- for (var name in prop) {
23
- // Check if we're overwriting an existing function
24
- prototype[name] = typeof prop[name] == "function" &&
25
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
26
- (function(name, fn){
27
- return function() {
28
- var tmp = this._super;
29
-
30
- // Add a new ._super() method that is the same method
31
- // but on the super-class
32
- this._super = _super[name];
33
-
34
- // The method only need to be bound temporarily, so we
35
- // remove it when we're done executing
36
- var ret = fn.apply(this, arguments);
37
- this._super = tmp;
38
-
39
- return ret;
40
- };
41
- })(name, prop[name]) :
42
- prop[name];
43
- }
44
-
45
- // The dummy class constructor
46
- function Class() {
47
- // All construction is actually done in the init method
48
- if ( !initializing && this.init )
49
- this.init.apply(this, arguments);
50
- }
51
-
52
- // Populate our constructed prototype object
53
- Class.prototype = prototype;
54
-
55
- // Enforce the constructor to be what we expect
56
- Class.prototype.constructor = Class;
57
-
58
- // And make this class extendable
59
- Class.extend = arguments.callee;
60
-
61
- return Class;
62
- };
63
- })();
64
- /*End Simple Inheritance*/
65
-
66
- /*Begin Hooch.js*/
67
- var Toggler = Class.extend({
68
- init: function(jq_obj){
69
- this.jq_obj = jq_obj;
70
- this.label = jq_obj.data('toggler');
71
- this.value = jq_obj.val();
72
- this.targets = $('[data-toggle_trigger="' + this.label + '"]');
73
- this.targets.hide();
74
- this.targets.filter('[data-toggle_value="' + this.value + '"]').show();
75
- }
76
- });
77
-
78
- var HoverOverflow = Class.extend({
79
- init: function(jq_obj){
80
- this.old_border = jq_obj.css('border-right');
81
- this.old_z_index = jq_obj.css('z-index');
82
- var hoverable = this;
83
- jq_obj.bind('mouseover',function(){
84
- hoverable.jq_obj.css({'overflow':'visible','z-index':'10000','border-right':'1px solid white'});
85
- });
86
- jq_obj.bind('mouseout',function(){
87
- hoverable.jq_obj.css({'overflow':'hidden','z-index':hoverable.old_z_index,'border-right':hoverable.old_border});
88
- });
89
- }
90
- })
91
-
92
- var HoverReveal = Class.extend({
93
- init: function($hover_revealer){
94
- $revealable = $hover_revealer.data('revealable')
95
- jq_obj.bind('mouseover',function(){
96
- $revealable.show();
97
- });
98
- jq_obj.bind('mouseout',function(){
99
- $revealable.hide();
100
- });
101
-
102
- }
103
- })
1
+ var initHooch = function(){
2
+ hooch = {
3
+ Emptier: Class.extend({
4
+ init: function($emptier){
5
+ $target = $($emptier.data('target'));
6
+ $emptier.click(function(e){
7
+ $target.empty();
8
+ })
9
+ }
10
+ }),
11
+ Toggler: Class.extend({
12
+ init: function(jq_obj){
13
+ this.jq_obj = jq_obj;
14
+ this.label = jq_obj.data('toggler');
15
+ this.value = jq_obj.val();
16
+ this.targets = $('[data-toggle_trigger="' + this.label + '"]');
17
+ this.targets.hide();
18
+ this.targets.filter('[data-toggle_value="' + this.value + '"]').show();
19
+ }
20
+ }),
21
+ HoverOverflow: Class.extend({
22
+ init: function(jq_obj){
23
+ this.old_border = jq_obj.css('border-right');
24
+ this.old_z_index = jq_obj.css('z-index');
25
+ var hoverable = this;
26
+ jq_obj.bind('mouseover',function(){
27
+ hoverable.jq_obj.css({'overflow':'visible','z-index':'10000','border-right':'1px solid white'});
28
+ });
29
+ jq_obj.bind('mouseout',function(){
30
+ hoverable.jq_obj.css({'overflow':'hidden','z-index':hoverable.old_z_index,'border-right':hoverable.old_border});
31
+ });
32
+ }
33
+ }),
34
+ HoverReveal: Class.extend({
35
+ init: function($hover_revealer){
36
+ $revealable = $hover_revealer.data('revealable')
37
+ jq_obj.bind('mouseover',function(){
38
+ $revealable.show();
39
+ });
40
+ jq_obj.bind('mouseout',function(){
41
+ $revealable.hide();
42
+ });
104
43
 
105
- var HideyButton = Class.extend({
106
- init: function($hidey_button){
107
- $hidey_button.hide();
108
- this.form = $hidey_button.parents('form');
109
- this.$hidey_button = $hidey_button;
110
- this.bindInputs();
111
- },
112
- bindInputs: function(){
113
- this.inputs = this.form.find('input,select,textarea');
114
- var hidey_button = this;
115
- this.cache_input_values();
116
- this.inputs.each(function(){
117
- $(this).bind("propertychange keyup input paste datechange change",function(){
118
- if(hidey_button.form_changed()){
119
- hidey_button.$hidey_button.show();
44
+ }
45
+ }),
46
+ HideyButton: Class.extend({
47
+ init: function($hidey_button){
48
+ $hidey_button.hide();
49
+ this.form = $hidey_button.parents('form');
50
+ this.$hidey_button = $hidey_button;
51
+ this.bindInputs();
52
+ },
53
+ bindInputs: function(){
54
+ this.inputs = this.form.find('input,select,textarea');
55
+ var hidey_button = this;
56
+ this.cache_input_values();
57
+ this.inputs.each(function(){
58
+ $(this).bind("propertychange keyup input paste datechange change",function(){
59
+ if(hidey_button.form_changed()){
60
+ hidey_button.$hidey_button.show();
61
+ } else {
62
+ hidey_button.$hidey_button.hide();
63
+ }
64
+ })
65
+ });
66
+ },
67
+ cache_input_values: function(){
68
+ this.inputs.each(function(){
69
+ if($(this).is(":checkbox")){
70
+ $(this).data('oldstate',$(this).is(':checked'));
71
+ } else {
72
+ $(this).data('oldval',$(this).val());
73
+ }
74
+ })
75
+ },
76
+ form_changed: function(){
77
+ var changed = false;
78
+ this.inputs.each(function(){
79
+ if($(this).is(":checkbox")){
80
+ if($(this).data('oldstate') != $(this).is(':checked')){
81
+ changed = true;
82
+ return false;
83
+ }
84
+ }else{
85
+ if($(this).data('oldval') != $(this).val()){
86
+ changed = true;
87
+ return false;
88
+ }
89
+ }
90
+ })
91
+ return changed;
92
+ }
93
+ }),
94
+ Expandable: Class.extend({
95
+ init: function($expandable){
96
+ this.$expandable = $expandable;
97
+ $expandable.data('expandable',this);
98
+ $collapser = $('[data-expand-id="' + $expandable.data('expand-id') + '"][data-collapser]');
99
+ if($collapser.length > 0){
100
+ this.collapser = new hooch.Collapser($collapser,this);
101
+ }
102
+ this.$expander = $('[data-expand-id="' + $expandable.data('expand-id') + '"][data-expander]');
103
+ this.expander = new hooch.Expander(this.$expander,this);
104
+ this.initial_state = $expandable.data('expand-state');
105
+ if(this.initial_state == 'expanded'){
106
+ this.expand();
120
107
  } else {
121
- hidey_button.$hidey_button.hide();
108
+ this.collapse();
122
109
  }
123
- })
124
- });
125
- },
126
- cache_input_values: function(){
127
- this.inputs.each(function(){
128
- if($(this).is(":checkbox")){
129
- $(this).data('oldstate',$(this).is(':checked'));
130
- } else {
131
- $(this).data('oldval',$(this).val());
132
- }
133
- })
134
- },
135
- form_changed: function(){
136
- var changed = false;
137
- this.inputs.each(function(){
138
- if($(this).is(":checkbox")){
139
- if($(this).data('oldstate') != $(this).is(':checked')){
140
- changed = true;
141
- return false;
110
+ },
111
+ expand: function(){
112
+ if(this.collapser){
113
+ this.expander.hide();
114
+ this.collapser.show();
142
115
  }
143
- }else{
144
- if($(this).data('oldval') != $(this).val()){
145
- changed = true;
146
- return false;
116
+ this.$expandable.show(10);
117
+ },
118
+ collapse: function(){
119
+ if(this.collapser){
120
+ this.collapser.hide();
121
+ this.expander.show();
147
122
  }
123
+ this.$expandable.hide(10);
124
+ },
125
+ toggle: function(){
126
+ this.$expandable.toggle(10);
148
127
  }
149
- })
150
- return changed;
151
- }
152
- })
153
- var Expandable = Class.extend({
154
- init: function($expandable){
155
- this.$expandable = $expandable;
156
- $expandable.data('expandable',this);
157
- $collapser = $('[data-expand-id="' + $expandable.data('expand-id') + '"][data-collapser]');
158
- if($collapser.length > 0){
159
- this.collapser = new Collapser($collapser,this);
160
- }
161
- this.$expander = $('[data-expand-id="' + $expandable.data('expand-id') + '"][data-expander]');
162
- this.expander = new Expander(this.$expander,this);
163
- this.initial_state = $expandable.data('expand-state');
164
- if(this.initial_state == 'expanded'){
165
- this.expand();
166
- } else {
167
- this.collapse();
168
- }
169
- },
170
- expand: function(){
171
- if(this.collapser){
172
- this.expander.hide();
173
- this.collapser.show();
174
- }
175
- this.$expandable.show(10);
176
- },
177
- collapse: function(){
178
- if(this.collapser){
179
- this.collapser.hide();
180
- this.expander.show();
181
- }
182
- this.$expandable.hide(10);
183
- },
184
- toggle: function(){
185
- this.$expandable.toggle(10);
186
- }
187
- });
188
- var AjaxExpandable = Expandable.extend({
189
- expand: function(){
190
- if(!this.ajax_loaded){
191
- this.ajax_loaded = true;
192
- new AjaxLinkSubmission(this.$expander);
193
- }
194
- this._super();
195
- }
196
- });
197
- var Expander = Class.extend({
198
- init: function($expander,target){
199
- this.$expander = $expander;
200
- if($expander.data('fake-dropdown')){
201
- target.$expandable.on('click',function(){
202
- target.toggle();
203
- })
204
- target.$expandable.on('mouseleave',function(){
205
- target.collapse();
206
- })
207
- }
208
- $expander.bind('click',function(){
209
- if(target.collapser){
210
- target.expand();
211
- } else {
212
- target.toggle();
128
+ }),
129
+ Expander: Class.extend({
130
+ init: function($expander,target){
131
+ this.$expander = $expander;
132
+ if($expander.data('fake-dropdown')){
133
+ target.$expandable.on('click',function(){
134
+ target.toggle();
135
+ })
136
+ target.$expandable.on('mouseleave',function(){
137
+ target.collapse();
138
+ })
139
+ }
140
+ $expander.bind('click',function(){
141
+ if(target.collapser){
142
+ target.expand();
143
+ } else {
144
+ target.toggle();
145
+ }
146
+ })
147
+ },
148
+ hide: function(){
149
+ this.$expander.hide();
150
+ },
151
+ show: function(){
152
+ this.$expander.show();
213
153
  }
214
- })
215
- },
216
- hide: function(){
217
- this.$expander.hide();
218
- },
219
- show: function(){
220
- this.$expander.show();
221
- }
222
- });
223
- var Collapser = Class.extend({
224
- init: function($collapser,target){
225
- this.$collapser = $collapser;
226
- $collapser.bind('click',function(){
227
- target.collapse();
228
- })
229
- },
230
- hide: function(){
231
- this.$collapser.hide();
232
- },
233
- show: function(){
234
- this.$collapser.show();
235
- }
236
- })
237
- var DisableForms = Class.extend({
238
- init: function($disable_container){
239
- $disable_container.find('input, select').each(function(){
240
- $(this).prop('disabled',true);
241
- });
242
- }
243
- })
244
-
245
- // Note: the method and variable names in this class are somehow creepy
246
-
247
- var Revealer = Class.extend({
248
- init: function($revealer){
249
- var revealer = this;
250
- this.$revealer = $revealer;
251
- this.children_id = this.$revealer.data('revealer-children-id');
252
- this.$all_children = $('[data-revealer_id="' + this.children_id + '"]');
253
- $revealer.bind('change',function(){
254
- revealer.reveal();
255
- });
256
- revealer.reveal();
257
- },
258
- reveal: function(){
259
- var sanitized_value = this.$revealer.val();
260
- this.$children = [];
261
- var revealer = this;
262
- this.$all_children.each(function(){
263
- var triggers = $(this).data('revealer-triggers');
264
- if(triggers){
265
- var revelation_triggers = eval('(' + triggers + ')');
266
- if($.inArray(sanitized_value,revelation_triggers) > -1){
267
- revealer.$children.push($(this));
154
+ }),
155
+ Collapser: Class.extend({
156
+ init: function($collapser,target){
157
+ this.$collapser = $collapser;
158
+ $collapser.bind('click',function(){
159
+ target.collapse();
160
+ })
161
+ },
162
+ hide: function(){
163
+ this.$collapser.hide();
164
+ },
165
+ show: function(){
166
+ this.$collapser.show();
167
+ }
168
+ }),
169
+ DisableForms: Class.extend({
170
+ init: function($disable_container){
171
+ $disable_container.find('input, select').each(function(){
172
+ $(this).prop('disabled',true);
173
+ });
174
+ }
175
+ }),
176
+ Revealer: Class.extend({
177
+ init: function($revealer){
178
+ var revealer = this;
179
+ this.$revealer = $revealer;
180
+ this.children_id = this.$revealer.data('revealer-children-id');
181
+ this.$all_children = $('[data-revealer_id="' + this.children_id + '"]');
182
+ $revealer.bind('change',function(){
183
+ revealer.reveal();
184
+ });
185
+ revealer.reveal();
186
+ },
187
+ reveal: function(){
188
+ var sanitized_value = this.$revealer.val();
189
+ this.$children = [];
190
+ var revealer = this;
191
+ this.$all_children.each(function(){
192
+ var triggers = $(this).data('revealer-triggers');
193
+ if(triggers){
194
+ var revelation_triggers = eval('(' + triggers + ')');
195
+ if($.inArray(sanitized_value,revelation_triggers) > -1){
196
+ revealer.$children.push($(this));
197
+ }
198
+ } else {
199
+ if(sanitized_value == $(this).data('revealer-trigger')){
200
+ revealer.$children.push($(this));
201
+ }
202
+ }
203
+ })
204
+ this.hideChildren();
205
+ this.revealChosenOnes();
206
+ },
207
+ hideChildren: function(){
208
+ this.$all_children.hide();
209
+ },
210
+ revealChosenOnes: function(){
211
+ $.each(this.$children,function(){ $(this).show(); });
212
+ }
213
+ }),
214
+ TabGroup: Class.extend({
215
+ init: function($tab_group){
216
+ this.$tab_group = $tab_group;
217
+ this.getName();
218
+ this.tab_triggers = [];
219
+ this.tab_triggers_by_id = {};
220
+ this.getTabTriggerClass();
221
+ this.createTabs();
222
+ this.getConentParent();
223
+ this.hideAll();
224
+ this.handleDefault();
225
+ hooch.TabGroup.addGroup(this);
226
+ },
227
+ createTabs: function(){
228
+ var tab_group = this;
229
+ this.$tab_group.find("[data-tab-trigger]").each(function(){
230
+ var new_tab = new tab_group.tab_trigger_class($(this),tab_group);
231
+ tab_group.tab_triggers.push(new_tab);
232
+ tab_group.tab_triggers_by_id[new_tab.tab_id] = new_tab;
233
+ })
234
+ },
235
+ getTabByPushState: function(state_value){
236
+ var selected_tab = null;
237
+ $.each(this.tab_triggers,function(index,trigger){
238
+ if(trigger.push_state == state_value){
239
+ selected_tab = trigger;
240
+ }
241
+ })
242
+ return selected_tab;
243
+ },
244
+ getName: function(){
245
+ this.name = this.$tab_group.data('tab-group');
246
+ },
247
+ getConentParent: function(){
248
+ this.$content_parent = this.tab_triggers[0].getParent();
249
+ },
250
+ handleDefault: function(){
251
+ if(this.$tab_group.data('default-tab')){
252
+ this.default_tab = this.tab_triggers_by_id[this.$tab_group.data('default-tab')];
253
+ this.default_tab.toggleTarget('replace');
268
254
  }
269
- } else {
270
- if(sanitized_value == $(this).data('revealer-trigger')){
271
- revealer.$children.push($(this));
255
+ },
256
+ hideAll: function(trigger){
257
+ $.each(this.tab_triggers,function(){
258
+ this.hideTarget();
259
+ })
260
+ },
261
+ getTabTriggerClass: function(){
262
+ this.tab_trigger_class = hooch.TabTrigger;
263
+ },
264
+ deactivateTabTriggers: function(){
265
+ $.each(this.tab_triggers,function(){
266
+ this.$tab_trigger.removeClass('active');
267
+ })
268
+ },
269
+ setActiveTab: function(tab_trigger){
270
+ if(this.active_tab){
271
+ var parent_height = this.$content_parent.height();
272
+ this.$content_parent.css({'height': parent_height, 'overflow': 'hidden'});
272
273
  }
274
+ this.hideAll();
275
+ this.deactivateTabTriggers();
276
+ this.active_tab = tab_trigger;
277
+ tab_trigger.revealTarget();
278
+ },
279
+ resize: function(){
280
+ this.$content_parent.css({'height': 'auto', 'overflow': 'visible'});
281
+ },
282
+ getActiveTab: function(){
283
+ return this.active_tab;
273
284
  }
274
- })
275
- this.hideChildren();
276
- this.revealChosenOnes();
277
- },
278
- hideChildren: function(){
279
- this.$all_children.hide();
280
- },
281
- revealChosenOnes: function(){
282
- $.each(this.$children,function(){ $(this).show(); });
283
- }
284
- });
285
-
286
- var FormFieldRevealer = Revealer.extend({
287
- init: function($revealer){
288
- this.children_id = $revealer.data('revealer-children-id');
289
- this.$revelation_target = $('[data-revealer-target="' + this.children_id + '"]');
290
- this._super($revealer);
291
- },
292
- hideChildren: function(){
293
- this._super();
294
- this.$form = this.$revealer.parents('form:first')
295
- if(this.$form.length > 0){
296
- this.$form.after(this.$all_children)
297
- }
298
- },
299
- revealChosenOnes: function(){
300
- this.$revelation_target.html(this.$children);
301
- this._super();
302
- }
303
- });
304
-
305
- var TabGroup = Class.extend({
306
- init: function($tab_group){
307
- this.$tab_group = $tab_group;
308
- this.getName();
309
- this.tab_triggers = [];
310
- this.tab_triggers_by_id = {};
311
- this.getTabTriggerClass();
312
- this.createTabs();
313
- this.getConentParent();
314
- this.hideAll();
315
- this.handleDefault();
316
- TabGroup.addGroup(this);
317
- },
318
- createTabs: function(){
319
- var tab_group = this;
320
- this.$tab_group.find("[data-tab-trigger]").each(function(){
321
- var new_tab = new tab_group.tab_trigger_class($(this),tab_group);
322
- tab_group.tab_triggers.push(new_tab);
323
- tab_group.tab_triggers_by_id[new_tab.tab_id] = new_tab;
324
- })
325
- },
326
- getTabByPushState: function(state_value){
327
- var selected_tab = null;
328
- $.each(this.tab_triggers,function(index,trigger){
329
- if(trigger.push_state == state_value){
330
- selected_tab = trigger;
285
+ }),
286
+ TabTrigger: Class.extend({
287
+ init: function($tab_trigger,tab_group){
288
+ this.$tab_trigger = $tab_trigger;
289
+ this.tab_group = tab_group;
290
+ this.tab_group_name = tab_group.name;
291
+ this.tab_id = $tab_trigger.data('tab-target-id');
292
+ this.getPushState();
293
+ this.getTarget();
294
+ var tab_trigger = this;
295
+ $tab_trigger.on('click', function(e){
296
+ e.preventDefault();
297
+ tab_trigger.toggleTarget()
298
+ })
299
+ },
300
+ getTarget: function(){
301
+ this.$target = $('[data-tab-id="' + this.tab_id + '"]');
302
+ },
303
+ getPushState: function(){
304
+ if(this.$tab_trigger.data('push-state') != null && this.$tab_trigger.data('push-state') != ""){
305
+ this.push_state = this.$tab_trigger.data('push-state')
306
+ }
307
+ },
308
+ toggleTarget: function(state_behavior){
309
+ var was_visible = this.$target.is(':visible');
310
+ if(!was_visible){
311
+ this.tab_group.setActiveTab(this);
312
+ this.resize();
313
+ var change_history = true;
314
+ var history_method = 'pushState'
315
+ if('no history' == state_behavior){
316
+ change_history = false
317
+ } else if('replace' == state_behavior){
318
+ history_method = 'replaceState'
319
+ }
320
+ if (this.push_state && change_history) {
321
+ var current_state = new hooch.IhHistoryState(history.state)
322
+ current_state.addState(this.tab_group_name, this.push_state);
323
+ history[history_method](current_state.state, null, current_state.toUrl());
324
+ }
325
+ }
326
+ },
327
+ hideTarget: function(){
328
+ this.$target.hide();
329
+ },
330
+ revealTarget: function(){
331
+ this.$target.show();
332
+ this.$tab_trigger.addClass('active');
333
+ },
334
+ getParent: function(){
335
+ return this.$target.parent();
336
+ },
337
+ resize: function(){
338
+ this.tab_group.resize();
331
339
  }
332
- })
333
- return selected_tab;
334
- },
335
- getName: function(){
336
- this.name = this.$tab_group.data('tab-group');
337
- },
338
- getConentParent: function(){
339
- this.$content_parent = this.tab_triggers[0].getParent();
340
- },
341
- handleDefault: function(){
342
- if(this.$tab_group.data('default-tab')){
343
- this.default_tab = this.tab_triggers_by_id[this.$tab_group.data('default-tab')];
344
- this.default_tab.toggleTarget('replace');
345
- }
346
- },
347
- hideAll: function(trigger){
348
- $.each(this.tab_triggers,function(){
349
- this.hideTarget();
350
- })
351
- },
352
- getTabTriggerClass: function(){
353
- this.tab_trigger_class = TabTrigger;
354
- },
355
- deactivateTabTriggers: function(){
356
- $.each(this.tab_triggers,function(){
357
- this.$tab_trigger.removeClass('active');
358
- })
359
- },
360
- setActiveTab: function(tab_trigger){
361
- if(this.active_tab){
362
- var parent_height = this.$content_parent.height();
363
- this.$content_parent.css({'height': parent_height, 'overflow': 'hidden'});
364
- }
365
- this.hideAll();
366
- this.deactivateTabTriggers();
367
- this.active_tab = tab_trigger;
368
- tab_trigger.revealTarget();
369
- },
370
- resize: function(){
371
- this.$content_parent.css({'height': 'auto', 'overflow': 'visible'});
372
- },
373
- getActiveTab: function(){
374
- return this.active_tab;
375
- }
376
- })
377
- TabGroup.addGroup = function(group){
378
- if(!TabGroup.all_groups){
379
- TabGroup.all_groups = [];
380
- }
381
- TabGroup.all_groups.push(group);
382
- }
383
- TabGroup.find = function(name){
384
- var selected_group = null;
385
- $.each(TabGroup.all_groups,function(index,group){
386
- if(group.name == name){
387
- selected_group = group;
388
- }
389
- });
390
- return selected_group;
391
- }
392
- var AjaxTabGroup = TabGroup.extend({
393
- getTabTriggerClass: function(){
394
- this.tab_trigger_class = AjaxTabTrigger;
395
- }
396
- })
397
- var TabTrigger = Class.extend({
398
- init: function($tab_trigger,tab_group){
399
- this.$tab_trigger = $tab_trigger;
400
- this.tab_group = tab_group;
401
- this.tab_group_name = tab_group.name;
402
- this.tab_id = $tab_trigger.data('tab-target-id');
403
- this.getPushState();
404
- this.getTarget();
405
- var tab_trigger = this;
406
- $tab_trigger.on('click', function(e){
407
- e.preventDefault();
408
- tab_trigger.toggleTarget()
409
- })
410
- },
411
- getTarget: function(){
412
- this.$target = $('[data-tab-id="' + this.tab_id + '"]');
413
- },
414
- getPushState: function(){
415
- if(this.$tab_trigger.data('push-state') != null && this.$tab_trigger.data('push-state') != ""){
416
- this.push_state = this.$tab_trigger.data('push-state')
417
- }
418
- },
419
- toggleTarget: function(state_behavior){
420
- var was_visible = this.$target.is(':visible');
421
- if(!was_visible){
422
- this.tab_group.setActiveTab(this);
423
- this.resize();
424
- var change_history = true;
425
- var history_method = 'pushState'
426
- if('no history' == state_behavior){
427
- change_history = false
428
- } else if('replace' == state_behavior){
429
- history_method = 'replaceState'
430
- }
431
- if (this.push_state && change_history) {
432
- var current_state = new IhHistoryState(history.state)
433
- current_state.addState(this.tab_group_name, this.push_state);
434
- history[history_method](current_state.state, null, current_state.toUrl());
340
+ }),
341
+ IhHistoryState: Class.extend({
342
+ init: function(state){
343
+ this.state = jQuery.extend(true, {}, state);
344
+ },
345
+ toQueryString: function(){
346
+ return $.param(this.state)
347
+ },
348
+ toUrl: function(){
349
+ return [location.protocol, '//', location.host, location.pathname, '?', this.toQueryString()].join('');
350
+ },
351
+ addState: function(key,value){
352
+ var new_state = {}
353
+ new_state[key] = value
354
+ this.state = $.extend(true, this.state, new_state);
435
355
  }
436
- }
437
- },
438
- hideTarget: function(){
439
- this.$target.hide();
440
- },
441
- revealTarget: function(){
442
- this.$target.show();
443
- this.$tab_trigger.addClass('active');
444
- },
445
- getParent: function(){
446
- return this.$target.parent();
447
- },
448
- resize: function(){
449
- this.tab_group.resize();
450
- }
451
- })
452
-
453
- var AjaxTabTrigger = TabTrigger.extend({
454
- toggleTarget: function(pop){
455
- var tab_group = this.tab_group;
456
- if(!this.ajax_loaded){
457
- this.ajax_loaded = true;
458
- this.$tab_trigger.data('ajax-target','[data-tab-id="' + this.tab_id + '"]')
459
- new AjaxLinkSubmission(this.$tab_trigger,{'on_complete': function(){tab_group.resize()}});
460
- this._super(pop);
461
- } else {
462
- this._super(pop);
463
- tab_group.resize()
464
- }
465
- },
466
- resize: function(){
467
- // noop
468
- }
469
- })
470
- var IhHistoryState = Class.extend({
471
- init: function(state){
472
- this.state = jQuery.extend(true, {}, state);
473
- },
474
- toQueryString: function(){
475
- return $.param(this.state)
476
- },
477
- toUrl: function(){
478
- return [location.protocol, '//', location.host, location.pathname, '?', this.toQueryString()].join('');
479
- },
480
- addState: function(key,value){
481
- var new_state = {}
482
- new_state[key] = value
483
- this.state = $.extend(true, this.state, new_state);
484
- }
485
- })
486
- var GoProxy = Class.extend({
487
- init: function($proxy){
488
- this.first_submit = true;
489
- var go_proxy = this;
490
- go_proxy.$proxy = $proxy;
491
- go_proxy.target = go_proxy.getTarget();
492
- go_proxy.prevent_double_submit = $proxy.data('prevent-double-submit')
493
- switch($proxy.get(0).nodeName.toLowerCase()){
494
- case 'input':
495
- switch($proxy.attr('type')){
496
- case 'checkbox':
497
- default:
356
+ }),
357
+ GoProxy: Class.extend({
358
+ init: function($proxy){
359
+ this.first_submit = true;
360
+ var go_proxy = this;
361
+ go_proxy.$proxy = $proxy;
362
+ go_proxy.target = go_proxy.getTarget();
363
+ go_proxy.prevent_double_submit = $proxy.data('prevent-double-submit')
364
+ switch($proxy.get(0).nodeName.toLowerCase()){
365
+ case 'input':
366
+ switch($proxy.attr('type')){
367
+ case 'checkbox':
368
+ default:
369
+ $proxy.on('change',function(){
370
+ go_proxy.doItNow();
371
+ })
372
+ break;
373
+ }
374
+ break;
375
+ case 'select':
498
376
  $proxy.on('change',function(){
499
377
  go_proxy.doItNow();
500
378
  })
501
379
  break;
380
+ case 'a':
381
+ default:
382
+ $proxy.on('click',function(e){
383
+ e.preventDefault();
384
+ go_proxy.doItNow();
385
+ return false;
386
+ });
387
+ break;
502
388
  }
503
- break;
504
- case 'select':
505
- $proxy.on('change',function(){
506
- go_proxy.doItNow();
389
+ },
390
+ doable: function(){
391
+ return(this.first_submit || !this.prevent_double_submit)
392
+ }
393
+ }),
394
+ FieldFiller: Class.extend({
395
+ init: function($field_filler){
396
+ this.$field_filler = $field_filler
397
+ this.value = $field_filler.data('value');
398
+ this.target = $($field_filler.data('target'));
399
+ var field_filler = this
400
+ this.$field_filler.bind('click', function(e){field_filler.fill(e)})
401
+ },
402
+ fill: function(e){
403
+ e.preventDefault();
404
+ this.target.val(this.value);
405
+ return false;
406
+ }
407
+ }),
408
+ Remover: Class.extend({
409
+ init: function($remover){
410
+ $target = $($remover.data('target'));
411
+ $remover.click(function(e){
412
+ $target.remove();
507
413
  })
508
- break;
509
- case 'a':
510
- default:
511
- $proxy.on('click',function(e){
512
- e.preventDefault();
513
- go_proxy.doItNow();
514
- return false;
414
+ }
415
+ }),
416
+ Link: Class.extend({
417
+ init: function($link){
418
+ $link.click(function(){
419
+ window.location = $link.attr('href');
420
+ })
421
+ }
422
+ }),
423
+ CheckboxHiddenProxy: Class.extend({
424
+ init: function($checkbox){
425
+ this.checked_value = $checkbox.data('checked-value');
426
+ this.unchecked_value = $checkbox.data('unchecked-value');
427
+ var target_selector = $checkbox.data('target');
428
+ this.target = $(target_selector);
429
+ var checkbox = this;
430
+ $checkbox.click(function(){
431
+ if ($(this).is(':checked')) {
432
+ checkbox.target.val(checkbox.checked_value);
433
+ } else {
434
+ checkbox.target.val(checkbox.unchecked_value);
435
+ }
436
+ })
437
+ }
438
+ }),
439
+ PreventDoubleSubmit: Class.extend({
440
+ init: function($clickable){
441
+ this.$clickable = $clickable;
442
+ var double_click_preventer = this;
443
+ switch($clickable.get(0).nodeName.toLowerCase()){
444
+ case 'form':
445
+ $clickable.submit(function(e){ double_click_preventer.preventItNow(); });
446
+ break;
447
+ case 'input':
448
+ $clickable.click(function() {
449
+ setTimeout(function(){
450
+ $clickable.attr("disabled", "disabled");
451
+ }, 10);
452
+ });
453
+ break;
454
+ }
455
+ },
456
+ preventItNow: function(){
457
+ this.$clickable.submit(function(e){ e.preventDefault(); return false; });
458
+ }
459
+ }),
460
+ PreventDoubleLinkClick: Class.extend({
461
+ init: function($clickable){
462
+ $clickable.click(function(e) {
463
+ if($clickable.data('clicked')) {
464
+ e.preventDefault();
465
+ return false;
466
+ } else {
467
+ $clickable.data('clicked',true);
468
+ return true;
469
+ }
515
470
  });
516
- break;
471
+ }
472
+ }),
473
+ ReloadPage: Class.extend({
474
+ init: function(reload_page){
475
+ window.location.href = reload_page;
476
+ }
477
+ })
478
+ };
479
+ hooch.AjaxExpandable = hooch.Expandable.extend({
480
+ expand: function(){
481
+ if(!this.ajax_loaded){
482
+ this.ajax_loaded = true;
483
+ new thin_man.AjaxLinkSubmission(this.$expander);
484
+ }
485
+ this._super();
486
+ }
487
+ });
488
+ hooch.FormFieldRevealer = hooch.Revealer.extend({
489
+ init: function($revealer){
490
+ this.children_id = $revealer.data('revealer-children-id');
491
+ this.$revelation_target = $('[data-revealer-target="' + this.children_id + '"]');
492
+ this._super($revealer);
493
+ },
494
+ hideChildren: function(){
495
+ this._super();
496
+ this.$form = this.$revealer.parents('form:first')
497
+ if(this.$form.length > 0){
498
+ this.$form.after(this.$all_children)
499
+ }
500
+ },
501
+ revealChosenOnes: function(){
502
+ this.$revelation_target.html(this.$children);
503
+ this._super();
517
504
  }
518
- },
519
- doable: function(){
520
- return(this.first_submit || !this.prevent_double_submit)
521
- }
522
- });
523
- var ClickProxy = GoProxy.extend({
524
- getTarget: function(){
525
- if(this.$proxy.data('target')){
526
- return $(this.$proxy.data('target'));
527
- } else {
528
- return this.$proxy.siblings('a');
505
+ });
506
+ hooch.AjaxTabGroup = hooch.TabGroup.extend({
507
+ getTabTriggerClass: function(){
508
+ this.tab_trigger_class = hooch.AjaxTabTrigger;
529
509
  }
530
- },
531
- doItNow: function(){
532
- if(this.doable) {
533
- this.target.click();
534
- this.first_submit = false;
510
+ });
511
+ hooch.AjaxTabTrigger = hooch.TabTrigger.extend({
512
+ toggleTarget: function(pop){
513
+ var tab_group = this.tab_group;
514
+ if(!this.ajax_loaded){
515
+ this.ajax_loaded = true;
516
+ this.$tab_trigger.data('ajax-target','[data-tab-id="' + this.tab_id + '"]')
517
+ new thin_man.AjaxLinkSubmission(this.$tab_trigger,{'on_complete': function(){tab_group.resize()}});
518
+ this._super(pop);
519
+ } else {
520
+ this._super(pop);
521
+ tab_group.resize()
522
+ }
523
+ },
524
+ resize: function(){
525
+ // noop
535
526
  }
536
- }
537
- });
538
-
539
- var SubmitProxy = GoProxy.extend({
540
- getTarget: function(){
541
- if(this.$proxy.data('target')){
542
- return $(this.$proxy.data('target'));
543
- } else {
544
- return this.$proxy.parents('form:first');
527
+ });
528
+ hooch.ClickProxy = hooch.GoProxy.extend({
529
+ getTarget: function(){
530
+ if(this.$proxy.data('target')){
531
+ return $(this.$proxy.data('target'));
532
+ } else {
533
+ return this.$proxy.siblings('a');
534
+ }
535
+ },
536
+ doItNow: function(){
537
+ if(this.doable()) {
538
+ if(this.target.data('ajax-target')){
539
+ this.target.click();
540
+ }else if(this.target.attr('href')){
541
+ window.location = this.target.attr('href');
542
+ }
543
+ this.first_submit = false;
544
+ }
545
545
  }
546
- },
547
- doItNow: function(){
548
- if(this.doable) {
549
- this.target.submit();
550
- this.first_submit = false;
546
+ });
547
+ hooch.SubmitProxy = hooch.GoProxy.extend({
548
+ getTarget: function(){
549
+ if(this.$proxy.data('target')){
550
+ return $(this.$proxy.data('target'));
551
+ } else {
552
+ return this.$proxy.parents('form:first');
553
+ }
554
+ },
555
+ doItNow: function(){
556
+ if(this.doable()) {
557
+ this.target.submit();
558
+ this.first_submit = false;
559
+ }
551
560
  }
552
- }
553
- });
554
-
555
- var FieldFiller = Class.extend({
556
- init: function($field_filler){
557
- this.$field_filler = $field_filler
558
- this.value = $field_filler.data('value');
559
- this.target = $($field_filler.data('target'));
560
- var field_filler = this
561
- this.$field_filler.bind('click', function(e){field_filler.fill(e)})
562
- },
563
- fill: function(e){
564
- e.preventDefault();
565
- this.target.val(this.value);
566
- return false;
567
- }
568
- });
569
-
570
- var Emptier = Class.extend({
571
- init: function($emptier){
572
- $target = $($emptier.data('target'));
573
- $emptier.click(function(e){
574
- $target.empty();
561
+ });
562
+ hooch.TabGroup.addGroup = function(group){
563
+ if(!hooch.TabGroup.all_groups){
564
+ hooch.TabGroup.all_groups = [];
565
+ }
566
+ hooch.TabGroup.all_groups.push(group);
567
+ };
568
+ hooch.TabGroup.find = function(name){
569
+ var selected_group = null;
570
+ $.each(hooch.TabGroup.all_groups,function(index,group){
571
+ if(group.name == name){
572
+ selected_group = group;
573
+ }
574
+ });
575
+ return selected_group;
576
+ };
577
+ hooch.loadClasses = function(){
578
+ window.any_time_manager.registerListWithClasses({
579
+ 'expand-state' : 'Expandable', 'prevent-double-click' : 'PreventDoubleLinkClick'
580
+ },'hooch');
581
+ window.any_time_manager.registerList(
582
+ ['hover_overflow','hidey_button','submit-proxy','click-proxy','field-filler','revealer',
583
+ 'checkbox-hidden-proxy','prevent-double-submit','prevent-double-link-click', 'tab-group',
584
+ 'hover-reveal', 'emptier', 'remover'],'hooch');
585
+ window.any_time_manager.load();
586
+ };
587
+ $(document).ready(function(){
588
+ if(typeof window.any_time_manager === "undefined" && typeof window.loading_any_time_manager === "undefined"){
589
+ window.loading_any_time_manager = true;
590
+ $.getScript("https://cdn.rawgit.com/edraut/anytime_manager/9f710d2280e68ea6156551728cb7e2d537a06ee6/anytime_manager.js",function(){
591
+ window.loading_any_time_manager = false
592
+ hooch.loadClasses();
593
+ });
594
+ }else if(typeof window.any_time_manager === "undefined"){
595
+ if(typeof window.any_time_load_functions === 'undefined'){
596
+ window.any_time_load_functions = []
597
+ }
598
+ window.any_time_load_functions.push(hooch.loadClasses)
599
+ }else{
600
+ hooch.loadClasses();
601
+ };
602
+ $(document).on('change','[data-toggler]',function(){
603
+ new hooch.Toggler($(this));
575
604
  })
576
- }
577
- });
578
-
579
- var Remover = Class.extend({
580
- init: function($remover){
581
- $target = $($remover.data('target'));
582
- $remover.click(function(e){
583
- $target.remove();
605
+ $('[data-toggler]').each(function(){
606
+ new hooch.Toggler($(this));
584
607
  })
585
- }
586
- });
587
-
588
- var Link = Class.extend({
589
- init: function($link){
590
- $link.click(function(){
591
- window.location = $link.attr('href');
608
+ $('[data-disable_forms]').each(function(){
609
+ new hooch.DisableForms($(this));
592
610
  })
593
- }
594
- });
595
-
596
- var CheckboxHiddenProxy = Class.extend({
597
- init: function($checkbox){
598
- this.checked_value = $checkbox.data('checked-value');
599
- this.unchecked_value = $checkbox.data('unchecked-value');
600
- var target_selector = $checkbox.data('target');
601
- this.target = $(target_selector);
602
- var checkbox = this;
603
- $checkbox.click(function(){
604
- if ($(this).is(':checked')) {
605
- checkbox.target.val(checkbox.checked_value);
606
- } else {
607
- checkbox.target.val(checkbox.unchecked_value);
608
- }
611
+ $('[data-link]').each(function(){
612
+ new hooch.Link($(this));
609
613
  })
610
- }
611
- });
612
-
613
- var PreventDoubleSubmit = Class.extend({
614
- init: function($clickable){
615
- this.$clickable = $clickable;
616
- var double_click_preventer = this;
617
- switch($clickable.get(0).nodeName.toLowerCase()){
618
- case 'form':
619
- $clickable.submit(function(e){ double_click_preventer.preventItNow(); });
620
- break;
621
- case 'input':
622
- $clickable.click(function() {
623
- setTimeout(function(){
624
- $clickable.attr("disabled", "disabled");
625
- }, 10);
626
- });
627
- break;
628
- }
629
- },
630
- preventItNow: function(){
631
- this.$clickable.submit(function(e){ e.preventDefault(); return false; });
632
- }
633
- });
634
-
635
- var PreventDoubleLinkClick = Class.extend({
636
- init: function($clickable){
637
- $clickable.click(function(e) {
638
- if($clickable.data('clicked')) {
639
- e.preventDefault();
640
- return false;
641
- } else {
642
- $clickable.data('clicked',true);
643
- return true;
614
+ // Initailizes auto complete for select inputs
615
+ $('input,select,textarea').filter(':visible:enabled:first').each(function(){
616
+ if(!$(this).data('date-picker')){
617
+ $(this).focus();
644
618
  }
645
619
  });
646
- }
647
- });
648
-
649
- var ReloadPage = Class.extend({
650
- init: function(reload_page){
651
- window.location.href = reload_page;
652
- }
653
- })
654
-
655
- $(window).bind("popstate", function(e){
656
- var previous_state = new IhHistoryState(e.originalEvent.state)
657
- $.each(previous_state.state, function(key,value){
658
- var tab_group = TabGroup.find(key)
659
- if(tab_group){
660
- var tab_trigger = tab_group.getTabByPushState(value)
661
- if(tab_trigger){
662
- tab_trigger.toggleTarget('no history');
620
+ });
621
+ $(window).bind("popstate", function(e){
622
+ var previous_state = new hooch.IhHistoryState(e.originalEvent.state)
623
+ $.each(previous_state.state, function(key,value){
624
+ var tab_group = hooch.TabGroup.find(key)
625
+ if(tab_group){
626
+ var tab_trigger = tab_group.getTabByPushState(value)
627
+ if(tab_trigger){
628
+ tab_trigger.toggleTarget('no history');
629
+ }
663
630
  }
664
- }
665
- })
666
- });
667
- $(document).ready(function(){
668
- $(document).on('change','[data-toggler]',function(){
669
- new Toggler($(this));
670
- })
671
- $('[data-toggler]').each(function(){
672
- new Toggler($(this));
673
- })
674
- $('[data-disable_forms]').each(function(){
675
- new DisableForms($(this));
676
- })
677
- $('[data-link]').each(function(){
678
- new Link($(this));
679
- })
680
- // Initailizes auto complete for select inputs
681
- $('input,select,textarea').filter(':visible:enabled:first').each(function(){
682
- if(!$(this).data('date-picker')){
683
- $(this).focus();
684
- }
631
+ })
685
632
  });
686
- });
633
+ }
634
+ if(typeof Class === "undefined"){
635
+ $.getScript('https://rawgit.com/edraut/js_inheritance/a6c1e40986ecb276335b0a0b1792abd01f05ff6c/inheritance.js', function(){
636
+ initHooch();
637
+ });
638
+ }else{
639
+ initHooch();
640
+ }
@@ -2,7 +2,7 @@ module Hooch
2
2
  module HoochHelper
3
3
  def tab_set(name, type: nil, default_tab: nil)
4
4
  if :ajax == type
5
- type = 'AjaxTabGroup'
5
+ type = 'hooch.AjaxTabGroup'
6
6
  end
7
7
  attrs = 'data-tab-group=' + name
8
8
  attrs += ' data-sub-type=' + type if type.present?
@@ -39,7 +39,7 @@ module Hooch
39
39
 
40
40
  def expanded(id, type: nil)
41
41
  if :ajax == type
42
- type = 'AjaxExpandable'
42
+ type = 'hooch.AjaxExpandable'
43
43
  end
44
44
  attrs = "data-expand-state=expanded data-expand-id=" + id
45
45
  attrs += " data-sub-type=" + type if type.present?
data/lib/hooch/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Hooch
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
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.3
4
+ version: 0.0.4
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-05-02 00:00:00.000000000 Z
11
+ date: 2015-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler