1jQuery(document).ready(function($) { 2 $('#glt-translate-trigger,#glt-translate-trigger font').toolbar({ 3 content: '#flags', 4 position: 'top', 5 hideOnClick: true, 6 event: 'click', 7 style: 'primary' 8 }); 9 10 $('#glt-translate-trigger').on('toolbarItemClick',function(event) { 11 $(this).removeClass('pressed'); 12 }); 13 14}); 15 16/** 17 * Toolbar.js 18 * 19 * @fileoverview jQuery plugin that creates tooltip style toolbars. 20 * @link http://paulkinzett.github.com/toolbar/ 21 * @author Paul Kinzett (http://kinzett.co.nz/) 22 * @version 1.1.0 23 * @requires jQuery 1.7+ 24 * 25 * @license jQuery Toolbar Plugin v1.1.0 26 * http://paulkinzett.github.com/toolbar/ 27 * Copyright 2013 - 2015 Paul Kinzett (http://kinzett.co.nz/) 28 * Released under the MIT license. 29 * <https://raw.github.com/paulkinzett/toolbar/master/LICENSE.txt> 30 */ 31 32if ( typeof Object.create !== 'function' ) { 33 Object.create = function( obj ) { 34 function F() {} 35 F.prototype = obj; 36 return new F(); 37 }; 38} 39 40(function( $, window, document, undefined ) { 41 42 var ToolBar = { 43 init: function( options, elem ) { 44 var self = this; 45 self.elem = elem; 46 self.$elem = $( elem ); 47 self.options = $.extend( {}, $.fn.toolbar.options, options ); 48 self.metadata = self.$elem.data(); 49 self.overrideOptions(); 50 self.toolbar = $('<div class="tool-container" />') 51 .addClass('tool-'+self.options.position) 52 .addClass('toolbar-'+self.options.style) 53 .append('<div class="tool-items" />') 54 .append('<div class="arrow" />') 55 .appendTo('body') 56 .css('opacity', 0) 57 .hide(); 58 self.toolbar_arrow = self.toolbar.find('.arrow'); 59 self.initializeToolbar(); 60 }, 61 62 overrideOptions: function() { 63 var self = this; 64 $.each( self.options, function( $option ) { 65 if (typeof(self.$elem.data('toolbar-'+$option)) != "undefined") { 66 self.options[$option] = self.$elem.data('toolbar-'+$option); 67 } 68 }); 69 }, 70 71 initializeToolbar: function() { 72 var self = this; 73 self.populateContent(); 74 self.setTrigger(); 75 self.toolbarWidth = self.toolbar.width(); 76 }, 77 78 setTrigger: function() { 79 var self = this; 80 81 if (self.options.event != 'click') { 82 83 var moveTime; 84 function decideTimeout () { 85 if (self.$elem.hasClass('pressed')) { 86 moveTime = setTimeout(function() { 87 self.hide(); 88 }, 150); 89 } else { 90 clearTimeout(moveTime); 91 }; 92 }; 93 94 self.$elem.on({ 95 mouseenter: function(event) { 96 if (self.$elem.hasClass('pressed')) { 97 clearTimeout(moveTime); 98 } else { 99 self.show(); 100 } 101 } 102 }); 103 104 self.$elem.parent().on({ 105 mouseleave: function(event){ decideTimeout(); } 106 }); 107 108 $('.tool-container').on({ 109 mouseenter: function(event){ clearTimeout(moveTime); }, 110 mouseleave: function(event){ decideTimeout(); } 111 }); 112 } 113 114 if (self.options.event == 'click') { 115 self.$elem.on('click', function(event) { 116 event.preventDefault(); 117 if(self.$elem.hasClass('pressed')) { 118 self.hide(); 119 } else { 120 self.show(); 121 } 122 }); 123 124 if (self.options.hideOnClick) { 125 $('html').on("click.toolbar", function ( event ) { 126 if (event.target != self.elem && 127 self.$elem.has(event.target).length === 0 && 128 self.toolbar.has(event.target).length === 0 && 129 self.toolbar.is(":visible")) { 130 self.hide(); 131 } 132 }); 133 } 134 } 135 136 if (self.options.hover) { 137 var moveTime; 138 139 function decideTimeout () { 140 if (self.$elem.hasClass('pressed')) { 141 moveTime = setTimeout(function() { 142 self.hide(); 143 }, 150); 144 } else { 145 clearTimeout(moveTime); 146 }; 147 }; 148 149 self.$elem.on({ 150 mouseenter: function(event) { 151 if (self.$elem.hasClass('pressed')) { 152 clearTimeout(moveTime); 153 } else { 154 self.show(); 155 } 156 } 157 }); 158 159 self.$elem.parent().on({ 160 mouseleave: function(event){ decideTimeout(); } 161 }); 162 163 $('.tool-container').on({ 164 mouseenter: function(event){ clearTimeout(moveTime); }, 165 mouseleave: function(event){ decideTimeout(); } 166 }); 167 } 168 169 $(window).resize(function( event ) { 170 event.stopPropagation(); 171 if ( self.toolbar.is(":visible") ) { 172 self.toolbarCss = self.getCoordinates(self.options.position, 20); 173 self.collisionDetection(); 174 self.toolbar.css( self.toolbarCss ); 175 self.toolbar_arrow.css( self.arrowCss ); 176 } 177 }); 178 }, 179 180 populateContent: function() { 181 var self = this; 182 var location = self.toolbar.find('.tool-items'); 183 var content = $(self.options.content).clone( true ).find('a').addClass('tool-item'); 184 location.html(content); 185 location.find('.tool-item').on('click', function(event) { 186 event.preventDefault(); 187 self.$elem.trigger('toolbarItemClick', this); 188 }); 189 }, 190 191 calculatePosition: function() { 192 var self = this; 193 self.arrowCss = {}; 194 self.toolbarCss = self.getCoordinates(self.options.position, self.options.adjustment); 195 self.toolbarCss.position = 'fixed'; 196 self.toolbarCss.zIndex = self.options.zIndex; 197 self.collisionDetection(); 198 self.toolbar.css(self.toolbarCss); 199 self.toolbar_arrow.css(self.arrowCss); 200 }, 201 202 getCoordinates: function( position, adjustment ) { 203 var self = this; 204 self.coordinates = self.$elem.offset(); 205 206 if (self.options.adjustment && self.options.adjustment[self.options.position]) { 207 adjustment = self.options.adjustment[self.options.position] + adjustment; 208 } 209 210 switch(self.options.position) { 211 case 'top': 212 return { 213 left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2), 214 top: self.coordinates.top-self.$elem.outerHeight()-adjustment, 215 right: 'auto' 216 }; 217 case 'left': 218 return { 219 left: self.coordinates.left-(self.toolbar.width()/2)-(self.$elem.outerWidth()/2)-adjustment, 220 top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2), 221 right: 'auto' 222 }; 223 case 'right': 224 return { 225 left: self.coordinates.left+(self.toolbar.width()/2)+(self.$elem.outerWidth()/2)+adjustment, 226 top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2), 227 right: 'auto' 228 }; 229 case 'bottom': 230 return { 231 left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2), 232 top: self.coordinates.top+self.$elem.outerHeight()+adjustment, 233 right: 'auto' 234 }; 235 } 236 }, 237 238 collisionDetection: function() { 239 var self = this; 240 var edgeOffset = 20; 241 if(self.options.position == 'top' || self.options.position == 'bottom') { 242 self.arrowCss = {left: '50%', right: '50%'}; 243 if( self.toolbarCss.left < edgeOffset ) { 244 self.toolbarCss.left = edgeOffset; 245 self.arrowCss.left = self.$elem.offset().left + self.$elem.width()/2-(edgeOffset); 246 } 247 else if(($(window).width() - (self.toolbarCss.left + self.toolbarWidth)) < edgeOffset) { 248 self.toolbarCss.right = edgeOffset; 249 self.toolbarCss.left = 'auto'; 250 self.arrowCss.left = 'auto'; 251 self.arrowCss.right = ($(window).width()-self.$elem.offset().left)-(self.$elem.width()/2)-(edgeOffset)-5; 252 } 253 } 254 }, 255 256 show: function() { 257 var self = this; 258 self.$elem.addClass('pressed'); 259 self.calculatePosition(); 260 self.toolbar.show().css({'opacity': 1}).addClass('animate-'+self.options.animation); 261 self.$elem.trigger('toolbarShown'); 262 }, 263 264 hide: function() { 265 var self = this; 266 var animation = {'opacity': 0}; 267 268 self.$elem.removeClass('pressed'); 269 270 switch(self.options.position) { 271 case 'top': 272 animation.top = '+=20'; 273 break; 274 case 'left': 275 animation.left = '+=20'; 276 break; 277 case 'right': 278 animation.left = '-=20'; 279 break; 280 case 'bottom': 281 animation.top = '-=20'; 282 break; 283 } 284 285 self.toolbar.animate(animation, 200, function() { 286 self.toolbar.hide(); 287 }); 288 289 self.$elem.trigger('toolbarHidden'); 290 }, 291 292 getToolbarElement: function () { 293 return this.toolbar.find('.tool-items'); 294 } 295 }; 296 297 $.fn.toolbar = function( options ) { 298 if ($.isPlainObject( options )) { 299 return this.each(function() { 300 var toolbarObj = Object.create( ToolBar ); 301 toolbarObj.init( options, this ); 302 $(this).data('toolbarObj', toolbarObj); 303 }); 304 } else if ( typeof options === 'string' && options.indexOf('_') !== 0 ) { 305 var toolbarObj = $(this).data('toolbarObj'); 306 var method = toolbarObj[options]; 307 return method.apply(toolbarObj, $.makeArray(arguments).slice(1)); 308 } 309 }; 310 311 $.fn.toolbar.options = { 312 content: '#myContent', 313 position: 'top', 314 hideOnClick: false, 315 zIndex: 120, 316 hover: false, 317 style: 'default', 318 animation: 'standard', 319 adjustment: 10 320 }; 321 322}) ( jQuery, window, document );
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.