From d71b960ecfd1146580cf1e884b7552e16ad8a0b9 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Fri, 17 Feb 2012 13:14:57 -0500 Subject: [PATCH] Working on edit --- snipt/media/css/style.scss | 1 + snipt/media/js/src/modules/snipt.js | 39 ++++++++++++++++--- snipt/snipts/templates/snipts/snipt-list.html | 4 +- snipt/templates/base.html | 6 +-- 4 files changed, 39 insertions(+), 11 deletions(-) diff --git a/snipt/media/css/style.scss b/snipt/media/css/style.scss index e1bc172..1be3ddd 100644 --- a/snipt/media/css/style.scss +++ b/snipt/media/css/style.scss @@ -801,6 +801,7 @@ div.modal { } h3 { span { + display: inline-block; max-width: 400px; overflow: hidden; text-overflow: ellipsis; diff --git a/snipt/media/js/src/modules/snipt.js b/snipt/media/js/src/modules/snipt.js index 58036b0..c2e6e2a 100644 --- a/snipt/media/js/src/modules/snipt.js +++ b/snipt/media/js/src/modules/snipt.js @@ -82,7 +82,7 @@ } }, detail: function() { - window.location = this.model.get('url'); + window.location = this.model.get('absolute_url'); }, edit: function() { if (!$('section.main-edit:visible').length) { @@ -95,11 +95,13 @@ }, embed: function() { alert('TODO'); + return false; }, expand: function() { this.$container.toggleClass('expanded', 100); this.$tags.toggleClass('expanded'); this.select(); + return false; }, next: function() { window.site.$copyModals.modal('hide'); @@ -144,7 +146,7 @@ e.stopPropagation(); }, test: function() { - this.model.set({'title': 'Changed title!'}); + console.log(this.model.attributes); } }); SniptListView = Backbone.View.extend({ @@ -160,11 +162,31 @@ }, addExistingSnipt: function() { - var $h1 = $('header h1 a', this); + + var $el = $(this); + var $h1 = $('header h1 a', $el); + var data = { + absolute_url: $h1.attr('href'), + code: '', + created: '', + description: '', + embed_url: '', + id: parseInt($el.attr('id').replace('snipt-', ''), 0), + key: '', + lexer: '', + line_count: 0, + modified: '', + pub: false, + resource_uri: '', + slug: '', + stylized: '', + tags: [], + tags_list: '', title: $h1.text(), - url: $h1.attr('href') + user: '' }; + var view = new SniptView({ el: this, model: new SniptModel(data) @@ -200,7 +222,7 @@ $selected.trigger('copyRaw'); } }); - $document.bind('keydown', 'e', function() { + $document.bind('keydown', 'Ctrl+e', function() { if ($selected) { if ($selected.hasClass('editable')) { $selected.trigger('edit'); @@ -240,7 +262,7 @@ } } }); - $document.bind('keydown', 'o', function() { + $document.bind('keydown', 'e', function() { if ($selected) { if ($selected.hasClass('expandable')) { $selected.trigger('expand'); @@ -260,6 +282,11 @@ $selected.trigger('embed'); } }); + $document.bind('keydown', 'o', function() { + if ($selected) { + $selected.trigger('detail'); + } + }); $document.bind('keydown', 'return', function() { if ($selected) { $selected.trigger('detail'); diff --git a/snipt/snipts/templates/snipts/snipt-list.html b/snipt/snipts/templates/snipts/snipt-list.html index dc7feb2..ac1a1d7 100644 --- a/snipt/snipts/templates/snipts/snipt-list.html +++ b/snipt/snipts/templates/snipts/snipt-list.html @@ -1,6 +1,6 @@ {% load humanize %} -
+
#{{ snipt.id }}
@@ -33,7 +33,7 @@ Embed
  • - CopyCopied! + Copy
  • diff --git a/snipt/templates/base.html b/snipt/templates/base.html index db6adce..d7e5ce8 100644 --- a/snipt/templates/base.html +++ b/snipt/templates/base.html @@ -210,7 +210,7 @@ Go to snipt - o + e Expand / collapse snipt @@ -222,7 +222,7 @@ Copy snipt - e + <ctrl-e> Edit snipt @@ -249,7 +249,7 @@
    - {{url}}
    + {{absolute_url}}
    {{title}}