Skip to content

TagSpaces is an offline, open source, document manager with tagging support

refactoring & optimizing the toolbar for mobile

uggrock13849bd7dba8
diff --git a/data/ext/editorHTML/editor.js b/data/ext/editorHTML/editor.js
index 333341fbf..27113881a 100644
--- a/data/ext/editorHTML/editor.js
+++ b/data/ext/editorHTML/editor.js
@@ -1,53 +1,45 @@
-function initEditor(cleanedBodyContent) {
- $htmlEditor = $('#htmlEditor');
- $htmlEditor.append(cleanedBodyContent);
+var isCordova = document.URL.indexOf( 'file:///android_asset' ) === 0;
+
+var toolbar = [
+ ['style', ['style']],
+ ['font', ['bold', 'italic', 'underline', 'superscript', 'subscript', 'strikethrough', 'clear']],
+ ['fontname', ['fontname']],
+ // ['fontsize', ['fontsize']],
+ ['color', ['color']],
+ ['para', ['ul', 'ol', 'paragraph']],
+ ['height', ['height']],
+ ['table', ['table']],
+ ['insert', ['link', 'picture', 'video', 'hr']],
+ ['view', ['fullscreen', 'codeview']],
+ ['help', ['help']]
+];
+
+if (isCordova) {
+ toolbar = [
+ ['color', ['color']],
+ ['style', ['style']],
+ ['para', ['paragraph', 'ul', 'ol']],
+ ['style', ['bold', 'italic', 'underline', 'clear']],
+ //['fontsize', ['fontsize']],
+ ['height', ['height']],
+ ['insert', ['picture', 'link', 'hr']],
+ ['table', ['table']],
+ ['view', ['codeview']]
+ ];
+}
+
+function initEditor() {
$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']]
- ],*/
+ toolbar: toolbar,
onkeyup: function() {
contentVersion++;
+// window.parent.postMessage('par1', '*');
}
});
}
-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;
@@ -57,23 +49,14 @@ 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");
+function setContent(content) {
+ resetContentVersion();
+ $htmlEditor = $('#htmlEditor');
+ $htmlEditor.append(content);
+ // Check if summernote is loaded
+ if(typeof $htmlEditor.summernote === 'function') {
+ initEditor();
+ } else {
+ // window.setTimeout(initEditor(), 1000);
}
-
-// 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 file
+}
\ No newline at end of file
diff --git a/data/ext/editorHTML/extension.js b/data/ext/editorHTML/extension.js
index 3be66ca63..fd96cdbdc 100644
--- a/data/ext/editorHTML/extension.js
+++ b/data/ext/editorHTML/extension.js
@@ -18,15 +18,12 @@ define(function(require, exports, module) {
var TSCORE = require("tscore");
- var $htmlEditor;
-
var extensionsPath = TSCORE.Config.getExtensionPath();
var extensionDirectory = extensionsPath+"/"+extensionID;
var currentContent,
currentFilePath,
- $iframeViewer,
$containerElement;
exports.init = function(filePath, containerElementID) {
@@ -51,33 +48,13 @@ define(function(require, exports, module) {
"nwdisable": "",
"nwfaketop": ""
}));
+ TSCORE.IO.loadTextFile(filePath);
- /*$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);
- //});
+// if (!window.addEventListener) {
+// window.attachEvent('onmessage', function(e) {alert(e.origin);alert(e.data);});
+// } else {
+// window.addEventListener('message', function(e) {alert(e.origin);alert(e.data);}, false);
+// }
};
exports.setFileType = function(fileType) {
@@ -90,16 +67,16 @@ define(function(require, exports, module) {
};
exports.setContent = function(content) {
- /*currentContent = content;
+ currentContent = content;
var bodyRegex = /\<body[^>]*\>([^]*)\<\/body/m;
var bodyContent = undefined;
-
+
try {
bodyContent = content.match( bodyRegex )[1];
} catch(e) {
console.log("Error parsing HTML document. "+e);
- TSCORE.FileOpener.closeFile(true);
+ TSCORE.FileOpener.closeFile(true);
TSCORE.showAlertDialog("Probably a body tag was not found in the document. Document will be closed.","Error parsing HTML document");
}
@@ -109,12 +86,7 @@ define(function(require, exports, module) {
// removing all scripts from the document
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);*/
+ document.getElementById("iframeViewer").contentWindow.setContent(cleanedBodyContent);
};
var contentVersion = 0;
@@ -125,7 +97,10 @@ define(function(require, exports, module) {
}
function checkContentChanged() {
- var newContentVersion = document.getElementById("iframeViewer").contentWindow.getContentVersion();
+ var newContentVersion;
+ //try {
+ newContentVersion = document.getElementById("iframeViewer").contentWindow.getContentVersion();
+ //} catch(e) { }
if(newContentVersion > contentVersion) {
contentVersion = newContentVersion;
TSCORE.FileOpener.setFileChanged(true);
@@ -140,8 +115,6 @@ define(function(require, exports, module) {
exports.getContent = function() {
var content = $("#iframeViewer").contents().find(".note-editable").html();
- var currentContent = document.getElementById("iframeViewer").contentWindow.getOriginalContent();
-
// removing all scripts from the document
var cleanedContent = content.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"");
diff --git a/data/ext/editorHTML/index.html b/data/ext/editorHTML/index.html
index 874f356a6..7797b3287 100644
--- a/data/ext/editorHTML/index.html
+++ b/data/ext/editorHTML/index.html
@@ -3,14 +3,14 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
+ <script type="text/javascript" src="../../libs/jquery/jquery-2.1.1.min.js"></script>
+ <script type="text/javascript" src="editor.js"></script>
+ <script type="text/javascript" src="../../libs/bootstrap/js/bootstrap.min.js"></script>
+ <script type="text/javascript" src="summernote/summernote.js"></script>
<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>