From ef1b927861f9a949aed20341144ffb5bfd42f038 Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Mon, 19 Sep 2022 11:22:21 +1000 Subject: Removing the web client --- javascript/app/components/text-file.js | 67 ---------------------------------- 1 file changed, 67 deletions(-) delete mode 100644 javascript/app/components/text-file.js (limited to 'javascript/app/components/text-file.js') diff --git a/javascript/app/components/text-file.js b/javascript/app/components/text-file.js deleted file mode 100644 index 2239571..0000000 --- a/javascript/app/components/text-file.js +++ /dev/null @@ -1,67 +0,0 @@ -/* global showdown */ -import Ember from 'ember'; -import {initializeLineSelection} from '../utils/line-selection'; - -function escapeHtml(text) { - return text.replace(/[\"&<>]/g, function (a) { - return { '"': '"', '&': '&', '<': '<', '>': '>' }[a]; - }); -} - -function addLineNumbers (text) { - const start = ""; - const end = "
"; - let lineNumber = 0; - const lines = text.split("\n").map((line) => { - lineNumber ++; - const lineNumberHtml = ""+lineNumber+""; - const lineContentHtml = ""+escapeHtml(line)+""; - return ""+ lineNumberHtml + lineContentHtml + ""; - }).join(""); - return start + lines + end; -} - -const markdownExtensions = ["markdown", "mdown", "mkdn", "mkd", "md"]; - -export default Ember.Component.extend({ - isMarkdown : Ember.computed('path',function() { - const maybeExtension = this.get('path').split('.').pop(); - return markdownExtensions.any((extension) => (maybeExtension === extension)); - }), - html : Ember.computed('path','isMarkdown',function() { - if(this.get('isMarkdown')) { - return this.markdownConverter.makeHtml(this.get('text')); - } else { - return addLineNumbers(this.get('text')); - } - }), - init() { - this._super(...arguments); - this.markdownConverter = new showdown.Converter(); - }, - didInsertElement() { - const sourceCodeContainerElement = this.element.querySelector('.source-code-container'); - initializeLineSelection(sourceCodeContainerElement,this); - this.element.parentNode.scrollTop = 0; - }, - willDestroyElement : function () { - this.cleanup(); - }, - cleanup() { - if(this._onhashchange) { - window.removeEventListener('hashchange',this._onhashchange); - } - if(this._onkeydown) { - document.removeEventListener('keydown',this._onkeydown); - } - if(this._onkeyup) { - document.removeEventListener('keyup',this._onkeyup); - } - }, - pathObserver : Ember.observer('path',function() { - Ember.run.next(this,() => { - this.cleanup(); - this.didInsertElement(); - }); - }) -}); -- cgit v1.2.3