Avoid auto-updating slug on live pages - fixes #528

Rewrite the initSlugAutoPopulate function so that the slug only tracks the
title field if the page is unpublished, AND the current slug matches the
title (indicating that it has not been edited manually, either in this editing
session or a previous one).
pull/1810/head
Matt Westcott 2015-10-09 20:44:00 +01:00
rodzic 055cdef5bd
commit 1e6adf2861
2 zmienionych plików z 14 dodań i 7 usunięć

Wyświetl plik

@ -303,15 +303,19 @@ function cleanForSlug(val, useURLify) {
} }
function initSlugAutoPopulate() { function initSlugAutoPopulate() {
var slugFollowsTitle = false;
$('#id_title').on('focus', function() { $('#id_title').on('focus', function() {
$('#id_slug').data('previous-val', $('#id_slug').val()); /* slug should only follow the title field if its value matched the title's value at the time of focus */
$(this).data('previous-val', $(this).val()); var currentSlug = $('#id_slug').val();
var slugifiedTitle = cleanForSlug(this.value);
slugFollowsTitle = (currentSlug == slugifiedTitle);
}); });
$('#id_title').on('keyup keydown keypress blur', function() { $('#id_title').on('keyup keydown keypress blur', function() {
if ($('body').hasClass('create') || (!$('#id_slug').data('previous-val').length || cleanForSlug($('#id_title').data('previous-val')) === $('#id_slug').data('previous-val'))) { if (slugFollowsTitle) {
// only update slug if the page is being created from scratch, if slug is completely blank, or if title and slug prior to typing were identical var slugifiedTitle = cleanForSlug(this.value);
$('#id_slug').val(cleanForSlug($('#id_title').val())); $('#id_slug').val(slugifiedTitle);
} }
}); });
} }
@ -364,7 +368,10 @@ function initCollapsibleBlocks() {
} }
$(function() { $(function() {
initSlugAutoPopulate(); /* Only non-live pages should auto-populate the slug from the title */
if (!$('body').hasClass('page-is-live')) {
initSlugAutoPopulate();
}
initSlugCleaning(); initSlugCleaning();
initErrorDetection(); initErrorDetection();
initCollapsibleBlocks(); initCollapsibleBlocks();

Wyświetl plik

@ -3,7 +3,7 @@
{% load gravatar %} {% load gravatar %}
{% load i18n %} {% load i18n %}
{% block titletag %}{% blocktrans with title=page.title page_type=content_type.model_class.get_verbose_name %}Editing {{ page_type }}: {{ title }}{% endblocktrans %}{% endblock %} {% block titletag %}{% blocktrans with title=page.title page_type=content_type.model_class.get_verbose_name %}Editing {{ page_type }}: {{ title }}{% endblocktrans %}{% endblock %}
{% block bodyclass %}page-editor model-{{ content_type.model }}{% endblock %} {% block bodyclass %}page-editor {% if page.live %}page-is-live{% endif %} model-{{ content_type.model }}{% endblock %}
{% block content %} {% block content %}
{% page_permissions page as page_perms %} {% page_permissions page as page_perms %}