forked from Antiarchitect/spree-facebox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfacebox_extension.rb
More file actions
41 lines (35 loc) · 1.16 KB
/
facebox_extension.rb
File metadata and controls
41 lines (35 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class FaceboxExtension < Spree::Extension
version "0.1"
description "Spree image zoom using facebox: http://github.com/defunkt/facebox"
url "http://github.com/Antiarchitect/spree-facebox"
def activate
# Add an extra large (xl) size to use for zooming.
Image.attachment_definitions[:attachment][:styles] =
{ :mini => '48x48>', :small => '100x100>', :product => '240x240>',
:large => '600x600>', :xl => '900x900>' }
ProductsHelper.class_eval do
def image_controls
@image_controls ||= Facebox::ImageControls.new(@product)
end
end
Product.class_eval do
def has_image_without_style?(style)
return true if contains_image_without_style?(images, style)
if !variants.blank?
variants.each do |variant|
return true if contains_image_without_style?(variant.images, style)
end
end
return false
end
private
def contains_image_without_style?(images, style)
return false if images.blank?
images.each do |image|
return true unless image.attachment.path(style)
end
return false
end
end
end
end