diff options
Diffstat (limited to 'src/Angular.js')
| -rw-r--r-- | src/Angular.js | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/src/Angular.js b/src/Angular.js index 8eef6ac0..d97c2282 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -1,3 +1,52 @@ + +////////////////////////////// +//UrlWatcher +////////////////////////////// + +function UrlWatcher(location) { + this.location = location; + this.delay = 25; + this.setTimeout = function(fn, delay) { + window.setTimeout(fn, delay); + }; + this.expectedUrl = location.href; + this.listeners = []; +} + +UrlWatcher.prototype = { + watch: function(fn){ + this.listeners.push(fn); + }, + + start: function() { + var self = this; + (function pull () { + if (self.expectedUrl !== self.location.href) { + foreach(self.listeners, function(listener){ + listener(self.location.href); + }); + self.expectedUrl = self.location.href; + } + self.setTimeout(pull, self.delay); + })(); + }, + + set: function(url) { + var existingURL = this.location.href; + if (!existingURL.match(/#/)) + existingURL += '#'; + if (existingURL != url) + this.location.href = url; + this.existingURL = url; + }, + + get: function() { + return this.location.href; + } +}; + +//////////////////////////////////// + if (typeof document.getAttribute == 'undefined') document.getAttribute = function() {}; @@ -16,7 +65,7 @@ var consoleNode, msie = !!/(msie) ([\w.]+)/.exec(lowercase(navigator.userAgent)), jqLite = jQuery || jqLiteWrap, slice = Array.prototype.slice, - angular = window['angular'] || (window['angular'] = {}), + angular = window['angular'] || (window['angular'] = {}), angularTextMarkup = extensionMap(angular, 'textMarkup'), angularAttrMarkup = extensionMap(angular, 'attrMarkup'), angularDirective = extensionMap(angular, 'directive'), @@ -336,3 +385,30 @@ function compile(element, config) { return compiler.compile($element)($element, rootScope); } ///////////////////////////////////////////////// + +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 toKeyValue(obj) { + var parts = []; + foreach(obj, function(value, key){ + parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(value)); + }); + return parts.length ? parts.join('&') : ''; +}; + +function angularInit(config){ + if (config.autobind) { + compile(window.document, config).$init(); + } +} + |
