removed google charts and few other filters, switched to simple optimization for compiler

This commit is contained in:
Misko Hevery 2010-08-11 11:17:55 -07:00
parent 49ffab3318
commit 412f05977c
5 changed files with 103 additions and 382 deletions

View file

@ -1,4 +1,4 @@
include FileUtils
include FileUtils
task :default => [:compile, :test]
@ -91,7 +91,7 @@ task :compile do
f.close
%x(java -jar lib/compiler-closure/compiler.jar \
--compilation_level ADVANCED_OPTIMIZATIONS \
--compilation_level SIMPLE_OPTIMIZATIONS \
--js angular-debug.js \
--externs externs.js \
--create_source_map ./angular-minified.map \

30
perf/startup.html Normal file
View file

@ -0,0 +1,30 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script type="text/javascript">
function time(timerName){
var started = new Date().getTime();
return {
name: timerName,
started: started,
lastLap: {duration:0, name:'BEGIN'},
lap: function(lapName){
var duration = (this.lapped = new Date().getTime()) - this.started;
var lastName = this.lastLap.name;
this.lastLap = {duration:duration-this.lastLap.duration, name:lapName};
console.log(timerName, lapName, 'TOTAL: ' + duration + ' ms.', 'since ' + lastName + ': ' + this.lastLap.duration + ' ms.');
return duration;
}
};
}
window.browser = time('BROWSER');
</script>
<script type="text/javascript" src="../angular-minified.js" ng:autobind ng:css="css/angular.css"></script>
<script type="text/javascript">
window.browser.lap('parse');
</script>
</head>
<body ng:init="$window.$scope = this; $window.browser.lap('ready')" style="display:none;" ng:show="true">
READY
</body>
</html>

View file

@ -307,14 +307,6 @@ function bind(_this, _function) {
}
}
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);

View file

@ -1,302 +1,74 @@
var angularFilterGoogleChartApi;
angularFilter.currency = function(amount){
this.$element.toggleClass('ng:format-negative', amount < 0);
return '$' + angularFilter['number'].apply(this, [amount, 2]);
};
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;
}
return null;
},
'lowercase': lowercase,
'uppercase': uppercase,
'linecount': function (obj) {
if (isString(obj)) {
if (obj==='') return 1;
return obj.split(/\n|\f/).length;
}
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('|');
},
'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;
},
'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;
}
}
),
'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);
}
},
'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.number = function(amount, fractionSize){
if (isNaN(amount) || !isFinite(amount)) {
return '';
}
}, function(v,k){angularFilter[k] = v;});
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;
};
angularFilterGoogleChartApi = angularFilter['googleChartApi'];
angularFilter.date = function(date) {
if (date instanceof Date)
return date.toLocaleDateString();
else
return date;
};
angularFilter.json = function(object) {
this.$element.addClass("ng-monospace");
return toJson(object, true);
};
angularFilter.lowercase = lowercase;
angularFilter.uppercase = uppercase;
angularFilter.html = function(html){
return new HTML(html);
};
angularFilter.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(''));
};

View file

@ -41,54 +41,6 @@ FiltersTest.prototype.testJson = function () {
assertEquals(toJson({a:"b"}, true), angular.filter.json.call({$element:jqLite('<div></div>')}, {a:"b"}));
};
FiltersTest.prototype.testPackageTracking = function () {
var assert = function(title, trackingNo) {
var val = angular.filter.trackPackage(trackingNo, title);
assertNotNull("Did Not Match: " + trackingNo, val);
assertEquals(title + ": " + trim(trackingNo), val.text());
assertNotNull(val.attr('href'));
};
assert('UPS', ' 1Z 999 999 99 9999 999 9 ');
assert('UPS', '1ZW5w5220379084747');
assert('FedEx', '418822131061812');
assert('FedEx', '9612019 5935 3267 2473 738');
assert('FedEx', '9612019593532672473738');
assert('FedEx', '235354667129449');
assert('FedEx', '915368880571');
assert('FedEx', '901712142390');
assert('FedEx', '297391510063413');
assert('USPS', '9101 8052 1390 7402 4335 49');
assert('USPS', '9101010521297963339560');
assert('USPS', '9102901001301038667029');
assert('USPS', '910 27974 4490 3000 8916 56');
assert('USPS', '9102801438635051633253');
};
FiltersTest.prototype.testLink = function() {
var assert = function(text, url, obj){
var val = angular.filter.link(obj);
assertEquals('<a href="' + url + '">' + text + '</a>', sortedHtml(val));
};
assert("url", "url", "url");
assert("hello", "url", {text:"hello", url:"url"});
assert("a@b.com", "mailto:a@b.com", "a@b.com");
};
FiltersTest.prototype.testImage = function(){
assertEquals(null, angular.filter.image());
assertEquals(null, angular.filter.image({}));
assertEquals(null, angular.filter.image(""));
assertEquals('http://localhost/abc', angular.filter.image({url:"http://localhost/abc"}).attr('src'));
};
FiltersTest.prototype.testQRcode = function() {
assertEquals(
'http://chart.apis.google.com/chart?chl=Hello%20world&chs=200x200&cht=qr',
angular.filter.qrcode('Hello world').attr('src'));
};
FiltersTest.prototype.testLowercase = function() {
assertEquals('abc', angular.filter.lowercase('AbC'));
assertEquals(null, angular.filter.lowercase(null));
@ -99,30 +51,6 @@ FiltersTest.prototype.testUppercase = function() {
assertEquals(null, angular.filter.uppercase(null));
};
FiltersTest.prototype.testLineCount = function() {
assertEquals(1, angular.filter.linecount(null));
assertEquals(1, angular.filter.linecount(''));
assertEquals(1, angular.filter.linecount('a'));
assertEquals(2, angular.filter.linecount('a\nb'));
assertEquals(3, angular.filter.linecount('a\nb\nc'));
};
FiltersTest.prototype.testIf = function() {
assertEquals('A', angular.filter['if']('A', true));
assertEquals(undefined, angular.filter['if']('A', false));
};
FiltersTest.prototype.testUnless = function() {
assertEquals('A', angular.filter.unless('A', false));
assertEquals(undefined, angular.filter.unless('A', true));
};
FiltersTest.prototype.testGoogleChartApiEncode = function() {
assertEquals(
'http://chart.apis.google.com/chart?chl=Hello world&chs=200x200&cht=qr',
angular.filter.googleChartApi.encode({cht:"qr", chl:"Hello world"}).attr('src'));
};
FiltersTest.prototype.testHtml = function() {
var html = angular.filter.html("a<b>c</b>d");
expect(html instanceof HTML).toBeTruthy();
@ -140,4 +68,3 @@ FiltersTest.prototype.testLinky = function() {
assertEquals(undefined, linky(undefined));
};