File tree Expand file tree Collapse file tree 9 files changed +477
-378
lines changed Expand file tree Collapse file tree 9 files changed +477
-378
lines changed Original file line number Diff line number Diff line change
1
+ Yii2 PDFJS Change Log
2
+ =================================
3
+
4
+ 1.0.1 July 21, 2016
5
+ ---------------------
6
+
7
+ - Enh #8 : Added option buttons config
Original file line number Diff line number Diff line change 8
8
*/
9
9
class Module extends \yii \base \Module
10
10
{
11
+ public $ buttons = [];
12
+
11
13
/**
12
14
* @inheritdoc
13
15
*/
@@ -20,6 +22,15 @@ public function init()
20
22
{
21
23
parent ::init ();
22
24
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
+
23
34
// custom initialization code goes here
24
35
}
25
36
}
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
namespace yii2assets \pdfjs ;
4
+ use Yii ;
4
5
use yii \helpers \Html ;
5
6
use yii \helpers \Url ;
6
7
use yii \helpers \ArrayHelper ;
@@ -17,16 +18,28 @@ class PdfJs extends \yii\base\Widget
17
18
18
19
public $ height = '500px ' ;
19
20
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
+ }
21
32
22
33
public function run ()
23
34
{
24
35
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 .'; ' ;
26
37
}
27
38
return $ this ->render ('viewer ' ,[
28
39
'options ' => $ this ->options ,
29
- 'url ' => $ this ->url
40
+ 'url ' => $ this ->url ,
41
+ 'buttons ' =>$ this ->buttons ,
42
+ 'id ' =>$ this ->id
30
43
]);
31
44
}
32
45
}
Original file line number Diff line number Diff line change @@ -12,13 +12,13 @@ The preferred way to install this extension is through [composer](http://getcomp
12
12
Either run
13
13
14
14
```
15
- php composer.phar require --prefer-dist yii2assets/yii2-pdfjs "* "
15
+ php composer.phar require --prefer-dist yii2assets/yii2-pdfjs ">=1.0 "
16
16
```
17
17
18
18
or add
19
19
20
20
```
21
- "yii2assets/yii2-pdfjs": "* "
21
+ "yii2assets/yii2-pdfjs": ">=1.0 "
22
22
```
23
23
24
24
to the require section of your ` composer.json ` file.
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 2
2
3
3
namespace yii2assets \pdfjs \controllers ;
4
4
5
+ use Yii ;
5
6
use yii \web \Controller ;
6
7
7
8
/**
@@ -17,6 +18,22 @@ class DefaultController extends Controller
17
18
*/
18
19
public function actionIndex ()
19
20
{
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
+ ]);
21
38
}
22
39
}
You can’t perform that action at this time.
0 commit comments