Skip to content

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

Refactoring extensions

uggrockb3b9b999367b
diff --git a/data/ext/editorHTML/example.html b/data/ext/editorHTML/example.html
new file mode 100644
index 000000000..be26bffb4
--- /dev/null
+++ b/data/ext/editorHTML/example.html
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+
+<meta http-equiv="X-UA-Compatible" content="IE=Edge">
+<meta charset="utf-8">
+
+<title>wysihtml5 - Advanced Demo</title>
+
+
+ <div id="toolbar" style="display: none;">
+ <a data-wysihtml5-command="bold" title="CTRL+B">bold</a> |
+ <a data-wysihtml5-command="italic" title="CTRL+I">italic</a> |
+ <a data-wysihtml5-command="createLink">insert link</a> |
+ <a data-wysihtml5-command="insertImage">insert image</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a> |
+ <a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a> |
+ <a data-wysihtml5-command="insertUnorderedList">insertUnorderedList</a> |
+ <a data-wysihtml5-command="insertOrderedList">insertOrderedList</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a> |
+ <a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a> |
+ <a data-wysihtml5-command="undo">undo</a> |
+ <a data-wysihtml5-command="redo">redo</a> |
+ <a data-wysihtml5-command="insertSpeech">speech</a>
+ <a data-wysihtml5-action="change_view">switch to html view</a>
+
+ <div data-wysihtml5-dialog="createLink" style="display: none;">
+ <label>
+ Link:
+ <input data-wysihtml5-dialog-field="href" value="http://">
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+
+ <div data-wysihtml5-dialog="insertImage" style="display: none;">
+ <label>
+ Image:
+ <input data-wysihtml5-dialog-field="src" value="http://">
+ </label>
+ <label>
+ Align:
+ <select data-wysihtml5-dialog-field="className">
+ <option value="">default</option>
+ <option value="wysiwyg-float-left">left</option>
+ <option value="wysiwyg-float-right">right</option>
+ </select>
+ </label>
+ <a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>
+ </div>
+ </div>
+ <textarea id="htmlEditor" placeholder="Enter text ..."></textarea>
+
+
+<script src="js/advanced.js"></script>
+<script src="js/wysihtml5-0.4.0pre.min.js"></script>
+<script>
+ var editor = new wysihtml5.Editor("htmlEditor", {
+ toolbar: "toolbar",
+ stylesheets: "stylesheet.css",
+ parserRules: wysihtml5ParserRules
+ });
+
+// document.getElementById("htmlEditor").innerHTML("<blockquote>foobar</blockquote>");
+
+ editor.setValue("<blockquote>foobar</blockquote>");
+
+</script>
\ No newline at end of file
diff --git a/data/ext/editorHTML/extension.js b/data/ext/editorHTML/extension.js
new file mode 100644
index 000000000..40509832b
--- /dev/null
+++ b/data/ext/editorHTML/extension.js
@@ -0,0 +1,117 @@
+define(function(require, exports, module) {
+"use strict";
+
+exports.config = {
+ "id": "editorHTML", // ID should be equal to the directory name where the ext. is located
+ "title": "HTML Editor",
+ "type": "editor", // viewer, ts for tagspace
+ "supportedFileTypes": [
+ "htm", "html", "*"
+ ]
+}
+
+var htmlEditor = undefined;
+
+exports.init1 = function(filePath, containerElementID) {
+ console.debug("Initalization HTML Text Editor...");
+ require([
+ './wysihtml5/advanced',
+ './wysihtml5/wysihtml5-0.4.0pre.min',
+ 'css!ext/editorHTML/wysihtml5/stylesheet'
+ ], function() {
+ generateUI(containerElementID);
+ htmlEditor = new wysihtml5.Editor("htmlEditor", {
+ toolbar : "toolbar",
+ parserRules : wysihtml5ParserRules
+ });
+ IOAPI.loadTextFile(filePath);
+ });
+}
+
+exports.init2 = function(filePath, containerElementID) {
+ console.debug("Initalization HTML Text Editor...");
+ require([
+ './jwysiwyg/jquery.wysiwyg',
+ 'css!./jwysiwyg/jquery.wysiwyg'
+ ], function() {
+ $("#"+containerElementID).append('<textarea id="htmlEditor" style="border-width: 0px; width: 100%; height: 100%"></textarea>');
+ $('#htmlEditor').wysiwyg();
+ IOAPI.loadTextFile(filePath);
+ });
+}
+
+exports.init = function(filePath, containerElementID) {
+ console.debug("Initalization HTML Text Editor...");
+ require([
+ './cleditor/jquery.cleditor.min',
+ 'css!./cleditor/jquery.cleditor'
+ ], function() {
+ $("#"+containerElementID).append('<textarea id="htmlEditor" style="border-width: 0px; width: 100%; height: 100%"></textarea>');
+ $.cleditor.defaultOptions.width = '100%';
+ $.cleditor.defaultOptions.height = '100%';
+ IOAPI.loadTextFile(filePath);
+ });
+}
+
+exports.setFileType = function(fileType) {
+ console.debug("setFileType not supported on this extension");
+}
+
+exports.viewerMode = function(isViewerMode) {
+ // set readonly
+}
+
+exports.setContent = function(content) {
+// htmlEditor.setValue(content);
+// $("#htmlEditor").wysiwyg("setContent", content);
+
+ $('#htmlEditor').val(content);
+ $('#htmlEditor').cleditor();
+ //$('#htmlEditor').html(content);
+ //$('#htmlEditor').cleditor().updateFrame()
+}
+
+exports.getContent = function() {
+// return htmlEditor.getValue();
+ return $('#htmlEditor').val();
+}
+
+var generateUI = function(containerElementID) {
+ $("#"+containerElementID).append(''+
+ '<div id="toolbar" >'+
+ '<a data-wysihtml5-command="bold" title="CTRL+B">bold</a> |'+
+ '<a data-wysihtml5-command="italic" title="CTRL+I">italic</a> |'+
+ '<a data-wysihtml5-command="createLink">insert link</a> |'+
+ '<a data-wysihtml5-command="insertImage">insert image</a> |'+
+ '<a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h1">h1</a> |'+
+ '<a data-wysihtml5-command="formatBlock" data-wysihtml5-command-value="h2">h2</a> |'+
+ '<a data-wysihtml5-command="insertUnorderedList">insertUnorderedList</a> |'+
+ '<a data-wysihtml5-command="insertOrderedList">insertOrderedList</a> |'+
+ '<a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="red">red</a> |'+
+ '<a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="green">green</a> |'+
+ '<a data-wysihtml5-command="foreColor" data-wysihtml5-command-value="blue">blue</a> |'+
+ '<a data-wysihtml5-command="undo">undo</a> |'+
+ '<a data-wysihtml5-command="redo">redo</a> |'+
+ '<a data-wysihtml5-command="insertSpeech">speech</a>'+
+ '<a data-wysihtml5-action="change_view">switch to html view</a>'+
+ '<div data-wysihtml5-dialog="createLink" style="display: none;">'+
+ '<label>Link:<input data-wysihtml5-dialog-field="href" value="http://"></label>'+
+ '<a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>'+
+ '</div> '+
+ '<div data-wysihtml5-dialog="insertImage" style="display: none;">'+
+ '<label>Image:<input data-wysihtml5-dialog-field="src" value="http://"></label>'+
+ '<label>Align:'+
+ '<select data-wysihtml5-dialog-field="className">'+
+ '<option value="">default</option>'+
+ '<option value="wysiwyg-float-left">left</option>'+
+ '<option value="wysiwyg-float-right">right</option>'+
+ '</select>'+
+ '</label>'+
+ '<a data-wysihtml5-dialog-action="save">OK</a>&nbsp;<a data-wysihtml5-dialog-action="cancel">Cancel</a>'+
+ '</div>'+
+ '</div>'+
+ '');
+ $("#"+containerElementID).append('<textarea id="wysihtml5Editor" style="border-width: 0px; width: 100%; height: 100%"></textarea>');
+}
+
+});
\ No newline at end of file
diff --git a/data/ext/editorText/extension.js b/data/ext/editorText/extension.js
index 50a272c87..89cb65fcf 100644
--- a/data/ext/editorText/extension.js
+++ b/data/ext/editorText/extension.js
@@ -17,82 +17,82 @@ exports.config = {
}
var aceEditor = undefined;
-//var editorElId = undefined;
-exports.init = function(elementID) {
+var generateUI = function(containerElementID) {
+ $("#"+containerElementID).append('<div id="aceEditor" style="width: 100%; height: 100%"></div>');
+}
+
+exports.init = function(filePath, containerElementID) {
console.debug("Initalization ACE Text Editor...");
-// editorElId = elementID;
+ var fileExt = filePath.substring(filePath.lastIndexOf(".")+1,filePath.length).toLowerCase();
+ generateUI(containerElementID);
var ace = require("./ace/ace");
- aceEditor = ace.edit(elementID);
- aceEditor.setTheme("./ace/theme/monokai");
+ aceEditor = ace.edit('aceEditor');
+// aceEditor.setTheme("./ace/theme/monokai");
+ IOAPI.loadTextFile(filePath);
+ if (filetype[fileExt] != null) {
+ require(["./ace/mode/" + filetype[fileExt]], function(acemode) {
+ var syntaxMode = acemode.Mode;
+ aceEditor.getSession().setMode(new syntaxMode());
+ })
+ }
}
-/*exports.getEditor = function() {
- return editorElId;
-}*/
-
exports.viewerMode = function(isViewerMode) {
- ace.setReadonly(isViewerMode);
+ aceEditor.setReadOnly(isViewerMode);
}
exports.setContent = function(content) {
aceEditor.setValue(content);
+ aceEditor.clearSelection();
}
exports.getContent = function() {
return aceEditor.getValue();
}
-exports.setFileType = function(fileExt) {
- var filetype = new Array();
- filetype["h"] = "c_cpp";
- filetype["c"] = "c_cpp";
- filetype["clj"] = "clojure";
- filetype["coffee"] = "coffee";
- filetype["coldfusion"] = "cfc";
- filetype["cpp"] = "c_cpp";
- filetype["cs"] = "csharp";
- filetype["css"] = "css";
- filetype["groovy"] = "groovy";
- filetype["haxe"] = "hx";
- filetype["htm"] = "html";
- filetype["html"] = "html";
- filetype["java"] = "java";
- filetype["js"] = "javascript";
- filetype["jsm"] = "javascript";
- filetype["json"] = "json";
- filetype["latex"] = "latex";
- filetype["less"] = "less";
- filetype["ly"] = "latex";
- filetype["ily"] = "latex";
- filetype["lua"] = "lua";
- filetype["markdown"] = "markdown";
- filetype["md"] = "markdown";
- filetype["mdown"] = "markdown";
- filetype["mdwn"] = "markdown";
- filetype["mkd"] = "markdown";
- filetype["ml"] = "ocaml";
- filetype["mli"] = "ocaml";
- filetype["pl"] = "perl";
- filetype["php"] = "php";
- filetype["powershell"] = "ps1";
- filetype["py"] = "python";
- filetype["rb"] = "ruby";
- filetype["scad"] = "scad";
- filetype["scala"] = "scala";
- filetype["scss"] = "scss";
- filetype["sh"] = "sh";
- filetype["sql"] = "sql";
- filetype["svg"] = "svg";
- filetype["textile"] = "textile";
- filetype["txt"] = "textile";
- filetype["xml"] = "xml";
-
- if (filetype[fileExt] != null) {
- aceEditor.getSession().setMode("./ace/mode/" + filetype[fileExt]);
- //var syntaxMode = require("./ace/mode/" + filetype[fileExt]).Mode;
- //aceEditor.getSession().setMode(new syntaxMode());
- }
-}
+var filetype = new Array();
+filetype["h"] = "c_cpp";
+filetype["c"] = "c_cpp";
+filetype["clj"] = "clojure";
+filetype["coffee"] = "coffee";
+filetype["coldfusion"] = "cfc";
+filetype["cpp"] = "c_cpp";
+filetype["cs"] = "csharp";
+filetype["css"] = "css";
+filetype["groovy"] = "groovy";
+filetype["haxe"] = "hx";
+filetype["htm"] = "html";
+filetype["html"] = "html";
+filetype["java"] = "java";
+filetype["js"] = "javascript";
+filetype["jsm"] = "javascript";
+filetype["json"] = "json";
+filetype["latex"] = "latex";
+filetype["less"] = "less";
+filetype["ly"] = "latex";
+filetype["ily"] = "latex";
+filetype["lua"] = "lua";
+filetype["markdown"] = "markdown";
+filetype["md"] = "markdown";
+filetype["mdown"] = "markdown";
+filetype["mdwn"] = "markdown";
+filetype["mkd"] = "markdown";
+filetype["ml"] = "ocaml";
+filetype["mli"] = "ocaml";
+filetype["pl"] = "perl";
+filetype["php"] = "php";
+filetype["powershell"] = "ps1";
+filetype["py"] = "python";
+filetype["rb"] = "ruby";
+filetype["scad"] = "scad";
+filetype["scala"] = "scala";
+filetype["scss"] = "scss";
+filetype["sh"] = "sh";
+filetype["sql"] = "sql";
+filetype["svg"] = "svg";
+filetype["textile"] = "textile";
+filetype["txt"] = "textile";
+filetype["xml"] = "xml";
});
\ No newline at end of file
diff --git a/data/ext/viewerBrowser/extension.js b/data/ext/viewerBrowser/extension.js
index 4fcba55b7..1d4441780 100644
--- a/data/ext/viewerBrowser/extension.js
+++ b/data/ext/viewerBrowser/extension.js
@@ -10,22 +10,26 @@ exports.config = {
],
}
-exports.init = function(elementID) {
+exports.init = function(filePath, elementID) {
console.debug("Initalization Browser Viewer...");
- var viewer = document.getElementById(elementID);
- viewer.innerHTML = '<iframe id="idFrameViewer"></iframe>';
+ filePath = "file:///"+filePath;
+
+ $('#'+elementID).append($('<iframe>', {
+ id: "iframeViewer",
+ src: filePath
+ }));
}
exports.viewerMode = function(isViewerMode) {
-
+ console.debug("viewerMode not supported on this extension");
}
exports.setContent = function(content) {
- document.getElementById('idFrameViewer').src = content;
+ console.debug("setContent not supported on this extension");
}
exports.getContent = function() {
-
+ console.debug("getContent not supported on this extension");
}
});
\ No newline at end of file
diff --git a/data/ext/viewerImage/extension.js b/data/ext/viewerImage/extension.js
index 041b7ef99..b82dc209f 100644
--- a/data/ext/viewerImage/extension.js
+++ b/data/ext/viewerImage/extension.js
@@ -14,22 +14,26 @@ exports.config = {
],
}
-exports.init = function(elementID) {
- console.debug("Initalization Browser Viewer...");
- var viewer = document.getElementById(elementID);
- viewer.innerHTML = '<img id="idImageViewer"></img>';
+exports.init = function(filePath, elementID) {
+ console.debug("Initalization Browser Image Viewer...");
+ filePath = "file:///"+filePath;
+
+ $('#'+elementID).append($('<img>', {
+ id: "imgViewer",
+ src: filePath
+ }));
}
exports.viewerMode = function(isViewerMode) {
-
+ console.debug("viewerMode not supported on this extension");
}
exports.setContent = function(content) {
- document.getElementById('idImageViewer').src = content;
+ console.debug("setContent not supported on this extension");
}
exports.getContent = function() {
-
+ console.debug("getContent not supported on this extension");
}
});
\ No newline at end of file
diff --git a/data/ext/viewerMD/extension.js b/data/ext/viewerMD/extension.js
index 1b1f4a117..5984f5c1a 100644
--- a/data/ext/viewerMD/extension.js
+++ b/data/ext/viewerMD/extension.js
@@ -1,15 +1,42 @@
-//var MDEditor = { };
+define(function(require, exports, module) {
+"use strict";
-var mdconvertor = require(["ext/viewer_md/showdown/showdown"]);
+exports.config = {
+ "id": "viewerMD", // ID should be equal to the directory name where the ext. is located
+ "title": "MD Viewer",
+ "type": "editor", // viewer, ts for tagspace
+ "supportedFileTypes": [
+ "md", "markdown"
+ ]
+}
-// export
-//if (typeof module !== 'undefined') module.exports = Showdown;
+var md2htmlConverter = undefined;
+var containerElID = undefined;
-// stolen from AMD branch of underscore
-// AMD define happens at the end for compatibility with AMD loaders
-// that don't enforce next-turn semantics on modules.
-if (typeof define === 'function' && define.amd) {
- define('mdviewer', function() {
- return mdconvertor;
- });
-}
\ No newline at end of file
+exports.init = function(filePath, containerElementID) {
+ console.debug("Initalization MD Viewer...");
+ containerElID = containerElementID;
+ require(['./showdown/showdown'], function() {
+ md2htmlConverter = new Showdown.converter();
+ IOAPI.loadTextFile(filePath);
+ });
+}
+
+exports.setFileType = function(fileType) {
+ console.debug("setFileType not supported on this extension");
+}
+
+exports.viewerMode = function(isViewerMode) {
+ // set readonly
+}
+
+exports.setContent = function(content) {
+ var html = md2htmlConverter.makeHtml(content);
+ $('#'+containerElID).append(html);
+}
+
+exports.getContent = function() {
+ $('#'+containerElID).html();
+}
+
+});
\ No newline at end of file