Cleanup, non-LuaJIT support, fix clear button

master
Lars Mueller 2020-06-23 15:11:25 +02:00
parent 9511530df8
commit e4d9add9e8
5 changed files with 15 additions and 15 deletions

View File

@ -195,7 +195,11 @@ function updateSearch() {
} }
$("#search").on("change", updateSearch); $("#search").on("change", updateSearch);
$("#search-btn").on("input", updateSearch); $("#search-btn").on("click", updateSearch);
$("#clear-btn").on("click", function() {
$("#search").val("");
updateSearch();
});
$(updateSearch); $(updateSearch);
renderItemList(searchItems()); renderItemList(searchItems());

File diff suppressed because one or more lines are too long

View File

@ -45,7 +45,7 @@
<div class="input-group my-3"> <div class="input-group my-3">
<div class="input-group-prepend"> <div class="input-group-prepend">
<button class="btn btn-outline-danger" type="button"><svg class="bi bi-x"> <button class="btn btn-outline-danger" type="button" id="clear-btn"><svg class="bi bi-x">
<!-- icon will be inserted here --></svg></button> <!-- icon will be inserted here --></svg></button>
</div> </div>
<input type="text" class="form-control" placeholder="Search" aria-label="Search" id="search"> <input type="text" class="form-control" placeholder="Search" aria-label="Search" id="search">

View File

@ -69,18 +69,17 @@ end
local handle = io.open(minetest.get_modpath("online_craftguide") .. "/docs/index.html", "w") local handle = io.open(minetest.get_modpath("online_craftguide") .. "/docs/index.html", "w")
function minetest_to_html(text) function minetest_to_html(text)
local previous_color local previous_color
text = text:gsub("<", "&lt;"):gsub("'", "&apos;"):gsub('"', "&quot;"):gsub("\x1b%((%a)@(.-)%)", function(type, args) return text:gsub("<", "&lt;"):gsub("'", "&apos;"):gsub('"', "&quot;"):gsub("\n", "<br>"):gsub("\27E", ""):gsub("\27%((%a)@(.-)%)", function(type, args)
if type == "c" and previous_color ~= args then if type == "c" and previous_color ~= args then
local retval = (previous_color and "</span>" or "") .. "<span style='color: " .. args .. " !important;'>" local retval = (previous_color and "</span>" or "") .. "<span style='color: " .. args .. " !important;'>"
previous_color = args previous_color = args
return retval return retval
end end
return "" return ""
end) :gsub("\n", "<br>"):gsub("\x1bE", "") end) .. (previous_color and "</span>" or "")
return text .. (previous_color and "</span>" or "")
end end
function minetest_to_searchable(text) function minetest_to_searchable(text)
return text:gsub("\x1b%((%a)@(.-)%)", ""):gsub("\x1bE", ""):lower() return text:gsub("\27%((%a)@(.-)%)", ""):gsub("\27E", ""):lower()
end end
function add_item(name, def) function add_item(name, def)
if (def.groups and def.groups.not_in_creative_inventory) or def.description == "" then if (def.groups and def.groups.not_in_creative_inventory) or def.description == "" then
@ -114,21 +113,19 @@ function add_item(name, def)
end end
function preprocess_html(text) function preprocess_html(text)
local regex = [[(<svg%s+class=['"]bi%sbi%-)(.-)(['"].->.-</svg>)]] local regex = [[(<svg%s+class=['"]bi%sbi%-)(.-)(['"].->.-</svg>)]]
text = text:gsub(regex, function(_, match) local replaced
return text:gsub(regex, function(_, match)
local svg = modlib.file.read(minetest.get_modpath("online_craftguide") .. "/node_modules/bootstrap-icons/icons/" .. modlib.text.split(match, "%s", 2, true)[1] .. ".svg") local svg = modlib.file.read(minetest.get_modpath("online_craftguide") .. "/node_modules/bootstrap-icons/icons/" .. modlib.text.split(match, "%s", 2, true)[1] .. ".svg")
return svg:gsub(regex, function(before, _, after) return svg:gsub(regex, function(before, _, after)
return before .. match .. after return before .. match .. after
end):gsub("\n", "") end):gsub("\n", "")
end) end):gsub([[<script%s*src=['"]online_craftguide['"]>.-</script>]], function()
local replaced
text = text:gsub([[<script%s*src=['"]online_craftguide['"]>.-</script>]], function()
if replaced then if replaced then
error("multiple script tags") error("multiple script tags")
end end
replaced = true replaced = true
return "<script>items = " .. minetest.write_json(item_defs) .. "; crafts = " .. minetest.write_json(crafts) .. "; groups = " .. minetest.write_json(groups) .. "</script>" return "<script>items = " .. minetest.write_json(item_defs) .. "; crafts = " .. minetest.write_json(crafts) .. "; groups = " .. minetest.write_json(groups) .. "</script>"
end) end)
return text
end end
minetest.register_on_mods_loaded(function() minetest.register_on_mods_loaded(function()
for name, def in pairs(minetest.registered_items) do for name, def in pairs(minetest.registered_items) do

File diff suppressed because one or more lines are too long