aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scenario/widgets.html4
-rw-r--r--src/Angular.js19
-rw-r--r--src/angular-bootstrap.js39
-rw-r--r--src/delete/Model.js (renamed from src/moveToAngularCom/Model.js)0
-rw-r--r--src/markups.js1
-rw-r--r--src/services.js40
-rw-r--r--test/BinderTest.js4
-rw-r--r--test/servicesSpec.js15
8 files changed, 68 insertions, 54 deletions
diff --git a/scenario/widgets.html b/scenario/widgets.html
index 21060ebf..5c11a2ee 100644
--- a/scenario/widgets.html
+++ b/scenario/widgets.html
@@ -2,9 +2,9 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<link rel="stylesheet" type="text/css" href="style.css"></link>
- <script type="text/javascript" src="../src/angular-bootstrap.js#autobind&rootScope=$view"></script>
+ <script type="text/javascript" src="../src/angular-bootstrap.js#autobind"></script>
</head>
- <body>
+ <body ng-init="$window.$scope = $root">
<table>
<tr>
<th>Description</th>
diff --git a/src/Angular.js b/src/Angular.js
index 72ff26b0..5b5aa87b 100644
--- a/src/Angular.js
+++ b/src/Angular.js
@@ -45,7 +45,7 @@ UrlWatcher.prototype = {
}
};
-
+////////////////////////////////////
if (typeof document.getAttribute == 'undefined')
document.getAttribute = function() {};
@@ -386,3 +386,20 @@ function compile(element, config) {
}
/////////////////////////////////////////////////
+function parseKeyValue(keyValue) {
+ var obj = {}, key_value, key;
+ 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;
+ }
+ });
+ return obj;
+}
+
+function angularInit(config){
+ if (config.autobind) {
+ compile(window.document, config).$init();
+ }
+}
diff --git a/src/angular-bootstrap.js b/src/angular-bootstrap.js
index 7798afa5..b0a3aa4f 100644
--- a/src/angular-bootstrap.js
+++ b/src/angular-bootstrap.js
@@ -22,23 +22,16 @@
* THE SOFTWARE.
*/
(function(previousOnLoad){
- var filename = /(.*)\/angular-(.*).js(#(.*))?/;
- var scripts = document.getElementsByTagName("SCRIPT");
- var serverPath;
- var config = {};
+ var filename = /(.*)\/angular-(.*).js(#(.*))?/,
+ scripts = document.getElementsByTagName("SCRIPT"),
+ serverPath,
+ config,
+ match;
for(var j = 0; j < scripts.length; j++) {
- var match = (scripts[j].src || "").match(filename);
+ match = (scripts[j].src || "").match(filename);
if (match) {
serverPath = match[1];
- parseConfig(match[4]);
- }
- }
-
- function parseConfig(args) {
- var keyValues = args.split('&'), keyValue, i = 0;
- for (; i < keyValues.length; i++) {
- keyValue = keyValues[i].split('=');
- config[keyValue[0]] = keyValue[1] || true;
+ config = match[4];
}
}
@@ -53,7 +46,6 @@
addScript("/jqlite.js");
addScript("/Parser.js");
addScript("/Resource.js");
- addScript("/URLWatcher.js");
// Extension points
addScript("/apis.js");
@@ -63,17 +55,14 @@
addScript("/directives.js");
addScript("/markups.js");
addScript("/widgets.js");
+ addScript("/services.js");
- if (config.autobind) {
- window.onload = function(){
- try {
- if (previousOnLoad) previousOnLoad();
- } catch(e) {}
- var scope = angular.compile(window.document, config);
- if (config.rootScope) window[config.rootScope] = scope;
- scope.$init();
- };
- }
+ window.onload = function(){
+ try {
+ if (previousOnLoad) previousOnLoad();
+ } catch(e) {}
+ angularInit(parseKeyValue(config));
+ };
})(window.onload);
diff --git a/src/moveToAngularCom/Model.js b/src/delete/Model.js
index b09efd0e..b09efd0e 100644
--- a/src/moveToAngularCom/Model.js
+++ b/src/delete/Model.js
diff --git a/src/markups.js b/src/markups.js
index 6bc27c85..3ae713fb 100644
--- a/src/markups.js
+++ b/src/markups.js
@@ -51,6 +51,7 @@ angularTextMarkup('{{}}', function(text, textNode, parentElement) {
}
});
+// TODO: this should be widget not a markup
angularTextMarkup('OPTION', function(text, textNode, parentElement){
if (parentElement[0].nodeName == "OPTION") {
var select = document.createElement('select');
diff --git a/src/services.js b/src/services.js
index 14c71363..5d235b32 100644
--- a/src/services.js
+++ b/src/services.js
@@ -1,34 +1,34 @@
angularService("$window", bind(window, identity, window));
-angularService("$anchor", function(){
+var URL_MATCH = /^(file|ftp|http|https):\/\/(\w+:{0,1}\w*@)?([\w\.]+)(:([0-9]+))?([^\?#]+)?(\?([^#]*))((#([^\?]*))(\?([^\?]*))?)$/;
+angularService("$location", function(){
var scope = this;
- function anchor(url){
+ function location(url){
if (isDefined(url)) {
- if (url.charAt(0) == '#') url = url.substr(1);
- var pathQuery = url.split('?');
- anchor.path = decodeURIComponent(pathQuery[0]);
- anchor.param = {};
- foreach((pathQuery[1] || "").split('&'), function(keyValue){
- if (keyValue) {
- var parts = keyValue.split('=');
- var key = decodeURIComponent(parts[0]);
- var value = parts[1];
- if (!value) value = true;
- anchor.param[key] = decodeURIComponent(value);
- }
- });
+ var match = URL_MATCH.exec(url);
+ dump(match);
+ location.href = url;
+ location.protocol = match[1];
+ location.host = match[3];
+ location.port = match[5];
+ location.path = match[6];
+ location.search = parseKeyValue(match[8]);
+ location.hash = match[9];
+ location.hashPath = match[11];
+ location.hashSearch = parseKeyValue(match[13]);
+ foreach(location, dump);
}
var params = [];
- foreach(anchor.param, function(value, key){
+ foreach(location.param, function(value, key){
params.push(encodeURIComponent(key) + '=' + encodeURIComponent(value));
});
- return (anchor.path ? anchor.path : '') + (params.length ? '?' + params.join('&') : '');
+ return (location.path ? location.path : '') + (params.length ? '?' + params.join('&') : '');
};
this.$config.location.watch(function(url){
- anchor(url);
+ location(url);
});
this.$onEval(PRIORITY_LAST, function(){
- scope.$config.location.set(anchor());
+ scope.$config.location.set(location());
});
- return anchor;
+ return location;
});
diff --git a/test/BinderTest.js b/test/BinderTest.js
index 67800e62..9c5c5dc6 100644
--- a/test/BinderTest.js
+++ b/test/BinderTest.js
@@ -721,13 +721,13 @@ BinderTest.prototype.testItShouldSelectTheCorrectRadioBox = function() {
var male = jqLite(c.node[0].childNodes[1]);
female.click();
- assertEquals("female", c.scope.$get("sex"));
+ assertEquals("female", c.scope.sex);
assertEquals(true, female[0].checked);
assertEquals(false, male[0].checked);
assertEquals("female", female.val());
male.click();
- assertEquals("male", c.scope.$get("sex"));
+ assertEquals("male", c.scope.sex);
assertEquals(false, female[0].checked);
assertEquals(true, male[0].checked);
assertEquals("male", male.val());
diff --git a/test/servicesSpec.js b/test/servicesSpec.js
index 5a6bcedc..88cbc947 100644
--- a/test/servicesSpec.js
+++ b/test/servicesSpec.js
@@ -13,10 +13,17 @@ describe("services", function(){
expect(scope.$window).toEqual(window);
});
- it("should inject $anchor", function(){
- scope.$anchor('#path?key=value');
- expect(scope.$anchor.path).toEqual("path");
- expect(scope.$anchor.param).toEqual({key:'value'});
+ it("should inject $location", function(){
+ scope.$location('http://host:1234/p/a/t/h?query=value#path?key=value');
+ expect(scope.$location.href).toEqual("http://host:123/p/a/t/h?query=value#path?key=value");
+ expect(scope.$location.protocol).toEqual("http");
+ expect(scope.$location.host).toEqual("host");
+ expect(scope.$location.port).toEqual("1234");
+ expect(scope.$location.path).toEqual("/p/a/t/h");
+ expect(scope.$location.search).toEqual({query:'value'});
+ expect(scope.$location.hash).toEqual('path?key=value');
+ expect(scope.$location.hashPath).toEqual('path');
+ expect(scope.$location.hashSearch).toEqual({key:'value'});
scope.$anchor.path = 'page=http://path';
scope.$anchor.param = {k:'a=b'};