aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Angular.js35
-rw-r--r--src/JSON.js6
-rw-r--r--src/Scope.js23
-rw-r--r--src/apis.js71
-rw-r--r--src/filters.js358
-rw-r--r--src/formatters.js49
-rw-r--r--src/jqLite.js27
-rw-r--r--src/services.js9
8 files changed, 128 insertions, 450 deletions
diff --git a/src/Angular.js b/src/Angular.js
index 42e2ce89..3970f762 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -291,30 +291,20 @@ function escapeAttr(html) {
'"');
}
-function bind(_this, _function) {
- var curryArgs = slice.call(arguments, 2, arguments.length);
- if (typeof _function == 'function') {
- return curryArgs.length == 0 ?
- function() {
- return _function.apply(_this, arguments);
- } :
- function() {
- return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
- };
+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 _function;
+ return fn;
}
}
-function outerHTML(node) {
- var temp = document.createElement('div');
- temp.appendChild(node);
- var outerHTML = temp.innerHTML;
- temp.removeChild(node);
- return outerHTML;
-}
-
function toBoolean(value) {
if (value && value.length !== 0) {
var v = lowercase("" + value);
@@ -338,12 +328,11 @@ function merge(src, dst) {
}
}
-function compile(element, parentScope) {
+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);
+ return compiler.compile($element)($element, existingScope);
}
/////////////////////////////////////////////////
diff --git a/src/JSON.js b/src/JSON.js
index 340b075a..1e468e89 100644
--- a/src/JSON.js
+++ b/src/JSON.js
@@ -1,4 +1,4 @@
-array = [].constructor;
+var array = [].constructor;
function toJson(obj, pretty){
var buf = [];
@@ -6,10 +6,6 @@ function toJson(obj, pretty){
return buf.join('');
}
-function toPrettyJson(obj) {
- return toJson(obj, true);
-}
-
function fromJson(json) {
if (!json) return json;
try {
diff --git a/src/Scope.js b/src/Scope.js
index 4d2aa5c3..27fafc3a 100644
--- a/src/Scope.js
+++ b/src/Scope.js
@@ -44,9 +44,10 @@ function setter(instance, path, value){
}
///////////////////////////////////
-
-var getterFnCache = {};
-var JS_KEYWORDS = {};
+var scopeId = 0;
+ getterFnCache = {},
+ compileCache = {},
+ JS_KEYWORDS = {};
foreach(
["abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "const", "continue", "debugger", "default",
"delete", "do", "double", "else", "enum", "export", "extends", "false", "final", "finally", "float", "for", "function", "goto",
@@ -75,7 +76,7 @@ function getterFn(path){
code += ' type = angular.Global.typeOf(last);\n';
code += ' fn = (angular[type.charAt(0).toUpperCase() + type.substring(1)]||{})["' + name + '"];\n';
code += ' if (fn)\n';
- code += ' self = function(){ return fn.apply(last, [last].concat(slice.call(arguments, 0, arguments.length))); };\n';
+ code += ' self = function(){ return fn.apply(last, [last].concat(Array.prototype.slice.call(arguments, 0, arguments.length))); };\n';
code += ' }\n';
}
});
@@ -88,7 +89,6 @@ function getterFn(path){
///////////////////////////////////
-var compileCache = {};
function expressionCompile(exp){
if (typeof exp === 'function') return exp;
var fn = compileCache[exp];
@@ -108,7 +108,6 @@ function errorHandlerFor(element, error) {
elementError(element, NG_EXCEPTION, isDefined(error) ? toJson(error) : error);
}
-var scopeId = 0;
function createScope(parent, services, existing) {
function Parent(){}
function API(){}
@@ -130,7 +129,8 @@ function createScope(parent, services, existing) {
$set: bind(instance, setter, instance),
$eval: function $eval(exp) {
- if (exp === undefined) {
+ var type = typeof exp;
+ if (type == 'undefined') {
for ( var i = 0, iSize = evalLists.sorted.length; i < iSize; i++) {
for ( var queue = evalLists.sorted[i],
jSize = queue.length,
@@ -138,18 +138,19 @@ function createScope(parent, services, existing) {
instance.$tryEval(queue[j].fn, queue[j].handler);
}
}
- } else if (typeof exp === 'function'){
+ } else if (type === 'function') {
return exp.call(instance);
- } else {
+ } else if (type === 'string') {
return expressionCompile(exp).call(instance);
}
},
$tryEval: function (expression, exceptionHandler) {
+ var type = typeof expression;
try {
- if (typeof expression == 'function') {
+ if (type == 'function') {
return expression.call(instance);
- } else {
+ } else if (type == 'string'){
return expressionCompile(expression).call(instance);
}
} catch (e) {
diff --git a/src/apis.js b/src/apis.js
index 136473b6..0cf24016 100644
--- a/src/apis.js
+++ b/src/apis.js
@@ -21,17 +21,6 @@ var angularObject = {
};
var angularArray = {
'indexOf': indexOf,
- 'include': includes,
- 'includeIf':function(array, value, condition) {
- var index = indexOf(array, value);
- if (condition) {
- if (index == -1)
- array.push(value);
- } else {
- array.splice(index, 1);
- }
- return array;
- },
'sum':function(array, expression) {
var fn = angular['Function']['compile'](expression);
var sum = 0;
@@ -49,20 +38,6 @@ var angularArray = {
array.splice(index, 1);
return value;
},
- 'find':function(array, condition, defaultValue) {
- if (!condition) return undefined;
- var fn = angular['Function']['compile'](condition);
- foreach(array, function($){
- if (fn($)){
- defaultValue = $;
- return true;
- }
- });
- return defaultValue;
- },
- 'findById':function(array, id) {
- return angular.Array.find(array, function($){return $.$id == id;}, null);
- },
'filter':function(array, expression) {
var predicates = [];
predicates.check = function(value) {
@@ -195,52 +170,6 @@ var angularArray = {
var arrayCopy = [];
for ( var i = 0; i < array.length; i++) { arrayCopy.push(array[i]); }
return arrayCopy.sort(reverse(comparator, descend));
- },
- 'orderByToggle':function(predicate, attribute) {
- var STRIP = /^([+|-])?(.*)/;
- var ascending = false;
- var index = -1;
- foreach(predicate, function($, i){
- if (index == -1) {
- if ($ == attribute) {
- ascending = true;
- index = i;
- return true;
- }
- if (($.charAt(0)=='+'||$.charAt(0)=='-') && $.substring(1) == attribute) {
- ascending = $.charAt(0) == '+';
- index = i;
- return true;
- }
- }
- });
- if (index >= 0) {
- predicate.splice(index, 1);
- }
- predicate.unshift((ascending ? "-" : "+") + attribute);
- return predicate;
- },
- 'orderByDirection':function(predicate, attribute, ascend, descend) {
- ascend = ascend || 'ng-ascend';
- descend = descend || 'ng-descend';
- var att = predicate[0] || '';
- var direction = true;
- if (att.charAt(0) == '-') {
- att = att.substring(1);
- direction = false;
- } else if(att.charAt(0) == '+') {
- att = att.substring(1);
- }
- return att == attribute ? (direction ? ascend : descend) : "";
- },
- 'merge':function(array, index, mergeValue) {
- var value = array[index];
- if (!value) {
- value = {};
- array[index] = value;
- }
- merge(mergeValue, value);
- return array;
}
};
diff --git a/src/filters.js b/src/filters.js
index 99d17405..27e3deca 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -1,302 +1,74 @@
-var angularFilterGoogleChartApi;
-
-foreach({
- 'currency': function(amount){
- this.$element.toggleClass('ng:format-negative', amount < 0);
- return '$' + angularFilter['number'].apply(this, [amount, 2]);
- },
-
- 'number': function(amount, fractionSize){
- if (isNaN(amount) || !isFinite(amount)) {
- return '';
- }
- fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize;
- var isNegative = amount < 0;
- amount = Math.abs(amount);
- var pow = Math.pow(10, fractionSize);
- var text = "" + Math.round(amount * pow);
- var whole = text.substring(0, text.length - fractionSize);
- whole = whole || '0';
- var frc = text.substring(text.length - fractionSize);
- text = isNegative ? '-' : '';
- for (var i = 0; i < whole.length; i++) {
- if ((whole.length - i)%3 === 0 && i !== 0) {
- text += ',';
- }
- text += whole.charAt(i);
- }
- if (fractionSize > 0) {
- for (var j = frc.length; j < fractionSize; j++) {
- frc += '0';
- }
- text += '.' + frc.substring(0, fractionSize);
- }
- return text;
- },
-
- 'date': function(date) {
- if (date instanceof Date)
- return date.toLocaleDateString();
- else
- return date;
- },
-
- 'json': function(object) {
- this.$element.addClass("ng-monospace");
- return toJson(object, true);
- },
-
- 'trackPackage': (function(){
- var MATCHERS = [
- { name: "UPS",
- url: "http://wwwapps.ups.com/WebTracking/processInputRequest?sort_by=status&tracknums_displayed=1&TypeOfInquiryNumber=T&loc=en_US&track.x=0&track.y=0&InquiryNumber1=",
- regexp: [
- /^1Z[0-9A-Z]{16}$/i]},
- { name: "FedEx",
- url: "http://www.fedex.com/Tracking?tracknumbers=",
- regexp: [
- /^96\d{10}?$/i,
- /^96\d{17}?$/i,
- /^96\d{20}?$/i,
- /^\d{15}$/i,
- /^\d{12}$/i]},
- { name: "USPS",
- url: "http://trkcnfrm1.smi.usps.com/PTSInternetWeb/InterLabelInquiry.do?origTrackNum=",
- regexp: [
- /^(91\d{20})$/i,
- /^(91\d{18})$/i]}];
- return function(trackingNo, noMatch) {
- trackingNo = trim(trackingNo);
- var tNo = trackingNo.replace(/ /g, '');
- var returnValue;
- foreach(MATCHERS, function(carrier){
- foreach(carrier.regexp, function(regexp){
- if (!returnValue && regexp.test(tNo)) {
- var text = carrier.name + ": " + trackingNo;
- var url = carrier.url + trackingNo;
- returnValue = jqLite('<a></a>');
- returnValue.text(text);
- returnValue.attr('href', url);
- }
- });
- });
- if (returnValue)
- return returnValue;
- else if (trackingNo)
- return noMatch || trackingNo + " is not recognized";
- else
- return null;
- };})(),
-
- 'link': function(obj, title) {
- if (obj) {
- var text = title || obj.text || obj;
- var url = obj.url || obj;
- if (url) {
- if (angular.validator.email(url) === null) {
- url = "mailto:" + url;
- }
- var a = jqLite('<a></a>');
- a.attr('href', url);
- a.text(text);
- return a;
- }
- }
- return obj;
- },
-
-
- 'bytes': (function(){
- var SUFFIX = ['bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
- return function(size) {
- if(size === null) return "";
-
- var suffix = 0;
- while (size > 1000) {
- size = size / 1024;
- suffix++;
- }
- var txt = "" + size;
- var dot = txt.indexOf('.');
- if (dot > -1 && dot + 2 < txt.length) {
- txt = txt.substring(0, dot + 2);
- }
- return txt + " " + SUFFIX[suffix];
- };
- })(),
-
- 'image': function(obj, width, height) {
- if (obj && obj.url) {
- var style = "", img = jqLite('<img>');
- if (width) {
- img.css('max-width', width + 'px');
- img.css('max-height', (height || width) + 'px');
- }
- img.attr('src', obj.url);
- return img;
+angularFilter.currency = function(amount){
+ this.$element.toggleClass('ng:format-negative', amount < 0);
+ return '$' + angularFilter['number'].apply(this, [amount, 2]);
+};
+
+angularFilter.number = function(amount, fractionSize){
+ if (isNaN(amount) || !isFinite(amount)) {
+ return '';
+ }
+ fractionSize = typeof fractionSize == 'undefined' ? 2 : fractionSize;
+ var isNegative = amount < 0;
+ amount = Math.abs(amount);
+ var pow = Math.pow(10, fractionSize);
+ var text = "" + Math.round(amount * pow);
+ var whole = text.substring(0, text.length - fractionSize);
+ whole = whole || '0';
+ var frc = text.substring(text.length - fractionSize);
+ text = isNegative ? '-' : '';
+ for (var i = 0; i < whole.length; i++) {
+ if ((whole.length - i)%3 === 0 && i !== 0) {
+ text += ',';
}
- return null;
- },
-
- 'lowercase': lowercase,
-
- 'uppercase': uppercase,
-
- 'linecount': function (obj) {
- if (isString(obj)) {
- if (obj==='') return 1;
- return obj.split(/\n|\f/).length;
+ text += whole.charAt(i);
+ }
+ if (fractionSize > 0) {
+ for (var j = frc.length; j < fractionSize; j++) {
+ frc += '0';
}
- return 1;
- },
-
- 'if': function (result, expression) {
- return expression ? result : undefined;
- },
-
- 'unless': function (result, expression) {
- return expression ? undefined : result;
- },
-
- 'googleChartApi': extend(
- function(type, data, width, height) {
- data = data || {};
- var chart = {
- 'cht':type,
- 'chco':angularFilterGoogleChartApi['collect'](data, 'color'),
- 'chtt':angularFilterGoogleChartApi['title'](data),
- 'chdl':angularFilterGoogleChartApi['collect'](data, 'label'),
- 'chd':angularFilterGoogleChartApi['values'](data),
- 'chf':'bg,s,FFFFFF00'
- };
- if (_.isArray(data['xLabels'])) {
- chart['chxt']='x';
- chart['chxl']='0:|' + data.xLabels.join('|');
- }
- return angularFilterGoogleChartApi['encode'](chart, width, height);
- },
- {
- 'values': function(data){
- var seriesValues = [];
- foreach(data['series']||[], function(serie){
- var values = [];
- foreach(serie['values']||[], function(value){
- values.push(value);
- });
- seriesValues.push(values.join(','));
- });
- var values = seriesValues.join('|');
- return values === "" ? null : "t:" + values;
- },
-
- 'title': function(data){
- var titles = [];
- var title = data['title'] || [];
- foreach(_.isArray(title)?title:[title], function(text){
- titles.push(encodeURIComponent(text));
- });
- return titles.join('|');
- },
+ text += '.' + frc.substring(0, fractionSize);
+ }
+ return text;
+};
- 'collect': function(data, key){
- var outterValues = [];
- var count = 0;
- foreach(data['series']||[], function(serie){
- var innerValues = [];
- var value = serie[key] || [];
- foreach(_.isArray(value)?value:[value], function(color){
- innerValues.push(encodeURIComponent(color));
- count++;
- });
- outterValues.push(innerValues.join('|'));
- });
- return count?outterValues.join(','):null;
- },
+angularFilter.date = function(date) {
+ if (date instanceof Date)
+ return date.toLocaleDateString();
+ else
+ return date;
+};
- 'encode': function(params, width, height) {
- width = width || 200;
- height = height || width;
- var url = "http://chart.apis.google.com/chart?",
- urlParam = [],
- img = jqLite('<img>');
- params['chs'] = width + "x" + height;
- foreach(params, function(value, key){
- if (value) {
- urlParam.push(key + "=" + value);
- }
- });
- urlParam.sort();
- url += urlParam.join("&");
- img.attr('src', url);
- img.css({width: width + 'px', height: height + 'px'});
- return img;
- }
- }
- ),
+angularFilter.json = function(object) {
+ this.$element.addClass("ng-monospace");
+ return toJson(object, true);
+};
+angularFilter.lowercase = lowercase;
- 'qrcode': function(value, width, height) {
- return angularFilterGoogleChartApi['encode']({
- 'cht':'qr', 'chl':encodeURIComponent(value)}, width, height);
- },
- 'chart': {
- 'pie':function(data, width, height) {
- return angularFilterGoogleChartApi('p', data, width, height);
- },
- 'pie3d':function(data, width, height) {
- return angularFilterGoogleChartApi('p3', data, width, height);
- },
- 'pieConcentric':function(data, width, height) {
- return angularFilterGoogleChartApi('pc', data, width, height);
- },
- 'barHorizontalStacked':function(data, width, height) {
- return angularFilterGoogleChartApi('bhs', data, width, height);
- },
- 'barHorizontalGrouped':function(data, width, height) {
- return angularFilterGoogleChartApi('bhg', data, width, height);
- },
- 'barVerticalStacked':function(data, width, height) {
- return angularFilterGoogleChartApi('bvs', data, width, height);
- },
- 'barVerticalGrouped':function(data, width, height) {
- return angularFilterGoogleChartApi('bvg', data, width, height);
- },
- 'line':function(data, width, height) {
- return angularFilterGoogleChartApi('lc', data, width, height);
- },
- 'sparkline':function(data, width, height) {
- return angularFilterGoogleChartApi('ls', data, width, height);
- },
- 'scatter':function(data, width, height) {
- return angularFilterGoogleChartApi('s', data, width, height);
- }
- },
+angularFilter.uppercase = uppercase;
- 'html': function(html){
- return new HTML(html);
- },
+angularFilter.html = function(html){
+ return new HTML(html);
+};
- 'linky': function(text){
- if (!text) return text;
- function regExpEscape(text) {
- return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
- }
- var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
- var match;
- var raw = text;
- var html = [];
- while (match=raw.match(URL)) {
- var url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
- var i = raw.indexOf(url);
- html.push(escapeHtml(raw.substr(0, i)));
- html.push('<a href="' + url + '">');
- html.push(url);
- html.push('</a>');
- raw = raw.substring(i + url.length);
- }
- html.push(escapeHtml(raw));
- return new HTML(html.join(''));
+angularFilter.linky = function(text){
+ if (!text) return text;
+ function regExpEscape(text) {
+ return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1');
}
-}, function(v,k){angularFilter[k] = v;});
-
-angularFilterGoogleChartApi = angularFilter['googleChartApi'];
+ var URL = /(ftp|http|https|mailto):\/\/([^\(\)|\s]+)/;
+ var match;
+ var raw = text;
+ var html = [];
+ while (match=raw.match(URL)) {
+ var url = match[0].replace(/[\.\;\,\(\)\{\}\<\>]$/,'');
+ var i = raw.indexOf(url);
+ html.push(escapeHtml(raw.substr(0, i)));
+ html.push('<a href="' + url + '">');
+ html.push(url);
+ html.push('</a>');
+ raw = raw.substring(i + url.length);
+ }
+ html.push(escapeHtml(raw));
+ return new HTML(html.join(''));
+};
diff --git a/src/formatters.js b/src/formatters.js
index ca1ce83e..9122489f 100644
--- a/src/formatters.js
+++ b/src/formatters.js
@@ -3,31 +3,28 @@ function toString(obj) {return (isDefined(obj) && obj !== null) ? "" + obj : obj
var NUMBER = /^\s*[-+]?\d*(\.\d*)?\s*$/;
-extend(angularFormatter, {
- 'noop':formatter(identity, identity),
- 'json':formatter(toJson, fromJson),
- 'boolean':formatter(toString, toBoolean),
- 'number':formatter(toString,
- function(obj){
- if (isString(obj) && NUMBER.exec(obj)) {
- return obj ? 1*obj : null;
- }
- throw "Not a number";
- }),
+angularFormatter.noop = formatter(identity, identity);
+angularFormatter.json = formatter(toJson, fromJson);
+angularFormatter['boolean'] = formatter(toString, toBoolean);
+angularFormatter.number = formatter(toString, function(obj){
+ if (isString(obj) && NUMBER.exec(obj)) {
+ return obj ? 1*obj : null;
+ }
+ throw "Not a number";
+});
- 'list':formatter(
- function(obj) { return obj ? obj.join(", ") : obj; },
- function(value) {
- var list = [];
- foreach((value || '').split(','), function(item){
- item = trim(item);
- if (item) list.push(item);
- });
- return list;
- }
- ),
+angularFormatter.list = formatter(
+ function(obj) { return obj ? obj.join(", ") : obj; },
+ function(value) {
+ var list = [];
+ foreach((value || '').split(','), function(item){
+ item = trim(item);
+ if (item) list.push(item);
+ });
+ return list;
+ }
+);
- 'trim':formatter(
- function(obj) { return obj ? trim("" + obj) : ""; }
- )
-});
+angularFormatter.trim = formatter(
+ function(obj) { return obj ? trim("" + obj) : ""; }
+);
diff --git a/src/jqLite.js b/src/jqLite.js
index 22b3c070..1ad4d96d 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -2,24 +2,17 @@
//JQLite
//////////////////////////////////
-var jqCache = {};
-var jqName = 'ng-' + new Date().getTime();
-var jqId = 1;
-function jqNextId() { return (jqId++); }
-
-var addEventListener = window.document.attachEvent ?
- function(element, type, fn) {
- element.attachEvent('on' + type, fn);
- } : function(element, type, fn) {
- element.addEventListener(type, fn, false);
- };
+var jqCache = {},
+ jqName = 'ng-' + new Date().getTime(),
+ jqId = 1,
+ addEventListener = (window.document.attachEvent ?
+ function(element, type, fn) {element.attachEvent('on' + type, fn);} :
+ function(element, type, fn) {element.addEventListener(type, fn, false);}),
+ removeEventListener = (window.document.detachEvent ?
+ function(element, type, fn) {element.detachEvent('on' + type, fn); } :
+ function(element, type, fn) { element.removeEventListener(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 jqNextId() { return (jqId++); }
function jqClearData(element) {
var cacheId = element[jqName],
diff --git a/src/services.js b/src/services.js
index 8df23564..a5158149 100644
--- a/src/services.js
+++ b/src/services.js
@@ -1,11 +1,12 @@
+var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?([^\?#]+)(\?([^#]*))?(#(.*))?$/,
+ HASH_MATCH = /^([^\?]*)?(\?([^\?]*))?$/,
+ DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp':21};
+
angularService("$window", bind(window, identity, window));
angularService("$document", function(window){
return jqLite(window.document);
}, {inject:['$window']});
-var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.-]*)(:([0-9]+))?([^\?#]+)(\?([^#]*))?(#(.*))?$/;
-var HASH_MATCH = /^([^\?]*)?(\?([^\?]*))?$/;
-var DEFAULT_PORTS = {'http': 80, 'https': 443, 'ftp':21};
angularService("$location", function(browser){
var scope = this,
location = {parse:parseUrl, toString:toString, update:update},
@@ -213,7 +214,7 @@ function switchRouteMatcher(on, when, dstName) {
return match ? dst : null;
}
-angularService('$route', function(location, params){
+angularService('$route', function(location){
var routes = {},
onChange = [],
matcher = switchRouteMatcher,