2010-01-06 00:36:58 +00:00
|
|
|
if (typeof document.getAttribute == 'undefined')
|
2010-01-12 00:15:12 +00:00
|
|
|
document.getAttribute = function() {};
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
if (!window['console']) window['console']={'log':noop, 'error':noop};
|
|
|
|
|
|
2010-03-26 23:27:18 +00:00
|
|
|
var consoleNode,
|
2010-03-24 23:13:42 +00:00
|
|
|
NOOP = 'noop',
|
2010-03-23 21:57:11 +00:00
|
|
|
jQuery = window['jQuery'] || window['$'], // weirdness to make IE happy
|
2010-03-26 23:27:18 +00:00
|
|
|
_ = window['_'],
|
2010-03-30 03:25:42 +00:00
|
|
|
jqLite = jQuery || jqLiteWrap,
|
2010-03-23 21:57:11 +00:00
|
|
|
slice = Array.prototype.slice,
|
|
|
|
|
angular = window['angular'] || (window['angular'] = {}),
|
2010-03-25 21:43:05 +00:00
|
|
|
angularTextMarkup = extensionMap(angular, 'textMarkup'),
|
|
|
|
|
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
|
2010-03-23 21:57:11 +00:00
|
|
|
angularDirective = extensionMap(angular, 'directive'),
|
|
|
|
|
angularWidget = extensionMap(angular, 'widget'),
|
|
|
|
|
angularValidator = extensionMap(angular, 'validator'),
|
|
|
|
|
angularFilter = extensionMap(angular, 'filter'),
|
|
|
|
|
angularFormatter = extensionMap(angular, 'formatter'),
|
|
|
|
|
angularCallbacks = extensionMap(angular, 'callbacks'),
|
|
|
|
|
angularAlert = angular['alert'] || (angular['alert'] = function(){
|
2010-03-15 21:36:50 +00:00
|
|
|
log(arguments); window.alert.apply(window, arguments);
|
2010-01-12 00:15:12 +00:00
|
|
|
});
|
2010-03-15 21:36:50 +00:00
|
|
|
angular['copy'] = copy;
|
2010-01-12 18:25:55 +00:00
|
|
|
|
2010-02-04 23:04:28 +00:00
|
|
|
var isVisible = isVisible || function (element) {
|
2010-03-15 21:36:50 +00:00
|
|
|
return jQuery(element).is(":visible");
|
2010-03-18 19:20:06 +00:00
|
|
|
};
|
2010-02-04 23:04:28 +00:00
|
|
|
|
2010-03-23 21:57:11 +00:00
|
|
|
function foreach(obj, iterator, context) {
|
|
|
|
|
var key;
|
|
|
|
|
if (obj) {
|
|
|
|
|
if (obj.forEach) {
|
|
|
|
|
obj.forEach(iterator, context);
|
2010-03-30 03:25:42 +00:00
|
|
|
} else if (isObject(obj) && isNumber(obj.length)) {
|
2010-03-23 21:57:11 +00:00
|
|
|
for (key = 0; key < obj.length; key++)
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
} else {
|
|
|
|
|
for (key in obj)
|
|
|
|
|
iterator.call(context, obj[key], key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function extend(dst) {
|
|
|
|
|
foreach(arguments, function(obj){
|
|
|
|
|
if (obj !== dst) {
|
|
|
|
|
foreach(obj, function(value, key){
|
|
|
|
|
dst[key] = value;
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
});
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function noop() {}
|
|
|
|
|
function identity($) {return $;}
|
|
|
|
|
function extensionMap(angular, name) {
|
|
|
|
|
var extPoint;
|
|
|
|
|
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
|
|
|
|
|
if (isDefined(fn)) {
|
|
|
|
|
extPoint[name] = extend(fn, prop || {});
|
|
|
|
|
}
|
|
|
|
|
return extPoint[name];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function jqLiteWrap(element) {
|
|
|
|
|
if (typeof element == 'string') {
|
|
|
|
|
var div = document.createElement('div');
|
|
|
|
|
div.innerHTML = element;
|
|
|
|
|
element = div.childNodes[0];
|
|
|
|
|
}
|
|
|
|
|
return element instanceof JQLite ? element : new JQLite(element);
|
|
|
|
|
}
|
2010-03-26 23:27:18 +00:00
|
|
|
function isUndefined(value){ return typeof value == 'undefined'; }
|
2010-03-23 04:29:57 +00:00
|
|
|
function isDefined(value){ return typeof value != 'undefined'; }
|
|
|
|
|
function isObject(value){ return typeof value == 'object';}
|
|
|
|
|
function isString(value){ return typeof value == 'string';}
|
2010-03-30 03:25:42 +00:00
|
|
|
function isNumber(value){ return typeof value == 'number';}
|
2010-03-23 04:29:57 +00:00
|
|
|
function isArray(value) { return value instanceof Array; }
|
|
|
|
|
function isFunction(value){ return typeof value == 'function';}
|
2010-03-24 23:13:42 +00:00
|
|
|
function lowercase(value){ return isString(value) ? value.toLowerCase() : value; }
|
|
|
|
|
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
|
|
|
|
|
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; };
|
2010-03-30 03:25:42 +00:00
|
|
|
function map(obj, iterator, context) {
|
|
|
|
|
var results = [];
|
|
|
|
|
foreach(obj, function(value, index, list) {
|
|
|
|
|
results.push(iterator.call(context, value, index, list));
|
|
|
|
|
});
|
|
|
|
|
return results;
|
|
|
|
|
};
|
|
|
|
|
function size(obj) {
|
|
|
|
|
var size = 0;
|
|
|
|
|
if (obj) {
|
|
|
|
|
if (isNumber(obj.length)) {
|
|
|
|
|
return obj.length;
|
|
|
|
|
} else if (isObject(obj)){
|
|
|
|
|
for (key in obj)
|
|
|
|
|
size++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return size;
|
|
|
|
|
}
|
2010-03-26 23:27:18 +00:00
|
|
|
function includes(array, obj) {
|
|
|
|
|
for ( var i = 0; i < array.length; i++) {
|
|
|
|
|
if (obj === array[i]) return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2010-03-20 05:18:39 +00:00
|
|
|
|
2010-03-30 03:25:42 +00:00
|
|
|
function indexOf(array, obj) {
|
|
|
|
|
for ( var i = 0; i < array.length; i++) {
|
|
|
|
|
if (obj === array[i]) return i;
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-12 18:25:55 +00:00
|
|
|
function log(a, b, c){
|
|
|
|
|
var console = window['console'];
|
|
|
|
|
switch(arguments.length) {
|
|
|
|
|
case 1:
|
|
|
|
|
console['log'](a);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
console['log'](a, b);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
console['log'](a, b, c);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function error(a, b, c){
|
|
|
|
|
var console = window['console'];
|
|
|
|
|
switch(arguments.length) {
|
|
|
|
|
case 1:
|
|
|
|
|
console['error'](a);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
console['error'](a, b);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
console['error'](a, b, c);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
|
|
|
|
|
function consoleLog(level, objs) {
|
2010-01-06 00:36:58 +00:00
|
|
|
var log = document.createElement("div");
|
|
|
|
|
log.className = level;
|
|
|
|
|
var msg = "";
|
|
|
|
|
var sep = "";
|
|
|
|
|
for ( var i = 0; i < objs.length; i++) {
|
|
|
|
|
var obj = objs[i];
|
2010-01-09 23:02:43 +00:00
|
|
|
msg += sep + (typeof obj == 'string' ? obj : toJson(obj));
|
2010-01-06 00:36:58 +00:00
|
|
|
sep = " ";
|
|
|
|
|
}
|
|
|
|
|
log.appendChild(document.createTextNode(msg));
|
2010-01-09 23:02:43 +00:00
|
|
|
consoleNode.appendChild(log);
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function isNode(inp) {
|
2010-01-06 00:36:58 +00:00
|
|
|
return inp &&
|
|
|
|
|
inp.tagName &&
|
|
|
|
|
inp.nodeName &&
|
|
|
|
|
inp.ownerDocument &&
|
|
|
|
|
inp.removeAttribute;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function isLeafNode (node) {
|
2010-03-23 21:57:11 +00:00
|
|
|
if (node) {
|
|
|
|
|
switch (node.nodeName) {
|
|
|
|
|
case "OPTION":
|
|
|
|
|
case "PRE":
|
|
|
|
|
case "TITLE":
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
2010-03-23 21:57:11 +00:00
|
|
|
return false;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-03-15 21:36:50 +00:00
|
|
|
function copy(source, destination){
|
|
|
|
|
if (!destination) {
|
|
|
|
|
if (!source) {
|
|
|
|
|
return source;
|
2010-03-26 23:27:18 +00:00
|
|
|
} else if (isArray(source)) {
|
2010-03-15 21:36:50 +00:00
|
|
|
return copy(source, []);
|
|
|
|
|
} else {
|
|
|
|
|
return copy(source, {});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-03-26 23:27:18 +00:00
|
|
|
if (isArray(source)) {
|
2010-03-15 21:36:50 +00:00
|
|
|
while(destination.length) {
|
|
|
|
|
destination.pop();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2010-03-30 03:25:42 +00:00
|
|
|
foreach(destination, function(value, key){
|
2010-03-15 21:36:50 +00:00
|
|
|
delete destination[key];
|
|
|
|
|
});
|
|
|
|
|
}
|
2010-03-30 03:25:42 +00:00
|
|
|
foreach(source, function(value, key){
|
|
|
|
|
destination[key] = isArray(value) ? copy(value, []) : (isObject(value) ? copy(value, {}) : value);
|
|
|
|
|
});
|
|
|
|
|
return destination;
|
2010-03-15 21:36:50 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function setHtml(node, html) {
|
2010-01-09 23:02:43 +00:00
|
|
|
if (isLeafNode(node)) {
|
|
|
|
|
if (msie) {
|
2010-01-06 00:36:58 +00:00
|
|
|
node.innerText = html;
|
|
|
|
|
} else {
|
|
|
|
|
node.textContent = html;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
node.innerHTML = html;
|
|
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function escapeHtml(html) {
|
2010-01-06 00:36:58 +00:00
|
|
|
if (!html || !html.replace)
|
|
|
|
|
return html;
|
|
|
|
|
return html.
|
|
|
|
|
replace(/&/g, '&').
|
|
|
|
|
replace(/</g, '<').
|
|
|
|
|
replace(/>/g, '>');
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function escapeAttr(html) {
|
2010-01-06 00:36:58 +00:00
|
|
|
if (!html || !html.replace)
|
|
|
|
|
return html;
|
|
|
|
|
return html.replace(/</g, '<').replace(/>/g, '>').replace(/\"/g,
|
|
|
|
|
'"');
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function bind(_this, _function) {
|
2010-03-18 19:20:06 +00:00
|
|
|
var curryArgs = slice.call(arguments, 2, arguments.length);
|
2010-01-06 00:36:58 +00:00
|
|
|
return function() {
|
2010-03-18 19:20:06 +00:00
|
|
|
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
2010-01-06 00:36:58 +00:00
|
|
|
};
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function outerHTML(node) {
|
2010-01-06 00:36:58 +00:00
|
|
|
var temp = document.createElement('div');
|
|
|
|
|
temp.appendChild(node);
|
|
|
|
|
var outerHTML = temp.innerHTML;
|
|
|
|
|
temp.removeChild(node);
|
|
|
|
|
return outerHTML;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function toBoolean(value) {
|
2010-01-06 00:36:58 +00:00
|
|
|
var v = ("" + value).toLowerCase();
|
|
|
|
|
if (v == 'f' || v == '0' || v == 'false' || v == 'no')
|
|
|
|
|
value = false;
|
|
|
|
|
return !!value;
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-12 00:15:12 +00:00
|
|
|
function merge(src, dst) {
|
2010-01-06 00:36:58 +00:00
|
|
|
for ( var key in src) {
|
|
|
|
|
var value = dst[key];
|
|
|
|
|
var type = typeof value;
|
|
|
|
|
if (type == 'undefined') {
|
2010-01-09 23:02:43 +00:00
|
|
|
dst[key] = fromJson(toJson(src[key]));
|
|
|
|
|
} else if (type == 'object' && value.constructor != array &&
|
2010-01-06 00:36:58 +00:00
|
|
|
key.substring(0, 1) != "$") {
|
2010-01-09 23:02:43 +00:00
|
|
|
merge(src[key], value);
|
2010-01-06 00:36:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
2010-01-12 00:15:12 +00:00
|
|
|
}
|
2010-01-06 00:36:58 +00:00
|
|
|
|
2010-01-23 23:54:58 +00:00
|
|
|
/////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
angular['compile'] = function(element, config) {
|
2010-03-26 23:27:18 +00:00
|
|
|
config = extend({
|
2010-02-09 21:13:18 +00:00
|
|
|
'onUpdateView': noop,
|
2010-01-23 23:54:58 +00:00
|
|
|
'server': "",
|
|
|
|
|
'location': {'get':noop, 'set':noop, 'listen':noop}
|
2010-03-26 23:27:18 +00:00
|
|
|
}, config||{});
|
|
|
|
|
|
|
|
|
|
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget);
|
|
|
|
|
$element = jqLite(element),
|
|
|
|
|
rootScope = {
|
|
|
|
|
'$window': window
|
|
|
|
|
};
|
|
|
|
|
return rootScope['$root'] = compiler.compile($element)($element, rootScope);
|
2010-02-17 05:30:15 +00:00
|
|
|
};
|