Class: Ferro::Element::Anchor

Inherits:
BaseElement show all
Defined in:
opal/opal-ferro/elements/ferro_inline.js.rb

Overview

Creates an inline element. In the DOM creates a: <a>. When link is clicked will navigate to the new location within the application or page 404 if not found. Specify option :href to set the location.

Constant Summary

Constants included from Ferro::Elementary

Ferro::Elementary::RESERVED_NAMES

Instance Attribute Summary

Attributes inherited from BaseElement

#children, #domtype, #element, #parent, #sym

Instance Method Summary collapse

Methods inherited from BaseElement

#add_state, #add_states, #classify_state, #component, #dom_id, #factory, #get_text, #html, #initialize, #option_replace, #remove_attribute, #root, #router, #set_attribute, #set_text, #state_active?, #toggle_state, #update_state, #value, #value=

Methods included from Ferro::Elementary

#_stylize, #add_child, #after_create, #before_create, #cascade, #create, #creation, #destroy, #each_child, #forget_children, #method_missing, #remove_child, #style, #symbolize

Constructor Details

This class inherits a constructor from Ferro::BaseElement

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Ferro::Elementary

Instance Method Details

#_after_createObject

Internal method.



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 107

def _after_create
  `#{@element}.addEventListener("click", function(e) {
    e.preventDefault();

    if (#{@push}) {
      history.pushState(null, null, #{@href});
    }

    #{clicked};

    document.activeElement.blur();
  })`
end

#_before_createObject

Internal method.



100
101
102
103
104
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 100

def _before_create
  @domtype = :a
  @href = @options[:href]
  @push = @href.to_s != ''
end

#clickedObject

Callback for click event. Calls ‘router.navigated`. Override this method to change its behavior.



131
132
133
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 131

def clicked
  router.navigated
end

#update_href(value) ⇒ Object

Set a new html reference for this item.

Parameters:

  • value (String)

    New reference



124
125
126
127
# File 'opal/opal-ferro/elements/ferro_inline.js.rb', line 124

def update_href(value)
  @href = value
  set_attribute('href', @href)
end