aboutsummaryrefslogtreecommitdiffhomepage
path: root/tpl/default/js/shaarli.js
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-03-12 12:45:32 +0100
committerArthurHoaro <arthur@hoa.ro>2017-03-12 12:45:32 +0100
commitb9b41d25e319f44f9fb8259a0237a8ee81ad394b (patch)
tree2926d2d9c5fdf0310372efa02c11efcf0bd0d428 /tpl/default/js/shaarli.js
parent196808e14f4df44faea4d010c062c09f36095d9b (diff)
downloadShaarli-b9b41d25e319f44f9fb8259a0237a8ee81ad394b.tar.gz
Shaarli-b9b41d25e319f44f9fb8259a0237a8ee81ad394b.tar.zst
Shaarli-b9b41d25e319f44f9fb8259a0237a8ee81ad394b.zip
Remove inline JS and add LibreJS headers in JS files
Fixes #33 (wow!) Relates to #395
Diffstat (limited to 'tpl/default/js/shaarli.js')
-rw-r--r--tpl/default/js/shaarli.js130
1 files changed, 127 insertions, 3 deletions
diff --git a/tpl/default/js/shaarli.js b/tpl/default/js/shaarli.js
index f7de0a49..30d8ed6f 100644
--- a/tpl/default/js/shaarli.js
+++ b/tpl/default/js/shaarli.js
@@ -1,3 +1,31 @@
1/** @licstart The following is the entire license notice for the
2 * JavaScript code in this page.
3 *
4 * Copyright: (c) 2011-2015 Sébastien SAUVAGE <sebsauvage@sebsauvage.net>
5 * (c) 2011-2017 The Shaarli Community, see AUTHORS
6 *
7 * This software is provided 'as-is', without any express or implied warranty.
8 * In no event will the authors be held liable for any damages arising from
9 * the use of this software.
10 *
11 * Permission is granted to anyone to use this software for any purpose,
12 * including commercial applications, and to alter it and redistribute it
13 * freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not
16 * claim that you wrote the original software. If you use this software
17 * in a product, an acknowledgment in the product documentation would
18 * be appreciated but is not required.
19 *
20 * 2. Altered source versions must be plainly marked as such, and must
21 * not be misrepresented as being the original software.
22 *
23 * 3. This notice may not be removed or altered from any source distribution.
24 *
25 * @licend The above is the entire license notice
26 * for the JavaScript code in this page.
27 */
28
1window.onload = function () { 29window.onload = function () {
2 30
3 /** 31 /**
@@ -185,9 +213,13 @@ window.onload = function () {
185 /** 213 /**
186 * Autofocus text fields 214 * Autofocus text fields
187 */ 215 */
188 var autofocusElements = document.querySelector('.autofocus'); 216 // ES6 syntax
189 if (autofocusElements != null) { 217 let autofocusElements = document.querySelectorAll('.autofocus');
190 autofocusElements.focus(); 218 for (let autofocusElement of autofocusElements) {
219 if (autofocusElement.value == '') {
220 autofocusElement.focus();
221 break;
222 }
191 } 223 }
192 224
193 /** 225 /**
@@ -266,4 +298,96 @@ window.onload = function () {
266 } 298 }
267 }); 299 });
268 } 300 }
301
302 /**
303 * TimeZome select
304 * FIXME! way too hackish
305 */
306 var toRemove = document.getElementById('timezone-remove');
307 if (toRemove != null) {
308 var firstSelect = toRemove.getElementsByTagName('select')[0];
309 var secondSelect = toRemove.getElementsByTagName('select')[1];
310 toRemove.parentNode.removeChild(toRemove);
311 var toAdd = document.getElementById('timezone-add');
312 var newTimezone = '<span class="timezone-continent">Continent ' + firstSelect.outerHTML + '</span>';
313 newTimezone += ' <span class="timezone-country">Country ' + secondSelect.outerHTML + '</span>';
314 toAdd.innerHTML = newTimezone;
315 }
316
317 /**
318 * Awesomplete trigger.
319 */
320 var tags = document.getElementById('lf_tags');
321 if (tags != null) {
322 awesompleteUniqueTag('#lf_tags');
323 }
324
325 /**
326 * bLazy trigger
327 */
328 var picwall = document.getElementById('picwall_container');
329 if (picwall != null) {
330 var bLazy = new Blazy();
331 }
332
333 /**
334 * Bookmarklet alert
335 */
336 var bookmarkletLinks = document.querySelectorAll('.bookmarklet-link');
337 var bkmMessage = document.getElementById('bookmarklet-alert');
338 [].forEach.call(bookmarkletLinks, function(link) {
339 link.addEventListener('click', function(event) {
340 event.preventDefault();
341 alert(bkmMessage.value);
342 });
343 });
344
345 /**
346 * Firefox Social
347 */
348 var ffButton = document.getElementById('ff-social-button');
349 if (ffButton != null) {
350 ffButton.addEventListener('click', function(event) {
351 activateFirefoxSocial(event.target);
352 });
353 }
354
355 /**
356 * Plugin admin order
357 */
358 var orderPA = document.querySelectorAll('.order');
359 [].forEach.call(orderPA, function(link) {
360 link.addEventListener('click', function(event) {
361 event.preventDefault();
362 if (event.target.classList.contains('order-up')) {
363 return orderUp(event.target.parentNode.parentNode.getAttribute('data-order'));
364 } else if (event.target.classList.contains('order-down')) {
365 return orderDown(event.target.parentNode.parentNode.getAttribute('data-order'));
366 }
367 });
368 });
269}; 369};
370
371function activateFirefoxSocial(node) {
372 var loc = location.href;
373 var baseURL = loc.substring(0, loc.lastIndexOf("/"));
374
375 // Keeping the data separated (ie. not in the DOM) so that it's maintainable and diffable.
376 var data = {
377 name: "{$shaarlititle}",
378 description: "The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community.",
379 author: "Shaarli",
380 version: "1.0.0",
381
382 iconURL: baseURL + "/images/favicon.ico",
383 icon32URL: baseURL + "/images/favicon.ico",
384 icon64URL: baseURL + "/images/favicon.ico",
385
386 shareURL: baseURL + "{noparse}?post=%{url}&title=%{title}&description=%{text}&source=firefoxsocialapi{/noparse}",
387 homepageURL: baseURL
388 };
389 node.setAttribute("data-service", JSON.stringify(data));
390
391 var activate = new CustomEvent("ActivateSocialFeature");
392 node.dispatchEvent(activate);
393}