2010-03-30 03:25:42 +00:00
|
|
|
//////////////////////////////////
|
2010-03-23 21:57:11 +00:00
|
|
|
//JQLite
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
|
|
|
|
var jqCache = {};
|
|
|
|
|
var jqName = 'ng-' + new Date().getTime();
|
|
|
|
|
var jqId = 1;
|
2010-04-04 00:04:36 +00:00
|
|
|
function jqNextId() { return (jqId++); }
|
2010-03-23 21:57:11 +00:00
|
|
|
|
|
|
|
|
var addEventListener = window.document.attachEvent ?
|
|
|
|
|
function(element, type, fn) {
|
|
|
|
|
element.attachEvent('on' + type, fn);
|
|
|
|
|
} : function(element, type, fn) {
|
|
|
|
|
element.addEventListener(type, fn, false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var removeEventListener = window.document.detachEvent ?
|
|
|
|
|
function(element, type, fn) {
|
|
|
|
|
element.detachEvent('on' + type, fn);
|
|
|
|
|
} : function(element, type, fn) {
|
|
|
|
|
element.removeEventListener(type, fn, false);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function jqClearData(element) {
|
|
|
|
|
var cacheId = element[jqName],
|
|
|
|
|
cache = jqCache[cacheId];
|
|
|
|
|
if (cache) {
|
|
|
|
|
foreach(cache.bind || {}, function(fn, type){
|
|
|
|
|
removeEventListener(element, type, fn);
|
|
|
|
|
});
|
|
|
|
|
delete jqCache[cacheId];
|
2010-04-20 00:02:46 +00:00
|
|
|
if (msie)
|
|
|
|
|
element[jqName] = ''; // ie does not allow deletion of attributes on elements.
|
|
|
|
|
else
|
|
|
|
|
delete element[jqName];
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
2010-04-04 00:04:36 +00:00
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
|
|
|
|
|
function JQLite(element) {
|
2010-04-12 21:28:15 +00:00
|
|
|
if (element.length && element.item) {
|
|
|
|
|
for(var i=0; i < element.length; i++) {
|
|
|
|
|
this[i] = element[i];
|
|
|
|
|
}
|
|
|
|
|
this.length = element.length;
|
|
|
|
|
} else {
|
|
|
|
|
this[0] = element;
|
|
|
|
|
this.length = 1;
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
JQLite.prototype = {
|
|
|
|
|
data: function(key, value) {
|
|
|
|
|
var element = this[0],
|
|
|
|
|
cacheId = element[jqName],
|
|
|
|
|
cache = jqCache[cacheId || -1];
|
|
|
|
|
if (isDefined(value)) {
|
|
|
|
|
if (!cache) {
|
|
|
|
|
element[jqName] = cacheId = jqNextId();
|
|
|
|
|
cache = jqCache[cacheId] = {};
|
|
|
|
|
}
|
|
|
|
|
cache[key] = value;
|
|
|
|
|
} else {
|
|
|
|
|
return cache ? cache[key] : null;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeData: function(){
|
|
|
|
|
jqClearData(this[0]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
dealoc: function(){
|
|
|
|
|
(function dealoc(element){
|
|
|
|
|
jqClearData(element);
|
|
|
|
|
for ( var i = 0, children = element.childNodes; i < children.length; i++) {
|
2010-03-25 20:01:08 +00:00
|
|
|
dealoc(children[i]);
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
})(this[0]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
bind: function(type, fn){
|
2010-03-24 23:13:42 +00:00
|
|
|
var self = this,
|
|
|
|
|
element = self[0],
|
|
|
|
|
bind = self.data('bind'),
|
2010-03-23 21:57:11 +00:00
|
|
|
eventHandler;
|
|
|
|
|
if (!bind) this.data('bind', bind = {});
|
2010-03-24 23:13:42 +00:00
|
|
|
foreach(type.split(' '), function(type){
|
|
|
|
|
eventHandler = bind[type];
|
|
|
|
|
if (!eventHandler) {
|
2010-03-26 23:27:18 +00:00
|
|
|
bind[type] = eventHandler = function(event) {
|
|
|
|
|
var bubbleEvent = false;
|
2010-03-24 23:13:42 +00:00
|
|
|
foreach(eventHandler.fns, function(fn){
|
2010-04-06 03:53:33 +00:00
|
|
|
bubbleEvent = bubbleEvent || fn.call(self, event);
|
2010-03-24 23:13:42 +00:00
|
|
|
});
|
2010-03-26 23:27:18 +00:00
|
|
|
if (!bubbleEvent) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
event.stopPropagation();
|
|
|
|
|
}
|
2010-03-24 23:13:42 +00:00
|
|
|
};
|
|
|
|
|
eventHandler.fns = [];
|
|
|
|
|
addEventListener(element, type, eventHandler);
|
|
|
|
|
}
|
|
|
|
|
eventHandler.fns.push(fn);
|
|
|
|
|
});
|
2010-03-23 21:57:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
trigger: function(type) {
|
2010-03-25 20:01:08 +00:00
|
|
|
var evnt = document.createEvent('MouseEvent');
|
|
|
|
|
evnt.initMouseEvent(type, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
|
|
|
this[0].dispatchEvent(evnt);
|
2010-03-23 21:57:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
click: function(fn) {
|
|
|
|
|
if (fn)
|
|
|
|
|
this.bind('click', fn);
|
|
|
|
|
else
|
|
|
|
|
this.trigger('click');
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
replaceWith: function(replaceNode) {
|
|
|
|
|
this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]);
|
|
|
|
|
},
|
|
|
|
|
|
2010-04-05 18:46:53 +00:00
|
|
|
append: function(node) {
|
2010-04-12 21:28:15 +00:00
|
|
|
var self = this[0];
|
|
|
|
|
node = jqLite(node);
|
|
|
|
|
foreach(node, function(child){
|
|
|
|
|
self.appendChild(child);
|
|
|
|
|
});
|
2010-04-05 18:46:53 +00:00
|
|
|
},
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
remove: function() {
|
|
|
|
|
this.dealoc();
|
2010-04-06 04:26:52 +00:00
|
|
|
var parentNode = this[0].parentNode;
|
|
|
|
|
if (parentNode) parentNode.removeChild(this[0]);
|
2010-03-23 21:57:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeAttr: function(name) {
|
|
|
|
|
this[0].removeAttribute(name);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
after: function(element) {
|
|
|
|
|
this[0].parentNode.insertBefore(jqLite(element)[0], this[0].nextSibling);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
hasClass: function(selector) {
|
|
|
|
|
var className = " " + selector + " ";
|
|
|
|
|
if ( (" " + this[0].className + " ").replace(/[\n\t]/g, " ").indexOf( className ) > -1 ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
},
|
|
|
|
|
|
2010-03-24 23:13:42 +00:00
|
|
|
removeClass: function(selector) {
|
|
|
|
|
this[0].className = trim((" " + this[0].className + " ").replace(/[\n\t]/g, " ").replace(" " + selector + " ", ""));
|
|
|
|
|
},
|
|
|
|
|
|
2010-04-08 20:43:40 +00:00
|
|
|
toggleClass: function(selector, condition) {
|
|
|
|
|
var self = this;
|
|
|
|
|
(condition ? self.addClass : self.removeClass).call(self, selector);
|
|
|
|
|
},
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
addClass: function( selector ) {
|
|
|
|
|
if (!this.hasClass(selector)) {
|
2010-03-31 20:57:25 +00:00
|
|
|
this[0].className = trim(this[0].className + ' ' + selector);
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
css: function(name, value) {
|
|
|
|
|
var style = this[0].style;
|
|
|
|
|
if (isString(name)) {
|
|
|
|
|
if (isDefined(value)) {
|
|
|
|
|
style[name] = value;
|
|
|
|
|
} else {
|
|
|
|
|
return style[name];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
extend(style, name);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
attr: function(name, value){
|
|
|
|
|
var e = this[0];
|
|
|
|
|
if (isObject(name)) {
|
|
|
|
|
foreach(name, function(value, name){
|
|
|
|
|
e.setAttribute(name, value);
|
|
|
|
|
});
|
|
|
|
|
} else if (isDefined(value)) {
|
|
|
|
|
e.setAttribute(name, value);
|
|
|
|
|
} else {
|
2010-04-16 21:01:29 +00:00
|
|
|
return e.getAttribute ? e.getAttribute(name) : undefined;
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
text: function(value) {
|
|
|
|
|
if (isDefined(value)) {
|
2010-04-19 21:36:41 +00:00
|
|
|
this[0].textContent = value;
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
2010-04-19 21:36:41 +00:00
|
|
|
return this[0].textContent;
|
2010-03-23 21:57:11 +00:00
|
|
|
},
|
|
|
|
|
|
2010-03-24 23:47:11 +00:00
|
|
|
val: function(value) {
|
|
|
|
|
if (isDefined(value)) {
|
|
|
|
|
this[0].value = value;
|
|
|
|
|
}
|
|
|
|
|
return this[0].value;
|
|
|
|
|
},
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
html: function(value) {
|
|
|
|
|
if (isDefined(value)) {
|
2010-04-05 18:46:53 +00:00
|
|
|
for ( var i = 0, children = this[0].childNodes; i < children.length; i++) {
|
|
|
|
|
jqLite(children[i]).dealoc();
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
this[0].innerHTML = value;
|
|
|
|
|
}
|
|
|
|
|
return this[0].innerHTML;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
parent: function() { return jqLite(this[0].parentNode);},
|
|
|
|
|
clone: function() { return jqLite(this[0].cloneNode(true)); }
|
|
|
|
|
};
|
2010-04-19 21:36:41 +00:00
|
|
|
|
|
|
|
|
if (msie) {
|
|
|
|
|
extend(JQLite.prototype, {
|
|
|
|
|
text: function(value) {
|
|
|
|
|
var e = this[0];
|
|
|
|
|
if (isDefined(value)) {
|
|
|
|
|
e.innerText = value;
|
|
|
|
|
}
|
|
|
|
|
// NodeType == 3 is text node
|
|
|
|
|
return e.nodeType == 3 ? e.nodeValue : e.innerText;
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
trigger: function(type) {
|
|
|
|
|
this[0].fireEvent('on' + type);
|
|
|
|
|
}
|
|
|
|
|
});
|
2010-04-19 21:41:36 +00:00
|
|
|
}
|