picture_zoomer 1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b92460d3662dccfdb553f636500ab4dbd3b89ffe
4
+ data.tar.gz: bc046fe02df2fd63307abbc4bdf802a46f77290e
5
+ SHA512:
6
+ metadata.gz: 2f6a509edae7dece0a3292e9341bf3571d11d1ec2d0392c6f9d7b25f8cc794f0f4f48911a60dd29aff51469d309039d7d69744d6f15ab3c98c9c63cb998c56dc
7
+ data.tar.gz: 0bde8ca21c1f3aa6aeba5ed90b1f200d77dc34657b4b0963f74df59bfaebe3e5b08a54bc4e212b2031e3a2ada9f3e371fb8acaafc46821d0897c09c08ebd5073
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright © 2015 LICO Innovations
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ 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, fitness
17
+ for a particular purpose and noninfringement. In no event shall the authors or
18
+ copyright holders be liable for any claim, damages or other liability, whether
19
+ in an action of contract, tort or otherwise, arising from, out of or in
20
+ connection with the software or the use or other dealings in the software.
data/README.markdown ADDED
@@ -0,0 +1,49 @@
1
+ [![Gem Version](https://badge.fury.io/rb/picture_zoomer.svg)](http://badge.fury.io/rb/picture_zoomer)
2
+
3
+ [Here's a demo](https://cdn.rawgit.com/bluerail/picture_zoomer/master/demo.html)
4
+
5
+ Simple "zooming lightbox" that doesn't suck.
6
+
7
+ This is a fairly simple piece of JS code, but also something I've re-written a
8
+ number of times over the last few years. So here's the "canonical version".
9
+
10
+ Usage
11
+ =====
12
+ Include the [JavaScript code](https://github.com/bluerail/picture_zoomer/tree/master/lib/assets/javascripts). For Ruby on Rails, you can use the gem (see below).
13
+
14
+ All you need to do after that is tell it which images to zoom:
15
+
16
+ $('img').picture_zoomer()
17
+
18
+ The larger version is loaded either from the `data-large` or `src` attribute:
19
+
20
+ <img src="smaller_version.jpg" data-large="larger-version.jpg">
21
+ <img src="large_version.jpg" style="width: 100px">
22
+
23
+ or if you also want your image to do something without JS:
24
+
25
+ <a href="larger-version.jpg">
26
+ <img src="smaller_version.jpg" data-large="larger-version.jpg">
27
+ </a>
28
+
29
+ There's one (optional) argument: the animation speed. The default is 400ms.
30
+
31
+ // Very fast!
32
+ $('img').picture_zoomer(100)
33
+
34
+ // Just show a large version (don't animate)
35
+ $('img').picture_zoomer(0)
36
+
37
+ That's all there's to it :-)
38
+
39
+ Ruby on Rails installation
40
+ --------------------------
41
+ This is packaged as a Ruby gem ready to use in a Rails app.
42
+
43
+ Add to your `Gemfile`
44
+
45
+ gem 'picture_zoomer'
46
+
47
+ Add to your `application.js`:
48
+
49
+ // =require picture_zoomer
@@ -0,0 +1,85 @@
1
+ // Generated by CoffeeScript 1.9.1
2
+ (function() {
3
+ 'use strict';
4
+ var get_scroll, zoom;
5
+
6
+ jQuery.fn.picture_zoomer = function(speed) {
7
+ if (speed == null) {
8
+ speed = 400;
9
+ }
10
+ return $(this).on('click', function(e) {
11
+ e.preventDefault();
12
+ if ($(this).is('img')) {
13
+ return zoom($(this), speed);
14
+ } else {
15
+ return zoom($(this).find('img'), speed);
16
+ }
17
+ });
18
+ };
19
+
20
+ get_scroll = function() {
21
+ return document.documentElement.scrollTop || document.body.scrollTop;
22
+ };
23
+
24
+ zoom = function(img, speed) {
25
+ var large, offset;
26
+ large = $(new Image());
27
+ large.attr('src', img.attr('data-large') || img.attr('src'));
28
+ offset = img.offset();
29
+ return large.on('load', function() {
30
+ var close, height, w_height, w_width, width;
31
+ width = large.prop('width');
32
+ height = large.prop('height');
33
+ w_width = $(window).width() - 25;
34
+ w_height = $(window).height() - 25;
35
+ if (width > w_width) {
36
+ height = height / (width / w_width);
37
+ width = w_width;
38
+ }
39
+ if (height > w_height) {
40
+ width = width / (height / w_height);
41
+ height = w_height;
42
+ }
43
+ large.css({
44
+ width: img.width(),
45
+ height: img.height(),
46
+ left: offset.left,
47
+ top: offset.top,
48
+ position: 'absolute',
49
+ 'box-shadow': '0 0 8px rgba(0, 0, 0, .3)',
50
+ 'z-index': 5000
51
+ });
52
+ $(document.body).append(large);
53
+ large.animate({
54
+ width: width,
55
+ height: height,
56
+ left: ($(window).width() - width) / 2,
57
+ top: ($(window).height() + $('#menu').height() - height) / 2 + get_scroll()
58
+ }, {
59
+ duration: speed
60
+ });
61
+ close = function() {
62
+ return large.animate({
63
+ width: img.width(),
64
+ height: img.height(),
65
+ left: offset.left,
66
+ top: offset.top
67
+ }, {
68
+ duration: speed,
69
+ complete: function() {
70
+ return large.remove();
71
+ }
72
+ });
73
+ };
74
+ $(document.body).one('click', close);
75
+ return $(document).on('keydown.photo_viewer', function(e) {
76
+ if (e.keyCode !== 27) {
77
+ return;
78
+ }
79
+ close();
80
+ return $(document).off('keydown.photo_viewer');
81
+ });
82
+ });
83
+ };
84
+
85
+ }).call(this);
@@ -0,0 +1,79 @@
1
+ 'use strict'
2
+
3
+ # Simple "zooming lightbox" that doesn't suck.
4
+ #
5
+ # Basic usage:
6
+ # $('.body img').picture_zoomer()
7
+ #
8
+ # // Faster animation
9
+ # $('.body img').picture_zoomer(200)
10
+ #
11
+ # // Don't animate
12
+ # $('.body img').picture_zoomer(0)
13
+ #
14
+ # The url for the large version is either 'data-large', or the image src
15
+ jQuery.fn.picture_zoomer = (speed=400) ->
16
+ $(this).on 'click', (e) ->
17
+ e.preventDefault()
18
+ if $(this).is('img')
19
+ zoom $(this), speed
20
+ else
21
+ zoom $(this).find('img'), speed
22
+
23
+
24
+ get_scroll = -> document.documentElement.scrollTop or document.body.scrollTop
25
+
26
+ zoom = (img, speed) ->
27
+ large = $(new Image())
28
+ large.attr 'src', (img.attr('data-large') or img.attr('src'))
29
+ offset = img.offset()
30
+
31
+ large.on 'load', ->
32
+ width = large.prop 'width'
33
+ height = large.prop 'height'
34
+
35
+ # Don't make it larger than the window
36
+ w_width = $(window).width() - 25
37
+ w_height = $(window).height() - 25
38
+ if width > w_width
39
+ height = height / (width / w_width)
40
+ width = w_width
41
+ if height > w_height
42
+ width = width / (height / w_height)
43
+ height = w_height
44
+
45
+ large.css
46
+ width: img.width()
47
+ height: img.height()
48
+ left: offset.left
49
+ top: offset.top
50
+ position: 'absolute'
51
+ 'box-shadow': '0 0 8px rgba(0, 0, 0, .3)'
52
+ 'z-index': 5000
53
+ $(document.body).append large
54
+
55
+ large.animate {
56
+ width: width
57
+ height: height
58
+ left: ($(window).width() - width) / 2
59
+ top: ($(window).height() + $('#menu').height() - height) / 2 + get_scroll()
60
+ }, {
61
+ duration: speed
62
+ }
63
+
64
+ # Close
65
+ close = ->
66
+ large.animate {
67
+ width: img.width()
68
+ height: img.height()
69
+ left: offset.left
70
+ top: offset.top
71
+ }, {
72
+ duration: speed
73
+ complete: -> large.remove()
74
+ }
75
+ $(document.body).one 'click', close
76
+ $(document).on 'keydown.photo_viewer', (e) ->
77
+ return unless e.keyCode is 27 # Esc
78
+ close()
79
+ $(document).off 'keydown.photo_viewer'
@@ -0,0 +1,7 @@
1
+ module PictureZoomer
2
+ end
3
+
4
+ if defined? ::Rails
5
+ class PictureZoomer::Engine < ::Rails::Engine
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: picture_zoomer
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Martin Tournoij
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jquery-rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description:
28
+ email:
29
+ - martin@arp242.net
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - MIT-LICENSE
35
+ - README.markdown
36
+ - lib/assets/javascripts/picture_zoomer.js
37
+ - lib/assets/javascripts/picture_zoomer.js.coffee
38
+ - lib/picture_zoomer.rb
39
+ homepage: https://github.com/bluerail/picture_zoomer
40
+ licenses:
41
+ - MIT
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.4.5.1
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Simple "zooming lightbox" that doesn't suck.
63
+ test_files: []