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.



82
83
84
85
86
87
88
# File 'lib/domle.rb', line 82

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.



80
81
82
# File 'lib/domle.rb', line 80

def attr_map
  @attr_map
end

Class Method Details

.attr2_accessor(*a) ⇒ Object



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
121
122
123
# File 'lib/domle.rb', line 90

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



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

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

Instance Method Details

#active=(v) ⇒ Object



133
134
135
# File 'lib/domle.rb', line 133

def active=(v)
  @active = v
end

#active?Boolean

Returns:

  • (Boolean)


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

def active?()
  @active
end

#classlistObject



137
138
139
140
141
142
143
144
145
146
# File 'lib/domle.rb', line 137

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

  
  
  return cl
end

#hotspot?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


153
154
155
156
157
158
159
# File 'lib/domle.rb', line 153

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



165
166
167
# File 'lib/domle.rb', line 165

def obj()
  @obj
end

#obj=(v) ⇒ Object



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

def obj=(v)
  @obj = v
end

#rexleObject



119
120
121
# File 'lib/domle.rb', line 119

def rexle()
  @rexle
end

#rexle?Boolean

Returns:

  • (Boolean)


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

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

#styleObject



148
149
150
# File 'lib/domle.rb', line 148

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