2019-02-12 11:29:50 +01:00
|
|
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
|
|
|
|
/**
|
|
|
|
* Filebrowser - Friendica Communications Server
|
|
|
|
*
|
2021-03-29 08:40:20 +02:00
|
|
|
* Copyright (c) 2010-2021, the Friendica project
|
2019-02-12 11:29:50 +01:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This code handle user interaction for image/file upload/browser dialog.
|
|
|
|
* Is loaded from filebrowser_plain.tpl
|
|
|
|
*
|
|
|
|
* To load filebrowser in colorbox, call
|
|
|
|
*
|
|
|
|
* Dialog.doImageBrowser(eventname, id);
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* Dialog.doFileBrowser(eventname, id);
|
|
|
|
*
|
|
|
|
* where:
|
|
|
|
*
|
|
|
|
* eventname: event name to catch return value
|
|
|
|
* id: id returned to event handler
|
|
|
|
*
|
|
|
|
* When user select an item, an event in fired in parent page, on body element
|
|
|
|
* The event is named
|
|
|
|
*
|
|
|
|
* fbrowser.<type>.[<eventname>]
|
|
|
|
*
|
|
|
|
* <type> will be one of "image" or "file", and the event handler will
|
|
|
|
* get the following params:
|
|
|
|
*
|
2022-11-25 23:43:07 +01:00
|
|
|
* filename: filename of item chosen by user
|
2019-02-12 11:29:50 +01:00
|
|
|
* embed: bbcode to embed element into posts
|
|
|
|
* id: id from caller code
|
|
|
|
*
|
|
|
|
* example:
|
|
|
|
*
|
|
|
|
* // open dialog for select an image for a textarea with id "myeditor"
|
|
|
|
* var id="myeditor";
|
|
|
|
* Dialog.doImageBrowser("example", id);
|
|
|
|
*
|
|
|
|
* // setup event handler to get user selection
|
|
|
|
* $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {
|
|
|
|
* // close colorbox
|
|
|
|
* $.colorbox.close();
|
2022-11-25 23:43:07 +01:00
|
|
|
* // replace textarea text with bbcode
|
2019-02-12 11:29:50 +01:00
|
|
|
* $(id).value = bbcode;
|
|
|
|
* });
|
|
|
|
**/
|
2022-11-27 01:33:13 +01:00
|
|
|
const Browser = {
|
2022-11-25 23:43:07 +01:00
|
|
|
nickname: '',
|
|
|
|
type: '',
|
|
|
|
event: '',
|
|
|
|
id: null,
|
2019-02-12 11:29:50 +01:00
|
|
|
|
2022-11-25 23:43:07 +01:00
|
|
|
init: function (nickname, type) {
|
2022-11-27 01:33:13 +01:00
|
|
|
Browser.nickname = nickname;
|
|
|
|
Browser.type = type;
|
|
|
|
Browser.event = 'fbrowser.' + type;
|
2022-11-26 23:34:16 +01:00
|
|
|
if (location['hash'] !== '') {
|
2022-11-25 23:43:07 +01:00
|
|
|
const h = location['hash'].replace('#', '');
|
2022-11-27 01:33:13 +01:00
|
|
|
Browser.event = Browser.event + '.' + h.split('-')[0];
|
|
|
|
Browser.id = h.split('-')[1];
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
|
|
|
|
2022-11-25 23:43:07 +01:00
|
|
|
$('.error a.close').on('click', function (e) {
|
2019-02-12 11:29:50 +01:00
|
|
|
e.preventDefault();
|
2022-11-25 23:43:07 +01:00
|
|
|
$('.error').addClass('hidden');
|
2019-02-12 11:29:50 +01:00
|
|
|
});
|
|
|
|
|
2022-11-25 23:43:07 +01:00
|
|
|
$('.folders a, .path a').on('click', function (e) {
|
2019-02-12 11:29:50 +01:00
|
|
|
e.preventDefault();
|
2022-11-27 01:33:13 +01:00
|
|
|
location.href = Browser._getUrl("minimal", location['hash'], this.dataset.folder);
|
2022-11-25 23:43:07 +01:00
|
|
|
location.reload();
|
2019-02-12 11:29:50 +01:00
|
|
|
});
|
|
|
|
|
2022-11-25 23:43:07 +01:00
|
|
|
$(".photo-album-photo-link").on('click', function (e) {
|
2019-02-12 11:29:50 +01:00
|
|
|
e.preventDefault();
|
|
|
|
|
2022-11-25 23:43:07 +01:00
|
|
|
let embed = '';
|
2022-11-27 01:33:13 +01:00
|
|
|
if (Browser.type === "photo") {
|
2022-11-25 23:43:07 +01:00
|
|
|
embed = '[url=' + this.dataset.link + '][img=' + this.dataset.img + ']' + this.dataset.alt + '[/img][/url]';
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
2022-11-27 01:33:13 +01:00
|
|
|
if (Browser.type === "attachment") {
|
2022-11-25 23:43:07 +01:00
|
|
|
embed = '[attachment]' + this.dataset.link + '[/attachment]';
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
2022-11-27 01:33:13 +01:00
|
|
|
parent.$('body').trigger(Browser.event, [
|
2019-02-12 11:29:50 +01:00
|
|
|
this.dataset.filename,
|
|
|
|
embed,
|
2022-11-27 01:33:13 +01:00
|
|
|
Browser.id
|
2019-02-12 11:29:50 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2022-11-27 01:25:59 +01:00
|
|
|
if ($('#upload-photo').length) {
|
2022-11-25 23:43:07 +01:00
|
|
|
new window.AjaxUpload(
|
2022-11-27 01:25:59 +01:00
|
|
|
'upload-photo',
|
2022-11-25 23:43:07 +01:00
|
|
|
{
|
2022-11-27 01:25:59 +01:00
|
|
|
action: 'media/photo/upload?response=json',
|
2019-02-12 11:29:50 +01:00
|
|
|
name: 'userfile',
|
|
|
|
responseType: 'json',
|
2022-11-25 23:43:07 +01:00
|
|
|
onSubmit: function (file, ext) {
|
|
|
|
$('#profile-rotator').show();
|
|
|
|
$('.error').addClass('hidden');
|
|
|
|
},
|
|
|
|
onComplete: function (file, response) {
|
|
|
|
if (response['error'] !== undefined) {
|
|
|
|
$('.error span').html(response['error']);
|
|
|
|
$('.error').removeClass('hidden');
|
2019-02-12 11:29:50 +01:00
|
|
|
$('#profile-rotator').hide();
|
|
|
|
return;
|
|
|
|
}
|
2022-11-27 01:33:13 +01:00
|
|
|
location.href = Browser._getUrl("minimal", location['hash']);
|
2022-11-25 23:43:07 +01:00
|
|
|
location.reload();
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2022-11-25 23:43:07 +01:00
|
|
|
}
|
2019-02-12 11:29:50 +01:00
|
|
|
|
2022-11-27 01:25:59 +01:00
|
|
|
if ($('#upload-attachment').length) {
|
2022-11-25 23:43:07 +01:00
|
|
|
new window.AjaxUpload(
|
|
|
|
'upload-attachment',
|
|
|
|
{
|
2022-11-27 01:25:59 +01:00
|
|
|
action: 'media/attachment/upload?response=json',
|
2019-02-12 11:29:50 +01:00
|
|
|
name: 'userfile',
|
2022-10-30 18:36:08 +01:00
|
|
|
responseType: 'json',
|
2022-11-25 23:43:07 +01:00
|
|
|
onSubmit: function (file, ext) {
|
|
|
|
$('#profile-rotator').show();
|
|
|
|
$('.error').addClass('hidden');
|
|
|
|
},
|
|
|
|
onComplete: function (file, response) {
|
|
|
|
if (response['error'] !== undefined) {
|
|
|
|
$('.error span').html(response['error']);
|
|
|
|
$('.error').removeClass('hidden');
|
2019-02-12 11:29:50 +01:00
|
|
|
$('#profile-rotator').hide();
|
|
|
|
return;
|
|
|
|
}
|
2022-11-27 01:33:13 +01:00
|
|
|
location.href = Browser._getUrl("minimal", location['hash']);
|
2022-11-25 23:43:07 +01:00
|
|
|
location.reload();
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-27 01:25:59 +01:00
|
|
|
);
|
|
|
|
}
|
2022-11-25 23:43:07 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
_getUrl: function (mode, hash, folder) {
|
2022-11-27 01:33:13 +01:00
|
|
|
let folderValue = folder !== undefined ? folder : Browser.folder;
|
2022-11-25 23:43:07 +01:00
|
|
|
let folderUrl = folderValue !== undefined ? '/' + encodeURIComponent(folderValue) : '';
|
2022-11-27 01:33:13 +01:00
|
|
|
return 'media/' + Browser.type + '/browser' + folderUrl + '?mode=' + mode + hash;
|
2019-02-12 11:29:50 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
// @license-end
|