opal-ferro 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,110 +0,0 @@
1
- class FerroElement
2
-
3
- include FerroElementary
4
-
5
- attr_reader :parent, :sym, :children, :element, :domtype
6
-
7
- def initialize(parent, sym, options = {})
8
- @parent = parent
9
- @sym = sym
10
- @children = {}
11
- @element = nil
12
- @domtype = :div
13
- @states = {}
14
- @options = options
15
-
16
- creation
17
- end
18
-
19
- def factory
20
- @parent.factory
21
- end
22
-
23
- def root
24
- @parent.root
25
- end
26
-
27
- def component
28
- @parent.component
29
- end
30
-
31
- def router
32
- @parent.router
33
- end
34
-
35
- def option_replace(key, default = nil)
36
- value = @options[key] || default
37
- @options.delete(key) if @options.has_key?(key)
38
- value
39
- end
40
-
41
- # Store element states: adds/removes css classes
42
- def add_states(states)
43
- states.each do |state|
44
- add_state(state)
45
- end
46
- end
47
-
48
- def add_state(state, value = false)
49
- @states[state] = [factory.dasherize(state), value]
50
- classify_state @states[state]
51
- end
52
-
53
- # active: true, false, nil
54
- def update_state(state, active)
55
- if !active.nil?
56
- @states.each do |s, v|
57
- v[1] = active if s == state
58
- classify_state v
59
- end
60
- end
61
- end
62
-
63
- def toggle_state(state)
64
- @states.select { |s, _| s == state }.each do |s, v|
65
- v[1] = !v[1]
66
- classify_state v
67
- end
68
- end
69
-
70
- def classify_state(state)
71
- if state[1]
72
- `#{element}.classList.add(#{state[0]})`
73
- else
74
- `#{element}.classList.remove(#{state[0]})`
75
- end
76
- end
77
-
78
- def state_active?(state)
79
- @states[state][1]
80
- end
81
-
82
- def value
83
- `#{@element}.innerHTML`
84
- end
85
-
86
- def get_text
87
- `#{@element}.textContent`
88
- end
89
-
90
- def set_text(value)
91
- # https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent
92
- `#{@element}.textContent = #{value}`
93
- end
94
-
95
- def html(raw_html)
96
- `#{@element}.innerHTML = #{raw_html}`
97
- end
98
-
99
- def set_attribute(name, value)
100
- if name == 'scrollTop'
101
- `#{element}.scrollTop=#{value}`
102
- else
103
- `#{element}.setAttribute(#{name}, #{value})`
104
- end
105
- end
106
-
107
- def remove_attribute(name)
108
- `#{element}.removeAttribute(#{name})`
109
- end
110
- end
@@ -1,160 +0,0 @@
1
- class FerroForm < FerroElement
2
- def _before_create
3
- # Dont use a real <form> so we don't have to prevent default actions
4
- @domtype = :div
5
- end
6
- end
7
-
8
- # :text, :password, :reset, :radio, :checkbox, :color,
9
- # :date, :datetime-local, :email, :month, :number,
10
- # :range, :search, :tel, :time, :url, :week
11
- class FerroFormInput < FerroElement
12
- def _before_create
13
- @domtype = :input
14
- @options[:type] ||= :text
15
- @options[:value] = option_replace :content
16
- @disabled = option_replace :disabled, false
17
- end
18
-
19
- def value
20
- `#{@element}.value`
21
- end
22
-
23
- def value=(value)
24
- `#{@element}.value = #{value}`
25
- end
26
-
27
- def set_focus
28
- # Doesn't work ?!
29
- `#{element}.focus()`
30
- end
31
-
32
- def _after_create
33
- disable if @disabled
34
-
35
- if [:text, :password, :number].include?(@options[:type])
36
- `#{@element}.addEventListener("keydown",function(e){self.$keydowned(e);})`
37
- end
38
- end
39
-
40
- def keydowned(event)
41
- entered if Native(event).keyCode == 13
42
- end
43
-
44
- def entered;end
45
-
46
- def disable
47
- set_attribute(:disabled, :disabled)
48
- end
49
-
50
- def enable
51
- remove_attribute(:disabled)
52
- end
53
- end
54
-
55
- class FerroFormLabel < FerroElement
56
- def _before_create
57
- @domtype = :label
58
- end
59
- end
60
-
61
- class FerroFormFieldset < FerroElement
62
- def _before_create
63
- @domtype = :fieldset
64
- @legend = @options[:legend]
65
- end
66
- end
67
-
68
- class FerroFormTextarea < FerroElement
69
- def _before_create
70
- @domtype = :textarea
71
- @size = { rows: 40, cols: 5 }
72
- end
73
- end
74
-
75
- class FerroFormOutput < FerroElement
76
- def _before_create
77
- @domtype = :output
78
- end
79
- end
80
-
81
- class FerroFormClickable < FerroFormInput
82
- def _after_create
83
- `#{@element}.addEventListener("click",function(e){#{clicked};document.activeElement.blur()})`
84
- super
85
- end
86
-
87
- def clicked;end
88
- end
89
-
90
- class FerroFormButton < FerroFormClickable
91
- def _before_create
92
- @options[:type] = :button
93
- super
94
- end
95
- end
96
-
97
- class FerroFormSubmit < FerroFormClickable
98
- def _before_create
99
- @options[:type] = :submit
100
- super
101
- end
102
- end
103
-
104
- class FerroFormBlock < FerroFormClickable
105
- def _before_create
106
- super
107
- @domtype = :div
108
- end
109
- end
110
-
111
- # CheckBox with click callback
112
- class FerroFormCheckBox < FerroFormClickable
113
- def _before_create
114
- @options[:type] = :checkbox
115
- super
116
- end
117
-
118
- def checked?
119
- `#{@element}.checked`
120
- end
121
- end
122
-
123
- # Select input
124
- class FerroFormSelect < FerroElement
125
- def _before_create
126
- @domtype = :select
127
- @list = option_replace :list, {}
128
- super
129
- end
130
-
131
- def after_create
132
- @list.each do |value, content|
133
- add_option(value, content)
134
- end
135
-
136
- `#{@element}.addEventListener("change",function(e){#{changed};document.activeElement.blur()})`
137
- super
138
- end
139
-
140
- def changed;end
141
-
142
- def add_option(value, content)
143
- add_child "opt_#{value}", FerroElementVar, domtype: :option, value: value, content: content
144
- end
145
-
146
- def selection
147
- option = `#{element}.options[#{element}.selectedIndex].value`
148
- text = `#{element}.options[#{element}.selectedIndex].text`
149
- { option: option, text: text }
150
- end
151
-
152
- def select(option)
153
- `for(var i=0; i < #{element}.options.length; i++) {
154
- if (#{element}.options[i].value === #{option}) {
155
- #{element}.selectedIndex = i;
156
- break;
157
- }
158
- }`
159
- end
160
- end