Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- var Tooltip,
- __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
- Tooltip = (function() {
- Tooltip.el = null;
- Tooltip.tooltip = null;
- Tooltip.open = false;
- Tooltip.closeTimer = null;
- Tooltip.topMargin = null;
- function Tooltip(el) {
- this.findPos = __bind(this.findPos, this);
- this.hide = __bind(this.hide, this);
- this.show = __bind(this.show, this);
- this.createTooltip = __bind(this.createTooltip, this);
- this.mouseOut = __bind(this.mouseOut, this);
- this.tooltipMouseOver = __bind(this.tooltipMouseOver, this);
- this.mouseOver = __bind(this.mouseOver, this);
- this.bindEvents = __bind(this.bindEvents, this); this.el = $(el);
- this.createTooltip();
- this.bindEvents();
- }
- Tooltip.prototype.bindEvents = function() {
- this.el.bind('mouseover', this.mouseOver);
- return this.el.bind('mouseout', this.mouseOut);
- };
- Tooltip.prototype.mouseOver = function() {
- if (this.open) {
- return clearTimeout(this.closeTimer);
- } else {
- return this.show();
- }
- };
- Tooltip.prototype.tooltipMouseOver = function() {
- return clearTimeout(this.closeTimer);
- };
- Tooltip.prototype.mouseOut = function() {
- return this.closeTimer = setTimeout(this.hide, 100);
- };
- Tooltip.prototype.createTooltip = function() {
- var el;
- el = $('<div></div>').attr('class', 'tooltip').append($('<i>')).append($("<span class='inner'>" + (this.el.data('tooltip')) + "</div>")).bind('mouseover', this.tooltipMouseOver).bind('mouseout', this.mouseOut);
- return this.tooltip = el;
- };
- Tooltip.prototype.show = function() {
- var pos;
- if (this.open) return;
- this.open = true;
- $('body').append(this.tooltip);
- this.topMargin = this.tooltip.css('margin-top');
- pos = this.findPos();
- this.tooltip.css('top', "" + pos.top + "px").css('left', "" + pos.left + "px");
- return this.tooltip.animate({
- opacity: 1,
- 'margin-top': '0px'
- }, 200);
- };
- Tooltip.prototype.hide = function() {
- var _this = this;
- return this.tooltip.animate({
- opacity: 0,
- 'margin-top': this.topMargin
- }, 200, function() {
- _this.tooltip.detach();
- return _this.open = false;
- });
- };
- Tooltip.prototype.findPos = function() {
- var pos;
- pos = this.el.offset();
- pos.left += this.el.width() / 2;
- pos.top -= this.tooltip.outerHeight();
- pos.left -= this.tooltip.outerWidth() / 2;
- return pos;
- };
- return Tooltip;
- })();
- jQuery.fn.extend({
- tooltip: function() {
- return this.each(function() {
- return new Tooltip(this);
- });
- }
- });
- }).call(this);
Add Comment
Please, Sign In to add comment