Beispiel #1
0
        /// <summary>
        /// Adds an event listener to this object.
        /// </summary>
        /// <param name="eventName">Name of the event to listen for</param>
        /// <param name="callback">Callback that fires when the event is triggered.</param>
        /// <param name="options"></param>
        public void addEventListener(EventName eventName, EventCallback callback, AddEventListenerOptions options = null)
        {/* Docs: https://dom.spec.whatwg.org/#dom-eventtarget-addeventlistener */
            bool capture = false;
            bool once    = false;
            bool passive = false;

            if (!ReferenceEquals(options, null))
            {
                capture = options.capture;
                once    = options.once;
                passive = options.passive;
            }
            /* 2) Add an event listener with the context object and an event listener whose type is type, callback is callback, capture is capture, passive is passive, and once is once. */
            /* To add an event listener given an EventTarget object eventTarget and an event listener listener, run these steps: */
            /* 1) ... */
            /* 2) If listener’s callback is null, then return. */
            if (ReferenceEquals(callback, null))
            {
                return;
            }

            /* 3) If eventTarget’s event listener list does not contain an event listener whose type is listener’s type, callback is listener’s callback, and capture is listener’s capture, then append listener to eventTarget’s event listener list. */
            var srch = Find_Listener(eventName, callback, capture);

            if (ReferenceEquals(srch, null))
            {
                var newListener = new EventListener(eventName, callback, capture, once, passive);
                Listeners.AddLast(newListener);
            }
        }
Beispiel #2
0
        public object Clone()
        {
            var ll = new Listeners();

            foreach (var v in this)
            {
                ll.AddLast(v);
            }
            return(ll);
        }