provide a basic viewer for text files
This commit is contained in:
parent
5da12fcfa1
commit
cffa4edb72
6 changed files with 97 additions and 0 deletions
|
@ -112,6 +112,7 @@ $loginresult=OC_USER::loginlisener();
|
|||
*/
|
||||
class OC_UTIL {
|
||||
public static $scripts=array();
|
||||
public static $styles=array();
|
||||
private static $fsSetup=false;
|
||||
|
||||
public static function setupFS(){// configure the initial filesystem based on the configuration
|
||||
|
@ -182,6 +183,14 @@ class OC_UTIL {
|
|||
public static function addScript($url){
|
||||
self::$scripts[]=$url;
|
||||
}
|
||||
/**
|
||||
* add a css file
|
||||
*
|
||||
* @param url $url
|
||||
*/
|
||||
public static function addStyle($url){
|
||||
self::$styles[]=$url;
|
||||
}
|
||||
|
||||
/**
|
||||
* array to store all the optional navigation buttons of the plugins
|
||||
|
|
|
@ -31,6 +31,9 @@
|
|||
foreach(OC_UTIL::$scripts as $script){
|
||||
echo("<script type='text/ecmascript' src='$WEBROOT/$script'></script>\n");
|
||||
}
|
||||
foreach(OC_UTIL::$styles as $style){
|
||||
echo("<link rel='stylesheet' type='text/css' href='$style'/>\n");
|
||||
}
|
||||
?>
|
||||
<script type='text/ecmascript'>
|
||||
var WEBROOT='<?php echo($WEBROOT)?>';
|
||||
|
|
5
plugins/textviewer/lib_textviewer.php
Normal file
5
plugins/textviewer/lib_textviewer.php
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?php
|
||||
//load the required js and css files
|
||||
OC_UTIL::addScript('plugins/textviewer/textviewer.js');
|
||||
OC_UTIL::addStyle('plugins/textviewer/style.css');
|
||||
?>
|
14
plugins/textviewer/plugin.xml
Normal file
14
plugins/textviewer/plugin.xml
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?xml version="1.0"?>
|
||||
<plugin version='1.0'>
|
||||
<info>
|
||||
<id>textviewer</id>
|
||||
<name>A simple text viewer for ownCloud</name>
|
||||
<version>0.1</version>
|
||||
<licence>AGPL</licence>
|
||||
<author>Icewind</author>
|
||||
<require>1.1</require>
|
||||
</info>
|
||||
<runtime>
|
||||
<include>lib_textviewer.php</include>
|
||||
</runtime>
|
||||
</plugin>
|
26
plugins/textviewer/style.css
Normal file
26
plugins/textviewer/style.css
Normal file
|
@ -0,0 +1,26 @@
|
|||
#textframe{
|
||||
position:absolute;
|
||||
top:0px;
|
||||
left:0px;
|
||||
height:100%;
|
||||
width:100%;
|
||||
background:rgb(20,20,20);
|
||||
background:rgba(20,20,20,0.9);
|
||||
text-align:center;
|
||||
}
|
||||
|
||||
#textframe div{
|
||||
vertical-align:middle;
|
||||
text-align:left;
|
||||
height:auto;
|
||||
max-height:90%;
|
||||
max-width:90%;
|
||||
margin:20px;
|
||||
margin-left:auto;
|
||||
margin-right:auto;
|
||||
margin-bottom:10px;
|
||||
border: black solid 3px;
|
||||
background:black;
|
||||
color:white;
|
||||
overflow:auto;
|
||||
}
|
40
plugins/textviewer/textviewer.js
Normal file
40
plugins/textviewer/textviewer.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
OC_TextViewer=new Object();
|
||||
|
||||
OC_TextViewer.loader=new OCXMLLoader();
|
||||
OC_TextViewer.showText=function(dir,file){
|
||||
var path=WEBROOT+'/files/open_file.php?dir='+encodeURIComponent(dir)+'&file='+encodeURIComponent(file);
|
||||
var div=document.createElement('div');
|
||||
div.setAttribute('id','textframe');
|
||||
div.setAttribute('class','center');
|
||||
div.addEvent('onclick',OC_TextViewer.hideText)
|
||||
OC_TextViewer.textFrame=document.createElement('div');
|
||||
div.appendChild(OC_TextViewer.textFrame);
|
||||
body=document.getElementsByTagName('body').item(0);
|
||||
body.appendChild(div);
|
||||
OC_TextViewer.loader.setCallBack(OC_TextViewer.showTexCallback);
|
||||
OC_TextViewer.loader.load(path);
|
||||
}
|
||||
|
||||
OC_TextViewer.showTexCallback=function(req){
|
||||
var text=req.responseText;
|
||||
OC_TextViewer.textFrame.innerHTML=OC_TextViewer.prepareText(text);
|
||||
}
|
||||
|
||||
OC_TextViewer.hideText=function(){
|
||||
var div=document.getElementById('textframe');
|
||||
div.parentNode.removeChild(div);
|
||||
}
|
||||
|
||||
OC_TextViewer.prepareText=function(text){
|
||||
text=text.replace(/\n/g,"<br/>\n");
|
||||
return text;
|
||||
}
|
||||
|
||||
if(!OC_FILES.fileActions.text){
|
||||
OC_FILES.fileActions.text=new Object()
|
||||
}
|
||||
OC_FILES.fileActions.text.show=function(){
|
||||
OC_TextViewer.showText(this.dir,this.file);
|
||||
}
|
||||
|
||||
OC_FILES.fileActions.text['default']=OC_FILES.fileActions.text.show;
|
Loading…
Reference in a new issue