2020-09-27 12:36:33 -04:00
|
|
|
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPLv3-or-later
|
2019-07-29 16:41:19 -04:00
|
|
|
/**
|
|
|
|
* Filebrowser - Friendica Communications Server
|
|
|
|
*
|
2021-03-29 02:40:20 -04:00
|
|
|
* Copyright (c) 2010-2021, the Friendica project
|
2019-07-29 16:41:19 -04: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.
|
|
|
|
*
|
2022-11-25 17:43:07 -05:00
|
|
|
* This code handle user interaction for photo/file upload/browser dialog.
|
2019-07-29 16:41:19 -04:00
|
|
|
* 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 17:43:07 -05:00
|
|
|
* filename: filename of item chosen by user
|
2019-07-29 16:41:19 -04: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 17:43:07 -05:00
|
|
|
* // replace textarea text with bbcode
|
2019-07-29 16:41:19 -04:00
|
|
|
* $(id).value = bbcode;
|
|
|
|
* });
|
|
|
|
**/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IMPORTANT
|
|
|
|
*
|
|
|
|
* This is a modified version to work with
|
|
|
|
* the frio theme.and bootstrap modals
|
|
|
|
*
|
2022-11-25 17:43:07 -05:00
|
|
|
* The original file is under:
|
2022-11-26 19:33:13 -05:00
|
|
|
* js/module/media/browser.js
|
2019-07-29 16:41:19 -04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
var Browser = {
|
2022-11-25 17:43:07 -05:00
|
|
|
nickname: '',
|
|
|
|
type: '',
|
|
|
|
event: '',
|
|
|
|
folder: '',
|
2021-01-22 08:38:44 -05:00
|
|
|
id: null,
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2021-01-22 08:38:44 -05:00
|
|
|
init: function (nickname, type, hash) {
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.nickname = nickname;
|
|
|
|
Browser.type = type;
|
|
|
|
Browser.event = 'fbrowser.' + type;
|
2022-11-25 17:43:07 -05:00
|
|
|
|
|
|
|
if (hash !== '') {
|
|
|
|
const h = hash.replace('#', '');
|
|
|
|
const destination = h.split('-')[0];
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.id = h.split('-')[1];
|
|
|
|
Browser.event = Browser.event + '.' + destination;
|
2022-11-25 17:43:07 -05:00
|
|
|
if (destination === 'comment') {
|
|
|
|
// Get the comment textinput field
|
2022-11-26 19:33:13 -05:00
|
|
|
var commentElm = document.getElementById('comment-edit-text-' + Browser.id);
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
2021-01-22 08:38:44 -05:00
|
|
|
}
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
console.log('FileBrowser: ' + nickname, type, Browser.event, Browser.id);
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.postLoad();
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.error .close').on('click', function (e) {
|
2019-07-29 16:41:19 -04:00
|
|
|
e.preventDefault();
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.error').addClass('hidden');
|
2019-07-29 16:41:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Click on album link
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser').on('click', '.folders button, .path button', function (e) {
|
2019-07-29 16:41:19 -04:00
|
|
|
e.preventDefault();
|
2022-11-26 19:33:13 -05:00
|
|
|
let url = Browser._getUrl("none", this.dataset.folder);
|
|
|
|
Browser.folder = this.dataset.folder;
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.loadContent(url);
|
2019-07-29 16:41:19 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
//Embed on click
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser').on('click', '.photo-album-photo-link', function (e) {
|
2019-07-29 16:41:19 -04:00
|
|
|
e.preventDefault();
|
|
|
|
|
2022-11-25 17:43:07 -05:00
|
|
|
let embed = '';
|
2022-11-26 19:33:13 -05:00
|
|
|
if (Browser.type === 'photo') {
|
2022-11-25 17:43:07 -05:00
|
|
|
embed = '[url=' + this.dataset.link + '][img=' + this.dataset.img + ']' + this.dataset.alt + '[/img][/url]';
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
2022-11-26 19:33:13 -05:00
|
|
|
if (Browser.type === 'attachment') {
|
2022-11-25 17:43:07 -05:00
|
|
|
embed = '[attachment]' + this.dataset.link + '[/attachment]';
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Delete prefilled Text of the comment input
|
|
|
|
// Note: not the best solution but function commentOpenUI don't
|
|
|
|
// work as expected (we need a way to wait until commentOpenUI would be finished).
|
|
|
|
// As for now we insert pieces of this function here
|
2022-11-25 17:43:07 -05:00
|
|
|
if (commentElm !== null && typeof commentElm !== 'undefined') {
|
|
|
|
if (commentElm.value === '') {
|
2022-11-26 19:33:13 -05:00
|
|
|
$('#comment-edit-text-' + Browser.id)
|
2022-11-25 17:43:07 -05:00
|
|
|
.addClass('comment-edit-text-full')
|
|
|
|
.removeClass('comment-edit-text-empty');
|
2022-11-26 19:33:13 -05:00
|
|
|
$('#comment-edit-submit-wrapper-' + Browser.id).show();
|
|
|
|
$('#comment-edit-text-' + Browser.id).attr('tabindex', '9');
|
|
|
|
$('#comment-edit-submit-' + Browser.id).attr('tabindex', '10');
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
console.log(Browser.event, this.dataset.filename, embed, Browser.id);
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
$('body').trigger(Browser.event, [this.dataset.filename, embed, Browser.id, this.dataset.img]);
|
2019-07-29 16:41:19 -04:00
|
|
|
|
|
|
|
// Close model
|
2022-11-25 17:43:07 -05:00
|
|
|
$('#modal').modal('hide');
|
2019-07-29 16:41:19 -04:00
|
|
|
// Update autosize for this textarea
|
2022-11-25 17:43:07 -05:00
|
|
|
autosize.update($('.text-autosize'));
|
2019-07-29 16:41:19 -04:00
|
|
|
});
|
|
|
|
|
2022-11-25 17:43:07 -05:00
|
|
|
// EventListener for switching between photo and file mode
|
|
|
|
$('.fbrowser').on('click', '.fbswitcher .btn', function (e) {
|
2019-07-29 16:41:19 -04:00
|
|
|
e.preventDefault();
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.type = this.getAttribute('data-mode');
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser')
|
2021-01-22 08:38:44 -05:00
|
|
|
.removeClass()
|
2022-11-26 19:33:13 -05:00
|
|
|
.addClass('fbrowser ' + Browser.type);
|
2019-07-29 16:41:19 -04:00
|
|
|
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.loadContent(Browser._getUrl("none"));
|
2019-07-29 16:41:19 -04:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Initialize the AjaxUpload for the upload buttons
|
2021-01-22 08:38:44 -05:00
|
|
|
uploadButtons: function () {
|
2022-11-26 19:25:59 -05:00
|
|
|
if ($('#upload-photo').length) {
|
2022-11-25 17:43:07 -05:00
|
|
|
//AjaxUpload for photos
|
|
|
|
new window.AjaxUpload(
|
2022-11-26 19:25:59 -05:00
|
|
|
'upload-photo',
|
2022-11-25 17:43:07 -05:00
|
|
|
{
|
2022-11-26 19:33:13 -05:00
|
|
|
action: 'media/photo/upload?response=json&album=' + encodeURIComponent(Browser.folder),
|
2022-11-25 17:43:07 -05:00
|
|
|
name: 'userfile',
|
|
|
|
responseType: 'json',
|
|
|
|
onSubmit: function (file, ext) {
|
|
|
|
$('.fbrowser-content').hide();
|
|
|
|
$('.fbrowser .profile-rotator-wrapper').show();
|
|
|
|
$('.error').addClass('hidden');
|
|
|
|
},
|
|
|
|
onComplete: function (file, response) {
|
|
|
|
if (response['error'] !== undefined) {
|
|
|
|
$('.error span').html(response['error']);
|
|
|
|
$('.error').removeClass('hidden');
|
|
|
|
$('.fbrowser .profile-rotator-wrapper').hide();
|
|
|
|
$('.fbrowser-content').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// load new content to fbrowser window
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.loadContent(Browser._getUrl("none"));
|
2022-11-25 17:43:07 -05:00
|
|
|
},
|
|
|
|
});
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
|
|
|
|
2022-11-25 17:43:07 -05:00
|
|
|
if ($('#upload-attachment').length) {
|
2019-07-29 16:41:19 -04:00
|
|
|
//AjaxUpload for files
|
2022-11-25 17:43:07 -05:00
|
|
|
new window.AjaxUpload(
|
|
|
|
'upload-attachment',
|
|
|
|
{
|
2022-11-26 19:25:59 -05:00
|
|
|
action: 'media/attachment/upload?response=json',
|
2022-11-25 17:43:07 -05:00
|
|
|
name: 'userfile',
|
|
|
|
responseType: 'json',
|
|
|
|
onSubmit: function (file, ext) {
|
|
|
|
$('.fbrowser-content').hide();
|
|
|
|
$('.fbrowser .profile-rotator-wrapper').show();
|
|
|
|
$('.error').addClass('hidden');
|
|
|
|
},
|
|
|
|
onComplete: function (file, response) {
|
|
|
|
if (response["error"] !== undefined) {
|
|
|
|
$('.error span').html(response['error']);
|
|
|
|
$('.error').removeClass('hidden');
|
|
|
|
$('.fbrowser .profile-rotator-wrapper').hide();
|
|
|
|
$('.fbrowser-content').show();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Load new content to fbrowser window
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.loadContent(Browser._getUrl("none"));
|
2022-11-25 17:43:07 -05:00
|
|
|
},
|
|
|
|
});
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-11-25 17:43:07 -05:00
|
|
|
// Stuff which should be executed if no content was loaded
|
2021-01-22 08:38:44 -05:00
|
|
|
postLoad: function () {
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.initGallery();
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser .fbswitcher .btn').removeClass('active');
|
2022-11-26 19:33:13 -05:00
|
|
|
$('.fbrowser .fbswitcher [data-mode=' + Browser.type + ']').addClass('active');
|
2019-07-29 16:41:19 -04:00
|
|
|
// We need to add the AjaxUpload to the button
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.uploadButtons();
|
2019-07-29 16:41:19 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
// Load new content (e.g. change photo album)
|
2021-01-22 08:38:44 -05:00
|
|
|
loadContent: function (url) {
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser-content').hide();
|
|
|
|
$('.fbrowser .profile-rotator-wrapper').show();
|
2019-07-29 16:41:19 -04:00
|
|
|
|
|
|
|
// load new content to fbrowser window
|
2022-11-25 17:43:07 -05:00
|
|
|
$('.fbrowser').load(url, function (responseText, textStatus) {
|
|
|
|
$('.profile-rotator-wrapper').hide();
|
|
|
|
if (textStatus === 'success') {
|
2019-07-29 16:41:19 -04:00
|
|
|
$(".fbrowser_content").show();
|
2022-11-26 19:33:13 -05:00
|
|
|
Browser.postLoad();
|
2019-07-29 16:41:19 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
// Initialize justified Gallery
|
2021-01-22 08:38:44 -05:00
|
|
|
initGallery: function () {
|
2022-11-26 19:25:59 -05:00
|
|
|
$('.fbrowser.photo .fbrowser-content-container').justifiedGallery({
|
2021-01-22 08:38:44 -05:00
|
|
|
rowHeight: 80,
|
|
|
|
margins: 4,
|
|
|
|
border: 0,
|
2019-07-29 16:41:19 -04:00
|
|
|
});
|
2021-01-22 08:38:44 -05:00
|
|
|
},
|
2022-11-25 17:43:07 -05:00
|
|
|
|
|
|
|
_getUrl: function (mode, folder) {
|
2022-11-26 19:33:13 -05:00
|
|
|
let folderValue = folder !== undefined ? folder : Browser.folder;
|
2022-11-25 17:43:07 -05:00
|
|
|
let folderUrl = folderValue !== undefined ? '/' + encodeURIComponent(folderValue) : '';
|
2022-11-26 19:33:13 -05:00
|
|
|
return 'media/' + Browser.type + '/browser' + folderUrl + '?mode=' + mode + "&theme=frio";
|
2022-11-25 17:43:07 -05:00
|
|
|
}
|
2019-07-29 16:41:19 -04:00
|
|
|
};
|
2020-09-27 12:36:33 -04:00
|
|
|
// @license-end
|