TagSpaces is an offline, open source, document manager with tagging support
updating html editor with a newer version of sommernote, allowing pasting of images from clipboard. Fixing #119
uggrockb9ec6df23986
diff --git a/data/ext/editorHTML/editor.js b/data/ext/editorHTML/editor.jsnew file mode 100644index 000000000..333341fbf--- /dev/null+++ b/data/ext/editorHTML/editor.js@@ -0,0 +1,79 @@+function initEditor(cleanedBodyContent) {+ $htmlEditor = $('#htmlEditor');+ $htmlEditor.append(cleanedBodyContent);+ $htmlEditor.summernote({+ focus: true,+ height: "100%",+ /*toolbar: [+ ['style', ['style']],+ ['style', ['bold', 'italic', 'underline', 'clear']],+ ['fontsize', ['fontsize']],+ ['color', ['color']],+ ['para', ['ul', 'ol', 'paragraph']],+ ['height', ['height']],+ ['insert', ['picture', 'link']],+ ['table', ['table']],+ ['view', ['codeview']]+ ],*/+ onkeyup: function() {+ contentVersion++;+ }+ });+}++function getParameterByName(name) {+ name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");+ var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),+ results = regex.exec(location.search);+ return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));+}++function init() {+ var filePath = getParameterByName("cp");+ $.ajax({+ url: "file://"+filePath,+ type: 'POST'+ })+ .done(function(data) {+ originalContent = data;+ cleanContent(data);+ })+ .fail(function(data) {+ console.log("AJAX failed "+data);+ });+}++var originalContent;+function getOriginalContent() {+ return originalContent;+}++var contentVersion = 0;+function resetContentVersion() {+ contentVersion = 0;+}++function getContentVersion() {+ return contentVersion;+}++function cleanContent(content) {+ var bodyRegex = /\<body[^>]*\>([^]*)\<\/body/m;+ var bodyContent = undefined;++ try {+ bodyContent = content.match( bodyRegex )[1];+ } catch(e) {+ console.log("Error parsing HTML document. "+e);+ alert("Document could not be proceeded, probably a body tag was! ","Error parsing HTML document");+ }++// var titleRegex = /\<title[^>]*\>([^]*)\<\/title/m;+// var titleContent = content.match( titleRegex )[1];++ // removing all scripts from the document+ var cleanedBodyContent = bodyContent.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"");+ initEditor(cleanedBodyContent)+}++init();\ No newline at end of filediff --git a/data/ext/editorHTML/extension.css b/data/ext/editorHTML/extension.cssindex 8235b49fe..190abd486 100644--- a/data/ext/editorHTML/extension.css+++ b/data/ext/editorHTML/extension.css@@ -1,23 +1,34 @@+html, body {+ height: 100%;+}+.note-editor {border-width: 0 !important;- width: 100%;- height: 99% !important;+ height: 90%;}.note-codable {- height: 95% !important;overflow: auto;}.note-editable {- height: 95% !important;- overflow: auto;- font-size: 140%;+ overflow: auto;+}++/* Custom scrollbars for chrome */+::-webkit-scrollbar-track+{+ background-color: transparent;+}++::-webkit-scrollbar+{+ width: 8px;+ height: 8px;+ background-color: #F5F5F5;}-/* partially fixes the resize issue in IE-#viewer {- background-color: white;- width: 100%;- height: 90% !important;-}*/+::-webkit-scrollbar-thumb+{+ background-color: #bbb;+}\ No newline at end of filediff --git a/data/ext/editorHTML/extension.js b/data/ext/editorHTML/extension.jsindex 5616d6d02..3be66ca63 100644--- a/data/ext/editorHTML/extension.js+++ b/data/ext/editorHTML/extension.js@@ -6,33 +6,78 @@ define(function(require, exports, module) {"use strict";console.log("Loading editorHTML");- exports.id = "editorHTML"; // ID should be equal to the directory name where the ext. is located- exports.title = "HTML Editor";- exports.type = "editor";- exports.supportedFileTypes = [ "htm", "html" ];++ var extensionTitle = "HTML Editor";+ var extensionID = "editorHTML"; // ID should be equal to the directory name where the ext. is located+ var extensionType = "editor";+ var extensionIcon = "icon-list";+ var extensionVersion = "1.0";+ var extensionManifestVersion = 1;+ var extensionLicense = "AGPL";+ var extensionSupportedFileTypes = [ "html", "htm" ];var TSCORE = require("tscore");- var htmlEditor;+ var $htmlEditor;var extensionsPath = TSCORE.Config.getExtensionPath();- var extensionDirectory = extensionsPath+"/"+exports.id;+ var extensionDirectory = extensionsPath+"/"+extensionID;- var currentContent;- var currentFilePath;+ var currentContent,+ currentFilePath,+ $iframeViewer,+ $containerElement;exports.init = function(filePath, containerElementID) {- console.log("Initalization HTML Text Editor...");+ console.log("Initalization HTML Editor...");++ $containerElement = $('#'+containerElementID);+currentFilePath = filePath;- require([- extensionDirectory+'/summernote/summernote.js',- 'css!'+extensionDirectory+'/summernote/summernote.css',- 'css!'+extensionDirectory+'/extension.css'- ], function() {- $("#"+containerElementID).append('<div id="htmlEditor"></div>');- TSCORE.IO.loadTextFile(filePath);- });++ //var fileExt = TSCORE.TagUtils.extractFileExtension(filePath);++ $containerElement.empty();+ $containerElement.css("background-color","white");++ var extPath = extensionDirectory+"/index.html";+ $containerElement.append($('<iframe>', {+ id: "iframeViewer",+ sandbox: "allow-same-origin allow-scripts",+ scrolling: "no",+ style: "background-color: white; overflow: hidden;",+ src: extPath+"?cp="+filePath,+ "nwdisable": "",+ "nwfaketop": ""+ }));++ /*$containerElement.append($('<iframe>', {+ //sandbox: "allow-same-origin allow-scripts",+ id: "iframeViewer",+ "nwdisable": "",+ "nwfaketop": ""+ })+ );++ $iframeViewer = $("#iframeViewer");+ if($iframeViewer != undefined) {+ var $iframeViewerHead = $iframeViewer.contents().find('head');+ $iframeViewerHead.append($('<link/>', { rel: 'stylesheet', href: extensionDirectory+'/extension.css' }));+ $iframeViewerHead.append($('<link/>', { rel: 'stylesheet', href: extensionDirectory+'/../../libs/bootstrap/css/bootstrap.css' }));+ $iframeViewerHead.append($('<link/>', { rel: 'stylesheet', href: extensionDirectory+'/../../libs/font-awesome/css/font-awesome.css' }));+ $iframeViewerHead.append($('<link/>', { rel: 'stylesheet', href: extensionDirectory+'/summernote/summernote.css' }));+ $iframeViewerHead.append($('<script/>', { type: 'text/javascript', src: extensionDirectory+'/../../libs/jquery/jquery-2.1.1.min.js' }));+ $iframeViewerHead.append($('<script/>', { type: 'text/javascript', src: extensionDirectory+'/../../libs/bootstrap/js/bootstrap.min.js' }));+ $iframeViewerHead.append($('<script/>', { type: 'text/javascript', src: extensionDirectory+'/summernote/summernote.js' }));+ $iframeViewerHead.append($('<script/>', { type: 'text/javascript', src: extensionDirectory+'/editor.js' }));+ }*/++ //require([+ // extensionDirectory+'/summernote/summernote.js'+ //], function(uiTPL) {+ //TSCORE.IO.loadTextFile(filePath);+ //});};exports.setFileType = function(fileType) {@@ -41,10 +86,11 @@ define(function(require, exports, module) {exports.viewerMode = function(isViewerMode) {// set readonly+ console.log("viewerMode not supported on this extension");};exports.setContent = function(content) {- currentContent = content;+ /*currentContent = content;var bodyRegex = /\<body[^>]*\>([^]*)\<\/body/m;var bodyContent = undefined;@@ -61,36 +107,45 @@ define(function(require, exports, module) {// var titleContent = content.match( titleRegex )[1];// removing all scripts from the document- var cleanedBodyContent = bodyContent.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"");-- var $htmlEditor = $('#htmlEditor');- $htmlEditor.append(cleanedBodyContent);- $htmlEditor.summernote({- focus: true,- toolbar: [- ['style', ['style']],- ['style', ['bold', 'italic', 'underline', 'clear']],- ['fontsize', ['fontsize']],- ['color', ['color']],- ['para', ['ul', 'ol', 'paragraph']],- ['height', ['height']],- ['insert', ['picture', 'link']],- ['table', ['table']],- ['view', ['codeview']]- ],- onkeyup: function() {- TSCORE.FileOpener.setFileChanged(true);- }- });+ var cleanedBodyContent = bodyContent.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"");++ var $iframeViewer = $("#iframeViewer");+ $iframeViewer.contents().find("body").append('<div id="htmlEditor"></div>');+ //console.log(document.getElementById("iframeViewer").contentWindow);+ window.setTimeout(function() {+ document.getElementById("iframeViewer").contentWindow.initEditor(cleanedBodyContent);+ }, 2000);*/};+ var contentVersion = 0;++ function resetContentVersion() {+ contentVersion = 0;+ document.getElementById("iframeViewer").contentWindow.resetContentVersion();+ }++ function checkContentChanged() {+ var newContentVersion = document.getElementById("iframeViewer").contentWindow.getContentVersion();+ if(newContentVersion > contentVersion) {+ contentVersion = newContentVersion;+ TSCORE.FileOpener.setFileChanged(true);+ // autosave+ //TSCORE.FileOpener.saveFile();+ }+ window.setTimeout(checkContentChanged, 1000);+ }++ window.setTimeout(checkContentChanged, 1000);+exports.getContent = function() {- var content = "<body>"+$('#htmlEditor').code()+"</body>";+ var content = $("#iframeViewer").contents().find(".note-editable").html();+ var currentContent = document.getElementById("iframeViewer").contentWindow.getOriginalContent();// removing all scripts from the documentvar cleanedContent = content.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"");+ // saving all images as png in base64 formatvar match,urls = [],imgUrl = "",@@ -106,9 +161,13 @@ define(function(require, exports, module) {cleanedContent = cleanedContent.split(dataURLObject[0]).join(dataURLObject[1]);//console.log(dataURLObject[0]+" - "+dataURLObject[1]);});+ // end saving all images++ cleanedContent = "<body>"+cleanedContent+"</body>";var htmlContent = currentContent.replace(/\<body[^>]*\>([^]*)\<\/body>/m,cleanedContent);//console.log("Final html "+htmlContent);+ resetContentVersion();return htmlContent;};@@ -123,4 +182,14 @@ define(function(require, exports, module) {return canvas.toDataURL("image/png");}+ // Extension Vars+ exports.Title = extensionTitle;+ exports.ID = extensionID;+ exports.Type = extensionType;+ exports.Icon = extensionIcon;+ exports.Version = extensionVersion;+ exports.ManifestVersion = extensionManifestVersion;+ exports.License = extensionLicense;+ exports.SupportedFileTypes = extensionSupportedFileTypes;+});diff --git a/data/ext/editorHTML/index.html b/data/ext/editorHTML/index.htmlnew file mode 100644index 000000000..874f356a6--- /dev/null+++ b/data/ext/editorHTML/index.html@@ -0,0 +1,18 @@+<!DOCTYPE html>+<html dir="ltr">+ <head>+ <meta charset="utf-8">+ <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />+ <link rel="stylesheet" href="extension.css" />+ <link rel="stylesheet" href="../../libs/bootstrap/css/bootstrap.css" />+ <link rel="stylesheet" href="../../libs/font-awesome/css/font-awesome.css" />+ <link rel="stylesheet" href="summernote/summernote.css" />+ <script type="text/javascript" charset="utf-8" src="../../libs/jquery/jquery-2.1.1.min.js"></script>+ <script type="text/javascript" charset="utf-8" src="../../libs/bootstrap/js/bootstrap.min.js"></script>+ <script type="text/javascript" charset="utf-8" src="summernote/summernote.js"></script>+ <script type="text/javascript" charset="utf-8" src="editor.js"></script>+ </head>+ <body>+ <div id="htmlEditor"></div>+ </body>+</html>\ No newline at end of file