Skip to content

Commit f2db129

Browse files
committed
modify useFile function
1 parent 53b763d commit f2db129

File tree

1 file changed

+76
-59
lines changed

1 file changed

+76
-59
lines changed

src/views/script.blade.php

Lines changed: 76 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -270,83 +270,100 @@ function download(file_name) {
270270
// ==================================
271271
272272
function useFile(file) {
273-
var path = $('#working_dir').val();
274273
275-
var item_url = image_url;
274+
function getUrlParam(paramName) {
275+
var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i');
276+
var match = window.location.search.match(reParam);
277+
return ( match && match.length > 1 ) ? match[1] : null;
278+
}
276279
277-
@if ("Images" !== $file_type)
278-
item_url = file_url;
279-
@endif
280+
function useTinymce3(url) {
281+
var win = tinyMCEPopup.getWindowArg("window");
282+
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
283+
if (typeof(win.ImageDialog) != "undefined") {
284+
// Update image dimensions
285+
if (win.ImageDialog.getImageData) {
286+
win.ImageDialog.getImageData();
287+
}
280288
281-
if (path.indexOf(ds) === 0) {
282-
path = path.substring(1);
289+
// Preview if necessary
290+
if (win.ImageDialog.showPreviewImage) {
291+
win.ImageDialog.showPreviewImage(url);
292+
}
293+
}
294+
tinyMCEPopup.close();
283295
}
284296
285-
if (path != ds) {
286-
item_url = item_url + path + ds;
297+
function useTinymce4AndColorbox(url, field_name) {
298+
parent.document.getElementById(field_name).value = url;
299+
300+
if(typeof parent.tinyMCE !== "undefined") {
301+
parent.tinyMCE.activeEditor.windowManager.close();
302+
}
303+
if(typeof parent.$.fn.colorbox !== "undefined") {
304+
parent.$.fn.colorbox.close();
305+
}
287306
}
288307
289-
function getUrlParam(paramName) {
290-
var reParam = new RegExp('(?:[\?&]|&)' + paramName + '=([^&]+)', 'i');
291-
var match = window.location.search.match(reParam);
292-
return ( match && match.length > 1 ) ? match[1] : null;
308+
function useCkeditor3(url) {
309+
if (window.opener) {
310+
// Popup
311+
window.opener.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
312+
} else {
313+
// Modal (in iframe)
314+
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
315+
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorCleanUpFuncNum'));
316+
}
293317
}
294318
295-
var field_name = getUrlParam('field_name');
296-
var url = item_url + file;
297-
url = url.replace(/\\/g,"/");
319+
function useFckeditor2(url) {
320+
var p = url;
321+
var w = data['Properties']['Width'];
322+
var h = data['Properties']['Height'];
323+
window.opener.SetUrl(p,w,h);
324+
}
298325
299-
if (window.opener || window.tinyMCEPopup || field_name || getUrlParam('CKEditorCleanUpFuncNum') || getUrlParam('CKEditor')) {
300-
if (window.tinyMCEPopup) {
301-
// use TinyMCE > 3.0 integration method
302-
var win = tinyMCEPopup.getWindowArg("window");
303-
win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
304-
if (typeof(win.ImageDialog) != "undefined") {
305-
// Update image dimensions
306-
if (win.ImageDialog.getImageData) {
307-
win.ImageDialog.getImageData();
308-
}
326+
function getFileUrl(file) {
327+
var path = $('#working_dir').val();
328+
var item_url = image_url;
309329
310-
// Preview if necessary
311-
if (win.ImageDialog.showPreviewImage) {
312-
win.ImageDialog.showPreviewImage(url);
313-
}
314-
}
315-
tinyMCEPopup.close();
316-
return;
330+
@if ("Images" !== $file_type)
331+
item_url = file_url;
332+
@endif
333+
334+
if (path.indexOf(ds) === 0) {
335+
path = path.substring(1);
317336
}
318337
319-
// tinymce 4 and colorbox
320-
if (field_name) {
321-
parent.document.getElementById(field_name).value = url;
338+
if (path != ds) {
339+
item_url = item_url + path + ds;
340+
}
322341
323-
if(typeof parent.tinyMCE !== "undefined") {
324-
parent.tinyMCE.activeEditor.windowManager.close();
325-
}
326-
if(typeof parent.$.fn.colorbox !== "undefined") {
327-
parent.$.fn.colorbox.close();
328-
}
342+
var url = item_url + file;
343+
url = url.replace(/\\/g, "/");
344+
345+
return url;
346+
}
329347
348+
var url = getFileUrl(file);
349+
var field_name = getUrlParam('field_name');
350+
351+
if (window.opener || window.tinyMCEPopup || field_name || getUrlParam('CKEditorCleanUpFuncNum') || getUrlParam('CKEditor')) {
352+
if (window.tinyMCEPopup) {
353+
// use TinyMCE > 3.0 integration method
354+
useTinymce3(url);
355+
return;
356+
} else if (field_name) {
357+
// tinymce 4 and colorbox
358+
useTinymce4AndColorbox(url, field_name);
330359
} else if(getUrlParam('CKEditor')) {
331360
// use CKEditor 3.0 + integration method
332-
if (window.opener) {
333-
// Popup
334-
window.opener.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
335-
} else {
336-
// Modal (in iframe)
337-
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorFuncNum'), url);
338-
parent.CKEDITOR.tools.callFunction(getUrlParam('CKEditorCleanUpFuncNum'));
339-
}
340-
} else {
361+
useCkeditor3(url);
362+
} else if (typeof data != 'undefined' && data['Properties']['Width'] != '') {
341363
// use FCKEditor 2.0 integration method
342-
if (typeof data != 'undefined' && data['Properties']['Width'] != '') {
343-
var p = url;
344-
var w = data['Properties']['Width'];
345-
var h = data['Properties']['Height'];
346-
window.opener.SetUrl(p,w,h);
347-
} else {
348-
window.opener.SetUrl(url);
349-
}
364+
useFckeditor2(url);
365+
} else {
366+
window.opener.SetUrl(url);
350367
}
351368
352369
if (window.opener) {

0 commit comments

Comments
 (0)