';
data.$target = $target;
data.$tipper = $(html);
$body.append(data.$tipper);
data.$content = data.$tipper.find(".tipper-content");
data.$caret = data.$tipper.find(".tipper-caret");
data.offset = $target.offset();
data.height = $target.outerHeight();
data.width = $target.outerWidth();
data.tipperPos = {};
data.caretPos = {};
data.contentPos = {};
var caretHeight = data.$caret.outerHeight(true),
caretWidth = data.$caret.outerWidth(true),
contentHeight = data.$content.outerHeight(true),
contentWidth = data.$content.outerWidth(true) + caretWidth;
// position content
if (data.direction === "right" || data.direction === "left") {
data.caretPos.top = (contentHeight - caretHeight) / 2;
data.contentPos.top = -contentHeight / 2;
if (data.direction === "right") {
data.contentPos.left = caretWidth + data.margin;
} else if (data.direction === "left") {
data.contentPos.left = -(contentWidth + data.margin);
}
} else {
data.caretPos.left = (contentWidth - caretWidth) / 2;
data.contentPos.left = -contentWidth / 2;
if (data.direction === "bottom") {
data.contentPos.top = data.margin;
} else if (data.direction === "top") {
data.contentPos.top = -(contentHeight + data.margin);
}
}
// modify dom
data.$content.css(data.contentPos);
data.$caret.css(data.caretPos);
// Position tipper
if (data.follow) {
data.$target.on("mousemove.tipper", data, _onMouseMove)
.trigger("mousemove");
} else {
if (data.direction === "right" || data.direction === "left") {
data.tipperPos.top = data.offset.top + (data.height / 2);
if (data.direction === "right") {
data.tipperPos.left = data.offset.left + data.width;
} else if (data.direction === "left") {
data.tipperPos.left = data.offset.left;
}
} else {
data.tipperPos.left = data.offset.left + (data.width / 2);
if (data.direction === "bottom") {
data.tipperPos.top = data.offset.top + data.height;
} else if (data.direction === "top") {
data.tipperPos.top = data.offset.top;
}
}
data.$tipper.css(data.tipperPos);
}
// Bind events
data.$target.one("mouseleave.tipper", data, _onMouseOut);
}
/**
* @method private
* @name _format
* @description Formats tooltip text
* @param $target [jQuery object] "Target element"
* @return [string] "Formatted text"
*/
function _format($target) {
return $target.data("title");
}
/**
* @method private
* @name _onMouseMove
* @description Handles mousemove event
* @param e [object] "Event data"
*/
function _onMouseMove(e) {
var data = e.data;
data.$tipper.css({ left: e.pageX, top: e.pageY });
}
/**
* @method private
* @name _onMouseOut
* @description Handles mouseout event
* @param e [object] "Event data"
*/
function _onMouseOut(e) {
var data = e.data;
data.$tipper.remove();
data.$target.off("mousemove.tipper mouseleave.tipper");
}
$.fn.tipper = function (method) {
if (pub[method]) {
return pub[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return _init.apply(this, arguments);
}
return this;
};
$.tipper = function (method) {
if (method === "defaults") {
pub.defaults.apply(this, Array.prototype.slice.call(arguments, 1));
}
};
})(jQuery);