|
1 | 1 | ;(function(document, window, $){ |
2 | 2 | window.lastImageCtrl = ''; |
3 | 3 | window.lastFileCtrl = ''; |
4 | | - const icon_header = "fa fa-external-link"; |
| 4 | + const icon_header = "fa fa-folder-open"; |
5 | 5 | var currentWin = window, |
6 | 6 | $actions, |
7 | | - showAlert = window.filemanageropen_alert || 0, |
8 | | - showButtons = window.filemanageropen_showbtn || 0; |
| 7 | + showAlert = parseInt(window.filemanageropen_alert) || 0, |
| 8 | + showButtons = parseInt(window.filemanageropen_showbtn) || 0; |
9 | 9 | window_init = function(){ |
10 | 10 | // Переопределяем метод window.open |
11 | 11 | (function(proxied) { |
|
33 | 33 | evoMod.popup( |
34 | 34 | { |
35 | 35 | url: window.location.origin + window.location.pathname + srg[0], |
36 | | - addclass: 'kcfinder_popup', |
37 | | - title: "gener", |
| 36 | + addclass: 'gener_popup', |
| 37 | + title: window.fmolang["load"], |
38 | 38 | icon: icon_header, |
39 | 39 | iframe: 'iframe', |
40 | 40 | position: 'center center', |
|
80 | 80 | } |
81 | 81 | return dir; |
82 | 82 | }, |
| 83 | + alertPopup = function(message = "", file_path = "", type = "default") { |
| 84 | + let evoMod = window.modx || window.parent.modx || window.parent.parent.modx; |
| 85 | + file_path = file_path.split("\n").join("<br>"); |
| 86 | + evoMod.alert( `${message}<br>${file_path}`, type); |
| 87 | + }, |
83 | 88 | copyFilePath = function(file_path){ |
84 | 89 | var fl = window.fmolang; |
85 | 90 | file_path = file_path.join("\n"); |
86 | 91 | if(currentWin.navigator.clipboard){ |
87 | 92 | currentWin.navigator.clipboard.writeText(file_path).then(function(){ |
88 | 93 | if(showAlert){ |
89 | | - currentWin.alert(fl["copy"] + "\n" + file_path); |
| 94 | + //currentWin.alert(fl["copy"] + "\n" + file_path); |
| 95 | + alertPopup(fl["copy"], file_path, 'success'); |
90 | 96 | } |
91 | 97 | }, function(err){ |
92 | 98 | alternativeCopyFilePath(file_path); |
|
104 | 110 | input.focus(); |
105 | 111 | input.select(); |
106 | 112 | if(!currentWin.document.execCommand('copy')) { |
107 | | - currentWin.alert(fl["nocopy"]); |
| 113 | + //currentWin.alert(fl["nocopy"]); |
| 114 | + alertPopup(fl["nocopy"], "", 'danger'); |
| 115 | + }else{ |
| 116 | + if(showAlert){ |
| 117 | + alertPopup(fl["copy"], path, 'success'); |
| 118 | + } |
108 | 119 | } |
109 | 120 | currentWin.document.body.removeChild(input); |
110 | | - if(showAlert){ |
111 | | - currentWin.alert(fl["copy"] + "\n" + path); |
112 | | - } |
113 | 121 | } catch (err) { |
114 | | - currentWin.alert(fl["nocopy"]); |
| 122 | + alertPopup(fl["nocopy"], "", 'danger'); |
115 | 123 | } |
116 | 124 | } |
117 | 125 | }; |
|
127 | 135 | // Переопределяем глобальную функию OpenServerBrowser |
128 | 136 | window.OpenServerBrowser = function(url) { |
129 | 137 | let evoMod = window.modx || window.parent.modx || window.parent.parent.modx; |
130 | | - //let evoPopupHeader; |
131 | 138 | let popup; |
132 | 139 | let pWidth; |
133 | 140 | let pHeight; |
134 | 141 | let myReq; |
| 142 | + let intIframe; |
| 143 | + let popupIframe; |
135 | 144 | const eventHandler = (event) => { |
136 | 145 | // |
137 | 146 | let data = typeof event.data == "string" ? JSON.parse(event.data) : event.data; |
138 | 147 | switch(data.type){ |
139 | 148 | case "kcfinder:change-title": |
140 | 149 | if(evoPopupHeader) { |
141 | | - evoPopupHeader.innerHTML = `<i class="${icon_header}"></i>${data.title}`; |
| 150 | + const regex = /^(kcfinder)/i; |
| 151 | + const subst = `<i class="${icon_header}"></i>$1`; |
| 152 | + data.title = data.title.replace(regex, subst); |
| 153 | + evoPopupHeader.innerHTML = data.title; |
142 | 154 | } |
143 | 155 | break; |
144 | 156 | } |
145 | 157 | }; |
| 158 | + const iframeLoad = function(e) { |
| 159 | + if (e.target.contentDocument.title) { |
| 160 | + // Если есть шапка попапа |
| 161 | + if(evoPopupHeader) { |
| 162 | + // Перезапись заголовка |
| 163 | + const regex = /^(kcfinder)/i; |
| 164 | + const subst = `<i class="${icon_header}"></i>$1`; |
| 165 | + evoPopupHeader.innerHTML = e.target.contentDocument.title.replace(regex, subst); |
| 166 | + // Остановить прелоадер |
| 167 | + evoMod.main.stopWork(); |
| 168 | + } |
| 169 | + } |
| 170 | + } |
| 171 | + // Ресайз попапа с kcfinder |
146 | 172 | const eventResizeHandler = function() { |
147 | 173 | if ( popup ) { |
148 | 174 | let w, |
|
172 | 198 | { |
173 | 199 | addclass: 'kcfinder_popup', |
174 | 200 | url: url, |
175 | | - title: `<i class="${icon_header}">File Manager Dialog`, |
| 201 | + title: window.fmolang["kcfinder"], |
176 | 202 | icon: icon_header, |
177 | 203 | iframe: 'iframe', |
178 | 204 | position: 'center center', |
|
183 | 209 | resize: !0, |
184 | 210 | overlay: 1, |
185 | 211 | overlayclose: 1, |
186 | | - onclose: function() { |
| 212 | + onclose: function(e, obj) { |
187 | 213 | if(typeof reloadElementsInTree == 'function'){ |
188 | 214 | setTimeout(reloadElementsInTree, 400); |
189 | 215 | } |
| 216 | + popupIframe && popupIframe.removeEventListener('load', iframeLoad) |
190 | 217 | // Удалить |
| 218 | + popupIframe = null; |
191 | 219 | evoPopupHeader = null; |
192 | 220 | window.removeEventListener('message', eventHandler); |
193 | 221 | // остановка |
194 | 222 | cancelAnimationFrame(myReq); |
195 | 223 | popup = null; |
196 | 224 | }, |
| 225 | + // Если подобная функция всё же будет |
| 226 | + onshow: function(e, obj) { |
| 227 | + evoPopupHeader = obj.querySelector('.evo-popup-header'); |
| 228 | + popupIframe = obj.querySelector('iframe'); |
| 229 | + // Подписываемся на события |
| 230 | + window.addEventListener('message', eventHandler); |
| 231 | + // старт ресайза. |
| 232 | + myReq = requestAnimationFrame(eventResizeHandler); |
| 233 | + popupIframe && popupIframe.addEventListener('load', iframeLoad); |
| 234 | + }, |
197 | 235 | wrap: document.body |
198 | 236 | } |
199 | 237 | ); |
200 | | - setTimeout(() => { |
201 | | - let popupEl = popup.el; |
202 | | - evoPopupHeader = popupEl.querySelector('.evo-popup-header'); |
203 | | - window.addEventListener('message', eventHandler); |
204 | | - // старт |
205 | | - myReq = requestAnimationFrame(eventResizeHandler); |
206 | | - }, 100); |
207 | 238 | } |
208 | 239 | } |
209 | 240 | // Переопределяем глобальную функию BrowseServer |
|
271 | 302 | var $td = $('#actions'); |
272 | 303 | if($td.length){ |
273 | 304 | var fl = window.fmolang; |
| 305 | + // Сделать логику на показ определённых клавишь |
274 | 306 | var html = `<div class="evoflbw_wrapper btn-group">`; |
275 | | - html += `<a href="evoflbw:button" data-type="images" class="btn btn-secondary"><i class="fas fa-file-image fa"></i><span>` + fl["images"] + `</span></a>`; |
276 | | - html += `<a href="evoflbw:button" data-type="media" class="btn btn-secondary"><i class="fas fa-file-video fa"></i><span>` + fl["media"] + `</span></a>`; |
277 | | - html += `<a href="evoflbw:button" data-type="files" class="btn btn-secondary"><i class="fas fa-file-alt fa"></i><span>` + fl["files"] + `</span></a>`; |
| 307 | + if(parseInt(fl["showimage"]) || 0) { |
| 308 | + html += `<a href="evoflbw:button" data-type="images" class="btn btn-secondary"><i class="fas fa-file-image fa"></i><span>` + fl["images"] + `</span></a>`; |
| 309 | + } |
| 310 | + if(parseInt(fl["showfile"]) || 0){ |
| 311 | + html += `<a href="evoflbw:button" data-type="files" class="btn btn-secondary"><i class="fas fa-file-alt fa"></i><span>` + fl["files"] + `</span></a>`; |
| 312 | + } |
| 313 | + if(parseInt(fl["showmedia"]) || 0){ |
| 314 | + html += `<a href="evoflbw:button" data-type="media" class="btn btn-secondary"><i class="fas fa-file-video fa"></i><span>` + fl["media"] + `</span></a>`; |
| 315 | + } |
278 | 316 | html += `</div>`; |
279 | 317 | $td.append(html); |
280 | 318 | $('a[href*="evoflbw:"]').on('click', function(e){ |
|
0 commit comments