Class: EditableText::MainController
- Inherits:
-
Volt::ModelController
- Object
- Volt::ModelController
- EditableText::MainController
- Defined in:
- app/editable-text/controllers/main_controller.rb
Instance Attribute Summary collapse
-
#section ⇒ Object
Returns the value of attribute section.
Instance Method Summary collapse
- #body_element ⇒ Object
- #edit(event) ⇒ Object
- #index ⇒ Object
- #size ⇒ Object
- #toggle_editing ⇒ Object
- #value ⇒ Object
- #value=(newvalue) ⇒ Object
Instance Attribute Details
#section ⇒ Object
Returns the value of attribute section.
3 4 5 |
# File 'app/editable-text/controllers/main_controller.rb', line 3 def section @section end |
Instance Method Details
#body_element ⇒ Object
10 11 12 |
# File 'app/editable-text/controllers/main_controller.rb', line 10 def body_element Element.find('body') end |
#edit(event) ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'app/editable-text/controllers/main_controller.rb', line 34 def edit(event) if event.key_code == 13 #for some reason .stop or stop_propagation thow the following error: #undefined method `stop_propagation' for #<Volt::JSEvent:7672> #event.stop_propagation toggle_editing end end |
#index ⇒ Object
6 7 8 |
# File 'app/editable-text/controllers/main_controller.rb', line 6 def index self.toggled = false end |
#size ⇒ Object
53 54 55 |
# File 'app/editable-text/controllers/main_controller.rb', line 53 def size return attrs.value.size end |
#toggle_editing ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/editable-text/controllers/main_controller.rb', line 14 def toggle_editing self.toggled = !toggled if toggled # Editing enabled, bind a listener for when they click on the document to disable # it again. body_element.on('click.editabletext') do |event| # Find the id for the text field inside of this component. clicked_id = Element.find(section.container_node).find('input').id if clicked_id != event.target.id # Didn't click inside of the edit text field, toggle back. toggle_editing end end else body_element.off('click.editabletext') end end |
#value ⇒ Object
49 50 51 |
# File 'app/editable-text/controllers/main_controller.rb', line 49 def value return attrs.value end |
#value=(newvalue) ⇒ Object
45 46 47 |
# File 'app/editable-text/controllers/main_controller.rb', line 45 def value=(newvalue) attrs.value = newvalue end |