1/*-------------------------------------------------------------------------------* 2 * Script for onClick trigger functionality used by flag images 3 * Script modified from original GTranslate plugin created by Edvard Ananyan at http://edo.webmaster.am 4 * GTranslate Free Version is licensed under GNU/GPL license 5 *-------------------------------------------------------------------------------*/ 6 7function GLTFireEvent(lang_pair, lang_dest) { 8 try { 9 if (document.createEvent) { 10 var event = document.createEvent("HTMLEvents"); 11 event.initEvent(lang_dest, true, true); 12 lang_pair.dispatchEvent(event) 13 } else { 14 var event = document.createEventObject(); 15 lang_pair.fireEvent('on' + lang_dest, event) 16 } 17 } catch (e) {} 18} 19 20function doGoogleLanguageTranslator(lang_pair) { 21 if(window.glt_request_uri) return true; 22 23 if (lang_pair.value) lang_pair = lang_pair.value; 24 if (lang_pair == '') return; 25 var lang_dest = lang_pair.split('|')[1]; 26 var event; 27 var classic = jQuery('.goog-te-combo'); 28 var simple = jQuery('.goog-te-menu-frame:first'); 29 var simpleValue = simple.contents().find('.goog-te-menu2-item span.text:contains('+lang_text+')'); 30 if (classic.length == 0) { 31 for (var i = 0; i < simple.length; i++) { 32 event = simple[i]; 33 //alert('Simple is active.'); 34 } 35 } else { 36 for (var i = 0; i < classic.length; i++) { 37 event = classic[i]; 38 //alert('Classic is active.'); 39 } 40 } 41 if (document.getElementById('google_language_translator') != null) { 42 if (classic.length != 0) { 43 if (lang_prefix != default_lang) { 44 event.value = lang_dest; 45 GLTFireEvent(event, 'change'); 46 } else { 47 jQuery('.goog-te-banner-frame:first').contents().find('.goog-close-link').get(0).click(); 48 } 49 } else { 50 event.value = lang_dest; 51 if (lang_prefix != default_lang) { 52 simpleValue.click(); 53 } else { 54 jQuery('.goog-te-banner-frame:first').contents().find('.goog-close-link').get(0).click(); 55 } 56 } 57 } 58} 59 60jQuery(document).ready(function($) { 61 $('#glt-translate-trigger,#glt-translate-trigger font').toolbar({ 62 content: '#flags', 63 position: 'top', 64 hideOnClick: true, 65 event: 'click', 66 style: 'primary' 67 }); 68 69 $('#glt-translate-trigger').on('toolbarItemClick',function(event) { 70 $(this).removeClass('pressed'); 71 }); 72}); 73 74/** 75 * Toolbar.js 76 * 77 * @fileoverview jQuery plugin that creates tooltip style toolbars. 78 * @link http://paulkinzett.github.com/toolbar/ 79 * @author Paul Kinzett (http://kinzett.co.nz/) 80 * @version 1.1.0 81 * @requires jQuery 1.7+ 82 * 83 * @license jQuery Toolbar Plugin v1.1.0 84 * http://paulkinzett.github.com/toolbar/ 85 * Copyright 2013 - 2015 Paul Kinzett (http://kinzett.co.nz/) 86 * Released under the MIT license. 87 * <https://raw.github.com/paulkinzett/toolbar/master/LICENSE.txt> 88 */ 89 90if ( typeof Object.create !== 'function' ) { 91 Object.create = function( obj ) { 92 function F() {} 93 F.prototype = obj; 94 return new F(); 95 }; 96} 97 98(function( $, window, document, undefined ) { 99 100 var ToolBar = { 101 init: function( options, elem ) { 102 var self = this; 103 self.elem = elem; 104 self.$elem = $( elem ); 105 self.options = $.extend( {}, $.fn.toolbar.options, options ); 106 self.metadata = self.$elem.data(); 107 self.overrideOptions(); 108 self.toolbar = $('<div class="tool-container" />') 109 .addClass('tool-'+self.options.position) 110 .addClass('toolbar-'+self.options.style) 111 .append('<div class="tool-items" />') 112 .append('<div class="arrow" />') 113 .appendTo('body') 114 .css('opacity', 0) 115 .hide(); 116 self.toolbar_arrow = self.toolbar.find('.arrow'); 117 self.initializeToolbar(); 118 }, 119 120 overrideOptions: function() { 121 var self = this; 122 123 $.each( self.options, function( $option ) { 124 if (typeof(self.$elem.data('toolbar-'+$option)) != "undefined") { 125 self.options[$option] = self.$elem.data('toolbar-'+$option); 126 } 127 }); 128 }, 129 130 initializeToolbar: function() { 131 var self = this; 132 self.populateContent(); 133 self.setTrigger(); 134 self.toolbarWidth = self.toolbar.width(); 135 }, 136 137 setTrigger: function() { 138 var self = this; 139 140 if (self.options.event == 'onload') { 141 $(window).load(function(event) { 142 event.preventDefault(); 143 self.show(); 144 }); 145 } 146 147 if (self.options.event == 'click') { 148 self.$elem.on('click', function(event) { 149 event.preventDefault(); 150 if(self.$elem.hasClass('pressed')) { 151 self.hide(); 152 } else { 153 self.show(); 154 } 155 }); 156 157 if (self.options.hideOnClick) { 158 $('html').on("click.toolbar", function ( event ) { 159 if (event.target != self.elem && 160 self.$elem.has(event.target).length === 0 && 161 self.toolbar.has(event.target).length === 0 && 162 self.toolbar.is(":visible")) { 163 self.hide(); 164 } 165 }); 166 } 167 } 168 169 if (self.options.hover) { 170 var moveTime; 171 172 function decideTimeout () { 173 if (self.$elem.hasClass('pressed')) { 174 moveTime = setTimeout(function() { 175 self.hide(); 176 }, 150); 177 } else { 178 clearTimeout(moveTime); 179 }; 180 }; 181 182 self.$elem.on({ 183 mouseenter: function(event) { 184 if (self.$elem.hasClass('pressed')) { 185 clearTimeout(moveTime); 186 } else { 187 self.show(); 188 } 189 } 190 }); 191 192 self.$elem.parent().on({ 193 mouseleave: function(event){ decideTimeout(); } 194 }); 195 196 $('.tool-container').on({ 197 mouseenter: function(event){ clearTimeout(moveTime); }, 198 mouseleave: function(event){ decideTimeout(); } 199 }); 200 } 201 202 $(window).resize(function( event ) { 203 event.stopPropagation(); 204 205 if ( self.toolbar.is(":visible") ) { 206 self.toolbarCss = self.getCoordinates(self.options.position, 20); 207 self.collisionDetection(); 208 self.toolbar.css( self.toolbarCss ); 209 self.toolbar_arrow.css( self.arrowCss ); 210 } 211 }); 212 }, 213 214 populateContent: function() { 215 var self = this; 216 var location = self.toolbar.find('.tool-items'); 217 var content = $(self.options.content).clone( true ).find('a').addClass('tool-item'); 218 219 location.html(content); 220 location.find('.tool-item').on('click', function(event) { 221 if(typeof window.glt_request_uri == 'undefined') 222 event.preventDefault(); 223 self.$elem.trigger('toolbarItemClick', this); 224 }); 225 }, 226 227 calculatePosition: function() { 228 var self = this; 229 self.arrowCss = {}; 230 self.toolbarCss = self.getCoordinates(self.options.position, self.options.adjustment); 231 self.toolbarCss.position = 'fixed'; 232 self.toolbarCss.zIndex = self.options.zIndex; 233 self.collisionDetection(); 234 self.toolbar.css(self.toolbarCss); 235 self.toolbar_arrow.css(self.arrowCss); 236 }, 237 238 getCoordinates: function( position, adjustment ) { 239 var self = this; 240 241 self.coordinates = self.$elem.offset(); 242 243 if (self.options.adjustment && self.options.adjustment[self.options.position]) { 244 adjustment = self.options.adjustment[self.options.position] + adjustment; 245 } 246 247 switch(self.options.position) { 248 case 'top': 249 return { 250 left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2), 251 top: self.coordinates.top-self.$elem.outerHeight()-adjustment, 252 right: 'auto' 253 }; 254 255 case 'left': 256 return { 257 left: self.coordinates.left-(self.toolbar.width()/2)-(self.$elem.outerWidth()/2)-adjustment, 258 top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2), 259 right: 'auto' 260 }; 261 262 case 'right': 263 return { 264 left: self.coordinates.left+(self.toolbar.width()/2)+(self.$elem.outerWidth()/2)+adjustment, 265 top: self.coordinates.top-(self.toolbar.height()/2)+(self.$elem.outerHeight()/2), 266 right: 'auto' 267 }; 268 269 case 'bottom': 270 return { 271 left: self.coordinates.left-(self.toolbar.width()/2)+(self.$elem.outerWidth()/2), 272 top: self.coordinates.top+self.$elem.outerHeight()+adjustment, 273 right: 'auto' 274 }; 275 } 276 }, 277 278 collisionDetection: function() { 279 var self = this; 280 var edgeOffset = 20; 281 282 if(self.options.position == 'top' || self.options.position == 'bottom') { 283 self.arrowCss = {left: '50%', right: '50%'}; 284 if( self.toolbarCss.left < edgeOffset ) { 285 self.toolbarCss.left = edgeOffset; 286 self.arrowCss.left = self.$elem.offset().left + self.$elem.width()/2-(edgeOffset); 287 } 288 289 else if(($(window).width() - (self.toolbarCss.left + self.toolbarWidth)) < edgeOffset) { 290 self.toolbarCss.right = edgeOffset; 291 self.toolbarCss.left = 'auto'; 292 self.arrowCss.left = 'auto'; 293 self.arrowCss.right = ($(window).width()-self.$elem.offset().left)-(self.$elem.width()/2)-(edgeOffset)-5; 294 } 295 } 296 }, 297 298 show: function() { 299 var self = this; 300 self.$elem.addClass('pressed'); 301 self.calculatePosition(); 302 self.toolbar.show().css({'opacity': 1}).addClass('animate-'+self.options.animation); 303 self.$elem.trigger('toolbarShown'); 304 }, 305 306 hide: function() { 307 var self = this; 308 var animation = {'opacity': 0}; 309 self.$elem.removeClass('pressed'); 310 switch(self.options.position) { 311 case 'top': 312 animation.top = '+=20'; 313 break; 314 case 'left': 315 animation.left = '+=20'; 316 break; 317 case 'right': 318 animation.left = '-=20'; 319 break; 320 case 'bottom': 321 animation.top = '-=20'; 322 break; 323 } 324 self.toolbar.animate(animation, 200, function() { 325 self.toolbar.hide(); 326 }); 327 self.$elem.trigger('toolbarHidden'); 328 }, 329 330 getToolbarElement: function () { 331 return this.toolbar.find('.tool-items'); 332 } 333 }; 334 335 $.fn.toolbar = function( options ) { 336 if ($.isPlainObject( options )) { 337 return this.each(function() { 338 var toolbarObj = Object.create( ToolBar ); 339 toolbarObj.init( options, this ); 340 $(this).data('toolbarObj', toolbarObj); 341 }); 342 } else if ( typeof options === 'string' && options.indexOf('_') !== 0 ) { 343 var toolbarObj = $(this).data('toolbarObj'); 344 var method = toolbarObj[options]; 345 return method.apply(toolbarObj, $.makeArray(arguments).slice(1)); 346 } 347 }; 348 349 $.fn.toolbar.options = { 350 content: '#myContent', 351 position: 'top', 352 hideOnClick: false, 353 zIndex: 120, 354 hover: false, 355 style: 'default', 356 animation: 'standard', 357 adjustment: 10 358 }; 359}) ( jQuery, window, document ); 360 361jQuery(function($) { 362 $('#flags a, a.single-language, .tool-items a').each(function() { 363 $(this).attr('data-lang', $(this).attr('title')); 364 }); 365 366 $(document.body).on("click", "a.flag", function() { 367 lang_text = $(this).attr('data-lang'); 368 default_lang = window.glt_default_lang || $('#google_language_translator').attr('class').split("-").pop(); 369 lang_prefix = $(this).attr("class").split(" ")[2]; 370 lang_prefix == default_lang ? l() : n(); 371 function l() { 372 doGoogleLanguageTranslator(default_lang + "|" + default_lang); 373 } 374 function n() { 375 doGoogleLanguageTranslator(default_lang + "|" + lang_prefix); 376 } 377 $(".tool-container").hide(); 378 }); 379 380 if(window.glt_request_uri) { 381 $('#google_language_translator select').on('change', function() { 382 doGLTTranslate($(this).val()); 383 }) 384 } 385}); 386
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.