gumby_on_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +34 -0
  4. data/app/assets/javascripts/gumby/libs/extensions/gumby.comments.js +152 -0
  5. data/app/assets/javascripts/gumby/libs/extensions/gumby.fittext.js +126 -0
  6. data/app/assets/javascripts/gumby/libs/extensions/gumby.images.js +202 -0
  7. data/app/assets/javascripts/gumby/libs/extensions/gumby.inview.js +219 -0
  8. data/app/assets/javascripts/gumby/libs/extensions/gumby.parallax.js +106 -0
  9. data/app/assets/javascripts/gumby/libs/extensions/gumby.shuffle.js +198 -0
  10. data/app/assets/javascripts/gumby/libs/gumby.init.js +47 -0
  11. data/app/assets/javascripts/gumby/libs/gumby.js +258 -0
  12. data/app/assets/javascripts/gumby/libs/gumby.min.js +1 -0
  13. data/app/assets/javascripts/gumby/libs/jquery-1.10.1.min.js +6 -0
  14. data/app/assets/javascripts/gumby/libs/jquery-1.10.1.min.map +1 -0
  15. data/app/assets/javascripts/gumby/libs/jquery-2.0.2.min.js +6 -0
  16. data/app/assets/javascripts/gumby/libs/jquery-2.0.2.min.map +1 -0
  17. data/app/assets/javascripts/gumby/libs/jquery.mobile.custom.min.js +3 -0
  18. data/app/assets/javascripts/gumby/libs/modernizr-2.6.2.min.js +4 -0
  19. data/app/assets/javascripts/gumby/libs/ui/gumby.checkbox.js +101 -0
  20. data/app/assets/javascripts/gumby/libs/ui/gumby.fixed.js +240 -0
  21. data/app/assets/javascripts/gumby/libs/ui/gumby.navbar.js +115 -0
  22. data/app/assets/javascripts/gumby/libs/ui/gumby.radiobtn.js +90 -0
  23. data/app/assets/javascripts/gumby/libs/ui/gumby.retina.js +81 -0
  24. data/app/assets/javascripts/gumby/libs/ui/gumby.skiplink.js +157 -0
  25. data/app/assets/javascripts/gumby/libs/ui/gumby.tabs.js +80 -0
  26. data/app/assets/javascripts/gumby/libs/ui/gumby.toggleswitch.js +264 -0
  27. data/app/assets/javascripts/gumby/libs/ui/jquery.validation.js +142 -0
  28. data/app/assets/javascripts/gumby/main.js +23 -0
  29. data/app/assets/javascripts/gumby/plugins.js +4 -0
  30. data/app/assets/javascripts/gumby.all.js +19 -0
  31. data/app/assets/javascripts/gumby.js +13 -0
  32. data/app/assets/stylesheets/gumby/_base.scss +49 -0
  33. data/app/assets/stylesheets/gumby/_custom.scss +1 -0
  34. data/app/assets/stylesheets/gumby/_fonts.scss +28 -0
  35. data/app/assets/stylesheets/gumby/_grid.scss +339 -0
  36. data/app/assets/stylesheets/gumby/_parallax.scss +11 -0
  37. data/app/assets/stylesheets/gumby/_shame.scss +36 -0
  38. data/app/assets/stylesheets/gumby/_typography.scss +272 -0
  39. data/app/assets/stylesheets/gumby/extensions/modular-scale/lib/modular-scale.rb +128 -0
  40. data/app/assets/stylesheets/gumby/extensions/modular-scale/stylesheets/_modular-scale.scss +310 -0
  41. data/app/assets/stylesheets/gumby/extensions/sassy-math/lib/sassy-math.rb +159 -0
  42. data/app/assets/stylesheets/gumby/extensions/sassy-math/stylesheets/_math.scss +310 -0
  43. data/app/assets/stylesheets/gumby/functions/_all.scss +25 -0
  44. data/app/assets/stylesheets/gumby/functions/_breakpoints.scss +11 -0
  45. data/app/assets/stylesheets/gumby/functions/_button-size.scss +44 -0
  46. data/app/assets/stylesheets/gumby/functions/_clearfix.scss +25 -0
  47. data/app/assets/stylesheets/gumby/functions/_em.scss +11 -0
  48. data/app/assets/stylesheets/gumby/functions/_even.scss +10 -0
  49. data/app/assets/stylesheets/gumby/functions/_fade.scss +20 -0
  50. data/app/assets/stylesheets/gumby/functions/_fancytiles.scss +29 -0
  51. data/app/assets/stylesheets/gumby/functions/_fixed.scss +21 -0
  52. data/app/assets/stylesheets/gumby/functions/_forms.scss +18 -0
  53. data/app/assets/stylesheets/gumby/functions/_grid-calc.scss +82 -0
  54. data/app/assets/stylesheets/gumby/functions/_height-calc.scss +6 -0
  55. data/app/assets/stylesheets/gumby/functions/_icons.scss +35 -0
  56. data/app/assets/stylesheets/gumby/functions/_line-and-height.scss +7 -0
  57. data/app/assets/stylesheets/gumby/functions/_palette.scss +76 -0
  58. data/app/assets/stylesheets/gumby/functions/_responsivity.scss +34 -0
  59. data/app/assets/stylesheets/gumby/functions/_semantic-grid.scss +170 -0
  60. data/app/assets/stylesheets/gumby/functions/_shapes.scss +22 -0
  61. data/app/assets/stylesheets/gumby/functions/_strip-units.scss +5 -0
  62. data/app/assets/stylesheets/gumby/functions/_tooltips.scss +98 -0
  63. data/app/assets/stylesheets/gumby/functions/_typography.scss +15 -0
  64. data/app/assets/stylesheets/gumby/functions/_visibility.scss +17 -0
  65. data/app/assets/stylesheets/gumby/gumby.scss +39 -0
  66. data/app/assets/stylesheets/gumby/ui/_all.scss +11 -0
  67. data/app/assets/stylesheets/gumby/ui/_buttons.scss +154 -0
  68. data/app/assets/stylesheets/gumby/ui/_forms.scss +392 -0
  69. data/app/assets/stylesheets/gumby/ui/_icons.scss +23 -0
  70. data/app/assets/stylesheets/gumby/ui/_images.scss +23 -0
  71. data/app/assets/stylesheets/gumby/ui/_labels.scss +87 -0
  72. data/app/assets/stylesheets/gumby/ui/_navbar.scss +440 -0
  73. data/app/assets/stylesheets/gumby/ui/_tables.scss +89 -0
  74. data/app/assets/stylesheets/gumby/ui/_tabs.scss +156 -0
  75. data/app/assets/stylesheets/gumby/ui/_toggles.scss +73 -0
  76. data/app/assets/stylesheets/gumby/ui/_tooltips.scss +12 -0
  77. data/app/assets/stylesheets/gumby/ui/_video.scss +24 -0
  78. data/app/assets/stylesheets/gumby/var/_lists.scss +20 -0
  79. data/app/assets/stylesheets/gumby/var/_settings.scss +169 -0
  80. data/app/assets/stylesheets/gumby/var/icons/_entypo-icon-list.scss +286 -0
  81. data/app/assets/stylesheets/gumby/var/icons/_entypo.scss +294 -0
  82. data/app/assets/stylesheets/gumby.all.css.scss +20 -0
  83. data/app/assets/stylesheets/gumby.css.scss +37 -0
  84. data/app/controllers/gumby/application_controller.rb +4 -0
  85. data/app/helpers/gumby/application_helper.rb +4 -0
  86. data/app/views/layouts/gumby/application.html.erb +14 -0
  87. data/config/routes.rb +2 -0
  88. data/lib/gumby/engine.rb +10 -0
  89. data/lib/gumby/version.rb +3 -0
  90. data/lib/gumby.rb +4 -0
  91. data/lib/tasks/gumby_tasks.rake +20 -0
  92. data/public/fonts/gumby/icons/entypo.eot +0 -0
  93. data/public/fonts/gumby/icons/entypo.ttf +0 -0
  94. data/public/fonts/gumby/icons/entypo.woff +0 -0
  95. metadata +235 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 68e25b9c9c26c4b193c3ba6da34e9cd2decac523
4
+ data.tar.gz: 9696bb0ce23170abb83822b0307e5f0e9be91fad
5
+ SHA512:
6
+ metadata.gz: f1e23ae40c7c9c316ad1b59581ec6eeec6c6e1418b6c034dc1f5cbd9b108d3e22fe6e7d7aa3648f07188cbcd1cf7c1ac1d814b95abe364fa5879ec3d296544a2
7
+ data.tar.gz: 26544b4b037dce4446cc6f5ae6337bd187744596f14c5c6fd67bd498dc99a6f4ad8fef567e8f3e7398e52ca1695c6b8ceb8bfc4777c56702c3665bb14c0b6e0a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Gumby'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,152 @@
1
+ /**
2
+ * Gumby Comments
3
+ * http://github.com/GumbyFramework/ResponsiveComments v1.0.0
4
+ */
5
+ !function($) {
6
+
7
+ 'use strict';
8
+
9
+ // data attributes
10
+ var attrs = {
11
+ 'media' : 'gumby-comment-media',
12
+ 'supports' : 'gumby-comment-supports',
13
+ 'insert' : 'gumby-comment-insert'
14
+ };
15
+
16
+ // cache responsive comments nodes and data
17
+ function prepNodes(nodes) {
18
+ var i = 0, l = nodes.length, mqs = [], el, ins, obj;
19
+ for(; i < l; i++) {
20
+ el = nodes[i];
21
+ // beforeend default insert type
22
+ ins = el.getAttribute(attrs.insert) || 'beforeend';
23
+ // store element, insert type, media query / support test
24
+ obj = {
25
+ 'element' : el,
26
+ 'insert' : ins,
27
+ 'media' : el.getAttribute(attrs.media) || false,
28
+ 'supports' : el.getAttribute(attrs.supports) || false
29
+ };
30
+
31
+ mqs.push(obj);
32
+ }
33
+ return mqs;
34
+ }
35
+
36
+ // call required function (media/supports) on each array element
37
+ function testNodes(type) {
38
+ // if type present first argument is event object
39
+ type = typeof type === 'string' ? type : false;
40
+ this.forEach(function(x) {
41
+ if((type === 'supports' || !type) && x.supports) {
42
+ testSupportNodes.apply(x);
43
+ } else if((type === 'media' || !type) && x.media) {
44
+ testMediaNodes.apply(x);
45
+ }
46
+ });
47
+ }
48
+
49
+ // test media query nodes, requires matchMedia
50
+ function testMediaNodes() {
51
+ // matchMedia and media query itself required
52
+ if(!this.media || !window.matchMedia) {
53
+ return;
54
+ }
55
+
56
+ // media query passes and attribute not already set to complete
57
+ if(window.matchMedia(this.media).matches &&
58
+ this.element.getAttribute(attrs.media) !== 'complete') {
59
+ childNodes.apply(this);
60
+ return;
61
+ }
62
+
63
+ return;
64
+ }
65
+
66
+ // test media query nodes, requires matchMedia
67
+ function testSupportNodes() {
68
+ // Modernizr and tests required
69
+ if(!this.supports || !Modernizr ||
70
+ // test already been carried out
71
+ this.element.getAttribute(attrs.support) === 'complete') {
72
+ return;
73
+ }
74
+
75
+ if(featureDetection(this.supports.split(','))) {
76
+ childNodes.apply(this);
77
+ return;
78
+ }
79
+
80
+ return;
81
+ }
82
+
83
+ // handle Modernir feature detection
84
+ // if multiple features hand off to multiFeatureDetection
85
+ function featureDetection(features) {
86
+ // multiple feature detections
87
+ if(features.length > 1) {
88
+ return multiFeatureDetection(features);
89
+ }
90
+
91
+ // single feature detection
92
+ return Modernizr[features];
93
+ }
94
+
95
+ // handle multiple modernizr feature detections
96
+ function multiFeatureDetection(features) {
97
+ var passed = true;
98
+ features.forEach(function(feature) {
99
+ if(!Modernizr[feature]) {
100
+ passed = false;
101
+ }
102
+ });
103
+ return passed;
104
+ }
105
+
106
+ // loop round child nodes, find commented content
107
+ function childNodes() {
108
+ var l = this.element.childNodes.length,
109
+ i = 0;
110
+
111
+ for(; i < l; i++) {
112
+ // node type 8 is comment
113
+ if(this.element.childNodes[i].nodeType === 8) {
114
+ insertComment.apply(this, [i]);
115
+ }
116
+ }
117
+ }
118
+
119
+ // insert commented content into DOM, mark as complete and trigger event
120
+ function insertComment(index) {
121
+ this.element.insertAdjacentHTML(this.insert, this.element.childNodes[index].textContent);
122
+ this.element.setAttribute(attrs.media, 'complete');
123
+ dispatchEvent.apply(this);
124
+ }
125
+
126
+ // dispatch CustomEvent if supported with media query and insert type detail
127
+ function dispatchEvent() {
128
+ $(this.element).trigger('gumby.onInsert');
129
+ }
130
+
131
+ // add initialisation
132
+ Gumby.addInitalisation('comments', function() {
133
+ // find and cache responsive comments nodes
134
+ var els = prepNodes(
135
+ document.querySelectorAll('['+attrs.media+'],['+attrs.supports+']')
136
+ );
137
+
138
+ // test media nodes only on resize
139
+ window.addEventListener('resize', testNodes.bind(els, 'media'));
140
+ // test media and support nodes on load
141
+ window.addEventListener('load', testNodes.bind(els));
142
+ });
143
+
144
+ // register UI module
145
+ Gumby.UIModule({
146
+ module: 'comments',
147
+ events: ['onInsert'],
148
+ init: function() {
149
+ Gumby.initialize('comments');
150
+ }
151
+ });
152
+ }(jQuery);
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Gumby FitText
3
+ *
4
+ * Adapted from the awesome FitText jQuery plugin
5
+ * brought to you by Paravel - http://paravelinc.com/
6
+ *
7
+ * http://github.com/GumbyFramework/FitText v1.0.1
8
+ */
9
+ !function() {
10
+
11
+ 'use strict';
12
+
13
+ function FitText($el) {
14
+
15
+ Gumby.debug('Initializing FitText', $el);
16
+
17
+ this.$el = $el;
18
+
19
+ this.rate = 0;
20
+ this.fontSizes = {};
21
+ this.debugDelay = 0;
22
+
23
+ // set up module based on attributes
24
+ this.setup();
25
+
26
+ var scope = this;
27
+
28
+ // re-initialize module
29
+ this.$el.on('gumby.initialize', function() {
30
+ Gumby.debug('Re-initializing FitText', scope.$el);
31
+ scope.setup();
32
+ scope.resize();
33
+ });
34
+
35
+ // lets go
36
+ $(window).on('load resize orientationchange', function() {
37
+ scope.resize();
38
+ });
39
+
40
+ this.resize();
41
+ }
42
+
43
+ // set up module based on attributes
44
+ FitText.prototype.setup = function() {
45
+ // optional compressor rate
46
+ this.rate = Number(Gumby.selectAttr.apply(this.$el, ['rate'])) || 1;
47
+ // optional font sizes (min|max)
48
+ this.fontSizes = this.parseSizes(Gumby.selectAttr.apply(this.$el, ['sizes']));
49
+ };
50
+
51
+ // apply the resizing
52
+ FitText.prototype.resize = function() {
53
+ var size = this.calculateSize(),
54
+ scope = this;
55
+
56
+ this.$el.css('font-size', size);
57
+
58
+ // wrap debug in timeout so not printing on every resize event
59
+ clearTimeout(this.debugDelay);
60
+ this.debugDelay = setTimeout(function() {
61
+ Gumby.debug('Updated font size to '+size+'px', scope.$el);
62
+ }, 200);
63
+ };
64
+
65
+ // calculate the font size
66
+ FitText.prototype.calculateSize = function() {
67
+ return Math.max(Math.min(this.$el.width() / (this.rate*10), parseFloat(this.fontSizes.max)), parseFloat(this.fontSizes.min));
68
+ };
69
+
70
+ // parse size attributes with min|max syntax
71
+ FitText.prototype.parseSizes = function(attrStr) {
72
+ var sizes = {
73
+ min: Number.NEGATIVE_INFINITY,
74
+ max: Number.POSITIVE_INFINITY
75
+ };
76
+
77
+ // attribute is optional
78
+ if(!attrStr) { return sizes; }
79
+
80
+ // min and/or max specified
81
+ if(attrStr.indexOf('|') > -1) {
82
+ attrStr = attrStr.split('|');
83
+
84
+ // both are optional
85
+ sizes.min = Number(attrStr[0]) || sizes.min;
86
+ sizes.max = Number(attrStr[1]) || sizes.max;
87
+ }
88
+
89
+ // only one value specific without | so use as min
90
+ sizes.min = Number(attrStr) || sizes.min;
91
+
92
+ return sizes;
93
+ };
94
+
95
+ // add initialisation
96
+ Gumby.addInitalisation('fittext', function(all) {
97
+ $('.fittext').each(function() {
98
+ var $this = $(this);
99
+
100
+ // this element has already been initialized
101
+ // and we're only initializing new modules
102
+ if($this.data('isFittext') && !all) {
103
+ return true;
104
+
105
+ // this element has already been initialized
106
+ // and we need to reinitialize it
107
+ } else if($this.data('isFittext') && all) {
108
+ $this.trigger('gumby.initialize');
109
+ return true;
110
+ }
111
+
112
+ // mark element as initialized
113
+ $this.data('isFittext', true);
114
+ new FitText($this);
115
+ });
116
+ });
117
+
118
+ // register UI module
119
+ Gumby.UIModule({
120
+ module: 'fittext',
121
+ events: ['initialize'],
122
+ init: function() {
123
+ Gumby.initialize('fittext');
124
+ }
125
+ });
126
+ }();
@@ -0,0 +1,202 @@
1
+ /**
2
+ * Gumby Images
3
+ * http://github.com/GumbyFramework/ResponsiveImages v1.1.0
4
+ */
5
+ !function() {
6
+
7
+ 'use strict';
8
+
9
+ function Images($el) {
10
+
11
+ Gumby.debug('Initializing Responsive Images module', $el);
12
+
13
+ this.$el = $el;
14
+
15
+ this.type = '';
16
+ this.supports = '';
17
+ this.media = '';
18
+ this.def = '';
19
+ this.current = '';
20
+
21
+ // set up module based on attributes
22
+ this.setup();
23
+
24
+ var scope = this;
25
+ $(window).on('load gumby.trigger '+(!this.media || 'resize'), function(e) {
26
+ scope.fire();
27
+ });
28
+
29
+ this.$el.on('gumby.initialize', function() {
30
+ Gumby.debug('Re-initializing Responsive Images module', scope.$el);
31
+ scope.setup();
32
+ scope.fire();
33
+ });
34
+
35
+ scope.fire();
36
+ }
37
+
38
+ // set up module based on attributes
39
+ Images.prototype.setup = function() {
40
+ // is this an <img> or background-image?
41
+ this.type = this.$el.is('img') ? 'img' : 'bg';
42
+ // supports attribute in format test:image
43
+ this.supports = Gumby.selectAttr.apply(this.$el, ['supports']) || false;
44
+ // media attribute in format mediaQuery:image
45
+ this.media = Gumby.selectAttr.apply(this.$el, ['media']) || false;
46
+ // default image to load
47
+ this.def = Gumby.selectAttr.apply(this.$el, ['default']) || false;
48
+
49
+ // parse support/media objects
50
+ if(this.supports) { this.supports = this.parseAttr(this.supports); }
51
+ if(this.media) { this.media = this.parseAttr(this.media); }
52
+
53
+ // check functions
54
+ this.checks = {
55
+ supports : function(val) {
56
+ return Modernizr[val];
57
+ },
58
+ media: function(val) {
59
+ return window.matchMedia(val).matches;
60
+ }
61
+ };
62
+ };
63
+
64
+ // fire required checks and load resulting image
65
+ Images.prototype.fire = function() {
66
+ // feature supported or media query matched
67
+ var success = false;
68
+
69
+ // if support attribute supplied and Modernizr is present
70
+ if(this.supports && Modernizr) {
71
+ success = this.handleTests('supports', this.supports);
72
+ }
73
+
74
+ // if media attribute supplied and matchMedia is supported
75
+ // and success is still false, meaning no supporting feature was found
76
+ if(this.media && window.matchMedia && !success) {
77
+ success = this.handleTests('media', this.media);
78
+ }
79
+
80
+ // no feature supported or media query matched so load default if supplied
81
+ if(!success && this.def) {
82
+ success = this.def;
83
+ }
84
+
85
+ // no image to load
86
+ if(!success) {
87
+ return false;
88
+ }
89
+
90
+ // preload image and insert or set background-image property if not already set
91
+ if(this.current !== success) {
92
+ this.current = success;
93
+ this.insertImage(this.type, success);
94
+ }
95
+ };
96
+
97
+ // handle media object checking each prop for matching media query
98
+ Images.prototype.handleTests = function(type, array) {
99
+ var scope = this,
100
+ supported = false;
101
+
102
+ $(array).each(function(key, val) {
103
+ // media query matched
104
+ // supplied in order of preference so halt each loop
105
+ if(scope.check(type, val.test)) {
106
+ supported = val.img;
107
+ return false;
108
+ }
109
+ });
110
+
111
+ return supported;
112
+ };
113
+
114
+ // return the result of test function
115
+ Images.prototype.check = function(type, val) {
116
+ return this.checks[type](val);
117
+ };
118
+
119
+ // preload image and insert or set background-image property
120
+ Images.prototype.insertImage = function(type, img) {
121
+ var scope = this,
122
+ image = $(new Image());
123
+
124
+ image.load(function() {
125
+ type === 'img' ? scope.$el.attr('src', img) : scope.$el.css('background-image', 'url('+img+')');
126
+
127
+ // trigger custom loaded event
128
+ Gumby.debug('Triggering onChange event', img, scope.$el);
129
+ scope.$el.trigger('gumby.onChange', [img]);
130
+ }).attr('src', img);
131
+ };
132
+
133
+ // parse attribute strings, media/support
134
+ Images.prototype.parseAttr = function(support) {
135
+ var scope = this,
136
+ supp = support.split(','),
137
+ res = [], splt = [];
138
+
139
+ // multiple can be supplied so loop round and create object
140
+ $(supp).each(function(key, val) {
141
+ splt = val.split('|');
142
+ if(splt.length !== 2) {
143
+ return true;
144
+ }
145
+
146
+ // object containing Modernizr test or media query and image url
147
+ res.push({
148
+ 'test' : scope.shorthand(splt[0]),
149
+ 'img' : splt[1]
150
+ });
151
+ });
152
+
153
+ return res;
154
+ };
155
+
156
+ // replace < and > with min/max width media queries
157
+ Images.prototype.shorthand = function(str) {
158
+ // replace < and >
159
+ if(str.indexOf('>') > -1 || str.indexOf('<') > -1) {
160
+ str = str.replace('>', 'min-width: ').replace('<', 'max-width: ');
161
+ }
162
+
163
+ // check if media query wrapped in ()
164
+ if(str.charAt(0) !== '(' && str.charAt(str.length - 1) !== ')') {
165
+ str = '('+str+')';
166
+ }
167
+
168
+ return str;
169
+ };
170
+
171
+ // add initialisation
172
+ Gumby.addInitalisation('images', function(all) {
173
+ $('[gumby-supports],[data-supports],[supports],[gumby-media],[data-media],[media]').each(function() {
174
+ var $this = $(this);
175
+
176
+ // this element has already been initialized
177
+ // and we're only initializing new modules
178
+ if($this.data('isImage') && !all) {
179
+ return true;
180
+
181
+ // this element has already been initialized
182
+ // and we need to reinitialize it
183
+ } else if($this.data('isImage') && all) {
184
+ $this.trigger('gumby.initialize');
185
+ return true;
186
+ }
187
+
188
+ // mark element as initialized
189
+ $this.data('isImage', true);
190
+ new Images($this);
191
+ });
192
+ });
193
+
194
+ // register UI module
195
+ Gumby.UIModule({
196
+ module: 'images',
197
+ events: ['onChange', 'trigger'],
198
+ init: function() {
199
+ Gumby.initialize('images');
200
+ }
201
+ });
202
+ }();