summaryrefslogtreecommitdiff
path: root/lib/viewers
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-06-04 09:56:49 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-06-04 09:56:49 (GMT)
commita1571ae31a5c6df9af5d81c47bd9ffc02c47c848 (patch)
tree3a8fb0c6f1cd71f635bb9d79a35c59565550dad7 /lib/viewers
parentc5b374791679da1ac8ed876d632631d8053fb89c (diff)
downloadkolab-chwala-a1571ae31a5c6df9af5d81c47bd9ffc02c47c848.tar.gz
Enabled plain text files editor
Diffstat (limited to 'lib/viewers')
-rw-r--r--lib/viewers/text.php9
-rw-r--r--lib/viewers/text/file_editor.js32
2 files changed, 35 insertions, 6 deletions
diff --git a/lib/viewers/text.php b/lib/viewers/text.php
index 236396d..4444af8 100644
--- a/lib/viewers/text.php
+++ b/lib/viewers/text.php
@@ -124,6 +124,7 @@ class file_viewer_text extends file_viewer
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Editor</title>
<script src="viewers/text/ace.js" type="text/javascript" charset="utf-8"></script>
+ <script src="viewers/text/file_editor.js" type="text/javascript" charset="utf-8"></script>
<style>
#editor { top: 0; right: 0; bottom: 0; left: 0; position: absolute; font-size: 14px; padding: 0; margin: 0; }
.ace_search_options { float: right; }
@@ -136,12 +137,8 @@ class file_viewer_text extends file_viewer
echo "</pre>
<script>
- var editor = ace.edit('editor'),
- session = editor.getSession();
-
- editor.focus();
- editor.setReadOnly(true);
- session.setMode('ace/mode/$mode');
+ var file_editor = new file_editor;
+ file_editor.init('editor', '$mode');
</script>
</body>
</html>";
diff --git a/lib/viewers/text/file_editor.js b/lib/viewers/text/file_editor.js
new file mode 100644
index 0000000..3601364
--- /dev/null
+++ b/lib/viewers/text/file_editor.js
@@ -0,0 +1,32 @@
+
+function file_editor()
+{
+ this.editable = true;
+
+ this.init = function(ed, mode)
+ {
+ this.editor = ace.edit(ed);
+ this.session = this.editor.getSession();
+
+ this.editor.focus();
+ this.editor.setReadOnly(true);
+ this.session.setMode('ace/mode/' + mode);
+ };
+
+ // switch editor into read-write mode
+ this.enable = function()
+ {
+ this.editor.setReadOnly(false);
+ };
+
+ // switch editor into read-only mode
+ this.disable = function()
+ {
+ this.editor.setReadOnly(true);
+ };
+
+ this.getContent = function()
+ {
+ return this.editor.getValue();
+ };
+}