From 9417a3ab28134d1a977e221a5c97de45b47193d5 Mon Sep 17 00:00:00 2001 From: Andrew Hayward Date: Mon, 9 Oct 2017 06:48:41 -0400 Subject: [PATCH] Switching from native 'confirm' prompt to HTML dialog for reset prompt. (#221) Adds Google's `dialog-polyfill` as a dependency. --- package.json | 5 +- src/css/style.css | 129 +++++++++++++++++++ src/images/lightbeam_dialog_warningreset.png | Bin 0 -> 4746 bytes src/index.html | 18 +++ src/js/lightbeam.js | 22 +++- 5 files changed, 167 insertions(+), 7 deletions(-) create mode 100644 src/images/lightbeam_dialog_warningreset.png diff --git a/package.json b/package.json index d8b6c20..b2fa484 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "build": "npm install && npm run updatesubmodule && npm run createlib && cd src && web-ext build --overwrite-dest", "updatesubmodule": "git submodule init && git submodule update", "createlib": "cd src && rm -rf ext-libs/ && mkdir ext-libs && npm run movelibcontents", - "movelibcontents": "cp node_modules/dexie/dist/dexie.js src/ext-libs && cp node_modules/d3/build/d3.min.js src/ext-libs && node node_modules/json/lib/json.js -f shavar-prod-lists/disconnect-entitylist.json > src/ext-libs/disconnect-entitylist.json", + "movelibcontents": "cp node_modules/dexie/dist/dexie.js src/ext-libs && cp node_modules/d3/build/d3.min.js src/ext-libs && cp node_modules/dialog-polyfill/dialog-polyfill.js src/ext-libs && node node_modules/json/lib/json.js -f shavar-prod-lists/disconnect-entitylist.json > src/ext-libs/disconnect-entitylist.json", "lint": "npm-run-all lint:*", "lint:eslint": "eslint --ext=.js,.json .", "lint:webext": "web-ext -s js lint", @@ -29,7 +29,8 @@ "homepage": "https://github.com/mozilla/lightbeam-we/blob/master/README.md", "dependencies": { "d3": "4.9.1", - "dexie": "^2.0.0-beta" + "dexie": "^2.0.0-beta", + "dialog-polyfill": "^0.4.9" }, "devDependencies": { "chai": "^3.5.0", diff --git a/src/css/style.css b/src/css/style.css index 1ec19ff..bc7caa9 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -32,6 +32,8 @@ --button-active-border-color: #6fc3e5; --primary-text-color: #eaeaea; --secondary-text-color: #73a4b8; + --dialog-header-color: #4cc7e6; + --dialog-button-color: #4cc7e6; } *::before, *::after, * { @@ -107,6 +109,133 @@ button::before, a.thumbs-up::before { margin-right: 10px; } +dialog { + display: block; + position: fixed; + transform: translate(0, -50%); + top: 50%; + left: 2em; + right: 2em; + width: -moz-fit-content; + width: -webkit-fit-content; + width: fit-content; + max-width: 40em; + height: -moz-fit-content; + height: -webkit-fit-content; + height: fit-content; + margin: auto; + padding: 1em; + background: white; + color: black; + border: none; + border-radius: 0.5em; + box-shadow: 0.5em 0.5em 0 rgba(0,0,0,0.5); + overflow: hidden; +} + +dialog:not([open]) { + display: none; +} + +dialog::backdrop, dialog + .backdrop { + background: rgba(0,0,0,0.25); +} + +dialog + .backdrop { + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; +} + +dialog .dialog-wrapper { + display: grid; + grid-template-columns: repeat(4, 1fr); + grid-gap: 10px; + grid-auto-rows: auto; +} + +dialog .dialog-title { + background: var(--dialog-header-color); + color: #FFF; + margin: -1em -1em 0; + padding: 1em; + font-size: 1em; + text-transform: uppercase; + grid-column: 1 / 5; + grid-row: 1; +} + +dialog .dialog-icon { + grid-column: 1; + grid-row: 2; + width: 100%; + display: block; +} + +dialog .dialog-content { + grid-column: 1 / 5; + grid-row: 2; +} + +dialog .dialog-icon + .dialog-content { + grid-column: 2 / 5; +} + +dialog .dialog-options { + text-align: right; + display: block; + margin: 0; + padding: 0; + grid-column: 1 / 5; + grid-row: 3; +} + +dialog .dialog-options button { + background: var(--dialog-button-color); + display: inline-block; + width: auto; + min-width: 6em; + box-shadow: none; + margin: 0; + padding: 0.5em 1em; + font-size: inherit; + text-align: center; +} + +dialog .dialog-options button::before { + display: none; +} + +dialog .dialog-options button::-moz-focus-inner { + padding: 0; + border: none; +} + +dialog .dialog-options button:focus { + outline: dotted 1px grey; +} + +@media (max-width: 44em) { + dialog .dialog-icon { + display: none; + } + + dialog .dialog-content, + dialog .dialog-icon + .dialog-content { + grid-column: 1 / 5; + } +} + +._dialog_overlay { + position: fixed; + top: 0; + right: 0; + bottom: 0; + left: 0; +} + .active { background-color: var(--button-active-color); border-top: 2px solid var(--button-active-border-color); diff --git a/src/images/lightbeam_dialog_warningreset.png b/src/images/lightbeam_dialog_warningreset.png new file mode 100644 index 0000000000000000000000000000000000000000..25e04701088696bfaf995496f03d6598c502ba57 GIT binary patch literal 4746 zcmb7I_ct2=7qyC-F>2J-8Z}B#Ge#+?QCceYh`mZt1VI$BTGR|`wDuNTDJ8LY)z*j+ zTWv+DuiroLo%6l(-nr+zch9}&{rFz&bA2!^)mahY-AH!Ks=yPK z{-wZJkNXl2v2u5S0Y?;8-Ij10ZYirUWL`}DQ&I{g-~{g{z2)tawEt=(|U}S+B@{t`}$D&&u#qTPnD*o4m4QylbpFQ&MB}?j`ee{2J9_Nmk)<4>7 zAUF96D(T=qqzfN{QYqw z#ZdUE7_B9(p$+EeU=7*gyAXAWXY|xzAK5&zK8@s-kuI<-*QHzrms$3bSN2rv;2%F^ z>yW*}3J#zO{vML-g!;v@r*}BbK6E}J-{kbpvrzl4ZpVZDvi5aJT_N1M8PL)1yG#!4 zB&3{ib_JVRP&Quv2<9qGd!xi^;7Hp9Lf32vcm(4W&;uskI<`^RGGw-7cp77Lf>X7> z{)BEsS>9s@GKgiC&&-7ON%mKFT~7{VxP6azj<#J2^Me?fU37-W@4ng z?-g@iQGgCw4b3Ya_W6J?Z$g~&dV2hswM3hJ`Bth{LlfDVR%0?@E1pbYK4N4pnFU_y zpHe%uJR!$Q9llG2peoaIx*gTud&u8DPtrgE)!EDC8)z4#?=fU0}4mdX7F*# z8zquGe)ph|loi>PsTf1ElAS~_8~gM~_~{*Y#M~S2)!DJ-m8A%)VpH;^HEj0K zu}hom_iv|{<$qA8#03u#x_a(wpSGasmRkayjio^<*^8~sI_H4V?B;D7sI=M{eopf1 zG0pNO_|#^c7=Yzub*D(+<8&_g%frouB^^?v=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8lv-U~o36y2os{y=gqooU|v*&5br8NF;>hdDj^o;SG}cb(7~C96Et zy8mZpD0=5$`Rw9){`U=e#W$uOFhMGi)qA0$ZaYCA~$dKdBb*_Uy0O6#Yyk=+?iS0x}hT- z*eFU2cf-4;-)<3*<#OOg9lY;Bcac)DXxusw=-IcQ+GjA+Hc%w*Xb1&9(%v7erQc>wkS+ arZ>478%Z*iQ`r&!rD<#GKdDx?efuA;4kMue literal 0 HcmV?d00001 diff --git a/src/index.html b/src/index.html index e67d9cf..cbbd37d 100644 --- a/src/index.html +++ b/src/index.html @@ -11,6 +11,7 @@ + @@ -130,5 +131,22 @@ + +
+

Reset Data

+ + + +
+

Pressing OK will delete all Lightbeam information including connection history, user preferences, block sites list, etc.

+

Your browser will be returned to the state of a fresh install of Lightbeam.

+
+ + + + + +
+
diff --git a/src/js/lightbeam.js b/src/js/lightbeam.js index fad6e0e..64b151e 100644 --- a/src/js/lightbeam.js +++ b/src/js/lightbeam.js @@ -254,14 +254,26 @@ const lightbeam = { resetData() { const resetData = document.getElementById('reset-data-button'); - resetData.addEventListener('click', async () => { - const msgBegin = 'Pressing OK will delete all Lightbeam data. '; - const msgEnd = 'Are you sure?'; - const confirmation = confirm(`${msgBegin + msgEnd}`); - if (confirmation) { + const dialog = document.getElementById('reset-data-dialog'); + window.dialogPolyfill && window.dialogPolyfill.registerDialog(dialog); + + resetData.addEventListener('click', () => { + dialog.showModal(); + }); + + dialog.addEventListener('cancel', () => { + delete dialog.returnValue; + }); + + dialog.addEventListener('close', async () => { + if (dialog.returnValue === 'confirm') { await storeChild.reset(); window.location.reload(); } + + // This is a little naive, because the dialog might not have been + // triggered by the reset button. But it's better than nothing. + resetData.focus(); }); },