+/** @licstart The following is the entire license notice for the
+ * JavaScript code in this page.
+ *
+ * Copyright: (c) 2011-2015 Sébastien SAUVAGE <sebsauvage@sebsauvage.net>
+ * (c) 2011-2017 The Shaarli Community, see AUTHORS
+ *
+ * This software is provided 'as-is', without any express or implied warranty.
+ * In no event will the authors be held liable for any damages arising from
+ * the use of this software.
+ *
+ * Permission is granted to anyone to use this software for any purpose,
+ * including commercial applications, and to alter it and redistribute it
+ * freely, subject to the following restrictions:
+ *
+ * 1. The origin of this software must not be misrepresented; you must not
+ * claim that you wrote the original software. If you use this software
+ * in a product, an acknowledgment in the product documentation would
+ * be appreciated but is not required.
+ *
+ * 2. Altered source versions must be plainly marked as such, and must
+ * not be misrepresented as being the original software.
+ *
+ * 3. This notice may not be removed or altered from any source distribution.
+ *
+ * @licend The above is the entire license notice
+ * for the JavaScript code in this page.
+ */
+
window.onload = function () {
/**
}
}
- document.getElementById('menu-toggle').addEventListener('click', function (e) {
- toggleMenu();
- });
+ var menuToggle = document.getElementById('menu-toggle');
+ if (menuToggle != null) {
+ menuToggle.addEventListener('click', function (e) {
+ toggleMenu();
+ });
+ }
window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu);
})(this, this.document);
/**
* Autofocus text fields
*/
- var autofocusElements = document.querySelector('.autofocus');
- if (autofocusElements != null) {
- autofocusElements.focus();
+ // ES6 syntax
+ let autofocusElements = document.querySelectorAll('.autofocus');
+ for (let autofocusElement of autofocusElements) {
+ if (autofocusElement.value == '') {
+ autofocusElement.focus();
+ break;
+ }
}
/**
* Remove CSS target padding (for fixed bar)
*/
if (location.hash != '') {
- var anchor = document.querySelector(location.hash);
+ var anchor = document.getElementById(location.hash.substr(1));
if (anchor != null) {
var padsize = anchor.clientHeight;
- console.log(document.querySelector(location.hash).clientHeight);
this.window.scroll(0, this.window.scrollY - padsize);
anchor.style.paddingTop = 0;
}
resize();
}
+
if (description != null) {
init();
+ // Submit editlink form with CTRL + Enter in the text area.
+ description.addEventListener('keydown', function (event) {
+ if (event.ctrlKey && event.keyCode === 13) {
+ document.getElementById('button-save-edit').click();
+ }
+ });
+ }
+
+ /**
+ * Awesomplete trigger.
+ */
+ var tags = document.getElementById('lf_tags');
+ if (tags != null) {
+ awesompleteUniqueTag('#lf_tags');
+ }
+
+ /**
+ * bLazy trigger
+ */
+ var picwall = document.getElementById('picwall_container');
+ if (picwall != null) {
+ var bLazy = new Blazy();
+ }
+
+ /**
+ * Bookmarklet alert
+ */
+ var bookmarkletLinks = document.querySelectorAll('.bookmarklet-link');
+ var bkmMessage = document.getElementById('bookmarklet-alert');
+ [].forEach.call(bookmarkletLinks, function(link) {
+ link.addEventListener('click', function(event) {
+ event.preventDefault();
+ alert(bkmMessage.value);
+ });
+ });
+
+ /**
+ * Firefox Social
+ */
+ var ffButton = document.getElementById('ff-social-button');
+ if (ffButton != null) {
+ ffButton.addEventListener('click', function(event) {
+ activateFirefoxSocial(event.target);
+ });
+ }
+
+ /**
+ * Plugin admin order
+ */
+ var orderPA = document.querySelectorAll('.order');
+ [].forEach.call(orderPA, function(link) {
+ link.addEventListener('click', function(event) {
+ event.preventDefault();
+ if (event.target.classList.contains('order-up')) {
+ return orderUp(event.target.parentNode.parentNode.getAttribute('data-order'));
+ } else if (event.target.classList.contains('order-down')) {
+ return orderDown(event.target.parentNode.parentNode.getAttribute('data-order'));
+ }
+ });
+ });
+
+ var continent = document.getElementById('continent');
+ var city = document.getElementById('city');
+ if (continent != null && city != null) {
+ continent.addEventListener('change', function(event) {
+ hideTimezoneCities(city, continent.options[continent.selectedIndex].value, true);
+ });
+ hideTimezoneCities(city, continent.options[continent.selectedIndex].value, false);
}
};
+
+function activateFirefoxSocial(node) {
+ var loc = location.href;
+ var baseURL = loc.substring(0, loc.lastIndexOf("/"));
+
+ // Keeping the data separated (ie. not in the DOM) so that it's maintainable and diffable.
+ var data = {
+ name: "{$shaarlititle}",
+ description: "The personal, minimalist, super-fast, database free, bookmarking service by the Shaarli community.",
+ author: "Shaarli",
+ version: "1.0.0",
+
+ iconURL: baseURL + "/images/favicon.ico",
+ icon32URL: baseURL + "/images/favicon.ico",
+ icon64URL: baseURL + "/images/favicon.ico",
+
+ shareURL: baseURL + "{noparse}?post=%{url}&title=%{title}&description=%{text}&source=firefoxsocialapi{/noparse}",
+ homepageURL: baseURL
+ };
+ node.setAttribute("data-service", JSON.stringify(data));
+
+ var activate = new CustomEvent("ActivateSocialFeature");
+ node.dispatchEvent(activate);
+}
+
+/**
+ * Add the class 'hidden' to city options not attached to the current selected continent.
+ *
+ * @param cities List of <option> elements
+ * @param currentContinent Current selected continent
+ * @param reset Set to true to reset the selected value
+ */
+function hideTimezoneCities(cities, currentContinent, reset = false) {
+ var first = true;
+ [].forEach.call(cities, function(option) {
+ if (option.getAttribute('data-continent') != currentContinent) {
+ option.className = 'hidden';
+ } else {
+ option.className = '';
+ if (reset === true && first === true) {
+ option.setAttribute('selected', 'selected');
+ first = false;
+ }
+ }
+ });
+}