Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created June 12, 2012 22:23
Show Gist options
  • Select an option

  • Save nfreear/2920496 to your computer and use it in GitHub Desktop.

Select an option

Save nfreear/2920496 to your computer and use it in GitHub Desktop.
Drupal 6: Require 2 backspaces to delete tags; don't use tab (accessibility) | Javascript | http://drupal.org/project/nice_tags#nice_tags.js
diff --git a/nice_tags.js b/nice_tags.js
index 5adedd2..c5ae14b 100644
--- a/nice_tags.js
+++ b/nice_tags.js
@@ -92,24 +92,36 @@ function easyTagsListen(input_wrapper) {
// key codes that trigger the tag to be added when pressed
var keyTriggers = [
- 9, // tab
+ /*9, // tab NDF: not tab - keyboard accessibility */
13, // return
186, // semi-colon
188, // comma
+ 32 //NDF: space
];
+ var backCount = 0; //NDF:
+
// key event listener
$inputField.keyup(function(e, keyCode){
// gets the pressed key
keyCode = keyCode || e.keyCode;
- // remove last tag if backspace is pressed and the form is empty
- if (keyCode == 8 && $inputField.val() == '') {
+ // remove last tag if backspace is pressed twice (NDF:) and the form is empty
+ if (backCount > 0 && keyCode == 8 && $inputField.val() == '') {
$tagContainer.find('span:last').remove();
tagStateRefresh(input_wrapper);
$inputField.val('');
+
+ backCount = 0;
+ //console.log('Delete tag');
+ }
+ else if (keyCode == 8 && $inputField.val() == '') {
+ backCount++;
+ //console.log('A backspace');
}
else {
+ backCount = 0;
+
// gets the new inputed tag
var tag = $inputField.val();
@@ -123,7 +135,7 @@ function easyTagsListen(input_wrapper) {
}
}).keydown(function(e) {
// prevents tab and enter to perform their default action
- if (e.which == 9 || e.which == 13) {
+ if (/*NDF: keyboard accessibility, e.which == 9 ||*/ e.which == 13) {
e.preventDefault();
}
});
/*
Enlarge nice_tags suggestions box/ font-size etc.
Thanks, 'nunoveloso'
*/
.nice-tags-form-item{ font-size:1.15em; }
.nice-tags-form-item .tag{ font-size:1.15em !important; }
.nice-tags-form-item .tag a{ background-color:navy !important; cursor:pointer; }
.nice-tags-form-item input[type=text]{ width:8em !important; border:1px dotted #bbb !important; position:relative; top:-2px; height:1.1em; }
.nice-tags-form-item .tags-container{ height:1.35em !important; }
.nice-tags-form-item #autocomplete {
x-margin-top:22px;
min-width:12em !important;
width:auto !important;
border:1px solid #bbb !important;
border-radius:4px;
background:#ffa !important;
padding:8px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment