From e0056a73b4298d7e03a33d10dbc8b3f9873f8b72 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Wed, 6 Jul 2016 21:53:28 -0400 Subject: [PATCH] Move Sync prompt into the extension On OS X, the confirm dialog appearing would cause the extension to lose focus and close. This fixes that. --- popup.html | 34 +++++++++++++++++++++++++++------- popup.js | 32 ++++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/popup.html b/popup.html index 8469af5..80662e1 100644 --- a/popup.html +++ b/popup.html @@ -3,7 +3,7 @@ Write.as @@ -127,6 +141,12 @@
Writing as write.as. Sync...
+
+ +
diff --git a/popup.js b/popup.js index e0cb3ca..300a177 100644 --- a/popup.js +++ b/popup.js @@ -76,6 +76,8 @@ document.addEventListener('DOMContentLoaded', function() { $content = document.getElementById("content"); $publish = document.getElementById("publish"); $url = document.getElementById("url"); + var $sync = document.getElementById('sync'); + var $modal = document.getElementById('modal'); var fontRadios = document.postForm.font; var isPopout = window.location.search.substring(1) == "popout"; @@ -116,19 +118,29 @@ document.addEventListener('DOMContentLoaded', function() { }); }); - document.getElementById('sync').addEventListener('click', function(e) { + document.querySelector('#modal .secondary').addEventListener('click', function(e) { + e.preventDefault(); + $modal.style.display = 'none'; + }); + $sync.addEventListener('click', function(e) { e.preventDefault(); var posts = JSON.parse(H.get('posts', '[]')); - - var p = "There "; - p += ((posts.length==1?'is ':'are ') + posts.length + " post" + (posts.length==1?'':'s')); - var thePosts = posts.length == 1 ? 'it' : 'them'; - p += " saved on this computer.\n\nSyncing "+thePosts+" to your account gives you access to "+thePosts+" from anywhere. Sync now?"; - if (!confirm(p)) { + if (posts.length == 0) { return; } + + var p = "

There "; + p += ((posts.length==1?'is':'are') + ' ' + posts.length + " post" + (posts.length==1?'':'s')); + var thePosts = posts.length == 1 ? 'it' : 'them'; + p += " saved on this computer.

Syncing "+thePosts+" to your account will give you access to "+thePosts+" from anywhere. Sync now?

"; + $modal.style.display = 'block'; + document.getElementById('modal-body').innerHTML = p; + }); + document.querySelector('#modal .primary').addEventListener('click', function(e) { + e.preventDefault(); + $modal.style.display = 'none'; - var $sync = this; + var posts = JSON.parse(H.get('posts', '[]')); $sync.innerText = "Syncing now..."; $sync.className = 'disabled'; @@ -234,9 +246,9 @@ document.addEventListener('DOMContentLoaded', function() { $accTools.style.display = 'block'; var posts = JSON.parse(H.get('posts', '[]')); if (posts.length > 0) { - document.getElementById('sync').style.display = 'inline'; + $sync.style.display = 'inline'; } else { - document.getElementById('sync').style.display = 'none'; + $sync.style.display = 'none'; } //document.getElementById("sync-count").innerText = posts.length + " post" + (posts.length==1?'':'s'); document.getElementById("username").innerText = data.username;