├── .babelrc ├── .eslintrc ├── .gitignore ├── Gruntfile.js ├── LICENSE ├── README.md ├── build ├── bundle.js └── index.js ├── package.json └── src └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015"], 3 | "plugins": [ 4 | "add-module-exports" 5 | ] 6 | } 7 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "airbnb/base", 3 | "rules": { 4 | "comma-dangle": 0 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | node_modules 28 | 29 | # Optional npm cache directory 30 | .npm 31 | 32 | # Optional REPL history 33 | .node_repl_history 34 | -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | module.exports = function (grunt) { // eslint-disable-line 2 | grunt.initConfig({ 3 | babel: { 4 | scripts: { 5 | files: [{ 6 | expand: true, 7 | cwd: 'src', 8 | src: '**/*.js', 9 | dest: 'build/' 10 | }] 11 | } 12 | }, 13 | clean: { 14 | files: ['build/**/*.js'] 15 | }, 16 | eslint: { 17 | files: ['src/**/*.js'] 18 | }, 19 | webpack: { 20 | scripts: { 21 | entry: './src/index.js', 22 | output: { 23 | path: 'build/', 24 | filename: 'bundle.js', 25 | libraryTarget: 'var', 26 | library: 'Gooz' 27 | }, 28 | module: { 29 | loaders: [ 30 | { 31 | test: /\.jsx?$/, 32 | exclude: /(node_modules|bower_components)/, 33 | loader: 'babel', 34 | query: { 35 | presets: ['es2015'], 36 | plugins: [ 37 | 'add-module-exports' 38 | ] 39 | } 40 | } 41 | ] 42 | } 43 | } 44 | }, 45 | watch: { 46 | scripts: { 47 | files: ['src/**/*.js'], 48 | tasks: ['eslint', 'babel', 'webpack'] 49 | } 50 | } 51 | }); 52 | 53 | grunt.loadNpmTasks('grunt-contrib-clean'); 54 | grunt.loadNpmTasks('grunt-contrib-watch'); 55 | grunt.loadNpmTasks('grunt-babel'); 56 | grunt.loadNpmTasks('grunt-eslint'); 57 | grunt.loadNpmTasks('grunt-webpack'); 58 | 59 | grunt.registerTask('default', ['clean', 'eslint', 'babel', 'webpack']); 60 | }; 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Mohamad Jahani 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 all 13 | 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 THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Gooz 2 | 3 | Send the old sh*tty browsers away from your website as simple as a Gooz 4 | 5 | 6 | ## Installation 7 | 8 | You can install it from [NPM](https://www.npmjs.com/package/gooz): 9 | 10 | ```bash 11 | npm install --save gooz 12 | ``` 13 | 14 | 15 | Or grab `build/bundle.js` and load it in your page. The `Gooz` class is now loaded as `Gooz` in the global scope (`window.Gooz`). 16 | 17 | ```html 18 | 19 | 22 | ``` 23 | 24 | ## Usage 25 | 26 | ```js 27 | // 1 28 | const gooz = new Gooz({redirect: true}); // if it's gooz, it will redirect to 'http://outdatedbrowser.com' 29 | 30 | // 2 31 | const gooz = new Gooz(); // or using var instead of const 32 | gooz.isGooz(); // true or false 33 | 34 | // 3 35 | const options = { 36 | features: ['SVGElement', 'localStorage'], // passing window global object you want to check 37 | globalObject: window, // global object (window) 38 | redirect: true, // auto redirect on class instance creation 39 | timeout: 7000, // redirect timeout (ms) 40 | uri: 'http://outdatedbrowser.com' // redirect uri 41 | } 42 | const gooz = new Gooz(options); // auto redirect if gooz and nothing if not 43 | 44 | // 4 45 | const gooz = new Gooz(); 46 | gooz.goozate(); // redirect if it's gooz 47 | 48 | // 5 49 | const gooz = new Gooz(); 50 | gooz.redirect({ 51 | timeout: 1500, 52 | uri: 'http://mozilla.org/firefox' 53 | }); 54 | 55 | ``` 56 | 57 | 58 | 59 | ## Ideas || Issues 60 | Just fill an issue and describe it. I'll check it ASAP! 61 | 62 | 63 | ## Contribution 64 | 65 | You can fork the repository, improve or fix some part of it and then send the pull requests back if you want to see them here. I really appreciate that. :heart: 66 | 67 | Pleas run `grunt` before sending PRs to run grunt tasks, lint your code and build it. 68 | -------------------------------------------------------------------------------- /build/bundle.js: -------------------------------------------------------------------------------- 1 | var Gooz = 2 | /******/ (function(modules) { // webpackBootstrap 3 | /******/ // The module cache 4 | /******/ var installedModules = {}; 5 | 6 | /******/ // The require function 7 | /******/ function __webpack_require__(moduleId) { 8 | 9 | /******/ // Check if module is in cache 10 | /******/ if(installedModules[moduleId]) 11 | /******/ return installedModules[moduleId].exports; 12 | 13 | /******/ // Create a new module (and put it into the cache) 14 | /******/ var module = installedModules[moduleId] = { 15 | /******/ exports: {}, 16 | /******/ id: moduleId, 17 | /******/ loaded: false 18 | /******/ }; 19 | 20 | /******/ // Execute the module function 21 | /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); 22 | 23 | /******/ // Flag the module as loaded 24 | /******/ module.loaded = true; 25 | 26 | /******/ // Return the exports of the module 27 | /******/ return module.exports; 28 | /******/ } 29 | 30 | 31 | /******/ // expose the modules object (__webpack_modules__) 32 | /******/ __webpack_require__.m = modules; 33 | 34 | /******/ // expose the module cache 35 | /******/ __webpack_require__.c = installedModules; 36 | 37 | /******/ // __webpack_public_path__ 38 | /******/ __webpack_require__.p = ""; 39 | 40 | /******/ // Load entry module and return exports 41 | /******/ return __webpack_require__(0); 42 | /******/ }) 43 | /************************************************************************/ 44 | /******/ ([ 45 | /* 0 */ 46 | /***/ function(module, exports) { 47 | 48 | 'use strict'; 49 | 50 | Object.defineProperty(exports, "__esModule", { 51 | value: true 52 | }); 53 | 54 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 55 | 56 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 57 | 58 | var DEFAULT_OPTIONS = { 59 | features: ['addEventListener', 'SVGElement', 'CanvasRenderingContext2D', 'localStorage'], 60 | globalObject: window, 61 | redirect: false, 62 | timeout: 3000, 63 | uri: 'http://outdatedbrowser.com' 64 | }; 65 | 66 | /** 67 | * Main Gooz class 68 | */ 69 | 70 | var Gooz = function () { 71 | function Gooz(props) { 72 | _classCallCheck(this, Gooz); 73 | 74 | var options = Object.assign({}, DEFAULT_OPTIONS, props); 75 | if (!options.globalObject) { 76 | throw new TypeError('No window object detected! :O Am I in a browser?!'); 77 | } 78 | this._options = options; 79 | if (options.redirect) { 80 | this.redirect(); 81 | } 82 | } 83 | 84 | /** 85 | * Check if the browser is gooz or goozoo 86 | * @return {Boolean} goozooish status 87 | */ 88 | 89 | 90 | _createClass(Gooz, [{ 91 | key: 'isGooz', 92 | value: function isGooz() { 93 | return this._options.features.some(function (feature) { 94 | return !(feature in window); 95 | }); 96 | } 97 | 98 | /** 99 | * Gooz the browser to redirect uri if it's goozed up 100 | */ 101 | 102 | }, { 103 | key: 'goozate', 104 | value: function goozate() { 105 | if (this.isGooz()) { 106 | this.redirect(); 107 | } 108 | } 109 | 110 | /** 111 | * Redirect the browser to the right uri in order to tell him about this goozed up status 112 | * @param {Object} redirect props { timeout, uri } 113 | * @return {Gooz} our Gooz instance 114 | */ 115 | 116 | }, { 117 | key: 'redirect', 118 | value: function redirect() { 119 | var props = arguments.length <= 0 || arguments[0] === undefined ? { timeout: this._options.timeout, uri: this._options.uri } : arguments[0]; 120 | var globalObject = this._options.globalObject; 121 | var timeout = props.timeout; 122 | var uri = props.uri; 123 | 124 | setTimeout(function () { 125 | globalObject.location = uri; 126 | }, timeout); 127 | return this; 128 | } 129 | }]); 130 | 131 | return Gooz; 132 | }(); 133 | 134 | exports.default = Gooz; 135 | module.exports = exports['default']; 136 | 137 | /***/ } 138 | /******/ ]); -------------------------------------------------------------------------------- /build/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Object.defineProperty(exports, "__esModule", { 4 | value: true 5 | }); 6 | 7 | var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); 8 | 9 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 10 | 11 | var DEFAULT_OPTIONS = { 12 | features: ['addEventListener', 'SVGElement', 'CanvasRenderingContext2D', 'localStorage'], 13 | globalObject: window, 14 | redirect: false, 15 | timeout: 3000, 16 | uri: 'http://outdatedbrowser.com' 17 | }; 18 | 19 | /** 20 | * Main Gooz class 21 | */ 22 | 23 | var Gooz = function () { 24 | function Gooz(props) { 25 | _classCallCheck(this, Gooz); 26 | 27 | var options = Object.assign({}, DEFAULT_OPTIONS, props); 28 | if (!options.globalObject) { 29 | throw new TypeError('No window object detected! :O Am I in a browser?!'); 30 | } 31 | this._options = options; 32 | if (options.redirect) { 33 | this.redirect(); 34 | } 35 | } 36 | 37 | /** 38 | * Check if the browser is gooz or goozoo 39 | * @return {Boolean} goozooish status 40 | */ 41 | 42 | 43 | _createClass(Gooz, [{ 44 | key: 'isGooz', 45 | value: function isGooz() { 46 | return this._options.features.some(function (feature) { 47 | return !(feature in window); 48 | }); 49 | } 50 | 51 | /** 52 | * Gooz the browser to redirect uri if it's goozed up 53 | */ 54 | 55 | }, { 56 | key: 'goozate', 57 | value: function goozate() { 58 | if (this.isGooz()) { 59 | this.redirect(); 60 | } 61 | } 62 | 63 | /** 64 | * Redirect the browser to the right uri in order to tell him about this goozed up status 65 | * @param {Object} redirect props { timeout, uri } 66 | * @return {Gooz} our Gooz instance 67 | */ 68 | 69 | }, { 70 | key: 'redirect', 71 | value: function redirect() { 72 | var props = arguments.length <= 0 || arguments[0] === undefined ? { timeout: this._options.timeout, uri: this._options.uri } : arguments[0]; 73 | var globalObject = this._options.globalObject; 74 | var timeout = props.timeout; 75 | var uri = props.uri; 76 | 77 | setTimeout(function () { 78 | globalObject.location = uri; 79 | }, timeout); 80 | return this; 81 | } 82 | }]); 83 | 84 | return Gooz; 85 | }(); 86 | 87 | exports.default = Gooz; 88 | module.exports = exports['default']; 89 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gooz", 3 | "version": "1.0.3", 4 | "description": "Send the old sh*tty browsers away from your website as simple as a Gooz", 5 | "main": "build/index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/mamal72/gooz.git" 12 | }, 13 | "keywords": [ 14 | "gooz", 15 | "browser", 16 | "detection", 17 | "detect" 18 | ], 19 | "author": "Mohamad Jahani ", 20 | "license": "MIT", 21 | "bugs": { 22 | "url": "https://github.com/mamal72/gooz/issues" 23 | }, 24 | "homepage": "https://github.com/mamal72/gooz#readme", 25 | "devDependencies": { 26 | "babel": "^6.5.2", 27 | "babel-core": "^6.7.4", 28 | "babel-loader": "^6.2.4", 29 | "babel-plugin-add-module-exports": "^0.1.2", 30 | "babel-preset-es2015": "^6.6.0", 31 | "eslint": "^2.7.0", 32 | "eslint-config-airbnb": "^6.2.0", 33 | "grunt": "^1.0.1", 34 | "grunt-babel": "^6.0.0", 35 | "grunt-contrib-clean": "^1.0.0", 36 | "grunt-contrib-watch": "^1.0.0", 37 | "grunt-eslint": "^18.0.0", 38 | "grunt-webpack": "^1.0.11", 39 | "webpack": "^1.12.14", 40 | "webpack-dev-server": "^1.14.1" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | const DEFAULT_OPTIONS = { 2 | features: ['addEventListener', 'SVGElement', 'CanvasRenderingContext2D', 'localStorage'], 3 | globalObject: window, 4 | redirect: false, 5 | timeout: 3000, 6 | uri: 'http://outdatedbrowser.com' 7 | }; 8 | 9 | /** 10 | * Main Gooz class 11 | */ 12 | export default class Gooz { 13 | constructor(props) { 14 | const options = Object.assign({}, DEFAULT_OPTIONS, props); 15 | if (!options.globalObject) { 16 | throw new TypeError('No window object detected! :O Am I in a browser?!'); 17 | } 18 | this._options = options; 19 | if (options.redirect) { 20 | this.redirect(); 21 | } 22 | } 23 | 24 | 25 | /** 26 | * Check if the browser is gooz or goozoo 27 | * @return {Boolean} goozooish status 28 | */ 29 | isGooz() { 30 | return this._options.features.some(feature => !(feature in window)); 31 | } 32 | 33 | 34 | /** 35 | * Gooz the browser to redirect uri if it's goozed up 36 | */ 37 | goozate() { 38 | if (this.isGooz()) { 39 | this.redirect(); 40 | } 41 | } 42 | 43 | 44 | /** 45 | * Redirect the browser to the right uri in order to tell him about this goozed up status 46 | * @param {Object} redirect props { timeout, uri } 47 | * @return {Gooz} our Gooz instance 48 | */ 49 | redirect(props = { timeout: this._options.timeout, uri: this._options.uri }) { 50 | const { globalObject } = this._options; 51 | const { timeout, uri } = props; 52 | setTimeout(() => { 53 | globalObject.location = uri; 54 | }, timeout); 55 | return this; 56 | } 57 | 58 | } 59 | --------------------------------------------------------------------------------