spree_product_hover_zoom 1.0.2

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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE +26 -0
  8. data/README.md +54 -0
  9. data/Rakefile +29 -0
  10. data/Versionfile +1 -0
  11. data/app/assets/images/zoom.gif +0 -0
  12. data/app/assets/javascripts/spree/backend/spree_product_hover_zoom.js +2 -0
  13. data/app/assets/javascripts/spree/frontend/spree_product_hover_zoom.js.coffee.erb +52 -0
  14. data/app/assets/stylesheets/spree/backend/spree_product_hover_zoom.css +4 -0
  15. data/app/assets/stylesheets/spree/frontend/spree_product_hover_zoom.css +25 -0
  16. data/app/models/spree/product_zoom_configuration.rb +3 -0
  17. data/app/overrides/spree/products/_thumbnails/add_lightbox_to_thumbnails.html.erb.deface +3 -0
  18. data/app/overrides/spree/products/_thumbnails/add_lightbox_to_thumbnails.html.erb.deface~HEAD +2 -0
  19. data/app/overrides/spree/products/_thumbnails/swap_product_variant_images.deface +3 -0
  20. data/app/overrides/spree/products/show.rb +6 -0
  21. data/app/views/spree/products/_hover_zoom.html.erb +1 -0
  22. data/app/views/spree/products/_image.html.erb +7 -0
  23. data/app/views/spree/products/_image0.html.erb +40 -0
  24. data/config/locales/en.yml +5 -0
  25. data/config/routes.rb +3 -0
  26. data/lib/generators/spree_product_hover_zoom/install/install_generator.rb +17 -0
  27. data/lib/spree_product_hover_zoom.rb +2 -0
  28. data/lib/spree_product_hover_zoom/engine.rb +34 -0
  29. data/lib/spree_product_hover_zoom/factories.rb +47 -0
  30. data/script/rails +7 -0
  31. data/spec/features/zoom_spec.rb +144 -0
  32. data/spec/products_images/1/mini/product1.jpg +0 -0
  33. data/spec/products_images/1/product/product1.jpg +0 -0
  34. data/spec/products_images/2/mini/product2.jpg +0 -0
  35. data/spec/products_images/2/product/product2.jpg +0 -0
  36. data/spec/products_images/3/mini/product1.jpg +0 -0
  37. data/spec/products_images/3/product/product1.jpg +0 -0
  38. data/spec/products_images/4/mini/product2.jpg +0 -0
  39. data/spec/products_images/4/product/product2.jpg +0 -0
  40. data/spec/products_images/info.txt +3 -0
  41. data/spec/spec_helper.rb +77 -0
  42. data/spree-zoom-on-hover.gif +0 -0
  43. data/spree_product_hover_zoom.gemspec +29 -0
  44. data/vendor/assets/images/store/blank.gif +0 -0
  45. data/vendor/assets/javascripts/drift.min.js +1 -0
  46. data/vendor/assets/javascripts/luminous.js +697 -0
  47. data/vendor/assets/stylesheets/drift-basic.css +151 -0
  48. data/vendor/assets/stylesheets/luminous-basic.css +195 -0
  49. metadata +245 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 328d354609d873fa6e05617148d57d2eed38856c
4
+ data.tar.gz: 05c94321bfc32ccad918a852089637899f7d689f
5
+ SHA512:
6
+ metadata.gz: d8f10f86edaeb77feae35254030fb841d4223bc2e27f883b032d7c6f4c98a0b632e88c5d3ebe780027c3202e79d24f13197456aa326e138dd01acd20dbddbd44
7
+ data.tar.gz: 1804aaa4a63ccc24a6dea198518aa6f62658f8ffba688a82ce2496581e21c590cdf500e4ef6f068bd85ad063a10bc7c9e1fd36e58fd8358d9fcacdc6c2849e18
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
10
+ spec/dummy
11
+ Gemfile.lock
12
+
13
+ /*.iml
14
+ /.rakeTasks
15
+ /.generators
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ spree_product_hover_zoom
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.4.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ Copyright (c) 2017 [name of plugin creator]
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification,
5
+ are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+ * Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ * Neither the name Spree nor the names of its contributors may be used to
13
+ endorse or promote products derived from this software without specific
14
+ prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ Spree Product - Gallery View and Hover Zoom
2
+ ===========================================
3
+
4
+ A Spree extension that adds gallery view and zoom-on-hover functionality for product images.
5
+ Gallery view is available thanks to the amazing work done on [Luminous](https://github.com/imgix/luminous).
6
+ Zoom on hover is available thanks to the amazing work done on [Drift](http://github.com/imgix/drift).
7
+ Forked from [robert-hromej/spree_product_zoom](https://github.com/robert-hromej/spree_product_zoom).
8
+
9
+ [![N|Solid](https://github.com/vinzloh/spree_product_hover_zoom/raw/master/spree-zoom-on-hover.gif)]()
10
+
11
+ Installation
12
+ =======
13
+
14
+ Add this extension to your Gemfile:
15
+
16
+ ```ruby
17
+ gem "spree_product_hover_zoom", :git => "git://github.com/vinzloh/spree_product_hover_zoom.git"
18
+ ```
19
+
20
+ Then run:
21
+
22
+ ```
23
+ bundle install
24
+ ```
25
+
26
+ Run:
27
+
28
+ ```
29
+ rails g spree_product_hover_zoom:install
30
+ ```
31
+
32
+ in order to copy over the required css and js files.
33
+
34
+ Once installation is complete, clicking on product thumbnails opens the gallery view, and hovering over the main product image opens a quick preview.
35
+
36
+ Customization
37
+ =============
38
+
39
+ To change the zoom factor, add the line below to your .js file:
40
+ ```
41
+ SpreeProductHoverZoom.zoomFactor = 1
42
+ ```
43
+
44
+ To change the hover pane height, override the css:
45
+ ```
46
+ .product-hover-zoom {
47
+ height: 500px;
48
+ }
49
+ ```
50
+
51
+ License
52
+ =======
53
+
54
+ This project has been released under the New BSD License, Copyright (c) 2017 Vinz Loh.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/packagetask'
4
+ require 'rubygems/package_task'
5
+ require 'rspec/core/rake_task'
6
+ require 'spree/testing_support/common_rake'
7
+
8
+ RSpec::Core::RakeTask.new
9
+
10
+ task :default => [:spec]
11
+
12
+ spec = eval(File.read('spree_product_hover_zoom.gemspec'))
13
+
14
+ Gem::PackageTask.new(spec) do |p|
15
+ p.gem_spec = spec
16
+ end
17
+
18
+ desc 'Release to gemcutter'
19
+ task :release => :package do
20
+ require 'rake/gemcutter'
21
+ Rake::Gemcutter::Tasks.new(spec).define
22
+ Rake::Task['gem:push'].invoke
23
+ end
24
+
25
+ desc 'Generates a dummy app for testing'
26
+ task :test_app do
27
+ ENV['LIB_NAME'] = 'spree_product_hover_zoom'
28
+ Rake::Task['common:test_app'].invoke
29
+ end
data/Versionfile ADDED
@@ -0,0 +1 @@
1
+ '2.1.x' => { :branch => 'master' }
Binary file
@@ -0,0 +1,2 @@
1
+ // Placeholder manifest file.
2
+ // the installer will append this file to the app vendored assets here: vendor/assets/javascripts/spree/frontend/all.js'
@@ -0,0 +1,52 @@
1
+ add_image_handlers = ->
2
+ ($ '#main-image').data 'selectedThumb', ($ '#main-image img').attr('src')
3
+ ($ 'ul.thumbnails li').eq(0).addClass 'selected'
4
+ ($ 'ul.thumbnails a').on 'click', (event) ->
5
+ ($ '#main-image').data 'selectedThumb', ($ event.currentTarget).attr('href')
6
+ ($ '#main-image').data 'selectedThumbId', ($ event.currentTarget).parent().attr('id')
7
+ ($ 'ul.thumbnails').find('li').removeClass 'selected'
8
+ ($ event.currentTarget).parent('li').addClass 'selected'
9
+ false
10
+
11
+ ($ 'ul.thumbnails li').on 'mouseenter', (event) ->
12
+ ($ '#main-image img').first().attr 'src', ($ event.currentTarget).find('a').attr('href')
13
+ ($ '[data-drift]').first().attr 'href', ($ event.currentTarget).find('a').attr('href')
14
+
15
+ # ($ 'ul.thumbnails li').on 'mouseleave', (event) ->
16
+ # ($ '#main-image img').first().attr 'src', ($ '#main-image').data('selectedThumb')
17
+ # ($ '[data-drift]').first().attr 'href', ($ '#main-image').data('selectedThumb')
18
+
19
+ window.SpreeProductHoverZoom = {
20
+ zoomFactor: 4,
21
+ handleTouch: true,
22
+ touchDelay: 0,
23
+ }
24
+
25
+ $ ->
26
+ add_image_handlers()
27
+
28
+ el_drift = $('[data-drift]')[0]
29
+
30
+ driftOptions =
31
+ paneContainer: $('[data-hook=product_hover_zoom]')[0]
32
+ zoomFactor: SpreeProductHoverZoom.zoomFactor
33
+ sourceAttribute: 'href'
34
+ handleTouch: SpreeProductHoverZoom.handleTouch
35
+ touchDelay: SpreeProductHoverZoom.touchDelay
36
+
37
+ new Drift(el_drift, driftOptions) if (el_drift && $(el_drift).attr('href').length > 0)
38
+
39
+ # Single zoom view for main product image
40
+ # new Luminous($('[data-luminous]')[0]);
41
+ # do nothing on main product image click
42
+ $('[data-luminous]').on 'click', (e) ->
43
+ e.preventDefault()
44
+ return
45
+
46
+ # Gallery view for thumbnails
47
+
48
+ # Whether pressing the arrow keys should move to the next/previous slide.
49
+ galleryOpts = arrowNavigation: true
50
+ # These options have the same defaults and potential values as the Luminous class.
51
+ luminousOpts = {}
52
+ new LuminousGallery($('ul.thumbnails > li > a'), galleryOpts, luminousOpts)
@@ -0,0 +1,4 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/backend/all.css'
4
+ */
@@ -0,0 +1,25 @@
1
+ /*
2
+ Placeholder manifest file.
3
+ the installer will append this file to the app vendored assets here: 'vendor/assets/stylesheets/spree/frontend/all.css'
4
+ */
5
+
6
+ /*
7
+ *= require drift-basic
8
+ */
9
+
10
+ /*
11
+ #product-images #main-image img.click-to-zoom { min-height: 0px; height: 12px; }
12
+ */
13
+ .product-hover-zoom {
14
+ position: absolute;
15
+ top: 0;
16
+ right: 0;
17
+ left: 0;
18
+ height: 400px;
19
+ }
20
+
21
+ .drift-link {
22
+ float: left;
23
+ cursor: zoom-in;
24
+ width: 100%;
25
+ }
@@ -0,0 +1,3 @@
1
+ class Spree::ProductZoomConfiguration < Spree::Preferences::Configuration
2
+ preference :default_image_style, :symbol, :default => :original
3
+ end
@@ -0,0 +1,3 @@
1
+ <!-- replace "erb[loud]:contains('image_tag')" -->
2
+ <!--original '1e84d3a5d442db03ee2f370d7b2f2988e9bfb66a'-->
3
+ <%= link_to(image_tag(i.attachment.url(:mini)), i.attachment.url(:product),:data => { :original => i.attachment.url(:original) }) %>
@@ -0,0 +1,2 @@
1
+ <!-- replace "erb[loud]:contains('image_tag')" -->
2
+ <%= link_to(image_tag(i.attachment.url(:mini)), i.attachment.url(:product),:data => { :original => i.attachment.url(:original) }) %>
@@ -0,0 +1,3 @@
1
+ insert_bottom '#product-thumbnails'
2
+ cut :start => 'erb:contains("@product.images.each do |i|")', :end => 'erb:contains("end")'
3
+ original 'ac7f68f024a55240dd25de7c792ebbdcbdfd2121'
@@ -0,0 +1,6 @@
1
+ Deface::Override.new(
2
+ virtual_path: 'spree/products/show',
3
+ name: 'add_hover_zoom_to_products_show',
4
+ insert_after: '[data-hook="product_right_part_wrap"]',
5
+ partial: 'spree/products/hover_zoom.html.erb'
6
+ )
@@ -0,0 +1 @@
1
+ <div data-hook="product_hover_zoom" class="product-hover-zoom"></div>
@@ -0,0 +1,7 @@
1
+ <% if defined?(image) && image %>
2
+ <%= image_tag image.attachment.url(:product), :itemprop => "image" %>
3
+ <% else %>
4
+ <a data-luminous data-drift href="<%= @product.images.first.attachment.url(:product) if @product.images.present? %>" class="drift-link">
5
+ <%= product_image(@product, :itemprop => "image", data: { image: '' }) %>
6
+ </a>
7
+ <% end %>
@@ -0,0 +1,40 @@
1
+ <% if defined?(image) && image %>
2
+ <%= link_to image_tag(image.attachment.url(:product), :itemprop => "image"), image.attachment.url(:original), :class => 'fancybox zoom-image' %>
3
+ <br />
4
+ <%= link_to image.attachment.url(:original), :class => 'fancybox zoom-image' %>
5
+ <% else %>
6
+ <% if @product.images.empty? and @product.has_variants? and @product.variant_images.empty? %>
7
+ <%= product_image(@product, :itemprop => "large") %>
8
+ <% else %>
9
+ <% if @product.images.empty? %>
10
+ <% @p = @product.variants.first %>
11
+ <% else %>
12
+ <% @p = @product %>
13
+ <% end %>
14
+ <%= link_to product_image(@product, :itemprop => "image", :class => 'zoom-click', data: { zoom: @p.images.first.attachment.url(Spree::ProductZoom::Config.default_image_style) }), @p.images.first.attachment.url(Spree::ProductZoom::Config.default_image_style), :class => 'zoom-image large-image zoom-click', :rel => 'gallery' %>
15
+ <br/>
16
+ <!-- PROBLEM: still in div#main-image, will be overwritten by javascript -->
17
+ <%= link_to image_tag('zoom.gif', alt: 'zoom image', class: 'click-to-zoom'), @p.images.first.attachment.url(Spree::ProductZoom::Config.default_image_style), :class => 'zoom-image click-to-zoom', :rel => 'gallery' %>
18
+ <div id="gallery" style="display:none;">
19
+ <% if @product.has_variants? %>
20
+ <% first_variant_id = @product.variants.first.id %>
21
+ <% @product.variants.each do |variant| %>
22
+ <% clazz = 'fancybox productid-' + variant.id.to_s %>
23
+ <% if first_variant_id == variant.id %>
24
+ <% clazz = 'fancybox productid-' + variant.id.to_s %>
25
+ <% else %>
26
+ <% clazz = 'productid-' + variant.id.to_s %>
27
+ <% end %>
28
+ <% variant.images.each do |i| %>
29
+ <% next if @product.images.include?(i) %>
30
+ <%= link_to image_tag(i.attachment.url(:product)), i.attachment.url(Spree::ProductZoom::Config.default_image_style), :class => clazz, :rel => 'gallery' %>
31
+ <% end %>
32
+ <% end %>
33
+ <% end %>
34
+ <% @product.images.each do |img| %>
35
+ <% clazz = 'master productid-' + @p.id.to_s + ' fancybox' %>
36
+ <%= link_to image_tag(img.attachment.url(:product)), img.attachment.url(Spree::ProductZoom::Config.default_image_style), :class => clazz, :rel => 'gallery' %>
37
+ <% end %>
38
+ </div>
39
+ <% end %>
40
+ <% end %>
@@ -0,0 +1,5 @@
1
+ # Sample localization file for English. Add more files in this directory for other locales.
2
+ # See https://github.com/svenfuchs/rails-i18n/tree/master/rails%2Flocale for starting points.
3
+
4
+ en:
5
+ hello: "Hello world"
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Spree::Core::Engine.routes.draw do
2
+ # Add your extension routes here
3
+ end
@@ -0,0 +1,17 @@
1
+ module SpreeProductHoverZoom
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+
5
+ def add_javascripts
6
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require drift.min\n"
7
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require luminous\n"
8
+ append_file 'vendor/assets/javascripts/spree/frontend/all.js', "//= require spree/frontend/spree_product_hover_zoom\n"
9
+ end
10
+
11
+ def add_stylesheets
12
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require luminous-basic\n", :before => /\*\//, :verbose => true
13
+ inject_into_file 'vendor/assets/stylesheets/spree/frontend/all.css', " *= require spree/frontend/spree_product_hover_zoom\n", :before => /\*\//, :verbose => true
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'spree_core'
2
+ require 'spree_product_hover_zoom/engine'
@@ -0,0 +1,34 @@
1
+ module Spree::ProductZoom; end
2
+
3
+ module SpreeProductHoverZoom
4
+ class Engine < Rails::Engine
5
+ require 'spree/core'
6
+ isolate_namespace Spree
7
+ engine_name 'spree_product_hover_zoom'
8
+
9
+ config.autoload_paths += %W(#{config.root}/lib)
10
+
11
+ # use rspec for tests
12
+ config.generators do |g|
13
+ g.test_framework :rspec
14
+ end
15
+
16
+ initializer :assets do |config|
17
+ Rails.application.config.assets.precompile += %w( store/blank.gif )
18
+ end
19
+
20
+ initializer("spree.product_zoom.preferences",
21
+ :after => "spree.environment",
22
+ :before => :load_config_initializers) do |app|
23
+ Spree::ProductZoom::Config = Spree::ProductZoomConfiguration.new
24
+ end
25
+
26
+ def self.activate
27
+ Dir.glob(File.join(File.dirname(__FILE__), '../../app/**/*_decorator*.rb')) do |c|
28
+ Rails.configuration.cache_classes ? require(c) : load(c)
29
+ end
30
+ end
31
+
32
+ config.to_prepare &method(:activate).to_proc
33
+ end
34
+ end
@@ -0,0 +1,47 @@
1
+ include ActionDispatch::TestProcess
2
+
3
+ FactoryGirl.define do
4
+ factory :product1, class: Spree::Product do
5
+ name "Some Product"
6
+ available_on { 1.year.ago }
7
+ shipping_category_id 1
8
+ tax_category_id 1
9
+ price 29.99
10
+ sku 'p1v'
11
+ end
12
+
13
+ factory :variant1, class: Spree::Variant do
14
+ sku 'p1v1'
15
+ is_master '0'
16
+ end
17
+ factory :variant2, class: Spree::Variant do
18
+ sku 'p1v2'
19
+ is_master '0'
20
+ end
21
+
22
+ factory :option_type1, class: Spree::OptionType do
23
+ name "opt"
24
+ presentation "Some Option"
25
+ end
26
+ factory :option_value1, class: Spree::OptionValue do
27
+ name "a"
28
+ presentation "a option value"
29
+ end
30
+ factory :option_value2, class: Spree::OptionValue do
31
+ name "b"
32
+ presentation "b option value"
33
+ end
34
+
35
+
36
+
37
+ factory :image1, class: Spree::Image do
38
+ attachment_content_type "image/jpeg"
39
+ attachment_file_name "product1.jpg"
40
+ alt "Product Image 1"
41
+ end
42
+ factory :image2, class: Spree::Image do
43
+ attachment_content_type "image/jpeg"
44
+ attachment_file_name "product2.jpg"
45
+ alt "Product Image 2"
46
+ end
47
+ end