diff --git a/lms/static/coffee/src/discussion/tooltips.coffee b/lms/static/coffee/src/discussion/tooltips.coffee new file mode 100644 index 0000000000..d2aa6e4857 --- /dev/null +++ b/lms/static/coffee/src/discussion/tooltips.coffee @@ -0,0 +1,47 @@ +$ -> + new Tooltips + +class @Tooltips + constructor: () -> + @$body = $('body') + @$tooltip = $('
') + @$body.delegate '[data-tooltip]', + 'mouseover': @showTooltip, + 'mousemove': @moveTooltip, + 'mouseout': @hideTooltip, + 'click': @hideTooltip + + showTooltip: (e) => + tooltipText = $(e.target).attr('data-tooltip') + @$tooltip.html(tooltipText) + @$body.append(@$tooltip) + $(e.target).children().css('pointer-events', 'none') + + tooltipCoords = + x: e.pageX - (@$tooltip.outerWidth() / 2) + y: e.pageY - (@$tooltip.outerHeight() + 15) + + @$tooltip.css + 'left': tooltipCoords.x, + 'top': tooltipCoords.y + + @tooltipTimer = setTimeout ()=> + @$tooltip.show().css('opacity', 1) + + @tooltipTimer = setTimeout ()=> + @hideTooltip() + , 3000 + , 500 + + moveTooltip: (e) => + tooltipCoords = + x: e.pageX - (@$tooltip.outerWidth() / 2) + y: e.pageY - (@$tooltip.outerHeight() + 15) + + @$tooltip.css + 'left': tooltipCoords.x + 'top': tooltipCoords.y + + hideTooltip: (e) => + @$tooltip.hide().css('opacity', 0) + clearTimeout(@tooltipTimer) diff --git a/lms/static/js/tooltips.js b/lms/static/js/tooltips.js deleted file mode 100644 index 3cc771d241..0000000000 --- a/lms/static/js/tooltips.js +++ /dev/null @@ -1,56 +0,0 @@ -var $body; -var $tooltip; -var tooltipTimer; -var tooltipCoords; -$(document).ready(function() { - $body = $('body'); - $tooltip = $('
'); - $body.delegate('[data-tooltip]', { - 'mouseover': showTooltip, - 'mousemove': moveTooltip, - 'mouseout': hideTooltip, - 'click': hideTooltip - }); -}); - -function showTooltip(e) { - var tooltipText = $(this).attr('data-tooltip'); - $tooltip.html(tooltipText); - $body.append($tooltip); - $(this).children().css('pointer-events', 'none'); - - tooltipCoords = { - x: e.pageX - ($tooltip.outerWidth() / 2), - y: e.pageY - ($tooltip.outerHeight() + 15) - }; - - $tooltip.css({ - 'left': tooltipCoords.x, - 'top': tooltipCoords.y - }); - - tooltipTimer = setTimeout(function() { - $tooltip.show().css('opacity', 1); - - tooltipTimer = setTimeout(function() { - hideTooltip(); - }, 3000); - }, 500); -} - -function moveTooltip(e) { - tooltipCoords = { - x: e.pageX - ($tooltip.outerWidth() / 2), - y: e.pageY - ($tooltip.outerHeight() + 15) - }; - - $tooltip.css({ - 'left': tooltipCoords.x, - 'top': tooltipCoords.y - }); -} - -function hideTooltip(e) { - $tooltip.hide().css('opacity', 0); - clearTimeout(tooltipTimer); -} diff --git a/lms/templates/discussion/_js_head_dependencies.html b/lms/templates/discussion/_js_head_dependencies.html index c3a764439c..bde873fee1 100644 --- a/lms/templates/discussion/_js_head_dependencies.html +++ b/lms/templates/discussion/_js_head_dependencies.html @@ -12,8 +12,6 @@ - -