mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-03 20:54:43 +00:00
clean up, fixes for app
This commit is contained in:
parent
e646068586
commit
0df93fd49c
15 changed files with 3551 additions and 36 deletions
|
|
@ -1,13 +1,9 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<classpath>
|
<classpath>
|
||||||
<classpathentry excluding="lib/swfobject/|test/test/|src/test/|src/|lib/jquery/|lib/webtoolkit/|lib/underscore/|test/" kind="src" path=""/>
|
|
||||||
<classpathentry kind="src" path="lib/jquery"/>
|
|
||||||
<classpathentry kind="src" path="lib/swfobject"/>
|
|
||||||
<classpathentry kind="src" path="lib/underscore"/>
|
|
||||||
<classpathentry kind="src" path="lib/webtoolkit"/>
|
|
||||||
<classpathentry excluding="test/" kind="src" path="src"/>
|
<classpathentry excluding="test/" kind="src" path="src"/>
|
||||||
<classpathentry kind="src" path="src/test"/>
|
<classpathentry kind="src" path="src/test"/>
|
||||||
<classpathentry excluding="test/" kind="src" path="test"/>
|
<classpathentry excluding="test/" kind="src" path="test"/>
|
||||||
<classpathentry kind="src" path="test/test"/>
|
<classpathentry kind="src" path="test/test"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
|
|
|
||||||
10
Rakefile
10
Rakefile
|
|
@ -39,10 +39,10 @@ task :compile do
|
||||||
src/JSON.js \
|
src/JSON.js \
|
||||||
src/Compiler.js \
|
src/Compiler.js \
|
||||||
src/Scope.js \
|
src/Scope.js \
|
||||||
src/jqlite.js \
|
|
||||||
src/Parser.js \
|
src/Parser.js \
|
||||||
src/Resource.js \
|
src/Resource.js \
|
||||||
src/URLWatcher.js \
|
src/Browser.js \
|
||||||
|
src/jqLite.js \
|
||||||
src/apis.js \
|
src/apis.js \
|
||||||
src/filters.js \
|
src/filters.js \
|
||||||
src/formatters.js \
|
src/formatters.js \
|
||||||
|
|
@ -50,15 +50,17 @@ task :compile do
|
||||||
src/directives.js \
|
src/directives.js \
|
||||||
src/markups.js \
|
src/markups.js \
|
||||||
src/widgets.js \
|
src/widgets.js \
|
||||||
|
src/services.js \
|
||||||
|
src/AngularPublic.js \
|
||||||
src/angular.suffix \
|
src/angular.suffix \
|
||||||
)
|
)
|
||||||
f = File.new("angular.js", 'w')
|
f = File.new("angular-debug.js", 'w')
|
||||||
f.write(concat)
|
f.write(concat)
|
||||||
f.close
|
f.close
|
||||||
|
|
||||||
%x(java -jar lib/compiler-closure/compiler.jar \
|
%x(java -jar lib/compiler-closure/compiler.jar \
|
||||||
--compilation_level ADVANCED_OPTIMIZATIONS \
|
--compilation_level ADVANCED_OPTIMIZATIONS \
|
||||||
--js angular.js \
|
--js angular-debug.js \
|
||||||
--externs externs.js \
|
--externs externs.js \
|
||||||
--create_source_map ./angular-minified.map \
|
--create_source_map ./angular-minified.map \
|
||||||
--js_output_file angular-minified.js)
|
--js_output_file angular-minified.js)
|
||||||
|
|
|
||||||
3442
angular-debug.js
vendored
Normal file
3442
angular-debug.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -102,7 +102,7 @@ function isTextNode(node) { return nodeName(node) == '#text'; }
|
||||||
function lowercase(value){ return isString(value) ? value.toLowerCase() : value; }
|
function lowercase(value){ return isString(value) ? value.toLowerCase() : value; }
|
||||||
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
|
function uppercase(value){ return isString(value) ? value.toUpperCase() : value; }
|
||||||
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
|
function trim(value) { return isString(value) ? value.replace(/^\s*/, '').replace(/\s*$/, '') : value; }
|
||||||
function nodeName(element) { return (element[0] || element || {}).nodeName; }
|
function nodeName(element) { return (element[0] || element).nodeName; }
|
||||||
function map(obj, iterator, context) {
|
function map(obj, iterator, context) {
|
||||||
var results = [];
|
var results = [];
|
||||||
foreach(obj, function(value, index, list) {
|
foreach(obj, function(value, index, list) {
|
||||||
|
|
@ -274,6 +274,8 @@ function escapeAttr(html) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function bind(_this, _function) {
|
function bind(_this, _function) {
|
||||||
|
if (!isFunction(_function))
|
||||||
|
throw "Not a function!";
|
||||||
var curryArgs = slice.call(arguments, 2, arguments.length);
|
var curryArgs = slice.call(arguments, 2, arguments.length);
|
||||||
return function() {
|
return function() {
|
||||||
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
return _function.apply(_this, curryArgs.concat(slice.call(arguments, 0, arguments.length)));
|
||||||
|
|
@ -347,3 +349,16 @@ function angularInit(config){
|
||||||
scope.$init();
|
scope.$init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function angularJsConfig(document) {
|
||||||
|
var filename = /(.*)\/angular(-(.*))?.js(#(.*))?/,
|
||||||
|
scripts = document.getElementsByTagName("SCRIPT"),
|
||||||
|
match;
|
||||||
|
for(var j = 0; j < scripts.length; j++) {
|
||||||
|
match = (scripts[j].src || "").match(filename);
|
||||||
|
if (match) {
|
||||||
|
return match[5];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
= * Template provides directions an how to bind to a given element.
|
* Template provides directions an how to bind to a given element.
|
||||||
* It contains a list of init functions which need to be called to
|
* It contains a list of init functions which need to be called to
|
||||||
* bind to a new instance of elements. It also provides a list
|
* bind to a new instance of elements. It also provides a list
|
||||||
* of child paths which contain child templates
|
* of child paths which contain child templates
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ function getter(instance, path, unboundFn) {
|
||||||
type = angular[type.charAt(0).toUpperCase()+type.substring(1)];
|
type = angular[type.charAt(0).toUpperCase()+type.substring(1)];
|
||||||
var fn = type ? type[[key.substring(1)]] : undefined;
|
var fn = type ? type[[key.substring(1)]] : undefined;
|
||||||
if (fn) {
|
if (fn) {
|
||||||
instance = bind(fn, lastInstance, lastInstance);
|
instance = bind(lastInstance, fn, lastInstance);
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,4 +21,4 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
(function(window, document, onLoadDelegate){
|
(function(window, document, previousOnLoad){
|
||||||
|
|
|
||||||
|
|
@ -1 +1,9 @@
|
||||||
|
|
||||||
|
window.onload = function(){
|
||||||
|
try {
|
||||||
|
if (previousOnLoad) previousOnLoad();
|
||||||
|
} catch(e) {}
|
||||||
|
angularInit(parseKeyValue(angularJsConfig(document)));
|
||||||
|
};
|
||||||
|
|
||||||
})(window, document, window.onload);
|
})(window, document, window.onload);
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ angularDirective("ng-controller", function(expression){
|
||||||
if (!isFunction(controller))
|
if (!isFunction(controller))
|
||||||
throw "Reference '"+expression+"' is not a class.";
|
throw "Reference '"+expression+"' is not a class.";
|
||||||
this.$become(controller);
|
this.$become(controller);
|
||||||
|
(this.init || noop)();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -159,28 +159,42 @@ angularWidget('SELECT', function(element){
|
||||||
angularWidget('NG:INCLUDE', function(element){
|
angularWidget('NG:INCLUDE', function(element){
|
||||||
var compiler = this,
|
var compiler = this,
|
||||||
src = element.attr("src");
|
src = element.attr("src");
|
||||||
return element.attr('switch-instance') ? null : function(element){
|
if (element.attr('switch-instance')) {
|
||||||
var scope = this, childScope;
|
this.descend(true);
|
||||||
element.attr('switch-instance', 'compiled');
|
this.directives(true);
|
||||||
scope.$browser.xhr('GET', src, function(code, response){
|
} else {
|
||||||
element.html(response);
|
return function(element){
|
||||||
childScope = createScope(scope);
|
var scope = this, childScope;
|
||||||
compiler.compile(element)(element, childScope);
|
element.attr('switch-instance', 'compiled');
|
||||||
childScope.$init();
|
scope.$browser.xhr('GET', src, function(code, response){
|
||||||
});
|
element.html(response);
|
||||||
scope.$onEval(function(){ if (childScope) childScope.$eval(); });
|
childScope = createScope(scope);
|
||||||
};
|
compiler.compile(element)(element, childScope);
|
||||||
|
childScope.$init();
|
||||||
|
scope.$root.$eval();
|
||||||
|
});
|
||||||
|
scope.$onEval(function(){
|
||||||
|
if (childScope) childScope.$eval();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
angularWidget('NG:SWITCH', function(element){
|
angularWidget('NG:SWITCH', function ngSwitch(element){
|
||||||
var compiler = this,
|
var compiler = this,
|
||||||
watchExpr = element.attr("on"),
|
watchExpr = element.attr("on"),
|
||||||
|
whenFn = ngSwitch[element.attr("using") || 'equals'];
|
||||||
|
changeExpr = element.attr('change') || '',
|
||||||
cases = [];
|
cases = [];
|
||||||
|
if (!whenFn) throw "Using expression '" + usingExpr + "' unknown.";
|
||||||
eachNode(element, function(caseElement){
|
eachNode(element, function(caseElement){
|
||||||
var when = caseElement.attr('ng-switch-when');
|
var when = caseElement.attr('ng-switch-when');
|
||||||
if (when) {
|
if (when) {
|
||||||
cases.push({
|
cases.push({
|
||||||
when: function(value){ return value == when; },
|
when: function(scope, value){
|
||||||
|
return whenFn.call(scope, value, when);
|
||||||
|
},
|
||||||
|
change: changeExpr,
|
||||||
element: caseElement,
|
element: caseElement,
|
||||||
template: compiler.compile(caseElement)
|
template: compiler.compile(caseElement)
|
||||||
});
|
});
|
||||||
|
|
@ -188,17 +202,28 @@ angularWidget('NG:SWITCH', function(element){
|
||||||
});
|
});
|
||||||
element.html('');
|
element.html('');
|
||||||
return function(element){
|
return function(element){
|
||||||
var scope = this;
|
var scope = this, childScope;
|
||||||
this.$watch(watchExpr, function(value){
|
this.$watch(watchExpr, function(value){
|
||||||
element.html('');
|
element.html('');
|
||||||
|
childScope = null;
|
||||||
foreach(cases, function(switchCase){
|
foreach(cases, function(switchCase){
|
||||||
if (switchCase.when(value)) {
|
if (switchCase.when(childScope, value)) {
|
||||||
element.append(switchCase.element);
|
element.append(switchCase.element);
|
||||||
var childScope = createScope(scope);
|
childScope = createScope(scope);
|
||||||
|
childScope.$tryEval(switchCase.change, element);
|
||||||
switchCase.template(switchCase.element, childScope);
|
switchCase.template(switchCase.element, childScope);
|
||||||
childScope.$init();
|
childScope.$init();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
scope.$onEval(function(){
|
||||||
|
if (childScope) childScope.$eval();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
}, {
|
||||||
|
equals: function(on, when) {
|
||||||
|
return on == when;
|
||||||
|
},
|
||||||
|
route: function(on, when) {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -162,13 +162,16 @@ describe("directives", function(){
|
||||||
this.greeting = 'hello';
|
this.greeting = 'hello';
|
||||||
};
|
};
|
||||||
window.Greeter.prototype = {
|
window.Greeter.prototype = {
|
||||||
|
init: function(){
|
||||||
|
this.suffix = '!';
|
||||||
|
},
|
||||||
greet: function(name) {
|
greet: function(name) {
|
||||||
return this.greeting + ' ' + name;
|
return this.greeting + ' ' + name + this.suffix;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
var scope = compile('<div ng-controller="Greeter"></div>');
|
var scope = compile('<div ng-controller="Greeter"></div>');
|
||||||
expect(scope.greeting).toEqual('hello');
|
expect(scope.greeting).toEqual('hello');
|
||||||
expect(scope.greet('misko')).toEqual('hello misko');
|
expect(scope.greet('misko')).toEqual('hello misko!');
|
||||||
delete window.Greeter;
|
delete window.Greeter;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -189,14 +189,36 @@ describe("input widget", function(){
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should switch on value change', function(){
|
it('should switch on value change', function(){
|
||||||
compile('<ng:switch on="select"><div ng-switch-when="1">first</div><div ng-switch-when="2">second</div></ng:switch>');
|
compile('<ng:switch on="select"><div ng-switch-when="1">first:{{name}}</div><div ng-switch-when="2">second:{{name}}</div></ng:switch>');
|
||||||
expect(element.html()).toEqual('');
|
expect(element.html()).toEqual('');
|
||||||
scope.select = 1;
|
scope.select = 1;
|
||||||
scope.$eval();
|
scope.$eval();
|
||||||
expect(element.text()).toEqual('first');
|
expect(element.text()).toEqual('first:');
|
||||||
|
scope.name="shyam";
|
||||||
|
scope.$eval();
|
||||||
|
expect(element.text()).toEqual('first:shyam');
|
||||||
scope.select = 2;
|
scope.select = 2;
|
||||||
scope.$eval();
|
scope.$eval();
|
||||||
expect(element.text()).toEqual('second');
|
scope.name = 'misko';
|
||||||
|
scope.$eval();
|
||||||
|
expect(element.text()).toEqual('second:misko');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('ng:switch', function(){
|
||||||
|
it("should match urls", function(){
|
||||||
|
var scope = compile('<ng:switch on="url" using="route"><div ng-switch-when="/Book/:name">{{name}}</div></ng:include>');
|
||||||
|
scope.url = '/Book/Moby';
|
||||||
|
scope.$init();
|
||||||
|
expect(scope.$element.text()).toEqual('Moby');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call init on switch', function(){
|
||||||
|
var scope = compile('<ng:switch on="url" change="name=\'works\'"><div ng-switch-when="a">{{name}}</div></ng:include>');
|
||||||
|
scope.url = 'a';
|
||||||
|
scope.$init();
|
||||||
|
expect(scope.name).toEqual(undefined);
|
||||||
|
expect(scope.$element.text()).toEqual('works');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -204,10 +226,11 @@ describe('ng:include', function(){
|
||||||
it('should include on external file', function() {
|
it('should include on external file', function() {
|
||||||
var element = jqLite('<ng:include src="myUrl"></ng:include>');
|
var element = jqLite('<ng:include src="myUrl"></ng:include>');
|
||||||
var scope = compile(element);
|
var scope = compile(element);
|
||||||
scope.$browser.xhr.expect('GET', 'myUrl').respond('hello');
|
scope.$browser.xhr.expect('GET', 'myUrl').respond('{{1+2}}');
|
||||||
scope.$init();
|
scope.$init();
|
||||||
expect(sortedHtml(element)).toEqual('<ng:include src="myUrl" switch-instance="compiled"></ng:include>');
|
expect(sortedHtml(element)).toEqual('<ng:include src="myUrl" switch-instance="compiled"></ng:include>');
|
||||||
scope.$browser.xhr.flush();
|
scope.$browser.xhr.flush();
|
||||||
expect(sortedHtml(element)).toEqual('<ng:include src="myUrl" switch-instance="compiled">hello</ng:include>');
|
expect(element.text()).toEqual('3');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue