From 0e566fe6cb41de388df6793b350fb81aaa4a8476 Mon Sep 17 00:00:00 2001 From: Misko Hevery Date: Mon, 18 Jan 2010 17:56:08 -0800 Subject: tweeter demo client --- src/Angular.js | 30 ++++++++++++++++-------------- src/Binder.js | 1 - src/Filters.js | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/Angular.js b/src/Angular.js index 69cab0a2..3dc72ff7 100644 --- a/src/Angular.js +++ b/src/Angular.js @@ -227,7 +227,7 @@ Angular.prototype = { bindHtml: function() { log('Angular.bindHtml()'); - var watcher = new UrlWatcher(this.location); + var watcher = this.watcher = new UrlWatcher(this.location); var document = this.document; var widgetFactory = new WidgetFactory(this.config.server, this.config.database); var binder = new Binder(document[0], widgetFactory, watcher, this.config); @@ -285,12 +285,6 @@ Angular.prototype = { log('$binder.parseAnchor()'); binder.parseAnchor(); - log('$binder.updateView()'); - binder.updateView(); - - //watcher.listener = bind(binder, binder.onUrlChange, watcher); - //watcher.onUpdate = function(){alert("update");}; - //watcher.watch(); document.find("body").show(); log('ready()'); }, @@ -378,12 +372,13 @@ UrlWatcher.prototype = { }, setUrl: function(url) { -// var existingURL = window.location.href; -// if (!existingURL.match(/#/)) -// existingURL += '#'; -// if (existingURL != url) -// window.location.href = url; -// this.existingURL = url; + //TODO: conditionaly? + var existingURL = window.location.href; + if (!existingURL.match(/#/)) + existingURL += '#'; + if (existingURL != url) + window.location.href = url; + this.existingURL = url; }, getUrl: function() { @@ -409,6 +404,13 @@ angular['compile'] = function(root, config) { 'updateView':function(){return scope.updateView();}, 'set':function(){return scope.set.apply(scope, arguments);}, 'get':function(){return scope.get.apply(scope, arguments);}, - 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();} + 'init':function(){scope.get('$binder.executeInit')(); scope.updateView();}, + 'watchUrl':function(){ + var binder = scope.get('$binder'); + var watcher = angular.watcher; + watcher.listener = bind(binder, binder.onUrlChange, watcher); + watcher.onUpdate = function(){alert("update");}; + watcher.watch(); + } }; }; \ No newline at end of file diff --git a/src/Binder.js b/src/Binder.js index 36cb6ec3..b29a07c6 100644 --- a/src/Binder.js +++ b/src/Binder.js @@ -66,7 +66,6 @@ Binder.prototype = { }, onUrlChange: function (url) { - log("URL change detected", url); this.parseAnchor(url); this.updateView(); }, diff --git a/src/Filters.js b/src/Filters.js index 666c9f30..833d5630 100644 --- a/src/Filters.js +++ b/src/Filters.js @@ -293,6 +293,23 @@ foreach({ 'html': function(html){ return new angularFilter.Meta({html:html}); + }, + + 'linky': function(text){ + function regExpEscape(text) { + return text.replace(/([\/\.\*\+\?\|\(\)\[\]\{\}\\])/g, '\\$1'); + } + var URL = /(ftp|http|https):\/\/([^\(\)|\s]+)/gm; + var html = text; + var dups = {}; + foreach(text.match(URL)||[], function(url){ + url = url.replace(/\.$/, ''); + if (!dups[url]) { + html = html.replace(new RegExp(regExpEscape(url), 'gm'), ''+url+''); + dups[url] = true; + } + }); + return new angularFilter.Meta({text:text, html:html}); } }, function(v,k){angularFilter[k] = v;}); -- cgit v1.2.3