2010-03-30 03:25:42 +00:00
|
|
|
//////////////////////////////////
|
2010-03-23 21:57:11 +00:00
|
|
|
//JQLite
|
|
|
|
|
//////////////////////////////////
|
|
|
|
|
|
2010-08-11 19:04:02 +00:00
|
|
|
var jqCache = {},
|
|
|
|
|
jqName = 'ng-' + new Date().getTime(),
|
|
|
|
|
jqId = 1,
|
2011-01-10 07:18:53 +00:00
|
|
|
addEventListenerFn = (window.document.addEventListener ?
|
|
|
|
|
function(element, type, fn) {element.addEventListener(type, fn, false);} :
|
|
|
|
|
function(element, type, fn) {element.attachEvent('on' + type, fn);}),
|
|
|
|
|
removeEventListenerFn = (window.document.removeEventListener ?
|
|
|
|
|
function(element, type, fn) {element.removeEventListener(type, fn, false); } :
|
|
|
|
|
function(element, type, fn) {element.detachEvent('on' + type, fn); });
|
2010-03-23 21:57:11 +00:00
|
|
|
|
2010-08-11 19:04:02 +00:00
|
|
|
function jqNextId() { return (jqId++); }
|
2010-03-23 21:57:11 +00:00
|
|
|
|
|
|
|
|
function jqClearData(element) {
|
|
|
|
|
var cacheId = element[jqName],
|
|
|
|
|
cache = jqCache[cacheId];
|
|
|
|
|
if (cache) {
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(cache.bind || {}, function(fn, type){
|
2011-01-05 01:36:51 +00:00
|
|
|
removeEventListenerFn(element, type, fn);
|
2010-03-23 21:57:11 +00:00
|
|
|
});
|
|
|
|
|
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
|
|
|
|
2010-07-15 00:48:09 +00:00
|
|
|
function getStyle(element) {
|
2010-07-15 21:16:04 +00:00
|
|
|
var current = {}, style = element[0].style, value, name, i;
|
|
|
|
|
if (typeof style.length == 'number') {
|
|
|
|
|
for(i = 0; i < style.length; i++) {
|
|
|
|
|
name = style[i];
|
|
|
|
|
current[name] = style[name];
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
for (name in style) {
|
|
|
|
|
value = style[name];
|
|
|
|
|
if (1*name != name && name != 'cssText' && value && typeof value == 'string' && value !='false')
|
|
|
|
|
current[name] = value;
|
|
|
|
|
}
|
2010-07-15 00:48:09 +00:00
|
|
|
}
|
|
|
|
|
return current;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
function JQLite(element) {
|
2011-01-10 07:21:48 +00:00
|
|
|
if (!isElement(element) && isDefined(element.length) && element.item && !isWindow(element)) {
|
2010-04-12 21:28:15 +00:00
|
|
|
for(var i=0; i < element.length; i++) {
|
|
|
|
|
this[i] = element[i];
|
|
|
|
|
}
|
|
|
|
|
this.length = element.length;
|
2011-01-05 01:54:37 +00:00
|
|
|
} else {
|
|
|
|
|
this[0] = element;
|
|
|
|
|
this.length = 1;
|
2010-04-12 21:28:15 +00:00
|
|
|
}
|
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 {
|
2010-08-18 23:23:12 +00:00
|
|
|
return cache ? cache[key] : _null;
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
removeData: function(){
|
|
|
|
|
jqClearData(this[0]);
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
dealoc: function(){
|
|
|
|
|
(function dealoc(element){
|
|
|
|
|
jqClearData(element);
|
2011-01-05 01:54:37 +00:00
|
|
|
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]);
|
|
|
|
|
},
|
|
|
|
|
|
2011-01-09 08:57:24 +00:00
|
|
|
ready: function(fn) {
|
|
|
|
|
var fired = false;
|
|
|
|
|
|
|
|
|
|
function trigger() {
|
|
|
|
|
if (fired) return;
|
|
|
|
|
fired = true;
|
|
|
|
|
fn();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.bind('DOMContentLoaded', trigger); // works for modern browsers and IE9
|
2011-02-05 00:42:21 +00:00
|
|
|
// we can not use jqLite since we are not done loading and jQuery could be loaded later.
|
|
|
|
|
new JQLite(window).bind('load', trigger); // fallback to window.onload for others
|
2011-01-09 08:57:24 +00:00
|
|
|
},
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
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 = {});
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(type.split(' '), function(type){
|
2010-03-24 23:13:42 +00:00
|
|
|
eventHandler = bind[type];
|
|
|
|
|
if (!eventHandler) {
|
2010-03-26 23:27:18 +00:00
|
|
|
bind[type] = eventHandler = function(event) {
|
2010-07-27 22:54:50 +00:00
|
|
|
if (!event.preventDefault) {
|
2010-07-27 23:53:23 +00:00
|
|
|
event.preventDefault = function(){
|
2010-09-30 23:33:34 +00:00
|
|
|
event.returnValue = false; //ie
|
2010-07-29 19:50:14 +00:00
|
|
|
};
|
2010-07-27 22:54:50 +00:00
|
|
|
}
|
2010-09-30 23:33:34 +00:00
|
|
|
if (!event.stopPropagation) {
|
|
|
|
|
event.stopPropagation = function() {
|
|
|
|
|
event.cancelBubble = true; //ie
|
2010-10-04 16:00:09 +00:00
|
|
|
};
|
2010-09-30 23:33:34 +00:00
|
|
|
}
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(eventHandler.fns, function(fn){
|
2010-07-27 22:54:50 +00:00
|
|
|
fn.call(self, event);
|
2010-03-24 23:13:42 +00:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
eventHandler.fns = [];
|
2011-01-05 01:36:51 +00:00
|
|
|
addEventListenerFn(element, type, eventHandler);
|
2010-03-24 23:13:42 +00:00
|
|
|
}
|
|
|
|
|
eventHandler.fns.push(fn);
|
|
|
|
|
});
|
2010-03-23 21:57:11 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
replaceWith: function(replaceNode) {
|
|
|
|
|
this[0].parentNode.replaceChild(jqLite(replaceNode)[0], this[0]);
|
|
|
|
|
},
|
|
|
|
|
|
2010-04-22 22:50:20 +00:00
|
|
|
children: function() {
|
|
|
|
|
return new JQLite(this[0].childNodes);
|
|
|
|
|
},
|
|
|
|
|
|
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);
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(node, function(child){
|
2010-04-12 21:28:15 +00:00
|
|
|
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];
|
|
|
|
|
}
|
2010-07-15 00:07:23 +00:00
|
|
|
} else {
|
2010-07-15 00:48:09 +00:00
|
|
|
extend(style, name);
|
2010-03-23 21:57:11 +00:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
attr: function(name, value){
|
|
|
|
|
var e = this[0];
|
|
|
|
|
if (isObject(name)) {
|
2011-01-08 06:02:23 +00:00
|
|
|
forEach(name, function(value, name){
|
2010-03-23 21:57:11 +00:00
|
|
|
e.setAttribute(name, value);
|
|
|
|
|
});
|
|
|
|
|
} else if (isDefined(value)) {
|
|
|
|
|
e.setAttribute(name, value);
|
|
|
|
|
} else {
|
2011-01-30 22:43:53 +00:00
|
|
|
// the extra argument "2" is to get the right thing for a.href in IE, see jQuery code
|
|
|
|
|
// some elements (e.g. Document) don't have get attribute, so return undefined
|
|
|
|
|
if (e.getAttribute) return e.getAttribute(name, 2);
|
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-23 05:44:48 +00:00
|
|
|
var i = 0, childNodes = this[0].childNodes;
|
|
|
|
|
for ( ; i < childNodes.length; i++) {
|
|
|
|
|
jqLite(childNodes[i]).dealoc();
|
2010-04-05 18:46:53 +00:00
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
this[0].innerHTML = value;
|
|
|
|
|
}
|
|
|
|
|
return this[0].innerHTML;
|
|
|
|
|
},
|
|
|
|
|
|
2010-04-26 23:49:34 +00:00
|
|
|
parent: function() {
|
|
|
|
|
return jqLite(this[0].parentNode);
|
|
|
|
|
},
|
|
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
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];
|
|
|
|
|
// NodeType == 3 is text node
|
2010-04-26 23:49:34 +00:00
|
|
|
if (e.nodeType == 3) {
|
|
|
|
|
if (isDefined(value)) e.nodeValue = value;
|
|
|
|
|
return e.nodeValue;
|
|
|
|
|
} else {
|
|
|
|
|
if (isDefined(value)) e.innerText = value;
|
|
|
|
|
return e.innerText;
|
|
|
|
|
}
|
2010-04-19 21:36:41 +00:00
|
|
|
}
|
|
|
|
|
});
|
2010-04-19 21:41:36 +00:00
|
|
|
}
|