Permalink
Browse files

handels now urls in todos

  • Loading branch information...
1 parent 7aedd15 commit 009845ef8a312c902fdcba52131e8bf02bf21ae5 @bartcc committed Aug 17, 2012
@@ -36,8 +36,7 @@ function add() {
$this->Todo->create();
$this->Todo->save($this->data);
$id = $this->Todo->id;
- $this->data = $this->data + array('id' => (string) $id);
- $this->set('json', $this->data['Todo']);
+ $this->set('json', $this->data['Todo'] + array('id' => (string) $id));
$this->render(SIMPLE_JSON, 'ajax');
}
@@ -31,6 +31,9 @@ h1, h2 {
font-weight: bold;
text-shadow: 0 1px 1px #ffffff;
}
+a {
+ text-decoration: underline;
+}
h1 {
font-size: 21pt;
color: #404040;
@@ -25,7 +25,6 @@ jQuery(function() {
initialize: function() {
_.bindAll(this, 'render', 'close');
- this.input = this.$('.todo-input');
this.model.bind('change', this.render);
this.model.view = this;
},
@@ -42,9 +41,31 @@ jQuery(function() {
// To avoid XSS (not that it would be harmful in this particular app),
// we use `jQuery.text` to set the contents of the todo item.
setContent: function() {
- var content = this.model.get('content');
- this.$('.todo-content').text(content);
- this.$('.todo-input').val(content);
+ var patt = /((?:http|https):\/\/[a-z0-9\/\?=_#&%~-]+(\.[a-z0-9\/\?=_#&%~-]+)+)|(www(\.[a-z0-9\/\?=_#&%~-]+){2,})/,
+ test, anchorEl, content, res, editor, anchorContent;
+
+ content = this.model.get('content');
+ test = patt.test(content);
+ res = content.match(patt);
+
+ if (test) {
+ anchorEl = $('<a></a>').attr({
+ 'href' : res[0],
+ 'target' : '_blank'
+ }).addClass('editor');
+
+ content = anchorEl.html(content);
+ anchorContent = anchorEl.text();
+
+ this.$('.todo-content').append(content);
+
+ } else {
+
+ this.$('.todo-content').text(content);
+
+ }
+
+ this.$('.todo-input').val(anchorContent || content);
},
// Toggle the `"done"` state of the model.

0 comments on commit 009845e

Please sign in to comment.