From f935ac56c2c97f3a5eca9673e4cdedc4ea3d2953 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Fri, 18 Nov 2011 16:42:05 -0500 Subject: [PATCH] Nicer page titles --- lib/document_handler.js | 2 +- static/application.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/document_handler.js b/lib/document_handler.js index 2be8805..db05386 100644 --- a/lib/document_handler.js +++ b/lib/document_handler.js @@ -13,7 +13,7 @@ DocumentHandler.prototype.handleGet = function(key, response) { if (DocumentHandler.documents[key]) { winston.verbose('retrieved document', { key: key }); response.writeHead(200, { 'content-type': 'application/json' }); - response.end(JSON.stringify({ data: DocumentHandler.documents[key] })); + response.end(JSON.stringify({ data: DocumentHandler.documents[key], key: key })); } else { winston.warn('document not found', { key: key }); diff --git a/static/application.js b/static/application.js index ee479c2..996579f 100644 --- a/static/application.js +++ b/static/application.js @@ -102,7 +102,11 @@ heist.prototype.loadDocument = function(key) { _this.doc.load(key, function(ret) { if (ret) { _this.$code.html(ret.value); - _this.setTitle(ret.language ? ret.language : 'unknown'); + var title = ret.key; + if (ret.language) { + title += ' - ' + ret.language; + } + _this.setTitle(title); _this.$textarea.val('').hide(); _this.$box.show(); } @@ -127,7 +131,11 @@ heist.prototype.lockDocument = function() { this.doc.save(this.$textarea.val(), function(ret) { if (ret) { _this.$code.html(ret.value); - _this.setTitle(ret.language ? ret.language : 'unknown'); + var title = ret.key; + if (ret.language) { + title += ' - ' + ret.language; + } + _this.setTitle(title); window.history.pushState(null, _this.appName + '-' + ret.key, '/' + ret.key); _this.$textarea.val('').hide(); _this.$box.show();