Module: Hyalite::BrowserEvent
- Defined in:
- lib/hyalite/browser_event.rb
Constant Summary collapse
- TOP_EVENT_MAPPING =
{ topBlur: 'blur', topChange: 'change', topClick: 'click', topCompositionEnd: 'compositionend', topCompositionStart: 'compositionstart', topCompositionUpdate: 'compositionupdate', topContextMenu: 'contextmenu', topCopy: 'copy', topCut: 'cut', topDoubleClick: 'dblclick', topDrag: 'drag', topDragEnd: 'dragend', topDragEnter: 'dragenter', topDragExit: 'dragexit', topDragLeave: 'dragleave', topDragOver: 'dragover', topDragStart: 'dragstart', topDrop: 'drop', topFocus: 'focus', topFocusIn: 'focusin', topFocusOut: 'focusout', topInput: 'input', topKeyDown: 'keydown', topKeyPress: 'keypress', topKeyUp: 'keyup', topMouseDown: 'mousedown', topMouseMove: 'mousemove', topMouseOut: 'mouseout', topMouseOver: 'mouseover', topMouseUp: 'mouseup', topPaste: 'paste', topScroll: 'scroll', topSelectionChange: 'selectionchange', topTextInput: 'textInput', topTouchCancel: 'touchcancel', topTouchEnd: 'touchend', topTouchMove: 'touchmove', topTouchStart: 'touchstart', topWheel: 'wheel' }
- TOP_LISTENERS_ID_KEY =
'_hyliteListenersID' + rand.to_s.chars.drop(2).join
Class Method Summary collapse
- .delete_all_listeners(id) ⇒ Object
- .delete_listener(id, registration_name) ⇒ Object
- .enabled=(enabled) ⇒ Object
- .enabled? ⇒ Boolean
- .event_dispatcher ⇒ Object
- .event_plugin_registry ⇒ Object
- .include?(name) ⇒ Boolean
- .listen_to(registration_name, content_document_handle) ⇒ Object
- .listener_at_phase(id, dispatch_config, propagation_phase) ⇒ Object
- .listening_for_document(mount_at) ⇒ Object
- .put_listener(id, event_name, listener) ⇒ Object
- .trap_bubbled_event(top_level_type, handler_base_name, handle) ⇒ Object
Class Method Details
.delete_all_listeners(id) ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'lib/hyalite/browser_event.rb', line 174 def delete_all_listeners(id) event_dispatcher.delete_all_listeners(id) do |id, registration_name| plugin = event_plugin_registry[registration_name] if plugin.respond_to? :will_delete_listener plugin.will_delete_listener(id, registration_name) end end end |
.delete_listener(id, registration_name) ⇒ Object
165 166 167 168 169 170 171 172 |
# File 'lib/hyalite/browser_event.rb', line 165 def delete_listener(id, registration_name) event_dispatcher.delete_listener(id, registration_name) do |id, registration_name| plugin = event_plugin_registry[registration_name] if plugin.respond_to? :will_delete_listener plugin.will_delete_listener(id, registration_name) end end end |
.enabled=(enabled) ⇒ Object
59 60 61 |
# File 'lib/hyalite/browser_event.rb', line 59 def enabled=(enabled) event_dispatcher.enabled = enabled end |
.enabled? ⇒ Boolean
55 56 57 |
# File 'lib/hyalite/browser_event.rb', line 55 def enabled? event_dispatcher.enabled? end |
.event_dispatcher ⇒ Object
63 64 65 66 67 |
# File 'lib/hyalite/browser_event.rb', line 63 def event_dispatcher @event_dispatcher ||= EventDispatcher.new do |top_level_type, top_level_target, top_level_target_id, event| event_plugin_registry.extract_events(top_level_type, top_level_target, top_level_target_id, event) end end |
.event_plugin_registry ⇒ Object
69 70 71 72 73 74 |
# File 'lib/hyalite/browser_event.rb', line 69 def event_plugin_registry @event_plugin_registry ||= EventPluginRegistry.new( SimpleEventPlugin.new, ChangeEventPlugin.new ) end |
.include?(name) ⇒ Boolean
76 77 78 |
# File 'lib/hyalite/browser_event.rb', line 76 def include?(name) event_plugin_registry.include? name end |
.listen_to(registration_name, content_document_handle) ⇒ Object
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 107 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/hyalite/browser_event.rb', line 80 def listen_to(registration_name, content_document_handle) mount_at = content_document_handle is_listening = listening_for_document(mount_at) dependencies = event_plugin_registry.dependencies(registration_name) dependencies.each do |dependency| unless is_listening[dependency] case dependency when :top_wheel nil # if isEventSupported('wheel') # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topWheel, # 'wheel', # mountAt # ); # elsif isEventSupported('mousewheel') # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topWheel, # 'mousewheel', # mountAt # ); # else # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topWheel, # 'DOMMouseScroll', # mountAt # ); # end # when :top_scroll # if isEventSupported('scroll', true) # ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent( # topLevelTypes.topScroll, # 'scroll', # mountAt # ); # else # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topScroll, # 'scroll', # ReactBrowserEventEmitter.ReactEventListener.WINDOW_HANDLE # ); # end # when :top_focus, :top_blur # if isEventSupported('focus', true) # ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent( # topLevelTypes.topFocus, # 'focus', # mountAt # ); # ReactBrowserEventEmitter.ReactEventListener.trapCapturedEvent( # topLevelTypes.topBlur, # 'blur', # mountAt # ); # elsif isEventSupported('focusin') # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topFocus, # 'focusin', # mountAt # ); # ReactBrowserEventEmitter.ReactEventListener.trapBubbledEvent( # topLevelTypes.topBlur, # 'focusout', # mountAt # ); # end # # is_listening[:top_blur] = true # is_listening[:top_focus] = true else if TOP_EVENT_MAPPING.has_key? dependency trap_bubbled_event(dependency, TOP_EVENT_MAPPING[dependency], mount_at) end end is_listening[dependency] = true end end end |
.listener_at_phase(id, dispatch_config, propagation_phase) ⇒ Object
183 184 185 186 |
# File 'lib/hyalite/browser_event.rb', line 183 def listener_at_phase(id, dispatch_config, propagation_phase) registration_name = dispatch_config[:phasedRegistrationNames][propagation_phase] event_dispatcher.get_listener(id, registration_name) end |
.listening_for_document(mount_at) ⇒ Object
188 189 190 191 192 193 194 195 |
# File 'lib/hyalite/browser_event.rb', line 188 def listening_for_document(mount_at) @already_listening_to ||= [] unless `Object.prototype.hasOwnProperty.call(mount_at.native, #{TOP_LISTENERS_ID_KEY})` `mount_at.native[#{TOP_LISTENERS_ID_KEY}] = #{@already_listening_to.length}` @already_listening_to << {} end @already_listening_to[`mount_at.native[#{TOP_LISTENERS_ID_KEY}]`] end |
.put_listener(id, event_name, listener) ⇒ Object
161 162 163 |
# File 'lib/hyalite/browser_event.rb', line 161 def put_listener(id, event_name, listener) event_dispatcher.put_listener(id, event_name, listener) end |
.trap_bubbled_event(top_level_type, handler_base_name, handle) ⇒ Object
197 198 199 |
# File 'lib/hyalite/browser_event.rb', line 197 def trap_bubbled_event(top_level_type, handler_base_name, handle) event_dispatcher.trap_bubbled_event(top_level_type, handler_base_name, handle) end |