middleman-gumby 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +43 -0
  6. data/Rakefile +1 -0
  7. data/lib/middleman/gumby.rb +17 -0
  8. data/lib/middleman/gumby/version.rb +5 -0
  9. data/middleman-gumby.gemspec +25 -0
  10. data/vendor/assets/fonts/icons/entypo.eot +0 -0
  11. data/vendor/assets/fonts/icons/entypo.ttf +0 -0
  12. data/vendor/assets/fonts/icons/entypo.woff +0 -0
  13. data/vendor/assets/javascripts/gumby/libs/gumby.init.js +47 -0
  14. data/vendor/assets/javascripts/gumby/libs/gumby.js +258 -0
  15. data/vendor/assets/javascripts/gumby/libs/gumby.min.js +1 -0
  16. data/vendor/assets/javascripts/gumby/libs/jquery-1.10.1.min.js +6 -0
  17. data/vendor/assets/javascripts/gumby/libs/jquery-1.10.1.min.map +1 -0
  18. data/vendor/assets/javascripts/gumby/libs/jquery-2.0.2.min.js +6 -0
  19. data/vendor/assets/javascripts/gumby/libs/jquery-2.0.2.min.map +1 -0
  20. data/vendor/assets/javascripts/gumby/libs/jquery.mobile.custom.min.js +3 -0
  21. data/vendor/assets/javascripts/gumby/libs/modernizr-2.6.2.min.js +4 -0
  22. data/vendor/assets/javascripts/gumby/libs/ui/gumby.checkbox.js +101 -0
  23. data/vendor/assets/javascripts/gumby/libs/ui/gumby.fixed.js +240 -0
  24. data/vendor/assets/javascripts/gumby/libs/ui/gumby.navbar.js +111 -0
  25. data/vendor/assets/javascripts/gumby/libs/ui/gumby.radiobtn.js +90 -0
  26. data/vendor/assets/javascripts/gumby/libs/ui/gumby.retina.js +81 -0
  27. data/vendor/assets/javascripts/gumby/libs/ui/gumby.skiplink.js +157 -0
  28. data/vendor/assets/javascripts/gumby/libs/ui/gumby.tabs.js +80 -0
  29. data/vendor/assets/javascripts/gumby/libs/ui/gumby.toggleswitch.js +264 -0
  30. data/vendor/assets/javascripts/gumby/libs/ui/jquery.validation.js +142 -0
  31. data/vendor/assets/javascripts/gumby/main.js +23 -0
  32. data/vendor/assets/javascripts/gumby/plugins.js +4 -0
  33. data/vendor/assets/javascripts/gumby/production.js +3 -0
  34. data/vendor/assets/sass/_base.scss +49 -0
  35. data/vendor/assets/sass/_custom.scss +1 -0
  36. data/vendor/assets/sass/_fonts.scss +28 -0
  37. data/vendor/assets/sass/_grid.scss +339 -0
  38. data/vendor/assets/sass/_shame.scss +36 -0
  39. data/vendor/assets/sass/_typography.scss +272 -0
  40. data/vendor/assets/sass/extensions/modular-scale/lib/modular-scale.rb +128 -0
  41. data/vendor/assets/sass/extensions/modular-scale/stylesheets/_modular-scale.scss +310 -0
  42. data/vendor/assets/sass/extensions/sassy-math/lib/sassy-math.rb +159 -0
  43. data/vendor/assets/sass/extensions/sassy-math/stylesheets/_math.scss +310 -0
  44. data/vendor/assets/sass/functions/_all.scss +25 -0
  45. data/vendor/assets/sass/functions/_breakpoints.scss +11 -0
  46. data/vendor/assets/sass/functions/_button-size.scss +44 -0
  47. data/vendor/assets/sass/functions/_clearfix.scss +25 -0
  48. data/vendor/assets/sass/functions/_em.scss +11 -0
  49. data/vendor/assets/sass/functions/_even.scss +10 -0
  50. data/vendor/assets/sass/functions/_fade.scss +20 -0
  51. data/vendor/assets/sass/functions/_fancytiles.scss +29 -0
  52. data/vendor/assets/sass/functions/_fixed.scss +21 -0
  53. data/vendor/assets/sass/functions/_forms.scss +18 -0
  54. data/vendor/assets/sass/functions/_grid-calc.scss +82 -0
  55. data/vendor/assets/sass/functions/_height-calc.scss +6 -0
  56. data/vendor/assets/sass/functions/_icons.scss +35 -0
  57. data/vendor/assets/sass/functions/_line-and-height.scss +7 -0
  58. data/vendor/assets/sass/functions/_palette.scss +76 -0
  59. data/vendor/assets/sass/functions/_responsivity.scss +34 -0
  60. data/vendor/assets/sass/functions/_semantic-grid.scss +170 -0
  61. data/vendor/assets/sass/functions/_shapes.scss +22 -0
  62. data/vendor/assets/sass/functions/_strip-units.scss +5 -0
  63. data/vendor/assets/sass/functions/_tooltips.scss +98 -0
  64. data/vendor/assets/sass/functions/_typography.scss +15 -0
  65. data/vendor/assets/sass/functions/_visibility.scss +17 -0
  66. data/vendor/assets/sass/gumby.scss +39 -0
  67. data/vendor/assets/sass/ui/_all.scss +11 -0
  68. data/vendor/assets/sass/ui/_buttons.scss +154 -0
  69. data/vendor/assets/sass/ui/_forms.scss +392 -0
  70. data/vendor/assets/sass/ui/_icons.scss +23 -0
  71. data/vendor/assets/sass/ui/_images.scss +23 -0
  72. data/vendor/assets/sass/ui/_labels.scss +87 -0
  73. data/vendor/assets/sass/ui/_navbar.scss +440 -0
  74. data/vendor/assets/sass/ui/_tables.scss +89 -0
  75. data/vendor/assets/sass/ui/_tabs.scss +156 -0
  76. data/vendor/assets/sass/ui/_toggles.scss +73 -0
  77. data/vendor/assets/sass/ui/_tooltips.scss +12 -0
  78. data/vendor/assets/sass/ui/_video.scss +24 -0
  79. data/vendor/assets/sass/var/_lists.scss +20 -0
  80. data/vendor/assets/sass/var/_settings.scss +169 -0
  81. data/vendor/assets/sass/var/icons/_entypo-icon-list.scss +286 -0
  82. data/vendor/assets/sass/var/icons/_entypo.scss +294 -0
  83. metadata +167 -0
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Gumby RadioBtn
3
+ */
4
+ !function($) {
5
+
6
+ 'use strict';
7
+
8
+ function RadioBtn($el) {
9
+
10
+ Gumby.debug('Initializing Radio Button', $el);
11
+
12
+ this.$el = $el;
13
+ this.$input = this.$el.find('input[type=radio]');
14
+
15
+ var scope = this;
16
+
17
+ // listen for click event and custom gumby check event
18
+ this.$el.on(Gumby.click, function(e) {
19
+ // prevent radio button checking, we'll do that manually
20
+ e.preventDefault();
21
+
22
+ // do nothing if radio is disabled
23
+ if (scope.$input.is('[disabled]')) {
24
+ return;
25
+ }
26
+
27
+ // check radio button
28
+ scope.update();
29
+ }).on('gumby.check', function() {
30
+ Gumby.debug('Check event triggered', scope.$el);
31
+ scope.update();
32
+ });
33
+
34
+ // update any prechecked on load
35
+ if(this.$input.prop('checked') || this.$el.hasClass('checked')) {
36
+ scope.update(true);
37
+ }
38
+ }
39
+
40
+ // check radio button, uncheck all others in name group
41
+ RadioBtn.prototype.update = function() {
42
+
43
+ // already checked so no need to update
44
+ if(this.$el.hasClass('checked') && this.$input.prop('checked') && this.$el.find('i.icon-dot').length) {
45
+ return;
46
+ }
47
+
48
+ Gumby.debug('Updating Radio Button group', this.$el);
49
+
50
+ var $span = this.$el.find('span'),
51
+ // the group of radio buttons
52
+ group = 'input[name="'+this.$input.attr('name')+'"]';
53
+
54
+ // uncheck radio buttons in same group - uncheck input, remove checked class, remove <i>
55
+ $('.radio').has(group).removeClass('checked')
56
+ .find('input').prop('checked', false).end()
57
+ .find('i').remove();
58
+
59
+ // check this radio button - check input, add checked class, append <i>
60
+ this.$input.prop('checked', true);
61
+ $span.append('<i class="icon-dot" />');
62
+
63
+ Gumby.debug('Triggering onCheck event', this.$el);
64
+
65
+ this.$el.addClass('checked').trigger('gumby.onCheck');
66
+ };
67
+
68
+ // add initialisation
69
+ Gumby.addInitalisation('radiobtn', function() {
70
+ $('.radio').each(function() {
71
+ var $this = $(this);
72
+ // this element has already been initialized
73
+ if($this.data('isRadioBtn')) {
74
+ return true;
75
+ }
76
+ // mark element as initialized
77
+ $this.data('isRadioBtn', true);
78
+ new RadioBtn($this);
79
+ });
80
+ });
81
+
82
+ // register UI module
83
+ Gumby.UIModule({
84
+ module: 'radiobtn',
85
+ events: ['onCheck', 'check'],
86
+ init: function() {
87
+ Gumby.initialize('radiobtn');
88
+ }
89
+ });
90
+ }(jQuery);
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Gumby Retina
3
+ */
4
+ !function($) {
5
+
6
+ 'use strict';
7
+
8
+ function Retina($el) {
9
+
10
+ Gumby.debug('Initializing Retina', $el);
11
+
12
+ this.$el = $el;
13
+ this.imageSrc = this.$el.attr('src');
14
+ this.retinaSrc = this.fetchRetinaImage();
15
+ this.$retinaImg = $(new Image());
16
+
17
+ var scope = this;
18
+
19
+ // image src not valid
20
+ if(!this.retinaSrc) {
21
+ return false;
22
+ }
23
+
24
+ // load retina image
25
+ this.$retinaImg.attr('src', this.retinaSrc).load(function() {
26
+ scope.retinaImageLoaded();
27
+ }).error(function() {
28
+ Gumby.error('Couln\'t load retina image: '+scope.retinaSrc);
29
+ });
30
+ }
31
+
32
+ // fetch retina src by appending '@2x' to image string before extension
33
+ Retina.prototype.fetchRetinaImage = function() {
34
+ var imgSrc = this.imageSrc,
35
+ index = this.imageSrc.search(/(\.|\/)(gif|jpe?g|png)$/i);
36
+
37
+ // image src is not valid
38
+ if(index < 0) {
39
+ return false;
40
+ }
41
+
42
+ // return retina src
43
+ return imgSrc.substr(0, index) + '@2x' + imgSrc.substr(index, imgSrc.length);
44
+ };
45
+
46
+ // once retina image loaded swap original src
47
+ Retina.prototype.retinaImageLoaded = function() {
48
+ Gumby.debug('Swapping image for retina version', this.$el);
49
+ Gumby.debug('Triggering onRetina event', this.$el);
50
+ this.$el.attr('src', this.$retinaImg.attr('src')).trigger('gumby.onRetina');
51
+ };
52
+
53
+ // add initialisation
54
+ Gumby.addInitalisation('retina', function() {
55
+
56
+ // this module is for retina devices only
57
+ if(!window.devicePixelRatio || window.devicePixelRatio <= 1) {
58
+ return;
59
+ }
60
+
61
+ $('img[data-retina],img[gumby-retina],img[retina]').each(function() {
62
+ var $this = $(this);
63
+ // this element has already been initialized
64
+ if($this.data('isRetina')) {
65
+ return true;
66
+ }
67
+ // mark element as initialized
68
+ $this.data('isRetina', true);
69
+ new Retina($this);
70
+ });
71
+ });
72
+
73
+ // register UI module
74
+ Gumby.UIModule({
75
+ module: 'retina',
76
+ events: ['onRetina'],
77
+ init: function() {
78
+ Gumby.initialize('retina');
79
+ }
80
+ });
81
+ }(jQuery);
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Gumby SkipLink
3
+ */
4
+ !function($) {
5
+
6
+ 'use strict';
7
+
8
+ function SkipLink($el) {
9
+
10
+ Gumby.debug('Initializing Skiplink', $el);
11
+
12
+ this.$el = $el;
13
+ this.targetPos = 0;
14
+ this.duration = 0;
15
+ this.offset = false;
16
+ this.easing = '';
17
+ this.update = false;
18
+
19
+ // set up module based on attributes
20
+ this.setup();
21
+
22
+ var scope = this;
23
+
24
+ // skip to target element on click or trigger of gumby.skipTo event
25
+ this.$el.on(Gumby.click+' gumby.skip', function(e) {
26
+ e.preventDefault();
27
+
28
+ if(e.namespace === 'skip') {
29
+ Gumby.debug('Skip event triggered', scope.$el);
30
+ }
31
+
32
+ // calculate target on each click if update var set to true
33
+ if(scope.update) {
34
+ scope.calculateTarget(scope.skipTo);
35
+
36
+ // skip straight to target
37
+ } else {
38
+ scope.skipTo();
39
+ }
40
+ }).on('gumby.initialize', function() {
41
+ Gumby.debug('Re-initializing Skiplink', scope.$el);
42
+ scope.setup();
43
+ });
44
+ }
45
+
46
+ // set up module based on attributes
47
+ SkipLink.prototype.setup = function() {
48
+ this.duration = Number(Gumby.selectAttr.apply(this.$el, ['duration'])) || 200;
49
+ this.offset = Gumby.selectAttr.apply(this.$el, ['offset']) || false;
50
+ this.easing = Gumby.selectAttr.apply(this.$el, ['easing']) || 'swing';
51
+ this.update = Gumby.selectAttr.apply(this.$el, ['update']) ? true : false;
52
+
53
+ this.calculateTarget();
54
+ };
55
+
56
+ // calculate target px point to skip to
57
+ SkipLink.prototype.calculateTarget = function(cb) {
58
+
59
+ var scope = this,
60
+ target = Gumby.selectAttr.apply(this.$el, ['goto']),
61
+ $target;
62
+
63
+ // 'top' specified so target is 0px
64
+ if(target == 'top') {
65
+ this.targetPos = 0;
66
+
67
+ // px point specified
68
+ } else if($.isNumeric(target)) {
69
+ this.targetPos = Number(target);
70
+ } else {
71
+
72
+ // check for element with target as selector
73
+ $target = $(target);
74
+
75
+ // target does not exist, we need a target
76
+ if(!$target.length) {
77
+ Gumby.error('Cannot find skiplink target: '+target);
78
+ return false;
79
+ }
80
+
81
+ this.targetPos = $target.offset().top;
82
+ }
83
+
84
+ if(cb) {
85
+ cb.apply(this);
86
+ }
87
+ };
88
+
89
+ // animate body, html scrollTop value to target px point
90
+ SkipLink.prototype.skipTo = function() {
91
+
92
+ Gumby.debug('Skipping to target', this.$el);
93
+
94
+ var scope = this;
95
+
96
+ // slide to position of target
97
+ $('html,body').animate({
98
+ 'scrollTop' : this.calculateOffset()
99
+ }, this.duration, this.easing).promise().done(function() {
100
+
101
+ Gumby.debug('Triggering onComplete event', scope.$el);
102
+ scope.$el.trigger('gumby.onComplete');
103
+ });
104
+ };
105
+
106
+ // calculate offset with current target point
107
+ SkipLink.prototype.calculateOffset = function() {
108
+ // no offset so return target here
109
+ if(!this.offset) {
110
+ return this.targetPos;
111
+ }
112
+
113
+ // negative / positive
114
+ var op = this.offset.substr(0, 1),
115
+ off = Number(this.offset.substr(1, this.offset.length));
116
+
117
+ // subtract offset from target position
118
+ if(op === '-') {
119
+ return this.targetPos - off;
120
+ // add offset to target position
121
+ } else if(op === '+') {
122
+ return this.targetPos + off;
123
+ }
124
+ };
125
+
126
+ // add initialisation
127
+ Gumby.addInitalisation('skiplink', function(all) {
128
+ $('.skiplink > a, .skip').each(function() {
129
+ var $this = $(this);
130
+
131
+ // this element has already been initialized
132
+ // and we're only initializing new modules
133
+ if($this.data('isSkipLink') && !all) {
134
+ return true;
135
+
136
+ // this element has already been initialized
137
+ // and we need to reinitialize it
138
+ } else if($this.data('isSkipLink') && all) {
139
+ $this.trigger('gumby.initialize');
140
+ return true;
141
+ }
142
+
143
+ // mark element as initialized
144
+ $this.data('isSkipLink', true);
145
+ new SkipLink($this);
146
+ });
147
+ });
148
+
149
+ // register UI module
150
+ Gumby.UIModule({
151
+ module: 'skiplink',
152
+ events: ['initialize', 'onComplete', 'skip'],
153
+ init: function() {
154
+ Gumby.initialize('skiplink');
155
+ }
156
+ });
157
+ }(jQuery);
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Gumby Tabs
3
+ */
4
+ !function($) {
5
+
6
+ 'use strict';
7
+
8
+ function Tabs($el) {
9
+
10
+ Gumby.debug('Initializing Tabs', $el);
11
+
12
+ this.$el = $el;
13
+ this.$nav = this.$el.find('ul.tab-nav > li');
14
+ this.$content = this.$el.find('.tab-content');
15
+
16
+ var scope = this;
17
+
18
+ // listen for click event on tab nav and custom gumby set event
19
+ this.$nav.children('a').on(Gumby.click, function(e) {
20
+ e.preventDefault();
21
+ scope.click($(this));
22
+ });
23
+
24
+ // listen for gumby.set value for dynamically set tabs
25
+ this.$el.on('gumby.set', function(e, index) {
26
+ Gumby.debug('Set event triggered', scope.$el);
27
+ scope.set(e, index);
28
+ });
29
+ }
30
+
31
+ // handle tab nav click event
32
+ Tabs.prototype.click = function($this) {
33
+ // index of item to activate
34
+ var index = $this.parent().index();
35
+
36
+ if(this.$nav.eq(index).add(this.$content.eq(index)).hasClass('active')) {
37
+ return;
38
+ }
39
+
40
+ Gumby.debug('Setting active tab to '+index, this.$el);
41
+
42
+ // deactivate other tab navigation and content
43
+ this.$nav.add(this.$content).removeClass('active');
44
+
45
+ // activate this tab nav link and content
46
+ this.$nav.eq(index).add(this.$content.eq(index)).addClass('active');
47
+
48
+ // trigger gumby.change event and pass current active tab index
49
+ Gumby.debug('Triggering onChange event', this.$el);
50
+ this.$el.trigger('gumby.onChange', index);
51
+ };
52
+
53
+ // set specific tab
54
+ Tabs.prototype.set = function(e, index) {
55
+ this.$nav.eq(index).find('a').trigger(Gumby.click);
56
+ };
57
+
58
+ // add initialisation
59
+ Gumby.addInitalisation('tabs', function() {
60
+ $('.tabs').each(function() {
61
+ var $this = $(this);
62
+ // this element has already been initialized
63
+ if($this.data('isTabs')) {
64
+ return true;
65
+ }
66
+ // mark element as initialized
67
+ $this.data('isTabs', true);
68
+ new Tabs($this);
69
+ });
70
+ });
71
+
72
+ // register UI module
73
+ Gumby.UIModule({
74
+ module: 'tabs',
75
+ events: ['onChange', 'set'],
76
+ init: function() {
77
+ Gumby.initialize('tabs');
78
+ }
79
+ });
80
+ }(jQuery);
@@ -0,0 +1,264 @@
1
+ /**
2
+ * Gumby Toggles/Switches
3
+ */
4
+ !function($) {
5
+
6
+ 'use strict';
7
+
8
+ // Toggle constructor
9
+ function Toggle($el) {
10
+ this.$el = $($el);
11
+ this.targets = [];
12
+ this.on = '';
13
+ this.className = '';
14
+ this.self = false;
15
+
16
+ if(this.$el.length) {
17
+ Gumby.debug('Initializing Toggle', $el);
18
+ this.init();
19
+ }
20
+ }
21
+
22
+ // Switch constructor
23
+ function Switch($el) {
24
+ this.$el = $($el);
25
+ this.targets = [];
26
+ this.on = '';
27
+ this.className = '';
28
+ this.self = false;
29
+
30
+ if(this.$el.length) {
31
+ Gumby.debug('Initializing Switch', $el);
32
+ this.init();
33
+ }
34
+ }
35
+
36
+ // intialise toggles, switches will inherit method
37
+ Toggle.prototype.init = function() {
38
+ var scope = this;
39
+
40
+ // set up module based on attributes
41
+ this.setup();
42
+
43
+ // bind to specified event and trigger
44
+ this.$el.on(this.on, function(e) {
45
+ e.preventDefault();
46
+ scope.trigger(scope.triggered);
47
+
48
+ // listen for gumby.trigger to dynamically trigger toggle/switch
49
+ }).on('gumby.trigger', function() {
50
+ Gumby.debug('Trigger event triggered', scope.$el);
51
+ scope.trigger(scope.triggered);
52
+ // re-initialize module
53
+ }).on('gumby.initialize', function() {
54
+ Gumby.debug('Re-initializing '+scope.constructor, $el);
55
+ scope.setup();
56
+ });
57
+ };
58
+
59
+ // set up module based on attributes
60
+ Toggle.prototype.setup = function() {
61
+ this.targets = this.parseTargets();
62
+ this.on = Gumby.selectAttr.apply(this.$el, ['on']) || Gumby.click;
63
+ this.className = Gumby.selectAttr.apply(this.$el, ['classname']) || 'active';
64
+ this.self = Gumby.selectAttr.apply(this.$el, ['self']) === 'false';
65
+ };
66
+
67
+ // parse data-for attribute, switches will inherit method
68
+ Toggle.prototype.parseTargets = function() {
69
+ var targetStr = Gumby.selectAttr.apply(this.$el, ['trigger']),
70
+ secondaryTargets = 0,
71
+ targets = [];
72
+
73
+ // no targets so return false
74
+ if(!targetStr) {
75
+ return false;
76
+ }
77
+
78
+ secondaryTargets = targetStr.indexOf('|');
79
+
80
+ // no secondary targets specified so return single target
81
+ if(secondaryTargets === -1) {
82
+ if(!this.checkTargets([targetStr])) {
83
+ return false;
84
+ }
85
+ return [$(targetStr)];
86
+ }
87
+
88
+ // return array of both targets, split and return 0, 1
89
+ targets = targetStr.split('|');
90
+ if(!this.checkTargets(targets)) {
91
+ return false;
92
+ }
93
+ return targets.length > 1 ? [$(targets[0]), $(targets[1])] : [$(targets[0])];
94
+ };
95
+
96
+ Toggle.prototype.checkTargets = function(targets) {
97
+ var i = 0;
98
+
99
+ for(i; i < targets.length; i++) {
100
+ if(targets[i] && !$(targets[i]).length) {
101
+ Gumby.error('Cannot find '+this.constructor.name+' target: '+targets[i]);
102
+ return false;
103
+ }
104
+ }
105
+
106
+ return true;
107
+ };
108
+
109
+ // call triggered event and pass target data
110
+ Toggle.prototype.triggered = function() {
111
+ // trigger gumby.onTrigger event and pass array of target status data
112
+ Gumby.debug('Triggering onTrigger event', this.$el);
113
+ this.$el.trigger('gumby.onTrigger', [this.$el.hasClass(this.className)]);
114
+ };
115
+
116
+ // Switch object inherits from Toggle
117
+ Switch.prototype = new Toggle();
118
+ Switch.prototype.constructor = Switch;
119
+
120
+ // Toggle specific trigger method
121
+ Toggle.prototype.trigger = function(cb) {
122
+
123
+ Gumby.debug('Triggering Toggle', this.$el);
124
+
125
+ var $target;
126
+
127
+ // no targets just toggle active class on toggle
128
+ if(!this.targets) {
129
+ this.$el.toggleClass(this.className);
130
+
131
+ // combine single target with toggle and toggle active class
132
+ } else if(this.targets.length == 1) {
133
+ this.$el.add(this.targets[0]).toggleClass(this.className);
134
+
135
+ // if two targets check active state of first
136
+ // always combine toggle and first target
137
+ } else if(this.targets.length > 1) {
138
+ if(this.targets[0].hasClass(this.className)) {
139
+ $target = this.targets[0];
140
+
141
+ // add this element to it unless gumby-self set
142
+ if(!this.self) {
143
+ $target = $target.add(this.$el);
144
+ }
145
+
146
+ $target.removeClass(this.className);
147
+ this.targets[1].addClass(this.className);
148
+ } else {
149
+ $target = this.targets[0];
150
+
151
+ // add this element to it unless gumby-self set
152
+ if(!this.self) {
153
+ $target = $target.add(this.$el);
154
+ }
155
+
156
+ $target.addClass(this.className);
157
+ this.targets[1].removeClass(this.className);
158
+ }
159
+ }
160
+
161
+ // call event handler here, applying scope of object Switch/Toggle
162
+ if(cb && typeof cb === 'function') {
163
+ cb.apply(this);
164
+ }
165
+ };
166
+
167
+ // Switch specific trigger method
168
+ Switch.prototype.trigger = function(cb) {
169
+
170
+ Gumby.debug('Triggering Switch', this.$el);
171
+
172
+ var $target;
173
+
174
+ // no targets just add active class to switch
175
+ if(!this.targets) {
176
+ this.$el.addClass(this.className);
177
+
178
+ // combine single target with switch and add active class
179
+ } else if(this.targets.length == 1) {
180
+ $target = this.targets[0];
181
+
182
+ // add this element to it unless gumby-self set
183
+ if(!this.self) {
184
+ $target = $target.add(this.$el);
185
+ }
186
+
187
+ $target.addClass(this.className);
188
+
189
+ // if two targets check active state of first
190
+ // always combine switch and first target
191
+ } else if(this.targets.length > 1) {
192
+ $target = this.targets[0];
193
+
194
+ // add this element to it unless gumby-self set
195
+ if(!this.self) {
196
+ $target = $target.add(this.$el);
197
+ }
198
+
199
+ $target.addClass(this.className);
200
+ this.targets[1].removeClass(this.className);
201
+ }
202
+
203
+ // call event handler here, applying scope of object Switch/Toggle
204
+ if(cb && typeof cb === 'function') {
205
+ cb.apply(this);
206
+ }
207
+ };
208
+
209
+ // add toggle initialisation
210
+ Gumby.addInitalisation('toggles', function(all) {
211
+ $('.toggle').each(function() {
212
+ var $this = $(this);
213
+
214
+ // this element has already been initialized
215
+ // and we're only initializing new modules
216
+ if($this.data('isToggle') && !all) {
217
+ return true;
218
+
219
+ // this element has already been initialized
220
+ // and we need to reinitialize it
221
+ } else if($this.data('isToggle') && all) {
222
+ $this.trigger('gumby.initialize');
223
+ }
224
+
225
+ // mark element as initialized
226
+ $this.data('isToggle', true);
227
+ new Toggle($this);
228
+ });
229
+ });
230
+
231
+ // add switches initialisation
232
+ Gumby.addInitalisation('switches', function(all) {
233
+ $('.switch').each(function() {
234
+ var $this = $(this);
235
+
236
+ // this element has already been initialized
237
+ // and we're only initializing new modules
238
+ if($this.data('isSwitch') && !all) {
239
+ return true;
240
+
241
+ // this element has already been initialized
242
+ // and we need to reinitialize it
243
+ } else if($this.data('isSwitch') && all) {
244
+ $this.trigger('gumby.initialize');
245
+ return true;
246
+ }
247
+
248
+ // mark element as initialized
249
+ $this.data('isSwitch', true);
250
+ new Switch($this);
251
+ });
252
+ });
253
+
254
+ // register UI module
255
+ Gumby.UIModule({
256
+ module: 'toggleswitch',
257
+ events: ['initialize', 'trigger', 'onTrigger'],
258
+ init: function() {
259
+ // Run initialize methods
260
+ Gumby.initialize('switches');
261
+ Gumby.initialize('toggles');
262
+ }
263
+ });
264
+ }(jQuery);