mirror of
https://github.com/cryptpad/cryptpad.git
synced 2026-09-14 11:05:41 +05:00
time-to-read v2
This commit is contained in:
parent
dbb9f9f9fc
commit
3eca49fea7
@ -29,6 +29,9 @@ CKEDITOR.editorConfig = function( config ) {
|
||||
config.mathJaxLib = '/pad/mathjax/MathJax.js?config=TeX-AMS_HTML';
|
||||
config.font_defaultLabel = 'Arial';
|
||||
config.fontSize_defaultLabel = '16';
|
||||
config.wordcount = {
|
||||
showCharCount: true,
|
||||
};
|
||||
|
||||
config.keystrokes = [
|
||||
[ CKEDITOR.ALT + 121 /*F10*/, 'toolbarFocus' ],
|
||||
|
||||
@ -1215,17 +1215,49 @@ define([
|
||||
|
||||
var wordCount = h('span.cp-app-pad-wordCount');
|
||||
$('.cke_toolbox_main').append(wordCount);
|
||||
Messages.pad_wordCountReadingTime = "{0} minute(s) to read"; // XXX
|
||||
Messages.pad_wordCountReadingTime = "{0} minute read"; // XXX
|
||||
Messages.pad_charCount = "Characters: {0}"; // XXX
|
||||
var latestCount = {};
|
||||
|
||||
var truncate = function (n) { return Math.floor(n * 10) / 10; };
|
||||
editor.on('cp-wc-update', function() {
|
||||
if (!editor.wordCount || typeof(editor.wordCount.wordCount) === "undefined") {
|
||||
var DOC_METRICS = {
|
||||
0: function () {
|
||||
if (!latestCount.wordCount) { return void DOC_METRICS.default(); }
|
||||
wordCount.innerText = Messages._getKey('pad_wordCount', [latestCount.wordCount]);
|
||||
},
|
||||
1: function () {
|
||||
var time = (truncate((latestCount.wordCount || 0) / 200));
|
||||
if (time < 1) { time = '< 1'; }
|
||||
wordCount.innerText = Messages._getKey('pad_wordCountReadingTime', [time]);
|
||||
},
|
||||
2: function () {
|
||||
if (!latestCount.charCount) { return void DOC_METRICS.default(); }
|
||||
wordCount.innerText = Messages._getKey('pad_charCount', [latestCount.charCount]); // XXX validate input
|
||||
},
|
||||
"default": function () {
|
||||
// console.error("default doc metric");
|
||||
wordCount.innerText = '';
|
||||
return;
|
||||
},
|
||||
};
|
||||
|
||||
var currentDocMetric = 0;
|
||||
var updateWordCount = function() {
|
||||
if (!editor.wordCount) {
|
||||
latestCount = {};
|
||||
return void DOC_METRICS.default();
|
||||
}
|
||||
wordCount.innerText = Messages._getKey('pad_wordCount', [editor.wordCount.wordCount]);
|
||||
wordCount.setAttribute("title", Messages._getKey('pad_wordCountReadingTime', [truncate(editor.wordCount.wordCount / 200)]));
|
||||
latestCount = editor.wordCount;
|
||||
//console.log(latestCount); // XXX
|
||||
var metric = DOC_METRICS[currentDocMetric] || DOC_METRICS.default;
|
||||
try { metric(); } catch (err) { console.error(err); }
|
||||
};
|
||||
$(wordCount).click(function () {
|
||||
currentDocMetric = (currentDocMetric + 1) % 3;
|
||||
updateWordCount();
|
||||
});
|
||||
|
||||
editor.on('cp-wc-update', updateWordCount); // not called on paste
|
||||
|
||||
// export the typing tests to the window.
|
||||
// call like `test = easyTest()`
|
||||
// terminate the test like `test.cancel()`
|
||||
|
||||
Loading…
Reference in New Issue
Block a user