Mass framework emitter module v2

Source: Internet
Author: User

This module is used to provide custom events and convert the objects implementing this interface into an event transmitter.

// ================================================ ================/// Event transmitter module ================================ ============================ (function (global, doc) {var dom = global [Doc. URL. replace (/(#. + | \ W)/g, '')]; Dom. define ("emitter", "data", function () {var firetype = "", blank = "" Var fig =/\ bhover (\. \ s + )? /, Rtypenamespace =/^ ([^ \.] *)? (?: \. (. + ))? $/, Reprop =/[A-Z]/; var system = Dom. event = {special :{}, // used to process individual DOM events BIND: function (types, handler, selector) {// It adds an attribute named uniquenumber to the native event transmitter or any common JS object that can be an event transmitter for associating a cache body, // store the required data in it, and now we store all the objects named @ events in it, // The @ event table is used to place various event types and the corresponding callback function var target = This, events = Dom. _ data (target), nativeemitter = Dom ["@ emitter"] in target, all, TNS, type, namespace, special, handlerobj, hand Lers, FN; If (target. nodetype = 3 | target. nodetype = 8 |! Types | typeof handler! = "Function" |! Events) return; All = {handler: handler, UUID: Dom. UUID ++} // ensure that UUID, bag and callback UUID are consistent all. handler. UUID = All. UUID; If (nativeemitter) {// process DOM Event fn = events. handle | (events. handle = function (e) {return (E | event ). type! = Firetype )? System. handle. apply (fn.tar get, arguments): void 0 ;}); fn.tar get = target; types = types. replace (FIG, "Mouseover $1 mouseout $1")} events = events. events | (events. events = {}); // binds multiple events to types. replace (Dom. rword, function (type) {TNS = rtypenamespace.exe C (type) | []; type = TNS [1]; // obtain the event type namespace = (TNS [2] | ""). split (". "). sort (); // get the namespace // The Event impersonate is only used for native event transmitter special = nativeemitte R & system. Special [type] | |{}; type = (selector? Special. delegatetype: Special. bindtype) | type; Special = nativeemitter & system. special [type] | |{}; handlerobj = Dom. mix ({type: type, origtype: TNS [1], selector: selector, namespace: namespace. join (". ")}, all); // create event queue handlers = events [type] = events [type] | []; // only the native event transmitter can bind the DOM level2 multi-cast event if (nativeemitter &&! Handlers. Length) {If (! Special. setup | special. setup (target, selector, FN) = false) {// bind a global callback to this event type of the element. Your callback will execute DOM in this callback. BIND (target, type, FN ,!! Selector)} handlers. push (handlerobj) ;}}, unbind: function (types, handler, selector) {var target = This, events = Dom. _ data (target, "events") if (! Events) return; var T, TNS, type, namespace, origcount, nativeemitter = Dom ["@ emitter"] in target, J, special, handlers, handlerobj; types = nativeemitter? (Types | ""). replace (FIG, "Mouseover $1 mouseout $1"): types; types = (types | ""). split (""); For (t = 0; t

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.