|
|
@ -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) {
|
|
|
|
|
|
|
|
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) {
|
|
|
|
//var myData = {};
|
|
|
|
defaultName = defaultTitle;
|
|
|
|
var getLastName = function (cb) {
|
|
|
|
APP.$bar.find('.' + Toolbar.constants.title).find('input').attr("placeholder", defaultName);
|
|
|
|
Cryptpad.getAttribute('username', function (err, userName) {
|
|
|
|
};
|
|
|
|
cb(err, userName || '');
|
|
|
|
var renameCb = function (err, title) {
|
|
|
|
});
|
|
|
|
if (err) { return; }
|
|
|
|
};
|
|
|
|
document.title = title;
|
|
|
|
|
|
|
|
APP.proxy.info.title = title;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var suggestName = function (fallback) {
|
|
|
|
var setName = APP.setName = function (newName) {
|
|
|
|
return document.title || defaultName || "";
|
|
|
|
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) {
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|