|
/// <reference path="jquery-1.8.2.min.js" />
(function ($) {
$.extend({
createDelegate: function (context, method) {
return function () {
method.apply(context, arguments);
}
},
createHandler: function (context, method) {
return function (e) {
var sender = this;
method.call(context, sender, e);
}
},
addEventHandler: function (instance, eventType, handler) {
var event = instance.events[eventType];
if (event == null) instance.events[eventType] = [handler];
else {
var index = event.length;
event[index] = handler;
}
},
removeEventHandler: function (instance, eventType, handler) {
var event = instance.events[eventType];
if (event == null) return;
for (var i = 0; i < event.length; i++) {
if (event[i] == handler) {
event[i] = null;
for (var j = i; j < event.length; j++) {
event[j] = event[j + 1];
}
event[event.length - 1] = null;
event.length = event.length - 1;
break;
}
}
},
raiseEvent: function (handlers, sender, e) {
if (handlers == null) return;
for (var i = 0; i < handlers.length; i++) {
var handler = handlers[i];
handler(sender, e);
}
},
getBox: function (el) {
el = $(el);
var offset = el.offset();
var left, right, top, bottom;
left = offset.left;
top = offset.top;
right = left + el.width();
bottom = top + el.height();
return {
left: left,
right: right,
top: top,
bottom: bottom
};
},
getMouseCoords: function (e) {
// pageX/Y is not supported in IE
// http://www.quirksmode.org/dom/w3c_cssom.html
if (!e.pageX && e.clientX) {
// In Internet Explorer 7 some properties (mouse coordinates) are treated as physical,
// while others are logical (offset).
var zoom = 1;
var body = document.body;
if (body.getBoundingClientRect) {
var bound = body.getBoundingClientRect();
zoom = (bound.right - bound.left) / body.clientWidth;
}
return {
x: e.clientX / zoom + d.body.scrollLeft + d.documentElement.scrollLeft,
y: e.clientY / zoom + d.body.scrollTop + d.documentElement.scrollTop
};
}
return {
x: e.pageX,
y: e.pageY
};
},
registerNamespace: function (namespace, parent) {
if (!parent) parent = window;
var parts = namespace.split('.');
var child = parts[0];
if (!parent[child]) parent[child] = {};
if (parts.length > 1) {
namespace = namespace.substr(namespace.indexOf('.') + 1)
$.registerNamespace(namespace, parent[child]);
}
}
});
})(window.jQuery);
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.