Class: Slider::MainController
- Inherits:
-
Volt::ModelController
- Object
- Volt::ModelController
- Slider::MainController
- Defined in:
- app/slider/controllers/main_controller.rb
Instance Method Summary collapse
- #before_index_remove ⇒ Object
- #clear_interval(interval) ⇒ Object
- #create_options_vars(options) ⇒ Object
- #default_options ⇒ Object
- #index ⇒ Object
- #index_ready ⇒ Object
- #move ⇒ Object
- #prev ⇒ Object
- #set_interval(time = 0, &block) ⇒ Object
- #show_icons? ⇒ Boolean
Instance Method Details
#before_index_remove ⇒ Object
81 82 83 84 85 |
# File 'app/slider/controllers/main_controller.rb', line 81 def before_index_remove if RUBY_PLATFORM == 'opal' clear_interval(@interval) end end |
#clear_interval(interval) ⇒ Object
93 94 95 96 97 |
# File 'app/slider/controllers/main_controller.rb', line 93 def clear_interval( interval ) if RUBY_PLATFORM == 'opal' `clearInterval(#{interval})` end end |
#create_options_vars(options) ⇒ Object
26 27 28 29 30 31 32 |
# File 'app/slider/controllers/main_controller.rb', line 26 def () .each { |k,v| puts "@#{k}" + (( (attrs.send(k) == '') ? nil : attrs.send(k) ) || v).to_s } .each { |k,v| instance_variable_set("@#{k}", (( (attrs.send(k) == '') ? nil : attrs.send(k) )|| v)) } #instance variables from attrs (@show_prev_next_icons == true or @show_prev_next_icons == 'true') ? @show_prev_next_icons = true : @show_prev_next_icons = false (@stop_on_mouseover==true or @stop_on_mouseover=='true') ? @stop_on_mouseover = true : @stop_on_mouseover = false end |
#default_options ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'app/slider/controllers/main_controller.rb', line 9 def { interval_time: 3000, #interval between moves in ms transition_time: 700, leftmost_point: -1600, #if container moved farther than that it's reset to zero - showing first slide stop_on_mouseover: true, css_visible_width: 800, css_visible_height: 260, css_container_length: 9999, show_prev_next_icons: true } end |
#index ⇒ Object
22 23 24 |
# File 'app/slider/controllers/main_controller.rb', line 22 def index () end |
#index_ready ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/slider/controllers/main_controller.rb', line 62 def index_ready if RUBY_PLATFORM == 'opal' if @stop_on_mouseover el = Element.find('.slider-viewport') el.on :mouseover do clear_interval(@interval) end el.on :mouseout do @interval = set_interval(@interval_time) do move end end end @interval = set_interval(@interval_time) do move end end end |
#move ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/slider/controllers/main_controller.rb', line 39 def move if RUBY_PLATFORM == 'opal' el = Element.find('.slider-container') moveto = el.css('left').to_i - @css_visible_width.to_i if moveto < @leftmost_point.to_i @leftmost_point_set = moveto + @css_visible_width.to_i moveto = 0 end el.animate({left: moveto, speed: @transition_time.to_i }) end end |
#prev ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'app/slider/controllers/main_controller.rb', line 51 def prev if RUBY_PLATFORM == 'opal' el = Element.find('.slider-container') moveto = el.css('left').to_i + @css_visible_width.to_i if moveto > 0 moveto = @leftmost_point_set || @leftmost_point end el.animate({left: moveto, speed: @transition_time.to_i }) end end |
#set_interval(time = 0, &block) ⇒ Object
87 88 89 90 91 |
# File 'app/slider/controllers/main_controller.rb', line 87 def set_interval( time=0, &block ) if RUBY_PLATFORM == 'opal' `setInterval(function(){#{block.call}}, time)` end end |
#show_icons? ⇒ Boolean
34 35 36 |
# File 'app/slider/controllers/main_controller.rb', line 34 def show_icons? (@show_prev_next_icons == true or @show_prev_next_icons == 'true') ? true : false end |