增加了自动记录当前“显示原文”状态的功能,以便在切换到其它页时保存状态。

This commit is contained in:
Zhicheng Wang 2016-05-15 22:11:52 +08:00
parent 0ee5264d19
commit 23eb2191b1
2 changed files with 11 additions and 2 deletions

View File

@ -63,7 +63,7 @@ angularIO.controller('AppCtrl', ['$mdDialog', '$timeout', '$http', '$sce', funct
// TRIGGER PRETTYPRINT AFTER DIGEST LOOP COMPLETE
$timeout(prettyPrint, 1);
vm.sourceVisible = debugging;
vm.sourceVisible = sourceVisible;
vm.toggleSource = function ($event) {
$event.preventDefault();
vm.sourceVisible = !vm.sourceVisible;
@ -74,5 +74,6 @@ angularIO.controller('AppCtrl', ['$mdDialog', '$timeout', '$http', '$sce', funct
} else {
$nodes.addClass('hidden');
}
localStorage.setItem('source-visible', vm.sourceVisible);
};
}]);

View File

@ -1,4 +1,12 @@
// TODO: refactor me!
var debugging = location.hostname === 'localhost';
var sourceVisible = localStorage.getItem('source-visible');
if (_.isUndefined(sourceVisible)) {
sourceVisible = debugging;
} else {
sourceVisible = sourceVisible === 'true';
}
(function ($) {
var nodes = document.querySelectorAll('p, li, h1, h2, h3, h4, h5, h6, header, a, button, small');
_.each(nodes, function (node) {
@ -18,7 +26,7 @@ var debugging = location.hostname === 'localhost';
}
$prevNode.removeAttr('id');
$prevNode.addClass('original-english');
if (!debugging) {
if (!sourceVisible) {
$prevNode.addClass('hidden');
}
if (node.tagName !== 'A' && node.tagName !== 'BUTTON') {