From 5893529cf429f859485bccc88eff47f77fdd770a Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 25 Mar 2017 15:57:30 +0100 Subject: Move tagcloud template file to tag.cloud --- tpl/default/tag.cloud.html | 64 ++++++++++++++++++++++++++++++++++++++++++++++ tpl/default/tagcloud.html | 60 ------------------------------------------- 2 files changed, 64 insertions(+), 60 deletions(-) create mode 100644 tpl/default/tag.cloud.html delete mode 100644 tpl/default/tagcloud.html (limited to 'tpl/default') diff --git a/tpl/default/tag.cloud.html b/tpl/default/tag.cloud.html new file mode 100644 index 00000000..59aa2ee0 --- /dev/null +++ b/tpl/default/tag.cloud.html @@ -0,0 +1,64 @@ + + + + {include="includes"} + + +{include="page.header"} + +{include="tag.sort"} + +
+
+
+ {$countTags=count($tags)} +

{'Tag cloud'|t} - {$countTags} {'tags'|t}

+ +
+
+
+
+ + + +
+
+
+
+ +
+ {loop="$plugin_start_zone"} + {$value} + {/loop} +
+ +
+ {loop="tags"} + {$key}{$value.count} + {loop="$value.tag_plugin"} + {$value} + {/loop} + {/loop} +
+ +
+ {loop="$plugin_end_zone"} + {$value} + {/loop} +
+
+
+ +{include="tag.sort"} + +{include="page.footer"} + + + diff --git a/tpl/default/tagcloud.html b/tpl/default/tagcloud.html deleted file mode 100644 index efe6e937..00000000 --- a/tpl/default/tagcloud.html +++ /dev/null @@ -1,60 +0,0 @@ - - - - {include="includes"} - - -{include="page.header"} - -
-
-
- {$countTags=count($tags)} -

{'Tag cloud'|t} - {$countTags} {'tags'|t}

- -
-
-
-
- - - -
-
-
-
- -
- {loop="$plugin_start_zone"} - {$value} - {/loop} -
- -
- {loop="tags"} - {$key}{$value.count} - {loop="$value.tag_plugin"} - {$value} - {/loop} - {/loop} -
- -
- {loop="$plugin_end_zone"} - {$value} - {/loop} -
-
-
- -{include="page.footer"} - - - -- cgit v1.2.3 From bc988eb0420156219fdeb7af684fff37c8b33f4b Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 25 Mar 2017 15:58:30 +0100 Subject: Add a token available everywhere --- tpl/default/page.footer.html | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tpl/default') diff --git a/tpl/default/page.footer.html b/tpl/default/page.footer.html index 77fc65dd..02fc7642 100644 --- a/tpl/default/page.footer.html +++ b/tpl/default/page.footer.html @@ -16,6 +16,9 @@
+ + + {loop="$plugins_footer.endofpage"} {$value} {/loop} -- cgit v1.2.3 From aa4797ba3679b847adc895e2f817ac058779a171 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 25 Mar 2017 15:59:01 +0100 Subject: Adds a taglist view with edit/delete buttons * The tag list can be sort alphabetically or by most used tag * Edit/Delete are perform using AJAX, or fallback to 'do=changetag' page * New features aren't backported to vintage theme --- tpl/default/changetag.html | 4 +- tpl/default/css/shaarli.css | 50 +++++++++++++++- tpl/default/js/shaarli.js | 136 +++++++++++++++++++++++++++++++++++++++++++- tpl/default/tag.list.html | 82 ++++++++++++++++++++++++++ tpl/default/tag.sort.html | 8 +++ 5 files changed, 276 insertions(+), 4 deletions(-) create mode 100644 tpl/default/tag.list.html create mode 100644 tpl/default/tag.sort.html (limited to 'tpl/default') diff --git a/tpl/default/changetag.html b/tpl/default/changetag.html index 8d263a16..49dd20d9 100644 --- a/tpl/default/changetag.html +++ b/tpl/default/changetag.html @@ -11,7 +11,7 @@

{"Manage tags"|t}

- {loop="$tags"}{/loop} @@ -31,6 +31,8 @@
+ +

You can also edit tags in the tag list.

{include="page.footer"} diff --git a/tpl/default/css/shaarli.css b/tpl/default/css/shaarli.css index 4415a1b7..2eda5df4 100644 --- a/tpl/default/css/shaarli.css +++ b/tpl/default/css/shaarli.css @@ -751,10 +751,11 @@ body, .pure-g [class*="pure-u"] { .page-form a { color: #1b926c; font-weight: bold; + text-decoration: none; } .page-form p { - padding: 0 10px; + padding: 5px 10px; margin: 0; } @@ -1070,7 +1071,7 @@ form[name="linkform"].page-form { } #cloudtag, #cloudtag a { - color: #000; + color: #252525; text-decoration: none; } @@ -1078,6 +1079,38 @@ form[name="linkform"].page-form { color: #7f7f7f; } +/** + * TAG LIST + */ +#taglist { + padding: 0 10px; +} + +#taglist a { + color: #252525; + text-decoration: none; +} + +#taglist .count { + display: inline-block; + width: 35px; + text-align: right; + color: #7f7f7f; +} + +#taglist .delete-tag { + color: #ac2925; + display: none; +} + +#taglist .rename-tag { + color: #0b5ea6; +} + +#taglist .validate-rename-tag { + color: #1b926c; +} + /** * Picture wall CSS */ @@ -1227,3 +1260,16 @@ form[name="linkform"].page-form { .pure-button { -moz-user-select: auto; } + +.tag-sort { + margin-top: 30px; + text-align: center; +} + +.tag-sort a { + display: inline-block; + margin: 0 15px; + color: white; + text-decoration: none; + font-weight: bold; +} diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js index ceb1d1b8..e19e9001 100644 --- a/tpl/default/js/shaarli.js +++ b/tpl/default/js/shaarli.js @@ -412,8 +412,139 @@ window.onload = function () { } }); } + + /** + * Tag list operations + * + * TODO: support error code in the backend for AJAX requests + */ + // Display/Hide rename form + var renameTagButtons = document.querySelectorAll('.rename-tag'); + [].forEach.call(renameTagButtons, function(rename) { + rename.addEventListener('click', function(event) { + event.preventDefault(); + var block = findParent(event.target, 'div', {'class': 'tag-list-item'}); + var form = block.querySelector('.rename-tag-form'); + form.style.display = form.style.display == 'none' ? 'block' : 'none'; + }); + }); + + // Rename a tag with an AJAX request + var renameTagSubmits = document.querySelectorAll('.validate-rename-tag'); + [].forEach.call(renameTagSubmits, function(rename) { + rename.addEventListener('click', function(event) { + event.preventDefault(); + var block = findParent(event.target, 'div', {'class': 'tag-list-item'}); + var input = block.querySelector('.rename-tag-input'); + var totag = input.value.replace('/"/g', '\\"'); + if (totag.trim() == '') { + return; + } + var fromtag = block.getAttribute('data-tag'); + var token = document.getElementById('token').value; + + xhr = new XMLHttpRequest(); + xhr.open('POST', '?do=changetag'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onload = function() { + if (xhr.status !== 200) { + alert('An error occurred. Return code: '+ xhr.status); + location.reload(); + } else { + block.setAttribute('data-tag', totag); + input.setAttribute('name', totag); + input.setAttribute('value', totag); + input.parentNode.style.display = 'none'; + block.querySelector('a.tag-link').innerHTML = htmlEntities(totag); + block.querySelector('a.tag-link').setAttribute('href', '?searchtags='+ encodeURIComponent(totag)); + block.querySelector('a.rename-tag').setAttribute('href', '?do=changetag&fromtag='+ encodeURIComponent(totag)); + } + }; + xhr.send('renametag=1&fromtag='+ encodeURIComponent(fromtag) +'&totag='+ encodeURIComponent(totag) +'&token='+ token); + refreshToken(); + }); + }); + + // Validate input with enter key + var renameTagInputs = document.querySelectorAll('.rename-tag-input'); + [].forEach.call(renameTagInputs, function(rename) { + rename.addEventListener('keypress', function(event) { + if (event.keyCode === 13) { // enter + findParent(event.target, 'div', {'class': 'tag-list-item'}).querySelector('.validate-rename-tag').click(); + } + }); + }); + + // Delete a tag with an AJAX query (alert popup confirmation) + var deleteTagButtons = document.querySelectorAll('.delete-tag'); + [].forEach.call(deleteTagButtons, function(rename) { + rename.style.display = 'inline'; + rename.addEventListener('click', function(event) { + event.preventDefault(); + var block = findParent(event.target, 'div', {'class': 'tag-list-item'}); + var tag = block.getAttribute('data-tag'); + var token = document.getElementById('token').value; + + if (confirm('Are you sure you want to delete the tag "'+ tag +'"?')) { + xhr = new XMLHttpRequest(); + xhr.open('POST', '?do=changetag'); + xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + xhr.onload = function() { + block.remove(); + }; + xhr.send(encodeURI('deletetag=1&fromtag='+ tag +'&token='+ token)); + refreshToken(); + } + }); + }); }; +function findParent(element, tagName, attributes) +{ + while (element) { + if (element.tagName.toLowerCase() == tagName) { + var match = true; + for (var key in attributes) { + if (! element.hasAttribute(key) + || (attributes[key] != '' && element.getAttribute(key).indexOf(attributes[key]) == -1) + ) { + match = false; + break; + } + } + + if (match) { + return element; + } + } + element = element.parentElement; + } + return null; +} + +function refreshToken() +{ + var xhr = new XMLHttpRequest(); + xhr.open('GET', '?do=token'); + xhr.onload = function() { + var token = document.getElementById('token'); + token.setAttribute('value', xhr.responseText); + }; + xhr.send(); +} + +/** + * html_entities in JS + * + * @see http://stackoverflow.com/questions/18749591/encode-html-entities-in-javascript + */ +function htmlEntities(str) +{ + return str.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { + return '&#'+i.charCodeAt(0)+';'; + }); +} + function activateFirefoxSocial(node) { var loc = location.href; var baseURL = loc.substring(0, loc.lastIndexOf("/")); @@ -445,8 +576,11 @@ function activateFirefoxSocial(node) { * @param currentContinent Current selected continent * @param reset Set to true to reset the selected value */ -function hideTimezoneCities(cities, currentContinent, reset = false) { +function hideTimezoneCities(cities, currentContinent) { var first = true; + if (reset == null) { + reset = false; + } [].forEach.call(cities, function (option) { if (option.getAttribute('data-continent') != currentContinent) { option.className = 'hidden'; diff --git a/tpl/default/tag.list.html b/tpl/default/tag.list.html new file mode 100644 index 00000000..98971051 --- /dev/null +++ b/tpl/default/tag.list.html @@ -0,0 +1,82 @@ + + + + {include="includes"} + + +{include="page.header"} + +{include="tag.sort"} + +
+
+
+ {$countTags=count($tags)} +

{'Tag list'|t} - {$countTags} {'tags'|t}

+ +
+
+
+
+ + + +
+
+
+
+ +
+ {loop="$plugin_start_zone"} + {$value} + {/loop} +
+ +
+ {loop="tags"} +
+
+ {if="isLoggedIn()===true"} +    + + + + {/if} + + {$value} + {$key} + + {loop="$value.tag_plugin"} + {$value} + {/loop} +
+ {if="isLoggedIn()===true"} + + {/if} +
+ {/loop} +
+ +
+ {loop="$plugin_end_zone"} + {$value} + {/loop} +
+
+
+ +{include="tag.sort"} + +{include="page.footer"} + + + diff --git a/tpl/default/tag.sort.html b/tpl/default/tag.sort.html new file mode 100644 index 00000000..89acda0d --- /dev/null +++ b/tpl/default/tag.sort.html @@ -0,0 +1,8 @@ +
+
+ {'Sort by:'|t} + {'Cloud'|t} · + {'Most used'|t} · + {'Alphabetical'|t} +
+
\ No newline at end of file -- cgit v1.2.3 From 82e3bb5f06dc531ee1080a0313833791a1c1f3c7 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 28 Mar 2017 20:11:07 +0200 Subject: Tag list: use awesomplete for tag auto completion --- tpl/default/css/shaarli.css | 4 +++ tpl/default/js/shaarli.js | 62 +++++++++++++++++++++++++++++++++++++++++++-- tpl/default/tag.list.html | 6 ++++- 3 files changed, 69 insertions(+), 3 deletions(-) (limited to 'tpl/default') diff --git a/tpl/default/css/shaarli.css b/tpl/default/css/shaarli.css index 2eda5df4..28920648 100644 --- a/tpl/default/css/shaarli.css +++ b/tpl/default/css/shaarli.css @@ -1098,6 +1098,10 @@ form[name="linkform"].page-form { color: #7f7f7f; } +#taglist .rename-tag-form { + display: none; +} + #taglist .delete-tag { color: #ac2925; display: none; diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js index e19e9001..4ebb7815 100644 --- a/tpl/default/js/shaarli.js +++ b/tpl/default/js/shaarli.js @@ -418,6 +418,9 @@ window.onload = function () { * * TODO: support error code in the backend for AJAX requests */ + var existingTags = document.querySelector('input[name="taglist"]').value.split(' '); + var awesomepletes = []; + // Display/Hide rename form var renameTagButtons = document.querySelectorAll('.rename-tag'); [].forEach.call(renameTagButtons, function(rename) { @@ -425,7 +428,12 @@ window.onload = function () { event.preventDefault(); var block = findParent(event.target, 'div', {'class': 'tag-list-item'}); var form = block.querySelector('.rename-tag-form'); - form.style.display = form.style.display == 'none' ? 'block' : 'none'; + if (form.style.display == 'none' || form.style.display == '') { + form.style.display = 'block'; + } else { + form.style.display = 'none'; + } + block.querySelector('input').focus(); }); }); @@ -454,10 +462,18 @@ window.onload = function () { block.setAttribute('data-tag', totag); input.setAttribute('name', totag); input.setAttribute('value', totag); - input.parentNode.style.display = 'none'; + findParent(input, 'div', {'class': 'rename-tag-form'}).style.display = 'none'; block.querySelector('a.tag-link').innerHTML = htmlEntities(totag); block.querySelector('a.tag-link').setAttribute('href', '?searchtags='+ encodeURIComponent(totag)); block.querySelector('a.rename-tag').setAttribute('href', '?do=changetag&fromtag='+ encodeURIComponent(totag)); + + // Refresh awesomplete values + for (var key in existingTags) { + if (existingTags[key] == fromtag) { + existingTags[key] = totag; + } + } + awesomepletes = updateAwesompleteList('.rename-tag-input', existingTags, awesomepletes); } }; xhr.send('renametag=1&fromtag='+ encodeURIComponent(fromtag) +'&totag='+ encodeURIComponent(totag) +'&token='+ token); @@ -468,6 +484,7 @@ window.onload = function () { // Validate input with enter key var renameTagInputs = document.querySelectorAll('.rename-tag-input'); [].forEach.call(renameTagInputs, function(rename) { + rename.addEventListener('keypress', function(event) { if (event.keyCode === 13) { // enter findParent(event.target, 'div', {'class': 'tag-list-item'}).querySelector('.validate-rename-tag').click(); @@ -497,8 +514,19 @@ window.onload = function () { } }); }); + + updateAwesompleteList('.rename-tag-input', document.querySelector('input[name="taglist"]').value.split(' '), awesomepletes); }; +/** + * Find a parent element according to its tag and its attributes + * + * @param element Element where to start the search + * @param tagName Expected parent tag name + * @param attributes Associative array of expected attributes (name=>value). + * + * @returns Found element or null. + */ function findParent(element, tagName, attributes) { while (element) { @@ -522,6 +550,9 @@ function findParent(element, tagName, attributes) return null; } +/** + * Ajax request to refresh the CSRF token. + */ function refreshToken() { var xhr = new XMLHttpRequest(); @@ -533,6 +564,33 @@ function refreshToken() xhr.send(); } +/** + * Update awesomplete list of tag for all elements matching the given selector + * + * @param selector CSS selector + * @param tags Array of tags + * @param instances List of existing awesomplete instances + */ +function updateAwesompleteList(selector, tags, instances) +{ + // First load: create Awesomplete instances + if (instances.length == 0) { + var elements = document.querySelectorAll(selector); + [].forEach.call(elements, function (element) { + instances.push(new Awesomplete( + element, + {'list': tags} + )); + }); + } else { + // Update awesomplete tag list + for (var key in instances) { + instances[key].list = tags; + } + } + return instances; +} + /** * html_entities in JS * diff --git a/tpl/default/tag.list.html b/tpl/default/tag.list.html index 98971051..62e2e7c6 100644 --- a/tpl/default/tag.list.html +++ b/tpl/default/tag.list.html @@ -57,7 +57,7 @@ {/loop} {if="isLoggedIn()===true"} - +{if="isLoggedIn()===true"} +