Permalink
Browse files

Catch window.alert and display a modal

1 parent bac726b commit 4022ae7a35b140b580931f72b7e4ce4f2c91fefb @ffflorian ffflorian committed Aug 31, 2016
Showing with 78 additions and 7 deletions.
  1. +0 −3 googlecalendar/css/franz.css
  2. +37 −0 googlecalendar/css/modal.css
  3. +41 −4 googlecalendar/webview.js
@@ -1,3 +0,0 @@
-footer {
- display: none !important;
-}
@@ -0,0 +1,37 @@
+#franz-modal {
+ display: none;
+ position: fixed;
+ z-index: 9999;
+ left: 0;
+ top: 0;
+ width: 100%;
+ height: 100%;
+ overflow: auto;
+ background-color: rgba(0, 0, 0, 0.8);
+}
+
+#franz-modal .modal-content {
+ background-color: #fefefe;
+ margin: 15% auto;
+ padding: 20px;
+ border: 1px solid #888;
+ width: 30%;
+ -webkit-border-radius: 3px;
+ -moz-border-radius: 3px;
+ border-radius: 3px;
+}
+
+#franz-modal .close {
+ color: #aaa;
+ float: right;
+ margin-top: -10px;
+ font-size: 20px;
+ font-weight: bold;
+}
+
+#franz-modal .close:hover,
+#franz-modal .close:focus {
+ color: black;
+ text-decoration: none;
+ cursor: pointer;
+}
@@ -1,6 +1,36 @@
const path = require('path');
module.exports = (Franz, options) => {
+ let updates = 0;
+ const modal = document.createElement('div');
+
+ function showModal (text) {
+ show(modal);
+ modal.querySelector('p').innerHTML = text;
+ updates += 1;
+ }
+
+ function hideModal () {
+ hide(modal);
+ modal.querySelector('p').innerHTML = '';
+ updates -= 1;
+ }
+
+ // Replace window.alert to hide alerts in Franz
+ const oldAlert = window.alert;
+ window.alert = function () {
+ // when Google Calendar displays an alert notify the user
+ showModal.apply(oldAlert, arguments);
+ };
+
+ function show (element) {
+ element.style.display = 'inherit';
+ }
+
+ function hide (element) {
+ element.style.display = 'none';
+ }
+
const getMessages = () => {
// get unread messages
//const updates = document.getElementById('franz').getAttribute('data-unread');
@@ -9,13 +39,20 @@ module.exports = (Franz, options) => {
//const inbox = document.getElementById('franz').getAttribute('data-inbox');
// set Franz badge
- // updates => active unread count
- // inbox => passive unread count
- Franz.setBadge(0, 0);
+ // updates => passive unread count
+ // inbox => active unread count
+ Franz.setBadge(0, updates);
};
+ modal.id = 'franz-modal';
+ modal.innerHTML = '<div class="modal-content"><span class="close">&times;</span><p></p></div>';
+ modal.querySelector('.close').addEventListener('click', hideModal);
+ document.body.appendChild(modal);
+
+ document.addEventListener('keydown', function(e) { if (e.keyCode === 27) { hideModal(); } })
+
// inject franz.css stylesheet
- //Franz.injectCSS(path.join(__dirname, 'css', 'franz.css'));
+ Franz.injectCSS(path.join(__dirname, 'css', 'modal.css'));
// check for new messages every second and update Franz badge
Franz.loop(getMessages);

0 comments on commit 4022ae7

Please sign in to comment.