Skip to content

Commit

Permalink
Allow ESC key to revert in-progress tag editing.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Jul 5, 2010
1 parent 9b60765 commit e4cfbd5
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions index.html
Expand Up @@ -247,9 +247,9 @@
});
} // save_tags

function process_tag_edit(element)
function process_tag_edit(element, tagstr)
{
var tagstr = element.val().toLowerCase();
tagstr = tagstr.toLowerCase();
tagstr = tagstr.replace(/^\s*|\s*$/g, '');
tagstr = tagstr.replace(/\s+/g, ' ');
tagstr = tagstr.replace(/[^a-z0-9 ]/g, '');
Expand Down Expand Up @@ -326,12 +326,22 @@
tagstr = '';

var html = "<input class='tagedit' name='tagedit' type='text'" +
"value='" + tagstr + "' autocomplete='off'/>";
"value='" + tagstr + "' autocomplete='off'/>";
element.html(html);

editor = $("input.tagedit");
editor.blur(function() { process_tag_edit($(this)); });
editor.change(function() { process_tag_edit($(this)); });
editor.blur(function() { process_tag_edit($(this), $(this).val()); });
editor.change(function() { process_tag_edit($(this), $(this).val()); });
editor.keyup(function(e) {
if (e.keyCode != 27)
return;
// revert to original tags on escape.
var parentdiv = $(this).parent();
var gameidx = parentdiv.attr('profilegameidx');
var game = profile.gamelist[gameidx];
var tagstr = game.tags.join(' ');
process_tag_edit($(this), tagstr);
});
editor.focus();
} // clicked_taglist

Expand Down

0 comments on commit e4cfbd5

Please sign in to comment.