Add favicon and notifications in polls

This commit is contained in:
yflory 2017-01-19 14:52:12 +01:00
parent 3338000018
commit 5d5d03163e
2 changed files with 106 additions and 74 deletions

View File

@ -4,6 +4,11 @@
<meta content="text/html; charset=utf-8" http-equiv="content-type"/> <meta content="text/html; charset=utf-8" http-equiv="content-type"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/> <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title data-localization="poll_title">Zero Knowledge Date Picker</title> <title data-localization="poll_title">Zero Knowledge Date Picker</title>
<link rel="icon" type="image/png"
href="/customize/main-favicon.png"
data-main-favicon="/customize/main-favicon.png"
data-alt-favicon="/customize/alt-favicon.png"
id="favicon" />
<link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css"> <link rel="stylesheet" href="/bower_components/components-font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/customize/main.css" /> <link rel="stylesheet" href="/customize/main.css" />
<script data-main="main" src="/bower_components/requirejs/require.js"></script> <script data-main="main" src="/bower_components/requirejs/require.js"></script>

View File

@ -12,7 +12,7 @@ define([
'/common/notify.js', '/common/notify.js',
'/bower_components/file-saver/FileSaver.min.js', '/bower_components/file-saver/FileSaver.min.js',
'/bower_components/jquery/dist/jquery.min.js', '/bower_components/jquery/dist/jquery.min.js',
], function (Config, Messages, TextPatcher, Listmap, Crypto, Cryptpad, Hyperjson, Renderer, Toolbar) { ], function (Config, Messages, TextPatcher, Listmap, Crypto, Cryptpad, Hyperjson, Renderer, Toolbar, Visible, Notify) {
var $ = window.jQuery; var $ = window.jQuery;
var unlockHTML = '<i class="fa fa-unlock" aria-hidden="true"></i>'; var unlockHTML = '<i class="fa fa-unlock" aria-hidden="true"></i>';
@ -187,6 +187,9 @@ define([
/* Any time the realtime object changes, call this function */ /* Any time the realtime object changes, call this function */
var change = function (o, n, path, throttle) { var change = function (o, n, path, throttle) {
if (!Cryptpad.isArray(path)) {
return;
}
if (path && path.join) { if (path && path.join) {
console.log("Change from [%s] to [%s] at [%s]", console.log("Change from [%s] to [%s] at [%s]",
o, n, path.join(', ')); o, n, path.join(', '));
@ -210,6 +213,7 @@ define([
https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion https://developer.mozilla.org/en-US/docs/Web/Security/Securing_your_site/Turning_off_form_autocompletion
*/ */
notify();
if (throttle) { if (throttle) {
if (APP.throttled) { window.clearTimeout(APP.throttled); } if (APP.throttled) { window.clearTimeout(APP.throttled); }
@ -391,87 +395,101 @@ define([
}); });
}; };
var userData = APP.userData = {}; // List of pretty names for all users (mapped with their ID) var unnotify = function () {
var userList; // List of users still connected to the channel (server IDs) if (APP.tabNotification &&
var addToUserData = function(data) { typeof(APP.tabNotification.cancel) === 'function') {
var users = userList ? userList.users : undefined; APP.tabNotification.cancel();
//var userData = APP.proxy.info.userData; }
for (var attrname in data) { userData[attrname] = data[attrname]; } };
if (users && users.length) { var notify = function () {
for (var userKey in userData) { if (Visible.isSupported() && !Visible.currently()) {
if (users.indexOf(userKey) === -1) { delete userData[userKey]; } unnotify();
} APP.tabNotification = Notify.tab(1000, 10);
} }
};
if(userList && typeof userList.onChange === "function") { var userData = APP.userData = {}; // List of pretty names for all users (mapped with their ID)
userList.onChange(userData); var userList; // List of users still connected to the channel (server IDs)
} var addToUserData = function(data) {
var users = userList ? userList.users : undefined;
//var userData = APP.proxy.info.userData;
for (var attrname in data) { userData[attrname] = data[attrname]; }
APP.proxy.info.userData = userData; if (users && users.length) {
}; for (var userKey in userData) {
if (users.indexOf(userKey) === -1) { delete userData[userKey]; }
}
}
//var myData = {}; if(userList && typeof userList.onChange === "function") {
var getLastName = function (cb) { userList.onChange(userData);
Cryptpad.getAttribute('username', function (err, userName) { }
cb(err, userName || '');
});
};
var setName = APP.setName = function (newName) { APP.proxy.info.userData = userData;
if (typeof(newName) !== 'string') { return; } };
var myUserNameTemp = Cryptpad.fixHTML(newName.trim());
if(myUserNameTemp.length > 32) {
myUserNameTemp = myUserNameTemp.substr(0, 32);
}
var myUserName = myUserNameTemp;
var myID = APP.myID;
var myData = {};
myData[myID] = {
name: myUserName
};
addToUserData(myData);
Cryptpad.setAttribute('username', newName, function (err, data) {
if (err) {
console.error("Couldn't set username");
return;
}
APP.userName.lastName = myUserName;
//change();
});
};
var updateTitle = function (newTitle) { //var myData = {};
if (newTitle === document.title) { return; } var getLastName = function (cb) {
// Change the title now, and set it back to the old value if there is an error Cryptpad.getAttribute('username', function (err, userName) {
var oldTitle = document.title; cb(err, userName || '');
document.title = newTitle; });
Cryptpad.renamePad(newTitle, function (err, data) { };
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
return;
}
document.title = data;
APP.$bar.find('.' + Toolbar.constants.title).find('span.title').text(data);
APP.$bar.find('.' + Toolbar.constants.title).find('input').val(data);
});
};
var updateDefaultTitle = function (defaultTitle) { var setName = APP.setName = function (newName) {
defaultName = defaultTitle; if (typeof(newName) !== 'string') { return; }
APP.$bar.find('.' + Toolbar.constants.title).find('input').attr("placeholder", defaultName); var myUserNameTemp = Cryptpad.fixHTML(newName.trim());
}; if(myUserNameTemp.length > 32) {
var renameCb = function (err, title) { myUserNameTemp = myUserNameTemp.substr(0, 32);
if (err) { return; } }
document.title = title; var myUserName = myUserNameTemp;
APP.proxy.info.title = title; var myID = APP.myID;
}; var myData = {};
myData[myID] = {
name: myUserName
};
addToUserData(myData);
Cryptpad.setAttribute('username', newName, function (err, data) {
if (err) {
console.error("Couldn't set username");
return;
}
APP.userName.lastName = myUserName;
//change();
});
};
var suggestName = function (fallback) { var updateTitle = function (newTitle) {
return document.title || defaultName || ""; if (newTitle === document.title) { return; }
}; // Change the title now, and set it back to the old value if there is an error
var oldTitle = document.title;
document.title = newTitle;
Cryptpad.renamePad(newTitle, function (err, data) {
if (err) {
console.log("Couldn't set pad title");
console.error(err);
document.title = oldTitle;
return;
}
document.title = data;
APP.$bar.find('.' + Toolbar.constants.title).find('span.title').text(data);
APP.$bar.find('.' + Toolbar.constants.title).find('input').val(data);
});
};
var updateDefaultTitle = function (defaultTitle) {
defaultName = defaultTitle;
APP.$bar.find('.' + Toolbar.constants.title).find('input').attr("placeholder", defaultName);
};
var renameCb = function (err, title) {
if (err) { return; }
document.title = title;
APP.proxy.info.title = title;
};
var suggestName = function (fallback) {
return document.title || defaultName || "";
};
var copyObject = function (obj) { var copyObject = function (obj) {
@ -575,6 +593,7 @@ define([
.on('change', ['info'], function (o, n, p) { .on('change', ['info'], function (o, n, p) {
if (p[1] === 'title') { if (p[1] === 'title') {
updateTitle(n); updateTitle(n);
notify();
} else if (p[1] === "userData") { } else if (p[1] === "userData") {
addToUserData(APP.proxy.info.userData); addToUserData(APP.proxy.info.userData);
} else if (p[1] === 'description') { } else if (p[1] === 'description') {
@ -591,6 +610,7 @@ define([
el.selectionStart = selects[0]; el.selectionStart = selects[0];
el.selectionEnd = selects[1]; el.selectionEnd = selects[1];
} }
notify();
} }
console.log("change: (%s, %s, [%s])", o, n, p.join(', ')); console.log("change: (%s, %s, [%s])", o, n, p.join(', '));
@ -600,6 +620,13 @@ define([
addToUserData(APP.proxy.info.userData); addToUserData(APP.proxy.info.userData);
if (Visible.isSupported()) {
Visible.onChange(function (yes) {
if (yes) { unnotify(); }
});
}
getLastName(function (err, lastName) { getLastName(function (err, lastName) {
APP.ready = true; APP.ready = true;