Skip to content
Browse files

Add modifications from railsdog/master

  • Loading branch information...
1 parent 91d5fc8 commit 20dffb6088c905509a68a64b019214ea114e1310 @romul committed Sep 2, 2009
Showing with 45 additions and 1 deletion.
  1. +45 −1 app/views/products/_thumbnails.html.erb
View
46 app/views/products/_thumbnails.html.erb
@@ -17,6 +17,50 @@ $(function() {
<li><%= link_to_image(i.attachment, product.name) %></li>
<% end -%>
</ul>
+ <% if @product.has_variants?
+ has_checked = false %>
+ <ul id="variant-thumbnails" class="thumbnails">
+ <% product.variants.each do |v|
+ checked = !has_checked && (v.available?)
+ has_checked = true if checked
+
+ if checked
+ v.images.each do |i| %>
+ <li><%= link_to_image(i.attachment, product.name) %></li>
+ <% end %>
+ <% end %>
+ <% end %>
+ </ul>
+ <% end %>
</div>
+ <script type="text/javascript" charset="utf-8">
+
+ var images = new Array();
+ <% product.variants.each do |v| %>
+ images[<%= v.id.to_s %>] = new Array();
+ <% v.images.each_with_index do |image, i| %>
+ images[<%= v.id.to_s %>][<%= i %>] = '<%= image.attachment.url(:mini) %>';
+ <% end %>
+ <% end %>
+
+ var add_image_handlers = function(){
+ $("#main-image").data('selectedThumb', $('#main-image img').attr('src'));
+ $('ul.thumbnails li').eq(0).addClass('selected');
+ $('ul.thumbnails li a').click(function() {
+ $("#main-image").data('selectedThumb', $(this).attr('href'));
+ $('ul.thumbnails li').removeClass('selected');
+ $(this).parent('li').addClass('selected');
+ return false;
+ }).hover(
+ function() {
+ $('#main-image img').attr('src', $(this).attr('href').replace('mini', 'product'));
+ },
+ function() {
+ $('#main-image img').attr('src', $("#main-image").data('selectedThumb'));
+ }
+ );
+ };
+
+ jQuery(document).ready(function(){ add_image_handlers(); });
+ </script>
<% end %>
-

0 comments on commit 20dffb6

Please sign in to comment.
Something went wrong with that request. Please try again.