Class: Aurita::GUI::Button

Inherits:
Element
  • Object
show all
Defined in:
lib/aurita-gui/button.rb

Overview

Specialization of Aurita::GUI::Element, extending it by @icon to display in the button.

Usage:

b = Button.new(:type => :submit,             # default is :button
               :icon => '/path/to/icon.png', # default is no icon
               :onclick => 'alert('button clicked'); ") { 
      'click me' 
    }

Change button text:

b.content = 'Custom button text'

Disable icon again:

b.icon   = false

Direct Known Subclasses

Reset_Button, Submit_Button

Instance Attribute Summary collapse

Attributes inherited from Element

#attrib, #force_closing_tag, #gui_element_id, #parent, #tag

Instance Method Summary collapse

Methods inherited from Element

#+, #<<, #[], #[]=, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #inspect, #js_init_code, #length, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #touch, #touched?, #type=, #untouch

Methods included from Marshal_Helper_Class_Methods

#marshal_load

Methods included from Marshal_Helper

#marshal_dump

Constructor Details

#initialize(params, &block) ⇒ Button

Returns a new instance of Button.



29
30
31
32
33
34
35
# File 'lib/aurita-gui/button.rb', line 29

def initialize(params, &block)
  params[:tag]  = :button
  params[:type] = :button unless params[:type]
  @icon         = params[:icon]
  params.delete(:icon)
  super(params, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element

Instance Attribute Details

#iconObject

Returns the value of attribute icon.



27
28
29
# File 'lib/aurita-gui/button.rb', line 27

def icon
  @icon
end

Instance Method Details

#contentObject



37
38
39
40
41
42
# File 'lib/aurita-gui/button.rb', line 37

def content
  if @icon then
    return [ HTML.img(:src => @icon), @content ]
  end
  return @content
end