From 680b69b17161aaca29c50090675bdfe05fe3b01d Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Mon, 22 Nov 2010 00:05:58 +0000 Subject: - Patch #976758 by pwolanin, sun: existing machine names are changed when human readable name is changed (e.g. node type, vocabulary). --- misc/machine-name.js | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'misc/machine-name.js') diff --git a/misc/machine-name.js b/misc/machine-name.js index befbc0efd..4c1ad8309 100644 --- a/misc/machine-name.js +++ b/misc/machine-name.js @@ -38,34 +38,41 @@ Drupal.behaviors.machineName = { } // Hide the form item container of the machine name form element. $wrapper.hide(); - // Append the machine name preview to the source field. - if ($target.is(':disabled')) { + // Determine the initial machine name value. Unless the machine name form + // element is disabled or not empty, the initial default value is based on + // the human-readable form element value. + if ($target.is(':disabled') || $target.val() != '') { var machine = $target.val(); } else { var machine = self.transliterate($source.val(), options); } + // Append the machine name preview to the source field. var $preview = $('' + machine + ''); $suffix.empty() .append(' ').append('' + options.label + ':') .append(' ').append($preview); - // Append a link to edit the machine name, if it is editable, and only if - // one of the following conditions is met: - // - the machine name is empty. - // - the human-readable name is equal to the existing machine name. - if (!$target.is(':disabled') && ($target.val() == '' || $target.val() == machine)) { - var $link = $('' + Drupal.t('Edit') + '') - .click(function () { - $wrapper.show(); - $target.focus(); - $suffix.hide(); - $source.unbind('keyup.machineName'); - return false; - }); - $suffix.append(' ').append($link); + // If the machine name cannot be edited, stop further processing. + if ($target.is(':disabled')) { + return; + } + + // If it is editable, append an edit link. + var $link = $('' + Drupal.t('Edit') + '') + .click(function () { + $wrapper.show(); + $target.focus(); + $suffix.hide(); + $source.unbind('.machineName'); + return false; + }); + $suffix.append(' ').append($link); - // Preview machine name in realtime when the human-readable name changes. + // Preview the machine name in realtime when the human-readable name + // changes, but only if there is no machine name yet; i.e., only upon + // initial creation, not when editing. + if ($target.val() == '') { $source.bind('keyup.machineName change.machineName', function () { machine = self.transliterate($(this).val(), options); // Set the machine name to the transliterated value. -- cgit v1.2.3