Tags separator: vintage theme compatibility
This commit is contained in:
parent
67339338af
commit
df9aac5b64
5 changed files with 35 additions and 26 deletions
|
@ -217,7 +217,7 @@ function init(description) {
|
|||
(() => {
|
||||
const basePath = document.querySelector('input[name="js_base_path"]').value;
|
||||
const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]');
|
||||
const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || '\s' : '\s';
|
||||
const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || ' ' : ' ';
|
||||
|
||||
/**
|
||||
* Handle responsive menu.
|
||||
|
|
|
@ -2,29 +2,36 @@ import Awesomplete from 'awesomplete';
|
|||
import 'awesomplete/awesomplete.css';
|
||||
|
||||
(() => {
|
||||
const awp = Awesomplete.$;
|
||||
const autocompleteFields = document.querySelectorAll('input[data-multiple]');
|
||||
[...autocompleteFields].forEach((autocompleteField) => {
|
||||
const awesomplete = new Awesomplete(awp(autocompleteField));
|
||||
awesomplete.filter = (text, input) => Awesomplete.FILTER_CONTAINS(text, input.match(/[^ ]*$/)[0]);
|
||||
awesomplete.replace = (text) => {
|
||||
const before = awesomplete.input.value.match(/^.+ \s*|/)[0];
|
||||
awesomplete.input.value = `${before}${text} `;
|
||||
};
|
||||
awesomplete.minChars = 1;
|
||||
const tagsSeparatorElement = document.querySelector('input[name="tags_separator"]');
|
||||
const tagsSeparator = tagsSeparatorElement ? tagsSeparatorElement.value || " " : " ";
|
||||
|
||||
autocompleteField.addEventListener('input', () => {
|
||||
const proposedTags = autocompleteField.getAttribute('data-list').replace(/,/g, '').split(' ');
|
||||
const reg = /(\w+) /g;
|
||||
let match;
|
||||
while ((match = reg.exec(autocompleteField.value)) !== null) {
|
||||
const id = proposedTags.indexOf(match[1]);
|
||||
if (id !== -1) {
|
||||
proposedTags.splice(id, 1);
|
||||
[...autocompleteFields].forEach((autocompleteField) => {
|
||||
const awesome = new Awesomplete(Awesomplete.$(autocompleteField));
|
||||
|
||||
// Tags are separated by separator
|
||||
awesome.filter = (text, input) => Awesomplete.FILTER_CONTAINS(
|
||||
text,
|
||||
input.match(new RegExp(`[^${tagsSeparator}]*$`))[0])
|
||||
;
|
||||
// Insert new selected tag in the input
|
||||
awesome.replace = (text) => {
|
||||
const before = awesome.input.value.match(new RegExp(`^.+${tagsSeparator}+|`))[0];
|
||||
awesome.input.value = `${before}${text}${tagsSeparator}`;
|
||||
};
|
||||
// Highlight found items
|
||||
awesome.item = (text, input) => Awesomplete.ITEM(text, input.match(new RegExp(`[^${tagsSeparator}]*$`))[0]);
|
||||
// Don't display already selected items
|
||||
const reg = new RegExp(`/(\w+)${tagsSeparator}/g`);
|
||||
let match;
|
||||
awesome.data = (item, input) => {
|
||||
while ((match = reg.exec(input))) {
|
||||
if (item === match[1]) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
awesomplete.list = proposedTags;
|
||||
});
|
||||
return item;
|
||||
};
|
||||
awesome.minChars = 1;
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -5,13 +5,13 @@
|
|||
<meta name="referrer" content="same-origin">
|
||||
<link rel="alternate" type="application/rss+xml" href="{$feedurl}feed/rss?{$searchcrits}#" title="RSS Feed" />
|
||||
<link rel="alternate" type="application/atom+xml" href="{$feedurl}feed/atom?{$searchcrits}#" title="ATOM Feed" />
|
||||
<link href="img/favicon.ico" rel="shortcut icon" type="image/x-icon" />
|
||||
<link href="{$asset_path}/img/favicon.ico#" rel="shortcut icon" type="image/x-icon" />
|
||||
<link type="text/css" rel="stylesheet" href="{$asset_path}/css/shaarli.min.css#" />
|
||||
{if="$formatter==='markdown'"}
|
||||
<link type="text/css" rel="stylesheet" href="{$asset_path}/css/markdown.min.css?v={$version_hash}#" />
|
||||
{/if}
|
||||
{loop="$plugins_includes.css_files"}
|
||||
<link type="text/css" rel="stylesheet" href="{$base_path}/{$value}#"/>
|
||||
<link type="text/css" rel="stylesheet" href="{$root_path}/{$value}#"/>
|
||||
{/loop}
|
||||
{if="is_file('data/user.css')"}<link type="text/css" rel="stylesheet" href="{$base_path}/data/user.css#" />{/if}
|
||||
<link rel="search" type="application/opensearchdescription+xml" href="{$base_path}/open-search#"
|
||||
|
|
|
@ -61,7 +61,7 @@
|
|||
for <em>{$search_term}</em>
|
||||
{/if}
|
||||
{if="!empty($search_tags)"}
|
||||
{$exploded_tags=explode(' ', $search_tags)}
|
||||
{$exploded_tags=tags_str2array($search_tags, $tags_separator)}
|
||||
tagged
|
||||
{loop="$exploded_tags"}
|
||||
<span class="linktag" title="Remove tag">
|
||||
|
|
|
@ -23,8 +23,6 @@
|
|||
</div>
|
||||
{/if}
|
||||
|
||||
<script src="{$asset_path}/js/shaarli.min.js#"></script>
|
||||
|
||||
{if="$is_logged_in"}
|
||||
<script>function confirmDeleteLink() { var agree=confirm("Are you sure you want to delete this link ?"); if (agree) return true ; else return false ; }</script>
|
||||
{/if}
|
||||
|
@ -34,3 +32,7 @@
|
|||
{/loop}
|
||||
|
||||
<input type="hidden" name="js_base_path" value="{$base_path}" />
|
||||
<input type="hidden" name="token" value="{$token}" id="token" />
|
||||
<input type="hidden" name="tags_separator" value="{$tags_separator}" id="tags_separator" />
|
||||
|
||||
<script src="{$asset_path}/js/shaarli.min.js#"></script>
|
||||
|
|
Loading…
Reference in a new issue