diff options
author | Dries Buytaert <dries@buytaert.net> | 2010-11-22 00:05:58 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2010-11-22 00:05:58 +0000 |
commit | 680b69b17161aaca29c50090675bdfe05fe3b01d (patch) | |
tree | e11f1e74449b92830386305da0c66c946be41f69 /misc/machine-name.js | |
parent | c890cb3a95396505f1cbfe03be922cfe67b1261e (diff) | |
download | brdo-680b69b17161aaca29c50090675bdfe05fe3b01d.tar.gz brdo-680b69b17161aaca29c50090675bdfe05fe3b01d.tar.bz2 |
- Patch #976758 by pwolanin, sun: existing machine names are changed when human readable name is changed (e.g. node type, vocabulary).
Diffstat (limited to 'misc/machine-name.js')
-rw-r--r-- | misc/machine-name.js | 41 |
1 files changed, 24 insertions, 17 deletions
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 = $('<span class="machine-name-value">' + machine + '</span>'); $suffix.empty() .append(' ').append('<span class="machine-name-label">' + options.label + ':</span>') .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 = $('<span class="admin-link"><a href="#">' + Drupal.t('Edit') + '</a></span>') - .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 = $('<span class="admin-link"><a href="#">' + Drupal.t('Edit') + '</a></span>') + .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. |