2020-07-01 11:26:07 +00:00
( function webpackUniversalModuleDefinition ( root , factory ) {
if ( typeof exports === 'object' && typeof module === 'object' )
module . exports = factory ( ) ;
else if ( typeof define === 'function' && define . amd )
define ( [ ] , factory ) ;
else if ( typeof exports === 'object' )
exports [ "mailgo" ] = factory ( ) ;
else
root [ "mailgo" ] = factory ( ) ;
} ) ( typeof self !== 'undefined' ? self : this , function ( ) {
return /******/ ( function ( modules ) { // webpackBootstrap
2020-06-17 21:01:27 +00:00
/******/ // The module cache
/******/ var installedModules = { } ;
/******/
/******/ // The require function
/******/ function _ _webpack _require _ _ ( moduleId ) {
/******/
/******/ // Check if module is in cache
/******/ if ( installedModules [ moduleId ] ) {
/******/ return installedModules [ moduleId ] . exports ;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules [ moduleId ] = {
/******/ i : moduleId ,
/******/ l : false ,
/******/ exports : { }
/******/ } ;
/******/
/******/ // Execute the module function
/******/ modules [ moduleId ] . call ( module . exports , module , module . exports , _ _webpack _require _ _ ) ;
/******/
/******/ // Flag the module as loaded
/******/ module . l = true ;
/******/
/******/ // Return the exports of the module
/******/ return module . exports ;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ _ _webpack _require _ _ . m = modules ;
/******/
/******/ // expose the module cache
/******/ _ _webpack _require _ _ . c = installedModules ;
/******/
/******/ // define getter function for harmony exports
/******/ _ _webpack _require _ _ . d = function ( exports , name , getter ) {
/******/ if ( ! _ _webpack _require _ _ . o ( exports , name ) ) {
/******/ Object . defineProperty ( exports , name , { enumerable : true , get : getter } ) ;
/******/ }
/******/ } ;
/******/
/******/ // define __esModule on exports
/******/ _ _webpack _require _ _ . r = function ( exports ) {
/******/ if ( typeof Symbol !== 'undefined' && Symbol . toStringTag ) {
/******/ Object . defineProperty ( exports , Symbol . toStringTag , { value : 'Module' } ) ;
/******/ }
/******/ Object . defineProperty ( exports , '__esModule' , { value : true } ) ;
/******/ } ;
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ _ _webpack _require _ _ . t = function ( value , mode ) {
/******/ if ( mode & 1 ) value = _ _webpack _require _ _ ( value ) ;
/******/ if ( mode & 8 ) return value ;
/******/ if ( ( mode & 4 ) && typeof value === 'object' && value && value . _ _esModule ) return value ;
/******/ var ns = Object . create ( null ) ;
/******/ _ _webpack _require _ _ . r ( ns ) ;
/******/ Object . defineProperty ( ns , 'default' , { enumerable : true , value : value } ) ;
/******/ if ( mode & 2 && typeof value != 'string' ) for ( var key in value ) _ _webpack _require _ _ . d ( ns , key , function ( key ) { return value [ key ] ; } . bind ( null , key ) ) ;
/******/ return ns ;
/******/ } ;
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ _ _webpack _require _ _ . n = function ( module ) {
/******/ var getter = module && module . _ _esModule ?
/******/ function getDefault ( ) { return module [ 'default' ] ; } :
/******/ function getModuleExports ( ) { return module ; } ;
/******/ _ _webpack _require _ _ . d ( getter , 'a' , getter ) ;
/******/ return getter ;
/******/ } ;
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ _ _webpack _require _ _ . o = function ( object , property ) { return Object . prototype . hasOwnProperty . call ( object , property ) ; } ;
/******/
/******/ // __webpack_public_path__
/******/ _ _webpack _require _ _ . p = "" ;
/******/
/******/
/******/ // Load entry module and return exports
2020-07-07 15:49:54 +00:00
/******/ return _ _webpack _require _ _ ( _ _webpack _require _ _ . s = 4 ) ;
2020-06-17 21:01:27 +00:00
/******/ } )
/************************************************************************/
2020-07-07 15:49:54 +00:00
/******/ ( [
/* 0 */
2020-07-01 11:26:07 +00:00
/***/ ( function ( module ) {
2020-07-27 08:20:15 +00:00
module . exports = JSON . parse ( "{\"languages\":[\"en\",\"it\",\"es\",\"de\",\"fr\",\"pt\",\"nl\"],\"translations\":{\"en\":{\"open_in_\":\"open in \",\"cc_\":\"cc \",\"bcc_\":\"bcc \",\"subject_\":\"subject \",\"body_\":\"body \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"call\",\"open\":\"open\",\"_default\":\" default\",\"_as_default\":\" as default\",\"copy\":\"copy\"},\"it\":{\"open_in_\":\"apri con \",\"cc_\":\"cc \",\"bcc_\":\"ccn \",\"subject_\":\"oggetto \",\"body_\":\"testo \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"chiama\",\"open\":\"apri\",\"_default\":\" \",\"_as_default\":\" \",\"copy\":\"copia\"},\"es\":{\"open_in_\":\"abrir con \",\"cc_\":\"cc \",\"bcc_\":\"cco \",\"subject_\":\"asunto \",\"body_\":\"cuerpo \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"llamar\",\"open\":\"abrir\",\"_default\":\" predefinido\",\"_as_default\":\" por defecto\",\"copy\":\"copiar\"},\"de\":{\"open_in_\":\"Öffnen in \",\"cc_\":\"cc \",\"bcc_\":\"bcc \",\"subject_\":\"Betreff \",\"body_\":\"Nachricht \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"Anrufen\",\"open\":\"Öffnen\",\"_default\":\" mit Standard\",\"_as_default\":\" mit Standard\",\"copy\":\"kopieren\"},\"pt\":{\"open_in_\":\"abrir com \",\"cc_\":\"cc \",\"bcc_\":\"cco \",\"subject_\":\"assunto \",\"body_\":\"corpo \",\"call\":\"ligar\",\"open\":\"abrir\",\"_default\":\" padrão\",\"_as_default\":\" por padrão\",\"copy\":\"copiar\"},\"fr\":{\"open_in_\":\"Ouvrir dans \",\"cc_\":\"cc \",\"bcc_\":\"cci \",\"subject_\":\"sujet \",\"body_\":\"contenu \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"Appeler\",\"open\":\"Ouvrir\",\"_default\":\" par défaut\",\"_as_default\":\" par défaut\",\"copy\":\"Copier\"},\"nl\":{\"open_in_\":\"open in \",\"cc_\":\"cc \",\"bcc_\":\"bcc \",\"subject_\":\"onderwerp \",\"body_\":\"bericht \",\"gmail\":\"Gmail\",\"outlook\":\"Outlook\",\"telegram\":\"Telegram\",\"whatsapp\":\"WhatsApp\",\"skype\":\"Skype\",\"call\":\"bellen\",\"open\":\"openen\",\"_default\":\" standaard\",\"_as_default\":\" als standaard\",\"copy\":\"kopiëren\"}}}" ) ;
2020-07-01 11:26:07 +00:00
/***/ } ) ,
2020-07-07 15:49:54 +00:00
/* 1 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2020-07-27 11:32:56 +00:00
var result = _ _webpack _require _ _ ( 2 ) ;
if ( typeof result === "string" ) {
module . exports = result ;
} else {
module . exports = result . toString ( ) ;
}
/***/ } ) ,
/* 2 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
// Imports
var _ _ _CSS _LOADER _API _IMPORT _ _ _ = _ _webpack _require _ _ ( 3 ) ;
2020-07-28 11:53:28 +00:00
var _ _ _CSS _LOADER _EXPORT _ _ _ = _ _ _CSS _LOADER _API _IMPORT _ _ _ ( true ) ;
2020-07-27 11:32:56 +00:00
// Module
2020-07-28 12:05:58 +00:00
_ _ _CSS _LOADER _EXPORT _ _ _ . push ( [ module . i , ".m-modal{position:fixed;top:0;right:0;bottom:0;left:0;justify-content:center;align-items:center;flex-direction:column;overflow:hidden;font-size:15px;z-index:10000}.m-modal p,.m-modal span,.m-modal strong,.m-modal a{margin:0;padding:0;font-size:100%;line-height:1;font-family:-apple-system,BlinkMacSystemFont,\"Segoe UI\",Roboto,Helvetica,Arial,sans-serif,\"Apple Color Emoji\",\"Segoe UI Emoji\",\"Segoe UI Symbol\";text-rendering:optimizeLegibility}.m-modal strong{font-weight:700}.m-modal .m-modal-back{position:absolute;z-index:10001;top:0;right:0;bottom:0;left:0;background-color:#20232a;opacity:0.8}.m-modal .m-modal-content{position:relative;z-index:10002;box-sizing:content-box;text-align:center;min-width:200px;max-width:240px;background-color:#fff;opacity:0.95;border-radius:20px;box-shadow:0 3px 20px rgba(32,35,42,0.5);color:#4a4a4a;display:flex;flex-direction:column;overflow:auto;padding:24px;transition:0.5s box-shadow}.m-modal .m-modal-content:hover{opacity:1}.m-modal .m-modal-content .m-title{margin-bottom:8px;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;line-height:1.2em}.m-modal .m-modal-content .m-details{margin-bottom:10px}.m-modal .m-modal-content .m-details p{font-size:12px;margin-top:3px;margin-bottom:3px}.m-modal .m-modal-content a{cursor:pointer;padding:10px;color:#4a4a4a;border-radius:20px;text-decoration:none}.m-modal .m-modal-content a.m-gmail{color:#d44638}.m-modal .m-modal-content a.m-gmail:hover{background-color:rgba(212,70,56,0.08);color:#d44638}.m-modal .m-modal-content a.m-outlook{color:#0072c6}.m-modal .m-modal-content a.m-outlook:hover{background-color:rgba(0,114,198,0.08);color:#0072c6}.m-modal .m-modal-content a.m-tg{color:#08c}.m-modal .m-modal-content a.m-tg:hover{background-color:rgba(0,136,204,0.08);color:#08c}.m-modal .m-modal-content a.m-wa{color:#00bfa5}.m-modal .m-modal-content a.m-wa:hover{background-color:rgba(0,191,165,0.08);color:#00bfa5}.m-modal .m-modal-content a.m-skype{color:#00aff0}.m-modal .m-modal-content a.m-skype:hover{background-color:rgba(0,175,240,0.08);color:#00aff0}.m-modal .m-modal-content a.m-copy{padding:16px 10px;font-size:16px}.m-modal .m-modal-content a.m-default:hover,.m-modal .m-modal-content a.m-copy:hover{background-color:rgba(0,0,0,0.08);color:#4a4a4a}.m-modal .m-modal-content a.m-by{font-size:9px;margin-top:0.8rem;padding:5px;color:#4a4a4a;opacity:0.55}.m-modal .m-modal-content a.m-by:hover{opacity:1}.m-modal .m-modal-content .w-500{font-weight:500}.m-modal.m-dark .m-modal-content{background-color:#20232a}.m-modal.m-dark .m-modal-content,.m-modal.m-dark .m-modal-content p,.m-modal.m-dark .m-modal-content p span,.m-modal.m-dark .m-modal-content strong{color:#fff}.m-modal.m-dark .m-modal-content a{color:#eaeaea}.m-modal.m-dark .m-modal-content a:not(.m-by):hover{background-color:rgba(134,134,134,0.08);color:#eaeaea}.m-modal.m-dark .m-modal-content a.m-gmail{color:#e07d73}.m-modal.m-dark .m-modal-content a.m-gmail:hover{background-color:rgba(212,70,56,0.08);color:#e07d73}.m-modal.m-dark .m-modal-content a.m-outlook{color:#4c9cd7}.m-modal.m-dark .m-modal-content a.m-outlook:hover{background-color:rgba(0,114,198,0.08);color:#4c9cd7}.m-modal.m-dark .m-modal-content a.m-tg{color:#4cabdb}.m-modal.m-dark .m-modal-content a.m-tg:hover{background-color:rgba(0,136,204,0.08);color:#4cabdb}.m-modal.m-dark .m-modal-content a.m-wa{color:#4cd2c0}.m-modal.m-dark .m-modal-content a.m-wa:hover{background-color:rgba(0,191,165,0.08);color:#4cd2c0}.m-modal.m-dark .m-modal-content a.m-skype{color:#4cc7f4}.m-modal.m-dark .m-modal-content a.m-skype:hover{background-color:rgba(0,175,240,0.08);color:#4cc7f4}\n" , "" , { "version" : 3 , "sources" : [ "/Users/matteo/git/mailgo/src/mailgo.scss" ] , "names" : [ ] , "mappings" : " AAsBA , SACE , cAAe , CACf , KAAM , CACN , OAAQ , CACR , QAAS , CACT , MAAO , CACP , sBAAuB , CACvB , kBAAmB , CACnB , qBAAsB , CACtB , eAAgB , CAChB , cAAe , CACf , aAAc , CAXhB , oDAiBI , QAAS , CACT , SAAU , CACV , cAAe , CACf , aAAc , CACd , gJAzCe , CA0Cf , iCAAkC , CAtBtC , gBA0BI , eAAgB , CA1BpB , uBA8BI , iBAAkB , CAClB , aAAc , CACd , KAAM , CACN , OAAQ , CACR , QAAS , CACT , MAAO , CACP , wBAAyB , CACzB , WAAY , CArChB , 0 BAyCI , iBAAkB
2020-07-27 11:32:56 +00:00
// Exports
2020-07-28 11:53:28 +00:00
module . exports = _ _ _CSS _LOADER _EXPORT _ _ _ ;
2020-07-27 11:32:56 +00:00
/***/ } ) ,
/* 3 */
/***/ ( function ( module , exports , _ _webpack _require _ _ ) {
2020-07-01 11:26:07 +00:00
"use strict" ;
/ *
MIT License http : //www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @ sokra
* /
// css base code, injected by the css-loader
// eslint-disable-next-line func-names
module . exports = function ( useSourceMap ) {
var list = [ ] ; // return the list of modules as css string
list . toString = function toString ( ) {
return this . map ( function ( item ) {
var content = cssWithMappingToString ( item , useSourceMap ) ;
if ( item [ 2 ] ) {
return "@media " . concat ( item [ 2 ] , " {" ) . concat ( content , "}" ) ;
}
return content ;
} ) . join ( '' ) ;
} ; // import a list of modules into the list
// eslint-disable-next-line func-names
list . i = function ( modules , mediaQuery , dedupe ) {
if ( typeof modules === 'string' ) {
// eslint-disable-next-line no-param-reassign
modules = [ [ null , modules , '' ] ] ;
}
var alreadyImportedModules = { } ;
if ( dedupe ) {
for ( var i = 0 ; i < this . length ; i ++ ) {
// eslint-disable-next-line prefer-destructuring
var id = this [ i ] [ 0 ] ;
if ( id != null ) {
alreadyImportedModules [ id ] = true ;
}
}
}
for ( var _i = 0 ; _i < modules . length ; _i ++ ) {
var item = [ ] . concat ( modules [ _i ] ) ;
if ( dedupe && alreadyImportedModules [ item [ 0 ] ] ) {
// eslint-disable-next-line no-continue
continue ;
}
if ( mediaQuery ) {
if ( ! item [ 2 ] ) {
item [ 2 ] = mediaQuery ;
} else {
item [ 2 ] = "" . concat ( mediaQuery , " and " ) . concat ( item [ 2 ] ) ;
}
}
list . push ( item ) ;
}
} ;
return list ;
} ;
function cssWithMappingToString ( item , useSourceMap ) {
var content = item [ 1 ] || '' ; // eslint-disable-next-line prefer-destructuring
var cssMapping = item [ 3 ] ;
if ( ! cssMapping ) {
return content ;
}
if ( useSourceMap && typeof btoa === 'function' ) {
var sourceMapping = toComment ( cssMapping ) ;
var sourceURLs = cssMapping . sources . map ( function ( source ) {
return "/*# sourceURL=" . concat ( cssMapping . sourceRoot || '' ) . concat ( source , " */" ) ;
} ) ;
return [ content ] . concat ( sourceURLs ) . concat ( [ sourceMapping ] ) . join ( '\n' ) ;
}
return [ content ] . join ( '\n' ) ;
} // Adapted from convert-source-map (MIT)
function toComment ( sourceMap ) {
// eslint-disable-next-line no-undef
var base64 = btoa ( unescape ( encodeURIComponent ( JSON . stringify ( sourceMap ) ) ) ) ;
var data = "sourceMappingURL=data:application/json;charset=utf-8;base64," . concat ( base64 ) ;
return "/*# " . concat ( data , " */" ) ;
}
/***/ } ) ,
2020-07-07 15:49:54 +00:00
/* 4 */
2020-06-17 21:01:27 +00:00
/***/ ( function ( module , _ _webpack _exports _ _ , _ _webpack _require _ _ ) {
"use strict" ;
2020-07-07 15:49:54 +00:00
// ESM COMPAT FLAG
2020-06-17 21:01:27 +00:00
_ _webpack _require _ _ . r ( _ _webpack _exports _ _ ) ;
2020-07-07 15:49:54 +00:00
// CONCATENATED MODULE: ../src/mailgo.ts
2020-06-10 17:19:38 +00:00
// i18n for mailgo
2020-07-28 11:56:38 +00:00
var i18n = _ _webpack _require _ _ ( 0 ) ; // mailgo scss
2020-07-01 12:48:18 +00:00
2020-07-27 11:32:56 +00:00
var mailgoCSS = _ _webpack _require _ _ ( 1 ) . toString ( ) ; // default lang
2020-07-01 12:48:18 +00:00
var DEFAULT _LANG = "en" ; // links
var MAILTO = "mailto:" ;
var TEL = "tel:" ;
var CALLTO = "callto:" ; // mailgo types
var MAIL _TYPE = "mail" ;
var TEL _TYPE = "tel" ; // default href for links
2020-07-07 12:48:18 +00:00
var DEFAULT _BTN _HREF = "javascript:void(0);" ; // useful html tags
2020-07-01 12:48:18 +00:00
2020-07-07 12:48:18 +00:00
var spanHTMLTag = "span" ;
var aHTMLTag = "a" ;
2020-07-10 11:02:17 +00:00
var pHTMLTag = "p" ; // global mailgo config object
var config ; // default language
2020-07-07 12:48:18 +00:00
2020-07-16 10:59:09 +00:00
var lang = DEFAULT _LANG ; // modals global object
var modalMailto , modalTel ; // mailgo variables
2020-07-01 12:48:18 +00:00
var url ,
mail = "" ,
encEmail = "" ,
cc = "" ,
bcc = "" ,
subject = "" ,
bodyMail = "" ; // mailgo tel variables
var tel = "" ,
msg = "" ,
telegramUsername = "" ,
skypeUsername = "" ; // the DOM elements
2020-07-24 08:21:11 +00:00
var title , titleTel , detailCc , detailBcc , detailSubject , detailBody , ccValue , bccValue , subjectValue , bodyValue , activatedLink ; // mailgo buttons (actions)
2020-07-01 12:48:18 +00:00
2020-07-07 15:49:54 +00:00
var gmail , outlook , mailgo _open , telegram , wa , skype , call , copyMail , copyTel ;
2020-04-24 19:51:34 +00:00
/ * *
* mailgoInit
* the function that creates the mailgo elements in DOM
* /
2020-07-01 12:48:18 +00:00
2020-07-28 11:56:38 +00:00
var mailgoInit = function mailgoInit ( ) {
2020-07-10 11:02:17 +00:00
var _config , _config2 ;
2020-07-17 08:45:21 +00:00
// translations
2020-07-28 11:56:38 +00:00
var _ref = i18n ,
2020-07-07 12:48:18 +00:00
translations = _ref . translations ; // if a default language is defined use it
2020-07-01 12:48:18 +00:00
2020-07-28 11:56:38 +00:00
if ( ( ( _config = config ) === null || _config === void 0 ? void 0 : _config . lang ) && i18n . languages . includes ( config . lang ) ) {
2020-07-10 11:02:17 +00:00
lang = config . lang ;
2020-07-01 12:48:18 +00:00
} // if is defined <html lang=""> use it!
2020-07-10 11:02:17 +00:00
if ( ! ( ( _config2 = config ) === null || _config2 === void 0 ? void 0 : _config2 . forceLang ) ) {
2020-07-01 20:53:28 +00:00
// keep the lang from html
var htmlLang = document . documentElement . lang ; // if there are translations...
2020-07-28 11:56:38 +00:00
if ( i18n . languages . includes ( htmlLang ) ) {
2020-07-01 20:53:28 +00:00
lang = document . documentElement . lang ;
}
2020-07-01 12:48:18 +00:00
} // strings
var defaultStrings = translations [ DEFAULT _LANG ] ;
var strings = translations [ lang ] ; // mailgo mail
{
2020-07-10 11:02:17 +00:00
var _config3 ;
2020-07-01 12:48:18 +00:00
// modal
2020-07-16 10:59:09 +00:00
modalMailto = createElement ( ) ;
modalMailto . style . display = "none" ;
modalMailto . id = "mailgo" ;
2020-07-24 08:21:11 +00:00
modalMailto . classList . add ( "m-modal" ) ;
modalMailto . setAttribute ( "role" , "dialog" ) ;
modalMailto . setAttribute ( "tabindex" , "-1" ) ;
modalMailto . setAttribute ( "aria-labelledby" , "m-title" ) ; // if dark is in config
2020-07-02 09:50:45 +00:00
2020-07-10 11:02:17 +00:00
if ( ( _config3 = config ) === null || _config3 === void 0 ? void 0 : _config3 . dark ) {
2020-07-16 13:11:40 +00:00
enableDarkMode ( MAIL _TYPE ) ;
} else {
disableDarkMode ( MAIL _TYPE ) ;
2020-07-02 09:50:45 +00:00
} // background
2020-07-01 12:48:18 +00:00
var modalBackground = createElement ( ) ;
modalBackground . className = "m-modal-back" ;
2020-07-16 10:59:09 +00:00
modalMailto . appendChild ( modalBackground ) ; // modal content
2020-07-01 12:48:18 +00:00
var modalContent = createElement ( ) ;
modalContent . className = "m-modal-content" ;
2020-07-16 10:59:09 +00:00
modalMailto . appendChild ( modalContent ) ; // title (email address)
2020-07-01 12:48:18 +00:00
title = createElement ( "strong" ) ;
title . id = "m-title" ;
title . className = "m-title" ;
modalContent . appendChild ( title ) ; // details
var details = createElement ( ) ;
details . id = "m-details" ;
details . className = "m-details" ;
2020-07-07 12:48:18 +00:00
detailCc = createElement ( pHTMLTag ) ;
2020-07-01 12:48:18 +00:00
detailCc . id = "m-cc" ;
2020-07-07 12:48:18 +00:00
var ccSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
ccSpan . className = "w-500" ;
2020-07-02 15:38:15 +00:00
ccSpan . appendChild ( createTextNode ( strings . cc _ || defaultStrings . cc _ ) ) ;
2020-07-07 12:48:18 +00:00
ccValue = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
ccValue . id = "m-cc-value" ;
detailCc . appendChild ( ccSpan ) ;
detailCc . appendChild ( ccValue ) ;
details . appendChild ( detailCc ) ;
2020-07-07 12:48:18 +00:00
detailBcc = createElement ( pHTMLTag ) ;
2020-07-01 12:48:18 +00:00
detailBcc . id = "m-bcc" ;
2020-07-07 12:48:18 +00:00
var bccSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
bccSpan . className = "w-500" ;
2020-07-02 15:38:15 +00:00
bccSpan . appendChild ( createTextNode ( strings . bcc _ || defaultStrings . bcc _ ) ) ;
2020-07-07 12:48:18 +00:00
bccValue = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
bccValue . id = "m-bcc-value" ;
detailBcc . appendChild ( bccSpan ) ;
detailBcc . appendChild ( bccValue ) ;
details . appendChild ( detailBcc ) ;
2020-07-07 12:48:18 +00:00
detailSubject = createElement ( pHTMLTag ) ;
2020-07-01 12:48:18 +00:00
detailSubject . id = "m-subject" ;
2020-07-07 12:48:18 +00:00
var subjectSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
subjectSpan . className = "w-500" ;
2020-07-02 15:38:15 +00:00
subjectSpan . appendChild ( createTextNode ( strings . subject _ || defaultStrings . subject _ ) ) ;
2020-07-07 12:48:18 +00:00
subjectValue = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
subjectValue . id = "m-subject-value" ;
detailSubject . appendChild ( subjectSpan ) ;
detailSubject . appendChild ( subjectValue ) ;
details . appendChild ( detailSubject ) ;
2020-07-07 12:48:18 +00:00
detailBody = createElement ( pHTMLTag ) ;
2020-07-01 12:48:18 +00:00
detailBody . id = "m-body" ;
2020-07-07 12:48:18 +00:00
var bodySpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
bodySpan . className = "w-500" ;
2020-07-02 15:38:15 +00:00
bodySpan . appendChild ( createTextNode ( strings . body _ || defaultStrings . body _ ) ) ;
2020-07-07 12:48:18 +00:00
bodyValue = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
bodyValue . id = "m-body-value" ;
detailBody . appendChild ( bodySpan ) ;
detailBody . appendChild ( bodyValue ) ;
details . appendChild ( detailBody ) ;
modalContent . appendChild ( details ) ; // Gmail
2020-07-07 12:48:18 +00:00
gmail = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
gmail . id = "m-gmail" ;
gmail . href = DEFAULT _BTN _HREF ;
gmail . classList . add ( "m-open" ) ;
gmail . classList . add ( "m-gmail" ) ;
2020-07-21 11:03:35 +00:00
gmail . appendChild ( createTextNode ( strings . open _in _ || defaultStrings . open _in _ ) ) ;
2020-07-07 12:48:18 +00:00
var gmailSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
gmailSpan . className = "w-500" ;
gmailSpan . appendChild ( createTextNode ( strings . gmail || defaultStrings . gmail ) ) ;
gmail . appendChild ( gmailSpan ) ;
modalContent . appendChild ( gmail ) ; // Outlook
2020-07-07 12:48:18 +00:00
outlook = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
outlook . id = "m-outlook" ;
outlook . href = DEFAULT _BTN _HREF ;
outlook . classList . add ( "m-open" ) ;
outlook . classList . add ( "m-outlook" ) ;
2020-07-21 11:03:35 +00:00
outlook . appendChild ( createTextNode ( strings . open _in _ || defaultStrings . open _in _ ) ) ;
2020-07-07 12:48:18 +00:00
var outlookSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
outlookSpan . className = "w-500" ;
outlookSpan . appendChild ( createTextNode ( strings . outlook || defaultStrings . outlook ) ) ;
outlook . appendChild ( outlookSpan ) ;
modalContent . appendChild ( outlook ) ; // open default
2020-07-07 15:49:54 +00:00
mailgo _open = createElement ( aHTMLTag ) ;
mailgo _open . id = "m-open" ;
mailgo _open . href = DEFAULT _BTN _HREF ;
mailgo _open . classList . add ( "m-open" ) ;
mailgo _open . classList . add ( "m-default" ) ;
2020-07-07 12:48:18 +00:00
var openSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
openSpan . className = "w-500" ;
openSpan . appendChild ( createTextNode ( strings . open || defaultStrings . open ) ) ;
2020-07-07 15:49:54 +00:00
mailgo _open . appendChild ( openSpan ) ;
mailgo _open . appendChild ( createTextNode ( strings . _default || defaultStrings . _default ) ) ;
modalContent . appendChild ( mailgo _open ) ; // copy
2020-07-01 12:48:18 +00:00
2020-07-07 12:48:18 +00:00
copyMail = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
copyMail . id = "m-copy" ;
copyMail . href = DEFAULT _BTN _HREF ;
copyMail . classList . add ( "m-copy" ) ;
copyMail . classList . add ( "w-500" ) ;
copyMail . appendChild ( createTextNode ( strings . copy || defaultStrings . copy ) ) ;
modalContent . appendChild ( copyMail ) ;
modalContent . appendChild ( byElement ( ) ) ; // add the modal at the end of the body
2020-07-16 10:59:09 +00:00
document . body . appendChild ( modalMailto ) ; // every click outside the modal will hide the modal
2020-07-01 12:48:18 +00:00
modalBackground . addEventListener ( "click" , hideMailgo ) ;
} // mailgo tel
{
2020-07-10 11:02:17 +00:00
var _config4 ;
2020-07-01 12:48:18 +00:00
// modal
2020-07-16 10:59:09 +00:00
modalTel = createElement ( ) ;
modalTel . style . display = "none" ;
modalTel . id = "mailgo-tel" ;
2020-07-24 08:21:11 +00:00
modalTel . classList . add ( "m-modal" ) ;
modalTel . setAttribute ( "role" , "dialog" ) ;
modalTel . setAttribute ( "tabindex" , "-1" ) ;
modalTel . setAttribute ( "aria-labelledby" , "m-tel-title" ) ; // if dark is in config
2020-07-02 15:38:15 +00:00
2020-07-10 11:02:17 +00:00
if ( ( _config4 = config ) === null || _config4 === void 0 ? void 0 : _config4 . dark ) {
2020-07-16 13:11:40 +00:00
enableDarkMode ( TEL _TYPE ) ;
} else {
disableDarkMode ( TEL _TYPE ) ;
2020-07-02 15:38:15 +00:00
} // background
2020-07-01 12:48:18 +00:00
var _modalBackground = createElement ( ) ;
_modalBackground . className = "m-modal-back" ;
2020-07-16 10:59:09 +00:00
modalTel . appendChild ( _modalBackground ) ; // modal content
2020-07-01 12:48:18 +00:00
var _modalContent = createElement ( ) ;
_modalContent . className = "m-modal-content" ;
2020-07-16 10:59:09 +00:00
modalTel . appendChild ( _modalContent ) ; // title (telephone number)
2020-07-01 12:48:18 +00:00
titleTel = createElement ( "strong" ) ;
titleTel . id = "m-tel-title" ;
titleTel . className = "m-title" ;
_modalContent . appendChild ( titleTel ) ; // Telegram
2020-07-07 12:48:18 +00:00
telegram = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
telegram . id = "m-tg" ;
telegram . href = DEFAULT _BTN _HREF ;
telegram . classList . add ( "m-open" ) ;
telegram . classList . add ( "m-tg" ) ; // by default not display
telegram . style . display = "none" ;
2020-07-21 11:03:35 +00:00
telegram . appendChild ( createTextNode ( strings . open _in _ || defaultStrings . open _in _ ) ) ;
2020-07-07 12:48:18 +00:00
var telegramSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
telegramSpan . className = "w-500" ;
telegramSpan . appendChild ( createTextNode ( strings . telegram || defaultStrings . telegram ) ) ;
telegram . appendChild ( telegramSpan ) ;
_modalContent . appendChild ( telegram ) ; // WhatsApp
2020-07-07 12:48:18 +00:00
wa = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
wa . id = "m-wa" ;
wa . href = DEFAULT _BTN _HREF ;
wa . classList . add ( "m-open" ) ;
wa . classList . add ( "m-wa" ) ;
2020-07-21 11:03:35 +00:00
wa . appendChild ( createTextNode ( strings . open _in _ || defaultStrings . open _in _ ) ) ;
2020-07-07 12:48:18 +00:00
var waSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
waSpan . className = "w-500" ;
waSpan . appendChild ( createTextNode ( strings . whatsapp || defaultStrings . whatsapp ) ) ;
wa . appendChild ( waSpan ) ;
_modalContent . appendChild ( wa ) ; // Skype
2020-07-07 12:48:18 +00:00
skype = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
skype . id = "m-skype" ;
skype . href = DEFAULT _BTN _HREF ;
skype . classList . add ( "m-open" ) ;
skype . classList . add ( "m-skype" ) ;
2020-07-21 11:03:35 +00:00
skype . appendChild ( createTextNode ( strings . open _in _ || defaultStrings . open _in _ ) ) ;
2020-07-07 12:48:18 +00:00
var skypeSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
skypeSpan . className = "w-500" ;
skypeSpan . appendChild ( createTextNode ( strings . skype || defaultStrings . skype ) ) ;
skype . appendChild ( skypeSpan ) ;
_modalContent . appendChild ( skype ) ; // call default
2020-07-07 12:48:18 +00:00
call = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
call . id = "m-call" ;
call . href = DEFAULT _BTN _HREF ;
call . classList . add ( "m-open" ) ;
call . classList . add ( "m-default" ) ;
2020-07-07 12:48:18 +00:00
var callSpan = createElement ( spanHTMLTag ) ;
2020-07-01 12:48:18 +00:00
callSpan . className = "w-500" ;
callSpan . appendChild ( createTextNode ( strings . call || defaultStrings . call ) ) ;
call . appendChild ( callSpan ) ;
call . appendChild ( createTextNode ( strings . _as _default || defaultStrings . _as _default ) ) ;
_modalContent . appendChild ( call ) ; // copy
2020-07-07 12:48:18 +00:00
copyTel = createElement ( aHTMLTag ) ;
2020-07-01 12:48:18 +00:00
copyTel . id = "m-tel-copy" ;
copyTel . href = DEFAULT _BTN _HREF ;
copyTel . classList . add ( "m-copy" ) ;
copyTel . classList . add ( "w-500" ) ;
copyTel . appendChild ( createTextNode ( strings . copy || defaultStrings . copy ) ) ;
_modalContent . appendChild ( copyTel ) ;
_modalContent . appendChild ( byElement ( ) ) ; // add the modal at the end of the body
2020-07-16 10:59:09 +00:00
document . body . appendChild ( modalTel ) ; // every click outside the modal will hide the modal
2020-07-01 12:48:18 +00:00
_modalBackground . addEventListener ( "click" , hideMailgo ) ;
} // event listener on body, if the element is mailgo-compatible the mailgo modal will be rendered
document . addEventListener ( "click" , mailgoCheckRender ) ;
2020-04-24 19:51:34 +00:00
} ;
/ * *
* mailgoRender
* function to render a mailgo ( mail or tel )
* /
2020-07-01 12:48:18 +00:00
2020-07-21 15:09:57 +00:00
function mailgoRender ( ) {
2020-07-16 18:25:29 +00:00
var _config7 ;
2020-07-01 12:48:18 +00:00
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
2020-07-16 13:11:40 +00:00
var mailgoElement = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2020-07-01 12:48:18 +00:00
// mailgo mail
if ( type === MAIL _TYPE ) {
2020-07-10 11:09:04 +00:00
var _config5 , _config6 ;
2020-07-01 12:48:18 +00:00
// if the element href=^"mailto:"
2020-07-16 13:11:40 +00:00
if ( mailgoElement . href && mailgoElement . href . toLowerCase ( ) . startsWith ( MAILTO ) ) {
mail = decodeURIComponent ( mailgoElement . href . split ( "?" ) [ 0 ] . split ( MAILTO ) [ 1 ] . trim ( ) ) ;
url = new URL ( mailgoElement . href ) ;
2020-07-01 12:48:18 +00:00
var urlParams = url . searchParams ; // optional parameters for the email
cc = urlParams . get ( "cc" ) ;
bcc = urlParams . get ( "bcc" ) ;
subject = urlParams . get ( "subject" ) ;
bodyMail = urlParams . get ( "body" ) ;
} else {
// if the element href="#mailgo" or class="mailgo"
// mail = data-address + @ + data-domain
2020-07-16 13:11:40 +00:00
mail = mailgoElement . getAttribute ( "data-address" ) + "@" + mailgoElement . getAttribute ( "data-domain" ) ;
2020-07-01 12:48:18 +00:00
url = new URL ( MAILTO + encodeURIComponent ( mail ) ) ; // cc = data-cc-address + @ + data-cc-domain
2020-07-16 13:11:40 +00:00
cc = mailgoElement . getAttribute ( "data-cc-address" ) + "@" + mailgoElement . getAttribute ( "data-cc-domain" ) ; // bcc = data-bcc-address + @ + data-bcc-domain
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
bcc = mailgoElement . getAttribute ( "data-bcc-address" ) + "@" + mailgoElement . getAttribute ( "data-bcc-domain" ) ; // subject = data-subject
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
subject = mailgoElement . getAttribute ( "data-subject" ) ; // body = data-body
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
bodyMail = mailgoElement . getAttribute ( "data-body" ) ;
2020-07-21 15:09:57 +00:00
}
2020-07-01 12:48:18 +00:00
2020-07-10 11:09:04 +00:00
if ( typeof ( ( _config5 = config ) === null || _config5 === void 0 ? void 0 : _config5 . validateEmail ) === "undefined" || ( ( _config6 = config ) === null || _config6 === void 0 ? void 0 : _config6 . validateEmail ) === true ) {
// validate the email address
if ( ! validateEmails ( mail . split ( "," ) ) ) return ; // if cc, bcc are not valid cc, bcc = ""
2020-07-01 12:48:18 +00:00
2020-07-10 11:09:04 +00:00
if ( cc && ! validateEmails ( cc . split ( "," ) ) ) cc = "" ;
if ( bcc && ! validateEmails ( bcc . split ( "," ) ) ) bcc = "" ;
} // the title of the modal (email address)
2020-07-01 12:48:18 +00:00
title . innerHTML = mail . split ( "," ) . join ( "<br/>" ) ; // add the details if provided
cc ? ( detailCc . style . display = "block" , ccValue . innerHTML = cc . split ( "," ) . join ( "<br/>" ) ) : detailCc . style . display = "none" ;
bcc ? ( detailBcc . style . display = "block" , bccValue . innerHTML = bcc . split ( "," ) . join ( "<br/>" ) ) : detailBcc . style . display = "none" ;
subject ? ( detailSubject . style . display = "block" , subjectValue . textContent = subject ) : detailSubject . style . display = "none" ;
bodyMail ? ( detailBody . style . display = "block" , bodyValue . textContent = bodyMail ) : detailBody . style . display = "none" ; // add the actions
gmail . addEventListener ( "click" , openGmail ) ;
outlook . addEventListener ( "click" , openOutlook ) ;
encEmail = encodeEmail ( mail ) ;
2020-07-07 15:49:54 +00:00
mailgo _open . addEventListener ( "click" , openDefault ) ;
2020-07-01 12:48:18 +00:00
copyMail . addEventListener ( "click" , function ( ) {
return copy ( mail ) ;
} ) ;
} // mailgo tel
2020-07-16 13:11:40 +00:00
else if ( type === TEL _TYPE ) {
if ( mailgoElement . href && mailgoElement . href . toLowerCase ( ) . startsWith ( TEL ) ) {
tel = decodeURIComponent ( mailgoElement . href . split ( "?" ) [ 0 ] . split ( TEL ) [ 1 ] . trim ( ) ) ;
} else if ( mailgoElement . href && mailgoElement . href . toLowerCase ( ) . startsWith ( CALLTO ) ) {
tel = decodeURIComponent ( mailgoElement . href . split ( "?" ) [ 0 ] . split ( CALLTO ) [ 1 ] . trim ( ) ) ;
} else if ( mailgoElement . hasAttribute ( "data-tel" ) ) {
tel = mailgoElement . getAttribute ( "data-tel" ) ;
msg = mailgoElement . getAttribute ( "data-msg" ) ;
} // validate the phone number
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
if ( ! validateTel ( tel ) ) return ; // Telegram username
2020-07-10 11:02:17 +00:00
2020-07-16 13:11:40 +00:00
if ( mailgoElement . hasAttribute ( "data-telegram" ) ) {
telegramUsername = mailgoElement . getAttribute ( "data-telegram" ) ;
} else {
telegramUsername = null ;
} // Telegram username
2020-07-10 11:02:17 +00:00
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
if ( mailgoElement . hasAttribute ( "data-skype" ) ) {
skypeUsername = mailgoElement . getAttribute ( "data-skype" ) ;
} // the title of the modal (tel)
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
titleTel . innerHTML = tel ; // add the actions to buttons
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
wa . addEventListener ( "click" , openWhatsApp ) ; // telegram must be shown only if data-telegram is provided
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
if ( telegramUsername ) {
document . getElementById ( "m-tg" ) . style . display = "block" ;
telegram . addEventListener ( "click" , openTelegram ) ;
} else {
document . getElementById ( "m-tg" ) . style . display = "none" ;
}
2020-07-01 12:48:18 +00:00
2020-07-16 13:11:40 +00:00
skype . addEventListener ( "click" , openSkype ) ;
call . addEventListener ( "click" , callDefault ) ;
copyTel . addEventListener ( "click" , function ( ) {
return copy ( tel ) ;
} ) ;
2020-07-16 18:25:29 +00:00
} // if config.dark is set to true then all the modals will be in dark mode
2020-07-01 12:48:18 +00:00
2020-07-16 18:25:29 +00:00
if ( ! ( ( _config7 = config ) === null || _config7 === void 0 ? void 0 : _config7 . dark ) ) {
// if the element contains dark as class enable dark mode
if ( mailgoElement . classList . contains ( "dark" ) ) {
enableDarkMode ( type ) ;
} else {
disableDarkMode ( type ) ;
}
2020-07-01 12:48:18 +00:00
} // show the mailgo
showMailgo ( type ) ; // add listener keyDown
document . addEventListener ( "keydown" , mailgoKeydown ) ;
2020-07-21 15:09:57 +00:00
} // actions
2020-07-01 12:48:18 +00:00
var openGmail = function openGmail ( ) {
// Gmail url
var gmailUrl = "https://mail.google.com/mail/u/0/?view=cm&source=mailto&to=" + encodeURIComponent ( mail ) ; // the details if provided
if ( cc ) gmailUrl = gmailUrl . concat ( "&cc=" + encodeURIComponent ( cc ) ) ;
if ( bcc ) gmailUrl = gmailUrl . concat ( "&bcc=" + encodeURIComponent ( bcc ) ) ;
if ( subject ) gmailUrl = gmailUrl . concat ( "&subject=" + subject ) ;
if ( bodyMail ) gmailUrl = gmailUrl . concat ( "&body=" + bodyMail ) ; // open the link
window . open ( gmailUrl , "_blank" ) ; // hide the modal
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var openOutlook = function openOutlook ( ) {
// Outlook url
var outlookUrl = "https://outlook.live.com/owa/?path=/mail/action/compose&to=" + encodeURIComponent ( mail ) ; // the details if provided
if ( subject ) outlookUrl = outlookUrl . concat ( "&subject=" + subject ) ;
if ( bodyMail ) outlookUrl = outlookUrl . concat ( "&body=" + bodyMail ) ; // open the link
window . open ( outlookUrl , "_blank" ) ; // hide the modal
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var openDefault = function openDefault ( ) {
mailToEncoded ( encEmail ) ;
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var openTelegram = function openTelegram ( ) {
// Telegram url
var tgUrl = "https://t.me/" + telegramUsername ; // open the url
window . open ( tgUrl , "_blank" ) ; // hide the modal
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var openSkype = function openSkype ( ) {
var skype = skypeUsername !== "" ? skypeUsername : tel ; // Telegram url
var skypeUrl = "skype:" + skype ; // open the url
window . open ( skypeUrl , "_blank" ) ; // hide the modal
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var openWhatsApp = function openWhatsApp ( ) {
// WhatsApp url
var waUrl = "https://wa.me/" + tel ; // the details if provided
if ( msg ) waUrl + "?text=" + msg ; // open the url
window . open ( waUrl , "_blank" ) ; // hide the modal
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var callDefault = function callDefault ( ) {
var callUrl = "tel:" + tel ;
window . open ( callUrl ) ;
hideMailgo ( ) ;
2020-04-24 19:51:34 +00:00
} ;
2020-07-01 12:48:18 +00:00
var copy = function copy ( content ) {
copyToClipboard ( content ) ;
var activeCopy ; // the correct copyButton (mail or tel)
mailgoIsShowing ( MAIL _TYPE ) ? activeCopy = copyMail : activeCopy = copyTel ;
activeCopy . textContent = "copied" ;
setTimeout ( function ( ) {
activeCopy . textContent = "copy" ; // hide after the timeout
2020-04-24 16:01:25 +00:00
hideMailgo ( ) ;
2020-07-01 12:48:18 +00:00
} , 999 ) ;
} ; // function that returns if an element is a mailgo
2020-07-21 15:09:57 +00:00
function isMailgo ( element ) {
2020-07-01 12:48:18 +00:00
var type = arguments . length > 1 && arguments [ 1 ] !== undefined ? arguments [ 1 ] : MAIL _TYPE ;
var href = element . href ; // mailgo type mail
if ( type === MAIL _TYPE ) {
return ( // first case: it is an <a> element with "mailto:..." in href and no no-mailgo in classList
href && href . toLowerCase ( ) . startsWith ( MAILTO ) && ! element . classList . contains ( "no-mailgo" ) || element . hasAttribute ( "data-address" ) && ( // second case: the href=#mailgo
href && element . getAttribute ( "href" ) . toLowerCase ( ) === "#mailgo" || // third case: the classList contains mailgo
element . classList && element . classList . contains ( "mailgo" ) )
) ;
} // mailgo type tel
if ( type === TEL _TYPE ) {
return ( // first case: it is an <a> element with "tel:..." or "callto:..." in href and no no-mailgo in classList
href && ( href . toLowerCase ( ) . startsWith ( TEL ) || href . toLowerCase ( ) . startsWith ( CALLTO ) ) && ! element . classList . contains ( "no-mailgo" ) || element . hasAttribute ( "data-tel" ) && // second case: the href=#mailgo
href && element . getAttribute ( "href" ) . toLowerCase ( ) === "#mailgo" || // third case: the classList contains mailgo
element . classList && element . classList . contains ( "mailgo" )
) ;
}
return false ;
2020-07-21 15:09:57 +00:00
}
2020-04-24 19:51:34 +00:00
/ * *
* mailgoCheckRender
* function to check if an element is mailgo - enabled or not referencing to
* mail :
* document . querySelectorAll (
* 'a[href^="mailto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
* ) ;
* tel :
* document . querySelectorAll (
* 'a[href^="tel:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
* ) ;
* or
* document . querySelectorAll (
* 'a[href^="callto:" i]:not(.no-mailgo), a[href="#mailgo"], a.mailgo'
* ) ;
* /
2020-07-01 12:48:18 +00:00
2020-07-21 15:09:57 +00:00
function mailgoCheckRender ( event ) {
2020-07-01 12:48:18 +00:00
// check if the id=mailgo exists in the body
2020-07-16 11:21:14 +00:00
if ( ! document . contains ( modalMailto ) || ! document . contains ( modalTel ) ) return false ; // if a mailgo is already showing do nothing
2020-07-01 12:48:18 +00:00
if ( mailgoIsShowing ( MAIL _TYPE ) || mailgoIsShowing ( TEL _TYPE ) ) return false ; // the path of the event
var path = event . composedPath && event . composedPath ( ) || composedPath ( event . target ) ;
if ( path ) {
path . forEach ( function ( element ) {
if ( element instanceof HTMLDocument || element instanceof Window ) return false ; // go in the event.path to find if the user has clicked on a mailgo element
if ( isMailgo ( element , MAIL _TYPE ) ) {
// stop the normal execution of the element click
event . preventDefault ( ) ; // render mailgo
mailgoRender ( MAIL _TYPE , element ) ;
return true ;
}
if ( isMailgo ( element , TEL _TYPE ) ) {
// stop the normal execution of the element click
event . preventDefault ( ) ; // render mailgo
mailgoRender ( TEL _TYPE , element ) ;
return true ;
}
} ) ;
}
return false ;
2020-07-21 15:09:57 +00:00
}
2020-04-24 19:51:34 +00:00
/ * *
* mailgoKeydown
* function to manage the keydown event when the modal is showing
* /
2020-07-01 12:48:18 +00:00
2020-07-16 11:21:14 +00:00
var mailgoKeydown = function mailgoKeydown ( keyboardEvent ) {
2020-07-01 12:48:18 +00:00
// if mailgo is showing
if ( mailgoIsShowing ( MAIL _TYPE ) ) {
2020-07-16 11:21:14 +00:00
switch ( keyboardEvent . keyCode ) {
2020-07-01 12:48:18 +00:00
case 27 :
// Escape
hideMailgo ( ) ;
break ;
case 71 :
// g -> open GMail
openGmail ( ) ;
break ;
case 79 :
// o -> open Outlook
openOutlook ( ) ;
break ;
case 32 :
case 13 :
// spacebar or enter -> open default
openDefault ( ) ;
break ;
case 67 :
// c -> copy
copy ( mail ) ;
break ;
default :
return ;
2020-04-25 13:19:10 +00:00
}
2020-07-01 12:48:18 +00:00
} else if ( mailgoIsShowing ( TEL _TYPE ) ) {
2020-07-16 11:21:14 +00:00
switch ( keyboardEvent . keyCode ) {
2020-07-01 12:48:18 +00:00
case 27 :
// Escape
hideMailgo ( ) ;
break ;
case 84 :
// t -> open Telegram
openTelegram ( ) ;
break ;
case 87 :
// w -> open WhatsApp
openWhatsApp ( ) ;
break ;
case 32 :
case 13 :
// spacebar or enter -> call default
callDefault ( ) ;
break ;
case 67 :
// c -> copy
copy ( tel ) ;
break ;
default :
return ;
2020-04-25 13:19:10 +00:00
}
2020-07-01 12:48:18 +00:00
}
return ;
} ; // show the modal
var showMailgo = function showMailgo ( ) {
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
2020-07-16 11:21:14 +00:00
// show the correct modal
2020-07-16 12:24:45 +00:00
setModalDisplay ( type , "flex" ) ;
2020-07-01 12:48:18 +00:00
} ; // hide the modal
var hideMailgo = function hideMailgo ( ) {
2020-07-16 11:21:14 +00:00
// hide all the modals
2020-07-16 12:24:45 +00:00
setModalDisplay ( MAIL _TYPE , "none" ) ;
setModalDisplay ( TEL _TYPE , "none" ) ; // remove listener keyDown
2020-07-01 12:48:18 +00:00
document . removeEventListener ( "keydown" , mailgoKeydown ) ;
} ; // is the mailgo modal hidden?
var mailgoIsShowing = function mailgoIsShowing ( ) {
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
2020-07-16 12:24:45 +00:00
return getModalDisplay ( type ) === "flex" ;
2020-04-25 13:19:10 +00:00
} ;
2020-07-01 12:48:18 +00:00
var byElement = function byElement ( ) {
// by
2020-07-07 12:49:37 +00:00
var by = createElement ( aHTMLTag ) ;
2020-07-10 08:47:11 +00:00
by . href = "https://mailgo.dev?ref=mailgo-modal" ;
2020-07-01 12:48:18 +00:00
by . className = "m-by" ;
by . target = "_blank" ;
by . rel = "noopener noreferrer" ;
2020-07-10 08:47:11 +00:00
by . appendChild ( createTextNode ( "mailgo.dev" ) ) ;
2020-07-01 12:48:18 +00:00
return by ;
} ; // create element
var createElement = function createElement ( ) {
var element = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : "div" ;
return document . createElement ( element ) ;
} ; // create text node
var createTextNode = function createTextNode ( element ) {
return document . createTextNode ( element ) ;
} ; // decrypt email
var mailToEncoded = function mailToEncoded ( encoded ) {
return window . location . href = MAILTO + atob ( encoded ) ;
} ; // encode email
var encodeEmail = function encodeEmail ( email ) {
return btoa ( email ) ;
2020-07-16 11:21:14 +00:00
} ; // get the correct HTMLElement from a type
2020-07-01 12:48:18 +00:00
2020-07-16 11:21:14 +00:00
var getModalHTMLElement = function getModalHTMLElement ( ) {
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
return type === TEL _TYPE ? modalTel : modalMailto ;
2020-07-01 12:48:18 +00:00
} ; // get display value
2020-07-16 12:24:45 +00:00
var getModalDisplay = function getModalDisplay ( ) {
2020-07-16 11:21:14 +00:00
var ref = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
2020-07-16 12:24:45 +00:00
return getModalHTMLElement ( ref ) . style . display ;
2020-07-24 08:21:11 +00:00
} ; // set display value
2020-07-01 12:48:18 +00:00
2020-07-16 12:24:45 +00:00
var setModalDisplay = function setModalDisplay ( ) {
2020-07-16 11:21:14 +00:00
var ref = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
var value = arguments . length > 1 ? arguments [ 1 ] : undefined ;
2020-07-24 08:21:11 +00:00
var modal = getModalHTMLElement ( ref ) ;
modal . style . display = value ;
2020-07-24 08:40:46 +00:00
if ( value === "flex" ) {
2020-07-24 08:21:11 +00:00
// "save" the activated link.
activatedLink = document . activeElement ;
2020-07-24 08:40:46 +00:00
modal . setAttribute ( "aria-hidden" , "false" ) ; // Focus on the modal container.
2020-07-24 08:21:11 +00:00
2020-07-24 08:40:46 +00:00
modal . setAttribute ( "tabindex" , "0" ) ;
2020-07-24 08:21:11 +00:00
modal . focus ( ) ;
setFocusLoop ( modal ) ;
} else {
2020-07-24 08:40:46 +00:00
modal . setAttribute ( "aria-hidden" , "true" ) ; // focus back the activated link for getting back to the context.
2020-07-24 08:21:11 +00:00
2020-07-24 08:40:46 +00:00
modal . setAttribute ( "tabindex" , "-1" ) ;
2020-07-24 08:21:11 +00:00
activatedLink . focus ( ) ;
}
} ; // set focus loop within modal
var setFocusLoop = function setFocusLoop ( ref ) {
var modal = ref ;
2020-07-24 08:40:46 +00:00
modal . querySelector ( ".m-modal-content a:last-of-type" ) . addEventListener ( "keydown" , leaveLastLink ) ;
modal . querySelector ( ".m-modal-content a:first-of-type" ) . addEventListener ( "keydown" , leaveFirstLink ) ;
2020-07-24 08:21:11 +00:00
} ;
var leaveLastLink = function leaveLastLink ( e ) {
// going back to the first link to force looping
2020-07-24 08:40:46 +00:00
if ( e . code === "Tab" && e . shiftKey === false ) {
2020-07-24 08:21:11 +00:00
e . preventDefault ( ) ;
2020-07-24 08:40:46 +00:00
e . target . closest ( "div" ) . querySelector ( "a:first-of-type" ) . focus ( ) ;
2020-07-24 08:21:11 +00:00
}
} ;
var leaveFirstLink = function leaveFirstLink ( e ) {
// going back to the first link to force looping
2020-07-24 08:40:46 +00:00
if ( e . code === "Tab" && e . shiftKey === true ) {
2020-07-24 08:21:11 +00:00
e . preventDefault ( ) ;
2020-07-24 08:40:46 +00:00
e . target . closest ( "div" ) . querySelector ( "a:last-of-type" ) . focus ( ) ;
2020-07-24 08:21:11 +00:00
}
2020-07-16 13:11:40 +00:00
} ; // enable dark mode
var enableDarkMode = function enableDarkMode ( ) {
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
return getModalHTMLElement ( type ) . classList . add ( "m-dark" ) ;
} ; // disable dark mode
var disableDarkMode = function disableDarkMode ( ) {
var type = arguments . length > 0 && arguments [ 0 ] !== undefined ? arguments [ 0 ] : MAIL _TYPE ;
return getModalHTMLElement ( type ) . classList . remove ( "m-dark" ) ;
2020-07-01 12:48:18 +00:00
} ; // custom composedPath if path or event.composedPath() are not defined
var composedPath = function composedPath ( el ) {
var path = [ ] ;
while ( el ) {
path . push ( el ) ;
if ( el . tagName === "HTML" ) {
path . push ( document ) ;
path . push ( window ) ;
return path ;
2020-04-25 13:19:10 +00:00
}
2020-07-01 12:48:18 +00:00
el = el . parentElement ;
}
} ; // validate a single email with regex
var validateEmail = function validateEmail ( email ) {
return /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ . test ( email ) ;
} ; // validate an array of emails
var validateEmails = function validateEmails ( arr ) {
return arr . every ( validateEmail ) ;
2020-07-10 11:02:17 +00:00
} ; // validate a single tel with regex
var validateTel = function validateTel ( tel ) {
2020-07-23 17:20:29 +00:00
return /^[+]{0,1}[\s0-9]{0,}[(]{0,1}[0-9]{1,4}[)]{0,1}[-\s\./0-9]*$/ . test ( tel ) ;
2020-07-01 12:48:18 +00:00
} ; // copy of a string
var copyToClipboard = function copyToClipboard ( str ) {
var el = createElement ( "textarea" ) ;
el . value = str ;
el . setAttribute ( "readonly" , "" ) ;
el . style . position = "absolute" ;
el . style . left = "-9999px" ;
document . body . appendChild ( el ) ;
var selected = document . getSelection ( ) . rangeCount > 0 ? document . getSelection ( ) . getRangeAt ( 0 ) : false ;
el . select ( ) ;
document . execCommand ( "copy" ) ;
document . body . removeChild ( el ) ;
if ( selected ) {
document . getSelection ( ) . removeAllRanges ( ) ;
document . getSelection ( ) . addRange ( selected ) ;
return true ;
}
return false ;
2020-04-25 13:19:10 +00:00
} ;
2020-07-01 12:48:18 +00:00
var mailgoStyle = function mailgoStyle ( ) {
// mailgo style
var mailgoCSSElement = createElement ( "style" ) ;
mailgoCSSElement . id = "mailgo-style" ;
2020-07-16 11:24:51 +00:00
mailgoCSSElement . type = "text/css" ;
2020-07-01 12:48:18 +00:00
mailgoCSSElement . appendChild ( createTextNode ( mailgoCSS ) ) ;
document . head . appendChild ( mailgoCSSElement ) ;
} ; // mailgo
2020-07-17 08:45:21 +00:00
function mailgo ( mailgoConfig ) {
// set the global config
config = mailgoConfig ; // if the window is defined...
2020-07-01 12:48:18 +00:00
if ( window && typeof window !== "undefined" ) {
2020-07-17 08:45:21 +00:00
var _config8 ;
2020-07-01 12:48:18 +00:00
// add the style for mailgo
mailgoStyle ( ) ; // if is set an initEvent add the listener
2020-07-17 08:45:21 +00:00
if ( ( _config8 = config ) === null || _config8 === void 0 ? void 0 : _config8 . initEvent ) {
var _config9 ;
if ( ( _config9 = config ) === null || _config9 === void 0 ? void 0 : _config9 . listenerOptions ) {
// listener options specified
document . addEventListener ( config . initEvent , function ( ) {
2020-07-28 11:56:38 +00:00
mailgoInit ( ) ;
2020-07-17 08:45:21 +00:00
} , config . listenerOptions ) ;
} else {
// no listener options
document . addEventListener ( config . initEvent , function ( ) {
2020-07-28 11:56:38 +00:00
mailgoInit ( ) ;
2020-07-17 08:45:21 +00:00
} ) ;
}
2020-07-01 12:48:18 +00:00
} else {
2020-07-28 11:56:38 +00:00
mailgoInit ( ) ;
2020-04-25 13:19:10 +00:00
}
2020-07-01 12:48:18 +00:00
}
2020-07-03 08:06:53 +00:00
}
2020-07-07 15:49:54 +00:00
/* harmony default export */ var src _mailgo = ( mailgo ) ;
// CONCATENATED MODULE: ./mailgo.lib.ts
2020-07-01 11:26:07 +00:00
// webpack > lib/mailgo.js
2020-06-17 21:01:27 +00:00
2020-07-01 12:09:49 +00:00
2020-07-07 15:49:54 +00:00
/* harmony default export */ var mailgo _lib = _ _webpack _exports _ _ [ "default" ] = ( src _mailgo ) ;
2020-06-17 21:01:27 +00:00
/***/ } )
2020-07-07 15:49:54 +00:00
/******/ ] ) [ "default" ] ;
2020-07-01 21:02:08 +00:00
} ) ;
//# sourceMappingURL=mailgo.js.map