Convert filebrowser.js to unix format

This commit is contained in:
Michael 2019-07-29 20:41:19 +00:00
parent 7f08f5be71
commit 1b0f260255

View File

@ -1,255 +1,255 @@
/** /**
* Filebrowser - Friendica Communications Server * Filebrowser - Friendica Communications Server
* *
* Copyright (c) 2010-2015 the Friendica Project * Copyright (c) 2010-2015 the Friendica Project
* *
* This program is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This code handle user interaction for image/file upload/browser dialog. * This code handle user interaction for image/file upload/browser dialog.
* Is loaded from filebrowser_plain.tpl * Is loaded from filebrowser_plain.tpl
* *
* To load filebrowser in colorbox, call * To load filebrowser in colorbox, call
* *
* Dialog.doImageBrowser(eventname, id); * Dialog.doImageBrowser(eventname, id);
* *
* or * or
* *
* Dialog.doFileBrowser(eventname, id); * Dialog.doFileBrowser(eventname, id);
* *
* where: * where:
* *
* eventname: event name to catch return value * eventname: event name to catch return value
* id: id returned to event handler * id: id returned to event handler
* *
* When user select an item, an event in fired in parent page, on body element * When user select an item, an event in fired in parent page, on body element
* The event is named * The event is named
* *
* fbrowser.<type>.[<eventname>] * fbrowser.<type>.[<eventname>]
* *
* <type> will be one of "image" or "file", and the event handler will * <type> will be one of "image" or "file", and the event handler will
* get the following params: * get the following params:
* *
* filemane: filename of item choosed by user * filemane: filename of item choosed by user
* embed: bbcode to embed element into posts * embed: bbcode to embed element into posts
* id: id from caller code * id: id from caller code
* *
* example: * example:
* *
* // open dialog for select an image for a textarea with id "myeditor" * // open dialog for select an image for a textarea with id "myeditor"
* var id="myeditor"; * var id="myeditor";
* Dialog.doImageBrowser("example", id); * Dialog.doImageBrowser("example", id);
* *
* // setup event handler to get user selection * // setup event handler to get user selection
* $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) { * $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {
* // close colorbox * // close colorbox
* $.colorbox.close(); * $.colorbox.close();
* // replace textxarea text with bbcode * // replace textxarea text with bbcode
* $(id).value = bbcode; * $(id).value = bbcode;
* }); * });
**/ **/
/* /*
* IMPORTANT * IMPORTANT
* *
* This is a modified version to work with * This is a modified version to work with
* the frio theme.and bootstrap modals * the frio theme.and bootstrap modals
* *
* The origninal file is under: * The origninal file is under:
* js/filebrowser.js * js/filebrowser.js
* *
*/ */
var FileBrowser = { var FileBrowser = {
nickname : "", nickname : "",
type : "", type : "",
event: "", event: "",
folder: "", folder: "",
id : null, id : null,
init: function(nickname, type, hash) { init: function(nickname, type, hash) {
FileBrowser.nickname = nickname; FileBrowser.nickname = nickname;
FileBrowser.type = type; FileBrowser.type = type;
FileBrowser.event = "fbrowser."+type; FileBrowser.event = "fbrowser."+type;
if (hash!=="") { if (hash!=="") {
var h = hash.replace("#",""); var h = hash.replace("#","");
var destination = h.split("-")[0]; var destination = h.split("-")[0];
FileBrowser.id = h.split("-")[1]; FileBrowser.id = h.split("-")[1];
FileBrowser.event = FileBrowser.event + "." + destination; FileBrowser.event = FileBrowser.event + "." + destination;
if (destination === "comment") { if (destination === "comment") {
// Get the comment textimput field // Get the comment textimput field
var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id); var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id);
} }
}; };
console.log("FileBrowser: " + nickname, type, FileBrowser.event, FileBrowser.id); console.log("FileBrowser: " + nickname, type, FileBrowser.event, FileBrowser.id);
FileBrowser.postLoad(); FileBrowser.postLoad();
$(".error .close").on("click", function(e) { $(".error .close").on("click", function(e) {
e.preventDefault(); e.preventDefault();
$(".error").addClass("hidden"); $(".error").addClass("hidden");
}); });
// Click on album link // Click on album link
$(".fbrowser").on("click", ".folders a, .path a", function(e) { $(".fbrowser").on("click", ".folders a, .path a", function(e) {
e.preventDefault(); e.preventDefault();
var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none&theme=frio"; var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none&theme=frio";
FileBrowser.folder = this.dataset.folder; FileBrowser.folder = this.dataset.folder;
FileBrowser.loadContent(url); FileBrowser.loadContent(url);
}); });
//Embed on click //Embed on click
$(".fbrowser").on('click', ".photo-album-photo-link", function(e) { $(".fbrowser").on('click', ".photo-album-photo-link", function(e) {
e.preventDefault(); e.preventDefault();
var embed = ""; var embed = "";
if (FileBrowser.type === "image") { if (FileBrowser.type === "image") {
embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]"; embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]";
} }
if (FileBrowser.type === "file") { if (FileBrowser.type === "file") {
// attachment links are "baseurl/attach/id"; we need id // attachment links are "baseurl/attach/id"; we need id
embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]"; embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]";
} }
// Delete prefilled Text of the comment input // Delete prefilled Text of the comment input
// Note: not the best solution but function commentOpenUI don't // Note: not the best solution but function commentOpenUI don't
// work as expected (we need a way to wait until commentOpenUI would be finished). // work as expected (we need a way to wait until commentOpenUI would be finished).
// As for now we insert pieces of this function here // As for now we insert pieces of this function here
if ((commentElm !== null) && (typeof commentElm !== "undefined")) { if ((commentElm !== null) && (typeof commentElm !== "undefined")) {
if (commentElm.value === "") { if (commentElm.value === "") {
$("#comment-edit-text-" + FileBrowser.id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty"); $("#comment-edit-text-" + FileBrowser.id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
$("#comment-edit-submit-wrapper-" + FileBrowser.id).show(); $("#comment-edit-submit-wrapper-" + FileBrowser.id).show();
$("#comment-edit-text-" + FileBrowser.id).attr('tabindex','9'); $("#comment-edit-text-" + FileBrowser.id).attr('tabindex','9');
$("#comment-edit-submit-" + FileBrowser.id).attr('tabindex','10'); $("#comment-edit-submit-" + FileBrowser.id).attr('tabindex','10');
} }
} }
console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id); console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);
$("body").trigger(FileBrowser.event, [ $("body").trigger(FileBrowser.event, [
this.dataset.filename, this.dataset.filename,
embed, embed,
FileBrowser.id, FileBrowser.id,
this.dataset.img this.dataset.img
]); ]);
// Close model // Close model
$('#modal').modal('hide'); $('#modal').modal('hide');
// Update autosize for this textarea // Update autosize for this textarea
autosize.update($(".text-autosize")); autosize.update($(".text-autosize"));
}); });
// EventListener for switching between image and file mode // EventListener for switching between image and file mode
$(".fbrowser").on('click', ".fbswitcher .btn", function(e) { $(".fbrowser").on('click', ".fbswitcher .btn", function(e) {
e.preventDefault(); e.preventDefault();
FileBrowser.type = this.getAttribute("data-mode"); FileBrowser.type = this.getAttribute("data-mode");
$(".fbrowser").removeClass().addClass("fbrowser " + FileBrowser.type); $(".fbrowser").removeClass().addClass("fbrowser " + FileBrowser.type);
url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio"; url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio";
FileBrowser.loadContent(url); FileBrowser.loadContent(url);
}); });
}, },
// Initialize the AjaxUpload for the upload buttons // Initialize the AjaxUpload for the upload buttons
uploadButtons: function() { uploadButtons: function() {
if ($("#upload-image").length) { if ($("#upload-image").length) {
// To get the albumname we need to convert it from hex // To get the albumname we need to convert it from hex
var albumname = hex2bin(FileBrowser.folder); var albumname = hex2bin(FileBrowser.folder);
//AjaxUpload for images //AjaxUpload for images
var image_uploader = new window.AjaxUpload( var image_uploader = new window.AjaxUpload(
'upload-image', 'upload-image',
{ action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname, { action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname,
name: 'userfile', name: 'userfile',
responseType: 'json', responseType: 'json',
onSubmit: function(file, ext) { onSubmit: function(file, ext) {
$(".fbrowser-content").hide(); $(".fbrowser-content").hide();
$(".fbrowser .profile-rotator-wrapper").show(); $(".fbrowser .profile-rotator-wrapper").show();
$(".error").addClass('hidden'); $(".error").addClass('hidden');
}, },
onComplete: function(file,response) { onComplete: function(file,response) {
if (response['error'] != undefined) { if (response['error'] != undefined) {
$(".error span").html(response['error']); $(".error span").html(response['error']);
$(".error").removeClass('hidden'); $(".error").removeClass('hidden');
$(".fbrowser .profile-rotator-wrapper").hide(); $(".fbrowser .profile-rotator-wrapper").hide();
$(".fbrowser-content").show(); $(".fbrowser-content").show();
return; return;
} }
var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none&theme=frio"; var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none&theme=frio";
// load new content to fbrowser window // load new content to fbrowser window
FileBrowser.loadContent(url); FileBrowser.loadContent(url);
} }
} }
); );
} }
if ($("#upload-file").length) { if ($("#upload-file").length) {
//AjaxUpload for files //AjaxUpload for files
var file_uploader = new window.AjaxUpload( var file_uploader = new window.AjaxUpload(
'upload-file', 'upload-file',
{ action: 'wall_attach/' + FileBrowser.nickname + '?response=json', { action: 'wall_attach/' + FileBrowser.nickname + '?response=json',
name: 'userfile', name: 'userfile',
onSubmit: function(file, ext) { onSubmit: function(file, ext) {
$(".fbrowser-content").hide(); $(".fbrowser-content").hide();
$(".fbrowser .profile-rotator-wrapper").show(); $(".fbrowser .profile-rotator-wrapper").show();
$(".error").addClass('hidden'); $(".error").addClass('hidden');
}, },
onComplete: function(file,response) { onComplete: function(file,response) {
if (response['error']!= undefined) { if (response['error']!= undefined) {
$(".error span").html(response['error']); $(".error span").html(response['error']);
$(".error").removeClass('hidden'); $(".error").removeClass('hidden');
$('#profile-rotator').hide(); $('#profile-rotator').hide();
$(".fbrowser-content").show(); $(".fbrowser-content").show();
return; return;
} }
var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio"; var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio";
// Load new content to fbrowser window // Load new content to fbrowser window
FileBrowser.loadContent(url); FileBrowser.loadContent(url);
} }
} }
); );
} }
}, },
// Stuff which should be executed if ne content was loaded // Stuff which should be executed if ne content was loaded
postLoad: function() { postLoad: function() {
FileBrowser.initGallery(); FileBrowser.initGallery();
$(".fbrowser .fbswitcher .btn").removeClass("active"); $(".fbrowser .fbswitcher .btn").removeClass("active");
$(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active"); $(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active");
// We need to add the AjaxUpload to the button // We need to add the AjaxUpload to the button
FileBrowser.uploadButtons(); FileBrowser.uploadButtons();
}, },
// Load new content (e.g. change photo album) // Load new content (e.g. change photo album)
loadContent: function(url) { loadContent: function(url) {
$(".fbrowser-content").hide(); $(".fbrowser-content").hide();
$(".fbrowser .profile-rotator-wrapper").show(); $(".fbrowser .profile-rotator-wrapper").show();
// load new content to fbrowser window // load new content to fbrowser window
$(".fbrowser").load(url, function(responseText, textStatus) { $(".fbrowser").load(url, function(responseText, textStatus) {
$(".profile-rotator-wrapper").hide(); $(".profile-rotator-wrapper").hide();
if (textStatus === 'success') { if (textStatus === 'success') {
$(".fbrowser_content").show(); $(".fbrowser_content").show();
FileBrowser.postLoad(); FileBrowser.postLoad();
} }
}); });
}, },
// Initialize justified Gallery // Initialize justified Gallery
initGallery: function() { initGallery: function() {
$(".fbrowser.image .fbrowser-content-container").justifiedGallery({ $(".fbrowser.image .fbrowser-content-container").justifiedGallery({
'rowHeight': 80, 'rowHeight': 80,
'margins': 4, 'margins': 4,
'border': 0 'border': 0
}); });
} }
}; };