aboutsummaryrefslogtreecommitdiffstats
path: root/src/services.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/services.js')
-rw-r--r--src/services.js90
1 files changed, 77 insertions, 13 deletions
diff --git a/src/services.js b/src/services.js
index a5158149..31c5e7af 100644
--- a/src/services.js
+++ b/src/services.js
@@ -40,7 +40,7 @@ angularService("$location", function(browser){
}
function check(param) {
- return lastLocation[param] == location[param] ? undefined : location[param];
+ return lastLocation[param] == location[param] ? _undefined : location[param];
}
function checkProtocol(){
@@ -49,9 +49,9 @@ angularService("$location", function(browser){
lastLocation.port === location.port &&
lastLocation.path === location.path &&
equals(lastLocation.search, location.search))
- return undefined;
+ return _undefined;
var url = toKeyValue(location.search);
- var port = (location.port == DEFAULT_PORTS[location.protocol] ? null : location.port);
+ var port = (location.port == DEFAULT_PORTS[location.protocol] ? _null : location.port);
return location.protocol + '://' + location.host +
(port ? ':' + port : '') + location.path +
(url ? '?' + url : '');
@@ -60,7 +60,7 @@ angularService("$location", function(browser){
function checkHashPathSearch(){
if (lastLocation.hashPath === location.hashPath &&
equals(lastLocation.hashSearch, location.hashSearch) )
- return undefined;
+ return _undefined;
var url = toKeyValue(location.hashSearch);
return escape(location.hashPath) + (url ? '?' + url : '');
}
@@ -72,7 +72,7 @@ angularService("$location", function(browser){
location.href = url.replace('#$', '');
location.protocol = match[1];
location.host = match[3] || '';
- location.port = match[5] || DEFAULT_PORTS[location.protocol] || null;
+ location.port = match[5] || DEFAULT_PORTS[location.protocol] || _null;
location.path = match[6];
location.search = parseKeyValue(match[8]);
location.hash = match[10] || '';
@@ -109,7 +109,7 @@ angularService('$exceptionHandler', function($log){
}, {inject:['$log']});
angularService("$hover", function(browser, document) {
- var tooltip, self = this, error, width = 300, arrowWidth = 10, body = jqLite(document[0].body);;
+ var tooltip, self = this, error, width = 300, arrowWidth = 10, body = jqLite(document[0].body);
browser.hover(function(element, show){
if (show && (error = element.attr(NG_EXCEPTION) || element.attr(NG_VALIDATION_ERROR))) {
if (!tooltip) {
@@ -149,7 +149,7 @@ angularService("$hover", function(browser, document) {
}
} else if (tooltip) {
tooltip.callout.remove();
- tooltip = null;
+ tooltip = _null;
}
});
}, {inject:['$browser', '$document']});
@@ -211,7 +211,7 @@ function switchRouteMatcher(on, when, dstName) {
});
if (dstName) this.$set(dstName, dst);
}
- return match ? dst : null;
+ return match ? dst : _null;
}
angularService('$route', function(location){
@@ -234,7 +234,7 @@ angularService('$route', function(location){
};
function updateRoute(){
var childScope;
- $route.current = null;
+ $route.current = _null;
angular.foreach(routes, function(routeParams, route) {
if (!childScope) {
var pathParams = matcher(location.hashPath, route);
@@ -262,7 +262,7 @@ angularService('$xhr', function($browser, $error, $log){
return function(method, url, post, callback){
if (isFunction(post)) {
callback = post;
- post = null;
+ post = _null;
}
if (post && isObject(post)) {
post = toJson(post);
@@ -300,7 +300,7 @@ angularService('$xhr.bulk', function($xhr, $error, $log){
function bulkXHR(method, url, post, callback) {
if (isFunction(post)) {
callback = post;
- post = null;
+ post = _null;
}
var currentQueue;
foreach(bulkXHR.urls, function(queue){
@@ -345,11 +345,11 @@ angularService('$xhr.bulk', function($xhr, $error, $log){
}, {inject:['$xhr', '$xhr.error', '$log']});
angularService('$xhr.cache', function($xhr){
- var inflight = {}, self = this;;
+ var inflight = {}, self = this;
function cache(method, url, post, callback, verifyCache){
if (isFunction(post)) {
callback = post;
- post = null;
+ post = _null;
}
if (method == 'GET') {
var data;
@@ -392,3 +392,67 @@ angularService('$resource', function($xhr){
var resource = new ResourceFactory($xhr);
return bind(resource, resource.route);
}, {inject: ['$xhr.cache']});
+
+
+angularService('$cookies', function($browser) {
+ var cookies = {}, rootScope = this;
+ $browser.watchCookies(function(newCookies){
+ copy(newCookies, cookies);
+ rootScope.$eval();
+ });
+ this.$onEval(PRIORITY_FIRST, update);
+ this.$onEval(PRIORITY_LAST, update);
+ return cookies;
+
+ function update(){
+ var name, browserCookies = $browser.cookies();
+ for(name in cookies) {
+ if (browserCookies[name] !== cookies[name]) {
+ $browser.cookies(name, browserCookies[name] = cookies[name]);
+ }
+ }
+ for(name in browserCookies) {
+ if (browserCookies[name] !== cookies[name]) {
+ $browser.cookies(name, _undefined);
+ //TODO: write test for this delete
+ //delete cookies[name];
+ }
+ }
+ }
+}, {inject: ['$browser']});
+
+
+angularService('$sessionStore', function($store) {
+
+ function SessionStore() {}
+
+ SessionStore.prototype.get = function(key) {
+ return fromJson($store[key]);
+ };
+
+ SessionStore.prototype.getAll = function() {
+ var all = {},
+ key;
+
+ for (key in $store) {
+ if (!$store.hasOwnProperty(key)) continue;
+ all[key] = fromJson($store[key]);
+ }
+
+ return all;
+ };
+
+
+ SessionStore.prototype.put = function(key, value) {
+ $store[key] = toJson(value);
+ };
+
+
+ SessionStore.prototype.remove = function(key) {
+ delete $store[key];
+ };
+
+
+ return new SessionStore();
+
+}, {inject: ['$cookies']});