From c12f77d1d1e9f6f0b52e1337336c33184272cf26 Mon Sep 17 00:00:00 2001 From: Luka Murn Date: Tue, 2 Oct 2018 11:25:51 +0200 Subject: [PATCH] Fix styling (ESLint) on tooltip_helper.js --- .../javascripts/sitewide/tooltip_helper.js | 119 ++++++++++-------- 1 file changed, 64 insertions(+), 55 deletions(-) diff --git a/app/assets/javascripts/sitewide/tooltip_helper.js b/app/assets/javascripts/sitewide/tooltip_helper.js index 37ed46a9e..ed9098512 100644 --- a/app/assets/javascripts/sitewide/tooltip_helper.js +++ b/app/assets/javascripts/sitewide/tooltip_helper.js @@ -2,10 +2,11 @@ 'use strict'; $.initTooltips = function() { - if ($(document.body).data("tooltips-enabled") === true || $(document.body).data("tooltips-enabled") == null) { - var popoversArray = []; - var leaveTimeout; - var enterTimeout; + var popoversArray = []; + var leaveTimeout; + var enterTimeout; + + if ($(document.body).data('tooltips-enabled') === true || $(document.body).data('tooltips-enabled') == null) { $('.tooltip_open').remove(); // Destroy all (if any) old open popovers $('.help_tooltips').each(function(i, obj) { var popoverObject = obj; @@ -15,61 +16,69 @@ var link = $(obj).data('tooltiplink'); var textData = $(obj).data('tooltipcontent'); - $(obj).popover({ - html: true, - container: 'body', - placement: 'auto right', - trigger: 'manual', - content: 'popovers will not display if empty', - template: '' - }).off("shown.bs.popover").on("shown.bs.popover", function() { - // hide all other popovers - popoversArray.forEach(function(arrayItem) { - if (obj !== arrayItem) { - $(arrayItem).popover("hide"); - } - }); - }).off("mouseleave").on("mouseleave", function( ) { - clearTimeout(enterTimeout); - leaveTimeout = setTimeout(function() { - if (!$(".tooltip_" + i + "_window:hover").length > 0) { - $(obj).popover("hide"); - } - }, 100); - }).off("mouseenter").on("mouseenter", function() { - clearTimeout(leaveTimeout); - enterTimeout = setTimeout(function() { - if ($(obj).hover().length > 0) { - $(obj).popover("show"); - $(".tooltip_" + i + "_window").removeClass("tooltip-enter"); - var top = $(obj).offset().top; - $('.tooltip_' + i + '_window').css({ - top: (top) + 'px' - }); - $(".tooltip_" + i + "_window").off("mouseleave").on("mouseleave", function() { - $(".tooltip_" + i + "_window").removeClass("tooltip-enter"); + $(obj) + .popover({ + html: true, + container: 'body', + placement: 'auto right', + trigger: 'manual', + content: 'popovers will not display if empty', + template: '' + }) + .off('shown.bs.popover') + .on('shown.bs.popover', function() { + // hide all other popovers + popoversArray.forEach(function(arrayItem) { + if (obj !== arrayItem) { + $(arrayItem).popover('hide'); + } + }); + }) + .off('mouseleave') + .on('mouseleave', function() { + clearTimeout(enterTimeout); + leaveTimeout = setTimeout(function() { + if (!$('.tooltip_' + i + '_window:hover').length > 0) { $(obj).popover('hide'); - }); - $(".tooltip_" + i + "_window").off("mouseenter").on("mouseenter", function() { - $(".tooltip_" + i + "_window").addClass("tooltip-enter"); - }); - } - }, 1000); - }); - }) + } + }, 100); + }) + .off('mouseenter') + .on('mouseenter', function() { + clearTimeout(leaveTimeout); + enterTimeout = setTimeout(function() { + var top; + + if ($(obj).hover().length > 0) { + $(obj).popover('show'); + $('.tooltip_' + i + '_window').removeClass('tooltip-enter'); + top = $(obj).offset().top; + $('.tooltip_' + i + '_window').css({ + top: (top) + 'px' + }); + $('.tooltip_' + i + '_window').off('mouseleave').on('mouseleave', function() { + $('.tooltip_' + i + '_window').removeClass('tooltip-enter'); + $(obj).popover('hide'); + }); + $('.tooltip_' + i + '_window').off('mouseenter').on('mouseenter', function() { + $('.tooltip_' + i + '_window').addClass('tooltip-enter'); + }); + } + }, 1000); + }); + }); } - } + }; $(document).ready(function() { $.initTooltips(); }); - }());