├── .gitignore ├── .travis.yml ├── webpack.config.js ├── package.json ├── LICENSE ├── karma.conf.js ├── README.md ├── test └── test.js ├── showIf.js └── dist └── showif.js /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | /node_modules 3 | /npm-debug.log 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | cache: 3 | directories: 4 | - node_modules 5 | node_js: 6 | - "8" 7 | before_install: 8 | - export DISPLAY=:99.0 9 | - sh -e /etc/init.d/xvfb start 10 | before_script: 11 | - npm install -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | var path = require('path'); 2 | var webpack = require('webpack'); 3 | module.exports = { 4 | entry: { 5 | path: path.resolve(__dirname), 6 | filename: 'showif.js' 7 | }, 8 | output: { 9 | path: path.resolve(__dirname, 'dist'), 10 | filename: 'showif.js' 11 | } 12 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "showif", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "showIf.js", 6 | "scripts": { 7 | "test": "./node_modules/.bin/karma start ./karma.conf.js --single-run --browsers Firefox" 8 | }, 9 | "author": "Hosein2398 (google.com)", 10 | "license": "MIT", 11 | "repository": { 12 | "type": "git", 13 | "url": "https://github.com/hosein2398/showIf" 14 | }, 15 | "dependencies": { 16 | "platform": "^1.3.4" 17 | }, 18 | "devDependencies": { 19 | "karma": "^3.0.0", 20 | "karma-chrome-launcher": "^2.2.0", 21 | "karma-firefox-launcher": "^1.0.1", 22 | "karma-mocha": "^1.3.0", 23 | "karma-webpack": "^3.0.0", 24 | "mocha": "^5.0.0", 25 | "webpack": "^4.0.0" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Hosein Barzegaran 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Thu Aug 24 2017 17:43:21 GMT+0330 (Iran Standard Time) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: './', 9 | 10 | 11 | // frameworks to use 12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 13 | frameworks: ['mocha'], 14 | 15 | 16 | // list of files / patterns to load in the browser 17 | files: [ 18 | // './showif.js', 19 | './test/*.js' 20 | ], 21 | 22 | 23 | // list of files to exclude 24 | exclude: [ 25 | ], 26 | 27 | 28 | // preprocess matching files before serving them to the browser 29 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 30 | preprocessors: { 31 | './test/*.js': ['webpack'] 32 | // './showif.js' :['webpack'] 33 | 34 | }, 35 | 36 | 37 | // test results reporter to use 38 | // possible values: 'dots', 'progress' 39 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 40 | reporters: ['progress'], 41 | 42 | 43 | // web server port 44 | port: 9876, 45 | 46 | 47 | // enable / disable colors in the output (reporters and logs) 48 | colors: true, 49 | 50 | 51 | // level of logging 52 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 53 | logLevel: config.LOG_INFO, 54 | 55 | 56 | // enable / disable watching file and executing tests whenever any file changes 57 | autoWatch: true, 58 | 59 | 60 | // start these browsers 61 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 62 | browsers: ['Chrome','Firefox'], 63 | 64 | // Continuous Integration mode 65 | // if true, Karma captures browsers, runs the tests and exits 66 | singleRun: false, 67 | 68 | // Concurrency level 69 | // how many browser should be started simultaneous 70 | concurrency: Infinity 71 | }) 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # ShowIf ![Build](https://img.shields.io/travis/hosein2398/showIf.svg) ![Dependencies](https://img.shields.io/david/hosein2398/showIf.svg) ![Devdependencies](https://img.shields.io/david/dev/hosein2398/showIf.svg) ![Greenkeeper badge](https://badges.greenkeeper.io/hosein2398/showIf.svg) 4 | 5 | Conditionally show/hide elements on your page depending on what user's browser is. 6 | 7 | ## Installing 8 | ``` 9 | npm i showif --save 10 | ``` 11 | and if you want to use in browser, you can use showif.js in dist folder: 12 | ```js 13 | 14 | ``` 15 | ## Usage 16 | There are three approaches to use this library. 17 | - Show/hide an element based on type of user's browser. 18 | - Show/hide an element based on type and version of user's browser. 19 | - Add/remove a className based on type and version of user's browser. 20 | 21 | 22 | So now lets try out each one with examples. 23 | For first one you need to add wanted className to the element for instance if you want to hide a element only on chrome you can write: 24 | ```html 25 |
not shown in Chrome
26 |
not shown in Firefox
27 | ``` 28 | So they are obvious enough to understand. 29 | 30 | --- 31 | 32 | For second approach which you can also define the browser's version here goes an example: 33 | ```html 34 |
Lorem!....
35 | ``` 36 | This one will only be shown if the browser is Firefox and also if it's version is higher than 56. 37 | Let's check out another one: 38 | ```html 39 |
Say nothing
40 | ``` 41 | This will only be represented in Firefox 55 ! 42 | Absolutely you can do contrary like : 43 | ```html 44 |
Say nothing
45 | ``` 46 | This will be hidden in Chrome with version less than 55 . (or shown in Chrome with v. higher than 55) 47 | 48 | --- 49 | 50 | Now the third approach , which you can define your condition and also the class you want to be embedded when that condition goes right : 51 | ```html 52 |

Yeah

53 | ``` 54 | So this will add class of `myclass` to this tag if user is in Chrome. Let's see another one: 55 | ```html 56 |
Sunday
57 | ``` 58 | So this will add the classes `myclass` and `bold-it` to this element if user's in Chrome and it's version is higher that 54. 59 | 60 | --- 61 | 62 | Now last one: 63 | 64 | ```html 65 |

Working on it

66 | ``` 67 | This one will have `reddy` class only in Chrome 56. Which is quite usefull. 68 | 69 | ## How this works 70 | So , you as a designer might ask that how this library works. After looping throw elements if the condition is not met as the browser in use, then display of none is added to that element. 71 | 72 | ## Supported browsers 73 | These browsers are supported for now: 74 | - Chrome 75 | - Firefox 76 | - IE 77 | - Safary 78 | 79 | 80 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | var showif = require('../showIf'); 2 | var assert = require('assert'); 3 | 4 | describe('ShowIf test', function () { 5 | 6 | it('type of browser version should be number', function () { 7 | assert.equal('number', typeof +showif.BROWSER_VERSION); 8 | }); 9 | 10 | it('type of browser name should be string', function () { 11 | assert.equal('string', typeof showif.BROWSER_NAME); 12 | }); 13 | 14 | it('testing functionaly of renderRegex().version', function () { 15 | var element = document.createElement('div'); 16 | element.setAttribute("class", "show-if-firefox(>56)"); 17 | document.body.appendChild(element); 18 | assert.equal( +showif.renderRegex(element).version, 56); 19 | }); 20 | 21 | it('testing functionaly of renderRegex().type', function () { 22 | var element = document.createElement('div'); 23 | element.setAttribute("class", "show-if-firefox(>56)"); 24 | document.body.appendChild(element); 25 | assert.equal( showif.renderRegex(element).type, 'greater'); 26 | }); 27 | 28 | it('testing functionaly of renderRegex().type', function () { 29 | var element = document.createElement('div'); 30 | element.setAttribute("class", "show-if-firefox(=56)"); 31 | document.body.appendChild(element); 32 | assert.equal( showif.renderRegex(element).type, 'equal'); 33 | }); 34 | 35 | it('testing functionaly of renderRegex().type', function () { 36 | var element = document.createElement('div'); 37 | element.setAttribute("class", "show-if-firefox(<56)"); 38 | document.body.appendChild(element); 39 | assert.equal( showif.renderRegex(element).type, 'lower'); 40 | }); 41 | 42 | it('testing functionaly of (renderRegex_for_data).type', function () { 43 | var element = document.createElement("div"); 44 | element.setAttribute("data-if-chrome", "(>55) classname"); 45 | assert.equal('string', typeof showif.renderRegex_for_data(element, 'data-if-chrome').type); 46 | }); 47 | 48 | it('testing functionaly of (renderRegex_for_data).type', function () { 49 | var element = document.createElement("div"); 50 | element.setAttribute("data-if-chrome", "(>55) classname"); 51 | assert.equal('greater', showif.renderRegex_for_data(element, 'data-if-chrome').type); 52 | }); 53 | 54 | it('testing functionaly of (renderRegex_for_data).type', function () { 55 | var element = document.createElement("div"); 56 | element.setAttribute("data-if-chrome", "(<55) classname"); 57 | assert.equal('lower', showif.renderRegex_for_data(element, 'data-if-chrome').type); 58 | }); 59 | 60 | it('testing functionaly of (renderRegex_for_data).type', function () { 61 | var element = document.createElement("div"); 62 | element.setAttribute("data-if-chrome", "(=55) classname"); 63 | assert.equal('equal', showif.renderRegex_for_data(element, 'data-if-chrome').type); 64 | }); 65 | 66 | it('testing functionaly of (renderRegex_for_data).version', function () { 67 | var element = document.createElement("div"); 68 | element.setAttribute("data-if-chrome", "(>57) classname"); 69 | assert.equal(57, showif.renderRegex_for_data(element, 'data-if-chrome').version); 70 | }); 71 | 72 | it('testing functionaly of iterate_to_hide()', function () { 73 | var element = document.createElement("div"); 74 | element.setAttribute("style", "display:block"); 75 | document.body.appendChild(element); 76 | showif.iterate_to_hide(document.getElementsByTagName('div')); 77 | assert.equal('none', element.style.display); 78 | }); 79 | 80 | it('testing functionaly of iterate_to_show()', function () { 81 | var element = document.createElement("div"); 82 | element.setAttribute("style", "display:none"); 83 | document.body.appendChild(element); 84 | showif.iterate_to_show(document.getElementsByTagName('div')); 85 | assert.equal('block', element.style.display); 86 | }); 87 | 88 | it('testing functionaly of iterate_data_without_rule() showing the tag', function () { 89 | var element = document.createElement('div'); 90 | element.setAttribute("data-if-chrome", "(>56) myclass"); 91 | document.body.appendChild(element); 92 | showif.iterate_data_without_rule(document.querySelectorAll("*[data-if-chrome]") , 'data-if-chrome' , 60); 93 | assert.equal(' myclass', element.getAttribute('class')); 94 | }); 95 | 96 | it('testing functionaly of iterate_data_without_rule() not showing the tag', function () { 97 | var element = document.createElement('div'); 98 | element.setAttribute("data-if-chrome", "(<56) myclass"); 99 | document.body.appendChild(element); 100 | showif.iterate_data_without_rule(document.querySelectorAll("*[data-if-chrome]") , 'data-if-chrome' , 60); 101 | assert.equal( null , element.getAttribute('class')); 102 | }); 103 | 104 | it('testing functionaly of iterate_class_with_v() showing the tag', function () { 105 | var element = document.createElement('div'); 106 | element.setAttribute("class", "show-if-chrome(>58)"); 107 | document.body.appendChild(element); 108 | showif.iterate_class_with_v(document.querySelectorAll('[class^="show-if-chrome("]') , 60); 109 | assert.equal('block', element.style.display); 110 | }); 111 | 112 | it('testing functionaly of iterate_class_with_v() not showing the tag', function () { 113 | var element = document.createElement('div'); 114 | element.setAttribute("class", "show-if-chrome(<58)"); 115 | document.body.appendChild(element); 116 | showif.iterate_class_with_v(document.querySelectorAll('[class^="show-if-chrome("]') , 60); 117 | assert.equal('none', element.style.display); 118 | }); 119 | 120 | it('testing functionaly of iterate_class_with_v() not showing the tag (type 2)', function () { 121 | var element = document.createElement('div'); 122 | element.setAttribute("class", "show-if-chrome(>58)"); 123 | document.body.appendChild(element); 124 | showif.iterate_class_with_v(document.querySelectorAll('[class^="show-if-chrome("]') , 60); 125 | assert.equal('block', element.style.display); 126 | }); 127 | 128 | 129 | }); -------------------------------------------------------------------------------- /showIf.js: -------------------------------------------------------------------------------- 1 | var platform = require('platform'); 2 | 3 | 4 | var BROWSER_NAME = platform.name; 5 | // var BROWSER_VERSION = platform.version; 6 | var BROWSER_VERSION = platform.version.substr(0, 2); 7 | console.log(platform.name); 8 | console.log(BROWSER_VERSION) 9 | 10 | function iterate_to_hide(browser) { 11 | if (browser.length > 0) { 12 | for (var i = 0; i < browser.length; i++) { 13 | browser[i].style.display = 'none'; 14 | } 15 | } 16 | } 17 | 18 | function iterate_to_show(browser) { 19 | if (browser.length > 0) { 20 | for (var i = 0; i < browser.length; i++) { 21 | browser[i].style.display = 'block'; 22 | } 23 | } 24 | } 25 | 26 | function iterate_data_without_rule(browser, atname, browser_v) { 27 | if (browser.length > 0) { 28 | var patt = /\(.*\)/g; 29 | for (var i = 0; i < browser.length; i++) { 30 | var tocheck = browser[i].getAttribute(atname); 31 | var newclass = browser[i].getAttribute(atname).replace(patt, ""); 32 | var lastclass; 33 | if (browser[i].getAttribute("class")) { 34 | lastclass = browser[i].getAttribute("class"); 35 | } else { 36 | lastclass = ""; 37 | } 38 | if (patt.test(tocheck)) { 39 | 40 | var newclassdata = browser[i].getAttribute(atname).replace(patt, " "); 41 | var t = renderRegex_for_data(browser[i], atname); 42 | if (t.type === "greater" && t.version < browser_v) { 43 | browser[i].setAttribute("class", lastclass + newclass); 44 | } 45 | if (t.type === "lower" && t.version > browser_v) { 46 | browser[i].setAttribute("class", lastclass + newclass); 47 | } 48 | if (t.type === "equal" && t.version == browser_v) { 49 | browser[i].setAttribute("class", lastclass + newclass); 50 | } 51 | } else { 52 | browser[i].setAttribute("class", lastclass + " " + newclass); 53 | } 54 | } 55 | } 56 | } 57 | 58 | function iterate_class_with_v(browser, browser_v) { 59 | if (browser.length > 0) { 60 | for (var i = 0; i < browser.length; i++) { 61 | var t = renderRegex(browser[i]); 62 | console.log(t.version); 63 | if (t.type === "greater" && t.version < browser_v) { 64 | browser[i].style.display = 'block'; 65 | console.log("greater") 66 | } else if (t.type === "lower" && t.version > browser_v) { 67 | browser[i].style.display = 'block'; 68 | } else if (t.type === "equal" && t.version == browser_v) { 69 | browser[i].style.display = 'block'; 70 | } else { 71 | browser[i].style.display = 'none'; 72 | } 73 | } 74 | } 75 | } 76 | 77 | function renderRegex(that) { 78 | var res = that.getAttribute("class").match(/\(.*\)/)[0]; 79 | var length = res.length; 80 | var value = res.substr(2, length - 3); 81 | var typeraw = res.substr(1, 1); 82 | var type; 83 | switch (typeraw) { 84 | case ">": 85 | type = "greater"; 86 | break; 87 | case "<": 88 | type = "lower"; 89 | break; 90 | case "=": 91 | type = "equal"; 92 | break; 93 | } 94 | return { 95 | version: value, 96 | type: type 97 | } 98 | 99 | } 100 | 101 | function renderRegex_for_data(that, attr) { 102 | var res = that.getAttribute(attr).match(/\(.*\)/)[0]; 103 | var length = res.length; 104 | var value = res.substr(2, length - 3); 105 | var typeraw = res.substr(1, 1); 106 | var type; 107 | switch (typeraw) { 108 | case ">": 109 | type = "greater"; 110 | break; 111 | case "<": 112 | type = "lower"; 113 | break; 114 | case "=": 115 | type = "equal"; 116 | break; 117 | } 118 | return { 119 | version: value, 120 | type: type 121 | } 122 | } 123 | 124 | /* Show if if with version in class */ 125 | var fire_fox_class_with_v = document.querySelectorAll('[class^="show-if-firefox("]'); 126 | var chrome_class_with_v = document.querySelectorAll('[class^="show-if-chrome("]'); 127 | var ie_class_with_v = document.querySelectorAll('[class^="show-if-ie("]'); 128 | var safary_class_with_v = document.querySelectorAll('[class^="show-if-safary("]'); 129 | 130 | 131 | /* typical show if */ 132 | var show_if_firefox = document.getElementsByClassName("show-if-firefox"); 133 | var show_if_chrome = document.getElementsByClassName("show-if-chrome"); 134 | var show_if_ie = document.getElementsByClassName("show-if-ie"); 135 | var show_if_safay = document.getElementsByClassName("show-if-safary"); 136 | 137 | 138 | /* typical hide if */ 139 | var hide_if_firefox = document.getElementsByClassName("hide-if-firefox"); 140 | var hide_if_chrome = document.getElementsByClassName("hide-if-chrome"); 141 | var hide_if_ie = document.getElementsByClassName("hide-if-ie"); 142 | var hide_if_safary = document.getElementsByClassName("hide-if-safary"); 143 | 144 | /* typical data change class */ 145 | var chrome_typical_data = document.querySelectorAll("*[data-if-chrome]"); 146 | var firefox_typical_data = document.querySelectorAll("*[data-if-firefox]"); 147 | var ie_typical_data = document.querySelectorAll("*[data-if-ie]"); 148 | var safary_typical_data = document.querySelectorAll("*[data-if-safary]"); 149 | 150 | 151 | /* if statments for browsers */ 152 | if (navigator.userAgent.includes("Chrome")) { 153 | iterate_to_show(show_if_chrome); 154 | iterate_data_without_rule(chrome_typical_data, "data-if-chrome", BROWSER_VERSION); 155 | iterate_to_hide(hide_if_chrome); 156 | iterate_class_with_v(chrome_class_with_v, BROWSER_VERSION); 157 | 158 | } 159 | if (navigator.userAgent.includes("Firefox")) { 160 | iterate_to_show(show_if_firefox); 161 | iterate_data_without_rule(firefox_typical_data, "data-if-firefox", BROWSER_VERSION); 162 | iterate_to_hide(hide_if_firefox); 163 | iterate_class_with_v(fire_fox_class_with_v, BROWSER_VERSION); 164 | } 165 | if (navigator.userAgent.includes("IE")) { 166 | iterate_to_show(show_if_ie); 167 | iterate_data_without_rule(ie_typical_data, "data-if-ie", BROWSER_VERSION); 168 | iterate_to_hide(hide_if_ie); 169 | iterate_class_with_v(ie_class_with_v, BROWSER_VERSION); 170 | } 171 | if (navigator.userAgent.includes("Safary")) { 172 | iterate_to_show(show_if_safary); 173 | iterate_data_without_rule(safary_typical_data, "data-if-safary", BROWSER_VERSION); 174 | iterate_to_hide(hide_if_safary); 175 | iterate_class_with_v(safary_class_with_v, BROWSER_VERSION); 176 | } 177 | 178 | module.exports = { 179 | BROWSER_VERSION: BROWSER_VERSION, 180 | BROWSER_NAME: BROWSER_NAME, 181 | renderRegex_for_data: renderRegex_for_data, 182 | iterate_to_show: iterate_to_show, 183 | iterate_to_hide: iterate_to_hide, 184 | iterate_data_without_rule: iterate_data_without_rule, 185 | iterate_class_with_v: iterate_class_with_v, 186 | renderRegex: renderRegex 187 | } -------------------------------------------------------------------------------- /dist/showif.js: -------------------------------------------------------------------------------- 1 | /******/ (function(modules) { // webpackBootstrap 2 | /******/ // The module cache 3 | /******/ var installedModules = {}; 4 | /******/ 5 | /******/ // The require function 6 | /******/ function __webpack_require__(moduleId) { 7 | /******/ 8 | /******/ // Check if module is in cache 9 | /******/ if(installedModules[moduleId]) { 10 | /******/ return installedModules[moduleId].exports; 11 | /******/ } 12 | /******/ // Create a new module (and put it into the cache) 13 | /******/ var module = installedModules[moduleId] = { 14 | /******/ i: moduleId, 15 | /******/ l: false, 16 | /******/ exports: {} 17 | /******/ }; 18 | /******/ 19 | /******/ // Execute the module function 20 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 21 | /******/ 22 | /******/ // Flag the module as loaded 23 | /******/ module.l = true; 24 | /******/ 25 | /******/ // Return the exports of the module 26 | /******/ return module.exports; 27 | /******/ } 28 | /******/ 29 | /******/ 30 | /******/ // expose the modules object (__webpack_modules__) 31 | /******/ __webpack_require__.m = modules; 32 | /******/ 33 | /******/ // expose the module cache 34 | /******/ __webpack_require__.c = installedModules; 35 | /******/ 36 | /******/ // define getter function for harmony exports 37 | /******/ __webpack_require__.d = function(exports, name, getter) { 38 | /******/ if(!__webpack_require__.o(exports, name)) { 39 | /******/ Object.defineProperty(exports, name, { 40 | /******/ configurable: false, 41 | /******/ enumerable: true, 42 | /******/ get: getter 43 | /******/ }); 44 | /******/ } 45 | /******/ }; 46 | /******/ 47 | /******/ // getDefaultExport function for compatibility with non-harmony modules 48 | /******/ __webpack_require__.n = function(module) { 49 | /******/ var getter = module && module.__esModule ? 50 | /******/ function getDefault() { return module['default']; } : 51 | /******/ function getModuleExports() { return module; }; 52 | /******/ __webpack_require__.d(getter, 'a', getter); 53 | /******/ return getter; 54 | /******/ }; 55 | /******/ 56 | /******/ // Object.prototype.hasOwnProperty.call 57 | /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; 58 | /******/ 59 | /******/ // __webpack_public_path__ 60 | /******/ __webpack_require__.p = ""; 61 | /******/ 62 | /******/ // Load entry module and return exports 63 | /******/ return __webpack_require__(__webpack_require__.s = 0); 64 | /******/ }) 65 | /************************************************************************/ 66 | /******/ ([ 67 | /* 0 */ 68 | /***/ (function(module, exports, __webpack_require__) { 69 | 70 | var platform = __webpack_require__(1); 71 | 72 | 73 | var BROWSER_NAME = platform.name; 74 | // var BROWSER_VERSION = platform.version; 75 | var BROWSER_VERSION = platform.version.substr(0, 2); 76 | console.log(platform.name); 77 | console.log(BROWSER_VERSION) 78 | 79 | function iterate_to_hide(browser) { 80 | if (browser.length > 0) { 81 | for (var i = 0; i < browser.length; i++) { 82 | browser[i].style.display = 'none'; 83 | } 84 | } 85 | } 86 | 87 | function iterate_to_show(browser) { 88 | if (browser.length > 0) { 89 | for (var i = 0; i < browser.length; i++) { 90 | browser[i].style.display = 'block'; 91 | } 92 | } 93 | } 94 | 95 | function iterate_data_without_rule(browser, atname, browser_v) { 96 | if (browser.length > 0) { 97 | var patt = /\(.*\)/g; 98 | for (var i = 0; i < browser.length; i++) { 99 | var tocheck = browser[i].getAttribute(atname); 100 | var newclass = browser[i].getAttribute(atname).replace(patt, ""); 101 | var lastclass; 102 | if (browser[i].getAttribute("class")) { 103 | lastclass = browser[i].getAttribute("class"); 104 | } else { 105 | lastclass = ""; 106 | } 107 | if (patt.test(tocheck)) { 108 | 109 | var newclassdata = browser[i].getAttribute(atname).replace(patt, " "); 110 | var t = renderRegex_for_data(browser[i], atname); 111 | if (t.type === "greater" && t.version < browser_v) { 112 | browser[i].setAttribute("class", lastclass + newclass); 113 | } 114 | if (t.type === "lower" && t.version > browser_v) { 115 | browser[i].setAttribute("class", lastclass + newclass); 116 | } 117 | if (t.type === "equal" && t.version == browser_v) { 118 | browser[i].setAttribute("class", lastclass + newclass); 119 | } 120 | } else { 121 | browser[i].setAttribute("class", lastclass + " " + newclass); 122 | } 123 | } 124 | } 125 | } 126 | 127 | function iterate_class_with_v(browser, browser_v) { 128 | if (browser.length > 0) { 129 | for (var i = 0; i < browser.length; i++) { 130 | var t = renderRegex(browser[i]); 131 | console.log(t.version); 132 | if (t.type === "greater" && t.version < browser_v) { 133 | browser[i].style.display = 'block'; 134 | console.log("greater") 135 | } else if (t.type === "lower" && t.version > browser_v) { 136 | browser[i].style.display = 'block'; 137 | } else if (t.type === "equal" && t.version == browser_v) { 138 | browser[i].style.display = 'block'; 139 | } else { 140 | browser[i].style.display = 'none'; 141 | } 142 | } 143 | } 144 | } 145 | 146 | function renderRegex(that) { 147 | var res = that.getAttribute("class").match(/\(.*\)/)[0]; 148 | var length = res.length; 149 | var value = res.substr(2, length - 3); 150 | var typeraw = res.substr(1, 1); 151 | var type; 152 | switch (typeraw) { 153 | case ">": 154 | type = "greater"; 155 | break; 156 | case "<": 157 | type = "lower"; 158 | break; 159 | case "=": 160 | type = "equal"; 161 | break; 162 | } 163 | return { 164 | version: value, 165 | type: type 166 | } 167 | 168 | } 169 | 170 | function renderRegex_for_data(that, attr) { 171 | var res = that.getAttribute(attr).match(/\(.*\)/)[0]; 172 | var length = res.length; 173 | var value = res.substr(2, length - 3); 174 | var typeraw = res.substr(1, 1); 175 | var type; 176 | switch (typeraw) { 177 | case ">": 178 | type = "greater"; 179 | break; 180 | case "<": 181 | type = "lower"; 182 | break; 183 | case "=": 184 | type = "equal"; 185 | break; 186 | } 187 | return { 188 | version: value, 189 | type: type 190 | } 191 | } 192 | 193 | /* Show if if with version in class */ 194 | var fire_fox_class_with_v = document.querySelectorAll('[class^="show-if-firefox("]'); 195 | var chrome_class_with_v = document.querySelectorAll('[class^="show-if-chrome("]'); 196 | var ie_class_with_v = document.querySelectorAll('[class^="show-if-ie("]'); 197 | var safary_class_with_v = document.querySelectorAll('[class^="show-if-safary("]'); 198 | 199 | 200 | /* typical show if */ 201 | var show_if_firefox = document.getElementsByClassName("show-if-firefox"); 202 | var show_if_chrome = document.getElementsByClassName("show-if-chrome"); 203 | var show_if_ie = document.getElementsByClassName("show-if-ie"); 204 | var show_if_safay = document.getElementsByClassName("show-if-safary"); 205 | 206 | 207 | /* typical hide if */ 208 | var hide_if_firefox = document.getElementsByClassName("hide-if-firefox"); 209 | var hide_if_chrome = document.getElementsByClassName("hide-if-chrome"); 210 | var hide_if_ie = document.getElementsByClassName("hide-if-ie"); 211 | var hide_if_safary = document.getElementsByClassName("hide-if-safary"); 212 | 213 | /* typical data change class */ 214 | var chrome_typical_data = document.querySelectorAll("*[data-if-chrome]"); 215 | var firefox_typical_data = document.querySelectorAll("*[data-if-firefox]"); 216 | var ie_typical_data = document.querySelectorAll("*[data-if-ie]"); 217 | var safary_typical_data = document.querySelectorAll("*[data-if-safary]"); 218 | 219 | 220 | /* if statments for browsers */ 221 | if (navigator.userAgent.includes("Chrome")) { 222 | iterate_to_show(show_if_chrome); 223 | iterate_data_without_rule(chrome_typical_data, "data-if-chrome", BROWSER_VERSION); 224 | iterate_to_hide(hide_if_chrome); 225 | iterate_class_with_v(chrome_class_with_v, BROWSER_VERSION); 226 | 227 | } 228 | if (navigator.userAgent.includes("Firefox")) { 229 | iterate_to_show(show_if_firefox); 230 | iterate_data_without_rule(firefox_typical_data, "data-if-firefox", BROWSER_VERSION); 231 | iterate_to_hide(hide_if_firefox); 232 | iterate_class_with_v(fire_fox_class_with_v, BROWSER_VERSION); 233 | } 234 | if (navigator.userAgent.includes("IE")) { 235 | iterate_to_show(show_if_ie); 236 | iterate_data_without_rule(ie_typical_data, "data-if-ie", BROWSER_VERSION); 237 | iterate_to_hide(hide_if_ie); 238 | iterate_class_with_v(ie_class_with_v, BROWSER_VERSION); 239 | } 240 | if (navigator.userAgent.includes("Safary")) { 241 | iterate_to_show(show_if_safary); 242 | iterate_data_without_rule(safary_typical_data, "data-if-safary", BROWSER_VERSION); 243 | iterate_to_hide(hide_if_safary); 244 | iterate_class_with_v(safary_class_with_v, BROWSER_VERSION); 245 | } 246 | 247 | module.exports = { 248 | BROWSER_VERSION: BROWSER_VERSION, 249 | BROWSER_NAME: BROWSER_NAME, 250 | renderRegex_for_data: renderRegex_for_data, 251 | iterate_to_show: iterate_to_show, 252 | iterate_to_hide: iterate_to_hide, 253 | iterate_data_without_rule: iterate_data_without_rule, 254 | iterate_class_with_v: iterate_class_with_v, 255 | renderRegex: renderRegex 256 | } 257 | 258 | /***/ }), 259 | /* 1 */ 260 | /***/ (function(module, exports, __webpack_require__) { 261 | 262 | /* WEBPACK VAR INJECTION */(function(module, global) {var __WEBPACK_AMD_DEFINE_RESULT__;/*! 263 | * Platform.js 264 | * Copyright 2014-2016 Benjamin Tan 265 | * Copyright 2011-2013 John-David Dalton 266 | * Available under MIT license 267 | */ 268 | ;(function() { 269 | 'use strict'; 270 | 271 | /** Used to determine if values are of the language type `Object`. */ 272 | var objectTypes = { 273 | 'function': true, 274 | 'object': true 275 | }; 276 | 277 | /** Used as a reference to the global object. */ 278 | var root = (objectTypes[typeof window] && window) || this; 279 | 280 | /** Backup possible global object. */ 281 | var oldRoot = root; 282 | 283 | /** Detect free variable `exports`. */ 284 | var freeExports = objectTypes[typeof exports] && exports; 285 | 286 | /** Detect free variable `module`. */ 287 | var freeModule = objectTypes[typeof module] && module && !module.nodeType && module; 288 | 289 | /** Detect free variable `global` from Node.js or Browserified code and use it as `root`. */ 290 | var freeGlobal = freeExports && freeModule && typeof global == 'object' && global; 291 | if (freeGlobal && (freeGlobal.global === freeGlobal || freeGlobal.window === freeGlobal || freeGlobal.self === freeGlobal)) { 292 | root = freeGlobal; 293 | } 294 | 295 | /** 296 | * Used as the maximum length of an array-like object. 297 | * See the [ES6 spec](http://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength) 298 | * for more details. 299 | */ 300 | var maxSafeInteger = Math.pow(2, 53) - 1; 301 | 302 | /** Regular expression to detect Opera. */ 303 | var reOpera = /\bOpera/; 304 | 305 | /** Possible global object. */ 306 | var thisBinding = this; 307 | 308 | /** Used for native method references. */ 309 | var objectProto = Object.prototype; 310 | 311 | /** Used to check for own properties of an object. */ 312 | var hasOwnProperty = objectProto.hasOwnProperty; 313 | 314 | /** Used to resolve the internal `[[Class]]` of values. */ 315 | var toString = objectProto.toString; 316 | 317 | /*--------------------------------------------------------------------------*/ 318 | 319 | /** 320 | * Capitalizes a string value. 321 | * 322 | * @private 323 | * @param {string} string The string to capitalize. 324 | * @returns {string} The capitalized string. 325 | */ 326 | function capitalize(string) { 327 | string = String(string); 328 | return string.charAt(0).toUpperCase() + string.slice(1); 329 | } 330 | 331 | /** 332 | * A utility function to clean up the OS name. 333 | * 334 | * @private 335 | * @param {string} os The OS name to clean up. 336 | * @param {string} [pattern] A `RegExp` pattern matching the OS name. 337 | * @param {string} [label] A label for the OS. 338 | */ 339 | function cleanupOS(os, pattern, label) { 340 | // Platform tokens are defined at: 341 | // http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx 342 | // http://web.archive.org/web/20081122053950/http://msdn.microsoft.com/en-us/library/ms537503(VS.85).aspx 343 | var data = { 344 | '10.0': '10', 345 | '6.4': '10 Technical Preview', 346 | '6.3': '8.1', 347 | '6.2': '8', 348 | '6.1': 'Server 2008 R2 / 7', 349 | '6.0': 'Server 2008 / Vista', 350 | '5.2': 'Server 2003 / XP 64-bit', 351 | '5.1': 'XP', 352 | '5.01': '2000 SP1', 353 | '5.0': '2000', 354 | '4.0': 'NT', 355 | '4.90': 'ME' 356 | }; 357 | // Detect Windows version from platform tokens. 358 | if (pattern && label && /^Win/i.test(os) && !/^Windows Phone /i.test(os) && 359 | (data = data[/[\d.]+$/.exec(os)])) { 360 | os = 'Windows ' + data; 361 | } 362 | // Correct character case and cleanup string. 363 | os = String(os); 364 | 365 | if (pattern && label) { 366 | os = os.replace(RegExp(pattern, 'i'), label); 367 | } 368 | 369 | os = format( 370 | os.replace(/ ce$/i, ' CE') 371 | .replace(/\bhpw/i, 'web') 372 | .replace(/\bMacintosh\b/, 'Mac OS') 373 | .replace(/_PowerPC\b/i, ' OS') 374 | .replace(/\b(OS X) [^ \d]+/i, '$1') 375 | .replace(/\bMac (OS X)\b/, '$1') 376 | .replace(/\/(\d)/, ' $1') 377 | .replace(/_/g, '.') 378 | .replace(/(?: BePC|[ .]*fc[ \d.]+)$/i, '') 379 | .replace(/\bx86\.64\b/gi, 'x86_64') 380 | .replace(/\b(Windows Phone) OS\b/, '$1') 381 | .replace(/\b(Chrome OS \w+) [\d.]+\b/, '$1') 382 | .split(' on ')[0] 383 | ); 384 | 385 | return os; 386 | } 387 | 388 | /** 389 | * An iteration utility for arrays and objects. 390 | * 391 | * @private 392 | * @param {Array|Object} object The object to iterate over. 393 | * @param {Function} callback The function called per iteration. 394 | */ 395 | function each(object, callback) { 396 | var index = -1, 397 | length = object ? object.length : 0; 398 | 399 | if (typeof length == 'number' && length > -1 && length <= maxSafeInteger) { 400 | while (++index < length) { 401 | callback(object[index], index, object); 402 | } 403 | } else { 404 | forOwn(object, callback); 405 | } 406 | } 407 | 408 | /** 409 | * Trim and conditionally capitalize string values. 410 | * 411 | * @private 412 | * @param {string} string The string to format. 413 | * @returns {string} The formatted string. 414 | */ 415 | function format(string) { 416 | string = trim(string); 417 | return /^(?:webOS|i(?:OS|P))/.test(string) 418 | ? string 419 | : capitalize(string); 420 | } 421 | 422 | /** 423 | * Iterates over an object's own properties, executing the `callback` for each. 424 | * 425 | * @private 426 | * @param {Object} object The object to iterate over. 427 | * @param {Function} callback The function executed per own property. 428 | */ 429 | function forOwn(object, callback) { 430 | for (var key in object) { 431 | if (hasOwnProperty.call(object, key)) { 432 | callback(object[key], key, object); 433 | } 434 | } 435 | } 436 | 437 | /** 438 | * Gets the internal `[[Class]]` of a value. 439 | * 440 | * @private 441 | * @param {*} value The value. 442 | * @returns {string} The `[[Class]]`. 443 | */ 444 | function getClassOf(value) { 445 | return value == null 446 | ? capitalize(value) 447 | : toString.call(value).slice(8, -1); 448 | } 449 | 450 | /** 451 | * Host objects can return type values that are different from their actual 452 | * data type. The objects we are concerned with usually return non-primitive 453 | * types of "object", "function", or "unknown". 454 | * 455 | * @private 456 | * @param {*} object The owner of the property. 457 | * @param {string} property The property to check. 458 | * @returns {boolean} Returns `true` if the property value is a non-primitive, else `false`. 459 | */ 460 | function isHostType(object, property) { 461 | var type = object != null ? typeof object[property] : 'number'; 462 | return !/^(?:boolean|number|string|undefined)$/.test(type) && 463 | (type == 'object' ? !!object[property] : true); 464 | } 465 | 466 | /** 467 | * Prepares a string for use in a `RegExp` by making hyphens and spaces optional. 468 | * 469 | * @private 470 | * @param {string} string The string to qualify. 471 | * @returns {string} The qualified string. 472 | */ 473 | function qualify(string) { 474 | return String(string).replace(/([ -])(?!$)/g, '$1?'); 475 | } 476 | 477 | /** 478 | * A bare-bones `Array#reduce` like utility function. 479 | * 480 | * @private 481 | * @param {Array} array The array to iterate over. 482 | * @param {Function} callback The function called per iteration. 483 | * @returns {*} The accumulated result. 484 | */ 485 | function reduce(array, callback) { 486 | var accumulator = null; 487 | each(array, function(value, index) { 488 | accumulator = callback(accumulator, value, index, array); 489 | }); 490 | return accumulator; 491 | } 492 | 493 | /** 494 | * Removes leading and trailing whitespace from a string. 495 | * 496 | * @private 497 | * @param {string} string The string to trim. 498 | * @returns {string} The trimmed string. 499 | */ 500 | function trim(string) { 501 | return String(string).replace(/^ +| +$/g, ''); 502 | } 503 | 504 | /*--------------------------------------------------------------------------*/ 505 | 506 | /** 507 | * Creates a new platform object. 508 | * 509 | * @memberOf platform 510 | * @param {Object|string} [ua=navigator.userAgent] The user agent string or 511 | * context object. 512 | * @returns {Object} A platform object. 513 | */ 514 | function parse(ua) { 515 | 516 | /** The environment context object. */ 517 | var context = root; 518 | 519 | /** Used to flag when a custom context is provided. */ 520 | var isCustomContext = ua && typeof ua == 'object' && getClassOf(ua) != 'String'; 521 | 522 | // Juggle arguments. 523 | if (isCustomContext) { 524 | context = ua; 525 | ua = null; 526 | } 527 | 528 | /** Browser navigator object. */ 529 | var nav = context.navigator || {}; 530 | 531 | /** Browser user agent string. */ 532 | var userAgent = nav.userAgent || ''; 533 | 534 | ua || (ua = userAgent); 535 | 536 | /** Used to flag when `thisBinding` is the [ModuleScope]. */ 537 | var isModuleScope = isCustomContext || thisBinding == oldRoot; 538 | 539 | /** Used to detect if browser is like Chrome. */ 540 | var likeChrome = isCustomContext 541 | ? !!nav.likeChrome 542 | : /\bChrome\b/.test(ua) && !/internal|\n/i.test(toString.toString()); 543 | 544 | /** Internal `[[Class]]` value shortcuts. */ 545 | var objectClass = 'Object', 546 | airRuntimeClass = isCustomContext ? objectClass : 'ScriptBridgingProxyObject', 547 | enviroClass = isCustomContext ? objectClass : 'Environment', 548 | javaClass = (isCustomContext && context.java) ? 'JavaPackage' : getClassOf(context.java), 549 | phantomClass = isCustomContext ? objectClass : 'RuntimeObject'; 550 | 551 | /** Detect Java environments. */ 552 | var java = /\bJava/.test(javaClass) && context.java; 553 | 554 | /** Detect Rhino. */ 555 | var rhino = java && getClassOf(context.environment) == enviroClass; 556 | 557 | /** A character to represent alpha. */ 558 | var alpha = java ? 'a' : '\u03b1'; 559 | 560 | /** A character to represent beta. */ 561 | var beta = java ? 'b' : '\u03b2'; 562 | 563 | /** Browser document object. */ 564 | var doc = context.document || {}; 565 | 566 | /** 567 | * Detect Opera browser (Presto-based). 568 | * http://www.howtocreate.co.uk/operaStuff/operaObject.html 569 | * http://dev.opera.com/articles/view/opera-mini-web-content-authoring-guidelines/#operamini 570 | */ 571 | var opera = context.operamini || context.opera; 572 | 573 | /** Opera `[[Class]]`. */ 574 | var operaClass = reOpera.test(operaClass = (isCustomContext && opera) ? opera['[[Class]]'] : getClassOf(opera)) 575 | ? operaClass 576 | : (opera = null); 577 | 578 | /*------------------------------------------------------------------------*/ 579 | 580 | /** Temporary variable used over the script's lifetime. */ 581 | var data; 582 | 583 | /** The CPU architecture. */ 584 | var arch = ua; 585 | 586 | /** Platform description array. */ 587 | var description = []; 588 | 589 | /** Platform alpha/beta indicator. */ 590 | var prerelease = null; 591 | 592 | /** A flag to indicate that environment features should be used to resolve the platform. */ 593 | var useFeatures = ua == userAgent; 594 | 595 | /** The browser/environment version. */ 596 | var version = useFeatures && opera && typeof opera.version == 'function' && opera.version(); 597 | 598 | /** A flag to indicate if the OS ends with "/ Version" */ 599 | var isSpecialCasedOS; 600 | 601 | /* Detectable layout engines (order is important). */ 602 | var layout = getLayout([ 603 | { 'label': 'EdgeHTML', 'pattern': 'Edge' }, 604 | 'Trident', 605 | { 'label': 'WebKit', 'pattern': 'AppleWebKit' }, 606 | 'iCab', 607 | 'Presto', 608 | 'NetFront', 609 | 'Tasman', 610 | 'KHTML', 611 | 'Gecko' 612 | ]); 613 | 614 | /* Detectable browser names (order is important). */ 615 | var name = getName([ 616 | 'Adobe AIR', 617 | 'Arora', 618 | 'Avant Browser', 619 | 'Breach', 620 | 'Camino', 621 | 'Electron', 622 | 'Epiphany', 623 | 'Fennec', 624 | 'Flock', 625 | 'Galeon', 626 | 'GreenBrowser', 627 | 'iCab', 628 | 'Iceweasel', 629 | 'K-Meleon', 630 | 'Konqueror', 631 | 'Lunascape', 632 | 'Maxthon', 633 | { 'label': 'Microsoft Edge', 'pattern': 'Edge' }, 634 | 'Midori', 635 | 'Nook Browser', 636 | 'PaleMoon', 637 | 'PhantomJS', 638 | 'Raven', 639 | 'Rekonq', 640 | 'RockMelt', 641 | { 'label': 'Samsung Internet', 'pattern': 'SamsungBrowser' }, 642 | 'SeaMonkey', 643 | { 'label': 'Silk', 'pattern': '(?:Cloud9|Silk-Accelerated)' }, 644 | 'Sleipnir', 645 | 'SlimBrowser', 646 | { 'label': 'SRWare Iron', 'pattern': 'Iron' }, 647 | 'Sunrise', 648 | 'Swiftfox', 649 | 'Waterfox', 650 | 'WebPositive', 651 | 'Opera Mini', 652 | { 'label': 'Opera Mini', 'pattern': 'OPiOS' }, 653 | 'Opera', 654 | { 'label': 'Opera', 'pattern': 'OPR' }, 655 | 'Chrome', 656 | { 'label': 'Chrome Mobile', 'pattern': '(?:CriOS|CrMo)' }, 657 | { 'label': 'Firefox', 'pattern': '(?:Firefox|Minefield)' }, 658 | { 'label': 'Firefox for iOS', 'pattern': 'FxiOS' }, 659 | { 'label': 'IE', 'pattern': 'IEMobile' }, 660 | { 'label': 'IE', 'pattern': 'MSIE' }, 661 | 'Safari' 662 | ]); 663 | 664 | /* Detectable products (order is important). */ 665 | var product = getProduct([ 666 | { 'label': 'BlackBerry', 'pattern': 'BB10' }, 667 | 'BlackBerry', 668 | { 'label': 'Galaxy S', 'pattern': 'GT-I9000' }, 669 | { 'label': 'Galaxy S2', 'pattern': 'GT-I9100' }, 670 | { 'label': 'Galaxy S3', 'pattern': 'GT-I9300' }, 671 | { 'label': 'Galaxy S4', 'pattern': 'GT-I9500' }, 672 | { 'label': 'Galaxy S5', 'pattern': 'SM-G900' }, 673 | { 'label': 'Galaxy S6', 'pattern': 'SM-G920' }, 674 | { 'label': 'Galaxy S6 Edge', 'pattern': 'SM-G925' }, 675 | { 'label': 'Galaxy S7', 'pattern': 'SM-G930' }, 676 | { 'label': 'Galaxy S7 Edge', 'pattern': 'SM-G935' }, 677 | 'Google TV', 678 | 'Lumia', 679 | 'iPad', 680 | 'iPod', 681 | 'iPhone', 682 | 'Kindle', 683 | { 'label': 'Kindle Fire', 'pattern': '(?:Cloud9|Silk-Accelerated)' }, 684 | 'Nexus', 685 | 'Nook', 686 | 'PlayBook', 687 | 'PlayStation Vita', 688 | 'PlayStation', 689 | 'TouchPad', 690 | 'Transformer', 691 | { 'label': 'Wii U', 'pattern': 'WiiU' }, 692 | 'Wii', 693 | 'Xbox One', 694 | { 'label': 'Xbox 360', 'pattern': 'Xbox' }, 695 | 'Xoom' 696 | ]); 697 | 698 | /* Detectable manufacturers. */ 699 | var manufacturer = getManufacturer({ 700 | 'Apple': { 'iPad': 1, 'iPhone': 1, 'iPod': 1 }, 701 | 'Archos': {}, 702 | 'Amazon': { 'Kindle': 1, 'Kindle Fire': 1 }, 703 | 'Asus': { 'Transformer': 1 }, 704 | 'Barnes & Noble': { 'Nook': 1 }, 705 | 'BlackBerry': { 'PlayBook': 1 }, 706 | 'Google': { 'Google TV': 1, 'Nexus': 1 }, 707 | 'HP': { 'TouchPad': 1 }, 708 | 'HTC': {}, 709 | 'LG': {}, 710 | 'Microsoft': { 'Xbox': 1, 'Xbox One': 1 }, 711 | 'Motorola': { 'Xoom': 1 }, 712 | 'Nintendo': { 'Wii U': 1, 'Wii': 1 }, 713 | 'Nokia': { 'Lumia': 1 }, 714 | 'Samsung': { 'Galaxy S': 1, 'Galaxy S2': 1, 'Galaxy S3': 1, 'Galaxy S4': 1 }, 715 | 'Sony': { 'PlayStation': 1, 'PlayStation Vita': 1 } 716 | }); 717 | 718 | /* Detectable operating systems (order is important). */ 719 | var os = getOS([ 720 | 'Windows Phone', 721 | 'Android', 722 | 'CentOS', 723 | { 'label': 'Chrome OS', 'pattern': 'CrOS' }, 724 | 'Debian', 725 | 'Fedora', 726 | 'FreeBSD', 727 | 'Gentoo', 728 | 'Haiku', 729 | 'Kubuntu', 730 | 'Linux Mint', 731 | 'OpenBSD', 732 | 'Red Hat', 733 | 'SuSE', 734 | 'Ubuntu', 735 | 'Xubuntu', 736 | 'Cygwin', 737 | 'Symbian OS', 738 | 'hpwOS', 739 | 'webOS ', 740 | 'webOS', 741 | 'Tablet OS', 742 | 'Tizen', 743 | 'Linux', 744 | 'Mac OS X', 745 | 'Macintosh', 746 | 'Mac', 747 | 'Windows 98;', 748 | 'Windows ' 749 | ]); 750 | 751 | /*------------------------------------------------------------------------*/ 752 | 753 | /** 754 | * Picks the layout engine from an array of guesses. 755 | * 756 | * @private 757 | * @param {Array} guesses An array of guesses. 758 | * @returns {null|string} The detected layout engine. 759 | */ 760 | function getLayout(guesses) { 761 | return reduce(guesses, function(result, guess) { 762 | return result || RegExp('\\b' + ( 763 | guess.pattern || qualify(guess) 764 | ) + '\\b', 'i').exec(ua) && (guess.label || guess); 765 | }); 766 | } 767 | 768 | /** 769 | * Picks the manufacturer from an array of guesses. 770 | * 771 | * @private 772 | * @param {Array} guesses An object of guesses. 773 | * @returns {null|string} The detected manufacturer. 774 | */ 775 | function getManufacturer(guesses) { 776 | return reduce(guesses, function(result, value, key) { 777 | // Lookup the manufacturer by product or scan the UA for the manufacturer. 778 | return result || ( 779 | value[product] || 780 | value[/^[a-z]+(?: +[a-z]+\b)*/i.exec(product)] || 781 | RegExp('\\b' + qualify(key) + '(?:\\b|\\w*\\d)', 'i').exec(ua) 782 | ) && key; 783 | }); 784 | } 785 | 786 | /** 787 | * Picks the browser name from an array of guesses. 788 | * 789 | * @private 790 | * @param {Array} guesses An array of guesses. 791 | * @returns {null|string} The detected browser name. 792 | */ 793 | function getName(guesses) { 794 | return reduce(guesses, function(result, guess) { 795 | return result || RegExp('\\b' + ( 796 | guess.pattern || qualify(guess) 797 | ) + '\\b', 'i').exec(ua) && (guess.label || guess); 798 | }); 799 | } 800 | 801 | /** 802 | * Picks the OS name from an array of guesses. 803 | * 804 | * @private 805 | * @param {Array} guesses An array of guesses. 806 | * @returns {null|string} The detected OS name. 807 | */ 808 | function getOS(guesses) { 809 | return reduce(guesses, function(result, guess) { 810 | var pattern = guess.pattern || qualify(guess); 811 | if (!result && (result = 812 | RegExp('\\b' + pattern + '(?:/[\\d.]+|[ \\w.]*)', 'i').exec(ua) 813 | )) { 814 | result = cleanupOS(result, pattern, guess.label || guess); 815 | } 816 | return result; 817 | }); 818 | } 819 | 820 | /** 821 | * Picks the product name from an array of guesses. 822 | * 823 | * @private 824 | * @param {Array} guesses An array of guesses. 825 | * @returns {null|string} The detected product name. 826 | */ 827 | function getProduct(guesses) { 828 | return reduce(guesses, function(result, guess) { 829 | var pattern = guess.pattern || qualify(guess); 830 | if (!result && (result = 831 | RegExp('\\b' + pattern + ' *\\d+[.\\w_]*', 'i').exec(ua) || 832 | RegExp('\\b' + pattern + ' *\\w+-[\\w]*', 'i').exec(ua) || 833 | RegExp('\\b' + pattern + '(?:; *(?:[a-z]+[_-])?[a-z]+\\d+|[^ ();-]*)', 'i').exec(ua) 834 | )) { 835 | // Split by forward slash and append product version if needed. 836 | if ((result = String((guess.label && !RegExp(pattern, 'i').test(guess.label)) ? guess.label : result).split('/'))[1] && !/[\d.]+/.test(result[0])) { 837 | result[0] += ' ' + result[1]; 838 | } 839 | // Correct character case and cleanup string. 840 | guess = guess.label || guess; 841 | result = format(result[0] 842 | .replace(RegExp(pattern, 'i'), guess) 843 | .replace(RegExp('; *(?:' + guess + '[_-])?', 'i'), ' ') 844 | .replace(RegExp('(' + guess + ')[-_.]?(\\w)', 'i'), '$1 $2')); 845 | } 846 | return result; 847 | }); 848 | } 849 | 850 | /** 851 | * Resolves the version using an array of UA patterns. 852 | * 853 | * @private 854 | * @param {Array} patterns An array of UA patterns. 855 | * @returns {null|string} The detected version. 856 | */ 857 | function getVersion(patterns) { 858 | return reduce(patterns, function(result, pattern) { 859 | return result || (RegExp(pattern + 860 | '(?:-[\\d.]+/|(?: for [\\w-]+)?[ /-])([\\d.]+[^ ();/_-]*)', 'i').exec(ua) || 0)[1] || null; 861 | }); 862 | } 863 | 864 | /** 865 | * Returns `platform.description` when the platform object is coerced to a string. 866 | * 867 | * @name toString 868 | * @memberOf platform 869 | * @returns {string} Returns `platform.description` if available, else an empty string. 870 | */ 871 | function toStringPlatform() { 872 | return this.description || ''; 873 | } 874 | 875 | /*------------------------------------------------------------------------*/ 876 | 877 | // Convert layout to an array so we can add extra details. 878 | layout && (layout = [layout]); 879 | 880 | // Detect product names that contain their manufacturer's name. 881 | if (manufacturer && !product) { 882 | product = getProduct([manufacturer]); 883 | } 884 | // Clean up Google TV. 885 | if ((data = /\bGoogle TV\b/.exec(product))) { 886 | product = data[0]; 887 | } 888 | // Detect simulators. 889 | if (/\bSimulator\b/i.test(ua)) { 890 | product = (product ? product + ' ' : '') + 'Simulator'; 891 | } 892 | // Detect Opera Mini 8+ running in Turbo/Uncompressed mode on iOS. 893 | if (name == 'Opera Mini' && /\bOPiOS\b/.test(ua)) { 894 | description.push('running in Turbo/Uncompressed mode'); 895 | } 896 | // Detect IE Mobile 11. 897 | if (name == 'IE' && /\blike iPhone OS\b/.test(ua)) { 898 | data = parse(ua.replace(/like iPhone OS/, '')); 899 | manufacturer = data.manufacturer; 900 | product = data.product; 901 | } 902 | // Detect iOS. 903 | else if (/^iP/.test(product)) { 904 | name || (name = 'Safari'); 905 | os = 'iOS' + ((data = / OS ([\d_]+)/i.exec(ua)) 906 | ? ' ' + data[1].replace(/_/g, '.') 907 | : ''); 908 | } 909 | // Detect Kubuntu. 910 | else if (name == 'Konqueror' && !/buntu/i.test(os)) { 911 | os = 'Kubuntu'; 912 | } 913 | // Detect Android browsers. 914 | else if ((manufacturer && manufacturer != 'Google' && 915 | ((/Chrome/.test(name) && !/\bMobile Safari\b/i.test(ua)) || /\bVita\b/.test(product))) || 916 | (/\bAndroid\b/.test(os) && /^Chrome/.test(name) && /\bVersion\//i.test(ua))) { 917 | name = 'Android Browser'; 918 | os = /\bAndroid\b/.test(os) ? os : 'Android'; 919 | } 920 | // Detect Silk desktop/accelerated modes. 921 | else if (name == 'Silk') { 922 | if (!/\bMobi/i.test(ua)) { 923 | os = 'Android'; 924 | description.unshift('desktop mode'); 925 | } 926 | if (/Accelerated *= *true/i.test(ua)) { 927 | description.unshift('accelerated'); 928 | } 929 | } 930 | // Detect PaleMoon identifying as Firefox. 931 | else if (name == 'PaleMoon' && (data = /\bFirefox\/([\d.]+)\b/.exec(ua))) { 932 | description.push('identifying as Firefox ' + data[1]); 933 | } 934 | // Detect Firefox OS and products running Firefox. 935 | else if (name == 'Firefox' && (data = /\b(Mobile|Tablet|TV)\b/i.exec(ua))) { 936 | os || (os = 'Firefox OS'); 937 | product || (product = data[1]); 938 | } 939 | // Detect false positives for Firefox/Safari. 940 | else if (!name || (data = !/\bMinefield\b/i.test(ua) && /\b(?:Firefox|Safari)\b/.exec(name))) { 941 | // Escape the `/` for Firefox 1. 942 | if (name && !product && /[\/,]|^[^(]+?\)/.test(ua.slice(ua.indexOf(data + '/') + 8))) { 943 | // Clear name of false positives. 944 | name = null; 945 | } 946 | // Reassign a generic name. 947 | if ((data = product || manufacturer || os) && 948 | (product || manufacturer || /\b(?:Android|Symbian OS|Tablet OS|webOS)\b/.test(os))) { 949 | name = /[a-z]+(?: Hat)?/i.exec(/\bAndroid\b/.test(os) ? os : data) + ' Browser'; 950 | } 951 | } 952 | // Add Chrome version to description for Electron. 953 | else if (name == 'Electron' && (data = (/\bChrome\/([\d.]+)\b/.exec(ua) || 0)[1])) { 954 | description.push('Chromium ' + data); 955 | } 956 | // Detect non-Opera (Presto-based) versions (order is important). 957 | if (!version) { 958 | version = getVersion([ 959 | '(?:Cloud9|CriOS|CrMo|Edge|FxiOS|IEMobile|Iron|Opera ?Mini|OPiOS|OPR|Raven|SamsungBrowser|Silk(?!/[\\d.]+$))', 960 | 'Version', 961 | qualify(name), 962 | '(?:Firefox|Minefield|NetFront)' 963 | ]); 964 | } 965 | // Detect stubborn layout engines. 966 | if ((data = 967 | layout == 'iCab' && parseFloat(version) > 3 && 'WebKit' || 968 | /\bOpera\b/.test(name) && (/\bOPR\b/.test(ua) ? 'Blink' : 'Presto') || 969 | /\b(?:Midori|Nook|Safari)\b/i.test(ua) && !/^(?:Trident|EdgeHTML)$/.test(layout) && 'WebKit' || 970 | !layout && /\bMSIE\b/i.test(ua) && (os == 'Mac OS' ? 'Tasman' : 'Trident') || 971 | layout == 'WebKit' && /\bPlayStation\b(?! Vita\b)/i.test(name) && 'NetFront' 972 | )) { 973 | layout = [data]; 974 | } 975 | // Detect Windows Phone 7 desktop mode. 976 | if (name == 'IE' && (data = (/; *(?:XBLWP|ZuneWP)(\d+)/i.exec(ua) || 0)[1])) { 977 | name += ' Mobile'; 978 | os = 'Windows Phone ' + (/\+$/.test(data) ? data : data + '.x'); 979 | description.unshift('desktop mode'); 980 | } 981 | // Detect Windows Phone 8.x desktop mode. 982 | else if (/\bWPDesktop\b/i.test(ua)) { 983 | name = 'IE Mobile'; 984 | os = 'Windows Phone 8.x'; 985 | description.unshift('desktop mode'); 986 | version || (version = (/\brv:([\d.]+)/.exec(ua) || 0)[1]); 987 | } 988 | // Detect IE 11 identifying as other browsers. 989 | else if (name != 'IE' && layout == 'Trident' && (data = /\brv:([\d.]+)/.exec(ua))) { 990 | if (name) { 991 | description.push('identifying as ' + name + (version ? ' ' + version : '')); 992 | } 993 | name = 'IE'; 994 | version = data[1]; 995 | } 996 | // Leverage environment features. 997 | if (useFeatures) { 998 | // Detect server-side environments. 999 | // Rhino has a global function while others have a global object. 1000 | if (isHostType(context, 'global')) { 1001 | if (java) { 1002 | data = java.lang.System; 1003 | arch = data.getProperty('os.arch'); 1004 | os = os || data.getProperty('os.name') + ' ' + data.getProperty('os.version'); 1005 | } 1006 | if (isModuleScope && isHostType(context, 'system') && (data = [context.system])[0]) { 1007 | os || (os = data[0].os || null); 1008 | try { 1009 | data[1] = context.require('ringo/engine').version; 1010 | version = data[1].join('.'); 1011 | name = 'RingoJS'; 1012 | } catch(e) { 1013 | if (data[0].global.system == context.system) { 1014 | name = 'Narwhal'; 1015 | } 1016 | } 1017 | } 1018 | else if ( 1019 | typeof context.process == 'object' && !context.process.browser && 1020 | (data = context.process) 1021 | ) { 1022 | if (typeof data.versions == 'object') { 1023 | if (typeof data.versions.electron == 'string') { 1024 | description.push('Node ' + data.versions.node); 1025 | name = 'Electron'; 1026 | version = data.versions.electron; 1027 | } else if (typeof data.versions.nw == 'string') { 1028 | description.push('Chromium ' + version, 'Node ' + data.versions.node); 1029 | name = 'NW.js'; 1030 | version = data.versions.nw; 1031 | } 1032 | } else { 1033 | name = 'Node.js'; 1034 | arch = data.arch; 1035 | os = data.platform; 1036 | version = /[\d.]+/.exec(data.version) 1037 | version = version ? version[0] : 'unknown'; 1038 | } 1039 | } 1040 | else if (rhino) { 1041 | name = 'Rhino'; 1042 | } 1043 | } 1044 | // Detect Adobe AIR. 1045 | else if (getClassOf((data = context.runtime)) == airRuntimeClass) { 1046 | name = 'Adobe AIR'; 1047 | os = data.flash.system.Capabilities.os; 1048 | } 1049 | // Detect PhantomJS. 1050 | else if (getClassOf((data = context.phantom)) == phantomClass) { 1051 | name = 'PhantomJS'; 1052 | version = (data = data.version || null) && (data.major + '.' + data.minor + '.' + data.patch); 1053 | } 1054 | // Detect IE compatibility modes. 1055 | else if (typeof doc.documentMode == 'number' && (data = /\bTrident\/(\d+)/i.exec(ua))) { 1056 | // We're in compatibility mode when the Trident version + 4 doesn't 1057 | // equal the document mode. 1058 | version = [version, doc.documentMode]; 1059 | if ((data = +data[1] + 4) != version[1]) { 1060 | description.push('IE ' + version[1] + ' mode'); 1061 | layout && (layout[1] = ''); 1062 | version[1] = data; 1063 | } 1064 | version = name == 'IE' ? String(version[1].toFixed(1)) : version[0]; 1065 | } 1066 | // Detect IE 11 masking as other browsers. 1067 | else if (typeof doc.documentMode == 'number' && /^(?:Chrome|Firefox)\b/.test(name)) { 1068 | description.push('masking as ' + name + ' ' + version); 1069 | name = 'IE'; 1070 | version = '11.0'; 1071 | layout = ['Trident']; 1072 | os = 'Windows'; 1073 | } 1074 | os = os && format(os); 1075 | } 1076 | // Detect prerelease phases. 1077 | if (version && (data = 1078 | /(?:[ab]|dp|pre|[ab]\d+pre)(?:\d+\+?)?$/i.exec(version) || 1079 | /(?:alpha|beta)(?: ?\d)?/i.exec(ua + ';' + (useFeatures && nav.appMinorVersion)) || 1080 | /\bMinefield\b/i.test(ua) && 'a' 1081 | )) { 1082 | prerelease = /b/i.test(data) ? 'beta' : 'alpha'; 1083 | version = version.replace(RegExp(data + '\\+?$'), '') + 1084 | (prerelease == 'beta' ? beta : alpha) + (/\d+\+?/.exec(data) || ''); 1085 | } 1086 | // Detect Firefox Mobile. 1087 | if (name == 'Fennec' || name == 'Firefox' && /\b(?:Android|Firefox OS)\b/.test(os)) { 1088 | name = 'Firefox Mobile'; 1089 | } 1090 | // Obscure Maxthon's unreliable version. 1091 | else if (name == 'Maxthon' && version) { 1092 | version = version.replace(/\.[\d.]+/, '.x'); 1093 | } 1094 | // Detect Xbox 360 and Xbox One. 1095 | else if (/\bXbox\b/i.test(product)) { 1096 | if (product == 'Xbox 360') { 1097 | os = null; 1098 | } 1099 | if (product == 'Xbox 360' && /\bIEMobile\b/.test(ua)) { 1100 | description.unshift('mobile mode'); 1101 | } 1102 | } 1103 | // Add mobile postfix. 1104 | else if ((/^(?:Chrome|IE|Opera)$/.test(name) || name && !product && !/Browser|Mobi/.test(name)) && 1105 | (os == 'Windows CE' || /Mobi/i.test(ua))) { 1106 | name += ' Mobile'; 1107 | } 1108 | // Detect IE platform preview. 1109 | else if (name == 'IE' && useFeatures) { 1110 | try { 1111 | if (context.external === null) { 1112 | description.unshift('platform preview'); 1113 | } 1114 | } catch(e) { 1115 | description.unshift('embedded'); 1116 | } 1117 | } 1118 | // Detect BlackBerry OS version. 1119 | // http://docs.blackberry.com/en/developers/deliverables/18169/HTTP_headers_sent_by_BB_Browser_1234911_11.jsp 1120 | else if ((/\bBlackBerry\b/.test(product) || /\bBB10\b/.test(ua)) && (data = 1121 | (RegExp(product.replace(/ +/g, ' *') + '/([.\\d]+)', 'i').exec(ua) || 0)[1] || 1122 | version 1123 | )) { 1124 | data = [data, /BB10/.test(ua)]; 1125 | os = (data[1] ? (product = null, manufacturer = 'BlackBerry') : 'Device Software') + ' ' + data[0]; 1126 | version = null; 1127 | } 1128 | // Detect Opera identifying/masking itself as another browser. 1129 | // http://www.opera.com/support/kb/view/843/ 1130 | else if (this != forOwn && product != 'Wii' && ( 1131 | (useFeatures && opera) || 1132 | (/Opera/.test(name) && /\b(?:MSIE|Firefox)\b/i.test(ua)) || 1133 | (name == 'Firefox' && /\bOS X (?:\d+\.){2,}/.test(os)) || 1134 | (name == 'IE' && ( 1135 | (os && !/^Win/.test(os) && version > 5.5) || 1136 | /\bWindows XP\b/.test(os) && version > 8 || 1137 | version == 8 && !/\bTrident\b/.test(ua) 1138 | )) 1139 | ) && !reOpera.test((data = parse.call(forOwn, ua.replace(reOpera, '') + ';'))) && data.name) { 1140 | // When "identifying", the UA contains both Opera and the other browser's name. 1141 | data = 'ing as ' + data.name + ((data = data.version) ? ' ' + data : ''); 1142 | if (reOpera.test(name)) { 1143 | if (/\bIE\b/.test(data) && os == 'Mac OS') { 1144 | os = null; 1145 | } 1146 | data = 'identify' + data; 1147 | } 1148 | // When "masking", the UA contains only the other browser's name. 1149 | else { 1150 | data = 'mask' + data; 1151 | if (operaClass) { 1152 | name = format(operaClass.replace(/([a-z])([A-Z])/g, '$1 $2')); 1153 | } else { 1154 | name = 'Opera'; 1155 | } 1156 | if (/\bIE\b/.test(data)) { 1157 | os = null; 1158 | } 1159 | if (!useFeatures) { 1160 | version = null; 1161 | } 1162 | } 1163 | layout = ['Presto']; 1164 | description.push(data); 1165 | } 1166 | // Detect WebKit Nightly and approximate Chrome/Safari versions. 1167 | if ((data = (/\bAppleWebKit\/([\d.]+\+?)/i.exec(ua) || 0)[1])) { 1168 | // Correct build number for numeric comparison. 1169 | // (e.g. "532.5" becomes "532.05") 1170 | data = [parseFloat(data.replace(/\.(\d)$/, '.0$1')), data]; 1171 | // Nightly builds are postfixed with a "+". 1172 | if (name == 'Safari' && data[1].slice(-1) == '+') { 1173 | name = 'WebKit Nightly'; 1174 | prerelease = 'alpha'; 1175 | version = data[1].slice(0, -1); 1176 | } 1177 | // Clear incorrect browser versions. 1178 | else if (version == data[1] || 1179 | version == (data[2] = (/\bSafari\/([\d.]+\+?)/i.exec(ua) || 0)[1])) { 1180 | version = null; 1181 | } 1182 | // Use the full Chrome version when available. 1183 | data[1] = (/\bChrome\/([\d.]+)/i.exec(ua) || 0)[1]; 1184 | // Detect Blink layout engine. 1185 | if (data[0] == 537.36 && data[2] == 537.36 && parseFloat(data[1]) >= 28 && layout == 'WebKit') { 1186 | layout = ['Blink']; 1187 | } 1188 | // Detect JavaScriptCore. 1189 | // http://stackoverflow.com/questions/6768474/how-can-i-detect-which-javascript-engine-v8-or-jsc-is-used-at-runtime-in-androi 1190 | if (!useFeatures || (!likeChrome && !data[1])) { 1191 | layout && (layout[1] = 'like Safari'); 1192 | data = (data = data[0], data < 400 ? 1 : data < 500 ? 2 : data < 526 ? 3 : data < 533 ? 4 : data < 534 ? '4+' : data < 535 ? 5 : data < 537 ? 6 : data < 538 ? 7 : data < 601 ? 8 : '8'); 1193 | } else { 1194 | layout && (layout[1] = 'like Chrome'); 1195 | data = data[1] || (data = data[0], data < 530 ? 1 : data < 532 ? 2 : data < 532.05 ? 3 : data < 533 ? 4 : data < 534.03 ? 5 : data < 534.07 ? 6 : data < 534.10 ? 7 : data < 534.13 ? 8 : data < 534.16 ? 9 : data < 534.24 ? 10 : data < 534.30 ? 11 : data < 535.01 ? 12 : data < 535.02 ? '13+' : data < 535.07 ? 15 : data < 535.11 ? 16 : data < 535.19 ? 17 : data < 536.05 ? 18 : data < 536.10 ? 19 : data < 537.01 ? 20 : data < 537.11 ? '21+' : data < 537.13 ? 23 : data < 537.18 ? 24 : data < 537.24 ? 25 : data < 537.36 ? 26 : layout != 'Blink' ? '27' : '28'); 1196 | } 1197 | // Add the postfix of ".x" or "+" for approximate versions. 1198 | layout && (layout[1] += ' ' + (data += typeof data == 'number' ? '.x' : /[.+]/.test(data) ? '' : '+')); 1199 | // Obscure version for some Safari 1-2 releases. 1200 | if (name == 'Safari' && (!version || parseInt(version) > 45)) { 1201 | version = data; 1202 | } 1203 | } 1204 | // Detect Opera desktop modes. 1205 | if (name == 'Opera' && (data = /\bzbov|zvav$/.exec(os))) { 1206 | name += ' '; 1207 | description.unshift('desktop mode'); 1208 | if (data == 'zvav') { 1209 | name += 'Mini'; 1210 | version = null; 1211 | } else { 1212 | name += 'Mobile'; 1213 | } 1214 | os = os.replace(RegExp(' *' + data + '$'), ''); 1215 | } 1216 | // Detect Chrome desktop mode. 1217 | else if (name == 'Safari' && /\bChrome\b/.exec(layout && layout[1])) { 1218 | description.unshift('desktop mode'); 1219 | name = 'Chrome Mobile'; 1220 | version = null; 1221 | 1222 | if (/\bOS X\b/.test(os)) { 1223 | manufacturer = 'Apple'; 1224 | os = 'iOS 4.3+'; 1225 | } else { 1226 | os = null; 1227 | } 1228 | } 1229 | // Strip incorrect OS versions. 1230 | if (version && version.indexOf((data = /[\d.]+$/.exec(os))) == 0 && 1231 | ua.indexOf('/' + data + '-') > -1) { 1232 | os = trim(os.replace(data, '')); 1233 | } 1234 | // Add layout engine. 1235 | if (layout && !/\b(?:Avant|Nook)\b/.test(name) && ( 1236 | /Browser|Lunascape|Maxthon/.test(name) || 1237 | name != 'Safari' && /^iOS/.test(os) && /\bSafari\b/.test(layout[1]) || 1238 | /^(?:Adobe|Arora|Breach|Midori|Opera|Phantom|Rekonq|Rock|Samsung Internet|Sleipnir|Web)/.test(name) && layout[1])) { 1239 | // Don't add layout details to description if they are falsey. 1240 | (data = layout[layout.length - 1]) && description.push(data); 1241 | } 1242 | // Combine contextual information. 1243 | if (description.length) { 1244 | description = ['(' + description.join('; ') + ')']; 1245 | } 1246 | // Append manufacturer to description. 1247 | if (manufacturer && product && product.indexOf(manufacturer) < 0) { 1248 | description.push('on ' + manufacturer); 1249 | } 1250 | // Append product to description. 1251 | if (product) { 1252 | description.push((/^on /.test(description[description.length - 1]) ? '' : 'on ') + product); 1253 | } 1254 | // Parse the OS into an object. 1255 | if (os) { 1256 | data = / ([\d.+]+)$/.exec(os); 1257 | isSpecialCasedOS = data && os.charAt(os.length - data[0].length - 1) == '/'; 1258 | os = { 1259 | 'architecture': 32, 1260 | 'family': (data && !isSpecialCasedOS) ? os.replace(data[0], '') : os, 1261 | 'version': data ? data[1] : null, 1262 | 'toString': function() { 1263 | var version = this.version; 1264 | return this.family + ((version && !isSpecialCasedOS) ? ' ' + version : '') + (this.architecture == 64 ? ' 64-bit' : ''); 1265 | } 1266 | }; 1267 | } 1268 | // Add browser/OS architecture. 1269 | if ((data = /\b(?:AMD|IA|Win|WOW|x86_|x)64\b/i.exec(arch)) && !/\bi686\b/i.test(arch)) { 1270 | if (os) { 1271 | os.architecture = 64; 1272 | os.family = os.family.replace(RegExp(' *' + data), ''); 1273 | } 1274 | if ( 1275 | name && (/\bWOW64\b/i.test(ua) || 1276 | (useFeatures && /\w(?:86|32)$/.test(nav.cpuClass || nav.platform) && !/\bWin64; x64\b/i.test(ua))) 1277 | ) { 1278 | description.unshift('32-bit'); 1279 | } 1280 | } 1281 | // Chrome 39 and above on OS X is always 64-bit. 1282 | else if ( 1283 | os && /^OS X/.test(os.family) && 1284 | name == 'Chrome' && parseFloat(version) >= 39 1285 | ) { 1286 | os.architecture = 64; 1287 | } 1288 | 1289 | ua || (ua = null); 1290 | 1291 | /*------------------------------------------------------------------------*/ 1292 | 1293 | /** 1294 | * The platform object. 1295 | * 1296 | * @name platform 1297 | * @type Object 1298 | */ 1299 | var platform = {}; 1300 | 1301 | /** 1302 | * The platform description. 1303 | * 1304 | * @memberOf platform 1305 | * @type string|null 1306 | */ 1307 | platform.description = ua; 1308 | 1309 | /** 1310 | * The name of the browser's layout engine. 1311 | * 1312 | * The list of common layout engines include: 1313 | * "Blink", "EdgeHTML", "Gecko", "Trident" and "WebKit" 1314 | * 1315 | * @memberOf platform 1316 | * @type string|null 1317 | */ 1318 | platform.layout = layout && layout[0]; 1319 | 1320 | /** 1321 | * The name of the product's manufacturer. 1322 | * 1323 | * The list of manufacturers include: 1324 | * "Apple", "Archos", "Amazon", "Asus", "Barnes & Noble", "BlackBerry", 1325 | * "Google", "HP", "HTC", "LG", "Microsoft", "Motorola", "Nintendo", 1326 | * "Nokia", "Samsung" and "Sony" 1327 | * 1328 | * @memberOf platform 1329 | * @type string|null 1330 | */ 1331 | platform.manufacturer = manufacturer; 1332 | 1333 | /** 1334 | * The name of the browser/environment. 1335 | * 1336 | * The list of common browser names include: 1337 | * "Chrome", "Electron", "Firefox", "Firefox for iOS", "IE", 1338 | * "Microsoft Edge", "PhantomJS", "Safari", "SeaMonkey", "Silk", 1339 | * "Opera Mini" and "Opera" 1340 | * 1341 | * Mobile versions of some browsers have "Mobile" appended to their name: 1342 | * eg. "Chrome Mobile", "Firefox Mobile", "IE Mobile" and "Opera Mobile" 1343 | * 1344 | * @memberOf platform 1345 | * @type string|null 1346 | */ 1347 | platform.name = name; 1348 | 1349 | /** 1350 | * The alpha/beta release indicator. 1351 | * 1352 | * @memberOf platform 1353 | * @type string|null 1354 | */ 1355 | platform.prerelease = prerelease; 1356 | 1357 | /** 1358 | * The name of the product hosting the browser. 1359 | * 1360 | * The list of common products include: 1361 | * 1362 | * "BlackBerry", "Galaxy S4", "Lumia", "iPad", "iPod", "iPhone", "Kindle", 1363 | * "Kindle Fire", "Nexus", "Nook", "PlayBook", "TouchPad" and "Transformer" 1364 | * 1365 | * @memberOf platform 1366 | * @type string|null 1367 | */ 1368 | platform.product = product; 1369 | 1370 | /** 1371 | * The browser's user agent string. 1372 | * 1373 | * @memberOf platform 1374 | * @type string|null 1375 | */ 1376 | platform.ua = ua; 1377 | 1378 | /** 1379 | * The browser/environment version. 1380 | * 1381 | * @memberOf platform 1382 | * @type string|null 1383 | */ 1384 | platform.version = name && version; 1385 | 1386 | /** 1387 | * The name of the operating system. 1388 | * 1389 | * @memberOf platform 1390 | * @type Object 1391 | */ 1392 | platform.os = os || { 1393 | 1394 | /** 1395 | * The CPU architecture the OS is built for. 1396 | * 1397 | * @memberOf platform.os 1398 | * @type number|null 1399 | */ 1400 | 'architecture': null, 1401 | 1402 | /** 1403 | * The family of the OS. 1404 | * 1405 | * Common values include: 1406 | * "Windows", "Windows Server 2008 R2 / 7", "Windows Server 2008 / Vista", 1407 | * "Windows XP", "OS X", "Ubuntu", "Debian", "Fedora", "Red Hat", "SuSE", 1408 | * "Android", "iOS" and "Windows Phone" 1409 | * 1410 | * @memberOf platform.os 1411 | * @type string|null 1412 | */ 1413 | 'family': null, 1414 | 1415 | /** 1416 | * The version of the OS. 1417 | * 1418 | * @memberOf platform.os 1419 | * @type string|null 1420 | */ 1421 | 'version': null, 1422 | 1423 | /** 1424 | * Returns the OS string. 1425 | * 1426 | * @memberOf platform.os 1427 | * @returns {string} The OS string. 1428 | */ 1429 | 'toString': function() { return 'null'; } 1430 | }; 1431 | 1432 | platform.parse = parse; 1433 | platform.toString = toStringPlatform; 1434 | 1435 | if (platform.version) { 1436 | description.unshift(version); 1437 | } 1438 | if (platform.name) { 1439 | description.unshift(name); 1440 | } 1441 | if (os && name && !(os == String(os).split(' ')[0] && (os == name.split(' ')[0] || product))) { 1442 | description.push(product ? '(' + os + ')' : 'on ' + os); 1443 | } 1444 | if (description.length) { 1445 | platform.description = description.join(' '); 1446 | } 1447 | return platform; 1448 | } 1449 | 1450 | /*--------------------------------------------------------------------------*/ 1451 | 1452 | // Export platform. 1453 | var platform = parse(); 1454 | 1455 | // Some AMD build optimizers, like r.js, check for condition patterns like the following: 1456 | if (true) { 1457 | // Expose platform on the global object to prevent errors when platform is 1458 | // loaded by a script tag in the presence of an AMD loader. 1459 | // See http://requirejs.org/docs/errors.html#mismatch for more details. 1460 | root.platform = platform; 1461 | 1462 | // Define as an anonymous module so platform can be aliased through path mapping. 1463 | !(__WEBPACK_AMD_DEFINE_RESULT__ = function() { 1464 | return platform; 1465 | }.call(exports, __webpack_require__, exports, module), 1466 | __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); 1467 | } 1468 | // Check for `exports` after `define` in case a build optimizer adds an `exports` object. 1469 | else if (freeExports && freeModule) { 1470 | // Export for CommonJS support. 1471 | forOwn(platform, function(value, key) { 1472 | freeExports[key] = value; 1473 | }); 1474 | } 1475 | else { 1476 | // Export to the global object. 1477 | root.platform = platform; 1478 | } 1479 | }.call(this)); 1480 | 1481 | /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2)(module), __webpack_require__(3))) 1482 | 1483 | /***/ }), 1484 | /* 2 */ 1485 | /***/ (function(module, exports) { 1486 | 1487 | module.exports = function(module) { 1488 | if(!module.webpackPolyfill) { 1489 | module.deprecate = function() {}; 1490 | module.paths = []; 1491 | // module.parent = undefined by default 1492 | if(!module.children) module.children = []; 1493 | Object.defineProperty(module, "loaded", { 1494 | enumerable: true, 1495 | get: function() { 1496 | return module.l; 1497 | } 1498 | }); 1499 | Object.defineProperty(module, "id", { 1500 | enumerable: true, 1501 | get: function() { 1502 | return module.i; 1503 | } 1504 | }); 1505 | module.webpackPolyfill = 1; 1506 | } 1507 | return module; 1508 | }; 1509 | 1510 | 1511 | /***/ }), 1512 | /* 3 */ 1513 | /***/ (function(module, exports) { 1514 | 1515 | var g; 1516 | 1517 | // This works in non-strict mode 1518 | g = (function() { 1519 | return this; 1520 | })(); 1521 | 1522 | try { 1523 | // This works if eval is allowed (see CSP) 1524 | g = g || Function("return this")() || (1,eval)("this"); 1525 | } catch(e) { 1526 | // This works if the window reference is available 1527 | if(typeof window === "object") 1528 | g = window; 1529 | } 1530 | 1531 | // g can still be undefined, but nothing to do about it... 1532 | // We return undefined, instead of nothing here, so it's 1533 | // easier to handle this case. if(!global) { ...} 1534 | 1535 | module.exports = g; 1536 | 1537 | 1538 | /***/ }) 1539 | /******/ ]); --------------------------------------------------------------------------------