JavaScript fixevent Function Instance

Source: Internet
Author: User


Dom.oneobject = function (arr,val) {
var result = {},value = val!== undefined? Val:1;
for (Var i=0,n=arr.length;i<n;i++)
Result[arr[i]] = value;
return result;
};
Dom.mixin = function (result, source) {
if (arguments.length = = 1) {
Source = result;
result = DOM;
}
If (result && source) {
for (var key in Source)
Source.hasownproperty (Key) && (Result[key] = Source[key]);
}
if (Arguments.length > 2) {
var others = [].slice.call (arguments,2);
for (Var i=0,n=others.length;i<n;i++) {
result = Arguments.callee (Result,others[i]);
}
}
return result;
}
var mouseeventone = Dom.oneobject (["Click", "DblClick", "MouseDown",
"MouseMove", "mouseout", "MouseOver", "MouseUp"], "[Object MouseEvent]");
var htmleventone = Dom.oneobject (["Abort", "blur", "Change", "error", "Focus",
"Load", "reset", "resize", "scroll", "select", "Submit", "unload"], "[Object Event]");
var keyboardeventone = Dom.oneobject (["KeyUp", "KeyDown", "KeyPress",],
"[Object KeyboardEvent]");
var EventMap = dom.mixin ({},mouseeventone,htmleventone,keyboardeventone)
var fn = "Prototype";
Dom. Event = function (src) {
if (!this.preventdefault) {
Return to new DOM. Event[fn].init (SRC);
}
};
function Returnfalse () {
return false;
}
function Returntrue () {
return true;
}
Http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html
Dom. EVENT[FN] = {
Init:function (SRC) {
If the event object is passed in
if (src && src.type) {
This.originalevent = src;
This.type = Src.type;
If the event type is passed in
} else {
This.type = src;
}
This.timestamp = new Date (). valueof ();
this["expando"] = true;
},
Http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/events.html#Conformance
Tostring:function () {
return Eventmap[this.type] | | "[Object Event]"
},
Preventdefault:function () {
this.isdefaultprevented = Returntrue;
var e = this.originalevent;
if (!e) {
Return
}
If there is a preventdefault then call it
if (E.preventdefault) {
E.preventdefault ();
}
If there is a returnvalue then set it to False
E.returnvalue = false;
},
Stoppropagation:function () {
this.ispropagationstopped = Returntrue;
var e = this.originalevent;
if (!e) {
Return
}
If there is a preventdefault then call it
if (e.stoppropagation) {
E.stoppropagation ();
}
If there is a returnvalue then set it to True
E.cancelbubble = true;
},
Stopimmediatepropagation:function () {
this.isimmediatepropagationstopped = Returntrue;
This.stoppropagation ();
},
Isdefaultprevented:returnfalse,
Ispropagationstopped:returnfalse,
Isimmediatepropagationstopped:returnfalse
};
Dom. EVENT[FN].INIT[FN] = dom. EVENT[FN];

Related Article

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.