class EventdElement

EventdElement

Object representation of an element on the client’s page. Mimics a jQuery style API.

Shot Framework - Copyright © Jesse Aaron Dunlap <me@jessedunlap.me> Licensed under the MIT License. For full licensing information, please see LICENSE.md. github.com/JesseDunlap/shot/

Attributes

client[RW]

Instance of EventdClient, which is used to trigger interface emissions

selector[RW]

jQuery Selector associated with the element

Public Class Methods

new(selector, client) click to toggle source

Initializer

Attributes

  • selector

  • client

Calls superclass method EventdObject::new
# File lib/eventd/eventd_element.rb, line 22
def initialize(selector, client)
        super()
        @selector = selector
        @client = client
end

Public Instance Methods

jq(method, *attributes) click to toggle source

Call a jQuery method

Attribtues

  • method

  • +*attributes+

# File lib/eventd/eventd_element.rb, line 41
def jq(method, *attributes)
        @client.emit "eapi_jq", {
                :selector => @selector,
                :method => method,
                :attributes => attributes
        }
end
method_missing(method, *attributes, &block) click to toggle source

Handles any method called, and attempts to turn it into a valid jQuery call

# File lib/eventd/eventd_element.rb, line 30
def method_missing(method, *attributes, &block)
        self.jq method, attributes
        return self
end
on(event, &callback) click to toggle source

Add an event listener

Attributes

  • event

  • +&callback+

Calls superclass method EventdObject#on
# File lib/eventd/eventd_element.rb, line 55
def on(event, &callback)
        random_callback_id = SecureRandom.uuid
        
        @client.emit "eapi_event", {
                :selector => @selector,
                :callback => random_callback_id,
                :event => event
        }

        @client.on random_callback_id do
                callback.call
        end

        super(event, callback)
end