118 lines
5.6 KiB
JavaScript
118 lines
5.6 KiB
JavaScript
// browser_logic.js
|
||
// Этот файл использует глобальные константы, определенные в шаблоне
|
||
// (IS_MULTILINK, REQUEST_ID, TARGET, TARGET_ID, MEDIA_PATH, REQUEST_TARGET, th_folder)
|
||
|
||
window.getUrlParam = function(paramName) {
|
||
let reParam = new RegExp('(?:[\\?&]|&)' + paramName + '=([^&]+)', 'i');
|
||
let match = window.location.search.match(reParam);
|
||
return (match && match.length > 1) ? match[1] : '';
|
||
}
|
||
|
||
window.getImgPreview = function(url) {
|
||
let parts = url.split('/');
|
||
let fileName = parts.pop();
|
||
let fileExt = fileName.split('.').pop();
|
||
|
||
// th_folder определен в шаблоне
|
||
let thumb = th_folder + '/' + fileName.substr(0, fileName.lastIndexOf(".")) + '-t128x128.' + fileExt;
|
||
|
||
parts.push(thumb);
|
||
return parts.join('/');
|
||
}
|
||
|
||
window.submitTheForm = function() {
|
||
var bDirName = document.bForm.bDirName.value;
|
||
if (bDirName && !bDirName.endsWith('/')) {
|
||
document.bForm.bDirName.value = bDirName + '/';
|
||
}
|
||
|
||
if (document.bForm.bFileName.value == '' && (TARGET != 'dir' && TARGET != 'directory' && TARGET != 'cascad')) {
|
||
alert(MAIN_MP_PLEASE_SELECT);
|
||
} else {
|
||
|
||
if (IS_MULTILINK) {
|
||
let fullPath = MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
// Убедимся, что путь начинается со слэша, если MEDIA_PATH его не содержит
|
||
if (!fullPath.startsWith('/')) {
|
||
fullPath = '/' + fullPath;
|
||
}
|
||
window.opener.document.getElementById(REQUEST_ID).value = fullPath;
|
||
}
|
||
|
||
else {
|
||
if (TARGET == 'link') {
|
||
var funcNum = window.getUrlParam('CKEditorFuncNum');
|
||
var fileUrl = MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||
|
||
} else if (TARGET == 'link_image') {
|
||
window.opener.document.getElementById('txtLnkUrl').value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
|
||
} else if (TARGET == 'txtUrl') {
|
||
var funcNum = window.getUrlParam('CKEditorFuncNum');
|
||
var fileUrl = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value
|
||
window.opener.CKEDITOR.tools.callFunction(funcNum, fileUrl);
|
||
|
||
} else if (TARGET == 'navi') {
|
||
window.opener.document.getElementById(REQUEST_ID).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
|
||
} else if (TARGET == 'img_feld') {
|
||
let imgSource = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
window.opener.document.getElementById('img_feld__' + TARGET_ID).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
window.opener.document.getElementById('_img_feld__' + TARGET_ID).src = window.getImgPreview(imgSource);
|
||
window.opener.$('.preview__' + TARGET_ID).attr("href", window.getImgPreview(imgSource));
|
||
|
||
} else if (TARGET != '' && TARGET_ID != '' && TARGET_ID != null) {
|
||
|
||
if (TARGET == 'image') {
|
||
let imgSource = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
window.opener.$('#preview__' + TARGET_ID).attr('src', window.getImgPreview(imgSource));
|
||
window.opener.$('.preview__' + TARGET_ID).attr('href', '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||
window.opener.$('#' + TARGET + '__' + TARGET_ID).val('/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value);
|
||
}
|
||
|
||
if (TARGET == 'dir') {
|
||
var bdn = document.bForm.bDirName.value.split('/').reverse();
|
||
window.opener.document.getElementById(TARGET + '__' + TARGET_ID).value = bdn[1];
|
||
}
|
||
|
||
if (TARGET == 'directory') {
|
||
window.opener.$.fn.myPlugin('/' + MEDIA_PATH + document.bForm.bDirName.value, TARGET_ID);
|
||
}
|
||
|
||
if (TARGET == 'cascad') {
|
||
var data_parts = TARGET_ID.split('_');
|
||
var data_id_0 = data_parts[0];
|
||
var data_id_1 = data_parts[1];
|
||
window.opener.$.fn.myPlugin('/' + MEDIA_PATH + document.bForm.bDirName.value, data_id_0, data_id_1);
|
||
}
|
||
|
||
}
|
||
|
||
else if (TARGET != 'all') {
|
||
if (REQUEST_TARGET != '') {
|
||
window.opener.document.getElementById(REQUEST_TARGET).value = '/' + MEDIA_PATH + document.bForm.bDirName.value + document.bForm.bFileName.value;
|
||
}
|
||
}
|
||
}
|
||
|
||
setTimeout("self.close();", 100);
|
||
}
|
||
}
|
||
|
||
window.NewFolder = function() {
|
||
var title = MAIN_MP_CREATE_FOLDER;
|
||
var text = MAIN_ADD_FOLDER;
|
||
jPrompt(text, '', title, function(b) {
|
||
if (b) {
|
||
$.alerts._overlay('hide');
|
||
$.alerts._overlay('show');
|
||
// используем REQUEST_TARGET (значение, полученное из TARGET)
|
||
window.parent.frames['zf'].location.href = 'index.php?do=browser&type=' + REQUEST_TARGET + '&target=' + TARGET + '&action=list&dir=' + document.bForm.bDirName.value + '&newdir=' + b;
|
||
$.alerts._overlay('hide');
|
||
} else {
|
||
$.alerts._overlay('hide');
|
||
$.jGrowl(MAIN_NO_ADD_FOLDER);
|
||
}
|
||
});
|
||
} |