From 17c9768b02a9a1e4278d6d55b54d4e47f2cf0099 Mon Sep 17 00:00:00 2001 From: Sebastian Spiegel Date: Wed, 19 Nov 2014 15:38:28 +0100 Subject: [PATCH 1/2] fix saving a single tag with multiple words in it, fixes #824 Add a preprocessTag option for tag-it.js in page-editor.js to fix a problem with saving a single tag with multiple words in it when editing a Page. tag-it.js doesn't put a comma after a single tag (neither double quotes it by default) when POSTing to Wagtail so django-taggit treats it as multiple tags. Force double quoting with mentioned preprocessTag option. --- .../static/wagtailadmin/js/page-editor.js | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index 6520ca8f6f..2f29c556f7 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -117,7 +117,15 @@ function initDateTimeChooser(id) { function initTagField(id, autocompleteUrl) { $('#' + id).tagit({ - autocomplete: {source: autocompleteUrl} + autocomplete: {source: autocompleteUrl}, + preprocessTag: function(val) { + // Double quote a tag if it contains a space + // and if it isn't already quoted. + if (val && val[0] != '"' && val.indexOf(' ') > -1) { + return '"' + val + '"'; + } + return val; + } }); } @@ -345,7 +353,7 @@ $(function() { var $this = $(this); var previewWindow = window.open($this.data('placeholder'), $this.data('windowname')); - + if(/MSIE/.test(navigator.userAgent)){ submitPreview.call($this, false); } else { @@ -362,22 +370,22 @@ $(function() { success: function(data, textStatus, request) { if (request.getResponseHeader('X-Wagtail-Preview') == 'ok') { var pdoc = previewWindow.document; - + if(enhanced){ var frame = pdoc.getElementById('preview-frame'); frame = frame.contentWindow || frame.contentDocument.document || frame.contentDocument; frame.document.open(); - frame.document.write(data); + frame.document.write(data); frame.document.close(); var hideTimeout = setTimeout(function(){ pdoc.getElementById('loading-spinner-wrapper').className += 'remove'; clearTimeout(hideTimeout); - }) // just enough to give effect without adding discernible slowness + }) // just enough to give effect without adding discernible slowness } else { pdoc.open(); - pdoc.write(data); + pdoc.write(data); pdoc.close() } } else { @@ -401,6 +409,6 @@ $(function() { }); } - + }); }); From 355fb67a92f0e5c06fc170e4845084001ce62407 Mon Sep 17 00:00:00 2001 From: Sebastian Spiegel Date: Wed, 19 Nov 2014 15:49:16 +0100 Subject: [PATCH 2/2] revert unwanted whitespace changes automatically made by code editor --- .../static/wagtailadmin/js/page-editor.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js index 2f29c556f7..a0ab8b2716 100644 --- a/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js +++ b/wagtail/wagtailadmin/static/wagtailadmin/js/page-editor.js @@ -353,7 +353,7 @@ $(function() { var $this = $(this); var previewWindow = window.open($this.data('placeholder'), $this.data('windowname')); - + if(/MSIE/.test(navigator.userAgent)){ submitPreview.call($this, false); } else { @@ -370,22 +370,22 @@ $(function() { success: function(data, textStatus, request) { if (request.getResponseHeader('X-Wagtail-Preview') == 'ok') { var pdoc = previewWindow.document; - + if(enhanced){ var frame = pdoc.getElementById('preview-frame'); frame = frame.contentWindow || frame.contentDocument.document || frame.contentDocument; frame.document.open(); - frame.document.write(data); + frame.document.write(data); frame.document.close(); var hideTimeout = setTimeout(function(){ pdoc.getElementById('loading-spinner-wrapper').className += 'remove'; clearTimeout(hideTimeout); - }) // just enough to give effect without adding discernible slowness + }) // just enough to give effect without adding discernible slowness } else { pdoc.open(); - pdoc.write(data); + pdoc.write(data); pdoc.close() } } else { @@ -409,6 +409,6 @@ $(function() { }); } - + }); });