summaryrefslogtreecommitdiff
path: root/lib/viewers
diff options
context:
space:
mode:
authorAleksander Machniak <alec@alec.pl>2013-06-12 13:09:57 (GMT)
committerAleksander Machniak <alec@alec.pl>2013-06-12 13:09:57 (GMT)
commit1dd7226c4dbb2532ac7f1fffe9876340ff3a8e2d (patch)
tree8baf9a9ea28ab3e0c75087d4c5d283400c6552ef /lib/viewers
parentba235dd7d80ac031205c548729328d6ce2c4c60b (diff)
downloadkolab-chwala-1dd7226c4dbb2532ac7f1fffe9876340ff3a8e2d.tar.gz
Implemented printing in text viewer
Diffstat (limited to 'lib/viewers')
-rw-r--r--lib/viewers/text.php8
-rw-r--r--lib/viewers/text/file_editor.js18
2 files changed, 20 insertions, 6 deletions
diff --git a/lib/viewers/text.php b/lib/viewers/text.php
index 05fb9c0..4963406 100644
--- a/lib/viewers/text.php
+++ b/lib/viewers/text.php
@@ -114,10 +114,7 @@ class file_viewer_text extends file_viewer
*/
public function href($file, $mimetype = null)
{
- return $_SERVER['SCRIPT_URI'] . '?method=file_get'
- . '&viewer=text'
- . '&file=' . urlencode($file)
- . '&token=' . urlencode(session_id());
+ return $this->api->file_url($file) . '&viewer=text';
}
/**
@@ -129,6 +126,7 @@ class file_viewer_text extends file_viewer
public function output($file, $mimetype = null)
{
$mode = $this->get_mode($mimetype, $file);
+ $href = addcslashes($this->api->file_url($file), "'");
echo '<!DOCTYPE html>
<html>
@@ -151,7 +149,7 @@ class file_viewer_text extends file_viewer
echo "</pre>
<script>
var file_editor = new file_editor;
- file_editor.init('editor', '$mode');
+ file_editor.init('editor', '$mode', '$href');
</script>
</body>
</html>";
diff --git a/lib/viewers/text/file_editor.js b/lib/viewers/text/file_editor.js
index 3601364..72d2a66 100644
--- a/lib/viewers/text/file_editor.js
+++ b/lib/viewers/text/file_editor.js
@@ -2,9 +2,11 @@
function file_editor()
{
this.editable = true;
+ this.printable = true;
- this.init = function(ed, mode)
+ this.init = function(ed, mode, href)
{
+ this.href = href;
this.editor = ace.edit(ed);
this.session = this.editor.getSession();
@@ -29,4 +31,18 @@ function file_editor()
{
return this.editor.getValue();
};
+
+ // print file content
+ this.print = function()
+ {
+ // There's no print function in Ace Editor
+ // it's also not possible to print the page as is
+ // we'd copy the content to a hidden iframe
+ var iframe = document.createElement('iframe');
+
+ iframe.onload = function() { iframe.focus(); iframe.contentWindow.print(); };
+ iframe.src = this.href + '&force-type=text/plain';
+
+ document.body.appendChild(iframe);
+ };
}