123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670 |
-
- Namespace.register("U.UF.EV");
- U.UF.EV.systemEventBind = function (fun) {
- U.selectEl('body').bind(fun);
- U.UF.EV.systemEventBind, Array.push(fun);
- }
- U.UF.EV.boundProperties = function (obj, str, fun1, fun2) {
-
- if (obj.__defineGetter__) {
- obj.__defineGetter__ = (obj, fun1);
- obj.__defineSetter__ = (obj, fun2);
- } else if (Object.defineProperty) {
-
-
-
-
-
-
-
-
- Object.defineProperty(obj, str, { configurable: true, get: fun1, set: fun2 });
- } else {
- obj[str] = fun1;
- obj[str].toString = fun1;
-
- obj.attachEvent("onpropertychange", function () {
- if (event.propertyName == obj) {
-
-
- var _str = arguments.caller.caller;
- obj.detachEvent("onpropertychange", _str);
- fun2(obj[str]);
- obj[str] = fun1;
- obj[str].toString = fun2;
- obj.attachEvent("onpropertychange", _str);
- }
- });
- }
- }
- U.UF.EV.addPrototype = function (obj, str, fun) {
-
- if (typeof str == "string") {
- obj.prototype[str] = fun;
- } else {
- var i;
- for (i in str) {
- obj.prototype[i] = str[i];
- }
- }
- }
- U.UF.EV.scrollLoad = function (obj, fun) {
- obj.onscroll = function () {
- clearTimeout(U.UF.EV.scrollLoad.time);
- if (U.UF.EV.scrollLoad.scrollTop(obj) + U.UF.EV.scrollLoad.windowHeight(obj) >= (U.UF.EV.scrollLoad.documentHeight(obj))) {
- U.UF.EV.scrollLoad.time = setTimeout(fun, 100);
- }
- }
- }
- U.UF.EV.scrollLoad.scrollTop = function (obj) {
- return Math.max(
-
- U.selectEl(obj)[0].scrollTop,
-
- document.documentElement.scrollTop
- );
- }
- U.UF.EV.scrollLoad.documentHeight = function (obj) {
-
- return Math.max($(obj)[0].scrollHeight, document.documentElement.scrollHeight);
- }
- U.UF.EV.scrollLoad.windowHeight = function (obj) {
- return U.selectEl(obj)[0].clientHeight;
- }
- U.UF.EV.IsActivity = function (fun1, fun2) {
- var _timer;
-
- if (fun1) {
-
- U.selectEl(document.body).mouseenter(function () {
-
- if (_timer) {
- window.clearTimeout(_timer);
- }
- _timer = window.setTimeout(fun1);
- });
-
- U.UF.EV.addElementEvent("focusin", document, function () {
-
- if (_timer) {
- window.clearTimeout(_timer);
- }
- _timer = window.setTimeout(fun1);
- });
- }
-
- if (fun2) {
-
- U.UF.EV.addElementEvent("focusout", document, function () {
- var _clientx = event.clientX;
- var _clienty = event.clientY;
-
- if ((!(U.UF.CI.getBrowser().browser == "msie") ||
- (_clientx < 0 || _clientx > US.width || _clienty < 0 || _clienty > US.height))) {
- fun2();
- }
- });
- }
- }
- U.UF.EV.scrollToPosition = function (str, fun1, fun2) {
- var _isnumber = U.UF.C.isNumber(str);
-
- if (_isnumber && fun2) {
- U.selectEl(fun1).animate({ "scrollTop": str }, fun2);
- }
- else {
-
- if (typeof str == "number") {
- fun1.scrollTop = str;
- }
- else {
- str.scrollIntoView();
- }
- }
- }
- U.UF.EV.simulateMouseClicks = function (el, str) {
-
- if (el.fireEvent) {
- return el.fireEvent("on" + str, window.event);
- }
-
- else if (document.createEvent) {
- var _mousevent = document.createEvent("MouseEvents"),
- _event = window.event;
-
- if (_event) {
-
- _mousevent.initMouseEvent(
- str,
- true,
- true,
- window,
- _event.detail,
- _event.screenX,
- _event.screenY,
- _event.clientX,
- _event.clientY,
- _event.ctrlKey,
- _event.altKey,
- _event.shiftKey,
- _event.metaKey,
- _event.button,
- _event.relatedTarget
- );
- }
- else {
-
- _mousevent.initMouseEvent(
- str,
- true,
- true,
- document.defaultView,
- 0,
- 0,
- 0,
- 0,
- 0,
- false,
- false,
- false,
- false,
- 0,
- el
- )
- }
-
- return el.dispatchEvent(_mousevent);
- }
- }
- U.UF.EV.simulatePhoneTouch = function (el, str, obj) {
- if (el.fireEvent) {
- el.fireEvent("on" + TF);
- }
- else if (document.createEvent) {
- var i,
- _arr,
- _event = obj || window.event;
-
- if (TouchEvent) {
- var _touchevent = new TouchEvent(str, _event);
- }
-
- else {
- var _touchevent = document.createEvent("TouchEvent");
- }
-
- if (_touchevent.initTouchEvent) {
- var _str = "initTouchEvent";
- }
- else {
- var _str = "initEvent";
- }
-
- _arr = [
-
- [
- event.touches,
- event.targetTouches,
- event.changedTouches,
- str,
- event.view,
- event.screenX,
- event.screenY,
- event.clientX,
- event.clientY,
- event.ctrlKey,
- event.alrKey,
- event.shiftKey,
- event.metaKey
- ],
-
- [
- str,
- true,
- event.cancelable,
- event.view,
- event.detail,
- event.screenX,
- event.screenY,
- event.clientX,
- event.clientY,
- event.ctrlKey,
- event.altKey,
- event.shiftKey,
- event.metaKey,
- event.touches,
- event.targetTouches,
- event.changedTouches,
- event.scale,
- event.rotation
- ],
-
- [
- str,
- true,
- event.cancelable,
- event.view,
- event.detail,
- event.ctrlKey,
- event.altKey,
- event.shiftKey,
- event.metaKey,
- event.touches,
- event.targetTouches,
- event.changedTouches
- ],
- ];
-
- for (i = 0; i < _arr.length; i++) {
-
- try {
- _touchevent[_str].apply(_touchevent, _arr[i]);
- }
- catch (e) {
- }
- if (_touchevent.type == str) {
- break;
- }
- }
- }
- return el.dispatchEvent(_touchevent);
- }
- U.UF.EV.addElementEvent = function (str, el, fun, isbubble) {
- if (el.addEventListener) {
- el.addEventListener(str, fun, isbubble || false);
- }
- else if (el.attachEvent) {
- el.attachEvent("on" + str, fun);
- }
- else {
- el["on" + str] = function () {
- el["on" + str]();
- fun();
- }
- }
- }
- U.UF.EV.delElementEvent = function (str, el, fun, isbubble) {
- if (el.removeEventListener) {
- el.removeEventListener(str, fun, isbubble || false);
- }
- else if (el.detachEvent) {
- el.detachEvent("on" + str, fun);
- }
- else { el["on" + str] = null; }
- }
- U.UF.EV.getEventSource = function () {
- var i,
- _data,
- _frames = window.frames;
- var _event = window.event;
- if (!_event) {
- for (i = 0; i < _frames.length; i++) {
- _data = _frames[i];
-
- try {
- _event = _data.event;
-
- if (_event) {
- break;
- }
- }
- catch (e) { continue; };
- }
- }
-
- return _event;
- }
- U.UF.EV.stopBubble = function () {
- var _event = U.UF.EV.getEventSource();
-
- if (_event) {
-
- if (_event.stopPropagation) {
- _event.stopPropagation();
- }
-
- else {
- _event.cancelBubble = true;
- }
- }
- }
- U.UF.EV.stopBubbleMouseOutOrOver = function (el, cb) {
- if (event && "mouseover,mouseout".indexOf(event.type) > -1) {
- var _target = (event.type == "mouseover" ? event.fromElement : event.toElement) || event.relatedTarget,
- _bool = U.UF.EL.isChild(el, _target);
- if (!_bool && U.UF.C.isFunction(cb)) {
- cb();
- }
- return _bool;
- }
- }
- U.UF.EV.stopDefault = function (e) {
- var _event = e || window.event;
- if (_event) {
-
- if (document.all) {
- _event.returnValue = false;
- }
-
- else {
- _event.preventDefault();
- }
- return false;
- }
- }
- U.UF.EV.eventDelegation = function (cb, params, isremove, id) {
- if (isremove == null) {
- isremove = true;
- }
- var _id = id || "a" + Guid.newGuid();
- window[_id] = function () {
- try {
-
- if (U.UF.C.isFunction(cb)) {
- cb.apply(null, arguments);
- }
-
- if (this.isremove) {
- window[_id] = null;
- delete window[_id];
- }
- }
- catch (e) { }
- }
- return _id;
- }
- U.UF.EV.message = function (fun, issender, id, iframeid) {
- this.fun = fun;
- this.id = id || Guid.guidNoDash();
- this.sender = issender;
- this.iframeid = iframeid;
- this.iframe = null;
- this.url = "";
- U.UF.EV.message.callbacks[this.id] = this;
-
- if ("onmessage" in window) {
- U.UF.EV.addElementEvent("message", window, U.UF.EV.message.getDataAndCallBack);
- }
-
- if (this.sender) {
- this.iframe = U.selectEl("#" + this.iframeid)[0];
- this.url = $$("a", { "src": this.iframe.src }).host;
- }
-
- else if (!("onmessage" in window)) {
- U.UF.EV.message.getDataAndCallBack();
- }
- }
- U.UF.EV.message.callbacks = [];
- U.UF.EV.message.getDataAndCallBack = function (message) {
- var _data;
-
- if ("onmessage" in window) {
- _data = message.data;
- }
-
- else {
- _data = window.name;
- }
- _data = _data.parseJSON();
- var _fun = U.UF.EV.message.callbacks[_data[1]];
-
- if (_fun) {
- _fun.message(_data[0], _data[1], _data[2]);
- }
- }
- U.UF.EV.message.prototype = {
-
- message: function (data, id, cookie) {
-
- if (U.UF.C.isFunction(this.fun)) {
- this.fun(data, id, cookie);
- }
-
- if (this.sender && !("onmessage" in window)) {
- var _doc = this.obj.contentWindow.document;
- _doc.open();
- _doc.write("");
- _doc.close();
- }
- },
-
- post: function (data, id, cookie) {
- var _win,
- _message = U.UF.C.jsonToStr([data, id || this.id, cookie]);
-
- if ("onmessage" in window) {
- if (this.sender) {
-
- try {
- _win = this.iframe.contentWindow || this.iframe;
- }
- catch (e) {
- _win = this.iframe;
- }
- }
- else {
- _win = parent;
- }
- _win.postMessage(_message, "*");
- }
-
- else {
-
- if (this.sender) {
-
- U.UF.DL.iframeLoad(this.iframe, U.UF.C.apply(this, function () {
- this.iframe.contentWindow.name = _message;
- this.iframe.contentWindow.location.href = this.url;
-
- U.UF.DL.iframeLoad(this.iframe, U.UF.C.apply(this, function () {
- U.UF.EV.message.getDataAndCallBack();
- }));
- }));
- this.iframe.src = "about:blank";
- }
-
- else {
- window.name = _message;
- window.src = "about:blank";
- }
- }
- }
- }
- U.UF.EV.print = function (el) {
-
-
-
-
-
- var iframe = document.createElement('iframe');
- var doc = null;
- iframe.setAttribute('style', 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
- document.body.appendChild(iframe);
- doc = iframe.contentWindow.document;
- doc.write('<div>' + el.innerHTML + '</div>');
- doc.close();
- iframe.contentWindow.focus();
- iframe.contentWindow.print();
- if (navigator.userAgent.indexOf("MSIE") > 0) {
- document.body.removeChild(iframe);
- }
- }
|