Class: Domle::Element

Inherits:
Rexle::Element
  • Object
show all
Defined in:
lib/domle.rb

Direct Known Subclasses

Script, Style

Defined Under Namespace

Classes: ClassList

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = , value: nil, attributes: {}, rexle: nil) ⇒ Element

Returns a new instance of Element.



79
80
81
82
83
84
85
# File 'lib/domle.rb', line 79

def initialize(name=self.class.to_s.downcase[/\w+$/], value: nil, \
                      attributes: {}, rexle: nil)
  
  attributes.merge!(style: '') unless attributes.has_key? :style
  super(name, value: value, attributes: VisualAttributes.new(attributes), rexle: rexle)
  
end

Instance Attribute Details

#attr_mapObject (readonly)

Returns the value of attribute attr_map.



77
78
79
# File 'lib/domle.rb', line 77

def attr_map
  @attr_map
end

Class Method Details

.attr2_accessor(*a) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/domle.rb', line 87

def self.attr2_accessor(*a)

  a.concat %i(id transform)
  # DOM events      
  a.concat %i(onload onmousemove onmousedown onmouseenter 
  onmouseleave onclick onscroll onkeydown onkeyup) 
  
  a.each do |attribute|

    class_eval do

      define_method attribute.to_s.gsub('-','_').to_sym do 
        attributes[attribute]
      end

      define_method (attribute.to_s + '=').to_sym do |val|
        attributes[attribute] = val
        rexle().refresh if rexle?
        attr_update(attribute, val)
        val
      end

    end
  end
  
  def rexle?()
    not @rexle.nil?
  end
  
  def rexle()
    @rexle
  end
        
end

.attr_mapper(h) ⇒ Object



122
123
124
# File 'lib/domle.rb', line 122

def self.attr_mapper(h)
  @attr_map = h
end

Instance Method Details

#active=(v) ⇒ Object



130
131
132
# File 'lib/domle.rb', line 130

def active=(v)
  @active = v
end

#active?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/domle.rb', line 126

def active?()
  @active
end

#classlistObject



134
135
136
137
138
139
140
141
142
143
# File 'lib/domle.rb', line 134

def classlist()
  
  a = attributes[:class]
  cl = ClassList.new(a, @rexle, self)
  

  
  
  return cl
end

#hotspot?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


150
151
152
153
154
155
156
# File 'lib/domle.rb', line 150

def hotspot?(x,y)

  (boundary.first.is_a?(Array) ? boundary : [boundary]).all? do |box|
    x1, y1, x2, y2 = box
    (x1..x2).include? x and (y1..y2).include? y
  end
end

#objObject



162
163
164
# File 'lib/domle.rb', line 162

def obj()
  @obj
end

#obj=(v) ⇒ Object



158
159
160
# File 'lib/domle.rb', line 158

def obj=(v)
  @obj = v
end

#rexleObject



116
117
118
# File 'lib/domle.rb', line 116

def rexle()
  @rexle
end

#rexle?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/domle.rb', line 112

def rexle?()
  not @rexle.nil?
end

#styleObject



145
146
147
# File 'lib/domle.rb', line 145

def style()
  attributes.style(@rexle)
end