Move tagname related functions from common.js to tag_autocomplete.js.
This commit is contained in:
parent
fdfc7308b0
commit
e1033d0138
5 changed files with 45 additions and 42 deletions
|
@ -125,19 +125,6 @@ function entry_with_history_hook(event)
|
|||
}
|
||||
}
|
||||
|
||||
common.entry_with_tagname_replacements =
|
||||
function entry_with_tagname_replacements(event)
|
||||
{
|
||||
var cursor_position = event.target.selectionStart;
|
||||
var new_value = common.tagname_replacements(event.target.value);
|
||||
if (new_value != event.target.value)
|
||||
{
|
||||
event.target.value = new_value;
|
||||
event.target.selectionStart = cursor_position;
|
||||
event.target.selectionEnd = cursor_position;
|
||||
}
|
||||
}
|
||||
|
||||
common.html_to_element =
|
||||
function html_to_element(html)
|
||||
{
|
||||
|
@ -262,26 +249,6 @@ function init_button_with_confirm()
|
|||
});
|
||||
}
|
||||
|
||||
common.normalize_tagname =
|
||||
function normalize_tagname(tagname)
|
||||
{
|
||||
tagname = tagname.trim();
|
||||
tagname = tagname.toLocaleLowerCase();
|
||||
tagname = tagname.split(".");
|
||||
tagname = tagname[tagname.length-1];
|
||||
tagname = tagname.split("+")[0];
|
||||
tagname = common.tagname_replacements(tagname);
|
||||
return tagname;
|
||||
}
|
||||
|
||||
common.tagname_replacements =
|
||||
function tagname_replacements(tagname)
|
||||
{
|
||||
tagname = tagname.replace(new RegExp(" ", 'g'), "_");
|
||||
tagname = tagname.replace(new RegExp("-", 'g'), "_");
|
||||
return tagname;
|
||||
}
|
||||
|
||||
common.refresh =
|
||||
function refresh()
|
||||
{
|
||||
|
|
|
@ -2,7 +2,8 @@ var tag_autocomplete = {};
|
|||
|
||||
tag_autocomplete.tagset = {"tags": [], "synonyms": {}};
|
||||
|
||||
tag_autocomplete.DATALIST_ID = "tag_autocomplete_datalist"
|
||||
tag_autocomplete.DATALIST_ID = "tag_autocomplete_datalist";
|
||||
|
||||
tag_autocomplete.init_datalist =
|
||||
function init_datalist()
|
||||
{
|
||||
|
@ -30,10 +31,43 @@ function init_datalist()
|
|||
}
|
||||
}
|
||||
|
||||
tag_automplete.normalize_tagname =
|
||||
function normalize_tagname(tagname)
|
||||
{
|
||||
tagname = tagname.trim();
|
||||
tagname = tagname.toLocaleLowerCase();
|
||||
tagname = tagname.split(".");
|
||||
tagname = tagname[tagname.length-1];
|
||||
tagname = tagname.split("+")[0];
|
||||
tagname = tag_automplete.tagname_replacements(tagname);
|
||||
return tagname;
|
||||
}
|
||||
|
||||
tag_automplete.tagname_replacements =
|
||||
function tagname_replacements(tagname)
|
||||
{
|
||||
tagname = tagname.replace(new RegExp(" ", 'g'), "_");
|
||||
tagname = tagname.replace(new RegExp("-", 'g'), "_");
|
||||
return tagname;
|
||||
}
|
||||
|
||||
tag_automplete.entry_with_tagname_replacements_hook =
|
||||
function entry_with_tagname_replacements_hook(event)
|
||||
{
|
||||
var cursor_position = event.target.selectionStart;
|
||||
var new_value = tag_automplete.tagname_replacements(event.target.value);
|
||||
if (new_value != event.target.value)
|
||||
{
|
||||
event.target.value = new_value;
|
||||
event.target.selectionStart = cursor_position;
|
||||
event.target.selectionEnd = cursor_position;
|
||||
}
|
||||
}
|
||||
|
||||
tag_autocomplete.resolve =
|
||||
function resolve(tagname)
|
||||
{
|
||||
tagname = common.normalize_tagname(tagname);
|
||||
tagname = tag_autocomplete.normalize_tagname(tagname);
|
||||
if (tag_autocomplete.tagset["tags"].indexOf(tagname) != -1)
|
||||
{
|
||||
return tagname;
|
||||
|
@ -59,6 +93,7 @@ function update_tagset_callback(response)
|
|||
{
|
||||
tag_autocomplete.init_datalist();
|
||||
}
|
||||
console.log(`Updated tagset contains ${tag_autocomplete.tagset.tags.length}.`);
|
||||
return tag_autocomplete.tagset;
|
||||
}
|
||||
console.error(response);
|
||||
|
|
|
@ -277,7 +277,7 @@ var PHOTO_ID = "{{photo.id}}";
|
|||
var add_tag_box = document.getElementById('add_tag_textbox');
|
||||
var add_tag_button = document.getElementById('add_tag_button');
|
||||
add_tag_box.addEventListener("keyup", common.entry_with_history_hook);
|
||||
add_tag_box.addEventListener("keyup", common.entry_with_tagname_replacements);
|
||||
add_tag_box.addEventListener("keyup", tag_autocomplete.entry_with_tagname_replacements_hook);
|
||||
common.bind_box_to_button(add_tag_box, add_tag_button, false);
|
||||
|
||||
var message_area = document.getElementById('message_area');
|
||||
|
|
|
@ -673,11 +673,11 @@ var inputted_forbids = [];
|
|||
{% endfor %}
|
||||
|
||||
input_musts.addEventListener("keyup", tag_input_hook_musts);
|
||||
input_musts.addEventListener("keyup", common.entry_with_tagname_replacements);
|
||||
input_mays.addEventListener("keyup",tag_input_hook_mays);
|
||||
input_mays.addEventListener("keyup", common.entry_with_tagname_replacements);
|
||||
input_musts.addEventListener("keyup", tag_autocomplete.entry_with_tagname_replacements_hook);
|
||||
input_mays.addEventListener("keyup", tag_input_hook_mays);
|
||||
input_mays.addEventListener("keyup", tag_autocomplete.entry_with_tagname_replacements_hook);
|
||||
input_forbids.addEventListener("keyup", tag_input_hook_forbids);
|
||||
input_forbids.addEventListener("keyup", common.entry_with_tagname_replacements);
|
||||
input_forbids.addEventListener("keyup", tag_autocomplete.entry_with_tagname_replacements_hook);
|
||||
|
||||
common.bind_box_to_button(input_expression, document.getElementById("search_go_button"));
|
||||
</script>
|
||||
|
|
|
@ -14,8 +14,9 @@
|
|||
{% if theme %}<link rel="stylesheet" href="/static/css/theme_{{theme}}.css">{% endif %}
|
||||
<script src="/static/js/common.js"></script>
|
||||
<script src="/static/js/api.js"></script>
|
||||
<script src="/static/js/spinner.js"></script>
|
||||
<script src="/static/js/editor.js"></script>
|
||||
<script src="/static/js/spinner.js"></script>
|
||||
<script src="/static/js/tag_autocomplete.js"></script>
|
||||
|
||||
<style>
|
||||
h2, h3
|
||||
|
@ -228,7 +229,7 @@ var add_tag_textbox = document.getElementById('add_tag_textbox');
|
|||
var add_tag_button = document.getElementById('add_tag_button');
|
||||
var message_area = document.getElementById('message_area');
|
||||
add_tag_textbox.addEventListener("keyup", common.entry_with_history_hook);
|
||||
add_tag_textbox.addEventListener("keyup", common.entry_with_tagname_replacements);
|
||||
add_tag_textbox.addEventListener("keyup", tag_autocomplete.entry_with_tagname_replacements_hook);
|
||||
common.bind_box_to_button(add_tag_textbox, add_tag_button, false);
|
||||
|
||||
function easybake_form()
|
||||
|
|
Loading…
Reference in a new issue