Class: HTML
Overview
this class is aimed at html rendering
Class Method Summary collapse
- .is_descendant(ancestor, descendant) ⇒ Object
- .locate(selector, base_element = JS.global[:document][:body]) ⇒ Object
Instance Method Summary collapse
- #action(_particle, action_found, option = nil) ⇒ Object
- #add_class(class_to_add) ⇒ Object
- #add_css_to_atomic_style(css) ⇒ Object
- #add_font_to_css(params) ⇒ Object
-
#animate(animation_properties) ⇒ Object
animation below.
- #animation_frame_callback(proc_pass, play_content) ⇒ Object
- #append(child_id_found) ⇒ Object
- #append_to(parent_id_found) ⇒ Object
-
#atomized(html_object) ⇒ Object
atomisation!.
- #attr(attribute, value) ⇒ Object
- #audio(id) ⇒ Object
- #backdropFilter(property, value) ⇒ Object
- #browse(id, file) ⇒ Object
- #center(options, attach) ⇒ Object
- #check_double(id) ⇒ Object
- #close_websocket ⇒ Object
- #colorize_svg_data(data) ⇒ Object
- #connect(params, &bloc) ⇒ Object
- #convert_to_css(data) ⇒ Object
- #css_to_data(css) ⇒ Object
- #currentTime(time) ⇒ Object
- #delete(id_to_delete) ⇒ Object
- #drag_end(_option) ⇒ Object
- #drag_locked(_option) ⇒ Object
- #drag_move(_option) ⇒ Object
- #drag_remove(_opt) ⇒ Object
- #drag_restrict(option) ⇒ Object
- #drag_start(_option) ⇒ Object
- #drop_activate(_option) ⇒ Object
- #drop_common(method, native_event) ⇒ Object
- #drop_deactivate(_option) ⇒ Object
- #drop_dropped(_option) ⇒ Object
- #drop_enter(_option) ⇒ Object
- #drop_leave(_option) ⇒ Object
- #drop_remove(option) ⇒ Object
- #editor(id) ⇒ Object
-
#event(action, variance, option = nil) ⇒ Object
def drag_code(params = nil) # FIXME : this method is an ugly patch when refreshing an atome twice, else it crash # and lose it’s drag drag_move(params) end.
- #event_validation(action_proc) ⇒ Object
- #extract_properties(properties_string) ⇒ Object
- #fill(params) ⇒ Object
- #filter(property, value) ⇒ Object
- #get_page_style ⇒ Object
-
#handle_atome(atome, td_element) ⇒ Object
Helper function to handle Atome objects.
- #handle_input ⇒ Object
- #hyperedit(params, usr_bloc) ⇒ Object
- #hypertext(params) ⇒ Object
- #id(id) ⇒ Object
- #image(id) ⇒ Object
-
#initialize(id_found, current_atome) ⇒ HTML
constructor
A new instance of HTML.
- #innerText(data) ⇒ Object
- #insert_cell(params) ⇒ Object
- #insert_column(params) ⇒ Object
- #insert_row(params) ⇒ Object
- #internet ⇒ Object
- #keyboard_down(_option) ⇒ Object
- #keyboard_press(_option) ⇒ Object
- #keyboard_remove(option) ⇒ Object
- #keyboard_up(_option) ⇒ Object
-
#location(loc_found) ⇒ Object
map.
- #map_pan(params) ⇒ Object
- #map_zoom(params) ⇒ Object
- #markup(new_tag, _usr_bloc) ⇒ Object
- #match(params) ⇒ Object
- #meteo(location) ⇒ Object
-
#meteo_helper(data) ⇒ Object
meteo.
- #object ⇒ Object
-
#on(property, _option) ⇒ Object
events handlers.
- #over_enter(_option) ⇒ Object
- #over_leave(_option) ⇒ Object
- #over_over(_option) ⇒ Object
- #over_remove(option) ⇒ Object
- #overflow(params, bloc) ⇒ Object
- #path(objet_path) ⇒ Object
- #raw(id) ⇒ Object
- #raw_data(html_string) ⇒ Object
- #read(id, file) ⇒ Object
- #record_audio(params) ⇒ Object
- #record_video(params) ⇒ Object
- #refresh_table(_params) ⇒ Object
- #remove(params) ⇒ Object
- #remove_class(class_to_remove) ⇒ Object
- #remove_this_drag(option) ⇒ Object
-
#remove_this_touch(option) ⇒ Object
def touch_long(_option) @element[:cursor] = ‘pointer’ @touch_long = @original_atome.instance_variable_get(‘@touch_code’) interact = JS.eval(“return interact(‘##@id’)”) # unless @touch_removed interact.on(‘hold’) do |native_event| @touch_long_event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it’s lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc..
- #resize(params, options) ⇒ Object
- #restrict_movement(restricted_x, restricted_y) ⇒ Object
- #sanitize_text(text) ⇒ Object
- #select_text(range) ⇒ Object
- #send_message(message) ⇒ Object
- #set_td_style(td) ⇒ Object
- #setup_touch_event(event_type, _option) ⇒ Object
- #shape(id) ⇒ Object
- #stop_animation ⇒ Object
- #stop_media_recorder(id) ⇒ Object
- #stop_video_preview(id) ⇒ Object
- #style(property, value = nil) ⇒ Object
- #svg(id) ⇒ Object
- #svg_data(all_datas) ⇒ Object
-
#table(data) ⇒ Object
Table manipulation.
- #table_insert(params) ⇒ Object
- #table_remove(params) ⇒ Object
- #terminal(id, cmd) ⇒ Object
- #text(id) ⇒ Object
- #textContent(data) ⇒ Object
- #touch_double(option) ⇒ Object
- #touch_down(option) ⇒ Object
- #touch_long(option) ⇒ Object
- #touch_remove(_opt) ⇒ Object
- #touch_tap(option) ⇒ Object
- #touch_up(option) ⇒ Object
- #transform(property, value = nil) ⇒ Object
- #transform_to_string_keys_and_values(hash) ⇒ Object
-
#update_data(params) ⇒ Object
this method update the data content of the atome.
- #update_svg_data(data) ⇒ Object
- #video(id) ⇒ Object
- #video_path(video_path, type = 'video/mp4') ⇒ Object
- #video_preview(id, video, audio) ⇒ Object
- #vr(id) ⇒ Object
- #vr_path(objet_path) ⇒ Object
- #www(id) ⇒ Object
Constructor Details
#initialize(id_found, current_atome) ⇒ HTML
Returns a new instance of HTML.
29 30 31 32 33 34 35 36 |
# File 'lib/renderers/html/html.rb', line 29 def initialize(id_found, current_atome) @element = JS.global[:document].getElementById(id_found.to_s) @id = id_found @original_atome = current_atome @touch_removed = {} end |
Class Method Details
.is_descendant(ancestor, descendant) ⇒ Object
25 26 27 |
# File 'lib/renderers/html/html.rb', line 25 def self.is_descendant(ancestor, descendant) JS.eval("return isDescendant('#{ancestor}', '#{descendant}')") end |
.locate(selector, base_element = JS.global[:document][:body]) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/renderers/html/html.rb', line 7 def self.locate(selector, base_element = JS.global[:document][:body]) return base_element if selector.empty? if selector.has_key?(:id) base_element.querySelector("##{selector[:id]}") elsif selector.has_key?(:parent) parent = base_element.querySelector("##{selector[:parent]}") return nil if parent.nil? parent.querySelectorAll("*").to_a elsif selector.has_key?(:html) html_element = selector[:html] return nil if html_element.nil? html_element.querySelectorAll("*").to_a end end |
Instance Method Details
#action(_particle, action_found, option = nil) ⇒ Object
835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 |
# File 'lib/renderers/html/html.rb', line 835 def action(_particle, action_found, option = nil) if action_found == :stop currentTime(option) @element.pause elsif action_found == :pause @element.pause else currentTime(option) proc_found = @original_atome.instance_variable_get('@play_code')[action_found] play_content = @original_atome.instance_variable_get('@play') animation_frame_callback(proc_found, play_content) @element.play end end |
#add_class(class_to_add) ⇒ Object
445 446 447 448 |
# File 'lib/renderers/html/html.rb', line 445 def add_class(class_to_add) @element[:classList].add(class_to_add.to_s) self end |
#add_css_to_atomic_style(css) ⇒ Object
61 62 63 64 65 |
# File 'lib/renderers/html/html.rb', line 61 def add_css_to_atomic_style(css) style_element = JS.global[:document].getElementById('atomic_style') text_node = JS.global[:document].createTextNode(css) style_element.appendChild(text_node) end |
#add_font_to_css(params) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/renderers/html/html.rb', line 47 def add_font_to_css(params) font_path = params[:path] font_name = params[:name] str_to_eval = <<~STRDELIM var styleSheet = document.styleSheets[0]; styleSheet.insertRule(` @font-face { font-family: '#{font_name}'; src: url('../medias/fonts/#{font_path}/#{font_name}.ttf') format('truetype'); }`, styleSheet.cssRules.length); STRDELIM JS.eval(str_to_eval) end |
#animate(animation_properties) ⇒ Object
animation below
1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 |
# File 'lib/renderers/html/html.rb', line 1716 def animate(animation_properties) prop = animation_properties[:particle] command = <<~JS var target_div = document.getElementById('#{@id}'); window.currentAnimation = popmotion.animate({ from: #{animation_properties[:from]}, to: #{animation_properties[:to]}, duration: #{animation_properties[:duration]}, onUpdate: function(v) { atomeJsToRuby("grab('#{@id}').animation_callback('#{prop}', "+v+")") atomeJsToRuby("grab('#{@id}').#{prop}("+v+")") }, onComplete: function(v) { window.currentAnimation = null; atomeJsToRuby("grab('#{@id}').animation_callback('#{prop}_end')") } }); JS JS.eval(command) end |
#animation_frame_callback(proc_pass, play_content) ⇒ Object
823 824 825 826 827 828 829 830 831 832 833 |
# File 'lib/renderers/html/html.rb', line 823 def animation_frame_callback(proc_pass, play_content) JS.global[:window].requestAnimationFrame(-> () { current_time = @element[:currentTime] fps = 30 current_frame = (current_time.to_f * fps).to_i @original_atome.instance_exec({ frame: current_frame, time: current_time }, &proc_pass) if proc_pass.is_a? Proc # we update play instance variable so if user ask for atome.play it will return current frame play_content[:play] = current_frame animation_frame_callback(proc_pass, play_content) }) end |
#append(child_id_found) ⇒ Object
864 865 866 867 868 |
# File 'lib/renderers/html/html.rb', line 864 def append(child_id_found) child_found = JS.global[:document].getElementById(child_id_found.to_s) @element.appendChild(child_found) self end |
#append_to(parent_id_found) ⇒ Object
851 852 853 854 855 |
# File 'lib/renderers/html/html.rb', line 851 def append_to(parent_id_found) parent_found = JS.global[:document].getElementById(parent_id_found.to_s) parent_found.appendChild(@element) self end |
#atomized(html_object) ⇒ Object
atomisation!
2039 2040 2041 |
# File 'lib/renderers/html/html.rb', line 2039 def atomized(html_object) @element = html_object end |
#attr(attribute, value) ⇒ Object
440 441 442 443 |
# File 'lib/renderers/html/html.rb', line 440 def attr(attribute, value) @element.setAttribute(attribute.to_s, value.to_s) self end |
#audio(id) ⇒ Object
570 571 572 573 574 575 576 577 578 579 580 |
# File 'lib/renderers/html/html.rb', line 570 def audio(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :audio @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#backdropFilter(property, value) ⇒ Object
814 815 816 817 |
# File 'lib/renderers/html/html.rb', line 814 def backdropFilter(property, value) filter_needed = "#{property}(#{value})" @element[:style][:"-webkit-backdrop-filter"] = filter_needed end |
#browse(id, file) ⇒ Object
1692 1693 1694 1695 1696 1697 1698 |
# File 'lib/renderers/html/html.rb', line 1692 def browse(id, file) if Atome.host == 'tauri' JS.eval("browseFile('#{id}','#{file}')") else puts 'browse file in progress in server mode' end end |
#center(options, attach) ⇒ Object
2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 |
# File 'lib/renderers/html/html.rb', line 2043 def center(, attach) @center_options = @parent = grab(attach) apply_centering(@center_options, @parent) return unless @center_options[:dynamic] event_handler = ->(event) do apply_centering(@center_options, @parent) end JS.global[:window].addEventListener('resize', event_handler) end |
#check_double(id) ⇒ Object
460 461 462 463 464 |
# File 'lib/renderers/html/html.rb', line 460 def check_double(id) # we remove any element if the id already exist element_to_delete = JS.global[:document].getElementById(id.to_s) delete(id) unless element_to_delete.inspect == 'null' end |
#close_websocket ⇒ Object
279 280 281 |
# File 'lib/renderers/html/html.rb', line 279 def close_websocket @websocket.close end |
#colorize_svg_data(data) ⇒ Object
687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 |
# File 'lib/renderers/html/html.rb', line 687 def colorize_svg_data(data) command = <<-JS let svgElement = document.getElementById("#{@id}"); if (!svgElement) { return []; } var children = svgElement.children; var ids = []; for (var i = 0; i < children.length; i++) { var element = document.getElementById(children[i].id); // Récupérer l'élément par son ID if (element) { element.setAttribute('fill', '#{data}'); // Modifier l'attribut fill element.setAttribute('stroke', '#{data}'); // Modifier l'attribut stroke } ids.push(children[i].id); } return ids JS JS.eval(command) end |
#connect(params, &bloc) ⇒ Object
254 255 256 257 258 259 260 |
# File 'lib/renderers/html/html.rb', line 254 def connect(params, &bloc) type = params[:type] server = params[:address] JS.eval("atomeJS.connect('#{type}','#{server}')") end |
#convert_to_css(data) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/renderers/html/html.rb', line 67 def convert_to_css(data) conditions = data[:condition] apply = data[:alterations] # Convert the conditions condition_strings = [] if conditions[:max] condition_strings << "(max-width: #{conditions[:max][:width]}px)" if conditions[:max][:width] condition_strings << "(max-height: #{conditions[:max][:height]}px)" if conditions[:max][:height] end if conditions[:min] condition_strings << "(min-width: #{conditions[:min][:width]}px)" if conditions[:min][:width] condition_strings << "(min-height: #{conditions[:min][:height]}px)" if conditions[:min][:height] end operator = conditions[:operator] == :and ? 'and' : 'or' # Convert properties to apply property_strings = [] apply.each do |key, values| inner_properties = [] values.each do |property, value| if property == :color inner_properties << "background-color: #{value} !important;" else inner_properties << "#{property}: #{value}px !important;" if value.is_a?(Integer) inner_properties << "#{property}: #{value} !important;" if value.is_a?(Symbol) end end # Prefix each key with "#" property_strings << "##{key} {\n#{inner_properties.join("\n")}\n}" end # let it build css = "@media #{condition_strings.join(" #{operator} ")} {\n#{property_strings.join("\n")}\n}" add_css_to_atomic_style(css) css end |
#css_to_data(css) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/renderers/html/html.rb', line 108 def css_to_data(css) data = { :condition => {}, :apply => {} } # Extract conditions media_conditions = css.match(/@media ([^\{]+)/)[1].split(',').map(&:strip) media_conditions.each do |condition| type = condition.match(/(max|min)-/)[1].to_sym property = condition.match(/(width|height)/)[1].to_sym value = condition.match(/(\d+)/)[1].to_i data[:condition][type] ||= {} data[:condition][type][property] = value end # Extract properties to be applied css.scan(/(\w+) \{([^\}]+)\}/).each do |match| key = match[0].to_sym properties = match[1].split(';').map(&:strip).reject(&:empty?) data[:apply][key] ||= {} properties.each do |property| prop, value = property.split(':').map(&:strip) if prop == 'background-color' data[:apply][key][:color] = value.to_sym elsif value[-2..] == 'px' data[:apply][key][prop.to_sym] = value.to_i else data[:apply][key][prop.to_sym] = value.to_sym end end end data end |
#currentTime(time) ⇒ Object
819 820 821 |
# File 'lib/renderers/html/html.rb', line 819 def currentTime(time) @element[:currentTime] = time end |
#delete(id_to_delete) ⇒ Object
857 858 859 860 861 862 |
# File 'lib/renderers/html/html.rb', line 857 def delete(id_to_delete) element_to_delete = JS.global[:document].getElementById(id_to_delete.to_s) return unless element_to_delete.to_s != 'null' return unless element_to_delete element_to_delete.remove end |
#drag_end(_option) ⇒ Object
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 |
# File 'lib/renderers/html/html.rb', line 1155 def drag_end(_option) unless @drag_end_already_set interact = JS.eval("return interact('##{@id}')") interact.on('dragend') do |native_event| drag_ends = @original_atome.instance_variable_get('@drag_code')[:end] event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_ends.each do |drag_end| proc_content = drag_end.call(event) if event_validation(drag_end) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_end_already_set = true end |
#drag_locked(_option) ⇒ Object
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 |
# File 'lib/renderers/html/html.rb', line 1180 def drag_locked(_option) unless @drag_locked_already_set interact = JS.eval("return interact('##{@id}')") interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 } }) interact.on('dragmove') do |native_event| drag_locks = @original_atome.instance_variable_get('@drag_code')[:locked] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_locks.each do |drag_lock| proc_content = drag_lock.call(event) if event_validation(drag_lock) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_locked_already_set = true end |
#drag_move(_option) ⇒ Object
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 |
# File 'lib/renderers/html/html.rb', line 1011 def drag_move(_option) unless @drag_move_already_set # the condition below prevent drag accumulation interact = JS.eval("return interact('##{@id}')") unless @draggable interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 }, }) unless @first_drag interact.on('dragmove') do |native_event| drag_moves = @original_atome.instance_variable_get('@drag_code')[:move] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_moves.each do |drag_move| proc_content = drag_move.call(event) if event_validation(drag_move) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end Universe.allow_tool_operations = false dx = event[:dx] dy = event[:dy] x = (@original_atome.left || 0) + dx.to_f y = (@original_atome.top || 0) + dy.to_f @original_atome.left(x) @original_atome.top(y) end end end @first_drag = true @draggable = true end @drag_move_already_set = true end |
#drag_remove(_opt) ⇒ Object
1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 |
# File 'lib/renderers/html/html.rb', line 1215 def drag_remove(_opt) interact = JS.eval("return interact('##{@id}')") if @original_atome.instance_variable_get('@drag_code') = @original_atome.instance_variable_get('@drag_code')[:remove] else = false end .each do |option| if option.instance_of? Array option.each do |opt| remove_this_drag(opt) end return false end @element[:style][:cursor] = 'default' @draggable = nil case option when :start remove_this_drag(:start) when :end, :stop remove_this_drag(:end) remove_this_drag(:stop) when :move remove_this_drag(:move) when :locked remove_this_drag(:locked) when :restrict remove_this_drag(:restrict) else interact.draggable(false) end end end |
#drag_restrict(option) ⇒ Object
1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 |
# File 'lib/renderers/html/html.rb', line 1060 def drag_restrict(option) unless @drag_restrict_already_set interact = JS.eval("return interact('##{@id}')") interact.draggable({ drag: true, inertia: { resistance: 12, minSpeed: 200, endSpeed: 100 }, }) if option.instance_of? Hash max_left = grab(:view).to_px(:width) max_top = grab(:view).to_px(:height) min_left = 0 min_top = 0 if option[:max] max_left = option[:max][:left] || max_left max_top = option[:max][:top] || max_top else max_left max_top end if option[:min] min_left = option[:min][:left] || min_left min_top = option[:min][:top] || min_top else min_left min_top end else parent_found = grab(option) min_left = parent_found.left min_top = parent_found.top parent_width = parent_found.compute({ particle: :width })[:value] parent_height = parent_found.compute({ particle: :height })[:value] original_width = @original_atome.width original_height = @original_atome.height max_left = min_left + parent_width - original_width max_top = min_top + parent_height - original_height end interact.on('dragmove') do |native_event| drag_moves = @original_atome.instance_variable_get('@drag_code')[:restrict] # the use of Native is only for Opal (look at lib/platform_specific/atome_wasm_extensions.rb for more infos) event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_moves.each do |drag_move| proc_content = drag_move.call(event) if event_validation(drag_move) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end dx = event[:dx] dy = event[:dy] x = (@original_atome.left || 0) + dx.to_f y = (@original_atome.top || 0) + dy.to_f restricted_x = [[x, min_left].max, max_left].min restricted_y = [[y, min_top].max, max_top].min restrict_movement(restricted_x, restricted_y) end end @drag_restrict_already_set = true end |
#drag_start(_option) ⇒ Object
1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 |
# File 'lib/renderers/html/html.rb', line 1133 def drag_start(_option) unless @drag_start_already_set interact = JS.eval("return interact('##{@id}')") interact.on('dragstart') do |native_event| drag_starts = @original_atome.instance_variable_get('@drag_code')[:start] event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. drag_starts.each do |drag_start| proc_content = drag_start.call(event) if event_validation(drag_start) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end @drag_start_already_set = true end |
#drop_activate(_option) ⇒ Object
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 |
# File 'lib/renderers/html/html.rb', line 1271 def drop_activate(_option) unless @drop_activate_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ accept: nil, # Accept any element overlap: 0.75, ondropactivate: lambda do |native_event| drop_common(:activate, native_event) end }) end @drop_activate_already_set = true end |
#drop_common(method, native_event) ⇒ Object
1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 |
# File 'lib/renderers/html/html.rb', line 1254 def drop_common(method, native_event) event = Native(native_event) draggable_element = event[:relatedTarget][:id].to_s dropzone_element = event[:target][:id].to_s # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_contents = @original_atome.instance_variable_get('@drop_code')[method] proc_contents.each do |proc_content| proc_content = proc_content.call({ source: draggable_element, destination: dropzone_element }) if event_validation(proc_content) return unless proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end |
#drop_deactivate(_option) ⇒ Object
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 |
# File 'lib/renderers/html/html.rb', line 1330 def drop_deactivate(_option) unless @drop_remove_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ # accept: nil, # Accept any element # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondropdeactivate: lambda do |native_event| drop_common(:deactivate, native_event) end }) end @drop_remove_already_set = true end |
#drop_dropped(_option) ⇒ Object
1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 |
# File 'lib/renderers/html/html.rb', line 1286 def drop_dropped(_option) unless @drop_dropped_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ overlap: 0.75, # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondrop: lambda do |native_event| drop_common(:dropped, native_event) end }) end @drop_dropped_already_set = true end |
#drop_enter(_option) ⇒ Object
1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 |
# File 'lib/renderers/html/html.rb', line 1301 def drop_enter(_option) unless @drop_enter_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ overlap: 0.001, # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondragenter: lambda do |native_event| drop_common(:enter, native_event) end }) end @drop_enter_already_set = true end |
#drop_leave(_option) ⇒ Object
1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 |
# File 'lib/renderers/html/html.rb', line 1315 def drop_leave(_option) unless @drop_leave_already_set interact = JS.eval("return interact('##{@id}')") interact.dropzone({ # FIXME : remove because os an opal bug since 1.8 reactivate when opal will be debbuged ondragleave: lambda do |native_event| drop_common(:leave, native_event) end }) end @drop_leave_already_set = true end |
#drop_remove(option) ⇒ Object
1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 |
# File 'lib/renderers/html/html.rb', line 1346 def drop_remove(option) case option when :activate @original_atome.instance_variable_get('@drop_code')[:activate] = [] when :deactivate @original_atome.instance_variable_get('@drop_code')[:deactivate] = [] when :dropped @original_atome.instance_variable_get('@drop_code')[:dropped] = [] when :enter @original_atome.instance_variable_get('@drop_code')[:enter] = [] when :leave @original_atome.instance_variable_get('@drop_code')[:leave] = [] else drop_remove(:activate) drop_remove(:deactivate) drop_remove(:dropped) drop_remove(:enter) drop_remove(:leave) end end |
#editor(id) ⇒ Object
466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/renderers/html/html.rb', line 466 def editor(id) check_double(id) editor_id = "#{id}_editor" check_double(editor_id) markup_found = @original_atome.markup || :textarea @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#event(action, variance, option = nil) ⇒ Object
def drag_code(params = nil)
# FIXME : this method is an ugly patch when refreshing an atome twice, else it crash
# and lose it's drag
drag_move(params)
end
1002 1003 1004 |
# File 'lib/renderers/html/html.rb', line 1002 def event(action, variance, option = nil) send("#{action}_#{variance}", option) end |
#event_validation(action_proc) ⇒ Object
1551 1552 1553 |
# File 'lib/renderers/html/html.rb', line 1551 def event_validation(action_proc) action_proc.is_a?(Proc) && (!Universe.edit_mode || @original_atome.tag[:system]) end |
#extract_properties(properties_string) ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/renderers/html/html.rb', line 145 def extract_properties(properties_string) properties_hash = {} properties = properties_string.split(';').map(&:strip).reject(&:empty?) properties.each do |property| key, value = property.split(':').map(&:strip) properties_hash[key] = value end properties_hash end |
#fill(params) ⇒ Object
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 |
# File 'lib/renderers/html/html.rb', line 764 def fill(params) # we remove previous background elements_to_remove = @element.getElementsByClassName('background') elements_to_remove = elements_to_remove.to_a elements_to_remove.each do |child| @element.removeChild(child) end params.each do |param| background_layer = JS.global[:document].createElement("div") background_layer[:style][:transform] = "rotate(#{param[:rotate]}deg)" # Applique une rotation de 45 degrés à l'élément background_layer[:style][:position] = "absolute" if param[:position] background_layer[:style][:top] = "#{param[:position][:x]}px" background_layer[:style][:left] = "#{param[:position][:y]}px" else background_layer[:style][:top] = "0" background_layer[:style][:left] = "0" end if param[:size] background_layer[:style][:width] = "#{param[:size][:x]}px" background_layer[:style][:height] = "#{param[:size][:y]}px" else background_layer[:style][:width] = "100%" background_layer[:style][:height] = "100%" end atome_path = grab(param[:atome]).path background_layer[:style][:backgroundImage] = "url('#{atome_path}')" background_layer[:style][:backgroundRepeat] = 'repeat' background_layer[:className] = 'background' background_layer[:style][:opacity] = param[:opacity] if param[:repeat] img_width = @original_atome.width / param[:repeat][:x] img_height = @original_atome.height / param[:repeat][:y] background_layer[:style][:backgroundSize] = "#{img_width}px #{img_height}px" else background_layer[:style][:backgroundSize] = "#{param[:width]}px #{param[:height]}px" end @element.appendChild(background_layer) end end |
#filter(property, value) ⇒ Object
809 810 811 812 |
# File 'lib/renderers/html/html.rb', line 809 def filter(property, value) filter_needed = "#{property}(#{value})" @element[:style][:filter] = filter_needed end |
#get_page_style ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/renderers/html/html.rb', line 155 def get_page_style main_view = JS.global[:document].getElementById('view') main_view_content = main_view[:innerHTML].to_s = main_view_content.split(/<\/?style[^>]*>/i).select.with_index { |_, index| index.odd? } = .join('') = .split("\n") hash_result = {} inside_media = false media_hash = {} .each do |line| line = line.strip next if line.empty? || line.start_with?('/*') if inside_media if line == '}' hash_result['@media'] << media_hash inside_media = false next end selector, properties = line.split('{').map(&:strip) next unless properties&.end_with?('}') properties = properties[0...-1].strip media_hash[selector] = extract_properties(properties) elsif line.start_with?('@media') media_content = line.match(/@media\s*\(([^)]+)\)\s*{/) next unless media_content media_query = media_content[1] hash_result['@media'] = [media_query] inside_media = true else selector, properties = line.split('{').map(&:strip) next unless properties&.end_with?('}') properties = properties[0...-1].strip hash_result[selector] = extract_properties(properties) end end hash_result end |
#handle_atome(atome, td_element) ⇒ Object
Helper function to handle Atome objects
1794 1795 1796 1797 1798 1799 1800 1801 1802 |
# File 'lib/renderers/html/html.rb', line 1794 def handle_atome(atome, td_element) atome.fit(cell_height) html_element = JS.global[:document].getElementById(atome.id.to_s) td_element.appendChild(html_element) html_element[:style][:transformOrigin] = 'top left' html_element[:style][:position] = 'relative' atome.top(0) atome.left(0) end |
#handle_input ⇒ Object
1700 1701 1702 |
# File 'lib/renderers/html/html.rb', line 1700 def handle_input @original_atome.instance_variable_set('@data', @element[:innerText].to_s) end |
#hyperedit(params, usr_bloc) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/renderers/html/html.rb', line 219 def hyperedit(params, usr_bloc) html_object = JS.global[:document].getElementById(params.to_s) particles_from_style = {} # we get all the styles tag present in the page get_page_style if html_object[:className].to_s classes_found = html_object[:className].to_s.split(' ') classes_found.each do |class_found| if get_page_style[".#{class_found}"] particles_from_style = particles_from_style.merge(get_page_style[".#{class_found}"]) end end end particles_found = {} particles_found[:data] = html_object[:innerText].to_s.chomp particles_found[:markup] = html_object[:tagName].to_s style_found = html_object[:style][:cssText].to_s style_found.split(';').each do |pair| key, value = pair.split(':').map(&:strip) particles_from_style[key.to_sym] = value if key && value end particles_found = particles_found.merge(particles_from_style) usr_bloc.call(particles_found) end |
#hypertext(params) ⇒ Object
42 43 44 45 |
# File 'lib/renderers/html/html.rb', line 42 def hypertext(params) current_div = JS.global[:document].getElementById(@id.to_s) current_div[:innerHTML] = params end |
#id(id) ⇒ Object
455 456 457 458 |
# File 'lib/renderers/html/html.rb', line 455 def id(id) attr('id', id) self end |
#image(id) ⇒ Object
545 546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/renderers/html/html.rb', line 545 def image(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :img @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#innerText(data) ⇒ Object
728 729 730 731 |
# File 'lib/renderers/html/html.rb', line 728 def innerText(data) sanitized_data = sanitize_text(data.to_s) @element[:innerText] = sanitized_data end |
#insert_cell(params) ⇒ Object
1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 |
# File 'lib/renderers/html/html.rb', line 1854 def insert_cell(params) row_index, cell_index = params[:cell] new_content = params[:content] container = JS.global[:document].getElementById(@id.to_s) table = container.querySelector('table') if table.nil? puts 'No table found in the container' return end row = table.querySelectorAll('tr')[row_index] if row.nil? puts "Row at index #{row_index} not found" return end cell = row.querySelectorAll('td')[cell_index] if cell.nil? puts "Cell at index #{cell_index} in row #{row_index} not found" return end if new_content.instance_of? Atome cell.innerHTML = '' html_element = JS.global[:document].getElementById(new_content.id.to_s) cell.appendChild(html_element) else cell[:textContent] = new_content.to_s end end |
#insert_column(params) ⇒ Object
1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 |
# File 'lib/renderers/html/html.rb', line 1916 def insert_column(params) insert_at_index = params[:column] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end rows = table_element.querySelectorAll('tr').to_a rows.each_with_index do |row, index| unless index == 0 new_cell = JS.global[:document].createElement('td') new_cell[:innerText] = '' set_td_style(new_cell) if insert_at_index.zero? row.insertBefore(new_cell, row.firstChild) else child_nodes = row.querySelectorAll('td').to_a if insert_at_index < child_nodes.length reference_cell = child_nodes[insert_at_index] row.insertBefore(new_cell, reference_cell) else row.appendChild(new_cell) end end end end end |
#insert_row(params) ⇒ Object
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 |
# File 'lib/renderers/html/html.rb', line 1886 def insert_row(params) insert_at_index = params[:row] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Tableau non trouvé' return end tbody = table_element.querySelector('tbody') header_row = table_element.querySelector('thead tr') column_count = header_row ? header_row.querySelectorAll('th').to_a.length : 0 new_row = JS.global[:document].createElement('tr') column_count.times do |cell_index| td = JS.global[:document].createElement('td') set_td_style(td) new_row.appendChild(td) end if insert_at_index.zero? tbody.insertBefore(new_row, tbody.firstChild) else reference_row = tbody.querySelectorAll('tr').to_a[insert_at_index] tbody.insertBefore(new_row, reference_row) end end |
#internet ⇒ Object
1672 1673 1674 |
# File 'lib/renderers/html/html.rb', line 1672 def internet JS.eval('return navigator.onLine') end |
#keyboard_down(_option) ⇒ Object
947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 |
# File 'lib/renderers/html/html.rb', line 947 def keyboard_down(_option) @keyboard_down = @original_atome.instance_variable_get('@keyboard_code')[:down] keypress_handler = ->(event) do # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_down.call(event) if event_validation(@keyboard_down) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keydown', keypress_handler) end |
#keyboard_press(_option) ⇒ Object
928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 |
# File 'lib/renderers/html/html.rb', line 928 def keyboard_press(_option) @keyboard_press = @original_atome.instance_variable_get('@keyboard_code')[:press] keypress_handler = ->(native_event) do event = Native(native_event) # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_press.call(event) if event_validation(@keyboard_press) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keypress', keypress_handler) end |
#keyboard_remove(option) ⇒ Object
981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/renderers/html/html.rb', line 981 def keyboard_remove(option) case option when :down @keyboard_down = '' when :up @keyboard_up = '' when :down @keyboard_press = '' else @keyboard_down = '' @keyboard_up = '' @keyboard_press = '' end end |
#keyboard_up(_option) ⇒ Object
964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
# File 'lib/renderers/html/html.rb', line 964 def keyboard_up(_option) @keyboard_up = @original_atome.instance_variable_get('@keyboard_code')[:up] keypress_handler = ->(event) do # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. proc_content = @keyboard_up.call(event) if event_validation(@keyboard_up) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener('keyup', keypress_handler) end |
#location(loc_found) ⇒ Object
map
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/renderers/html/html.rb', line 284 def location(loc_found) if loc_found[:longitude] && loc_found[:latitude] long_f = loc_found[:longitude] lat_f = loc_found[:latitude] js_code = <<~JAVASCRIPT const locatorElement = document.getElementById('#{@id}'); if (!locatorElement._leaflet_map) { const map = L.map('#{@id}').setView([51.505, -0.09], 2); // Centrer initialement sur une position par défaut L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' }).addTo(map); locatorElement._leaflet_map = map; if ('#{long_f}' === 'auto' || '#{lat_f}' === 'auto') { function onLocationFound(e) { const radius = e.accuracy / 2; const locationMarker = L.marker(e.latlng).addTo(map) .bindPopup(`You are within ${radius} meters from this point`).openPopup(); // Ajouter un ID au marqueur locationMarker._icon.id = '#{@id}_locator'; locationMarker.on('click', function() { alert(`You clicked the location marker at ${e.latlng.toString()}`); }); const locationCircle = L.circle(e.latlng, radius).addTo(map); map.setView(e.latlng, map.getZoom()); // Centrer la carte sur la position trouvée en conservant le zoom actuel } function onLocationError(e) { console.log(e.message); } map.on('locationfound', onLocationFound); map.on('locationerror', onLocationError); map.locate({ setView: true }); // Tenter de localiser l'utilisateur sans modifier le zoom } else { const lat = parseFloat('#{lat_f}'); const long = parseFloat('#{long_f}'); map.setView([lat, long], map.getZoom()); // Centrer la carte sur les coordonnées fournies en conservant le zoom actuel const locationMarker = L.marker([lat, long]).addTo(map) .bindPopup('This is your point').openPopup(); // Ajouter un ID au marqueur locationMarker._icon.id = '#{@id}_locator'; locationMarker.on('click', function() { alert(`You clicked the location marker at [${lat}, ${long}]`); }); } // Ecouter l'événement 'load' de la carte pour rafraîchir l'écran et afficher une alerte map.whenReady(function() { map.invalidateSize(); // important setimout re-center the view else the view is incorrect (map.invalidateSize() refresh the view) setTimeout(function() { map.invalidateSize(); }, 0001); }); } else { const map = locatorElement._leaflet_map; if ('#{long_f}' !== 'auto' && '#{lat_f}' !== 'auto') { const lat = parseFloat('#{lat_f}'); const long = parseFloat('#{long_f}'); map.setView([lat, long], map.getZoom()); // Centrer la carte sur les coordonnées fournies en conservant le zoom actuel const locationMarker = L.marker([lat, long]).addTo(map) .bindPopup('This is your point').openPopup(); // Ajouter un ID au marqueur locationMarker._icon.id = '#{@id}_locator'; locationMarker.on('click', function() { alert(`You clicked the location marker at [${lat}, ${long}]`); }); } // Ecouter l'événement 'load' de la carte pour rafraîchir l'écran et afficher une alerte map.whenReady(function() { setTimeout(function() { map.invalidateSize(); }, 0001); }); } // Ecouter l'événement de redimensionnement de la fenêtre pour réinitialiser la taille de la carte et la vue window.addEventListener('resize', () => { const map = locatorElement._leaflet_map; setTimeout(function() { map.invalidateSize(); }, 0001); }); JAVASCRIPT JS.eval(js_code) end end |
#map_pan(params) ⇒ Object
398 399 400 401 402 403 404 405 406 407 |
# File 'lib/renderers/html/html.rb', line 398 def map_pan(params) left_found = params[:left] || 0 top_found = params[:top] || 0 js_code = <<~JAVASCRIPT const locatorElement = document.getElementById('#{@id}'); const map = locatorElement._leaflet_map; map.panBy([#{left_found}, #{top_found}], { animate: true }); JAVASCRIPT JS.eval(js_code) end |
#map_zoom(params) ⇒ Object
389 390 391 392 393 394 395 396 |
# File 'lib/renderers/html/html.rb', line 389 def map_zoom(params) js_code = <<~JAVASCRIPT const locatorElement = document.getElementById('#{@id}'); const map = locatorElement._leaflet_map; map.setZoom(#{params}); JAVASCRIPT JS.eval(js_code) end |
#markup(new_tag, _usr_bloc) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/renderers/html/html.rb', line 199 def markup(new_tag, _usr_bloc) element_id = @id.to_s js_code = <<~JAVASCRIPT let element = document.getElementById('#{element_id}'); if (!element) { console.error(`Element with id "${'#{element_id}'}" not found.`); return; } let newElement = document.createElement('#{new_tag}'); newElement.style.cssText = element.style.cssText; Array.from(element.attributes).forEach(attr => { newElement.setAttribute(attr.name, attr.value); }); newElement.innerHTML = element.innerHTML; element.parentNode.replaceChild(newElement, element); JAVASCRIPT JS.eval(js_code) end |
#match(params) ⇒ Object
249 250 251 252 |
# File 'lib/renderers/html/html.rb', line 249 def match(params) css_converted = convert_to_css(params) css_to_data(css_converted) end |
#meteo(location) ⇒ Object
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/renderers/html/html.rb', line 414 def meteo(location) js_code = <<~JAVASCRIPT const url = 'https://api.openweathermap.org/data/2.5/weather?q=#{location},fr&appid=c21a75b667d6f7abb81f118dcf8d4611&units=metric'; async function fetchWeather() { try { let response = await fetch(url); if (!response.ok) { throw new Error('Erreur HTTP ! statut : ' + response.status); } let data = await response.json(); let jsonString = JSON.stringify(data); atomeJsToRuby("grab('#{@id}').html.meteo_helper("+jsonString+")"); } catch (error) { console.log('Error getting meteo : ' + error.message); } } fetchWeather(); JAVASCRIPT JS.eval(js_code) end |
#meteo_helper(data) ⇒ Object
meteo
410 411 412 |
# File 'lib/renderers/html/html.rb', line 410 def meteo_helper(data) grab(@id).instance_variable_get('@meteo_code')[:meteo].call(data) end |
#object ⇒ Object
38 39 40 |
# File 'lib/renderers/html/html.rb', line 38 def object @element end |
#on(property, _option) ⇒ Object
events handlers
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 |
# File 'lib/renderers/html/html.rb', line 871 def on(property, _option) property = property.to_s if property.start_with?('media:') # extract request from property media_query = property.split(':', 2).last mql = JS.global[:window].matchMedia(media_query) event_handler = ->(event) do bloc = @original_atome.instance_variable_get('@on_code')[:view_resize] proc_content = bloc.call({ matches: event[:matches] }) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end # add a listener to matchMedia object mql.addListener(event_handler) elsif property == 'resize' unless @on_resize_already_set event_handler = ->(event) do width = JS.global[:window][:innerWidth] height = JS.global[:window][:innerHeight] blocs = @original_atome.instance_variable_get('@on_code')[:view_resize] blocs.each do |bloc| proc_content = bloc.call({ width: width, height: height }) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end JS.global[:window].addEventListener('resize', event_handler) end @on_resize_already_set = true elsif property == 'remove' alert 'ok' @original_atome.instance_variable_get('@on_code')[:view_resize] = [] else event_handler = ->(event) do proc_content = bloc.call(event) if event_validation(bloc) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end @element.addEventListener(property, event_handler) end end |
#over_enter(_option) ⇒ Object
1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 |
# File 'lib/renderers/html/html.rb', line 1479 def over_enter(_option) return if @over_enter_already_set @element.addEventListener('mouseenter') do |native_event| = @original_atome.instance_variable_get('@over_code')[:enter] event = Native(native_event) .each do |over_option| proc_content = over_option.call(event) if event_validation(over_option) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_enter_already_set = true # unless @over_enter_already_set # over_enters = @original_atome.instance_variable_get('@over_code')[:enter] # # return unless over_enters # # over_enters.each do |over_enter| # @over_enter_callback = lambda do |event| # # we use .call instead of instance_eval because instance_eval bring the current object as context # # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # # group etc.. # proc_content = over_enter.call(event) if event_validation(over_enter) # if proc_content.instance_of? Hash # proc_content.each do |k, v| # @original_atome.send(k, v) # end # end # end # @element.addEventListener('mouseenter', @over_enter_callback) # # end # # end # @over_enter_already_set = true end |
#over_leave(_option) ⇒ Object
1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 |
# File 'lib/renderers/html/html.rb', line 1519 def over_leave(_option) return if @over_leave_already_set @element.addEventListener('mouseleave') do |native_event| over_leaves = @original_atome.instance_variable_get('@over_code')[:leave] event = Native(native_event) over_leaves.each do |over_leave| proc_content = over_leave.call(event) if event_validation(over_leave) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_leave_already_set = true end |
#over_over(_option) ⇒ Object
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 |
# File 'lib/renderers/html/html.rb', line 1441 def over_over(_option) return if @over_over_already_set @element.addEventListener('mouseover') do |native_event| = @original_atome.instance_variable_get('@over_code')[:flyover] event = Native(native_event) .each do |over_option| proc_content = over_option.call(event) if event_validation(over_option) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end @over_over_already_set = true # unless @over_over_already_set # interact = JS.eval("return interact('##{@id}')") # over_overs = @original_atome.instance_variable_get('@over_code')[:flyover] # # return unless over_overs # over_overs.each do |over_over| # interact.on('mouseover') do |native_event| # over_over_event = Native(native_event) # # we use .call instead of instance_eval because instance_eval bring the current object as context # # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # # group etc.. # # proc_content = over_over.call(over_over_event) if event_validation(over_over) # if proc_content.instance_of? Hash # proc_content.each do |k, v| # @original_atome.send(k, v) # end # end # end # end # end # @over_over_already_set = true end |
#over_remove(option) ⇒ Object
1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 |
# File 'lib/renderers/html/html.rb', line 1536 def over_remove(option) case option when :enter @original_atome.instance_variable_get('@over_code')[:enter] = [] when :leave @original_atome.instance_variable_get('@over_code')[:leave] = [] when :over @original_atome.instance_variable_get('@over_code')[:flyover] = [] else over_remove(:enter) over_remove(:leave) over_remove(:over) end end |
#overflow(params, bloc) ⇒ Object
1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 |
# File 'lib/renderers/html/html.rb', line 1421 def overflow(params, bloc) style(:overflow, params) @overflow = @original_atome.instance_variable_get('@overflow_code')[:overflow] @element.addEventListener('scroll', lambda do |native_event| scroll_top = @element[:scrollTop].to_i scroll_left = @element[:scrollLeft].to_i # we use .call instead of instance_eval because instance_eval bring the current object as context # and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape , # group etc.. @overflow.call({ left: scroll_left, top: scroll_top }) if event_validation(@overflow) proc_content = @overflow.call({ left: scroll_left, top: scroll_top }) if event_validation(@overflow) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end) end |
#path(objet_path) ⇒ Object
737 738 739 740 741 742 743 744 745 |
# File 'lib/renderers/html/html.rb', line 737 def path(objet_path) @element.setAttribute('src', objet_path) # below we get image to feed width and height if needed @element[:src] = objet_path @element[:onload] = lambda do |_event| @element[:width] @element[:height] end end |
#raw(id) ⇒ Object
638 639 640 641 642 643 644 645 646 |
# File 'lib/renderers/html/html.rb', line 638 def raw(id) # we remove any element if the id already exist check_double(id) @element = JS.global[:document].createElement('div') add_class('atome') self.id(id) JS.global[:document][:body].appendChild(@element) self end |
#raw_data(html_string) ⇒ Object
708 709 710 |
# File 'lib/renderers/html/html.rb', line 708 def raw_data(html_string) @element[:innerHTML] = html_string end |
#read(id, file) ⇒ Object
1684 1685 1686 1687 1688 1689 1690 |
# File 'lib/renderers/html/html.rb', line 1684 def read(id, file) if Atome.host == 'tauri' JS.eval("readFile('#{id}','#{file}')") else puts 'read file in progress in server mode' end end |
#record_audio(params) ⇒ Object
2058 2059 2060 2061 2062 |
# File 'lib/renderers/html/html.rb', line 2058 def record_audio(params) duration = params[:duration] * 1000 name = params[:name] JS.eval("recordAudio(#{duration},'#{@id}', '#{name}')") end |
#record_video(params) ⇒ Object
2064 2065 2066 2067 2068 |
# File 'lib/renderers/html/html.rb', line 2064 def record_video(params) duration = params[:duration] * 1000 name = params[:name] JS.eval("recordVideo(#{duration},'#{@id}', '#{name}')") end |
#refresh_table(_params) ⇒ Object
1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 |
# File 'lib/renderers/html/html.rb', line 1804 def refresh_table(_params) # first we need to extact all atome from the table or they will be deleted by the table refres data = @original_atome.data data.each do |row| row.each do |k, v| v.attach(:view) if v.instance_of? Atome end end table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end (table_element[:rows].to_a.length - 1).downto(1) do |i| table_element.deleteRow(i) end max_cells = data.map { |row| row.keys.length }.max data.each do |row| new_row = table_element.insertRow(-1) max_cells.times do |i| key = row.keys[i] value = row[key] cell = new_row.insertCell(-1) if value.instance_of? Atome html_element = JS.global[:document].getElementById(value.id.to_s) cell.appendChild(html_element) else cell[:textContent] = value.to_s end set_td_style(cell) end end end |
#remove(params) ⇒ Object
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 |
# File 'lib/renderers/html/html.rb', line 1958 def remove(params) # TODO: FIXME: "html : must create a case here #{params} (#{@original_atome.id})" case params when Hash params.each do |k, v| case k when :row row_index = params[:row] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' return end rows = table_element.querySelectorAll('tbody tr').to_a if row_index >= rows.length puts "row not found : #{row_index}" true end row_to_remove = rows[row_index] row_to_remove[:parentNode].removeChild(row_to_remove) rows.each_with_index do |row, i| next if i <= row_index end when :column column_index = params[:column] table_element = JS.global[:document].querySelector("##{@id} table") if table_element.nil? puts 'Table not found' true end rows = table_element.querySelectorAll('tbody tr').to_a rows.each do |row| cells = row.querySelectorAll('td').to_a if column_index < cells.length cell_to_remove = cells[column_index] cell_to_remove[:parentNode].removeChild(cell_to_remove) end end when :all case v when :paint style(:background, 'none') when :color # when :shadow style('box-shadow', 'none') style('text-shadow', 'none') style("filter", 'none') else # end end end else @original_atome.apply.delete(params) style(:background, 'none') style('box-shadow', 'none') style('text-shadow', 'none') style("boxShadow", 'none') style("filter", 'none') @original_atome.apply(@original_atome.apply) end end |
#remove_class(class_to_remove) ⇒ Object
450 451 452 453 |
# File 'lib/renderers/html/html.rb', line 450 def remove_class(class_to_remove) @element[:classList].remove(class_to_remove.to_s) self end |
#remove_this_drag(option) ⇒ Object
1211 1212 1213 |
# File 'lib/renderers/html/html.rb', line 1211 def remove_this_drag(option) @original_atome.instance_variable_get('@drag_code')[option] = [] if @original_atome.instance_variable_get('@drag_code') end |
#remove_this_touch(option) ⇒ Object
def touch_long(_option)
@element[:style][:cursor] = 'pointer'
@touch_long = @original_atome.instance_variable_get('@touch_code')[:long]
interact = JS.eval("return interact('##{@id}')")
# unless @touch_removed[:long]
interact.on('hold') do |native_event|
@touch_long_event = Native(native_event)
# we use .call instead of instance_eval because instance_eval bring the current object as context
# and it's lead to a problem of context and force the use of grab(:view) when suing atome method such as shape ,
# group etc..
proc_content = @touch_long.call(@touch_long_event) if event_validation(@touch_long)
if proc_content.instance_of? Hash
proc_content.each do |k, v|
@original_atome.send(k, v)
end
end
end
end
1636 1637 1638 |
# File 'lib/renderers/html/html.rb', line 1636 def remove_this_touch(option) @original_atome.instance_variable_get('@touch_code')[option] = [] if @original_atome.instance_variable_get('@touch_code') end |
#resize(params, options) ⇒ Object
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 |
# File 'lib/renderers/html/html.rb', line 1368 def resize(params, ) interact = JS.eval("return interact('##{@id}')") # Désactiver explicitement le déplacement # interact.draggable(false) if params == :remove @resize = '' interact.resizable(false) else min_width = [:min][:width] || 10 min_height = [:min][:height] || 10 max_width = [:max][:width] || 3000 max_height = [:max][:height] || 3000 @resize = @original_atome.instance_variable_get('@resize_code')[:resize] interact.resizable({ edges: { left: true, right: true, top: true, bottom: true }, inertia: true, modifiers: [], listeners: { move: lambda do |native_event| Universe.allow_tool_operations = false event = Native(native_event) proc_content = @resize.call(event) if event_validation(@resize) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end x = (@element[:offsetLeft].to_i || 0) y = (@element[:offsetTop].to_i || 0) width = event[:rect][:width] height = event[:rect][:height] # Translate when resizing from any corner x += event[:deltaRect][:left].to_f y += event[:deltaRect][:top].to_f @original_atome.width width.to_i if width.to_i.between?(min_width, max_width) @original_atome.height height.to_i if height.to_i.between?(min_height, max_height) @original_atome.left(x) @original_atome.top(y) end, }, }) end end |
#restrict_movement(restricted_x, restricted_y) ⇒ Object
1006 1007 1008 1009 |
# File 'lib/renderers/html/html.rb', line 1006 def restrict_movement(restricted_x, restricted_y) @original_atome.left(restricted_x) @original_atome.top(restricted_y) end |
#sanitize_text(text) ⇒ Object
719 720 721 722 723 724 725 726 |
# File 'lib/renderers/html/html.rb', line 719 def sanitize_text(text) text.to_s .gsub('&', "\&") .gsub('<', "\<") .gsub('>', "\>") .gsub('"', '"') .gsub("'", "\'") end |
#select_text(range) ⇒ Object
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/renderers/html/html.rb', line 523 def select_text(range) # TODO : use atome color object instead of basic css color back_color = grab(:back_selection) text_color = grab(:text_selection) back_color_rgba = "rgba(#{back_color.red * 255},#{back_color.green * 255},#{back_color.blue * 255}, #{back_color.alpha})" text_color_rgba = "rgba(#{text_color.red * 255},#{text_color.green * 255},#{text_color.blue * 255}, #{text_color.alpha})" range = JS.global[:document].createRange() range.selectNodeContents(@element) selection = JS.global[:window].getSelection() selection.removeAllRanges() selection.addRange(range) @element.focus() style = JS.global[:document].createElement('style') style[:innerHTML] = "::selection { background-color: #{back_color_rgba}; color: #{text_color_rgba}; }" JS.global[:document][:head].appendChild(style) return unless @element[:innerText].to_s.length == 1 @element[:innerHTML] = '​' end |
#send_message(message) ⇒ Object
272 273 274 275 276 277 |
# File 'lib/renderers/html/html.rb', line 272 def () # puts "message : #{message}" # FIXME : find why we have to sanitize this message when using ruby wams = transform_to_string_keys_and_values() JS.eval("atomeJS.ws_sender('#{}')") end |
#set_td_style(td) ⇒ Object
1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 |
# File 'lib/renderers/html/html.rb', line 1840 def set_td_style(td) cell_height = @original_atome.component[:height] cell_width = @original_atome.component[:width] td[:style][:backgroundColor] = 'white' td[:style][:width] = "#{cell_width}px" td[:style]['min-width'] = "#{cell_width}px" td[:style]['max-width'] = "#{cell_height}px" td[:style]['min-height'] = "#{cell_height}px" td[:style]['max-height'] = "#{cell_height}px" td[:style][:height] = "#{cell_height}px" td[:style][:overflow] = 'hidden' { cell_height: cell_height, cell_width: cell_width } end |
#setup_touch_event(event_type, _option) ⇒ Object
1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 |
# File 'lib/renderers/html/html.rb', line 1555 def setup_touch_event(event_type, _option) instance_variable = "@touch_#{event_type}_already_set" unless instance_variable_get(instance_variable) @element[:style][:cursor] = 'pointer' interact = JS.eval("return interact('##{@id}')") interact.on(event_type) do |native_event| touch_event = Native(native_event) touch_needed = @original_atome.instance_variable_get('@touch_code')[event_type.to_sym] touch_needed.each do |proc_found| proc_content = proc_found.call(touch_event) if event_validation(proc_found) if proc_content.instance_of? Hash proc_content.each do |k, v| @original_atome.send(k, v) end end end end end instance_variable_set(instance_variable, true) end |
#shape(id) ⇒ Object
def editor(id)
check_double(id)
editor_id = "#{id}_editor"
check_double(editor_id)
markup_found = @original_atome.markup || :div
@element_type = markup_found.to_s
@element = JS.global[:document].createElement(@element_type)
@element.setAttribute('style', 'font-size: 12px;')
JS.global[:document][:body].appendChild(@element)
add_class('atome')
id(id)
textarea = JS.global[:document].createElement('textarea')
textarea.setAttribute('id', editor_id)
wait 0.1 do
@element.appendChild(textarea)
end
self
end
499 500 501 502 503 504 505 506 507 508 509 |
# File 'lib/renderers/html/html.rb', line 499 def shape(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :div @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#stop_animation ⇒ Object
1737 1738 1739 |
# File 'lib/renderers/html/html.rb', line 1737 def stop_animation JS.eval('if (window.currentAnimation) window.currentAnimation.stop();') end |
#stop_media_recorder(id) ⇒ Object
2078 2079 2080 |
# File 'lib/renderers/html/html.rb', line 2078 def stop_media_recorder(id) JS.eval("writeatomestore('#{id}', 'record', 'stop')") end |
#stop_video_preview(id) ⇒ Object
2070 2071 2072 |
# File 'lib/renderers/html/html.rb', line 2070 def stop_video_preview(id) JS.eval("stopPreview('#{id}')") end |
#style(property, value = nil) ⇒ Object
752 753 754 755 756 757 758 759 760 761 762 |
# File 'lib/renderers/html/html.rb', line 752 def style(property, value = nil) if value @element[:style][property] = value.to_s elsif value.nil? @element[:style][property] else # If value is explicitly set to false, remove the property command = "document.getElementById('#{@id}').style.removeProperty('#{property}')" JS.eval(command) end end |
#svg(id) ⇒ Object
648 649 650 651 652 653 654 655 656 657 658 659 660 661 |
# File 'lib/renderers/html/html.rb', line 648 def svg(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || 'svg' @element_type = markup_found.to_s svg_ns = 'http://www.w3.org/2000/svg' @element = JS.global[:document].createElementNS(svg_ns, 'svg') JS.global[:document][:body].appendChild(@element) @element.setAttribute('viewBox', '0 0 1024 1024') @element.setAttribute('version', '1.1') add_class('atome') self.id(id) self end |
#svg_data(all_datas) ⇒ Object
663 664 665 666 667 668 669 670 671 672 673 674 675 676 |
# File 'lib/renderers/html/html.rb', line 663 def svg_data(all_datas) all_datas.each do |full_data| full_data.each do |type_passed, datas| svg_ns = 'http://www.w3.org/2000/svg' new_path = JS.global[:document].createElementNS(svg_ns.to_s, type_passed.to_s) JS.global[:document][:body].appendChild(new_path) datas.each do |property, value| new_path.setAttribute(property.to_s, value.to_s) end @element.appendChild(new_path) end end end |
#table(data) ⇒ Object
Table manipulation
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 |
# File 'lib/renderers/html/html.rb', line 1743 def table(data) table_html = JS.global[:document].createElement('table') thead = JS.global[:document].createElement('thead') max_length = data.max_by { |row| row.keys.length }.keys.length if @original_atome.option[:header] header_row = JS.global[:document].createElement('tr') max_length.times do |i| th = JS.global[:document].createElement('th') th[:textContent] = data.map { |row| row.keys[i].to_s }.compact.first || '' header_row.appendChild(th) end thead.appendChild(header_row) end table_html.appendChild(thead) tbody = JS.global[:document].createElement('tbody') data.each_with_index do |row, _row_index| tr = JS.global[:document].createElement('tr') max_length.times do |cell_index| td = JS.global[:document].createElement('td') cell_size = set_td_style(td) cell_height = cell_size[:cell_height] cell_value = row.values[cell_index] if cell_value.instance_of? Atome cell_value.fit(cell_height) html_element = JS.global[:document].getElementById(cell_value.id.to_s) td.appendChild(html_element) html_element[:style][:transformOrigin] = 'top left' html_element[:style][:position] = 'relative' cell_value.top(0) cell_value.left(0) else td[:textContent] = cell_value.to_s end tr.appendChild(td) end tbody.appendChild(tr) end table_html.appendChild(tbody) JS.global[:document].querySelector("##{@id}").appendChild(table_html) end |
#table_insert(params) ⇒ Object
1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 |
# File 'lib/renderers/html/html.rb', line 1947 def table_insert(params) if params[:cell] insert_cell(params) elsif params[:row] insert_row(params) elsif params[:column] insert_column(params) end end |
#table_remove(params) ⇒ Object
2030 2031 2032 2033 2034 2035 2036 |
# File 'lib/renderers/html/html.rb', line 2030 def table_remove(params) if params[:row] # elsif params[:column] # end end |
#terminal(id, cmd) ⇒ Object
1676 1677 1678 1679 1680 1681 1682 |
# File 'lib/renderers/html/html.rb', line 1676 def terminal(id, cmd) if Atome.host == 'tauri' JS.eval("terminal('#{id}','#{cmd}')") else JS.eval("distant_terminal('#{id}','#{cmd}')") end end |
#text(id) ⇒ Object
511 512 513 514 515 516 517 518 519 520 521 |
# File 'lib/renderers/html/html.rb', line 511 def text(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :pre @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') id(id) self end |
#textContent(data) ⇒ Object
733 734 735 |
# File 'lib/renderers/html/html.rb', line 733 def textContent(data) @element[:textContent] = data end |
#touch_double(option) ⇒ Object
1589 1590 1591 |
# File 'lib/renderers/html/html.rb', line 1589 def touch_double(option) setup_touch_event('doubletap', option) end |
#touch_down(option) ⇒ Object
1577 1578 1579 |
# File 'lib/renderers/html/html.rb', line 1577 def touch_down(option) setup_touch_event('down', option) end |
#touch_long(option) ⇒ Object
1593 1594 1595 |
# File 'lib/renderers/html/html.rb', line 1593 def touch_long(option) setup_touch_event('hold', option) end |
#touch_remove(_opt) ⇒ Object
1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 |
# File 'lib/renderers/html/html.rb', line 1640 def touch_remove(_opt) if @original_atome.instance_variable_get('@touch_code') option = @original_atome.instance_variable_get('@touch_code')[:remove] else option = false end @element[:style][:cursor] = 'default' case option when :double remove_this_touch(:double) when :down remove_this_touch(:down) when :long remove_this_touch(:long) when :tap remove_this_touch(:tap) when :touch remove_this_touch(:touch) when :up remove_this_touch(:up) else remove_this_touch(:double) remove_this_touch(:down) remove_this_touch(:long) remove_this_touch(:touch) remove_this_touch(:double) remove_this_touch(:up) end end |
#touch_tap(option) ⇒ Object
1585 1586 1587 |
# File 'lib/renderers/html/html.rb', line 1585 def touch_tap(option) setup_touch_event('tap', option) end |
#touch_up(option) ⇒ Object
1581 1582 1583 |
# File 'lib/renderers/html/html.rb', line 1581 def touch_up(option) setup_touch_event('up', option) end |
#transform(property, value = nil) ⇒ Object
747 748 749 750 |
# File 'lib/renderers/html/html.rb', line 747 def transform(property, value = nil) transform_needed = "#{property}(#{value}deg)" @element[:style][:transform] = transform_needed.to_s end |
#transform_to_string_keys_and_values(hash) ⇒ Object
262 263 264 265 266 267 268 269 270 |
# File 'lib/renderers/html/html.rb', line 262 def transform_to_string_keys_and_values(hash) hash.transform_keys(&:to_s).transform_values do |value| if value.is_a?(Hash) transform_to_string_keys_and_values(value) else value.to_s end end end |
#update_data(params) ⇒ Object
this method update the data content of the atome
1705 1706 1707 1708 1709 1710 1711 1712 1713 |
# File 'lib/renderers/html/html.rb', line 1705 def update_data(params) # we update the @data of the atome @input_listener ||= lambda { |event| handle_input } if params @element.addEventListener('input', &@input_listener) else @element.removeEventListener('input', &@input_listener) end end |
#update_svg_data(data) ⇒ Object
678 679 680 681 682 683 684 685 |
# File 'lib/renderers/html/html.rb', line 678 def update_svg_data(data) data.each do |type_passed, datas| element_to_update = JS.global[:document].getElementById(type_passed.to_s) datas.each do |property, value| element_to_update.setAttribute(property.to_s, value.to_s) end end end |
#video(id) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/renderers/html/html.rb', line 558 def video(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :video @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#video_path(video_path, type = 'video/mp4') ⇒ Object
712 713 714 715 716 717 |
# File 'lib/renderers/html/html.rb', line 712 def video_path(video_path, type = 'video/mp4') source = JS.global[:document].createElement('source') source.setAttribute('src', video_path) source.setAttribute('type', type) @element.appendChild(source) end |
#video_preview(id, video, audio) ⇒ Object
2074 2075 2076 |
# File 'lib/renderers/html/html.rb', line 2074 def video_preview(id, video, audio) JS.eval("create_preview('#{id}','#{video}','#{audio}')") end |
#vr(id) ⇒ Object
582 583 584 585 586 587 588 589 590 591 592 593 |
# File 'lib/renderers/html/html.rb', line 582 def vr(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :div @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') self.id(id) self end |
#vr_path(objet_path) ⇒ Object
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/renderers/html/html.rb', line 595 def vr_path(objet_path) js_code = <<~JAVASCRIPT initWithParam('#{objet_path}', '#{@id}', 'method', 'params'); JAVASCRIPT JS.eval(js_code) # tags = <<~HTML # <a-scene embedded> # <a-sky src="#{objet_path}" rotation="0 -130 0"></a-sky> # <a-text font="kelsonsans" value="Puy de Sancy, France" width="6" position="-2.5 0.25 -1.5" rotation="0 15 0"></a-text> # <!-- Hotspot --> # <a-sphere id="clickable" color="#FF0000" radius="0.1" position="0 1 -2" # event-set__mouseenter="_event: mouseenter; color: green" # event-set__mouseleave="_event: mouseleave; color: red"></a-sphere> # <!-- Camera with cursor to detect clicks --> # </a-scene> # HTML # @element[:innerHTML] = tags # # # Ajouter un écouteur d'événement pour le hotspot # cursor = JS.global[:document].getElementById('cursor') # cursor.addEventListener('click', -> { # target = cursor.components.cursor.intersectedEl # if target && target.id == 'clickable' # alert :yes # end # }) end |
#www(id) ⇒ Object
625 626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/renderers/html/html.rb', line 625 def www(id) # we remove any element if the id already exist check_double(id) markup_found = @original_atome.markup || :iframe @element_type = markup_found.to_s @element = JS.global[:document].createElement(@element_type) JS.global[:document][:body].appendChild(@element) add_class('atome') @element.setAttribute('src', 'https://www.youtube.com/embed/lLeQZ8Llkso?si=MMsGBEXELy9yBl9R') self.id(id) self end |