1
+ ( function ( OCA ) {
2
+
3
+ OCA . LibreOnline = OCA . LibreOnline || { } ;
4
+ OCA . LibreOnline . Viewer = {
5
+
6
+
7
+ attach : function ( fileList ) {
8
+ this . _extendFileActions ( fileList . fileActions ) ;
9
+ } ,
10
+
11
+ hide : function ( ) {
12
+ $ ( '#loframe' ) . remove ( ) ;
13
+ if ( $ ( '#isPublic' ) . val ( ) && $ ( '#filesApp' ) . val ( ) ) {
14
+ $ ( '#controls' ) . removeClass ( 'hidden' ) ;
15
+ }
16
+
17
+ FileList . setViewerMode ( false ) ;
18
+
19
+ $ ( '#app-content #controls' ) . removeClass ( 'hidden' ) ;
20
+ } ,
21
+
22
+
23
+ show : function ( downloadUrl , isFileList ) {
24
+ var self = this ;
25
+ var $iframe ;
26
+ var viewer = OC . generateUrl ( '/apps/libreonline/?file={file}' , { file : downloadUrl } ) ;
27
+ $iframe = $ ( '<iframe id="loframe" style="width:100%;height:100%;display:block;position:absolute;top:0;" src="' + viewer + '" />' ) ;
28
+
29
+ if ( isFileList === true ) {
30
+ FileList . setViewerMode ( true ) ;
31
+ }
32
+
33
+ if ( $ ( '#isPublic' ) . val ( ) ) {
34
+ $ ( '#preview' ) . append ( $iframe ) . css ( { height : '100%' } ) ;
35
+ $ ( 'body' ) . css ( { height : '100%' } ) ;
36
+ $ ( 'footer' ) . addClass ( 'hidden' ) ;
37
+ $ ( '#imgframe' ) . addClass ( 'hidden' ) ;
38
+ $ ( '.directLink' ) . addClass ( 'hidden' ) ;
39
+ $ ( '.directDownload' ) . addClass ( 'hidden' ) ;
40
+ $ ( '#controls' ) . addClass ( 'hidden' ) ;
41
+ } else {
42
+ $ ( '#app-content' ) . append ( $iframe ) ;
43
+ }
44
+
45
+ $ ( "#pageWidthOption" ) . attr ( "selected" , "selected" ) ;
46
+ $ ( '#app-content #controls' ) . addClass ( 'hidden' ) ;
47
+
48
+ $ ( '#loframe' ) . load ( function ( ) {
49
+ var iframe = $ ( '#loframe' ) . contents ( ) ;
50
+ if ( $ ( '#fileList' ) . length ) {
51
+ iframe . find ( '#secondaryToolbarClose' ) . click ( function ( ) {
52
+ self . hide ( ) ;
53
+ } ) ;
54
+ } else {
55
+ iframe . find ( "#secondaryToolbarClose" ) . addClass ( 'hidden' ) ;
56
+ }
57
+ } ) ;
58
+ } ,
59
+
60
+
61
+ _extendFileActions : function ( fileActions ) {
62
+
63
+
64
+ var self = this ;
65
+
66
+ mimes = [ 'application/msword' ,
67
+ 'application/msword' ,
68
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document' ,
69
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.template' ,
70
+ 'application/vnd.ms-word.document.macroEnabled.12' ,
71
+ 'application/vnd.ms-word.template.macroEnabled.12' ,
72
+ 'application/vnd.ms-excel' ,
73
+ 'application/vnd.ms-excel' ,
74
+ 'application/vnd.ms-excel' ,
75
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ,
76
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.template' ,
77
+ 'application/vnd.ms-excel.sheet.macroEnabled.12' ,
78
+ 'application/vnd.ms-excel.template.macroEnabled.12' ,
79
+ 'application/vnd.ms-excel.addin.macroEnabled.12' ,
80
+ 'application/vnd.ms-excel.sheet.binary.macroEnabled.12' ,
81
+ 'application/vnd.ms-powerpoint' ,
82
+ 'application/vnd.ms-powerpoint' ,
83
+ 'application/vnd.ms-powerpoint' ,
84
+ 'application/vnd.ms-powerpoint' ,
85
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation' ,
86
+ 'application/vnd.openxmlformats-officedocument.presentationml.template' ,
87
+ 'application/vnd.openxmlformats-officedocument.presentationml.slideshow' ,
88
+ 'application/vnd.ms-powerpoint.addin.macroEnabled.12' ,
89
+ 'application/vnd.ms-powerpoint.presentation.macroEnabled.12' ,
90
+ 'application/vnd.ms-powerpoint.template.macroEnabled.12' ,
91
+ 'application/vnd.ms-powerpoint.slideshow.macroEnabled.12' ,
92
+ 'application/vnd.oasis.opendocument.chart' ,
93
+ 'application/vnd.oasis.opendocument.chart-template' ,
94
+ 'application/vnd.oasis.opendocument.formula' ,
95
+ 'application/vnd.oasis.opendocument.formula-template' ,
96
+ 'application/vnd.oasis.opendocument.graphics' ,
97
+ 'application/vnd.oasis.opendocument.graphics-template' ,
98
+ 'application/vnd.oasis.opendocument.image' ,
99
+ 'application/vnd.oasis.opendocument.image-template' ,
100
+ 'application/vnd.oasis.opendocument.presentation' ,
101
+ 'application/vnd.oasis.opendocument.presentation-template' ,
102
+ 'application/vnd.oasis.opendocument.spreadsheet' ,
103
+ 'application/vnd.oasis.opendocument.spreadsheet-template' ,
104
+ 'application/vnd.oasis.opendocument.text' ,
105
+ 'application/vnd.oasis.opendocument.text-master' ,
106
+ 'application/vnd.oasis.opendocument.text-template' ,
107
+ 'application/vnd.oasis.opendocument.text-web' ,
108
+ 'application/vnd.oasis.opendocument.database' ,
109
+ ]
110
+
111
+ for ( var _mime in mimes ) {
112
+ fileActions . registerAction ( {
113
+ name : 'view' ,
114
+ displayName : 'Favorite' ,
115
+ mime : mimes [ _mime ] ,
116
+ permissions : OC . PERMISSION_READ ,
117
+ actionHandler : function ( fileName , context ) {
118
+ var downloadUrl = '' ;
119
+ if ( $ ( '#isPublic' ) . val ( ) ) {
120
+ var sharingToken = $ ( '#sharingToken' ) . val ( ) ;
121
+ downloadUrl = OC . generateUrl ( '/s/{token}/download?files={files}&path={path}' , {
122
+ token : sharingToken ,
123
+ files : fileName ,
124
+ path : context . dir
125
+ } ) ;
126
+ } else {
127
+ downloadUrl = Files . getDownloadUrl ( fileName , context . dir ) ;
128
+ }
129
+ self . show ( context . dir + '/' + fileName , true ) ;
130
+ }
131
+ } ) ;
132
+ fileActions . setDefault ( mimes [ _mime ] , 'view' ) ;
133
+ }
134
+
135
+ }
136
+ } ;
137
+
138
+ } ) ( OCA ) ;
139
+
140
+ if ( ! $ . browser . msie || ( $ . browser . msie && $ . browser . version >= 9 ) ) {
141
+ OC . Plugins . register ( 'OCA.Files.FileList' , OCA . LibreOnline . Viewer ) ;
142
+ }
0 commit comments