Permalink
Browse files

try to fix for spree 1-3-stable

  • Loading branch information...
damianogiacomello committed Mar 3, 2013
1 parent 4873913 commit 33e082dbf6a1579c2598a5f382a258cd889110e3
View
@@ -22,21 +22,24 @@ Example
1. add slideshow helper method in your view:
<pre>
- <%= insert_slideshow %>
+ <%= insert_slideshow() %>
</pre>
add slides for the slideshow in the admin section
2. Additional options:
<pre>
- <%= insert_slideshow(:category => "my_category") %>
+ {
+ :id => "slideshow"
+ :class => "first_slideshow"
+ :category => "my_category"
+ :style => "custom"
+ :auto => true|false
+ :next_text => ">>"
+ :prev_text => "<<"
+ :next_selector => "bx-next"
+ :prev_selector => "bx-prev"
+ :pagination_class => "pagination"
+ :show_content => true|false
+ }
</pre>
-displays slides for which the category column, dafault is "home"
-<pre>
- <%= insert_slideshow(:style => "small") %>
-</pre>
-style layout for slideshow: [small, medium, slide, default => custom]
-<pre>
- <%= insert_slideshow(:enable_content => true/false, :style => "custom", :category => "custom") %>
-</pre>
-added a content_tag for display title and description of slide
Copyright (c) 2012 [Damiano Giacomello], released under the New BSD License
@@ -0,0 +1,41 @@
+$(document).ready(function() {
+
+ $('.destroy_style').live("click", function(e) {
+ e.preventDefault();
+ $(this).parent().remove();
+ });
+
+ $('.destroy_new_slide_styles').live("click", function(e) {
+ e.preventDefault();
+ $(this).closest('.new_slide_styles').remove();
+ });
+
+ // Handle adding new styles
+ var styles_hash_index = 1;
+ $('.add_new_style').live("click", function(e) {
+ e.preventDefault();
+ $('#new-styles').append(generate_html_for_hash("new_slide_styles", styles_hash_index));
+ });
+
+ // Generates html for new paperclip styles form fields
+ generate_html_for_hash = function(hash_name, index) {
+ var html = '<div class="' + hash_name + ' row"><div class="field">';
+ html += '<div class="five columns">';
+ html += '<label for="' + hash_name + '_' + index + '_name">';
+ html += Spree.translations.name + '</label>';
+ html += '<input id="' + hash_name + '_' + index + '_name" name="' + hash_name + '[' + index + '][name]" type="text" class="fullwidth"><br>';
+ html += '</div><div class="five columns">'
+ html += '<label for="' + hash_name + '_' + index + '_value">';
+ html += Spree.translations.value + '</label>';
+ html += '<input id="' + hash_name + '_' + index + '_value" name="' + hash_name + '[' + index + '][value]" type="text" class="fullwidth">';
+ html += '</div><div class="two columns">'
+ html += '<a href="#" title="' + Spree.translations.destroy + '" class="destroy_' + hash_name + ' with-tip button" style="margin-top: 19px;"><i class="icon-trash"></i> &nbsp; ' + Spree.translations.destroy + '</a>';
+ html += '</div></div></div>';
+
+ index += 1;
+ return html;
+ };
+
+
+
+});
@@ -438,10 +438,10 @@
if(type == 'slide'){
// set the property value
el.css(slider.animProp, propValue);
- // bind a callback method - executes when CSS transition completes
- el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
- // unbind the callback
- el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
+ // on a callback method - executes when CSS transition completes
+ el.on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
+ // off the callback
+ el.off('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
updateAfterSlideTransition();
});
}else if(type == 'reset'){
@@ -450,10 +450,10 @@
// make the transition use 'linear'
el.css('-' + slider.cssPrefix + '-transition-timing-function', 'linear');
el.css(slider.animProp, propValue);
- // bind a callback method - executes when CSS transition completes
- el.bind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
- // unbind the callback
- el.unbind('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
+ // on a callback method - executes when CSS transition completes
+ el.on('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd', function(){
+ // off the callback
+ el.off('transitionend webkitTransitionEnd oTransitionEnd MSTransitionEnd');
// reset the position
setPositionProperty(params['resetValue'], 'reset', 0);
// start the loop again
@@ -534,9 +534,9 @@
var appendControls = function(){
slider.controls.next = $('<a class="bx-next" href="">' + slider.settings.nextText + '</a>');
slider.controls.prev = $('<a class="bx-prev" href="">' + slider.settings.prevText + '</a>');
- // bind click actions to the controls
- slider.controls.next.bind('click', clickNextBind);
- slider.controls.prev.bind('click', clickPrevBind);
+ // on click actions to the controls
+ slider.controls.next.on('click', clickNextBind);
+ slider.controls.prev.on('click', clickPrevBind);
// if nextSlector was supplied, populate it
if(slider.settings.nextSelector){
$(slider.settings.nextSelector).append(slider.controls.next);
@@ -564,7 +564,7 @@
slider.controls.stop = $('<div class="bx-controls-auto-item"><a class="bx-stop" href="">' + slider.settings.stopText + '</a></div>');
// add the controls to the DOM
slider.controls.autoEl = $('<div class="bx-controls-auto" />');
- // bind click actions to the controls
+ // on click actions to the controls
slider.controls.autoEl.delegate('.bx-start', 'click', clickStartBind);
slider.controls.autoEl.delegate('.bx-stop', 'click', clickStopBind);
// if autoControlsCombine, insert only the "start" control
@@ -852,7 +852,7 @@
start: {x: 0, y: 0},
end: {x: 0, y: 0}
}
- slider.viewport.bind('touchstart', onTouchStart);
+ slider.viewport.on('touchstart', onTouchStart);
}
/**
@@ -871,10 +871,10 @@
// record the starting touch x, y coordinates
slider.touch.start.x = orig.changedTouches[0].pageX;
slider.touch.start.y = orig.changedTouches[0].pageY;
- // bind a "touchmove" event to the viewport
- slider.viewport.bind('touchmove', onTouchMove);
- // bind a "touchend" event to the viewport
- slider.viewport.bind('touchend', onTouchEnd);
+ // on a "touchmove" event to the viewport
+ slider.viewport.on('touchmove', onTouchMove);
+ // on a "touchend" event to the viewport
+ slider.viewport.on('touchend', onTouchEnd);
}
}
@@ -909,7 +909,7 @@
* - DOM event object
*/
var onTouchEnd = function(e){
- slider.viewport.unbind('touchmove', onTouchMove);
+ slider.viewport.off('touchmove', onTouchMove);
var orig = e.originalEvent;
var value = 0;
// record end x, y positions
@@ -947,7 +947,7 @@
}
}
}
- slider.viewport.unbind('touchend', onTouchEnd);
+ slider.viewport.off('touchend', onTouchEnd);
}
/**
@@ -1172,6 +1172,6 @@
/*jshint curly: true, eqeqeq: true, noempty: true, strict: true, undef: true, browser: true */
/*global jQuery: false */
-(function(c,n){var l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";c.fn.imagesLoaded=function(f){function m(){var b=c(i),a=c(h);d&&(h.length?d.reject(e,b,a):d.resolve(e));c.isFunction(f)&&f.call(g,e,b,a)}function j(b,a){b.src===l||-1!==c.inArray(b,k)||(k.push(b),a?h.push(b):i.push(b),c.data(b,"imagesLoaded",{isBroken:a,src:b.src}),o&&d.notifyWith(c(b),[a,e,c(i),c(h)]),e.length===k.length&&(setTimeout(m),e.unbind(".imagesLoaded")))}var g=this,d=c.isFunction(c.Deferred)?c.Deferred():
-0,o=c.isFunction(d.notify),e=g.find("img").add(g.filter("img")),k=[],i=[],h=[];c.isPlainObject(f)&&c.each(f,function(b,a){if("callback"===b)f=a;else if(d)d[b](a)});e.length?e.bind("load.imagesLoaded error.imagesLoaded",function(b){j(b.target,"error"===b.type)}).each(function(b,a){var d=a.src,e=c.data(a,"imagesLoaded");if(e&&e.src===d)j(a,e.isBroken);else if(a.complete&&a.naturalWidth!==n)j(a,0===a.naturalWidth||0===a.naturalHeight);else if(a.readyState||a.complete)a.src=l,a.src=d}):m();return d?d.promise(g):
+(function(c,n){var l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";c.fn.imagesLoaded=function(f){function m(){var b=c(i),a=c(h);d&&(h.length?d.reject(e,b,a):d.resolve(e));c.isFunction(f)&&f.call(g,e,b,a)}function j(b,a){b.src===l||-1!==c.inArray(b,k)||(k.push(b),a?h.push(b):i.push(b),c.data(b,"imagesLoaded",{isBroken:a,src:b.src}),o&&d.notifyWith(c(b),[a,e,c(i),c(h)]),e.length===k.length&&(setTimeout(m),e.off(".imagesLoaded")))}var g=this,d=c.isFunction(c.Deferred)?c.Deferred():
+0,o=c.isFunction(d.notify),e=g.find("img").add(g.filter("img")),k=[],i=[],h=[];c.isPlainObject(f)&&c.each(f,function(b,a){if("callback"===b)f=a;else if(d)d[b](a)});e.length?e.on("load.imagesLoaded error.imagesLoaded",function(b){j(b.target,"error"===b.type)}).each(function(b,a){var d=a.src,e=c.data(a,"imagesLoaded");if(e&&e.src===d)j(a,e.isBroken);else if(a.complete&&a.naturalWidth!==n)j(a,0===a.naturalWidth||0===a.naturalHeight);else if(a.readyState||a.complete)a.src=l,a.src=d}):m();return d?d.promise(g):
g}})(jQuery);
@@ -0,0 +1,45 @@
+module Spree
+ module Admin
+ class SlideSettingsController < Spree::Admin::BaseController
+ def edit
+ @styles = ActiveSupport::JSON.decode(Spree::Config[:attachment_styles])
+ end
+
+ def update
+ update_styles(params)
+
+ Spree::Config.set(params[:preferences])
+ update_paperclip_settings
+
+ respond_to do |format|
+ format.html {
+ flash[:success] = t(:slide_settings_updated)
+ redirect_to edit_admin_image_settings_path
+ }
+ end
+ end
+
+
+ private
+
+ def update_styles(params)
+ params[:new_slide_styles].each do |index, style|
+ params[:slide_styles][style[:name]] = style[:value] unless style[:value].empty?
+ end if params[:new_slide_styles].present?
+
+ styles = params[:slide_styles]
+
+ Spree::Config[:slide_styles] = ActiveSupport::JSON.encode(styles) unless styles.nil?
+ end
+
+ def update_paperclip_settings
+
+ Spree::Slide.attachment_definitions[:attachment][:styles] = ActiveSupport::JSON.decode(Spree::Config[:slide_styles])
+ Spree::Slide.attachment_definitions[:attachment][:path] = Spree::Config[:slide_path]
+ Spree::Slide.attachment_definitions[:attachment][:default_url] = Spree::Config[:slide_default_url]
+ Spree::Slide.attachment_definitions[:attachment][:default_style] = Spree::Config[:slide_default_style]
+ end
+ end
+ end
+end
+
@@ -6,25 +6,14 @@ class SlidesController < ResourceController
create.before :set_slideshow
update.before :set_slideshow
destroy.before :destroy_before
-
- def update_positions
- params[:positions].each do |id, index|
- Spree::Slide.update_all(['position=?', index], ['id=?', id])
- end
-
- respond_to do |format|
- format.html { redirect_to admin_slideshow_slides_url(@slideshow) }
- format.js { render :text => 'Ok' }
- end
- end
private
def location_after_save
- admin_slideshow_images_url(@slideshow)
+ admin_slideshow_slides_url(@slideshow)
end
def load_data
- @slideshow = Spree::Slideshow.find(params[:slideshow_id].to_i)
+ @slideshow = Spree::Slideshow.find(params[:slideshow_id])
end
def set_slideshow
@@ -1,7 +1,11 @@
module Spree
module Admin
class SlideshowsController < ResourceController
-
+
+ def show
+ redirect_to( :action => :edit )
+ end
+
def location_after_save
edit_admin_slideshow_url(@slideshow)
end
@@ -6,7 +6,7 @@ def insert_slideshow(params={})
params[:id] ||= "slideshow"
params[:class] ||= "first_slideshow"
params[:category] ||= "home"
- params[:auto_play] ||= false
+ params[:auto] ||= false
params[:next_text] ||= '>>'
params[:prev_text] ||= '<<'
params[:next_selector] ||= 'bx-next'
@@ -22,14 +22,18 @@ def insert_slideshow(params={})
res << "<script type='text/javascript'>
$(function() {
$('##{params[:id]}').bxSlider({
- auto: #{params[:auto_play]},
+ auto: #{params[:auto]},
+ autoStart: #{@@slideshow.auto_start},
+ mode: #{@@slideshow.mode},
controls: #{@@slideshow.enable_navigation},
nextText: '#{params[:next_text]}',
nextSelector: '#{params[:next_selector]}',
prevText: '#{params[:prev_text]}',
prevSelector: '#{params[:prev_selector]}',
speed: 2000,
pager: #{@@slideshow.enable_pagination},
+ infiniteLoop: #{@@slideshow.infinite_loop},
+ hideControlOnEnd: #{@@slideshow.hide_control_on_end},
autoHover: true,
pagerSelector: '#{params[:pagination_class]}'
});
@@ -40,18 +44,18 @@ def insert_slideshow(params={})
end
def slide_images(params, slideshow)
- params[:style] ||= "custom"
+ params[:style] ||= "medium"
params[:show_content] ||= false
- max = slideshow.slides.count
- slides = slideshow.slides.limit(max).sort_by { |slide| slide.position }
+ max = slideshow.slides.enable.count
+ slides = slideshow.slides.enable.limit(max).sort_by { |slide| slide.position }
slides.map do |slide|
content_tag(:div, :class => "slide_list") do
divs = []
divs << link_to(image_tag(slide.attachment.url(params[:style].to_sym)), (slide.url.blank? ? "javascript: void(0)" : slide.url), { :title => slide.title })
if params[:show_content]
- divs << content_tag(:div, content_tag(:strong, raw(slide.title)) + content_tag(:p, raw(slide.content)), :class => "caption")
+ divs << content_tag(:div, content_tag(:strong, raw(slide.title)) + content_tag(:p, raw(slide.presentation)), :class => "caption")
end
divs.join.html_safe
@@ -0,0 +1,25 @@
+# This is the primary location for defining spree preferences
+#
+# The expectation is that this is created once and stored in
+# the spree environment
+#
+# setters:
+# a.color = :blue
+# a[:color] = :blue
+# a.set :color = :blue
+# a.preferred_color = :blue
+#
+# getters:
+# a.color
+# a[:color]
+# a.get :color
+# a.preferred_color
+#
+Spree::AppConfiguration.class_eval do
+ # Preferences related to slide settings
+ preference :slide_default_url, :string, :default => '/spree/slides/:id/:style/:basename.:extension'
+ preference :slide_path, :string, :default => ':rails_root/public/spree/slides/:id/:style/:basename.:extension'
+ preference :slide_url, :string, :default => '/spree/slides/:id/:style/:basename.:extension'
+ preference :slide_styles, :string, :default => "{\"mini\":\"60x60#\",\"small\":\"300x100#\",\"medium\":\"600x200#\",\"large\":\"900x300#\"}"
+ preference :slide_default_style, :string, :default => 'medium'
+end
@@ -0,0 +1,3 @@
+Spree::Product.class_eval do
+ has_many :slides, :as => :slideable
+end
Oops, something went wrong.

0 comments on commit 33e082d

Please sign in to comment.