]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frio/js/theme.js
Merge pull request #9039 from MrPetovan/task/frio-accent-scheme
[friendica.git] / view / theme / frio / js / theme.js
index 2ab11e637ba8284843476b1f2f6d5a094427c96e..b7f222c0a25e6d3c21a077f022b0ee44e002d038 100644 (file)
@@ -3,11 +3,21 @@ var jotcache = ''; //The jot cache. We use it as cache to restore old/original j
 
 $(document).ready(function(){
        //fade in/out based on scrollTop value
+       var scrollStart;
+
        $(window).scroll(function () {
-               if ($(this).scrollTop() > 1000) {
-                       $("#back-to-top").fadeIn();
-               } else {
+               let currentScroll = $(this).scrollTop();
+
+               // Top of the page or going down = hide the button
+               if (!scrollStart || !currentScroll || currentScroll > scrollStart) {
                        $("#back-to-top").fadeOut();
+                       scrollStart = currentScroll;
+               }
+
+               // Going up enough = show the button
+               if (scrollStart - currentScroll > 100) {
+                       $("#back-to-top").fadeIn();
+                       scrollStart = currentScroll;
                }
        });
 
@@ -63,29 +73,23 @@ $(document).ready(function(){
                'target': ".flex-target"
        });
 
-       // add Jot botton to the scecond navbar
+       // add Jot button to the second navbar
        let $jotButton = $("#jotOpen");
-       let $composeButton = $("#composeOpen");
-       if (compose) {
-               $jotButton.hide();
-               if ($composeButton.length) {
-                       $composeButton.appendTo("#topbar-second > .container > #navbar-button");
-                       if($("#jot-popup").is(":hidden")) {
-                               $composeButton.hide();
-                       }
-               }
-       } else {
-               $composeButton.hide();
-               if ($jotButton.length) {
-                       $jotButton.appendTo("#topbar-second > .container > #navbar-button");
-                       if($("#jot-popup").is(":hidden")) {
-                               $jotButton.hide();
-                       }
+       if ($jotButton.length) {
+               $jotButton.appendTo("#topbar-second > .container > #navbar-button");
+               if ($("#jot-popup").is(":hidden")) {
+                       $jotButton.hide();
                }
+               $jotButton.on('click', function (e) {
+                       e.preventDefault();
+                       jotShow();
+               });
        }
 
+       let $body = $('body');
+
        // show bulk deletion button at network page if checkbox is checked
-       $("body").change("input.item-select", function(){
+       $body.change("input.item-select", function(){
                var checked = false;
 
                // We need to get all checked items, so it would close the delete button
@@ -108,10 +112,8 @@ $(document).ready(function(){
                }
        });
 
-       //$('ul.flex-nav').flexMenu();
-
        // initialize the bootstrap tooltips
-       $('body').tooltip({
+       $body.tooltip({
                selector: '[data-toggle="tooltip"]',
                container: 'body',
                animation: true,
@@ -169,7 +171,7 @@ $(document).ready(function(){
        }
 
        // move the "Save the search" button to the second navbar
-       $(".search-content-wrapper #search-save-form ").appendTo("#topbar-second > .container > #navbar-button");
+       $(".search-content-wrapper #search-save").appendTo("#topbar-second > .container > #navbar-button");
 
        // append the vcard-short-info to the second nav after passing the element
        // with .fn (vcard username). Use scrollspy to get the scroll position.
@@ -226,28 +228,10 @@ $(document).ready(function(){
 
        // Dropdown menus with the class "dropdown-head" will display the active tab
        // as button text
-       $("body").on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
+       $body.on('click', '.dropdown-head .dropdown-menu li a, .dropdown-head .dropdown-menu li button', function(){
                toggleDropdownText(this);
        });
 
-       /* setup onoff widgets */
-       // Add the correct class to the switcher according to the input
-       // value (On/Off)
-       $(".toggle input").each(function(){
-               // Get the value of the input element
-               val = $(this).val();
-               id = $(this).attr("id");
-
-               // The css classes for "on" and "off"
-               onstyle = "btn-primary";
-               offstyle = "btn-default off";
-
-               // Add the correct class in dependence of input value (On/Off)
-               toggleclass = (val == 0 ? offstyle : onstyle);
-               $("#"+id+"_onoff").addClass(toggleclass);
-
-       });
-
        // Change the css class while clicking on the switcher elements
        $(".toggle label, .toggle .toggle-handle").click(function(event){
                event.preventDefault();
@@ -278,7 +262,7 @@ $(document).ready(function(){
        // to the input element where the padding value would be at least the width
        // of the button. Otherwise long user input would be invisible because it is
        // behind the button.
-       $("body").on('click', '.form-group-search > input', function() {
+       $body.on('click', '.form-group-search > input', function() {
                // Get the width of the button (if the button isn't available
                // buttonWidth will be null
                var buttonWidth = $(this).next('.form-button-search').outerWidth();
@@ -365,17 +349,83 @@ $(document).ready(function(){
         */
        $("aside")
                .on("shown.bs.offcanvas", function() {
-                       $("body").addClass("aside-out");
+                       $body.addClass("aside-out");
                })
                .on("hidden.bs.offcanvas", function() {
-                       $("body").removeClass("aside-out");
+                       $body.removeClass("aside-out");
                });
 
        // Event listener for 'Show & hide event map' button in the network stream.
-       $("body").on("click", ".event-map-btn", function() {
+       $body.on("click", ".event-map-btn", function() {
                showHideEventMap(this);
        });
 
+       // Comment form submit
+       $body.on('submit', '.comment-edit-form', function(e) {
+               let $form = $(this);
+               let id = $form.data('item-id');
+
+               // Compose page form exception: id is always 0 and form must not be submitted asynchronously
+               if (id === 0) {
+                       return;
+               }
+
+               e.preventDefault();
+
+               let $commentSubmit = $form.find('.comment-edit-submit').button('loading');
+
+               unpause();
+               commentBusy = true;
+
+               $.post(
+                       'item',
+                       $form.serialize(),
+                       'json'
+               )
+               .then(function(data) {
+                       if (data.success) {
+                               $('#comment-edit-wrapper-' + id).hide();
+                               let $textarea = $('#comment-edit-text-' + id);
+                               $textarea.val('');
+                               if ($textarea.get(0)) {
+                                       commentClose($textarea.get(0), id);
+                               }
+                               if (timer) {
+                                       clearTimeout(timer);
+                               }
+                               timer = setTimeout(NavUpdate,10);
+                               force_update = true;
+                               update_item = id;
+                       }
+                       if (data.reload) {
+                               window.location.href = data.reload;
+                       }
+               })
+               .always(function() {
+                       $commentSubmit.button('reset');
+               });
+       });
+
+       $body.on('submit', '.modal-body #poke-wrapper', function(e) {
+               e.preventDefault();
+
+               let $form = $(this);
+               let $pokeSubmit = $form.find('button[type=submit]').button('loading');
+
+               $.post(
+                       $form.attr('action'),
+                       $form.serialize(),
+                       'json'
+               )
+               .then(function(data) {
+                       if (data.success) {
+                               $('#modal').modal('hide');
+                       }
+               })
+               .always(function() {
+                       $pokeSubmit.button('reset');
+               });
+       })
 });
 
 function openClose(theID) {
@@ -650,9 +700,9 @@ function scrollToItem(elementId) {
        // Scroll to the DIV with the ID (GUID)
        $('html, body').animate({
                scrollTop: itemPos
-       }, 400, function() {
+       }, 400).promise().done( function() {
                // Highlight post/commenent with ID  (GUID)
-               $el.animate(colWhite, 1000).animate(colShiny).animate(colWhite, 600);
+               $el.animate(colWhite, 1000).animate(colShiny).animate({backgroundColor: 'transparent'}, 600);
        });
 }
 
@@ -670,22 +720,17 @@ function htmlToText(htmlString) {
  * Sends a /like API call and updates the display of the relevant action button
  * before the update reloads the item.
  *
- * @param {string} ident The id of the relevant item
- * @param {string} verb The verb of the action
- * @returns {undefined}
+ * @param {int}     ident The id of the relevant item
+ * @param {string}  verb  The verb of the action
+ * @param {boolean} un    Whether to perform an activity removal instead of creation
  */
-function doLikeAction(ident, verb) {
-       unpause();
-
+function doLikeAction(ident, verb, un) {
        if (verb.indexOf('attend') === 0) {
                $('.item-' + ident + ' .button-event:not(#' + verb + '-' + ident + ')').removeClass('active');
        }
        $('#' + verb + '-' + ident).toggleClass('active');
-       $('#like-rotator-' + ident.toString()).show();
-       $.get('like/' + ident.toString() + '?verb=' + verb, NavUpdate );
-       liking = 1;
-       force_update = true;
-       update_item = ident.toString();
+
+       dolike(ident, verb, un);
 }
 
 // Decodes a hexadecimally encoded binary string