backstretch-rails 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in backstretch-rails.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Andre Meij
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ # Backstretch::Rails
2
+
3
+ A rails asset pipeline packaged version of jQuery Backstretch v2.0.3 this gem will follow the version number of the backstretch distribution.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'backstretch-rails'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install backstretch-rails
18
+
19
+ ## Usage
20
+
21
+ //= require 'jquery-backstretch'
22
+
23
+
24
+ ## Acknowledgements
25
+
26
+ * Backstretch by srobbin https://github.com/srobbin/jquery-backstretch which is a terrific library
27
+ * Font awesome rails package by bokmann: https://github.com/bokmann/font-awesome-rails used as a template
28
+
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'backstretch-rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "backstretch-rails"
8
+ gem.version = Backstretch::Rails::VERSION
9
+ gem.authors = ["Andre Meij"]
10
+ gem.email = ["andre@socialreferral.com"]
11
+ gem.description = %q{Rails asset pipeline packaging for the Backstretch jQuery plugin, following the version number of the Backstretch project.}
12
+ gem.summary = %q{Rails asset pipeline packaging for the Backstretch jQuery plugin}
13
+ gem.homepage = "https://github.com/socialreferral/backstretch-rails"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_dependency "railties", "~> 3.1"
21
+ gem.add_development_dependency "rake"
22
+ end
@@ -0,0 +1,8 @@
1
+ require "backstretch-rails/version"
2
+
3
+ module Backstretch
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module Backstretch
2
+ module Rails
3
+ VERSION = "2.0.3"
4
+ end
5
+ end
@@ -0,0 +1,357 @@
1
+ /*! Backstretch - v2.0.3 - 2012-11-30
2
+ * http://srobbin.com/jquery-plugins/backstretch/
3
+ * Copyright (c) 2012 Scott Robbin; Licensed MIT */
4
+
5
+ ;(function ($, window, undefined) {
6
+ 'use strict';
7
+
8
+ /* PLUGIN DEFINITION
9
+ * ========================= */
10
+
11
+ $.fn.backstretch = function (images, options) {
12
+ // We need at least one image
13
+ if (images === undefined || images.length === 0) {
14
+ $.error("No images were supplied for Backstretch");
15
+ }
16
+
17
+ /*
18
+ * Scroll the page one pixel to get the right window height on iOS
19
+ * Pretty harmless for everyone else
20
+ */
21
+ if ($(window).scrollTop() === 0 ) {
22
+ window.scrollTo(0, 0);
23
+ }
24
+
25
+ return this.each(function () {
26
+ var $this = $(this)
27
+ , obj = $this.data('backstretch');
28
+
29
+ // If we've already attached Backstretch to this element, remove the old instance.
30
+ if (obj) {
31
+ // Merge the old options with the new
32
+ options = $.extend(obj.options, options);
33
+
34
+ // Remove the old instance
35
+ obj.destroy(true);
36
+ }
37
+
38
+ obj = new Backstretch(this, images, options);
39
+ $this.data('backstretch', obj);
40
+ });
41
+ };
42
+
43
+ // If no element is supplied, we'll attach to body
44
+ $.backstretch = function (images, options) {
45
+ // Return the instance
46
+ return $('body')
47
+ .backstretch(images, options)
48
+ .data('backstretch');
49
+ };
50
+
51
+ // Custom selector
52
+ $.expr[':'].backstretch = function(elem) {
53
+ return $(elem).data('backstretch') !== undefined;
54
+ };
55
+
56
+ /* DEFAULTS
57
+ * ========================= */
58
+
59
+ $.fn.backstretch.defaults = {
60
+ centeredX: true // Should we center the image on the X axis?
61
+ , centeredY: true // Should we center the image on the Y axis?
62
+ , duration: 5000 // Amount of time in between slides (if slideshow)
63
+ , fade: 0 // Speed of fade transition between slides
64
+ };
65
+
66
+ /* STYLES
67
+ *
68
+ * Baked-in styles that we'll apply to our elements.
69
+ * In an effort to keep the plugin simple, these are not exposed as options.
70
+ * That said, anyone can override these in their own stylesheet.
71
+ * ========================= */
72
+ var styles = {
73
+ wrap: {
74
+ left: 0
75
+ , top: 0
76
+ , overflow: 'hidden'
77
+ , margin: 0
78
+ , padding: 0
79
+ , height: '100%'
80
+ , width: '100%'
81
+ , zIndex: -999999
82
+ }
83
+ , img: {
84
+ position: 'absolute'
85
+ , display: 'none'
86
+ , margin: 0
87
+ , padding: 0
88
+ , border: 'none'
89
+ , width: 'auto'
90
+ , height: 'auto'
91
+ , maxWidth: 'none'
92
+ , zIndex: -999999
93
+ }
94
+ };
95
+
96
+ /* CLASS DEFINITION
97
+ * ========================= */
98
+ var Backstretch = function (container, images, options) {
99
+ this.options = $.extend({}, $.fn.backstretch.defaults, options || {});
100
+
101
+ /* In its simplest form, we allow Backstretch to be called on an image path.
102
+ * e.g. $.backstretch('/path/to/image.jpg')
103
+ * So, we need to turn this back into an array.
104
+ */
105
+ this.images = $.isArray(images) ? images : [images];
106
+
107
+ // Preload images
108
+ $.each(this.images, function () {
109
+ $('<img />')[0].src = this;
110
+ });
111
+
112
+ // Convenience reference to know if the container is body.
113
+ this.isBody = container === document.body;
114
+
115
+ /* We're keeping track of a few different elements
116
+ *
117
+ * Container: the element that Backstretch was called on.
118
+ * Wrap: a DIV that we place the image into, so we can hide the overflow.
119
+ * Root: Convenience reference to help calculate the correct height.
120
+ */
121
+ this.$container = $(container);
122
+ this.$wrap = $('<div class="backstretch"></div>').css(styles.wrap).appendTo(this.$container);
123
+ this.$root = this.isBody ? supportsFixedPosition ? $(window) : $(document) : this.$container;
124
+
125
+ // Non-body elements need some style adjustments
126
+ if (!this.isBody) {
127
+ // If the container is statically positioned, we need to make it relative,
128
+ // and if no zIndex is defined, we should set it to zero.
129
+ var position = this.$container.css('position')
130
+ , zIndex = this.$container.css('zIndex');
131
+
132
+ this.$container.css({
133
+ position: position === 'static' ? 'relative' : position
134
+ , zIndex: zIndex === 'auto' ? 0 : zIndex
135
+ , background: 'none'
136
+ });
137
+
138
+ // Needs a higher z-index
139
+ this.$wrap.css({zIndex: -999998});
140
+ }
141
+
142
+ // Fixed or absolute positioning?
143
+ this.$wrap.css({
144
+ position: this.isBody && supportsFixedPosition ? 'fixed' : 'absolute'
145
+ });
146
+
147
+ // Set the first image
148
+ this.index = 0;
149
+ this.show(this.index);
150
+
151
+ // Listen for resize
152
+ $(window).on('resize.backstretch', $.proxy(this.resize, this))
153
+ .on('orientationchange.backstretch', $.proxy(function () {
154
+ // Need to do this in order to get the right window height
155
+ if (this.isBody && window.pageYOffset === 0) {
156
+ window.scrollTo(0, 1);
157
+ this.resize();
158
+ }
159
+ }, this));
160
+ };
161
+
162
+ /* PUBLIC METHODS
163
+ * ========================= */
164
+ Backstretch.prototype = {
165
+ resize: function () {
166
+ try {
167
+ var bgCSS = {left: 0, top: 0}
168
+ , rootWidth = this.isBody ? this.$root.width() : this.$root.innerWidth()
169
+ , bgWidth = rootWidth
170
+ , rootHeight = this.isBody ? ( window.innerHeight ? window.innerHeight : this.$root.height() ) : this.$root.innerHeight()
171
+ , bgHeight = bgWidth / this.$img.data('ratio')
172
+ , bgOffset;
173
+
174
+ // Make adjustments based on image ratio
175
+ if (bgHeight >= rootHeight) {
176
+ bgOffset = (bgHeight - rootHeight) / 2;
177
+ if(this.options.centeredY) {
178
+ bgCSS.top = '-' + bgOffset + 'px';
179
+ }
180
+ } else {
181
+ bgHeight = rootHeight;
182
+ bgWidth = bgHeight * this.$img.data('ratio');
183
+ bgOffset = (bgWidth - rootWidth) / 2;
184
+ if(this.options.centeredX) {
185
+ bgCSS.left = '-' + bgOffset + 'px';
186
+ }
187
+ }
188
+
189
+ this.$wrap.css({width: rootWidth, height: rootHeight})
190
+ .find('img:not(.deleteable)').css({width: bgWidth, height: bgHeight}).css(bgCSS);
191
+ } catch(err) {
192
+ // IE7 seems to trigger resize before the image is loaded.
193
+ // This try/catch block is a hack to let it fail gracefully.
194
+ }
195
+
196
+ return this;
197
+ }
198
+
199
+ // Show the slide at a certain position
200
+ , show: function (index) {
201
+ // Validate index
202
+ if (Math.abs(index) > this.images.length - 1) {
203
+ return;
204
+ } else {
205
+ this.index = index;
206
+ }
207
+
208
+ // Vars
209
+ var self = this
210
+ , oldImage = self.$wrap.find('img').addClass('deleteable')
211
+ , evt = $.Event('backstretch.show', {
212
+ relatedTarget: self.$container[0]
213
+ });
214
+
215
+ // Pause the slideshow
216
+ clearInterval(self.interval);
217
+
218
+ // New image
219
+ self.$img = $('<img />')
220
+ .css(styles.img)
221
+ .bind('load', function (e) {
222
+ var imgWidth = this.width || $(e.target).width()
223
+ , imgHeight = this.height || $(e.target).height();
224
+
225
+ // Save the ratio
226
+ $(this).data('ratio', imgWidth / imgHeight);
227
+
228
+ // Show the image, then delete the old one
229
+ // "speed" option has been deprecated, but we want backwards compatibilty
230
+ $(this).fadeIn(self.options.speed || self.options.fade, function () {
231
+ oldImage.remove();
232
+
233
+ // Resume the slideshow
234
+ if (!self.paused) {
235
+ self.cycle();
236
+ }
237
+
238
+ // Trigger the event
239
+ self.$container.trigger(evt, self);
240
+ });
241
+
242
+ // Resize
243
+ self.resize();
244
+ })
245
+ .appendTo(self.$wrap);
246
+
247
+ // Hack for IE img onload event
248
+ self.$img.attr('src', self.images[index]);
249
+ return self;
250
+ }
251
+
252
+ , next: function () {
253
+ // Next slide
254
+ return this.show(this.index < this.images.length - 1 ? this.index + 1 : 0);
255
+ }
256
+
257
+ , prev: function () {
258
+ // Previous slide
259
+ return this.show(this.index === 0 ? this.images.length - 1 : this.index - 1);
260
+ }
261
+
262
+ , pause: function () {
263
+ // Pause the slideshow
264
+ this.paused = true;
265
+ return this;
266
+ }
267
+
268
+ , resume: function () {
269
+ // Resume the slideshow
270
+ this.paused = false;
271
+ this.next();
272
+ return this;
273
+ }
274
+
275
+ , cycle: function () {
276
+ // Start/resume the slideshow
277
+ if(this.images.length > 1) {
278
+ // Clear the interval, just in case
279
+ clearInterval(this.interval);
280
+
281
+ this.interval = setInterval($.proxy(function () {
282
+ // Check for paused slideshow
283
+ if (!this.paused) {
284
+ this.next();
285
+ }
286
+ }, this), this.options.duration);
287
+ }
288
+ return this;
289
+ }
290
+
291
+ , destroy: function (preserveBackground) {
292
+ // Stop the resize events
293
+ $(window).off('resize.backstretch orientationchange.backstretch');
294
+
295
+ // Clear the interval
296
+ clearInterval(this.interval);
297
+
298
+ // Remove Backstretch
299
+ if(!preserveBackground) {
300
+ this.$wrap.remove();
301
+ }
302
+ this.$container.removeData('backstretch');
303
+ }
304
+ };
305
+
306
+ /* SUPPORTS FIXED POSITION?
307
+ *
308
+ * Based on code from jQuery Mobile 1.1.0
309
+ * http://jquerymobile.com/
310
+ *
311
+ * In a nutshell, we need to figure out if fixed positioning is supported.
312
+ * Unfortunately, this is very difficult to do on iOS, and usually involves
313
+ * injecting content, scrolling the page, etc.. It's ugly.
314
+ * jQuery Mobile uses this workaround. It's not ideal, but works.
315
+ *
316
+ * Modified to detect IE6
317
+ * ========================= */
318
+
319
+ var supportsFixedPosition = (function () {
320
+ var ua = navigator.userAgent
321
+ , platform = navigator.platform
322
+ // Rendering engine is Webkit, and capture major version
323
+ , wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ )
324
+ , wkversion = !!wkmatch && wkmatch[ 1 ]
325
+ , ffmatch = ua.match( /Fennec\/([0-9]+)/ )
326
+ , ffversion = !!ffmatch && ffmatch[ 1 ]
327
+ , operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ )
328
+ , omversion = !!operammobilematch && operammobilematch[ 1 ]
329
+ , iematch = ua.match( /MSIE ([0-9]+)/ )
330
+ , ieversion = !!iematch && iematch[ 1 ];
331
+
332
+ return !(
333
+ // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
334
+ ((platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534) ||
335
+
336
+ // Opera Mini
337
+ (window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]") ||
338
+ (operammobilematch && omversion < 7458) ||
339
+
340
+ //Android lte 2.1: Platform is Android and Webkit version is less than 533 (Android 2.2)
341
+ (ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 533) ||
342
+
343
+ // Firefox Mobile before 6.0 -
344
+ (ffversion && ffversion < 6) ||
345
+
346
+ // WebOS less than 3
347
+ ("palmGetResource" in window && wkversion && wkversion < 534) ||
348
+
349
+ // MeeGo
350
+ (ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1) ||
351
+
352
+ // IE6
353
+ (ieversion && ieversion <= 6)
354
+ );
355
+ }());
356
+
357
+ }(jQuery, window));
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: backstretch-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Andre Meij
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: railties
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Rails asset pipeline packaging for the Backstretch jQuery plugin, following
47
+ the version number of the Backstretch project.
48
+ email:
49
+ - andre@socialreferral.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README.md
58
+ - Rakefile
59
+ - backstretch-rails.gemspec
60
+ - lib/backstretch-rails.rb
61
+ - lib/backstretch-rails/version.rb
62
+ - vendor/assets/javascripts/jquery.backstretch.js
63
+ homepage: https://github.com/socialreferral/backstretch-rails
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 1.8.24
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Rails asset pipeline packaging for the Backstretch jQuery plugin
87
+ test_files: []
88
+ has_rdoc: