image_zoomer 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +17 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/app/assets/javascripts/image_zoomer.js +113 -0
- data/app/assets/javascripts/image_zoomer_initializer.js +6 -0
- data/app/assets/javascripts/image_zoomer_main.js +1 -0
- data/app/assets/javascripts/image_zoomer_options.js.erb +7 -0
- data/image_zoomer.gemspec +24 -0
- data/lib/image_zoomer/configuration.rb +18 -0
- data/lib/image_zoomer/engine.rb +4 -0
- data/lib/image_zoomer/railtie.rb +13 -0
- data/lib/image_zoomer/version.rb +3 -0
- data/lib/image_zoomer/zoom_image_helper.rb +19 -0
- data/lib/image_zoomer.rb +13 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c895266f84f49e890f76ab6ac25c286b4ce5c842
|
4
|
+
data.tar.gz: 2df7c11928d805e227f398e56e628b250611a1f9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3cdd7c2e7fcb1f177b8f197b6b010e364afa4fceabac207c746213831a6b3da787337aac83ab327b870b1f18fc4fed2c670ba757bcc6425cad5f8d662a509ebc
|
7
|
+
data.tar.gz: 22c7b3783e087b4de78f97a6e382d73f8cd4b85cb98146a70bbc336bd0686c5ad683f348d6b4eab21ade3cfc723852c552841a25a1b83eda92e32d7efa5eb0f6
|
data/.gitignore
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
*.rbc
|
2
|
+
capybara-*.html
|
3
|
+
.rspec
|
4
|
+
/log
|
5
|
+
/tmp
|
6
|
+
/db/*.sqlite3
|
7
|
+
/public/system
|
8
|
+
/coverage/
|
9
|
+
/spec/tmp
|
10
|
+
**.orig
|
11
|
+
rerun.txt
|
12
|
+
pickle-email-*.html
|
13
|
+
config/initializers/secret_token.rb
|
14
|
+
config/secrets.yml
|
15
|
+
|
16
|
+
## Environment normalisation:
|
17
|
+
/.bundle
|
18
|
+
/vendor/bundle
|
19
|
+
|
20
|
+
# these should all be checked in to normalise the environment:
|
21
|
+
# Gemfile.lock, .ruby-version, .ruby-gemset
|
22
|
+
|
23
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
24
|
+
.rvmrc
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Imran Latif
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 imranjs
|
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,29 @@
|
|
1
|
+
# ImageZoomer
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'image_zoomer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install image_zoomer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/image_zoomer/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
(function($) {
|
2
|
+
|
3
|
+
var zoom_context, zoom_canvas = "<canvas id='zoom_canvas' style='position: absolute; border: solid 1px #e8e8e8;'></canvas>";
|
4
|
+
var zoom_canvas_container_name = "#zoom_canvas_container", zoom_canvas_name = "#zoom_canvas", temp_image_canvas_context, remove_image_zoomer_timer;
|
5
|
+
|
6
|
+
$.fn.image_zoomer = function(options) {
|
7
|
+
|
8
|
+
if (typeof options == "string" && options == "destroy") {
|
9
|
+
this.data("is_destroyed", true);
|
10
|
+
return this;
|
11
|
+
} else {
|
12
|
+
// extend default options with passed ones
|
13
|
+
var options = $.extend({
|
14
|
+
height: 90,
|
15
|
+
width: 90,
|
16
|
+
scale: 1.5
|
17
|
+
}, options);
|
18
|
+
this.data("is_destroyed", false);
|
19
|
+
}
|
20
|
+
|
21
|
+
var image = this;
|
22
|
+
|
23
|
+
this.mouseenter(function(e) {
|
24
|
+
if ($(this).data("is_destroyed")) {
|
25
|
+
return false;
|
26
|
+
}
|
27
|
+
if ($(zoom_canvas_container_name).length == 0) {
|
28
|
+
$(this).wrap("<span id='zoom_canvas_container'></span>");
|
29
|
+
var zoom_canvas_container = $(zoom_canvas_container_name);
|
30
|
+
var temp_image_canvas = _insert_temp_canvas(zoom_canvas_container, image);
|
31
|
+
$(zoom_canvas_container).mousemove(function(e) {
|
32
|
+
if ($(zoom_canvas_name).length == 0) {
|
33
|
+
create_zoom_canvas(options);
|
34
|
+
$(zoom_canvas_name).mousemove(function(e) {
|
35
|
+
zoom_image_mousemove(zoom_canvas_container, e, options, image, temp_image_canvas, true);
|
36
|
+
return false;
|
37
|
+
}).mouseleave(zoom_image_mouseleave);
|
38
|
+
}
|
39
|
+
zoom_image_mousemove(zoom_canvas_container, e, options, image, temp_image_canvas, false);
|
40
|
+
return false;
|
41
|
+
});
|
42
|
+
}
|
43
|
+
return false;
|
44
|
+
});
|
45
|
+
return this;
|
46
|
+
}
|
47
|
+
|
48
|
+
function create_zoom_canvas(options) {
|
49
|
+
$("body").append(zoom_canvas);
|
50
|
+
$(zoom_canvas_name).attr("width", options.width).attr("height", options.height);
|
51
|
+
zoom_context = $(zoom_canvas_name).get(0).getContext('2d');
|
52
|
+
zoom_context.scale(options.scale, options.scale);
|
53
|
+
}
|
54
|
+
|
55
|
+
function zoom_image_mousemove(elem, e, options, image, temp_image_canvas, check_bounds) {
|
56
|
+
var image_offset = image.offset();
|
57
|
+
if (check_if_in_bounds(e, image, image_offset)) {
|
58
|
+
zoom_context.clearRect(0, 0, options.width, options.height);
|
59
|
+
zoom_image(e, options, temp_image_canvas, image_offset);
|
60
|
+
} else if (check_bounds) {
|
61
|
+
zoom_image_mouseleave();
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
function zoom_image_mouseleave(e) {
|
66
|
+
remove_image_zoomer();
|
67
|
+
}
|
68
|
+
|
69
|
+
function zoom_image(e, options, temp_image_canvas, image_offset) {
|
70
|
+
var coordinates = _prepare_coordinates(e, options, image_offset);
|
71
|
+
$(zoom_canvas_name).css({left: coordinates.page_x, top: coordinates.page_y, "z-index": 99});
|
72
|
+
try {
|
73
|
+
zoom_context.drawImage(temp_image_canvas.get(0), coordinates.image_x, coordinates.image_y, options.width, options.height, 0, 0, options.width, options.height);
|
74
|
+
} catch(err){};
|
75
|
+
}
|
76
|
+
|
77
|
+
function _prepare_coordinates(e, options, image_offset) {
|
78
|
+
var page_x = e.pageX, page_y = e.pageY, coordinates;
|
79
|
+
coordinates = {page_x: page_x - options.width / 2, page_y: page_y - options.height / 2};
|
80
|
+
coordinates.image_x = (page_x - image_offset.left) - (options.width / 2 / options.scale);
|
81
|
+
coordinates.image_y = (page_y - image_offset.top) - (options.height / 2 / options.scale);
|
82
|
+
return coordinates;
|
83
|
+
}
|
84
|
+
|
85
|
+
function _insert_temp_canvas(zoom_canvas_container, image) {
|
86
|
+
var width = image.width(), height = image.height(), temp_image_canvas;
|
87
|
+
zoom_canvas_container.append("<canvas id='temp_image_canvas' width='" + width + "' height='" + height + "' style='position: absolute; left: -5000px;'></canvas>");
|
88
|
+
temp_image_canvas = $("#temp_image_canvas");
|
89
|
+
temp_image_canvas_context = temp_image_canvas.get(0).getContext("2d");
|
90
|
+
temp_image_canvas_context.drawImage(image.get(0), 0, 0, width, height);
|
91
|
+
return temp_image_canvas;
|
92
|
+
}
|
93
|
+
|
94
|
+
function check_if_in_bounds(e, image, image_offset) {
|
95
|
+
if (e.pageX < image_offset.left) { // User moved mouse out in left direction
|
96
|
+
return false;
|
97
|
+
} else if (e.pageY < image_offset.top) { // User moved mouse out in top direction
|
98
|
+
return false;
|
99
|
+
} else if (e.pageX > image_offset.left + image.width()) { // User moved mouse out in right direction
|
100
|
+
return false;
|
101
|
+
} else if (e.pageY > image_offset.top + image.height()) { // User moved mouse out in bottom direction
|
102
|
+
return false;
|
103
|
+
}
|
104
|
+
return true;
|
105
|
+
}
|
106
|
+
|
107
|
+
function remove_image_zoomer() {
|
108
|
+
$(zoom_canvas_name).remove();
|
109
|
+
$(zoom_canvas_container_name).find("img").unwrap();
|
110
|
+
$("#temp_image_canvas").remove();
|
111
|
+
}
|
112
|
+
|
113
|
+
})(jQuery);
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'image_zoomer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "image_zoomer"
|
8
|
+
spec.version = ImageZoomer::VERSION
|
9
|
+
spec.authors = ["Imran Latif"]
|
10
|
+
spec.email = ["ilatif.bwp@gmail.com"]
|
11
|
+
spec.summary = %q{Image Zoomer}
|
12
|
+
spec.description = %q{This gem provides functionality for zooming images by using a jQuery plugin image_zoomer.}
|
13
|
+
spec.homepage = "http://i8ecoders.com/image_zoomer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
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
|
+
spec.post_install_message = "Thanks for installing image_zoomer gem."
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module ImageZoomer
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :width
|
4
|
+
attr_accessor :height
|
5
|
+
attr_accessor :zoom_level
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@width = 90
|
9
|
+
@height = 90
|
10
|
+
@zoom_level = 1.5
|
11
|
+
end
|
12
|
+
|
13
|
+
def set_options(&block)
|
14
|
+
block.yield(self)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class Railtie < Rails::Railtie
|
2
|
+
|
3
|
+
initializer "image_zoomer.configuration" do |app|
|
4
|
+
app.config.image_zoomer = ImageZoomer::Configuration.new
|
5
|
+
FileUtils.rm_rf("#{Rails.application.root}/tmp/cache/assets") if Rails.env.development?
|
6
|
+
end
|
7
|
+
|
8
|
+
initializer "image_zoomer.initialize_zoom_image_helper" do |app|
|
9
|
+
ActiveSupport.on_load(:action_view) do
|
10
|
+
include ImageZoomer
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module ImageZoomer
|
2
|
+
def zoom_image_tag(*args, &block)
|
3
|
+
options = insert_zoom_class(args.extract_options!)
|
4
|
+
args << options
|
5
|
+
image_tag(*args, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
def insert_zoom_class(options)
|
9
|
+
class_name = "image_zoomer"
|
10
|
+
if options.key?(:class)
|
11
|
+
options[:class] += " #{class_name}"
|
12
|
+
elsif options.key?('class')
|
13
|
+
options['class'] += " #{class_name}"
|
14
|
+
else
|
15
|
+
options[:class] = class_name
|
16
|
+
end
|
17
|
+
options
|
18
|
+
end
|
19
|
+
end
|
data/lib/image_zoomer.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "image_zoomer/version"
|
2
|
+
require 'image_zoomer/configuration'
|
3
|
+
require "image_zoomer/engine"
|
4
|
+
require "image_zoomer/zoom_image_helper"
|
5
|
+
require "image_zoomer/railtie"
|
6
|
+
|
7
|
+
# module ActionView
|
8
|
+
# module Helpers
|
9
|
+
# module AssetTagHelper
|
10
|
+
# include ImageZoomer
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
# end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: image_zoomer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Imran Latif
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: This gem provides functionality for zooming images by using a jQuery
|
42
|
+
plugin image_zoomer.
|
43
|
+
email:
|
44
|
+
- ilatif.bwp@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE
|
53
|
+
- LICENSE.txt
|
54
|
+
- README.md
|
55
|
+
- Rakefile
|
56
|
+
- app/assets/javascripts/image_zoomer.js
|
57
|
+
- app/assets/javascripts/image_zoomer_initializer.js
|
58
|
+
- app/assets/javascripts/image_zoomer_main.js
|
59
|
+
- app/assets/javascripts/image_zoomer_options.js.erb
|
60
|
+
- image_zoomer.gemspec
|
61
|
+
- lib/image_zoomer.rb
|
62
|
+
- lib/image_zoomer/configuration.rb
|
63
|
+
- lib/image_zoomer/engine.rb
|
64
|
+
- lib/image_zoomer/railtie.rb
|
65
|
+
- lib/image_zoomer/version.rb
|
66
|
+
- lib/image_zoomer/zoom_image_helper.rb
|
67
|
+
homepage: http://i8ecoders.com/image_zoomer
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message: Thanks for installing image_zoomer gem.
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.2.2
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: Image Zoomer
|
91
|
+
test_files: []
|