Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: static/js/main.js

Issue 29559620: Issue 5692 - Create Browser Selector with Browser Detection Component for help.eyeo.com (Closed) Base URL: https://hg.adblockplus.org/help.eyeo.com
Left Patch Set: Indentation Created Nov. 1, 2017, 12:34 p.m.
Right Patch Set: Re-add browser-select include, add scripts block Created Nov. 2, 2017, 2:29 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « static/img/svg/arrow-icon-down-secondary.svg ('k') | static/js/vendor/bowser.js » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 (function(){ 1 (function()
2 {
2 document.addEventListener("DOMContentLoaded", function() 3 document.addEventListener("DOMContentLoaded", function()
3 { 4 {
4 5
5 /************************************************************************** 6 /**************************************************************************
6 * General 7 * General
7 **************************************************************************/ 8 **************************************************************************/
8 9
9 // Change html class name from "no-js" to "js" 10 // Change html class name from "no-js" to "js"
10 document.documentElement.className = "js"; 11 document.documentElement.className = "js";
11 12
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 229
229 /************************************************************************** 230 /**************************************************************************
230 * BrowserSelect 231 * BrowserSelect
231 **************************************************************************/ 232 **************************************************************************/
232 233
233 function BrowserSelect(select) 234 function BrowserSelect(select)
234 { 235 {
235 this.select = select; 236 this.select = select;
236 CustomSelect.apply(this, [this.select]); 237 CustomSelect.apply(this, [this.select]);
237 238
238 this.DEFAULT_BROWSER = "chrome";
239 this.BROWSER_STORAGE_KEY = "BROWSER"; 239 this.BROWSER_STORAGE_KEY = "BROWSER";
240 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED"; 240 this.BROWSER_AUTODETECTED_STORAGE_KEY = "BROWSER_AUTODETECTED";
241 this.SUPPORTED_BROWSERS = ["chrome", "opera", "samsungBrowser",
242 "yandexbrowser", "maxthon", "msie",
243 "msedge", "firefox", "ios", "safari"];
244 this.DEFAULT_BROWSER = "chrome";
241 245
242 this.select 246 this.select
243 .addEventListener("click", this._onClickOrKeyDown.bind(this), false); 247 .addEventListener("click", this._onClickOrKeyDown.bind(this), false);
244 248
245 this.select 249 this.select
246 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false); 250 .addEventListener("keydown", this._onClickOrKeyDown.bind(this), false);
247 251
248 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY); 252 var storedBrowser = localStorage.getItem(this.BROWSER_STORAGE_KEY);
249 if (storedBrowser) this.selectOption(storedBrowser); 253 if (storedBrowser) this.selectOption(storedBrowser);
250 else this.detectBrowser(); 254 else this.detectBrowser();
251 } 255 }
252 256
253 BrowserSelect.prototype = Object.create(CustomSelect.prototype); 257 BrowserSelect.prototype = Object.create(CustomSelect.prototype);
254 BrowserSelect.prototype.constructor = BrowserSelect; 258 BrowserSelect.prototype.constructor = BrowserSelect;
255 259
256 BrowserSelect.prototype.detectBrowser = function() 260 BrowserSelect.prototype.detectBrowser = function()
257 { 261 {
258 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true"); 262 for (var i = 0; i < this.SUPPORTED_BROWSERS.length; i++)
259 263 {
260 var browser; 264 var supportedBrowser = this.SUPPORTED_BROWSERS[i];
261 if (bowser.chrome) browser = "chrome"; 265 if (bowser[supportedBrowser])
262 else if (bowser.opera) browser = "opera"; 266 {
263 else if (bowser.coast) browser = "opera"; 267 localStorage.setItem(this.BROWSER_AUTODETECTED_STORAGE_KEY, "true");
264 else if (bowser.samsungBrowser) browser = "samsung"; 268 return this.selectOption(supportedBrowser);
265 else if (bowser.yandexbrowser) browser = "yandex"; 269 }
266 else if (bowser.maxthon) browser = "maxthon"; 270 }
267 else if (bowser.msie) browser = "ie"; 271
268 else if (bowser.msedge) browser = "edge"; 272 this.selectOption(this.DEFAULT_BROWSER);
269 else if (bowser.firefox) browser = "firefox";
270 else if (bowser.ios) browser = "ios";
271 else if (bowser.safari) browser = "safari";
272 else
273 {
274 localStorage.removeItem(this.BROWSER_AUTODETECTED_STORAGE_KEY);
275 browser = this.DEFAULT_BROWSER;
276 }
277
278 this.selectOption(browser);
279 }; 273 };
280 274
281 BrowserSelect.prototype.selectOption = function(browser) 275 BrowserSelect.prototype.selectOption = function(browser)
282 { 276 {
283 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser); 277 localStorage.setItem(this.BROWSER_STORAGE_KEY, browser);
284 278
285 // Change body class 279 // Change body class
286 var bodyClassList = Array.prototype.slice.call(document.body.classList); 280 var bodyClassList = Array.prototype.slice.call(document.body.classList);
287 for (var i = 0; i < bodyClassList.length; i++) 281 for (var i = 0; i < bodyClassList.length; i++)
288 { 282 {
289 if (bodyClassList[i].indexOf('ua-') > -1) 283 if (bodyClassList[i].indexOf('ua-') > -1)
290 { 284 {
291 document.body.classList.remove(bodyClassList[i]); 285 document.body.classList.remove(bodyClassList[i]);
292 } 286 }
293 } 287 }
294 document.body.classList.add("ua-" + browser); 288 document.body.classList.add("ua-" + browser);
295 289
296 // Check selected option 290 // Check selected option
297 var selectedItem = this.select 291 var selectedItem = this.select
298 .querySelector("[data-value='" + browser + "']"); 292 .querySelector("[data-value='" + browser + "']");
ire 2017/11/01 12:36:49 @julian Is this what you mean?
juliandoucette 2017/11/01 12:49:21 Yes. RE: kzar's comment. I think kzar debunked m
ire 2017/11/01 17:20:12 Okay, I prefer my way then :p
299 selectedItem.setAttribute("aria-checked", "true"); 293 selectedItem.setAttribute("aria-checked", "true");
300 294
301 // Set selected option 295 // Set selected option
302 var selectedOption = selectedItem.innerHTML; 296 var selectedOption = selectedItem.innerHTML;
303 297
304 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY)) 298 if (localStorage.getItem(this.BROWSER_AUTODETECTED_STORAGE_KEY))
305 { 299 {
306 var autodetected = document 300 var autodetected = document
307 .getElementById('browser-select-autodetected') 301 .getElementById('browser-select-autodetected')
308 .innerHTML; 302 .innerHTML;
(...skipping 25 matching lines...) Expand all
334 }; 328 };
335 329
336 var browserSelect = document.getElementById("browser-select"); 330 var browserSelect = document.getElementById("browser-select");
337 if (browserSelect) 331 if (browserSelect)
338 { 332 {
339 new BrowserSelect(browserSelect); 333 new BrowserSelect(browserSelect);
340 } 334 }
341 335
342 }, false); 336 }, false);
343 }()); 337 }());
LEFTRIGHT

Powered by Google App Engine
This is Rietveld