aboutsummaryrefslogtreecommitdiffstats
path: root/src/Angular.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/Angular.js')
-rw-r--r--src/Angular.js157
1 files changed, 74 insertions, 83 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 2b26c88d..3970f762 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -3,8 +3,6 @@
if (typeof document.getAttribute == 'undefined')
document.getAttribute = function() {};
-if (!window['console']) window['console']={'log':noop, 'error':noop};
-
var consoleNode,
PRIORITY_FIRST = -99999,
PRIORITY_WATCH = -1000,
@@ -18,11 +16,12 @@ var consoleNode,
msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)),
jqLite = jQuery || jqLiteWrap,
slice = Array.prototype.slice,
+ error = window['console'] ? bind(window['console'], window['console']['error'] || noop) : noop,
angular = window['angular'] || (window['angular'] = {}),
- angularTextMarkup = extensionMap(angular, 'textMarkup'),
+ angularTextMarkup = extensionMap(angular, 'markup'),
angularAttrMarkup = extensionMap(angular, 'attrMarkup'),
angularDirective = extensionMap(angular, 'directive'),
- angularWidget = extensionMap(angular, 'widget'),
+ angularWidget = extensionMap(angular, 'widget', lowercase),
angularValidator = extensionMap(angular, 'validator'),
angularFilter = extensionMap(angular, 'filter'),
angularFormatter = extensionMap(angular, 'formatter'),
@@ -30,10 +29,6 @@ var consoleNode,
angularCallbacks = extensionMap(angular, 'callbacks'),
nodeName;
-function angularAlert(){
- log(arguments); window.alert.apply(window, arguments);
-}
-
function foreach(obj, iterator, context) {
var key;
if (obj) {
@@ -78,11 +73,16 @@ function extend(dst) {
return dst;
}
+function inherit(parent, extra) {
+ return extend(new (extend(function(){}, {prototype:parent}))(), extra);
+};
+
function noop() {}
function identity($) {return $;}
-function extensionMap(angular, name) {
+function extensionMap(angular, name, transform) {
var extPoint;
return angular[name] || (extPoint = angular[name] = function (name, fn, prop){
+ name = (transform || identity)(name);
if (isDefined(fn)) {
extPoint[name] = extend(fn, prop || {});
}
@@ -173,50 +173,6 @@ function indexOf(array, obj) {
return -1;
}
-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;
- }
-}
-
-function consoleLog(level, objs) {
- var log = document.createElement("div");
- log.className = level;
- var msg = "";
- var sep = "";
- for ( var i = 0; i < objs.length; i++) {
- var obj = objs[i];
- msg += sep + (typeof obj == 'string' ? obj : toJson(obj));
- sep = " ";
- }
- log.appendChild(document.createTextNode(msg));
- consoleNode.appendChild(log);
-}
-
function isLeafNode (node) {
if (node) {
switch (node.nodeName) {
@@ -259,6 +215,32 @@ function copy(source, destination){
}
}
+function equals(o1, o2) {
+ if (o1 == o2) return true;
+ var t1 = typeof o1, t2 = typeof o2, length, key, keySet;
+ if (t1 == t2 && t1 == 'object') {
+ if (o1 instanceof Array) {
+ if ((length = o1.length) == o2.length) {
+ for(key=0; key<length; key++) {
+ if (!equals(o1[key], o2[key])) return false;
+ }
+ return true;
+ }
+ } else {
+ keySet = {};
+ for(key in o1) {
+ if (key.charAt(0) !== '$' && !equals(o1[key], o2[key])) return false;
+ keySet[key] = true;
+ }
+ for(key in o2) {
+ if (key.charAt(0) !== '$' && keySet[key] !== true) return false;
+ }
+ return true;
+ }
+ }
+ return false;
+}
+
function setHtml(node, html) {
if (isLeafNode(node)) {
if (msie) {
@@ -309,27 +291,24 @@ function escapeAttr(html) {
'&quot;');
}
-function bind(_this, _function) {
- if (!isFunction(_function))
- throw "Not a function!";
- var curryArgs = slice.call(arguments, 2, arguments.length);
- return function() {
- return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
- };
-}
-
-function outerHTML(node) {
- var temp = document.createElement('div');
- temp.appendChild(node);
- var outerHTML = temp.innerHTML;
- temp.removeChild(node);
- return outerHTML;
+function bind(self, fn) {
+ var curryArgs = arguments.length > 2 ? slice.call(arguments, 2, arguments.length) : [];
+ if (typeof fn == 'function') {
+ return curryArgs.length ? function() {
+ return arguments.length ? fn.apply(self, curryArgs.concat(slice.call(arguments, 0, arguments.length))) : fn.apply(self, curryArgs);
+ }: function() {
+ return arguments.length ? fn.apply(self, arguments) : fn.call(self);
+ };
+ } else {
+ // in IE, native methods ore not functions and so they can not be bound (but they don't need to be)
+ return fn;
+ }
}
function toBoolean(value) {
if (value && value.length !== 0) {
var v = lowercase("" + value);
- value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == '[]');
+ value = !(v == 'f' || v == '0' || v == 'false' || v == 'no' || v == 'n' || v == '[]');
} else {
value = false;
}
@@ -349,12 +328,11 @@ function merge(src, dst) {
}
}
-function compile(element, parentScope, overrides) {
+function compile(element, existingScope) {
var compiler = new Compiler(angularTextMarkup, angularAttrMarkup, angularDirective, angularWidget),
- $element = jqLite(element),
- parent = extend({}, parentScope);
+ $element = jqLite(element);
parent.$element = $element;
- return compiler.compile($element)($element, parent, overrides);
+ return compiler.compile($element)($element, existingScope);
}
/////////////////////////////////////////////////
@@ -363,8 +341,8 @@ function parseKeyValue(keyValue) {
foreach((keyValue || "").split('&'), function(keyValue){
if (keyValue) {
key_value = keyValue.split('=');
- key = decodeURIComponent(key_value[0]);
- obj[key] = key_value[1] ? decodeURIComponent(key_value[1]) : true;
+ key = unescape(key_value[0]);
+ obj[key] = key_value[1] ? unescape(key_value[1]) : true;
}
});
return obj;
@@ -373,29 +351,42 @@ function parseKeyValue(keyValue) {
function toKeyValue(obj) {
var parts = [];
foreach(obj, function(value, key){
- parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
+ parts.push(escape(key) + '=' + escape(value));
});
return parts.length ? parts.join('&') : '';
}
function angularInit(config){
if (config.autobind) {
- var scope = compile(window.document, null, {'$config':config});
// TODO default to the source of angular.js
- scope.$browser.addCss('css/angular.css');
+ var scope = compile(window.document, null, {'$config':config});
+ if (config.css)
+ scope.$browser.addCss(config.base_url + config.css);
scope.$init();
}
}
-function angularJsConfig(document) {
- var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/,
- scripts = document.getElementsByTagName("SCRIPT"),
+function angularJsConfig(document, config) {
+ var filename = /^(.*)\/angular(-([^\/]*))?.js(#(.*))?$/,
+ scripts = document.getElementsByTagName("script"),
match;
+ config = extend({
+ base_url: '',
+ css: '../css/angular.css'
+ }, config);
for(var j = 0; j < scripts.length; j++) {
match = (scripts[j].src || "").match(filename);
if (match) {
- return match[5];
+ config.base_url = match[1] + '/';
+ extend(config, parseKeyValue(match[5]));
+ eachAttribute(jqLite(scripts[j]), function(value, name){
+ if (/^ng:/.exec(name)) {
+ name = name.substring(3).replace(/-/g, '_');
+ if (name == 'autobind') value = true;
+ config[name] = value;
+ }
+ });
}
}
- return "";
+ return config;
}