]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - tpl/default/js/shaarli.js
Simplify admin fields, change home icon
[github/shaarli/Shaarli.git] / tpl / default / js / shaarli.js
index 8e541998d6b59e2513f59b4ded26cde8778486de..a382a7ebe9d83cc83c28b7b925192c7022c8fcb4 100644 (file)
@@ -53,31 +53,19 @@ function getParentByClass(el, className) {
     window.addEventListener(WINDOW_CHANGE_EVENT, closeMenu);
 })(this, this.document);
 
-
 /**
- * Expend search fields on focus.
- */
-var searchInputs = document.querySelectorAll('#search input[type="text"]');
-[].forEach.call(searchInputs, function(searchInput) {
-    searchInput.addEventListener('focus', function(event) {
-        event.target.style.width = '250px';
-    });
-    searchInput.addEventListener('blur', function(event) {
-        event.target.style.width = '140px';
-    });
-});
-
-/**
- * Fold/Expand shaares description.
+ * Fold/Expand shaares description and thumbnail.
  */
 var foldButtons = document.querySelectorAll('.fold-button');
 [].forEach.call(foldButtons, function(foldButton) {
     // Retrieve description
     var description = null;
+    var thumbnail = null;
     var linklistItem = getParentByClass(foldButton, 'linklist-item');
     if (linklistItem != null) {
         description = linklistItem.querySelector('.linklist-item-description');
-        if (description != null) {
+        thumbnail = linklistItem.querySelector('.linklist-item-thumbnail');
+        if (description != null || thumbnail != null) {
             foldButton.style.display = 'inline';
         }
     }
@@ -88,11 +76,21 @@ var foldButtons = document.querySelectorAll('.fold-button');
         // Switch fold/expand - up = fold
         if (event.target.classList.contains('fa-chevron-up')) {
             event.target.title = 'Expand';
-            description.style.display = 'none';
+            if (description != null) {
+                description.style.display = 'none';
+            }
+            if (thumbnail != null) {
+                thumbnail.style.display = 'none';
+            }
         }
         else {
             event.target.title = 'Fold';
-            description.style.display = 'block';
+            if (description != null) {
+                description.style.display = 'block';
+            }
+            if (thumbnail != null) {
+                thumbnail.style.display = 'block';
+            }
         }
         event.target.classList.toggle('fa-chevron-down');
         event.target.classList.toggle('fa-chevron-up');
@@ -105,7 +103,7 @@ var foldButtons = document.querySelectorAll('.fold-button');
 var deleteLinks = document.querySelectorAll('.delete-link');
 [].forEach.call(deleteLinks, function(deleteLink) {
     deleteLink.addEventListener('click', function(event) {
-        if(!confirm('Are you sure you want to delete this link ?')) {
+        if(! confirm('Are you sure you want to delete this link ?')) {
             event.preventDefault();
         }
     });
@@ -140,16 +138,44 @@ if (newVersionDismiss != null) {
     });
 }
 
+var hiddenReturnurl = document.getElementsByName('returnurl');
+if (hiddenReturnurl != null) {
+    hiddenReturnurl.value = window.location.href;
+}
+
 /**
- * Login button
+ * Autofocus text fields
  */
-var loginButton = document.getElementById('login-button');
-loginButton.addEventListener('click', function(event) {
-    event.preventDefault();
-    var loginBlock = document.getElementById('header-login-form');
-    loginBlock.style.display = 'block';
-    loginBlock.classList.toggle('open');
-    // Focus on login field.
-    loginBlock.firstElementChild.focus();
-    document.getElementById('content').style.boxShadow = 'none';
-});
+var autofocusElements = document.querySelector('.autofocus');
+if (autofocusElements != null) {
+    autofocusElements.focus();
+}
+
+/**
+ * Handle sub menus/forms
+ */
+var openers = document.getElementsByClassName('subheader-opener');
+if (openers != null) {
+    [].forEach.call(openers, function(opener) {
+         opener.addEventListener('click', function(event) {
+             event.preventDefault();
+
+             var id = opener.getAttribute('data-open-id');
+             var sub = document.getElementById(id);
+
+             if (sub != null) {
+                [].forEach.call(document.getElementsByClassName('subheader-form'), function (element) {
+                    if (element != sub) {
+                        removeClass(element, 'open')
+                    }
+                 });
+
+                 sub.classList.toggle('open');
+             }
+         });
+    });
+}
+
+function removeClass(element, classname) {
+    element.className = element.className.replace(new RegExp('(?:^|\\s)'+ classname + '(?:\\s|$)'), ' ');
+}