From dd7ecac993839e2b74ccd098c8ba6fa0994b61ee Mon Sep 17 00:00:00 2001 From: IamEmpty Date: Thu, 9 Jun 2016 01:07:53 +0300 Subject: [PATCH 1/5] remove files --- demo/demo.html | 49 ------------- demo/index.pug | 23 +++--- demo/js/main.js | 9 --- package.json | 4 +- src/check-browser.js | 162 +++++++++++++++++++++---------------------- 5 files changed, 93 insertions(+), 154 deletions(-) delete mode 100644 demo/demo.html delete mode 100644 demo/js/main.js diff --git a/demo/demo.html b/demo/demo.html deleted file mode 100644 index f019ede..0000000 --- a/demo/demo.html +++ /dev/null @@ -1,49 +0,0 @@ - - - - - Check browser plugin demonstration - - - - - - - - - - - - - - -
-
-
- -
-
-

Warning!

-

You use oldest version of a browser. It may be a reason of incorrect work and view of a website.

-

For comfortable work, please download latest version of a browser convenient for you from official website.

-

Please read ourdocumentation.

-
- -
- - - - -
- - -
- -
-
- - -
- - - \ No newline at end of file diff --git a/demo/index.pug b/demo/index.pug index 8ca0435..736dcbc 100644 --- a/demo/index.pug +++ b/demo/index.pug @@ -9,16 +9,6 @@ html(lang='en') link(rel='stylesheet', href='old-browser.css') //- SyntaxHighlighter style link(rel='stylesheet', href='prism.css') - //- Add jquery - script(src='https://code.jquery.com/jquery-1.11.0.min.js') - //- Latest compiled and minified Bootstrap JavaScript - script(src='https://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js') - //- Add plugin Check browser - script(src='check-browser.js') - //- Syntax highlighter Prism js - script(src='prism.js') - //- Own main javascript file - script(src='main.js') body(data-spy='scroll', data-target='#bs-example-navbar-collapse-1', data-offset='170') header.header nav.navbar.navbar-default.navbar-fixed-top(role='navigation') @@ -129,3 +119,16 @@ html(lang='en') IE: 10 } }); + //- Add plugin Check browser + script(src='check-browser.js') + //- Syntax highlighter Prism js + script(src='prism.js') + //- Own main javascript file + script. + checkBrowser({ + once: true, + duration: 1000, + browsers: { + Chrome: 52 + } + }); diff --git a/demo/js/main.js b/demo/js/main.js deleted file mode 100644 index 600e78b..0000000 --- a/demo/js/main.js +++ /dev/null @@ -1,9 +0,0 @@ -$(document).ready(function () { - $('body').checkBrowser({ - once: 'Yes', - duration: 1000, - browsers: { - Chrome: 52 - } - }); -}); diff --git a/package.json b/package.json index d7f7617..f326073 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,8 @@ "copy1": "cp bower_components/prism/prism.js build", "copy2": "cp bower_components/prism/themes/prism.css build", "copy3": "cp src/check-browser.js build", - "copy4": "cp demo/js/main.js build", - "build": "npm run pug && npm run stylus && npm run copy1 && npm run copy2 && npm run copy3 && npm run copy4" + "build": "npm run pug && npm run stylus && npm run copy1 && npm run copy2 && npm run copy3", + "clean": "rm -rf build" }, "repository": { "type": "git", diff --git a/src/check-browser.js b/src/check-browser.js index a5b962a..73dee82 100644 --- a/src/check-browser.js +++ b/src/check-browser.js @@ -1,85 +1,79 @@ -// Old browser check -(function($) { - 'use strict'; - - $.fn.checkBrowser = function(options) { - - var defaults = { - once: 'No', - warningBoxName: '.old-browser-warning', - closeBtnName: '#close-old-browser-warning', - duration: 1200, - easing: 'swing', - - browsers: { - Firefox: 27, - Chrome: 30, - Opera: 15, - IE: 10 - } - }; - - - return this.each(function() { - - var settings = $.extend( {}, defaults, options), - $once = settings.once, - $warningBoxName = $(settings.warningBoxName, this), - $closeBtnName = settings.closeBtnName, - $duration = settings.duration, - $easing = settings.easing; - - - $warningBoxName.hide(); - - - // Old browser warning close button - $warningBoxName.on('click', $closeBtnName, function(e) { - e.preventDefault(); - - // Check if parameter is setup we will save user press close button - if($once == 'Yes') { - sessionStorage.setItem('DoNotShowMeItAgain', 'Yes'); - } - - $warningBoxName.fadeToggle($duration, $easing); - }); - - - // Detecting version of using browser - var browserDetect = (function () { - var ua = navigator.userAgent, tem, - M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; - if (/trident/i.test(M[1])) { - tem = /\brv[ :]+(\d+)/g.exec(ua) || []; - return 'IE ' + (tem[1] || ''); - } - if (M[1] === 'Chrome') { - tem = ua.match(/\bOPR\/(\d+)/); - if (tem !== null) return 'Opera ' + tem[1]; - } - M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; - if ((tem = ua.match(/version\/(\d+)/i)) !== null) M.splice(1, 1, tem[1]); - return M; - })(); - - - var checkBrowser = function(takesBrowsers) { - var storage = sessionStorage.getItem('DoNotShowMeItAgain'); - - // Check if user press close button - if(storage == 'Yes') { - return false; - } - - // If version of browser more old you will see window - for(var name in takesBrowsers) { - if(browserDetect.indexOf(name) != -1 && takesBrowsers[name] > browserDetect[1]) { - $warningBoxName.show(); - break; - } - } - }(settings.browsers); - }); +'use strict'; + +var checkBrowser = function(options = defaults) { + + var defaults = { + once: true, + warningBox: '.old-browser-warning', + closeBtnName: '#close-old-browser-warning', + duration: 1200, + easing: 'swing', + browsers: { + Firefox: 27, + Chrome: 30, + Opera: 15, + IE: 11 + } }; -}(jQuery)); + + var $once = defaults.once, + $warningBox = defaults.warningBox, + $closeBtnName = defaults.closeBtnName, + $duration = defaults.duration, + $easing = defaults.easing; + + document.querySelector($warningBox).addClass('hide'); + + // Old browser warning close button + document.querySelector($warningBox).on('click', $closeBtnName, function(e) { + e.preventDefault(); + + // Check if parameter is setup we will save user press close button + if($once === true) { + sessionStorage.setItem('DoNotShowMeItAgain', 'true'); + } + + document.querySelector($warningBox).fadeToggle($duration, $easing); + }); + + + // Detecting browser version + var browserDetect = (function () { + var ua = navigator.userAgent, tem, + M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; + + if (/trident/i.test(M[1])) { + tem = /\brv[ :]+(\d+)/g.exec(ua) || []; + return 'IE ' + (tem[1] || ''); + } + + if (M[1] === 'Chrome') { + tem = ua.match(/\bOPR\/(\d+)/); + if (tem !== null) return 'Opera ' + tem[1]; + } + + M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; + + if ((tem = ua.match(/version\/(\d+)/i)) !== null) M.splice(1, 1, tem[1]); + + return M; + })(); + + + var checkBrowser = function(takesBrowsers) { + var storage = sessionStorage.getItem('DoNotShowMeItAgain'); + + // Check if user press close button + if(storage === 'true') { + return false; + } + + // If version of browser more old you will see window + for(var name in takesBrowsers) { + if(browserDetect.indexOf(name) != -1 && takesBrowsers[name] > browserDetect[1]) { + $warningBox.show(); + break; + } + } + }(settings.browsers); +}; From 5ca22f909484826f247045a5b88101d3dd89aab0 Mon Sep 17 00:00:00 2001 From: IamEmpty Date: Thu, 9 Jun 2016 11:09:59 +0300 Subject: [PATCH 2/5] add jquery selector --- src/check-browser.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/check-browser.js b/src/check-browser.js index 73dee82..c30df79 100644 --- a/src/check-browser.js +++ b/src/check-browser.js @@ -1,11 +1,11 @@ 'use strict'; -var checkBrowser = function(options = defaults) { +var checkBrowser = function(options) { var defaults = { once: true, warningBox: '.old-browser-warning', - closeBtnName: '#close-old-browser-warning', + closeBtn: '#close-old-browser-warning', duration: 1200, easing: 'swing', browsers: { @@ -17,24 +17,26 @@ var checkBrowser = function(options = defaults) { }; var $once = defaults.once, - $warningBox = defaults.warningBox, - $closeBtnName = defaults.closeBtnName, + $warningBox = document.querySelector(defaults.warningBox), + $closeBtn = document.querySelector(defaults.closeBtn), $duration = defaults.duration, - $easing = defaults.easing; + $easing = defaults.easing, + $browsers = defaults.browsers; - document.querySelector($warningBox).addClass('hide'); + $warningBox.classList.add('hide'); // Old browser warning close button - document.querySelector($warningBox).on('click', $closeBtnName, function(e) { - e.preventDefault(); + $closeBtn.onclick = hidePopUp(); + function hidePopUp() { // Check if parameter is setup we will save user press close button - if($once === true) { + if($once) { sessionStorage.setItem('DoNotShowMeItAgain', 'true'); } - document.querySelector($warningBox).fadeToggle($duration, $easing); - }); + // TODO: write fadeToggle alternative + $warningBox.classList.add('hide'); + }; // Detecting browser version @@ -55,7 +57,7 @@ var checkBrowser = function(options = defaults) { M = M[2] ? [M[1], M[2]] : [navigator.appName, navigator.appVersion, '-?']; if ((tem = ua.match(/version\/(\d+)/i)) !== null) M.splice(1, 1, tem[1]); - + return M; })(); @@ -75,5 +77,5 @@ var checkBrowser = function(options = defaults) { break; } } - }(settings.browsers); + }($browsers); }; From 1575f9f8dc80efa915e53e9ec31301346a78e89b Mon Sep 17 00:00:00 2001 From: pure-js Date: Fri, 25 Nov 2016 00:44:54 +0300 Subject: [PATCH 3/5] update --- .gitignore | 3 ++ bower.json | 4 +-- demo/index.pug | 2 +- package.json | 10 +++---- src/check-browser.js | 68 +++++++++++++++++++++----------------------- 5 files changed, 43 insertions(+), 44 deletions(-) diff --git a/.gitignore b/.gitignore index 249476e..7a767f8 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,6 @@ bower_components # Build build + +# OSX +.DS_store diff --git a/bower.json b/bower.json index 8ee4db5..bf6ba18 100644 --- a/bower.json +++ b/bower.json @@ -3,13 +3,13 @@ "description": "script to check browser version", "main": "src/check-browser.js", "authors": [ - "IamEmpty" + "pure-js" ], "license": "MIT", "keywords": [ "js" ], - "homepage": "https://github.com/iamempty/check-browser", + "homepage": "https://github.com/pure-js/check-browser", "ignore": [ "**/.*", "node_modules", diff --git a/demo/index.pug b/demo/index.pug index 736dcbc..b09190f 100644 --- a/demo/index.pug +++ b/demo/index.pug @@ -129,6 +129,6 @@ html(lang='en') once: true, duration: 1000, browsers: { - Chrome: 52 + Chrome: 57 } }); diff --git a/package.json b/package.json index f326073..0bf67e4 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "check-browser", "version": "0.0.1", "description": "script to check browser version", - "main": "README.md", + "main": "src/check-browser.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "pug": "pug demo --out build", @@ -15,17 +15,17 @@ }, "repository": { "type": "git", - "url": "git+https://github.com/IamEmpty/check-browser.git" + "url": "git+https://github.com/pure-js/check-browser.git" }, "keywords": [ "js" ], - "author": "IamEmpty", + "author": "pure-js", "license": "MIT", "bugs": { - "url": "https://github.com/IamEmpty/check-browser/issues" + "url": "https://github.com/pure-js/check-browser/issues" }, - "homepage": "https://github.com/IamEmpty/check-browser#readme", + "homepage": "https://github.com/pure-js/check-browser#readme", "devDependencies": { "jshint": "^2.8.0", "pug": "^2.0.0-beta2", diff --git a/src/check-browser.js b/src/check-browser.js index c30df79..2270477 100644 --- a/src/check-browser.js +++ b/src/check-browser.js @@ -1,32 +1,30 @@ -'use strict'; - -var checkBrowser = function(options) { - - var defaults = { - once: true, - warningBox: '.old-browser-warning', - closeBtn: '#close-old-browser-warning', - duration: 1200, - easing: 'swing', - browsers: { - Firefox: 27, - Chrome: 30, - Opera: 15, - IE: 11 - } - }; +const defaults = { + once: true, + warningBox: '.old-browser-warning', + closeBtn: '#close-old-browser-warning', + duration: 1200, + easing: 'swing', + browsers: { + Firefox: 27, + Chrome: 30, + Opera: 15, + IE: 11 + } +}; - var $once = defaults.once, - $warningBox = document.querySelector(defaults.warningBox), - $closeBtn = document.querySelector(defaults.closeBtn), - $duration = defaults.duration, - $easing = defaults.easing, - $browsers = defaults.browsers; +function checkBrowser( + once = defaults.once, + warningBox = document.querySelector(defaults.warningBox), + closeBtn = document.querySelector(defaults.closeBtn), + duration = defaults.duration, + easing = defaults.easing, + browsers = defaults.browsers) { + 'use strict'; - $warningBox.classList.add('hide'); + warningBox.classList.add('hide'); // Old browser warning close button - $closeBtn.onclick = hidePopUp(); + closeBtn.onclick = hidePopUp(); function hidePopUp() { // Check if parameter is setup we will save user press close button @@ -34,14 +32,12 @@ var checkBrowser = function(options) { sessionStorage.setItem('DoNotShowMeItAgain', 'true'); } - // TODO: write fadeToggle alternative - $warningBox.classList.add('hide'); - }; - + warningBox.classList.add('hide'); + } // Detecting browser version - var browserDetect = (function () { - var ua = navigator.userAgent, tem, + let browserDetect = (function () { + let ua = navigator.userAgent, tem, M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || []; if (/trident/i.test(M[1])) { @@ -63,7 +59,7 @@ var checkBrowser = function(options) { var checkBrowser = function(takesBrowsers) { - var storage = sessionStorage.getItem('DoNotShowMeItAgain'); + let storage = sessionStorage.getItem('DoNotShowMeItAgain'); // Check if user press close button if(storage === 'true') { @@ -71,11 +67,11 @@ var checkBrowser = function(options) { } // If version of browser more old you will see window - for(var name in takesBrowsers) { - if(browserDetect.indexOf(name) != -1 && takesBrowsers[name] > browserDetect[1]) { - $warningBox.show(); + for(let name in takesBrowsers) { + if(browserDetect.indexOf(name) !== -1 && takesBrowsers[name] > browserDetect[1]) { + warningBox.show(); break; } } - }($browsers); + }(browsers); }; From f20368f3151d006520e0f888e689da25b7a0822e Mon Sep 17 00:00:00 2001 From: pure-js Date: Fri, 25 Nov 2016 02:22:18 +0300 Subject: [PATCH 4/5] go to gulp --- README.md | 3 +++ gulp/config.js | 19 +++++++++++++++++++ gulp/tasks/build.js | 28 ++++++++++++++++++++++++++++ gulp/tasks/index.js | 5 +++++ gulpfile.js | 19 +++++++++++++++++++ package.json | 19 +++++++++---------- 6 files changed, 83 insertions(+), 10 deletions(-) create mode 100644 gulp/config.js create mode 100644 gulp/tasks/build.js create mode 100644 gulp/tasks/index.js create mode 100644 gulpfile.js diff --git a/README.md b/README.md index 2e4306a..54640b5 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ # Check browser Check browser version and show pop-up if version is less then recommended + + bower i + npm i diff --git a/gulp/config.js b/gulp/config.js new file mode 100644 index 0000000..7b85261 --- /dev/null +++ b/gulp/config.js @@ -0,0 +1,19 @@ +module.exports = { + paths: { + pug: 'demo/index.pug', + pugWatch: [ + 'demo/index.pug', + ], + styl: [ + 'stylesheets/old-browser.styl' + ], + stylWatch: [ + 'src/blocks/**/*.styl' + ], + copy: ['bower_components/prism/prism.js', 'bower_components/prism/themes/prism.css', 'src/check-browser.js'], + build: 'build/' + }, + names: { + css: 'app.min.css' + } +}; diff --git a/gulp/tasks/build.js b/gulp/tasks/build.js new file mode 100644 index 0000000..03409ce --- /dev/null +++ b/gulp/tasks/build.js @@ -0,0 +1,28 @@ +const gulp = require('gulp'), + config = require('../config'), + plugins = require('gulp-load-plugins')(); + +const build = gulp.parallel(html, css, copy); + +module.exports = build; + +function html() { + return gulp.src(config.paths.pug) + .pipe(plugins.pug({ + pretty: true + })) + .pipe(gulp.dest(config.paths.build)); +} + +function css() { + return gulp.src(config.paths.styl) + .pipe(plugins.stylus({ + 'include css': true + })) + .pipe(gulp.dest(config.paths.build)); +} + +function copy() { + return gulp.src(config.paths.copy) + .pipe(gulp.dest(config.paths.build)); +} diff --git a/gulp/tasks/index.js b/gulp/tasks/index.js new file mode 100644 index 0000000..641ea60 --- /dev/null +++ b/gulp/tasks/index.js @@ -0,0 +1,5 @@ +module.exports = require('require-dir')('.', { + camelcase: true, + recurse: true + } +); diff --git a/gulpfile.js b/gulpfile.js new file mode 100644 index 0000000..a7ca0ca --- /dev/null +++ b/gulpfile.js @@ -0,0 +1,19 @@ +const gulp = require('gulp'), + del = require('del'), + // config = require('./gulp/config'), + tasks = require('./gulp/tasks'), + plugins = require('gulp-load-plugins')(); + +gulp.task('build', tasks.build); + +const clean = () => del(['build']); + +exports.clean = clean; + +// gulp.task('deploy', () => +// gulp.src(paths.dist + '**/*') +// .pipe(plugins.ghPages()) +// ); + +// The default task (called when you run `gulp` from cli) +gulp.task('default', tasks.build); diff --git a/package.json b/package.json index 0bf67e4..e7596f1 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,7 @@ "description": "script to check browser version", "main": "src/check-browser.js", "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "pug": "pug demo --out build", - "stylus": "stylus stylesheets/old-browser.styl -o build", - "copy1": "cp bower_components/prism/prism.js build", - "copy2": "cp bower_components/prism/themes/prism.css build", - "copy3": "cp src/check-browser.js build", - "build": "npm run pug && npm run stylus && npm run copy1 && npm run copy2 && npm run copy3", - "clean": "rm -rf build" + "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", @@ -27,8 +20,14 @@ }, "homepage": "https://github.com/pure-js/check-browser#readme", "devDependencies": { + "del": "^2.2.2", + "gulp-load-plugins": "^1.4.0", "jshint": "^2.8.0", - "pug": "^2.0.0-beta2", - "stylus": "^0.54.5" + "require-dir": "^0.3.1" + }, + "dependencies": { + "gulp": "github:gulpjs/gulp#4.0", + "gulp-pug": "^3.1.0", + "gulp-stylus": "^2.6.0" } } From 98e3b934a0871b0ed5061331ca41828a1ba3ffb8 Mon Sep 17 00:00:00 2001 From: pure-js Date: Fri, 25 Nov 2016 03:47:30 +0300 Subject: [PATCH 5/5] working --- demo/index.pug | 78 ++++++++++++++++++++------------------------ gulpfile.js | 12 +++++-- src/check-browser.js | 51 ++++++++++++++++------------- 3 files changed, 73 insertions(+), 68 deletions(-) diff --git a/demo/index.pug b/demo/index.pug index b09190f..37ea8d5 100644 --- a/demo/index.pug +++ b/demo/index.pug @@ -37,71 +37,63 @@ html(lang='en') h1#home The check browser version plugin p Latest version is 1.0.0 p You can use default view of this plugin look like so (See under) or create himself warning block - .row - .col-md-12 - .old-browser-warning - .old-browser-warning__left-side - h3.text-primary.h3 Warning! - p.old-browser-warning__text You use the oldest version of a browser. It may be a reason of incorrect work and view of a website. - p.old-browser-warning__text For comfortable work, please download latest version of a browser convenient for you from official website. - p.old-browser-warning__text - | Please read our - a.old-browser-warning__link(href='#') documentation - | . - .old-browser-warning__right-side - a.old-browser-warning__img-link.browser-sprite.browser-chrome(href='https://www.google.com/intl/ru/chrome/browser/', target='_blank', title='Chrome') - a.old-browser-warning__img-link.browser-sprite.browser-firefox(href='http://www.mozilla.org/ru/firefox/new/', target='_blank', title='Firefox') - a.old-browser-warning__img-link.browser-sprite.browser-ie(href='http://windows.microsoft.com/ru-ru/internet-explorer/download-ie', target='_blank', title='Internet Explorer') - a.old-browser-warning__img-link.browser-sprite.browser-opera(href='http://www.opera.com/ru', target='_blank', title='Opera') - i#close-old-browser-warning.icon-remove(title='Close') + .old-browser-warning + .old-browser-warning__left-side + h3.text-primary.h3 Warning! + p.old-browser-warning__text You use the oldest version of a browser. It may be a reason of incorrect work and view of a website. + p.old-browser-warning__text For comfortable work, please download latest version of a browser convenient for you from official website. + p.old-browser-warning__text + | Please read our + a.old-browser-warning__link(href='#') documentation + | . + .old-browser-warning__right-side + a.old-browser-warning__img-link.browser-sprite.browser-chrome(href='https://www.google.com/intl/ru/chrome/browser/', target='_blank', title='Chrome') + a.old-browser-warning__img-link.browser-sprite.browser-firefox(href='http://www.mozilla.org/ru/firefox/new/', target='_blank', title='Firefox') + a.old-browser-warning__img-link.browser-sprite.browser-ie(href='http://windows.microsoft.com/ru-ru/internet-explorer/download-ie', target='_blank', title='Internet Explorer') + a.old-browser-warning__img-link.browser-sprite.browser-opera(href='http://www.opera.com/ru', target='_blank', title='Opera') + i#close-old-browser-warning.icon-remove(title='Close') .row .col-md-12 p For begin you need check - you use jquery or not use? If you not add jquery plugin - you need do it p And inicialize plugin pre code.language-javascript. - $(document).ready(function () { - $('body').checkBrowser(); - }); - + checkBrowser(); p All supported params: pre code.language-javascript. - $(document).ready(function () { - $('body').checkBrowser({ - once: 'No', - warningBoxName: '.old-browser-warning', - closeBtnName: '#close-old-browser-warning', - duration: 1200, - easing: 'swing', - - browsers: { - Firefox: 27, - Chrome: 30, - Opera: 15, - IE: 10 - } - }); + checkBrowser({ + once: false, + warningEl: '.old-browser-warning', + closeBtnName: '#close-old-browser-warning', + duration: 1200, + easing: 'swing', + browsers: { + Firefox: 27, + Chrome: 30, + Opera: 15, + IE: 10 + } }); p In this option you can change amount of show pre code.language-javascript. - $('body').checkBrowser({ - once: 'No' + checkBrowser({ + once: false }); pre code.language-javascript. - $('body').checkBrowser({ - warningBoxName: '.old-browser-warning' + checkBrowser({ + warningEl: '.old-browser-warning' }); pre code.language-javascript. - $('body').checkBrowser({ + checkBrowser({ closeBtnName: '#close-old-browser-warning' }); pre code.language-javascript. - $('body').checkBrowser({ + checkBrowser({ duration: 1200 }); pre @@ -111,7 +103,7 @@ html(lang='en') }); pre code.language-javascript. - $('body').checkBrowser({ + checkBrowser({ browsers: { Firefox: 27, Chrome: 30, diff --git a/gulpfile.js b/gulpfile.js index a7ca0ca..d91a3ff 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -1,19 +1,25 @@ const gulp = require('gulp'), del = require('del'), - // config = require('./gulp/config'), + config = require('./gulp/config'), tasks = require('./gulp/tasks'), plugins = require('gulp-load-plugins')(); gulp.task('build', tasks.build); -const clean = () => del(['build']); +const clean = () => del([config.paths.build]); exports.clean = clean; +function watch() { + gulp.watch(config.paths.stylusWatch, tasks.build); + gulp.watch(config.paths.pugWatch, tasks.build); +} + // gulp.task('deploy', () => // gulp.src(paths.dist + '**/*') // .pipe(plugins.ghPages()) // ); // The default task (called when you run `gulp` from cli) -gulp.task('default', tasks.build); +const dev = gulp.parallel(tasks.build, watch); +gulp.task('default', dev); diff --git a/src/check-browser.js b/src/check-browser.js index 2270477..7e5f004 100644 --- a/src/check-browser.js +++ b/src/check-browser.js @@ -1,38 +1,38 @@ const defaults = { once: true, - warningBox: '.old-browser-warning', + warningEl: '.old-browser-warning', closeBtn: '#close-old-browser-warning', duration: 1200, easing: 'swing', browsers: { Firefox: 27, - Chrome: 30, + Chrome: 60, Opera: 15, IE: 11 } }; -function checkBrowser( +function checkBrowser({ once = defaults.once, - warningBox = document.querySelector(defaults.warningBox), + warningEl = document.querySelector(defaults.warningEl), closeBtn = document.querySelector(defaults.closeBtn), duration = defaults.duration, easing = defaults.easing, - browsers = defaults.browsers) { - 'use strict'; + browsers = defaults.browsers +}) { - warningBox.classList.add('hide'); + warningEl.classList.add('hide'); // Old browser warning close button - closeBtn.onclick = hidePopUp(); + closeBtn.addEventListener('click', hidePopup); - function hidePopUp() { + function hidePopup() { // Check if parameter is setup we will save user press close button - if($once) { - sessionStorage.setItem('DoNotShowMeItAgain', 'true'); + if(once) { + sessionStorage.setItem('browserWarningClose', true); } - warningBox.classList.add('hide'); + warningEl.classList.add('hide'); } // Detecting browser version @@ -57,21 +57,28 @@ function checkBrowser( return M; })(); + let currentBrowser = { + name: browserDetect[0], + version: Number(browserDetect[1]) + } - var checkBrowser = function(takesBrowsers) { - let storage = sessionStorage.getItem('DoNotShowMeItAgain'); + function findBrowser(browsers) { + let close = sessionStorage.getItem('browserWarningClose'); - // Check if user press close button - if(storage === 'true') { + // Check if user press on close button + if(close === 'true') { return false; } - // If version of browser more old you will see window - for(let name in takesBrowsers) { - if(browserDetect.indexOf(name) !== -1 && takesBrowsers[name] > browserDetect[1]) { - warningBox.show(); + // If version of browser is older - you will see the window + for(let name in browsers) { + let version = browsers[name]; + if(name === currentBrowser.name && version > currentBrowser.version) { + warningEl.classList.remove('hide'); break; } } - }(browsers); -}; + } + + findBrowser(browsers); +}