Skip to content

Commit f953701

Browse files
committed
Merge branch 'release/1.0.1'
2 parents dd3f19d + df041ef commit f953701

File tree

9 files changed

+477
-378
lines changed

9 files changed

+477
-378
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Yii2 PDFJS Change Log
2+
=================================
3+
4+
1.0.1 July 21, 2016
5+
---------------------
6+
7+
- Enh #8: Added option buttons config

Module.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
class Module extends \yii\base\Module
1010
{
11+
public $buttons = [];
12+
1113
/**
1214
* @inheritdoc
1315
*/
@@ -20,6 +22,15 @@ public function init()
2022
{
2123
parent::init();
2224

25+
$this->buttons = array_merge([
26+
'presentationMode' => true,
27+
'openFile' => true,
28+
'print' => true,
29+
'download' => true,
30+
'viewBookmark' => true,
31+
'secondaryToolbarToggle'=> true
32+
], $this->buttons);
33+
2334
// custom initialization code goes here
2435
}
2536
}

PdfJs.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace yii2assets\pdfjs;
4+
use Yii;
45
use yii\helpers\Html;
56
use yii\helpers\Url;
67
use yii\helpers\ArrayHelper;
@@ -17,16 +18,28 @@ class PdfJs extends \yii\base\Widget
1718

1819
public $height = '500px';
1920

20-
public $options= [];
21+
public $options = [];
22+
23+
public $buttons = [];
24+
25+
public function init()
26+
{
27+
parent::init();
28+
$buttons = Yii::$app->getModule('pdfjs')->buttons;
29+
$this->buttons = array_merge($buttons,$this->buttons);
30+
$this->getView()->registerJsFile(Yii::$app->assetManager->getPublishedUrl('@yii2assets/pdfjs/assets').'/yii2-pdfjs.js');
31+
}
2132

2233
public function run()
2334
{
2435
if(!array_key_exists('style',$this->options)){
25-
$this->options['style'] = 'border:solid 2px #736d6d; width:'.$this->width.'; height:'.$this->height.';';
36+
$this->options['style'] = 'border:solid 2px #404040; width:'.$this->width.'; height:'.$this->height.';';
2637
}
2738
return $this->render('viewer',[
2839
'options' => $this->options,
29-
'url' => $this->url
40+
'url' => $this->url,
41+
'buttons'=>$this->buttons,
42+
'id'=>$this->id
3043
]);
3144
}
3245
}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ The preferred way to install this extension is through [composer](http://getcomp
1212
Either run
1313

1414
```
15-
php composer.phar require --prefer-dist yii2assets/yii2-pdfjs "*"
15+
php composer.phar require --prefer-dist yii2assets/yii2-pdfjs ">=1.0"
1616
```
1717

1818
or add
1919

2020
```
21-
"yii2assets/yii2-pdfjs": "*"
21+
"yii2assets/yii2-pdfjs": ">=1.0"
2222
```
2323

2424
to the require section of your `composer.json` file.

assets/yii2-pdfjs.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
function PDFJSIframeform(url)
2+
{
3+
var object = this;
4+
object.time = new Date().getTime();
5+
object.form = $('<form action="'+url+'" target="iframe'+object.time+'" method="post" style="display:none;" id="form'+object.time+'" name="form'+object.time+'"></form>');
6+
7+
object.addParameter = function(parameter,value)
8+
{
9+
$("<input type='hidden' />")
10+
.attr("name", parameter)
11+
.attr("value", value)
12+
.appendTo(object.form);
13+
}
14+
15+
object.send = function()
16+
{
17+
var iframe = $('<iframe data-time="'+object.time+'" style="display:none;" id="iframe'+object.time+'"></iframe>');
18+
$( "body" ).append(iframe);
19+
$( "body" ).append(object.form);
20+
object.form.submit();
21+
iframe.load(function(){ $('#form'+$(this).data('time')).remove(); $(this).remove(); });
22+
}
23+
}

controllers/DefaultController.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace yii2assets\pdfjs\controllers;
44

5+
use Yii;
56
use yii\web\Controller;
67

78
/**
@@ -17,6 +18,22 @@ class DefaultController extends Controller
1718
*/
1819
public function actionIndex()
1920
{
20-
return $this->render('index');
21+
$buttons = Yii::$app->getModule('pdfjs')->buttons;
22+
if(Yii::$app->request->getIsPost()){
23+
24+
$widgitButtonConfig = Yii::$app->request->post();
25+
if(isset(Yii::$app->request->csrfParam)){
26+
unset($widgitButtonConfig[Yii::$app->request->csrfParam]);
27+
}
28+
29+
foreach ($widgitButtonConfig as $key => $value) {
30+
$widgitButtonConfig[$key] = $value == '0' ? false : true;
31+
}
32+
$buttons = array_merge($buttons,$widgitButtonConfig);
33+
}
34+
35+
return $this->render('index',[
36+
'buttons'=>$buttons
37+
]);
2138
}
2239
}

0 commit comments

Comments
 (0)