-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.touchTips.min.js
10 lines (10 loc) · 2.22 KB
/
jquery.touchTips.min.js
1
2
3
4
5
6
7
8
9
10
/*
cornerstoneUX.touchTips Plug-In
Version: 1.0.0
Author: Matt Zimmermann
Website & Documentation: http://influxweb.github.io/cornerstoneUX.touchTips/
Repo: https://github.com/influxweb/cornerstoneUX.touchTips
Issues: https://github.com/influxweb/cornerstoneUX.touchTips/issues
License: MIT
*/
;(function(e,b,g){b.cornerstoneUX||(b.cornerstoneUX={});b.cornerstoneUX.touchTips=function(d,f){var a=this;a.$el=b(d);a.el=d;a.$el.data("cornerstoneUX.touchTips",a);a.init=function(){a.target=!1;a.tooltip=!1;a.options=b.extend({},b.cornerstoneUX.touchTips.defaultOptions,f);a.$el.on("mouseenter",function(){a.target=b(this);tip=a.options.tip;titleSaver=a.target.attr("title");a.tooltip=b('<div id="js-touchTips" class="'+a.options.tipClass+'"></div>');if(tip&&""!==tip)tip instanceof Object&&(tip=tip.html()); else{if(null===a.target.attr("data-touchTips"))return!1;tip=0<b(a.target.attr("data-touchTips")).length?b(a.target.attr("data-touchTips")).html():a.target.attr("data-touchTips")}a.target.removeAttr("title");a.tooltip.html(tip).appendTo("body");var c=function(){b(e).width()<1.5*a.tooltip.outerWidth()?a.tooltip.css("max-width",b(e).width()/2):a.tooltip.css("max-width",a.options.maxWidth);var c=a.target.offset().left+a.target.outerWidth()/2-a.tooltip.outerWidth()/2,d=a.target.offset().top-a.tooltip.outerHeight()- 5;0>c?(c=a.target.offset().left+a.target.outerWidth()/2-20,a.tooltip.addClass("left")):a.tooltip.removeClass("left");c+a.tooltip.outerWidth()>b(e).width()?(c=a.target.offset().left-a.tooltip.outerWidth()+a.target.outerWidth()/2+20,a.tooltip.addClass("right")):a.tooltip.removeClass("right");0>d?(d=a.target.offset().top+a.target.outerHeight()+8,a.tooltip.addClass("top")):a.tooltip.removeClass("top");a.tooltip.css({top:d,left:c}).addClass("touchTips--show")};c();b(e).resize(c);c=function(){a.tooltip.removeClass("touchTips--show").delay(500).remove(); a.target.attr("title",titleSaver)};a.target.on("mouseleave",c);a.tooltip.on("click",c)})};a.init()};b.cornerstoneUX.touchTips.defaultOptions={maxWidth:360,tip:null,tipClass:"touchTips"};b.fn.touchTips=function(d){return this.each(function(){new b.cornerstoneUX.touchTips(this,d)})};b.fn.getcornerstoneUX_touchTips=function(){this.data("cornerstoneUX.touchTips")}})(window,jQuery,document);