1/*! 2 * Copyright (c) 2015. [j]karef GmbH 3 */ 4 5/** 6 * @author Rene Jablonski <[email protected]> 7 * @date 07.05.15 8 */ 9 10AUI.add('owidiblue-base', function (A) { 11 12 var DEBUG = window.location.href.indexOf('js_fast_load=0') !== -1; 13 14 var LOGINBAR_ID = '#navSiteNavigationNavbarBtn'; 15 /** 16 * 17 * @type {owidiblue-base} 18 * @constructor 19 */ 20 A.OwidiBlue = A.Base.create('owidiblue-base', A.Base, [A.EventTarget], { 21 22 // COMPATIBILITY WITH OLD SEARCH 23 _cartClearedListener: {}, 24 _cartRemovedListener: {}, 25 _cartAddeddListener: {}, 26 // COMPATIBILITY WITH OLD SEARCH END 27 28 _contactSlider: null, 29 _contactSliderButton: null, 30 _loginbar: null, 31 32 33 _loginPortlet: null, 34 _registrationPortlet: null, 35 36 37 /** 38 * slide the contact details in or out by clicking on the contact "button" on the left side 39 * @method 40 */ 41 toggleContactSlider: function() { 42 if (DEBUG) console.log("[toggleContactSlider]"); 43 var instance = this, 44 contactSliderDuration = instance.get('contactSliderDuration'); 45 if (DEBUG) console.log('duration: '+contactSliderDuration); 46 if(instance._contactSlider.getStyle('left') === '-275px') { 47 instance._contactSlider.transition({ 48 duration: contactSliderDuration, 49 easing: 'ease-in', 50 left: '0px' 51 }); 52 } else { 53 instance._contactSlider.transition({ 54 duration: contactSliderDuration, 55 easing: 'ease-out', 56 left: '-275px' 57 }); 58 } 59 }, 60 61 /** 62 * 63 * @private 64 */ 65 _calculateLoginTopValue: function() { 66 var instance = this, 67 autologin = A.one('#auto-login'), 68 seperator = A.one('#loginbar .horizontal-seperator'), 69 result = 0; 70 71 if(autologin != null) { 72 result = autologin.get('offsetHeight') + seperator.get('offsetHeight'); 73 } 74 if(instance._registrationPortlet != null) { 75 result += instance._registrationPortlet.get('offsetHeight'); 76 } 77 result += instance._loginPortlet.get('offsetHeight'); 78 return "-" + result + "px"; 79 }, 80 81 /** A very simple workaround to fix Liferays browser detection. 82 * (see https://issues.liferay.com/browse/LPS-43909 and https://issues.liferay.com/browse/LPS-43946) 83 * Liferay.Browser.isIe() will return true in this case but the BrowserSnifferImpl Java class return false! 84 */ 85 _initIE11Workaround: function() { 86 var regex = /trident/; 87 if(regex.test(navigator.userAgent.toLowerCase())) { 88 $('html').addClass('ie'); 89 Liferay.Browser.isIe = function() { return true; }; 90 if(Liferay.Browser.getMajorVersion() === 11) { 91 $('html').addClass('ie11'); 92 } 93 } 94 }, 95 96 /** 97 * init the contact slider 98 * @private 99 */ 100 _initContactSlider: function() { 101 if (DEBUG) console.log("[_initContactSlider]"); 102 var instance = this; 103 instance._contactSlider = A.one('#contact-slider'); 104 instance._contactSliderButton = A.one('#contact-slider .contact-button'); 105 if(instance._contactSliderButton !== null && typeof instance._contactSliderButton !== 'undefined') { 106 instance._contactSliderButton.on('click', function () { 107 instance.toggleContactSlider(); 108 }); 109 } 110 }, 111 112 _initPageCustomizationForm: function() { 113 if (DEBUG) console.log("[_initPageCustomizationForm]"); 114 var instance = this, 115 form = A.one('.page-customization-bar #_145_resetFm'), 116 reset_button = A.one('.page-customization-bar #_145_submit'), 117 answer; 118 119 if(form != null && reset_button != null) { 120 if (DEBUG) console.log("[_initPageCustomizationForm] form found, add click event listener"); 121 reset_button.on('click', function(event) { 122 if (DEBUG) console.log("[_initPageCustomizationForm] reset clicked. prevent default behaviour."); 123 event.preventDefault(); 124 answer = confirm(A.OwidiBlue.getText('are-you-sure-you-want-to-reset-your-customizations-to-default')); 125 if(answer) { 126 form.submit(); 127 } 128 }); 129 } 130 }, 131 132 _initImpersonatingHint: function() { 133 if(Liferay.ThemeDisplay.isImpersonated()) { 134 // sending the username unencoded could result in encoding issues. 135 var username = encodeURIComponent(encodeURI(Liferay.ThemeDisplay.getUserName())), 136 text = decodeURI(Liferay.Language.get("you-are-impersonating-x", username)), 137 node = A.one("#impersonating-hint a"); 138 139 if(node) { 140 node.attr("title", text); 141 } 142 } 143 }, 144 145 _initSearchToggle: function() { 146 var instance = this, 147 searchToggle = '<a class="btn btn-navbar" id="searchToggleBtn"><i class="icon-search"></i></a>', 148 siteSearch, dockbar, loginbar, newNode; 149 150 var listener = function(event) { 151 A.one('#site-search').toggleClass('show'); 152 }; 153 154 siteSearch = A.one('#site-search'); 155 dockbar = A.one('#_145_dockbarResponsiveButton'); 156 loginbar = A.one(LOGINBAR_ID); 157 158 if(siteSearch && (dockbar || loginbar)) { 159 newNode = A.Node.create(searchToggle); 160 newNode.on('click', listener); 161 if(dockbar) { 162 dockbar.append(newNode); 163 } else { 164 loginbar.placeAfter(newNode); 165 } 166 newNode.show(); 167 } 168 }, 169 170 _initNavigationToggle: function () { 171 var loginForm = A.one("#loginbar form"); 172 var navigation = A.one(Liferay.Data.NAV_SELECTOR); 173 var btnNavigation = A.one(LOGINBAR_ID); 174 175 if (!loginForm && btnNavigation && navigation) { 176 console.log("[_initNavigationToggle] no login form found! add our listener!"); 177 btnNavigation.on( 178 'click', 179 function(event) { 180 btnNavigation.toggleClass('open'); 181 navigation.toggleClass('open'); 182 } 183 ); 184 } 185 }, 186 187 // COMPATIBILITY WITH OLD SEARCH 188 _initShoppingCart: function() { 189 var instance = this; 190 /* no user is signed in so nothing to do */ 191 if(!A.one('#cart')) { 192 //console.warn("[_initShoppingCart] cart id not found"); 193 return; 194 } 195 196 /* if the main.js file isn't present do nothing */ 197 if( typeof shoppingCartStatus === "undefined" ) { 198 //console.warn('[_initShoppingCart] ShoppingCartFrontendPortlet main.js not found'); 199 return; 200 } 201 202 /* get initial quantity */ 203 shoppingCartStatus.getItemsQuantity(instance._cartGetQuantityCallback); 204 205 /* initialize event listener */ 206 instance._cartClearedListener = A.Global.on("shopping-cart:cart-empty", function() { 207 if (DEBUG) console.log('[_initShoppingCart] event cartCleared fired'); 208 shoppingCartStatus.getItemsQuantity(instance._cartGetQuantityCallback); 209 }); 210 211 instance._cartRemovedListener = A.Global.on("shopping-cart:item-removed", function() { 212 if (DEBUG) console.log('[_initShoppingCart] event cartItemRemoved fired'); 213 shoppingCartStatus.getItemsQuantity(instance._cartGetQuantityCallback); 214 }); 215 216 if (typeof shoppingCart !== 'undefined') { 217 instance._cartAddeddListener = shoppingCart.on("cartItemAdded", function() { 218 if (DEBUG) console.log('[_initShoppingCart] event cartItemAdded fired'); 219 shoppingCartStatus.getItemsQuantity(instance._cartGetQuantityCallback); 220 }); 221 } 222 }, 223 // COMPATIBILITY WITH OLD SEARCH END 224 225 226 /** 227 * is automatically called after object creation 228 * @method 229 */ 230 initializer: function() { 231 if (DEBUG) console.log("[initializer]"); 232 var instance = this; 233 234 instance._initIE11Workaround(); 235 instance._initContactSlider(); 236 instance._initPageCustomizationForm(); 237 instance._initImpersonatingHint(); 238 instance._initSearchToggle();
239 instance._initNavigationToggle(); 240 241 // COMPATIBILITY WITH OLD SEARCH 242 instance._initShoppingCart(); 243 // COMPATIBILITY WITH OLD SEARCH END 244 245 } 246 }, { 247 ATTRS: { 248 contactSliderDuration: { value: 0.5 } 249 } 250 }); 251 252 A.OwidiBlue.getText = function(key) { 253 return Liferay.Language.get(key); 254 }; 255 }, 256 '1.0.0', 257 { 258 requires: ['base', 'node', 'transition', 'selector-native' , 'liferay-language'] 259 } 260); 261 262jQuery("html").addClass("site-" + document.location.hostname.split(".").slice(-2).join("-"));
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.