Skip to content

Commit

Permalink
add viewerjs
Browse files Browse the repository at this point in the history
  • Loading branch information
lesha724 committed Nov 10, 2017
1 parent f709fe5 commit e219511
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ADocumentViewer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function _checkUrl(){

public function run()
{
parent::run(); // TODO: Change the autogenerated stub
parent::run();

return $this->_run();
}
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
online document viewer
======================
виджет для отображения online документов с помощью google viewer и microsoft document viewer
виджет для отображения online документов с помощью google viewer, microsoft document viewer и [viewerJs](http://viewerjs.org/)

Installation
------------
Expand Down Expand Up @@ -48,10 +48,22 @@ Once the extension is installed, simply use it in your code by :

```

```php
<?php
echo \lesha724\documentviewer\ViewerJsDocumentViewer::widget([
'url' => '/README-viewer.odt', //url на ваш документ или http://example.com/test.odt
'width'=>'100%',
'height'=>'100%',
]);?>
```

Links
-----

1. https://support.office.com/uk-ua/article/%D0%9F%D0%B5%D1%80%D0%B5%D0%B3%D0%BB%D1%8F%D0%B4-%D0%B4%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%96%D0%B2-Office-%D0%B2-%D0%86%D0%BD%D1%82%D0%B5%D1%80%D0%BD%D0%B5%D1%82%D1%96-1cc2ea26-0f7b-41f7-8e0e-6461a104544e?ui=uk-UA&rs=uk-UA&ad=UA&fromAR=1
2. https://products.office.com/en-us/office-online/view-office-documents-online
3. https://support.office.com/uk-ua/article/%D0%9F%D1%96%D0%B4%D1%82%D1%80%D0%B8%D0%BC%D0%BA%D0%B0-%D0%B1%D1%80%D0%B0%D1%83%D0%B7%D0%B5%D1%80%D1%96%D0%B2-%D1%83-%D0%B2%D0%B5%D0%B1-%D0%BF%D1%80%D0%BE%D0%B3%D1%80%D0%B0%D0%BC%D0%B0%D1%85-Office-Online-ad1303e0-a318-47aa-b409-d3a5eb44e452?ui=uk-UA&rs=uk-UA&ad=UA
4. https://geektimes.ru/post/111647/
4. https://geektimes.ru/post/111647/
5. http://viewerjs.org/
6. http://viewerjs.org/examples/
7. https://github.com/kogmbh/ViewerJS
42 changes: 42 additions & 0 deletions ViewerJsAssets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Created by PhpStorm.
* User: Lesha
* Date: 08.11.2017
* Time: 0:29
*/

namespace lesha724\documentviewer;


use yii\web\AssetBundle;

/**
* Class ViewerJsAssets
* @package lesha724\documentviewer
*/
class ViewerJsAssets extends AssetBundle
{
/**
* @var string the directory that contains the source asset files for this asset bundle.
*/
public $sourcePath = '@vendor/bower/viewerjs/ViewerJs';
/**
* @var array list of JavaScript files that this bundle contains.
*/
public $js = [
/*'compatibility.js',
'pdf.js',
'pdf.worker.js',
'pdfjsversion.js',
'text_layer_builder.js',
'ui_utils.js',
'webodf.js',*/
];
/**
* @var array list of CSS files that this bundle contains.
*/
public $css = [

];
}
72 changes: 72 additions & 0 deletions ViewerJsDocumentViewer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php
/**
* Created by PhpStorm.
* User: Lesha
* Date: 07.11.2017
* Time: 23:00
*/

namespace lesha724\documentviewer;

use yii\helpers\Html;

/**
* Class ViewerJsDocumentViewer
* @package lesha724\documentviewer
* @property string $urlViewer
*/
class ViewerJsDocumentViewer extends ADocumentViewer
{
/**
* @var string|null
*/
protected $_urlViewer = null;

/**
* getter for urlViewer
* @return string|null
*/
/*public function getUrlViewer(){
return $this->_urlViewer;
}*/

/**
* setter for urlViewer
* @param $value
*/
/*public function setUrlViewer($value){
$this->_urlViewer = $value;
}*/

/**
* Get iframe url for doc
* @return mixed
*/
protected function _getIframeUrl()
{
return $this->_urlViewer.'#'.$this->url;
}

public function init()
{
ViewerJsAssets::register($this->view);
$this->_urlViewer = \Yii::$app->assetManager->getPublishedUrl('@vendor/bower/viewerjs/ViewerJs');
parent::init();
}

/**
* герерация iframe
* @return string
*/
protected function _run(){
$options = [
'src'=>$this->_getIframeUrl(),
'width'=>$this->width,
'height'=>$this->height,
'allowfullscreen',
'webkitallowfullscreen'
];

return Html::tag('iframe','',$options);
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "lesha724/yii2-document-viewer",
"description": "виджет для отображения online документов с помощью google viewer и microsoft document viewer",
"type": "yii2-extension",
"keywords": ["yii2","extension"],
"keywords": ["yii2","extension", "viewer", "viewerjs", "docs", "widget"],
"license": "MIT",
"authors": [
{
Expand All @@ -11,7 +11,8 @@
}
],
"require": {
"yiisoft/yii2": "*"
"yiisoft/yii2": "*",
"bower-asset/viewerjs": "*"
},
"autoload": {
"psr-4": {
Expand Down

0 comments on commit e219511

Please sign in to comment.