1 /* 2 * TipTip 3 * Copyright 2010 Drew Wilson 4 * www.drewwilson.com 5 * code.drewwilson.com/entry/tiptip-jquery-plugin 6 * 7 * Version 1.3 - Updated: Mar. 23, 2010 8 * 9 * This Plug-In will create a custom tooltip to replace the default 10 * browser tooltip. It is extremely lightweight and very smart in 11 * that it detects the edges of the browser window and will make sure 12 * the tooltip stays within the current window size. As a result the 13 * tooltip will adjust itself to be displayed above, below, to the left 14 * or to the right depending on what is necessary to stay within the 15 * browser window. It is completely customizable as well via CSS. 16 * 17 * This TipTip jQuery plug-in is dual licensed under the MIT and GPL licenses: 18 * http://www.opensource.org/licenses/mit-license.php 19 * http://www.gnu.org/licenses/gpl.html 20 * 21 * Updated by Cyril Rezé (JoomliC) 22 * @version 3.5.5 2015-04-27 23 */ 24 25(function($){ 26 $.fn.tipTip = function(options) { 27 var defaults = { 28 activation: "hover", 29 keepAlive: false, 30 maxWidth: "200px", 31 edgeOffset: 3, 32 defaultPosition: "bottom", 33 delay: 400, 34 fadeIn: 200, 35 fadeOut: 200, 36 attribute: "title", 37 content: false, // HTML or String to fill TipTIp with 38 enter: function(){}, 39 exit: function(){} 40 }; 41 var opts = $.extend(defaults, options); 42 43 // Setup tip tip elements and render them to the DOM 44 if($("#tiptip_holder").length <= 0){ 45 var tiptip_holder = $('<div id="tiptip_holder" style="max-width:'+ opts.maxWidth +';"></div>'); 46 var tiptip_content = $('<div id="tiptip_content"></div>'); 47 var tiptip_arrow = $('<div id="tiptip_arrow"></div>'); 48 $("body").append(tiptip_holder.html(tiptip_content).prepend(tiptip_arrow.html('<div id="tiptip_arrow_inner"></div>'))); 49 } else { 50 var tiptip_holder = $("#tiptip_holder"); 51 var tiptip_content = $("#tiptip_content"); 52 var tiptip_arrow = $("#tiptip_arrow"); 53 } 54 55 return this.each(function(){ 56 var org_elem = $(this); 57 if(opts.content){ 58 var org_title = opts.content; 59 } else { 60 var org_title = org_elem.attr(opts.attribute); 61 } 62 if(org_title != ""){ 63 if(!opts.content){ 64 org_elem.removeAttr(opts.attribute); //remove original Attribute 65 } 66 var timeout = false; 67 68 if(opts.activation == "hover"){ 69 org_elem.hover(function(){ 70 active_tiptip(); 71 }, function(){ 72 if(!opts.keepAlive){ 73 deactive_tiptip(); 74 } 75 }); 76 if(opts.keepAlive){ 77 tiptip_holder.hover(function(){}, function(){ 78 deactive_tiptip(); 79 }); 80 } 81 } else if(opts.activation == "focus"){ 82 org_elem.focus(function(){ 83 active_tiptip(); 84 }).blur(function(){ 85 deactive_tiptip(); 86 }); 87 } else if(opts.activation == "click"){ 88 org_elem.click(function(){ 89 active_tiptip(); 90 return false; 91 }).hover(function(){},function(){ 92 if(!opts.keepAlive){ 93 deactive_tiptip(); 94 } 95 }); 96 if(opts.keepAlive){ 97 tiptip_holder.hover(function(){}, function(){ 98 deactive_tiptip(); 99 }); 100 } 101 } 102 103 function active_tiptip(){ 104 opts.enter.call(this); 105 tiptip_content.html(org_title); 106 tiptip_holder.hide().removeAttr("class").css("margin","0"); 107 tiptip_arrow.removeAttr("style"); 108 109 // Add body offset control 110 var body_offset = $('body').offset(), 111 offset = org_elem.offset(), 112 tip_top = offset.top, 113 tip_left = offset.left, 114 body_top = body_offset.top, 115 body_left = body_offset.left, 116 top = parseInt(tip_top - body_top), 117 left = parseInt(tip_left - body_left); 118 119 var org_width = parseInt(org_elem.outerWidth()), 120 org_height = parseInt(org_elem.outerHeight()), 121 tip_w = tiptip_holder.outerWidth(), 122 tip_h = tiptip_holder.outerHeight(), 123 w_compare = Math.round((org_width - tip_w) / 2), 124 h_compare = Math.round((org_height - tip_h) / 2), 125 marg_left = Math.round(left + w_compare), 126 marg_top = Math.round(top + org_height + opts.edgeOffset), 127 t_class = "", 128 arrow_top = "", 129 arrow_left = Math.round(tip_w - 12) / 2; 130 131 if(opts.defaultPosition == "bottom"){ 132 t_class = "_bottom"; 133 } else if(opts.defaultPosition == "top"){ 134 t_class = "_top"; 135 } else if(opts.defaultPosition == "left"){ 136 t_class = "_left"; 137 } else if(opts.defaultPosition == "right"){ 138 t_class = "_right"; 139 } 140 141 var right_compare = (w_compare + left) < parseInt($(window).scrollLeft()); 142 var left_compare = (tip_w + left) > parseInt($(window).width()); 143 144 if((right_compare && w_compare < 0) || (t_class == "_right" && !left_compare) || (t_class == "_left" && left < (tip_w + opts.edgeOffset + 5))){ 145 t_class = "_right"; 146 arrow_top = Math.round(tip_h - 13) / 2; 147 arrow_left = -12; 148 marg_left = Math.round(left + org_width + opts.edgeOffset); 149 marg_top = Math.round(top + h_compare); 150 } else if((left_compare && w_compare < 0) || (t_class == "_left" && !right_compare)){ 151 t_class = "_left"; 152 arrow_top = Math.round(tip_h - 13) / 2; 153 arrow_left = Math.round(tip_w); 154 marg_left = Math.round(left - (tip_w + opts.edgeOffset + 5)); 155 marg_top = Math.round(top + h_compare); 156 } 157 158 var top_compare = (top + org_height + opts.edgeOffset + tip_h + 8) > parseInt($(window).height() + $(window).scrollTop()); 159 var bottom_compare = ((top + org_height) - (opts.edgeOffset + tip_h + 8)) < 0; 160 161 if(top_compare || (t_class == "_bottom" && top_compare) || (t_class == "_top" && !bottom_compare)){ 162 if(t_class == "_top" || t_class == "_bottom"){ 163 t_class = "_top"; 164 } else { 165 t_class = t_class+"_top"; 166 } 167 arrow_top = tip_h;
168 marg_top = Math.round(top - (tip_h + 5 + opts.edgeOffset)); 169 } else if(bottom_compare | (t_class == "_top" && bottom_compare) || (t_class == "_bottom" && !top_compare)){ 170 if(t_class == "_top" || t_class == "_bottom"){ 171 t_class = "_bottom"; 172 } else { 173 t_class = t_class+"_bottom"; 174 } 175 arrow_top = -12; 176 marg_top = Math.round(top + org_height + opts.edgeOffset); 177 } 178 179 if(t_class == "_right_top" || t_class == "_left_top"){ 180 marg_top = marg_top + 5; 181 } else if(t_class == "_right_bottom" || t_class == "_left_bottom"){ 182 marg_top = marg_top - 5; 183 } 184 if(t_class == "_left_top" || t_class == "_left_bottom"){ 185 marg_left = marg_left + 5; 186 } 187 tiptip_arrow.css({"margin-left": arrow_left+"px", "margin-top": arrow_top+"px"}); 188 tiptip_holder.css({"margin-left": marg_left+"px", "margin-top": marg_top+"px"}).attr("class","tip"+t_class); 189 190 if (timeout){ clearTimeout(timeout); } 191 timeout = setTimeout(function(){ tiptip_holder.stop(true,true).fadeIn(opts.fadeIn); }, opts.delay); 192 } 193 194 function deactive_tiptip(){ 195 opts.exit.call(this); 196 if (timeout){ clearTimeout(timeout); } 197 tiptip_holder.fadeOut(opts.fadeOut); 198 } 199 } 200 }); 201 } 202})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.