Module: Shoes::Common::Hover
- Defined in:
- shoes-core/lib/shoes/common/hover.rb
Instance Attribute Summary collapse
-
#hover_blk ⇒ Object
readonly
Returns the value of attribute hover_blk.
-
#leave_blk ⇒ Object
readonly
Returns the value of attribute leave_blk.
Class Method Summary collapse
Instance Method Summary collapse
- #add_mouse_hover_control ⇒ Object
- #apply_style_from_hover_class ⇒ Object
- #apply_style_from_pre_hover ⇒ Object
- #eval_hover_block(blk) ⇒ Object
- #hover(&blk) ⇒ Object
- #hover_class ⇒ Object
- #hovered? ⇒ Boolean
- #leave(&blk) ⇒ Object
- #mouse_hovered ⇒ Object
- #mouse_left ⇒ Object
Instance Attribute Details
#hover_blk ⇒ Object (readonly)
Returns the value of attribute hover_blk.
6 7 8 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 6 def hover_blk @hover_blk end |
#leave_blk ⇒ Object (readonly)
Returns the value of attribute leave_blk.
6 7 8 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 6 def leave_blk @leave_blk end |
Class Method Details
.create_hover_class(base) ⇒ Object
12 13 14 15 16 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 12 def self.create_hover_class(base) clazz = Class.new {} name = base.name.split("::").last Shoes.const_set("#{name}Hover", clazz) end |
Instance Method Details
#add_mouse_hover_control ⇒ Object
59 60 61 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 59 def add_mouse_hover_control app.add_mouse_hover_control(self) end |
#apply_style_from_hover_class ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 67 def apply_style_from_hover_class hover_style = @app.element_styles[hover_class] return unless hover_style @pre_hover_style = hover_style.each_with_object({}) do |(key, _), memo| memo[key] = style[key] memo end style(hover_style) end |
#apply_style_from_pre_hover ⇒ Object
79 80 81 82 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 79 def apply_style_from_pre_hover style(@pre_hover_style) if defined?(@pre_hover_style) && @pre_hover_style @pre_hover_style = nil end |
#eval_hover_block(blk) ⇒ Object
63 64 65 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 63 def eval_hover_block(blk) safely_evaluate(self, &blk) if blk end |
#hover(&blk) ⇒ Object
18 19 20 21 22 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 18 def hover(&blk) @hover_blk = blk add_mouse_hover_control self end |
#hover_class ⇒ Object
34 35 36 37 38 39 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 34 def hover_class return @hover_class if defined?(@hover_class) name = self.class.name.split("::").last @hover_class = Shoes.const_get("#{name}Hover") end |
#hovered? ⇒ Boolean
30 31 32 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 30 def hovered? @hovered ||= false end |
#leave(&blk) ⇒ Object
24 25 26 27 28 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 24 def leave(&blk) @leave_blk = blk add_mouse_hover_control self end |
#mouse_hovered ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 41 def mouse_hovered return if hovered? @hovered = true apply_style_from_hover_class eval_hover_block(@hover_blk ||= nil) end |
#mouse_left ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'shoes-core/lib/shoes/common/hover.rb', line 50 def mouse_left return unless hovered? @hovered = false apply_style_from_pre_hover eval_hover_block(@leave_blk ||= nil) end |