1;(function($){ 2 3window.MapifyTooltip = function(settings) { 4 this.dom_node = $('<div></div>'); 5 this.dom_node.data('tooltip', this); 6 this.settings = settings; 7 this.class_prefix = 'mpfy'; 8 this.creation_id = 0; 9 this.visible = false; 10 this.pinId = typeof settings.pinId !== 'undefined' ? parseInt( settings.pinId ) : 0; 11 12 this.dom_node.addClass( this.settings.classes ); 13 this.dom_node.data( 'pinId', this.pinId ); 14 15 this.node = function() { 16 return this.dom_node; 17 } 18 19 this.init = function() { 20 MapifyTooltip._instances.push(this); 21 this.creation_id = MapifyTooltip._instances.length; 22 23 var inner_wrap = $('<div class="inner-wrap"></div>'); 24 this.node().append(inner_wrap); 25 inner_wrap.append($('<div class="top"></div>')); 26 inner_wrap.append( 27 $('<div class="center"></div>') 28 .append('<div class="tltpcnt">' + this.settings.content + '</div>') 29 ); 30 inner_wrap.append($('<div class="bottom" style="border-top: 20px solid rgba(' + this.settings.rgba[0] + ', ' + this.settings.rgba[1] + ', ' + this.settings.rgba[2] + ', ' + this.settings.rgba[3] + ');"></div>')); 31 32 inner_wrap 33 .find('.mpfy-tooltip-content') 34 .css( 'backgroundColor', 'rgba(' + this.settings.rgba[0] + ', ' + this.settings.rgba[1] + ', ' + this.settings.rgba[2] + ', ' + this.settings.rgba[3] + ')' ); 35 36 if (this.settings.close_behavior == 'manual') { 37 var close_button = $('<a href="#" class="' + this.class_prefix + '-close-tooltip ' + this.class_prefix + '-notext"> </a>'); 38 close_button.data('tooltip', this); 39 close_button.on('click', function(e) { 40 var t = $(this).data('tooltip'); 41 t.node().trigger({ 42 'type': 'tooltip_close' 43 }); 44 e.preventDefault(); 45 }); 46 this.node().find('.center:first').prepend(close_button); 47 } 48 49 $('body').append(this.node()); 50 51 52 // Handle events 53 this.node() 54 .on('tooltip_mouseover', function(e) { 55 var t = $(this).data('tooltip'); 56 t.show(e.settings.left, e.settings.top); 57 }) 58 .on('tooltip_mouseout', function(e) { 59 var t = $(this).data('tooltip'); 60 if (t.settings.close_behavior == 'auto') { 61 t.hide(); 62 } 63 }) 64 .on('tooltip_close', function(e) { 65 var t = $(this).data('tooltip'); 66 t.hide(); 67 }); 68 69 } 70 71 this.show = function(l, t) { 72 l = Math.round(l); 73 t = Math.round(t); 74 75 if ( $('body').css( 'position' ) === 'relative' ) { 76 t -= $('body').offset().top; 77 } 78 79 for (var i = 0; i < MapifyTooltip._instances.length; i++) { 80 var instance = MapifyTooltip._instances[i]; 81 82 83 if (instance.creation_id != this.creation_id) { 84 instance.hide(); 85 } 86 } 87 88 var tooltip_width = this.node().width(); 89 90 var arrow_width = 30; 91 var arrow_margin = '0 auto'; 92 93 if (l < 0) { 94 arrow_margin = '0 0 0 ' + Math.floor(tooltip_width / 2 + l - arrow_width / 2).toString() + 'px'; 95 l = 0; 96 } else if (l + tooltip_width > $(window).width()) { 97 var excess = l + tooltip_width - $(window).width(); 98 arrow_margin = '0 0 0 ' + Math.floor(tooltip_width / 2 + excess - arrow_width / 2).toString() + 'px'; 99 l = $(window).width() - tooltip_width; 100 } 101 102 if (this.settings.animate && !this.visible) { 103 this.node().find('.inner-wrap:first') 104 .stop() 105 .css({ 106 'top': 7, 107 'opacity': 0 108 }) 109 .animate({ 110 'top': 0, 111 'opacity': 1 112 }, 300); 113 } 114 this.node() 115 .stop() 116 .css({ 117 'left': l, 118 'top': t, 119 'opacity': 1 120 }) 121 .show(); 122 this.node().find('.bottom:first').css({ 123 'margin': arrow_margin 124 }); 125 126 this.visible = true; 127 } 128 129 this.showCentered = function(l, t) { 130 var l = l - Math.ceil(this.node().width() / 2); 131 var t = t - this.node().height(); 132 this.show(l, t); 133 } 134 135 this.hide = function() { 136 if (!this.visible) { 137 return false; 138 } 139 if (this.settings.animate) { 140 this.node().stop().fadeTo(300, 0, function() { 141 $(this).hide(); 142 }) 143 } else { 144 this.node().hide(); 145 } 146 147 this.visible = false; 148 this.node().trigger({ 149 'type': 'tooltip_closed' 150 }); 151 } 152 153 this.setContent = function(content) { 154 this.node().find('.tltpcnt:first').html(content); 155 } 156 157 this.setGoogleMap = function(map) { 158 var me = this; 159 google.maps.event.addListener(map, 'center_changed', function(){ 160 me.hide(); 161 }); 162 google.maps.event.addListener(map, 'zoom_changed', function(){ 163 me.hide(); 164 }); 165 google.maps.event.addListener(map, 'dragstart', function(){ 166 me.hide(); 167 }); 168 } 169 170 this.setImageMap = function(map) { 171 var me = this; 172 google.maps.event.addListener(map, 'center_changed', function(){ 173 me.hide(); 174 }); 175 google.maps.event.addListener(map, 'zoom_changed', function(){ 176 me.hide(); 177 }); 178 google.maps.event.addListener(map, 'dragstart', function(){ 179 me.hide(); 180 }); 181 } 182 183 this.init(); 184} 185MapifyTooltip._instances = []; 186 187})(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.