Path: blob/master/docs/ja/interactive.js
4934 views
var Highlighter = /** @class */ (function () {1function Highlighter() {2var _this = this;3this.onClick = function (e) {4var t = e.currentTarget.textContent;5if (!(t in _this.nodes)) {6console.log(e.currentTarget);7return;8}9if (_this.highlighted == t) {10_this.unhighlight();11}12else {13if (_this.highlighted != '') {14_this.unhighlight();15}16_this.highlightWord(t);17}18};19this.nodes = {};20this.highlighted = '';21this.addNodes(document.querySelectorAll('.highlight .n'));22this.addNodes(document.querySelectorAll('.highlight .nn'));23this.addNodes(document.querySelectorAll('.highlight .nc'));24this.addNodes(document.querySelectorAll('.highlight .nf'));25for (var k in this.nodes) {26for (var _i = 0, _a = this.nodes[k]; _i < _a.length; _i++) {27var n = _a[_i];28n.addEventListener('click', this.onClick);29}30}31}32Highlighter.prototype.unhighlight = function () {33for (var _i = 0, _a = this.nodes[this.highlighted]; _i < _a.length; _i++) {34var n = _a[_i];35n.classList.remove('clicked');36}37this.highlighted = '';38document.body.classList.remove('lights-off');39};40Highlighter.prototype.highlightWord = function (t) {41for (var _i = 0, _a = this.nodes[t]; _i < _a.length; _i++) {42var n = _a[_i];43n.classList.add('clicked');44}45document.body.classList.add('lights-off');46this.highlighted = t;47};48Highlighter.prototype.addNodes = function (nodes) {49for (var i = 0; i < nodes.length; ++i) {50var name_1 = nodes[i].textContent;51if (!(name_1 in this.nodes)) {52this.nodes[name_1] = [];53}54this.nodes[name_1].push(nodes[i]);55}56};57return Highlighter;58}());59var KatexHighlighter = /** @class */ (function () {60function KatexHighlighter() {61var _this = this;62this.onClick = function (e) {63e.preventDefault();64e.stopPropagation();65var t = KatexHighlighter.getName(e.currentTarget);66// console.log('clicked', t)67if (!(t in _this.nodes)) {68console.log(e.currentTarget);69return;70}71if (_this.highlighted == t) {72_this.unhighlight();73}74else {75if (_this.highlighted != '') {76_this.unhighlight();77}78_this.highlightWord(t);79}80};81this.nodes = {};82this.highlighted = '';83this.addNodes(document.querySelectorAll('.coloredeq'));84for (var k in this.nodes) {85for (var _i = 0, _a = this.nodes[k]; _i < _a.length; _i++) {86var n = _a[_i];87n.addEventListener('click', this.onClick);88}89}90}91KatexHighlighter.prototype.unhighlight = function () {92for (var _i = 0, _a = this.nodes[this.highlighted]; _i < _a.length; _i++) {93var n = _a[_i];94n.classList.remove('clicked');95}96this.highlighted = '';97document.body.classList.remove('lights-off');98};99KatexHighlighter.prototype.highlightWord = function (t) {100for (var _i = 0, _a = this.nodes[t]; _i < _a.length; _i++) {101var n = _a[_i];102n.classList.add('clicked');103}104document.body.classList.add('lights-off');105this.highlighted = t;106};107KatexHighlighter.getName = function (node) {108var name = '';109for (var i = 0; i < node.classList.length; ++i) {110var cn = node.classList[i];111if (cn.substr(0, 2) === 'eq') {112name = cn.substr(2);113}114}115return name;116};117KatexHighlighter.prototype.addNodes = function (nodes) {118for (var i = 0; i < nodes.length; ++i) {119var name_2 = KatexHighlighter.getName(nodes[i]);120console.log(nodes[i]);121if (!(name_2 in this.nodes)) {122this.nodes[name_2] = [];123}124this.nodes[name_2].push(nodes[i]);125}126};127return KatexHighlighter;128}());129function addListeners() {130var h = new Highlighter();131var k = new KatexHighlighter();132}133if (document.readyState == "complete") {134addListeners();135}136else {137document.onreadystatechange = function () {138if (document.readyState == "complete") {139addListeners();140}141};142}143144145