gumby 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  module Gumby
2
2
  module Framework
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
@@ -0,0 +1,47 @@
1
+ /* TEAM */
2
+
3
+ Digital Surgeons
4
+ Twitter: @digitalsurgeons
5
+ Twitter: @gumbycss
6
+ Web: www.digitalsurgeons.com
7
+ Web: www.gumbyframework.com
8
+
9
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
10
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
11
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
12
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,:~~~====~,,,,,,,,,,,,,
13
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=================+,,,,,,,,,,,,,
14
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,:==================,,,,,,,,,,,,,
15
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,+=================:,,,,,,,,,,,,
16
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================:,,,,,,,,,,,,
17
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,~=================~,,,,,,,,,,,,
18
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,~=================~,,,,,,,,,,,,
19
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,=================~,,,,,,,,,,,,
20
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================,,,,,,,,,,,,
21
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================,,,,,,,,,,,,
22
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================,,,,,,,,,,,,
23
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================,,,,,,,,,,,,
24
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==================,,,,,,,,,,,,
25
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,~==============:,,,,,,,,,,,,,,
26
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,==========:,,,,,,,,,,,,,,,,,,,
27
+ ,,,,,,,,,,,,,,,,,,,,,,,,:~=========:,,,,,,,,,,,,,,,,,,,,,,,,
28
+ ,,,,,,,,,,,,,,,,,:================,,,,,,,,,,,,,,,,,,,,,,,,,,
29
+ ,,,,,,,,,,,,:=====================,,,,,,,,,,,,,,,,,,,,,,,,,,
30
+ ,,,,,,,,,,,=======================,,,,,,,,,,,,,,,,,,,,,,,,,,
31
+ ,,,,,,,,,,,=======================:,,,,,,,,,,,,,,,,,,,,,,,,,
32
+ ,,,,,,,,,,,=======================~,,,,,,,,,,,,,,,,,,,,,,,,,
33
+ ,,,,,,,,,,,,=~====================~,,,,,,,,,,,,,,,,,,,,,,,,,
34
+ ,,,,,,,,,,,,=~~~~~~~~~~~~~~~~~~~~~=,,,,,,,,,,,,,,,,,,,,,,,,,
35
+ ,,,,,,,,,,,,~~==~~~~~~~~~~~~~~=====,,,,,,,,,,,,,,,,,,,,,,,,,
36
+ ,,,,,,,,,,,,,=~~~~~~~~~~~~~~~~~~~~~,,,,,,,,,,,,,,,,,,,,,,,,,
37
+ ,,,,,,,,,,,,,=~~~~~~~~~~~~~~~~~~~~~,,,,,,,,,,,,,,,,,,,,,,,,,
38
+ ,,,,,,,,,,,,,,~~~~~~~~~~~~~~~~~~~~,,,,,,,,,,,,,,,,,,,,,,,,,,
39
+ ,,,,,,,,,,,,,,~~~~~~~~~~~~~~~~:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
40
+ ,,,,,,,,,,,,,,~~~~~~~~~~~~~:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
41
+ ,,,,,,,,,,,,,,,~~~~~~~~,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
42
+ ,,,,,,,,,,,,,,,~~~~:,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
43
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
44
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,..
45
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....
46
+ ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....
47
+
@@ -17,134 +17,155 @@
17
17
  */
18
18
  !function() {
19
19
 
20
- 'use strict';
21
-
22
- function Gumby() {
23
- this.$dom = $(document);
24
- this.isOldie = !!this.$dom.find('html').hasClass('oldie');
25
- this.click = 'click';
26
- this.onReady = this.onOldie = this.onTouch = false;
27
- this.uiModules = {};
28
- this.inits = {};
29
-
30
- // check and set path with js/libs default
31
- this.path = $('script[gumby-path]').attr('gumby-path') || 'js/libs';
32
-
33
- // check and set breakpoint with 1024 default
34
- this.breakpoint = Number($('script[gumby-breakpoint]').attr('gumby-breakpoint')) || 1024;
35
- }
36
-
37
- // initialize Gumby
38
- Gumby.prototype.init = function() {
39
- var scope = this;
40
-
41
- // call ready() code when dom is ready
42
- this.$dom.ready(function() {
43
- // init UI modules
44
- scope.initUIModules();
45
-
46
- if(scope.onReady) {
47
- scope.onReady();
48
- }
49
-
50
- // call oldie() callback if applicable
51
- if(scope.isOldie && scope.onOldie) {
52
- scope.onOldie();
53
- }
54
-
55
- // call touch() callback if applicable
56
- if(Modernizr.touch && scope.onTouch) {
57
- scope.onTouch();
58
- }
59
- });
60
- };
61
-
62
- // public helper - set Gumby ready callback
63
- Gumby.prototype.ready = function(code) {
64
- if(code && typeof code === 'function') {
65
- this.onReady = code;
66
- }
67
- };
68
-
69
- // public helper - set oldie callback
70
- Gumby.prototype.oldie = function(code) {
71
- if(code && typeof code === 'function') {
72
- this.onOldie = code;
73
- }
74
- };
75
-
76
- // public helper - set touch callback
77
- Gumby.prototype.touch = function(code) {
78
- if(code && typeof code === 'function') {
79
- this.onTouch = code;
80
- }
81
- };
82
-
83
- // public helper - return debuggin object including uiModules object
84
- Gumby.prototype.debug = function() {
85
- return {
86
- $dom: this.$dom,
87
- isOldie: this.isOldie,
88
- uiModules: this.uiModules,
89
- click: this.click
90
- };
91
- };
92
-
93
- // grab attribute value, testing data- gumby- and no prefix
94
- Gumby.prototype.selectAttr = function() {
95
- var i = 0;
96
-
97
- // any number of attributes can be passed
98
- for(; i < arguments.length; i++) {
99
- // various formats
100
- var attr = arguments[i],
101
- dataAttr = 'data-'+arguments[i],
102
- gumbyAttr = 'gumby-'+arguments[i];
103
-
104
- // first test for data-attr
105
- if(this.is('['+dataAttr+']')) {
106
- return this.attr(dataAttr) ? this.attr(dataAttr) : true;
107
-
108
- // next test for gumby-attr
109
- } else if(this.is('['+gumbyAttr+']')) {
110
- return this.attr(gumbyAttr) ? this.attr(gumbyAttr) : true;
111
-
112
- // finally no prefix
113
- } else if(this.is('['+attr+']')) {
114
- return this.attr(attr) ? this.attr(attr) : true;
115
- }
116
- }
117
-
118
- // none found
119
- return false;
120
- };
121
-
122
- // add an initialisation method
123
- Gumby.prototype.addInitalisation = function(ref, code) {
124
- this.inits[ref] = code;
125
- };
126
-
127
- // initialize a uiModule
128
- Gumby.prototype.initialize = function(ref, all) {
129
- if(this.inits[ref] && typeof this.inits[ref] === 'function') {
130
- this.inits[ref](all);
131
- }
132
- };
133
-
134
- // store a UI module
135
- Gumby.prototype.UIModule = function(data) {
136
- var module = data.module;
137
- this.uiModules[module] = data;
138
- };
139
-
140
- // loop round and init all UI modules
141
- Gumby.prototype.initUIModules = function() {
142
- var x;
143
- for(x in this.uiModules) {
144
- this.uiModules[x].init();
145
- }
146
- };
147
-
148
- window.Gumby = new Gumby();
20
+ 'use strict';
21
+
22
+ function Gumby() {
23
+ this.$dom = $(document);
24
+ this.isOldie = !!this.$dom.find('html').hasClass('oldie');
25
+ this.click = this.detectClickEvent();
26
+ this.uiModules = {};
27
+ this.inits = {};
28
+ this.onReady = false;
29
+ this.onOldie = false;
30
+
31
+ var scope = this;
32
+
33
+ // when document is ready init
34
+ this.$dom.ready(function() {
35
+
36
+ // call oldie callback if available
37
+ if(scope.isOldie && scope.onOldie) {
38
+ scope.onOldie();
39
+ }
40
+
41
+ // init UI modules
42
+ scope.initUIModules();
43
+
44
+ // call ready callback if available
45
+ if(scope.onReady) {
46
+ scope.onReady();
47
+ }
48
+ });
49
+ }
50
+
51
+ // public helper - return debuggin object including uiModules object
52
+ Gumby.prototype.debug = function() {
53
+ return {
54
+ $dom: this.$dom,
55
+ isOldie: this.isOldie,
56
+ uiModules: this.uiModules
57
+ };
58
+ };
59
+
60
+ // public helper - set Gumby ready callback
61
+ Gumby.prototype.ready = function(code) {
62
+ if(code && typeof code === 'function') {
63
+ this.onReady = code;
64
+ }
65
+ };
66
+
67
+ // public helper - set oldie callback
68
+ Gumby.prototype.oldie = function(code) {
69
+ if(code && typeof code === 'function') {
70
+ this.onOldie = code;
71
+ }
72
+ };
73
+
74
+ // grab attribute value, testing data- gumby- and no prefix
75
+ Gumby.prototype.selectAttr = function() {
76
+ var i = 0;
77
+
78
+ // any number of attributes can be passed
79
+ for(; i < arguments.length; i++) {
80
+ // various formats
81
+ var attr = arguments[i],
82
+ dataAttr = 'data-'+arguments[i],
83
+ gumbyAttr = 'gumby-'+arguments[i];
84
+
85
+ // first test for data-attr
86
+ if(this.attr(dataAttr)) {
87
+ return this.attr(dataAttr);
88
+
89
+ // next test for gumby-attr
90
+ } else if(this.attr(gumbyAttr)) {
91
+ return this.attr(gumbyAttr);
92
+
93
+ // finally no prefix
94
+ } else if(this.attr(attr)) {
95
+ return this.attr(attr);
96
+ }
97
+ }
98
+
99
+ // none found
100
+ return false;
101
+ };
102
+
103
+ // add an initialisation method
104
+ Gumby.prototype.addInitalisation = function(ref, code) {
105
+ this.inits[ref] = code;
106
+ };
107
+
108
+ // initialize a uiModule
109
+ Gumby.prototype.initialize = function(ref) {
110
+ if(this.inits[ref] && typeof this.inits[ref] === 'function') {
111
+ this.inits[ref]();
112
+ }
113
+ };
114
+
115
+ // store a UI module
116
+ Gumby.prototype.UIModule = function(data) {
117
+ var module = data.module;
118
+ this.uiModules[module] = data;
119
+ };
120
+
121
+ // loop round and init all UI modules
122
+ Gumby.prototype.initUIModules = function() {
123
+ var x;
124
+ for(x in this.uiModules) {
125
+ this.uiModules[x].init();
126
+ }
127
+ };
128
+
129
+ // use touchy events if available otherwise click
130
+ Gumby.prototype.detectClickEvent = function() {
131
+ if(Modernizr.touch) {
132
+ this.setupTapEvent();
133
+ return 'gumbyTap';
134
+ } else {
135
+ return 'click';
136
+ }
137
+ };
138
+
139
+ // set up gumbyTap jQuery.specialEvent
140
+ Gumby.prototype.setupTapEvent = function() {
141
+ $.event.special.gumbyTap = {
142
+ setup: function(data) {
143
+ $(this).bind('touchstart touchend touchmove', $.event.special.gumbyTap.handler);
144
+ },
145
+
146
+ teardown: function() {
147
+ $(this).unbind('touchstart touchend touchmove', $.event.special.gumbyTap.handler);
148
+ },
149
+
150
+ handler: function(event) {
151
+ var $this = $(this);
152
+ // touch start event so store ref to tap event starting
153
+ if(event.type === 'touchstart') {
154
+ $this.data('gumbyTouchStart', true);
155
+ // touchmove event so cancel tap event
156
+ } else if(event.type === 'touchmove') {
157
+ $this.data('gumbyTouchStart', false);
158
+ // touchend event so if tap event ref still present, we have a tap!
159
+ } else if($this.data('gumbyTouchStart')) {
160
+ $this.data('gumbyTouchStart', false);
161
+ event.type = "gumbyTap";
162
+ $this.click(function(e) { e.stopImmediatePropagation(); });
163
+ $.event.handle.apply(this, arguments);
164
+ }
165
+ }
166
+ };
167
+ };
168
+
169
+ window.Gumby = new Gumby();
149
170
 
150
171
  }();
@@ -12,18 +12,7 @@
12
12
 
13
13
  // listen for click event and custom gumby check/uncheck events
14
14
  this.$el.on(Gumby.click, function(e) {
15
- // prevent propagation
16
- e.stopImmediatePropagation();
17
-
18
- // prevent checkbox checking, we'll do that manually
19
- e.preventDefault();
20
-
21
- // check/uncheck
22
- if(scope.$el.hasClass('checked')) {
23
- scope.update(false);
24
- } else {
25
- scope.update(true);
26
- }
15
+ scope.click(e);
27
16
  }).on('gumby.check', function() {
28
17
  scope.update(true);
29
18
  }).on('gumby.uncheck', function() {
@@ -36,24 +25,37 @@
36
25
  }
37
26
  }
38
27
 
39
- // update checkbox, check equals true/false to sepcify check/uncheck
40
- Checkbox.prototype.update = function(check) {
28
+ // handle checkbox click event
29
+ Checkbox.prototype.click = function(e) {
41
30
 
42
- var $input = this.$el.find('input'),
43
- $span = this.$el.find('span');
31
+ // element responsible for event trigger
32
+ var $target = $(e.target);
44
33
 
45
- // check checkbox - check input, add checked class, append <i>
46
- if(check) {
34
+ // prevent propagation
35
+ e.stopPropagation();
47
36
 
48
- $span.append('<i class="icon-check" />');
37
+ // prevent checkbox checking, we'll do that manually
38
+ e.preventDefault();
49
39
 
50
- $input.prop('checked', true).end()
51
- .addClass('checked')
40
+ // check/uncheck
41
+ if(this.$el.hasClass('checked')) {
42
+ this.update(false);
43
+ } else {
44
+ this.update(true);
45
+ }
46
+ };
47
+
48
+ // update checkbox, check equals true/false to sepcify check/uncheck
49
+ Checkbox.prototype.update = function(check) {
50
+ // check checkbox - check input, add checked class, append <i>
51
+ if(check) {
52
+ this.$el.find('input').attr('checked', true).end()
53
+ .addClass('checked').append('<i class="icon-check" />')
52
54
  .trigger('gumby.onCheck').trigger('gumby.onChange');
53
55
 
54
56
  // uncheck checkbox - uncheck input, remove checked class, remove <i>
55
57
  } else {
56
- $input.prop('checked', false).end()
58
+ this.$el.find('input').attr('checked', false).end()
57
59
  .find('i').remove().end()
58
60
  .removeClass('checked').trigger('gumby.onUncheck').trigger('gumby.onChange');
59
61
  }
@@ -7,162 +7,67 @@
7
7
 
8
8
  function Fixed($el) {
9
9
  this.$el = $el;
10
-
11
- this.fixedPoint = '';
12
- this.pinPoint = false;
13
- this.offset = 0;
14
- this.pinOffset = 0;
15
- this.top = 0;
16
- this.constrainEl = true;
17
- this.state = false;
18
- this.measurements = {
19
- left: 0,
20
- width: 0
21
- };
22
-
23
- // set up module based on attributes
24
- this.setup();
25
-
26
- var scope = this;
27
-
28
- // monitor scroll and update fixed elements accordingly
29
- $(window).on('scroll load', function() {
30
- scope.monitorScroll();
31
- });
32
-
33
- // reinitialize event listener
34
- this.$el.on('gumby.initialize', function() {
35
- scope.setup();
36
- });
37
- }
38
-
39
- // set up module based on attributes
40
- Fixed.prototype.setup = function() {
41
- var scope = this;
42
-
43
- this.fixedPoint = this.parseAttrValue(Gumby.selectAttr.apply(this.$el, ['fixed']));
44
-
45
- // pin point is optional
46
- this.pinPoint = Gumby.selectAttr.apply(this.$el, ['pin']) || false;
47
-
48
- // offset from fixed point
49
- this.offset = Number(Gumby.selectAttr.apply(this.$el, ['offset'])) || 0;
50
-
51
- // offset from pin point
52
- this.pinOffset = Number(Gumby.selectAttr.apply(this.$el, ['pinoffset'])) || 0;
53
-
54
- // top position when fixed
55
- this.top = Number(Gumby.selectAttr.apply(this.$el, ['top'])) || 0;
56
-
57
- // constrain can be turned off
58
- this.constrainEl = Gumby.selectAttr.apply(this.$el, ['constrain']) || true;
59
- if(this.constrainEl === 'false') {
60
- this.constrainEl = false;
61
- }
62
-
63
- // reference to the parent, row/column
64
- this.$parent = this.$el.parents('.columns, .column, .row');
65
- this.$parent = this.$parent.length ? this.$parent.first() : false;
66
- this.parentRow = this.$parent ? !!this.$parent.hasClass('row') : false;
67
-
68
- // if optional pin point set then parse now
69
- if(this.pinPoint) {
70
- this.pinPoint = this.parseAttrValue(this.pinPoint);
10
+ this.$holder = Gumby.selectAttr.apply(this.$el, ['holder']);
11
+ this.fixedPoint = Gumby.selectAttr.apply(this.$el, ['fixed']);
12
+ this.unfixPoint = false;
13
+
14
+ // if holder attr set then create jQuery object
15
+ // otherwise use window for scrolling cals
16
+ if(this.$holder) {
17
+ this.$holder = $(this.$holder);
18
+ } else {
19
+ this.$holder = $(window);
71
20
  }
72
21
 
73
- // if we have a parent constrain dimenions
74
- if(this.$parent && this.constrainEl) {
75
- // measure up
76
- this.measure();
77
- // and on resize reset measurement
78
- $(window).resize(function() {
79
- if(scope.state) {
80
- scope.measure();
81
- scope.constrain();
82
- }
83
- });
22
+ // fix/unfix points specified
23
+ if(this.fixedPoint.indexOf('|') > -1) {
24
+ var points = this.fixedPoint.split('|');
25
+ this.fixedPoint = points[0];
26
+ this.unfixPoint = points[1];
84
27
  }
85
- };
86
-
87
- // monitor scroll and trigger changes based on position
88
- Fixed.prototype.monitorScroll = function() {
89
- var scrollAmount = $(window).scrollTop(),
90
- // recalculate selector attributes as position may have changed
91
- fixedPoint = this.fixedPoint instanceof jQuery ? this.fixedPoint.offset().top : this.fixedPoint,
92
- pinPoint = false;
93
28
 
94
- // if a pin point is set recalculate
95
- if(this.pinPoint) {
96
- pinPoint = this.pinPoint instanceof jQuery ? this.pinPoint.offset().top : this.pinPoint;
29
+ // parse possible parameters
30
+ this.fixedPoint = this.parseAttrValue(this.fixedPoint);
31
+ if(this.unfixPoint) {
32
+ this.unfixPoint = this.parseAttrValue(this.unfixPoint);
97
33
  }
98
34
 
99
- // apply offsets
100
- if(this.offset) { fixedPoint -= this.offset; }
101
- if(this.pinOffset) { pinPoint -= this.pinOffset; }
102
-
103
- // fix it
104
- if((scrollAmount >= fixedPoint) && this.state !== 'fixed') {
105
- if(!pinPoint || scrollAmount < pinPoint) {
106
- this.fix();
107
- }
108
- // unfix it
109
- } else if(scrollAmount < fixedPoint && this.state === 'fixed') {
110
- this.unfix();
35
+ var scope = this;
36
+ this.$holder.scroll(function() {
37
+ scope.scroll();
38
+ });
39
+ }
111
40
 
112
- // pin it
113
- } else if(pinPoint && scrollAmount >= pinPoint && this.state !== 'pinned') {
114
- this.pin();
41
+ // handle scroll event on window/specified holder
42
+ Fixed.prototype.scroll = function() {
43
+ var offset = this.$holder.scrollTop(),
44
+ fixedPoint = this.fixedPoint,
45
+ unfixPoint = this.unfixPoint,
46
+ endPoint = this.endPoint;
47
+
48
+ // if fixed point, unfix point or end point are DOM fragements
49
+ // then re-calculate values as could have been updated
50
+ fixedPoint = fixedPoint instanceof jQuery ? this.fixedPoint.offset().top : this.fixedPoint;
51
+ unfixPoint = unfixPoint instanceof jQuery ? this.unfixPoint.offset().top : this.unfixPoint;
52
+
53
+ // ensure unfix point is never reached if not set
54
+ if(!unfixPoint) {
55
+ unfixPoint = offset * 2;
115
56
  }
116
- };
117
57
 
118
- // fix the element and update state
119
- Fixed.prototype.fix = function() {
120
- this.state = 'fixed';
121
- this.$el.css({
122
- 'top' : 0 + this.top
123
- }).addClass('fixed').removeClass('unfixed pinned').trigger('gumby.onFixed');
58
+ // scrolled past fixed point and no fixed class present
59
+ if((offset >= fixedPoint) && (offset < unfixPoint) && !this.$el.hasClass('fixed')) {
60
+ this.$el.addClass('fixed').trigger('gumby.onFixed');
124
61
 
125
- // if we have a parent constrain dimenions
126
- if(this.$parent) {
127
- this.constrain();
62
+ // before fixed point, pass 0 to onUnfixed event
63
+ } else if((offset <= fixedPoint) && this.$el.hasClass('fixed')) {
64
+ this.$el.removeClass('fixed').trigger('gumby.onUnfixed', 0);
128
65
  }
129
- };
130
66
 
131
- // unfix the element and update state
132
- Fixed.prototype.unfix = function() {
133
- this.state = 'unfixed';
134
- this.$el.addClass('unfixed').removeClass('fixed pinned').trigger('gumby.onUnfixed');
135
- };
136
-
137
- // pin the element in position
138
- Fixed.prototype.pin = function() {
139
- this.state = 'pinned';
140
- this.$el.css({
141
- 'top' : this.$el.offset().top
142
- }).addClass('pinned fixed').removeClass('unfixed').trigger('gumby.onPinned');
143
- };
144
-
145
- // constrain elements dimensions to match width/height
146
- Fixed.prototype.constrain = function() {
147
- this.$el.css({
148
- left: this.measurements.left,
149
- width: this.measurements.width
150
- });
151
- };
152
-
153
- // measure up the parent for constraining
154
- Fixed.prototype.measure = function() {
155
- var offsets = this.$parent.offset(), parentPadding;
156
-
157
- this.measurements.left = offsets.left;
158
- this.measurements.width = this.$parent.width();
159
-
160
- // if element has a parent row then need to consider padding
161
- if(this.parentRow) {
162
- parentPadding = Number(this.$parent.css('paddingLeft').replace(/px/, ''));
163
- if(parentPadding) {
164
- this.measurements.left += parentPadding;
165
- }
67
+ // after unfix point, pass 1 to onUnfixed event
68
+ // separate conditional as should override
69
+ if(unfixPoint && (offset >= unfixPoint) && this.$el.hasClass('fixed')) {
70
+ this.$el.removeClass('fixed').trigger('gumby.onUnfixed', 1);
166
71
  }
167
72
  };
168
73
 
@@ -177,7 +82,7 @@
177
82
  // selector specified
178
83
  } else {
179
84
  var $el = $(attr);
180
- return $el;
85
+ return $el.length ? $el : false;
181
86
  }
182
87
  };
183
88
 
@@ -12,14 +12,7 @@
12
12
 
13
13
  // listen for click event and custom gumby check event
14
14
  this.$el.on(Gumby.click, function(e) {
15
- // prevent propagation
16
- e.stopImmediatePropagation();
17
-
18
- // prevent radio button checking, we'll do that manually
19
- e.preventDefault();
20
-
21
- // check radio button
22
- scope.update();
15
+ scope.click(e);
23
16
  }).on('gumby.check', function() {
24
17
  scope.update();
25
18
  });
@@ -30,23 +23,37 @@
30
23
  }
31
24
  }
32
25
 
26
+ // handle radio button click event
27
+ RadioBtn.prototype.click = function(e) {
28
+
29
+ // element responsible for event trigger
30
+ var $target = $(e.target);
31
+
32
+ // prevent propagation
33
+ e.stopPropagation();
34
+
35
+ // prevent radio button checking, we'll do that manually
36
+ e.preventDefault();
37
+
38
+ // check radio button
39
+ this.update();
40
+ };
41
+
33
42
  // check radio button, uncheck all others in name group
34
43
  RadioBtn.prototype.update = function() {
35
44
  var // this specific radio button
36
45
  $input = this.$el.find('input[type=radio]'),
37
- $span = this.$el.find('span'),
38
46
  // the group of radio buttons
39
47
  group = 'input[name="'+$input.attr('name')+'"]';
40
48
 
41
49
  // uncheck radio buttons in same group - uncheck input, remove checked class, remove <i>
42
50
  $('.radio').has(group).removeClass('checked')
43
- .find('input').prop('checked', false).end()
44
- .find('i').remove();
51
+ .find('input').attr('checked', false).end()
52
+ .find('i').remove();
45
53
 
46
54
  // check this radio button - check input, add checked class, append <i>
47
- $input.prop('checked', true);
48
- $span.append('<i class="icon-dot" />');
49
- this.$el.addClass('checked').trigger('gumby.onChange');
55
+ $input.attr('checked', true);
56
+ this.$el.append('<i class="icon-dot" />').addClass('checked').trigger('gumby.onChange');
50
57
  };
51
58
 
52
59
  // add initialisation
@@ -15,7 +15,6 @@
15
15
 
16
16
  // listen for click event on tab nav and custom gumby set event
17
17
  this.$nav.children('a').on(Gumby.click, function(e) {
18
- e.stopImmediatePropagation();
19
18
  e.preventDefault();
20
19
  scope.click($(this));
21
20
  });
@@ -29,39 +29,29 @@
29
29
 
30
30
  // intialise toggles, switches will inherit method
31
31
  Toggle.prototype.init = function() {
32
- var scope = this;
32
+ this.targets = this.parseTargets();
33
+ this.on = Gumby.selectAttr.apply(this.$el, ['on']) || Gumby.click;
33
34
 
34
- // set up module based on attributes
35
- this.setup();
35
+ var scope = this;
36
36
 
37
37
  // bind to specified event and trigger
38
38
  this.$el.on(this.on, function(e) {
39
- // stop propagation
40
- e.stopImmediatePropagation();
41
-
42
39
  // only disable default if <a>
43
40
  if($(this).prop('tagName') === 'A') {
44
41
  e.preventDefault();
45
42
  }
46
43
 
44
+ // stop propagation
45
+ e.stopPropagation();
46
+
47
47
  scope.trigger(scope.triggered);
48
48
 
49
49
  // listen for gumby.trigger to dynamically trigger toggle/switch
50
50
  }).on('gumby.trigger', function() {
51
51
  scope.trigger(scope.triggered);
52
- // re-initialize module
53
- }).on('gumby.initialize', function() {
54
- scope.setup();
55
52
  });
56
53
  };
57
54
 
58
- // set up module based on attributes
59
- Toggle.prototype.setup = function() {
60
- this.targets = this.parseTargets();
61
- this.on = Gumby.selectAttr.apply(this.$el, ['on']) || Gumby.click;
62
- this.className = Gumby.selectAttr.apply(this.$el, ['classname']) || 'active';
63
- };
64
-
65
55
  // parse data-for attribute, switches will inherit method
66
56
  Toggle.prototype.parseTargets = function() {
67
57
  var targetStr = Gumby.selectAttr.apply(this.$el, ['trigger']),
@@ -81,38 +71,49 @@
81
71
  }
82
72
 
83
73
  // return array of both targets, split and return 0, 1
84
- targets = targetStr.split('|');
74
+ var targets = targetStr.split('|');
85
75
  return targets.length > 1 ? [$(targets[0]), $(targets[1])] : [$(targets[0])];
86
76
  };
87
77
 
88
78
  // call triggered event and pass target data
89
79
  Toggle.prototype.triggered = function() {
80
+ var targetLength = this.targets.length,
81
+ // if no targets then use toggle/switch itself
82
+ targetData = !targetLength ? [this.$el.hasClass('active')] : [],
83
+ i;
84
+
85
+ // loop round targets and store boolean indicating if selector is active
86
+ for(i = 0; i < targetLength; i++) {
87
+ targetData.push(this.targets[i].hasClass('active'));
88
+ }
89
+
90
90
  // trigger gumby.onTrigger event and pass array of target status data
91
- this.$el.trigger('gumby.onTrigger', [this.$el.hasClass(this.className)]);
91
+ this.$el.trigger('gumby.onTrigger', targetData);
92
92
  };
93
93
 
94
94
  // Switch object inherits from Toggle
95
95
  Switch.prototype = new Toggle();
96
+ Switch.constructor = Switch;
96
97
 
97
98
  // Toggle specific trigger method
98
99
  Toggle.prototype.trigger = function(cb) {
99
100
  // no targets just toggle active class on toggle
100
101
  if(!this.targets) {
101
- this.$el.toggleClass(this.className);
102
+ this.$el.toggleClass('active');
102
103
 
103
104
  // combine single target with toggle and toggle active class
104
105
  } else if(this.targets.length == 1) {
105
- this.$el.add(this.targets[0]).toggleClass(this.className);
106
+ this.$el.add(this.targets[0]).toggleClass('active');
106
107
 
107
108
  // if two targets check active state of first
108
109
  // always combine toggle and first target
109
110
  } else if(this.targets.length > 1) {
110
- if(this.targets[0].hasClass(this.className)) {
111
- this.$el.add(this.targets[0]).removeClass(this.className);
112
- this.targets[1].addClass(this.className);
111
+ if(this.targets[0].hasClass('active')) {
112
+ this.$el.add(this.targets[0]).removeClass('active');
113
+ this.targets[1].addClass('active');
113
114
  } else {
114
- this.targets[1].removeClass(this.className);
115
- this.$el.add(this.targets[0]).addClass(this.className);
115
+ this.targets[1].removeClass('active');
116
+ this.$el.add(this.targets[0]).addClass('active');
116
117
  }
117
118
  }
118
119
 
@@ -126,17 +127,17 @@
126
127
  Switch.prototype.trigger = function(cb) {
127
128
  // no targets just add active class to switch
128
129
  if(!this.targets) {
129
- this.$el.addClass(this.className);
130
+ this.$el.addClass('active');
130
131
 
131
132
  // combine single target with switch and add active class
132
133
  } else if(this.targets.length == 1) {
133
- this.$el.add(this.targets[0]).addClass(this.className);
134
+ this.$el.add(this.targets[0]).addClass('active');
134
135
 
135
136
  // if two targets check active state of first
136
137
  // always combine switch and first target
137
138
  } else if(this.targets.length > 1) {
138
- this.$el.add(this.targets[0]).addClass(this.className);
139
- this.targets[1].removeClass(this.className);
139
+ this.$el.add(this.targets[0]).addClass('active');
140
+ this.targets[1].removeClass('active');
140
141
  }
141
142
 
142
143
  // call event handler here, applying scope of object Switch/Toggle
@@ -146,21 +147,13 @@
146
147
  };
147
148
 
148
149
  // add toggle initialisation
149
- Gumby.addInitalisation('toggles', function(all) {
150
+ Gumby.addInitalisation('toggles', function() {
150
151
  $('.toggle').each(function() {
151
152
  var $this = $(this);
152
-
153
153
  // this element has already been initialized
154
- // and we're only initializing new modules
155
- if($this.data('isToggle') && !all) {
154
+ if($this.data('isToggle')) {
156
155
  return true;
157
-
158
- // this element has already been initialized
159
- // and we need to reinitialize it
160
- } else if($this.data('isToggle') && all) {
161
- $this.trigger('gumby.initialize');
162
156
  }
163
-
164
157
  // mark element as initialized
165
158
  $this.data('isToggle', true);
166
159
  new Toggle($this);
@@ -168,22 +161,13 @@
168
161
  });
169
162
 
170
163
  // add switches initialisation
171
- Gumby.addInitalisation('switches', function(all) {
164
+ Gumby.addInitalisation('switches', function() {
172
165
  $('.switch').each(function() {
173
166
  var $this = $(this);
174
-
175
167
  // this element has already been initialized
176
- // and we're only initializing new modules
177
- if($this.data('isSwitch') && !all) {
178
- return true;
179
-
180
- // this element has already been initialized
181
- // and we need to reinitialize it
182
- } else if($this.data('isSwitch') && all) {
183
- $this.trigger('gumby.initialize');
168
+ if($this.data('isSwitch')) {
184
169
  return true;
185
170
  }
186
-
187
171
  // mark element as initialized
188
172
  $this.data('isSwitch', true);
189
173
  new Switch($this);
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gumby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -58,17 +58,13 @@ files:
58
58
  - gumby.gemspec
59
59
  - lib/gumby.rb
60
60
  - lib/gumby/version.rb
61
+ - vendor/assets/fonts/humans.txt
61
62
  - vendor/assets/fonts/icons/entypo.eot
62
63
  - vendor/assets/fonts/icons/entypo.ttf
63
64
  - vendor/assets/fonts/icons/entypo.woff
64
- - vendor/assets/javascripts/.DS_Store
65
- - vendor/assets/javascripts/gumby.init.js
66
65
  - vendor/assets/javascripts/gumby.js
67
- - vendor/assets/javascripts/gumby.min.js
68
66
  - vendor/assets/javascripts/ui/gumby.checkbox.js
69
- - vendor/assets/javascripts/ui/gumby.fittext.js
70
67
  - vendor/assets/javascripts/ui/gumby.fixed.js
71
- - vendor/assets/javascripts/ui/gumby.navbar.js
72
68
  - vendor/assets/javascripts/ui/gumby.radiobtn.js
73
69
  - vendor/assets/javascripts/ui/gumby.retina.js
74
70
  - vendor/assets/javascripts/ui/gumby.skiplink.js
@@ -1,27 +0,0 @@
1
- /**
2
- * Gumby Init
3
- */
4
-
5
- // test for touch event support
6
- Modernizr.load({
7
- test: Modernizr.touch,
8
-
9
- // if present load custom jQuery mobile build and update Gumby.click
10
- yep: Gumby.path+'/jquery.mobile.custom.min.js',
11
- callback: function(url, result, key) {
12
- // check jQuery mobile has successfully loaded before using tap events
13
- if($.mobile) {
14
- window.Gumby.click += ' tap';
15
- }
16
- },
17
-
18
- // either way initialize Gumby
19
- complete: function() {
20
- window.Gumby.init();
21
-
22
- // if AMD return Gumby object to define
23
- if(typeof define == "function" && define.amd) {
24
- define(window.Gumby);
25
- }
26
- }
27
- });
@@ -1 +0,0 @@
1
- !function(){"use strict";function t(){this.$dom=$(document),this.isOldie=!!this.$dom.find("html").hasClass("oldie"),this.click="click",this.onReady=this.onOldie=this.onTouch=!1,this.uiModules={},this.inits={},this.path=$("script[gumby-path]").attr("gumby-path")||"js/libs",this.breakpoint=Number($("script[gumby-breakpoint]").attr("gumby-breakpoint"))||1024}t.prototype.init=function(){var t=this;this.$dom.ready(function(){t.initUIModules(),t.onReady&&t.onReady(),t.isOldie&&t.onOldie&&t.onOldie(),Modernizr.touch&&t.onTouch&&t.onTouch()})},t.prototype.ready=function(t){t&&"function"==typeof t&&(this.onReady=t)},t.prototype.oldie=function(t){t&&"function"==typeof t&&(this.onOldie=t)},t.prototype.touch=function(t){t&&"function"==typeof t&&(this.onTouch=t)},t.prototype.debug=function(){return{$dom:this.$dom,isOldie:this.isOldie,uiModules:this.uiModules,click:this.click}},t.prototype.selectAttr=function(){for(var t=0;t<arguments.length;t++){var i=arguments[t],e="data-"+arguments[t],s="gumby-"+arguments[t];if(this.is("["+e+"]"))return this.attr(e)?this.attr(e):!0;if(this.is("["+s+"]"))return this.attr(s)?this.attr(s):!0;if(this.is("["+i+"]"))return this.attr(i)?this.attr(i):!0}return!1},t.prototype.addInitalisation=function(t,i){this.inits[t]=i},t.prototype.initialize=function(t,i){this.inits[t]&&"function"==typeof this.inits[t]&&this.inits[t](i)},t.prototype.UIModule=function(t){var i=t.module;this.uiModules[i]=t},t.prototype.initUIModules=function(){var t;for(t in this.uiModules)this.uiModules[t].init()},window.Gumby=new t}(),!function(){"use strict";function t(t){this.$el=t;var i=this;this.$el.on(Gumby.click,function(t){t.stopImmediatePropagation(),t.preventDefault(),i.$el.hasClass("checked")?i.update(!1):i.update(!0)}).on("gumby.check",function(){i.update(!0)}).on("gumby.uncheck",function(){i.update(!1)}),i.$el.hasClass("checked")&&i.update(!0)}t.prototype.update=function(t){var i=this.$el.find("input"),e=this.$el.find("span");t?(e.append('<i class="icon-check" />'),i.prop("checked",!0).end().addClass("checked").trigger("gumby.onCheck").trigger("gumby.onChange")):i.prop("checked",!1).end().find("i").remove().end().removeClass("checked").trigger("gumby.onUncheck").trigger("gumby.onChange")},Gumby.addInitalisation("checkboxes",function(){$(".checkbox").each(function(){var i=$(this);return i.data("isCheckbox")?!0:(i.data("isCheckbox",!0),new t(i),void 0)})}),Gumby.UIModule({module:"checkbox",events:["onCheck","onUncheck","onChange","check","uncheck"],init:function(){Gumby.initialize("checkboxes")}})}(),!function(){"use strict";function t(t){this.$el=t,this.rate=0,this.fontSizes={},this.setup();var i=this;this.$el.on("gumby.initialize",function(){i.setup()}),$(window).on("load resize orientationchange",function(){i.resize()})}t.prototype.setup=function(){this.rate=Number(Gumby.selectAttr.apply(this.$el,["rate"]))||1,this.fontSizes=this.parseSizes(Gumby.selectAttr.apply(this.$el,["sizes"]))},t.prototype.resize=function(){this.$el.css("font-size",this.calculateSize())},t.prototype.calculateSize=function(){return Math.max(Math.min(this.$el.width()/(10*this.rate),parseFloat(this.fontSizes.max)),parseFloat(this.fontSizes.min))},t.prototype.parseSizes=function(t){var i={min:Number.NEGATIVE_INFINITY,max:Number.POSITIVE_INFINITY};return t?(t.indexOf("|")>-1&&(t=t.split("|"),i.min=Number(t[0])||i.min,i.max=Number(t[1])||i.max),i.min=Number(t)||i.min,i):i},Gumby.addInitalisation("fittext",function(i){$(".fittext").each(function(){var e=$(this);return e.data("isFittext")&&!i?!0:e.data("isFittext")&&i?(e.trigger("gumby.initialize"),!0):(e.data("isFittext",!0),new t(e),void 0)})}),Gumby.UIModule({module:"fittext",events:[],init:function(){Gumby.initialize("fittext")}})}(),!function(){"use strict";function t(t){this.$el=t,this.fixedPoint="",this.pinPoint=!1,this.offset=0,this.pinOffset=0,this.top=0,this.constrainEl=!0,this.state=!1,this.measurements={left:0,width:0},this.setup();var i=this;$(window).on("scroll load",function(){i.monitorScroll()}),this.$el.on("gumby.initialize",function(){i.setup()})}t.prototype.setup=function(){var t=this;this.fixedPoint=this.parseAttrValue(Gumby.selectAttr.apply(this.$el,["fixed"])),this.pinPoint=Gumby.selectAttr.apply(this.$el,["pin"])||!1,this.offset=Number(Gumby.selectAttr.apply(this.$el,["offset"]))||0,this.pinOffset=Number(Gumby.selectAttr.apply(this.$el,["pinoffset"]))||0,this.top=Number(Gumby.selectAttr.apply(this.$el,["top"]))||0,this.constrainEl=Gumby.selectAttr.apply(this.$el,["constrain"])||!0,"false"===this.constrainEl&&(this.constrainEl=!1),this.$parent=this.$el.parents(".columns, .column, .row"),this.$parent=this.$parent.length?this.$parent.first():!1,this.parentRow=this.$parent?!!this.$parent.hasClass("row"):!1,this.pinPoint&&(this.pinPoint=this.parseAttrValue(this.pinPoint)),this.$parent&&this.constrainEl&&(this.measure(),$(window).resize(function(){t.state&&(t.measure(),t.constrain())}))},t.prototype.monitorScroll=function(){var t=$(window).scrollTop(),i=this.fixedPoint instanceof jQuery?this.fixedPoint.offset().top:this.fixedPoint,e=!1;this.pinPoint&&(e=this.pinPoint instanceof jQuery?this.pinPoint.offset().top:this.pinPoint),this.offset&&(i-=this.offset),this.pinOffset&&(e-=this.pinOffset),t>=i&&"fixed"!==this.state?(!e||e>t)&&this.fix():i>t&&"fixed"===this.state?this.unfix():e&&t>=e&&"pinned"!==this.state&&this.pin()},t.prototype.fix=function(){this.state="fixed",this.$el.css({top:0+this.top}).addClass("fixed").removeClass("unfixed pinned").trigger("gumby.onFixed"),this.$parent&&this.constrain()},t.prototype.unfix=function(){this.state="unfixed",this.$el.addClass("unfixed").removeClass("fixed pinned").trigger("gumby.onUnfixed")},t.prototype.pin=function(){this.state="pinned",this.$el.css({top:this.$el.offset().top}).addClass("pinned fixed").removeClass("unfixed").trigger("gumby.onPinned")},t.prototype.constrain=function(){this.$el.css({left:this.measurements.left,width:this.measurements.width})},t.prototype.measure=function(){var t,i=this.$parent.offset();this.measurements.left=i.left,this.measurements.width=this.$parent.width(),this.parentRow&&(t=Number(this.$parent.css("paddingLeft").replace(/px/,"")),t&&(this.measurements.left+=t))},t.prototype.parseAttrValue=function(t){if($.isNumeric(t))return Number(t);if("top"===t)return this.$el.offset().top;var i=$(t);return i},Gumby.addInitalisation("fixed",function(){$("[data-fixed],[gumby-fixed],[fixed]").each(function(){var i=$(this);return i.data("isFixed")?!0:(i.data("isFixed",!0),new t(i),void 0)})}),Gumby.UIModule({module:"fixed",events:["onFixed","onUnfixed"],init:function(){Gumby.initialize("fixed")}})}(),!function(){"use strict";function t(t){this.$el=t,this.$dropDowns=this.$el.find("li:has(.dropdown)");var i=this;this.$dropDowns.on("tap",this.toggleDropdown).on("swiperight",this.openLink),"#"!==this.$dropDowns.children("a").attr("href")&&this.$dropDowns.children("a").append('<i class="icon-popup"></i>').children("i").on("tap",this.openLink),$(window).on("mousemove touchstart",function(t){t.stopImmediatePropagation(),"mousemove"===t.type&&i.$dropDowns.on("mouseover mouseout",i.toggleDropdown)})}var i=Gumby.$dom.find("html");return!Modernizr.touch||$(window).width()>Gumby.breakpoint?(i.addClass("gumby-no-touch"),void 0):(i.addClass("gumby-touch"),t.prototype.toggleDropdown=function(t){t.stopImmediatePropagation(),t.preventDefault();var i=$(this);i.hasClass("active")?i.removeClass("active"):i.addClass("active")},t.prototype.openLink=function(t){t.stopImmediatePropagation(),t.preventDefault();var i,e,s=$(this);s.is("i")?i=s.parent("a"):s.is("li")&&(i=s.children("a")),e=i.attr("href"),"blank"==i.attr("target")?window.open(e):window.location=e},Gumby.addInitalisation("navbars",function(){$(".navbar").each(function(){var i=$(this);return i.data("isNavbar")?!0:(i.data("isNavbar",!0),new t(i),void 0)})}),Gumby.UIModule({module:"navbar",events:[],init:function(){Gumby.initialize("navbars")}}),void 0)}(),!function(){"use strict";function t(t){this.$el=t;var i=this;this.$el.on(Gumby.click,function(t){t.stopImmediatePropagation(),t.preventDefault(),i.update()}).on("gumby.check",function(){i.update()}),i.$el.hasClass("checked")&&i.update()}t.prototype.update=function(){var t=this.$el.find("input[type=radio]"),i=this.$el.find("span"),e='input[name="'+t.attr("name")+'"]';$(".radio").has(e).removeClass("checked").find("input").prop("checked",!1).end().find("i").remove(),t.prop("checked",!0),i.append('<i class="icon-dot" />'),this.$el.addClass("checked").trigger("gumby.onChange")},Gumby.addInitalisation("radiobtns",function(){$(".radio").each(function(){var i=$(this);return i.data("isRadioBtn")?!0:(i.data("isRadioBtn",!0),new t(i),void 0)})}),Gumby.UIModule({module:"radiobtn",events:["onChange","check"],init:function(){Gumby.initialize("radiobtns")}})}(),!function(){"use strict";function t(t){this.$el=t,this.imageSrc=this.$el.attr("src"),this.retinaSrc=this.fetchRetinaImage(),this.$retinaImg=$(new Image);var i=this;return this.retinaSrc?(this.$retinaImg.attr("src",this.retinaSrc).load(function(){i.retinaImageLoaded()}),void 0):!1}t.prototype.fetchRetinaImage=function(){var t=this.imageSrc,i=this.imageSrc.search(/(\.|\/)(gif|jpe?g|png)$/i);return 0>i?!1:t.substr(0,i)+"@2x"+t.substr(i,t.length)},t.prototype.retinaImageLoaded=function(){this.$el.attr("src",this.$retinaImg.attr("src")).trigger("gumby.onRetina")},Gumby.addInitalisation("retina",function(){!window.devicePixelRatio||window.devicePixelRatio<=1||$("img[data-retina],img[gumby-retina],img[retina]").each(function(){var i=$(this);return i.data("isRetina")?!0:(i.data("isRetina",!0),new t(i),void 0)})}),Gumby.UIModule({module:"retina",events:["onRetina"],init:function(){Gumby.initialize("retina")}})}(),!function(){"use strict";function t(t){this.$el=t,this.targetPos=0,this.duration=0,this.offset=!1,this.easing="",this.update=!1,this.setup();var i=this;this.$el.on(Gumby.click+" gumby.skip",function(t){t.stopImmediatePropagation(),t.preventDefault(),i.update?i.calculateTarget(i.skipTo):i.skipTo()}).on("gumby.initialize",function(){i.setup()})}t.prototype.setup=function(){this.duration=Number(Gumby.selectAttr.apply(this.$el,["duration"]))||200,this.offset=Gumby.selectAttr.apply(this.$el,["offset"])||!1,this.easing=Gumby.selectAttr.apply(this.$el,["easing"])||"swing",this.update=Gumby.selectAttr.apply(this.$el,["update"])?!0:!1,this.calculateTarget()},t.prototype.calculateTarget=function(t){var i,e=Gumby.selectAttr.apply(this.$el,["goto"]);if("top"==e)this.targetPos=0;else if($.isNumeric(e))this.targetPos=Number(e);else{if(i=$(e),!i)return!1;this.targetPos=i.offset().top}t&&t.apply(this)},t.prototype.skipTo=function(){var t=this;$("html,body").animate({scrollTop:this.calculateOffset()},this.duration,this.easing).promise().done(function(){t.$el.trigger("gumby.onComplete")})},t.prototype.calculateOffset=function(){if(!this.offset)return this.targetPos;var t=this.offset.substr(0,1),i=Number(this.offset.substr(1,this.offset.length));return"-"===t?this.targetPos-i:"+"===t?this.targetPos+i:void 0},Gumby.addInitalisation("skiplinks",function(i){$(".skiplink > a, .skip").each(function(){var e=$(this);return e.data("isSkipLink")&&!i?!0:e.data("isSkipLink")&&i?(e.trigger("gumby.initialize"),!0):(e.data("isSkipLink",!0),new t(e),void 0)})}),Gumby.UIModule({module:"skiplink",events:["onComplete","skip"],init:function(){Gumby.initialize("skiplinks")}})}(),!function(){"use strict";function t(t){this.$el=t,this.$nav=this.$el.find("ul.tab-nav > li"),this.$content=this.$el.find(".tab-content");var i=this;this.$nav.children("a").on(Gumby.click,function(t){t.stopImmediatePropagation(),t.preventDefault(),i.click($(this))}),this.$el.on("gumby.set",function(t,e){i.set(t,e)})}t.prototype.click=function(t){var i=t.parent().index();this.$nav.add(this.$content).removeClass("active"),this.$nav.eq(i).add(this.$content.eq(i)).addClass("active"),this.$el.trigger("gumby.onChange",i)},t.prototype.set=function(t,i){this.$nav.eq(i).find("a").trigger(Gumby.click)},Gumby.addInitalisation("tabs",function(){$(".tabs").each(function(){var i=$(this);return i.data("isTabs")?!0:(i.data("isTabs",!0),new t(i),void 0)})}),Gumby.UIModule({module:"tabs",events:["onChange","set"],init:function(){Gumby.initialize("tabs")}})}(),!function(){"use strict";function t(t){this.$el=$(t),this.targets=[],this.on="",this.$el.length&&this.init()}function i(t){this.$el=$(t),this.targets=[],this.on="",this.$el.length&&this.init()}t.prototype.init=function(){var t=this;this.setup(),this.$el.on(this.on,function(i){i.stopImmediatePropagation(),"A"===$(this).prop("tagName")&&i.preventDefault(),t.trigger(t.triggered)}).on("gumby.trigger",function(){t.trigger(t.triggered)}).on("gumby.initialize",function(){t.setup()})},t.prototype.setup=function(){this.targets=this.parseTargets(),this.on=Gumby.selectAttr.apply(this.$el,["on"])||Gumby.click,this.className=Gumby.selectAttr.apply(this.$el,["classname"])||"active"},t.prototype.parseTargets=function(){var t=Gumby.selectAttr.apply(this.$el,["trigger"]),i=0,e=[];return t?(i=t.indexOf("|"),-1===i?[$(t)]:(e=t.split("|"),e.length>1?[$(e[0]),$(e[1])]:[$(e[0])])):!1},t.prototype.triggered=function(){this.$el.trigger("gumby.onTrigger",[this.$el.hasClass(this.className)])},i.prototype=new t,t.prototype.trigger=function(t){this.targets?1==this.targets.length?this.$el.add(this.targets[0]).toggleClass(this.className):this.targets.length>1&&(this.targets[0].hasClass(this.className)?(this.$el.add(this.targets[0]).removeClass(this.className),this.targets[1].addClass(this.className)):(this.targets[1].removeClass(this.className),this.$el.add(this.targets[0]).addClass(this.className))):this.$el.toggleClass(this.className),t&&"function"==typeof t&&t.apply(this)},i.prototype.trigger=function(t){this.targets?1==this.targets.length?this.$el.add(this.targets[0]).addClass(this.className):this.targets.length>1&&(this.$el.add(this.targets[0]).addClass(this.className),this.targets[1].removeClass(this.className)):this.$el.addClass(this.className),t&&"function"==typeof t&&t.apply(this)},Gumby.addInitalisation("toggles",function(i){$(".toggle").each(function(){var e=$(this);return e.data("isToggle")&&!i?!0:(e.data("isToggle")&&i&&e.trigger("gumby.initialize"),e.data("isToggle",!0),new t(e),void 0)})}),Gumby.addInitalisation("switches",function(t){$(".switch").each(function(){var e=$(this);return e.data("isSwitch")&&!t?!0:e.data("isSwitch")&&t?(e.trigger("gumby.initialize"),!0):(e.data("isSwitch",!0),new i(e),void 0)})}),Gumby.UIModule({module:"toggleswitch",events:["trigger","onTrigger"],init:function(){Gumby.initialize("switches"),Gumby.initialize("toggles")}})}(),!function(t){"use strict";function i(t,i){this.$this=t,this.$field=this.$this.parents(".field"),this.req=i||function(){return!!this.$this.val().length};var e=this;this.$this.is("[type=checkbox], [type=radio]")?(this.$field=this.$this.parent("label"),this.$field.on("gumby.onChange",function(){e.validate()})):this.$this.is("select")?(this.$field=this.$this.parents(".picker"),this.$field.on("change",function(){e.validate()})):this.$this.on("blur",function(t){9!==t.which&&e.validate()})}i.prototype.validate=function(){var t=this.req(this.$this);return t?this.$field.removeClass("danger").addClass("success"):this.$field.removeClass("success").addClass("danger"),t},t.fn.validation=function(e){var s=t.extend({submit:!1,fail:!1,required:[]},e),n=[];return this.each(function(){if(!s.required.length)return!1;var e,a=t(this),o=s.required.length;for(e=0;o>e;e++)n.push(new i(a.find('[name="'+s.required[e].name+'"]'),s.required[e].validate||!1));a.on("submit",function(t){var i=!1;if(!a.data("passed")){t.preventDefault();var e,o=n.length;for(e=0;o>e;e++)n[e].validate()||(i=!0);if(i){if(s.fail&&"function"==typeof s.fail)return s.fail(),void 0}else{if(s.submit&&"function"==typeof s.submit)return s.submit(a.serializeArray()),void 0;a.data("passed",!0).submit()}}})})}}(jQuery),Modernizr.load({test:Modernizr.touch,yep:Gumby.path+"/jquery.mobile.custom.min.js",callback:function(){$.mobile&&(window.Gumby.click+=" tap")},complete:function(){window.Gumby.init(),"function"==typeof define&&define.amd&&define(window.Gumby)}});
@@ -1,107 +0,0 @@
1
- /**
2
- * Gumby FitText
3
- *
4
- * Adapted from the awesome FitText jQuery plugin
5
- * brought to you by Paravel - http://paravelinc.com/
6
- */
7
- !function() {
8
-
9
- 'use strict';
10
-
11
- function FitText($el) {
12
- this.$el = $el;
13
-
14
- this.rate = 0;
15
- this.fontSizes = {};
16
-
17
- // set up module based on attributes
18
- this.setup();
19
-
20
- var scope = this;
21
-
22
- // re-initialize module
23
- this.$el.on('gumby.initialize', function() {
24
- scope.setup();
25
- });
26
-
27
- // lets go
28
- $(window).on('load resize orientationchange', function() {
29
- scope.resize();
30
- });
31
- }
32
-
33
- // set up module based on attributes
34
- FitText.prototype.setup = function() {
35
- // optional compressor rate
36
- this.rate = Number(Gumby.selectAttr.apply(this.$el, ['rate'])) || 1;
37
- // optional font sizes (min|max)
38
- this.fontSizes = this.parseSizes(Gumby.selectAttr.apply(this.$el, ['sizes']));
39
- };
40
-
41
- // apply the resizing
42
- FitText.prototype.resize = function() {
43
- this.$el.css('font-size', this.calculateSize());
44
- };
45
-
46
- // calculate the font size
47
- FitText.prototype.calculateSize = function() {
48
- return Math.max(Math.min(this.$el.width() / (this.rate*10), parseFloat(this.fontSizes.max)), parseFloat(this.fontSizes.min));
49
- };
50
-
51
- // parse size attributes with min|max syntax
52
- FitText.prototype.parseSizes = function(attrStr) {
53
- var sizes = {
54
- min: Number.NEGATIVE_INFINITY,
55
- max: Number.POSITIVE_INFINITY
56
- };
57
-
58
- // attribute is optional
59
- if(!attrStr) { return sizes; }
60
-
61
- // min and/or max specified
62
- if(attrStr.indexOf('|') > -1) {
63
- attrStr = attrStr.split('|');
64
-
65
- // both are optional
66
- sizes.min = Number(attrStr[0]) || sizes.min;
67
- sizes.max = Number(attrStr[1]) || sizes.max;
68
- }
69
-
70
- // only one value specific without | so use as min
71
- sizes.min = Number(attrStr) || sizes.min;
72
-
73
- return sizes;
74
- };
75
-
76
- // add initialisation
77
- Gumby.addInitalisation('fittext', function(all) {
78
- $('.fittext').each(function() {
79
- var $this = $(this);
80
-
81
- // this element has already been initialized
82
- // and we're only initializing new modules
83
- if($this.data('isFittext') && !all) {
84
- return true;
85
-
86
- // this element has already been initialized
87
- // and we need to reinitialize it
88
- } else if($this.data('isFittext') && all) {
89
- $this.trigger('gumby.initialize');
90
- return true;
91
- }
92
-
93
- // mark element as initialized
94
- $this.data('isFittext', true);
95
- new FitText($this);
96
- });
97
- });
98
-
99
- // register UI module
100
- Gumby.UIModule({
101
- module: 'fittext',
102
- events: [],
103
- init: function() {
104
- Gumby.initialize('fittext');
105
- }
106
- });
107
- }();
@@ -1,115 +0,0 @@
1
- /**
2
- * Gumby Navbar
3
- */
4
- !function() {
5
-
6
- 'use strict';
7
-
8
- var $html = Gumby.$dom.find('html');
9
-
10
- // define and init module on touch enabled devices only
11
- // when we are at tablet size or smaller
12
- if(!Modernizr.touch || $(window).width() > Gumby.breakpoint) {
13
-
14
- // add Gumby no touch class
15
- $html.addClass('gumby-no-touch');
16
- return;
17
- }
18
-
19
- // add Gumby touch class
20
- $html.addClass('gumby-touch');
21
-
22
- function Navbar($el) {
23
- this.$el = $el;
24
- this.$dropDowns = this.$el.find('li:has(.dropdown)');
25
- var scope = this;
26
-
27
- // when navbar items
28
- this.$dropDowns
29
- // are tapped hide/show dropdowns
30
- .on('tap', this.toggleDropdown)
31
- // are swiped right open link
32
- .on('swiperight', this.openLink);
33
-
34
- // if there's a link set
35
- if(this.$dropDowns.children('a').attr('href') !== '#') {
36
- // append an icon
37
- this.$dropDowns.children('a').append('<i class="icon-popup"></i>').children('i')
38
- // and bind to click event to open link
39
- .on('tap', this.openLink);
40
- }
41
-
42
- // on mousemove and touchstart toggle modernizr classes and disable/enable this module
43
- // workaround for Pixel and other multi input devices
44
- $(window).on('mousemove touchstart', function(e) {
45
- e.stopImmediatePropagation();
46
- if(e.type === 'mousemove') {
47
- scope.$dropDowns.on('mouseover mouseout', scope.toggleDropdown);
48
- }
49
- });
50
- }
51
-
52
- Navbar.prototype.toggleDropdown = function(e) {
53
- // prevent click from triggering here too
54
- e.stopImmediatePropagation();
55
- e.preventDefault();
56
-
57
- var $this = $(this);
58
-
59
- if($this.hasClass('active')) {
60
- $this.removeClass('active');
61
- } else {
62
- $this.addClass('active');
63
- }
64
- };
65
-
66
- // handle opening list item link
67
- Navbar.prototype.openLink = function(e) {
68
- e.stopImmediatePropagation();
69
- e.preventDefault();
70
-
71
- var $this = $(this),
72
- $el, href;
73
-
74
- // tapped icon
75
- if($this.is('i')) {
76
- $el = $this.parent('a');
77
- // swiped li
78
- } else if($this.is('li')) {
79
- $el = $this.children('a');
80
- }
81
-
82
- href = $el.attr('href');
83
-
84
- // open in new window
85
- if($el.attr('target') == 'blank') {
86
- window.open(href);
87
- // regular relocation
88
- } else {
89
- window.location = href;
90
- }
91
- };
92
-
93
- // add initialisation
94
- Gumby.addInitalisation('navbars', function() {
95
- $('.navbar').each(function() {
96
- var $this = $(this);
97
- // this element has already been initialized
98
- if($this.data('isNavbar')) {
99
- return true;
100
- }
101
- // mark element as initialized
102
- $this.data('isNavbar', true);
103
- new Navbar($this);
104
- });
105
- });
106
-
107
- // register UI module
108
- Gumby.UIModule({
109
- module: 'navbar',
110
- events: [],
111
- init: function() {
112
- Gumby.initialize('navbars');
113
- }
114
- });
115
- }();