Skip to content

Commit 09fb120

Browse files
committed
Update to support toggle editor theme and spellcheck in status bar
1 parent 6577313 commit 09fb120

File tree

3 files changed

+119
-1
lines changed

3 files changed

+119
-1
lines changed

public/css/index.css

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,11 +394,34 @@ div[contenteditable]:empty:not(:focus):before{
394394
border-left: 1px solid #343434;
395395
}
396396

397-
.status-bar .status-indicators .status-keymap > a {
397+
.status-bar .status-indicators .status-keymap > a,
398+
.status-bar .status-indicators .status-theme > a,
399+
.status-bar .status-indicators .status-spellcheck > a {
398400
color: inherit;
399401
text-decoration: none;
400402
}
401403

404+
.status-bar .status-indicators .status-theme,
405+
.status-bar .status-indicators .status-spellcheck {
406+
padding: 0 4.3px;
407+
}
408+
409+
.ui-theme-toggle,
410+
.ui-spellcheck-toggle {
411+
opacity: 0.2;
412+
cursor: pointer;
413+
}
414+
415+
.ui-theme-toggle.active,
416+
.ui-spellcheck-toggle.active {
417+
opacity: 1;
418+
}
419+
420+
.ui-theme-toggle:hover,
421+
.ui-spellcheck-toggle:hover {
422+
opacity: 0.8;
423+
}
424+
402425
.status-bar .indent-type, .status-bar .indent-width-label {
403426
cursor: pointer;
404427
/* margin-right: 3px;*/

public/js/index.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ var statusIndicators = null;
307307
var statusLength = null;
308308
var statusKeymap = null;
309309
var statusIndent = null;
310+
var statusTheme = null;
311+
var statusSpellcheck = null;
310312

311313
function getStatusBarTemplate(callback) {
312314
$.get(serverurl + '/views/statusbar.html', function (template) {
@@ -328,12 +330,16 @@ function addStatusBar() {
328330
statusIndent = statusBar.find('.status-indent');
329331
statusKeymap = statusBar.find('.status-keymap');
330332
statusLength = statusBar.find('.status-length');
333+
statusTheme = statusBar.find('.status-theme');
334+
statusSpellcheck = statusBar.find('.status-spellcheck');
331335
statusPanel = editor.addPanel(statusBar[0], {
332336
position: "bottom"
333337
});
334338

335339
setIndent();
336340
setKeymap();
341+
setTheme();
342+
setSpellcheck();
337343
}
338344

339345
function setIndent() {
@@ -467,6 +473,89 @@ function setKeymap() {
467473
});
468474
}
469475

476+
function setTheme() {
477+
var cookieTheme = Cookies.get('theme');
478+
if (cookieTheme) {
479+
editor.setOption('theme', cookieTheme);
480+
}
481+
482+
var themeToggle = statusTheme.find('.ui-theme-toggle');
483+
themeToggle.click(function () {
484+
var theme = editor.getOption('theme');
485+
if (theme == "one-dark") {
486+
theme = "default";
487+
} else {
488+
theme = "one-dark";
489+
}
490+
editor.setOption('theme', theme);
491+
Cookies.set('theme', theme, {
492+
expires: 365
493+
});
494+
checkTheme();
495+
});
496+
function checkTheme() {
497+
var theme = editor.getOption('theme');
498+
if (theme == "one-dark") {
499+
themeToggle.removeClass('active');
500+
} else {
501+
themeToggle.addClass('active');
502+
}
503+
}
504+
checkTheme();
505+
}
506+
507+
function setSpellcheck() {
508+
var cookieSpellcheck = Cookies.get('spellcheck');
509+
if (cookieSpellcheck) {
510+
var mode = null;
511+
if (cookieSpellcheck === 'true') {
512+
mode = 'spell-checker';
513+
} else {
514+
mode = 'gfm';
515+
}
516+
if (mode && mode !== editor.getOption('mode')) {
517+
editor.setOption('mode', mode);
518+
}
519+
}
520+
521+
var spellcheckToggle = statusSpellcheck.find('.ui-spellcheck-toggle');
522+
spellcheckToggle.click(function () {
523+
var mode = editor.getOption('mode');
524+
if (mode == "gfm") {
525+
mode = "spell-checker";
526+
} else {
527+
mode = "gfm";
528+
}
529+
if (mode && mode !== editor.getOption('mode')) {
530+
editor.setOption('mode', mode);
531+
}
532+
Cookies.set('spellcheck', (mode == "spell-checker"), {
533+
expires: 365
534+
});
535+
checkSpellcheck();
536+
});
537+
function checkSpellcheck() {
538+
var mode = editor.getOption('mode');
539+
if (mode == "gfm") {
540+
spellcheckToggle.removeClass('active');
541+
} else {
542+
spellcheckToggle.addClass('active');
543+
}
544+
}
545+
checkSpellcheck();
546+
547+
//workaround spellcheck might not activate beacuse the ajax loading
548+
if (num_loaded < 2) {
549+
var spellcheckTimer = setInterval(function () {
550+
if (num_loaded >= 2) {
551+
if (editor.getOption('mode') == "spell-checker")
552+
editor.setOption('mode', "spell-checker");
553+
clearInterval(spellcheckTimer);
554+
}
555+
}, 100);
556+
}
557+
}
558+
470559
var selection = null;
471560

472561
function updateStatusBar() {

public/views/statusbar.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
<div class="indent-width-label" title="Click to change indentation size">4</div>
2121
<input class="indent-width-input hidden" type="number" min="1" max="10" maxlength="2" size="2">
2222
</div>
23+
<div class="status-theme">
24+
<a class="ui-theme-toggle" data-target="#" title="Toggle editor theme"><i class="fa fa-sun-o fa-fw"></i></a>
25+
</div>
26+
<div class="status-spellcheck">
27+
<a class="ui-spellcheck-toggle" data-target="#" title="Toggle spellcheck"><i class="fa fa-check fa-fw"></i></a>
28+
</div>
2329
</div>
2430
</div>

0 commit comments

Comments
 (0)