22
33window . modals = {
44 stack : [ ] , // of types of undismissed modals
5+ get class ( ) { return `${ this . dependencies . app . cssPrefix } -modal` } ,
56
67 dependencies : {
7- import ( dependencies ) { // { app }
8+ import ( dependencies ) { // { app, env }
89 for ( const name in dependencies ) this [ name ] = dependencies [ name ] }
910 } ,
1011
1112 alert ( title = '' , msg = '' , btns = '' , checkbox = '' , width = '' ) {
1213 const alertID = chatgpt . alert ( title , msg , btns , checkbox , width ) ,
1314 alert = document . getElementById ( alertID ) . firstChild
15+ this . init ( alert ) // add class
1416 return alert
1517 } ,
1618
@@ -23,6 +25,54 @@ window.modals = {
2325 this . observeRemoval ( modal , modalType ) // to maintain stack for proper nav
2426 } ,
2527
28+ init ( modal ) {
29+ if ( ! this . styles ) this . stylize ( ) // to init/append stylesheet
30+ modal . classList . add ( this . class ) ; modal . parentNode . classList . add ( `${ this . class } -bg` ) // add classes
31+ } ,
32+
33+ stylize ( ) {
34+ if ( ! this . styles ) {
35+ this . styles = document . createElement ( 'style' ) ; this . styles . id = `${ this . class } -styles`
36+ document . head . append ( this . styles )
37+ }
38+ this . styles . innerText = (
39+ `.${ this . class } {` // modals
40+ + 'font-family: -apple-system, system-ui, BlinkMacSystemFont, Segoe UI, Roboto,'
41+ + 'Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif ;'
42+ + 'padding: 20px 25px 24px 25px !important ; font-size: 20px ;'
43+ + `color: ${ this . dependencies . env . scheme == 'dark' ? 'white' : 'black' } !important ;`
44+ + `background-image: linear-gradient(180deg, ${
45+ this . dependencies . env . scheme == 'dark' ? '#99a8a6 -200px, black 200px'
46+ : '#b6ebff -296px, white 171px' } ) }`
47+ + `.${ this . class } [class*=modal-close-btn] {`
48+ + 'position: absolute !important ; float: right ; top: 14px !important ; right: 16px !important ;'
49+ + 'cursor: pointer ; width: 33px ; height: 33px ; border-radius: 20px }'
50+ + `.${ this . class } [class*=modal-close-btn] svg { height: 10px }`
51+ + `.${ this . class } [class*=modal-close-btn] path {`
52+ + `${ this . dependencies . env . scheme == 'dark' ? 'stroke: white ; fill: white'
53+ : 'stroke: #9f9f9f ; fill: #9f9f9f' } }`
54+ + ( this . dependencies . env . scheme == 'dark' ? // invert dark mode hover paths
55+ `.${ this . class } [class*=modal-close-btn]:hover path { stroke: black ; fill: black }` : '' )
56+ + `.${ this . class } [class*=modal-close-btn]:hover { background-color: #f2f2f2 }` // hover underlay
57+ + `.${ this . class } [class*=modal-close-btn] svg { margin: 11.5px }` // center SVG for hover underlay
58+ + `.${ this . class } a { color: #${ this . dependencies . env . scheme == 'dark' ? '00cfff' : '1e9ebb' } !important }`
59+ + `.${ this . class } h2 { font-weight: bold }`
60+ + `.${ this . class } button {`
61+ + 'font-size: 14px ; text-transform: uppercase ;' // shrink/uppercase labels
62+ + 'border-radius: 0 !important ;' // square borders
63+ + 'transition: transform 0.1s ease-in-out, box-shadow 0.1s ease-in-out ;' // smoothen hover fx
64+ + 'cursor: pointer !important ;' // add finger cursor
65+ + `border: 1px solid ${ this . dependencies . env . scheme == 'dark' ? 'white' : 'black' } !important ;`
66+ + 'padding: 8px !important ; min-width: 102px }' // resize
67+ + `.${ this . class } button:hover {` // add zoom, re-scheme
68+ + 'transform: scale(1.055) ; color: black !important ;'
69+ + `background-color: #${ this . dependencies . env . scheme == 'dark' ? '00cfff' : '9cdaff' } !important }`
70+ + ( ! this . dependencies . env . browser . isMobile ?
71+ `.${ this . class } .modal-buttons { margin-left: -13px !important }` : '' )
72+ + `.about-em { color: ${ this . dependencies . env . scheme == 'dark' ? 'white' : 'green' } !important }`
73+ )
74+ } ,
75+
2676 observeRemoval ( modal , modalType ) { // to maintain stack for proper nav
2777 const modalBG = modal . parentNode
2878 new MutationObserver ( ( [ mutation ] , obs ) => {
0 commit comments