safari-beauty-toolbar
Version:
Make the Safari Toolbar more consistent with your brand colors
15 lines (14 loc) • 5.79 kB
JavaScript
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.SBToolbar=e():t.SBToolbar=e()}(window,function(){return function(t){var e={};function i(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}return i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},i.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},i.t=function(t,e){if(1&e&&(t=i(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)i.d(n,o,function(e){return t[e]}.bind(null,o));return n},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=0)}([function(t,e,i){"use strict";
/**
* Safari Beauty Toolbar
* {@link https://github.com/neSpecc/safari-beauty-toolbar}
*
* Make the Safari Toolbar more consistent with your brand colors.
* Works only on the MacOS, Safari browser that has native toolbar's opacity
*
*
* @author Petr Savchenko <specc.dev@gmail.com>
* @see CodeX - team of enthusiasts developers unifying students and graduates of the ITMO University {@link https://ifmo.su}
* @license MIT
* @preserve
*/var n;t.exports=((n=function(){function t(t){this.initialized=!1,this.currentColorIndex=0,t&&t.color?(this.color=t.color,this.init()):this.log("«color» option is missed")}return t.prototype.destroy=function(){this.initialized&&(this.stopAnimation(),this.stopBlinking(),this.underlayer.remove(),this.underlayer=null,this.color=null,this.initialized=!1)},t.prototype.reinit=function(t){this.destroy(),t&&t.color&&(this.color=t.color),this.init()},t.prototype.blink=function(t){var e=this;void 0===t&&(t={interval:400,transitionSpeed:500}),this.initialized?(this.stopAllEffects(),this.underlayer.style["will-change"]="opacity",isNaN(t.transitionSpeed)?this.log("transitionSpeed must be a number"):this.underlayer.style.transition="opacity "+t.transitionSpeed+"ms ease",this.blinkingInterval=setInterval(function(){"1"===e.underlayer.style.opacity?e.underlayer.style.opacity="0":e.underlayer.style.opacity="1"},t.interval)):this.log("Module was not initialized")},t.prototype.animate=function(t){var e=this;if(this.initialized)if(t&&t.colors){this.stopAllEffects(),this.underlayer.style["will-change"]="background-color";var i=800;t&&t.speed&&!isNaN(t.speed)&&(i=t.speed),this.underlayer.style.transition="background-color "+Math.floor(i/1.1)+"ms ease",this.animationInterval=setInterval(function(){e.underlayer.style.backgroundColor=t.colors[e.currentColorIndex],e.currentColorIndex++,e.currentColorIndex>t.colors.length&&(e.currentColorIndex=0)},i)}else this.log("Missed required parameter «colors» (array of strings) for the animation");else this.log("Module was not initialized")},t.prototype.startProgress=function(t){var e=this,i=void 0===t?{color:"#05c7ff",estimate:3500}:t,n=i.color,o=i.estimate;this.initialized?(this.stopAnimation(),this.stopBlinking(),this.underlayer.style.transition="none",this.underlayer.style.width="0",this.underlayer.style.transition="width "+(o||3500)+"ms cubic-bezier(.12,.63,.81,.44)",this.underlayer.style.backgroundColor=n||"#05c7ff",setTimeout(function(){e.underlayer.style.width="90%"},100)):this.log("Module was not initialized")},t.prototype.stopProgress=function(){var t=this;this.underlayer.style.width="100%",setTimeout(function(){t.underlayer.style.width="auto"},200)},t.prototype.stopBlinking=function(){this.initialized&&this.blinkingInterval&&(clearTimeout(this.blinkingInterval),this.blinkingInterval=null,this.underlayer.style.opacity="1")},t.prototype.stopAnimation=function(){this.initialized&&this.animationInterval&&(clearTimeout(this.animationInterval),this.animationInterval=null,this.currentColorIndex=0,this.underlayer.style.backgroundColor=this.color)},t.prototype.stopAllEffects=function(){this.stopAnimation(),this.stopBlinking(),this.stopProgress()},t.prototype.init=function(){t.supported?(this.underlayer=this.make(),this.initialized=!0):this.log("Module is not supported by current platform")},Object.defineProperty(t,"supported",{get:function(){return t.isSafari&&(t.isMac||t.isIOS)},enumerable:!0,configurable:!0}),Object.defineProperty(t,"isMac",{get:function(){return navigator.platform.toUpperCase().indexOf("MAC")>=0},enumerable:!0,configurable:!0}),Object.defineProperty(t,"isIOS",{get:function(){return!!navigator.platform.match(/(iPhone|iPod|iPad)/i)},enumerable:!0,configurable:!0}),Object.defineProperty(t,"isSafari",{get:function(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)},enumerable:!0,configurable:!0}),t.prototype.log=function(t){window.console&&window.console.log("%cSBToolbar%c"+t,"color: #047ec6;\n font-size: 11.8px;\n letter-spacing: 3px;\n border: 1px solid #047ec6;\n border-radius: 3px;\n display: inline-block;\n padding: 1px 3px;\n margin-right: 5px","")},t.prototype.make=function(){var t=document.createElement("div");return t.style.position="fixed",t.style.top="0",t.style.left="0",t.style.right="0",t.style.height="100px",t.style.transform="translateY(-99.99%)",t.style.zIndex="9999",t.style.backgroundColor=this.color,t.setAttribute("name","safari-colorful-toolbar"),document.body.appendChild(t),t},t}()).version="1.0.0",n)}])});