lib/hatemile/implementation/accessible_display_implementation.rb
##
# Insert a element before or after other element.
#
# @param element [Hatemile::Util::Html::HTMLDOMElement] The reference
#   element.
# @param new_element [Hatemile::Util::Html::HTMLDOMElement] The element
#   that be inserted.
# @param before [Boolean] To insert the element before the other element.
# @return [void]
Insert a element before or after other element.
Insert a element before or after other element .
def insert(element, new_element, before)
        return unless Hatemile::Util::CommonFunctions.is_valid_element?(element)
        tag_name = element.get_tag_name
        append_tags = %w[BODY A FIGCAPTION LI DT DD LABEL OPTION TD TH]
        controls = %w[INPUT SELECT TEXTAREA]
        if tag_name == 'HTML'
          body = @parser.find('body').first_result
          insert(body, new_element, before) unless body.nil?
        elsif append_tags.include?(tag_name)
          element.prepend_element(new_element) if before
          element.append_element(new_element) unless before
        elsif controls.include?(tag_name)
          labels = []
          if element.has_attribute?('id')
            labels = @parser.find(
              "label[for=\"#{element.get_attribute('id')}\"]"
            ).list_results
          end
          if labels.empty?
            labels = @parser.find(element).find_ancestors('label').list_results
          end
          labels.each do |label|
            insert(label, new_element, before)
          end
        elsif before
          element.insert_before(new_element)
        else
          element.insert_after(new_element)
        end
      end
def insert ( element , new_element , before ) return unless Hatemile :: Util :: CommonFunctions . is_valid_element? ( element ) tag_name = element . get_tag_name append_tags = %w[ BODY A FIGCAPTION LI DT DD LABEL OPTION TD TH ] controls = %w[ INPUT SELECT TEXTAREA ] if tag_name == 'HTML' body = @parser . find ( 'body' ) . first_result insert ( body , new_element , before ) unless body . nil? elsif append_tags . include? ( tag_name ) element . prepend_element ( new_element ) if before element . append_element ( new_element ) unless before elsif controls . include? ( tag_name ) labels = [ ] if element . has_attribute? ( 'id' ) labels = @parser . find ( "label[for=\"#{element.get_attribute('id')}\"]" ) . list_results end if labels . empty? labels = @parser . find ( element ) . find_ancestors ( 'label' ) . list_results end labels . each do | label | insert ( label , new_element , before ) end elsif before element . insert_before ( new_element ) else element . insert_after ( new_element ) end end
Insert a element before or after other element.
Insert a element before or after other element .
None
void
element
The reference element.
The reference element .
new_element
The element that be inserted.
The element that be inserted .
before
To insert the element before the other element.
To insert the element before the other element .