Permalink
Browse files

initial import

  • Loading branch information...
0 parents commit 13751bcde9fd77805f02e19837add273beaf6495 @enriquez committed Mar 17, 2009
Showing with 202 additions and 0 deletions.
  1. +23 −0 LICENSE
  2. +7 −0 README.textile
  3. +172 −0 jquery.tooltip.js
23 LICENSE
@@ -0,0 +1,23 @@
+The MIT License
+
+EZPZ Tooltip v0.9
+
+Copyright (c) 2009 Mike Enriquez, http://theezpzway.com
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
@@ -0,0 +1,7 @@
+h1. EZPZ Tooltip
+
+There are a "ton of tooltip plugins":http://www.google.com/search?q=jquery+tooltip for jQuery out there, but I couldn’t find one that works with the way I think. To me, it’s a simple concept: You hover over a target element, then some content shows up. It should be flexible enough to customize the look and feel without requiring the bloat of any CSS or images. Hover targets should be mapped to their content counterparts by convention. I think I’ve built just that with the EZPZ Tooltip.
+
+Check out "the demo here":http://theezpzway.com/2009/3/16/ezpz-tooltip-demo.
+
+Check out "the documentation here":http://theezpzway.com/2009/3/16/jquery-plugin-ezpz-tooltip.
@@ -0,0 +1,172 @@
+// EZPZ Tooltip v0.9; Copyright (c) 2009 Mike Enriquez, http://theezpzway.com; Released under the MIT License
+(function($){
+ $.fn.ezpz_tooltip = function(options){
+ var settings = $.extend({}, $.fn.ezpz_tooltip.defaults, options);
+
+ return this.each(function(){
+ var content = $("#" + getContentId(this.id));
+ var targetMousedOver = $(this).mouseover(function(){
+ settings.beforeShow(content, $(this));
+ }).mousemove(function(e){
+ contentInfo = getElementDimensionsAndPosition(content);
+ targetInfo = getElementDimensionsAndPosition($(this));
+ contentInfo = $.fn.ezpz_tooltip.positions[settings.contentPosition](contentInfo, e.pageX, e.pageY, settings.offset, targetInfo);
+ contentInfo = keepInWindow(contentInfo);
+
+ content.css('top', contentInfo['top']);
+ content.css('left', contentInfo['left']);
+
+ $.fn.ezpz_tooltip.showContent(content);
+ })
+
+ if (settings.stayOnContent && this.id != "") {
+ $("#" + this.id + ", #" + getContentId(this.id)).mouseover(function(){
+ content.css('display', 'block');
+ }).mouseout(function(){
+ content.css('display', 'none');
+ settings.afterHide();
+ });
+ }
+ else {
+ targetMousedOver.mouseout(function(){
+ content.hide();
+ settings.afterHide();
+ })
+ }
+
+ });
+
+ function getContentId(targetId){
+ if (settings.contentId == "") {
+ var name = targetId.split('-')[0];
+ var id = targetId.split('-')[2];
+ return name + '-content-' + id;
+ }
+ else {
+ return settings.contentId;
+ }
+ };
+
+ function getElementDimensionsAndPosition(element){
+ var height = element.outerHeight(true);
+ var width = element.outerWidth(true);
+ var top = $(element).offset().top;
+ var left = $(element).offset().left;
+ var info = new Array();
+
+ // Set dimensions
+ info['height'] = height;
+ info['width'] = width;
+
+ // Set position
+ info['top'] = top;
+ info['left'] = left;
+
+ return info;
+ };
+
+ function keepInWindow(contentInfo){
+ var windowWidth = $(window).width();
+ var windowTop = $(window).scrollTop();
+ var output = new Array();
+
+ output = contentInfo;
+
+ if (contentInfo['top'] < windowTop) { // Top edge is too high
+ output['top'] = windowTop;
+ }
+ if ((contentInfo['left'] + contentInfo['width']) > windowWidth) { // Right edge is past the window
+ output['left'] = windowWidth - contentInfo['width'];
+ }
+ if (contentInfo['left'] < 0) { // Left edge is too far left
+ output['left'] = 0;
+ }
+
+ return output;
+ };
+ };
+
+ $.fn.ezpz_tooltip.showContent = function(content) {
+ content.show();
+ };
+
+ $.fn.ezpz_tooltip.positionContent = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY - offset - contentInfo['height'];
+ contentInfo['left'] = mouseX + offset;
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions = {
+ aboveRightFollow: function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY - offset - contentInfo['height'];
+ contentInfo['left'] = mouseX + offset;
+
+ return contentInfo;
+ }
+ };
+
+ $.fn.ezpz_tooltip.defaults = {
+ contentPosition: 'aboveRightFollow',
+ stayOnContent: false,
+ offset: 10,
+ contentId: "",
+ beforeShow: function(content){},
+ afterHide: function(){}
+ };
+
+})(jQuery);
+
+// Plugin for different content positions. Keep what you need, remove what you don't need to reduce file size.
+
+(function($){
+ $.fn.ezpz_tooltip.positions.aboveFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY - offset - contentInfo['height'];
+ contentInfo['left'] = mouseX - (contentInfo['width'] / 2);
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.rightFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY - (contentInfo['height'] / 2);
+ contentInfo['left'] = mouseX + offset;
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.belowRightFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY + offset;
+ contentInfo['left'] = mouseX + offset;
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.belowFollow = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = mouseY + offset;
+ contentInfo['left'] = mouseX - (contentInfo['width'] / 2);
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.aboveStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = targetInfo['top'] - offset - contentInfo['height'];
+ contentInfo['left'] = (targetInfo['left'] + (targetInfo['width'] / 2)) - (contentInfo['width'] / 2);
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.rightStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = (targetInfo['top'] + (targetInfo['height'] / 2)) - (contentInfo['height'] / 2);
+ contentInfo['left'] = targetInfo['left'] + targetInfo['width'] + offset;
+
+ return contentInfo;
+ };
+
+ $.fn.ezpz_tooltip.positions.belowStatic = function(contentInfo, mouseX, mouseY, offset, targetInfo) {
+ contentInfo['top'] = targetInfo['top'] + targetInfo['height'] + offset;
+ contentInfo['left'] = (targetInfo['left'] + (targetInfo['width'] / 2)) - (contentInfo['width'] / 2);
+
+ return contentInfo;
+ };
+
+})(jQuery);

0 comments on commit 13751bc

Please sign in to comment.