echo_lazy_loader 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -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 echo_lazy_loader.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Kinaan Khan
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.
data/README.md ADDED
@@ -0,0 +1,73 @@
1
+ # EchoLazyLoader
2
+
3
+ Gem for lazily loading the images using [Echo](https://github.com/toddmotto/echo) javascript library.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'echo_lazy_loader'
10
+
11
+ And then execute:
12
+
13
+ $ bundle install
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install echo_lazy_loader
18
+
19
+ ## Usage
20
+
21
+ Add the following to your `app/assets/javascripts/application.js`:
22
+
23
+ //= require echo
24
+
25
+ To use minified version use this:
26
+
27
+ //= require echo.min
28
+
29
+ Use the following helper function instead of `image_tag` for images that you want to lazily load
30
+
31
+ echo_image_tag src, options
32
+
33
+ This function takes same parameters as the `image_tag` helper.
34
+
35
+ You will also have to call the following function ( prefereably in application layout ).
36
+
37
+ echo_init
38
+
39
+ If you want to apply lazy loading to images that donot show on scrolling but are swaped by some slider or filter layout , you can directly use this javascript code
40
+
41
+ <script type="text/javascript">
42
+ Echo.render();
43
+ </script>
44
+
45
+ ## Configuration
46
+
47
+ you can use `rails g echo_lazy_loader:config` that will generate `echo_lazy_loader.rb` in project's initializer folder.
48
+
49
+ The configurable options ( with default values) are as follows.
50
+
51
+ default_image = "/assets/blankloading.gif"
52
+ offset= 100
53
+ throttle= 250
54
+
55
+ `default_image` is the path to the image which you want to show when the actual image is loading .
56
+ `offset` and `throttle` are used by the `Echo Library` and has been explained in its [documentation](https://github.com/toddmotto/echo#init-api-options) .
57
+
58
+ You can also pass the `offset` and `throttle` while calling `echo_init`. The values passed to the function will be used instead of those given in configuration file.
59
+
60
+
61
+ ## Contributors
62
+
63
+ 1. [Kinaan Khan Sherwani](https://github.com/kinaan-khan-confiz) ( kinaan.khan@confiz.com )
64
+ 2. [Usman Ali](https://github.com/usman-ali-confiz) ( usman.ali@confiz.com)
65
+ 3. [Ahmad Hussain](https://github.com/ahmad-hussain-confiz) ( ahmad.hussain@confiz.com)
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ module EchoLazyLoaderHelper
2
+
3
+ def echo_image_tag src,options = {}
4
+ options.merge!({"data-echo" => path_to_image(src)})
5
+ raw(image_tag(EchoLazyLoader::default_image,options))
6
+ # TODO: add noscript
7
+ end
8
+
9
+ def echo_init(offest = EchoLazyLoader::offset, throttle = EchoLazyLoader::throttle)
10
+ javascript_tag do
11
+ raw("
12
+ window.onload= function(){
13
+ Echo.init({
14
+ offset: #{offest},
15
+ throttle: #{throttle}
16
+ });
17
+ } ;")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'echo_lazy_loader/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "echo_lazy_loader"
8
+ spec.version = EchoLazyLoader::VERSION
9
+ spec.authors = ["Confiz Limited"]
10
+ spec.email = ["kinaan.khan@confiz.com"]
11
+ spec.description = %q{Gem for loading images lazily using echo js library}
12
+ spec.summary = %q{Gem for loading images lazily using echo js library}
13
+ spec.homepage = "http://github.com/confiz/echo_lazy_loader"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,20 @@
1
+ require "echo_lazy_loader/version"
2
+
3
+ module EchoLazyLoader
4
+ mattr_accessor :default_image
5
+ @@default_image="/assets/blankloading.gif"
6
+ mattr_accessor :offset
7
+ @@default_image=100
8
+ mattr_accessor :throttle
9
+ @@throttle=250
10
+
11
+ class << self
12
+ def setup
13
+ yield self
14
+ end
15
+ end
16
+
17
+ class Engine < Rails::Engine
18
+
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module EchoLazyLoader
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,9 @@
1
+ module EchoLazyLoader
2
+ class ConfigGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ def add_initializer_file
6
+ template "initializer.rb", "config/initializers/echo_lazy_loader.rb"
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ EchoLazyLoader.setup do |s|
2
+ s.default_image = "/assets/blankloading.gif"
3
+ s.offset= 100
4
+ s.throttle= 250
5
+ end
@@ -0,0 +1,58 @@
1
+ /*!
2
+ * Echo v1.4.0
3
+ * Lazy-loading with data-* attributes, offsets and throttle options
4
+ * Project: https://github.com/toddmotto/echo
5
+ * by Todd Motto: http://toddmotto.com
6
+ * Copyright. MIT licensed.
7
+ */
8
+ window.Echo = (function (window, document, undefined) {
9
+
10
+ 'use strict';
11
+
12
+ var store = [], offset, throttle, poll;
13
+
14
+ var _inView = function (el) {
15
+ var coords = el.getBoundingClientRect();
16
+ return ((coords.top >= 0 && coords.left >= 0 && coords.top) <= (window.innerHeight || document.documentElement.clientHeight) + parseInt(offset));
17
+ };
18
+
19
+ var _pollImages = function () {
20
+ for (var i = store.length; i--;) {
21
+ var self = store[i];
22
+ if (_inView(self)) {
23
+ self.src = self.getAttribute('data-echo');
24
+ store.splice(i, 1);
25
+ }
26
+ }
27
+ };
28
+
29
+ var _throttle = function () {
30
+ clearTimeout(poll);
31
+ poll = setTimeout(_pollImages, throttle);
32
+ };
33
+
34
+ var init = function (obj) {
35
+ var nodes = document.querySelectorAll('[data-echo]');
36
+ var opts = obj || {};
37
+ offset = opts.offset || 0;
38
+ throttle = opts.throttle || 250;
39
+
40
+ for (var i = 0; i < nodes.length; i++) {
41
+ store.push(nodes[i]);
42
+ }
43
+
44
+ _throttle();
45
+
46
+ if (document.addEventListener) {
47
+ window.addEventListener('scroll', _throttle, false);
48
+ } else {
49
+ window.attachEvent('onscroll', _throttle);
50
+ }
51
+ };
52
+
53
+ return {
54
+ init: init,
55
+ render: _throttle
56
+ };
57
+
58
+ })(window, document);
@@ -0,0 +1,8 @@
1
+ /*!
2
+ * Echo v1.4.0
3
+ * Lazy-loading with data-* attributes, offsets and throttle options
4
+ * Project: https://github.com/toddmotto/echo
5
+ * by Todd Motto: http://toddmotto.com
6
+ * Copyright. MIT licensed.
7
+ */
8
+ window.Echo=function(a,b){"use strict";var c,d,e,f=[],g=function(d){var e=d.getBoundingClientRect();return(e.top>=0&&e.left>=0&&e.top)<=(a.innerHeight||b.documentElement.clientHeight)+parseInt(c)},h=function(){for(var a=f.length;a--;){var b=f[a];g(b)&&(b.src=b.getAttribute("data-echo"),f.splice(a,1))}},i=function(){clearTimeout(e),e=setTimeout(h,d)},j=function(e){var g=b.querySelectorAll("[data-echo]"),h=e||{};c=h.offset||0,d=h.throttle||250;for(var j=0;j<g.length;j++)f.push(g[j]);i(),b.addEventListener?a.addEventListener("scroll",i,!1):a.attachEvent("onscroll",i)};return{init:j,render:i}}(window,document);
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: echo_lazy_loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Confiz Limited
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
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: Gem for loading images lazily using echo js library
47
+ email:
48
+ - kinaan.khan@confiz.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - app/helpers/echo_lazy_loader_helper.rb
59
+ - echo_lazy_loader.gemspec
60
+ - lib/echo_lazy_loader.rb
61
+ - lib/echo_lazy_loader/version.rb
62
+ - lib/generators/echo_lazy_loader/config_generator.rb
63
+ - lib/generators/echo_lazy_loader/templates/initializer.rb
64
+ - vendor/assets/images/blankloading.gif
65
+ - vendor/assets/javascripts/echo.js
66
+ - vendor/assets/javascripts/echo.min.js
67
+ homepage: http://github.com/confiz/echo_lazy_loader
68
+ licenses:
69
+ - MIT
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -4550767949091289016
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: -4550767949091289016
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.25
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Gem for loading images lazily using echo js library
98
+ test_files: []