2016-03-28 16:29:05 +02:00
|
|
|
/**
|
|
|
|
* Filebrowser - Friendica Communications Server
|
|
|
|
*
|
|
|
|
* Copyright (c) 2010-2015 the Friendica Project
|
|
|
|
*
|
|
|
|
* 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:
|
|
|
|
*
|
|
|
|
* filemane: filename of item choosed by user
|
|
|
|
* 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();
|
|
|
|
* // replace textxarea text with bbcode
|
|
|
|
* $(id).value = bbcode;
|
|
|
|
* });
|
|
|
|
**/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* IMPORTANT
|
2017-01-07 15:49:13 +01:00
|
|
|
*
|
|
|
|
* This is a modified version to work with
|
2016-03-28 16:29:05 +02:00
|
|
|
* the frio theme.and bootstrap modals
|
2017-01-07 15:49:13 +01:00
|
|
|
*
|
2016-03-28 16:29:05 +02:00
|
|
|
* The origninal file is under:
|
|
|
|
* js/filebrowser.js
|
2017-01-07 15:49:13 +01:00
|
|
|
*
|
2016-03-28 16:29:05 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
var FileBrowser = {
|
|
|
|
nickname : "",
|
|
|
|
type : "",
|
|
|
|
event: "",
|
2017-03-21 23:08:37 +01:00
|
|
|
folder: "",
|
2016-03-28 16:29:05 +02:00
|
|
|
id : null,
|
|
|
|
|
|
|
|
init: function(nickname, type, hash) {
|
|
|
|
FileBrowser.nickname = nickname;
|
|
|
|
FileBrowser.type = type;
|
|
|
|
FileBrowser.event = "fbrowser."+type;
|
|
|
|
|
|
|
|
if (hash!=="") {
|
|
|
|
var h = hash.replace("#","");
|
2016-05-09 21:08:11 +02:00
|
|
|
var destination = h.split("-")[0];
|
2016-03-28 16:29:05 +02:00
|
|
|
FileBrowser.id = h.split("-")[1];
|
2016-05-09 21:08:11 +02:00
|
|
|
FileBrowser.event = FileBrowser.event + "." + destination;
|
|
|
|
if (destination == "comment") {
|
2017-03-21 03:35:25 +01:00
|
|
|
// Get the comment textimput field
|
2016-05-09 21:08:11 +02:00
|
|
|
var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id);
|
|
|
|
}
|
2016-03-28 16:29:05 +02:00
|
|
|
};
|
|
|
|
|
2017-03-25 19:12:16 +01:00
|
|
|
console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id);
|
2016-03-28 16:29:05 +02:00
|
|
|
|
2017-03-21 03:35:25 +01:00
|
|
|
FileBrowser.postLoad();
|
2017-03-20 22:45:24 +01:00
|
|
|
|
2017-03-18 01:26:40 +01:00
|
|
|
$(".error .close").on("click", function(e) {
|
2016-03-28 16:29:05 +02:00
|
|
|
e.preventDefault();
|
|
|
|
$(".error").addClass("hidden");
|
|
|
|
});
|
|
|
|
|
2017-03-20 22:45:24 +01:00
|
|
|
// Click on album link
|
|
|
|
$(".fbrowser").on("click", ".folders a, .path a", function(e) {
|
2016-03-28 16:29:05 +02:00
|
|
|
e.preventDefault();
|
2016-05-15 13:41:37 +02:00
|
|
|
var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none";
|
2017-03-21 23:08:37 +01:00
|
|
|
FileBrowser.folder = this.dataset.folder;
|
2017-03-21 03:35:25 +01:00
|
|
|
|
|
|
|
FileBrowser.loadContent(url);
|
2016-03-28 16:29:05 +02:00
|
|
|
});
|
|
|
|
|
2017-03-21 03:35:25 +01:00
|
|
|
//Embed on click
|
2017-03-20 22:45:24 +01:00
|
|
|
$(".fbrowser").on('click', ".photo-album-photo-link", function(e) {
|
2016-03-28 16:29:05 +02:00
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
var embed = "";
|
|
|
|
if (FileBrowser.type == "image") {
|
2017-03-25 19:12:16 +01:00
|
|
|
embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]";
|
2016-03-28 16:29:05 +02:00
|
|
|
}
|
2017-03-21 03:35:25 +01:00
|
|
|
if (FileBrowser.type == "file") {
|
2016-03-28 16:29:05 +02:00
|
|
|
// attachment links are "baseurl/attach/id"; we need id
|
2017-03-25 19:12:16 +01:00
|
|
|
embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]";
|
2016-03-28 16:29:05 +02:00
|
|
|
}
|
2016-05-09 21:08:11 +02: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
|
|
|
|
if ((commentElm !== null) && (typeof commentElm !== "undefined")) {
|
2017-01-07 16:13:55 +01:00
|
|
|
if (commentElm.value == "") {
|
2016-05-09 21:08:11 +02:00
|
|
|
$("#comment-edit-text-" + FileBrowser.id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");
|
|
|
|
$("#comment-edit-submit-wrapper-" + FileBrowser.id).show();
|
|
|
|
$("#comment-edit-text-" + FileBrowser.id).attr('tabindex','9');
|
|
|
|
$("#comment-edit-submit-" + FileBrowser.id).attr('tabindex','10');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-03-25 19:12:16 +01:00
|
|
|
|
2016-03-28 16:29:05 +02:00
|
|
|
console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);
|
2017-03-25 19:12:16 +01:00
|
|
|
|
2016-03-28 16:29:05 +02:00
|
|
|
parent.$("body").trigger(FileBrowser.event, [
|
|
|
|
this.dataset.filename,
|
|
|
|
embed,
|
|
|
|
FileBrowser.id,
|
2017-03-21 23:08:37 +01:00
|
|
|
this.dataset.img
|
2016-03-28 16:29:05 +02:00
|
|
|
]);
|
|
|
|
|
2017-03-21 03:35:25 +01:00
|
|
|
// Close model
|
2016-03-28 16:29:05 +02:00
|
|
|
$('#modal').modal('hide');
|
2017-03-21 03:35:25 +01:00
|
|
|
// Update autosize for this textarea
|
2016-08-23 16:48:13 +02:00
|
|
|
autosize.update($(".text-autosize"));
|
2016-03-28 16:29:05 +02:00
|
|
|
});
|
2017-03-21 03:35:25 +01:00
|
|
|
|
|
|
|
// EventListener for switching between image and file mode
|
|
|
|
$(".fbrowser").on('click', ".fbswitcher .btn", function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
FileBrowser.type = this.getAttribute("data-mode");
|
|
|
|
$(".fbrowser").removeClass().addClass("fbrowser " + FileBrowser.type);
|
|
|
|
url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none";
|
|
|
|
|
|
|
|
FileBrowser.loadContent(url);
|
|
|
|
});
|
2017-03-20 22:45:24 +01:00
|
|
|
},
|
2016-03-28 16:29:05 +02:00
|
|
|
|
2017-03-21 03:35:25 +01:00
|
|
|
// Initialize the AjaxUpload for the upload buttons
|
2017-03-20 22:45:24 +01:00
|
|
|
uploadButtons: function() {
|
|
|
|
if ($("#upload-image").length) {
|
2017-03-21 23:08:37 +01:00
|
|
|
// To get the albumname we need to convert it from hex
|
|
|
|
var albumname = hex2bin(FileBrowser.folder);
|
|
|
|
//AjaxUpload for images
|
2016-03-28 16:29:05 +02:00
|
|
|
var image_uploader = new window.AjaxUpload(
|
|
|
|
'upload-image',
|
2017-03-25 19:12:16 +01:00
|
|
|
{ action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname,
|
2016-03-28 16:29:05 +02:00
|
|
|
name: 'userfile',
|
|
|
|
responseType: 'json',
|
2017-03-25 19:12:16 +01:00
|
|
|
onSubmit: function(file, ext) {
|
2017-03-20 22:45:24 +01:00
|
|
|
$(".fbrowser-content").hide();
|
|
|
|
$(".fbrowser .profile-rotator-wrapper").show();
|
|
|
|
$(".error").addClass('hidden');
|
|
|
|
},
|
2016-03-28 16:29:05 +02:00
|
|
|
onComplete: function(file,response) {
|
2017-03-25 19:12:16 +01:00
|
|
|
if (response['error'] != undefined) {
|
2016-03-28 16:29:05 +02:00
|
|
|
$(".error span").html(response['error']);
|
|
|
|
$(".error").removeClass('hidden');
|
2017-03-20 22:45:24 +01:00
|
|
|
$(".fbrowser .profile-rotator-wrapper").hide();
|
2016-03-28 16:29:05 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-03-20 22:45:24 +01:00
|
|
|
|
2016-05-15 13:41:37 +02:00
|
|
|
// location = baseurl + "/fbrowser/image/?mode=none"+location['hash'];
|
2016-05-09 21:08:11 +02:00
|
|
|
// location.reload(true);
|
|
|
|
|
2017-03-21 23:08:37 +01:00
|
|
|
var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none";
|
2016-05-09 21:08:11 +02:00
|
|
|
// load new content to fbrowser window
|
2017-03-21 03:35:25 +01:00
|
|
|
FileBrowser.loadContent(url);
|
2016-03-28 16:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2017-03-20 22:45:24 +01:00
|
|
|
}
|
2016-03-28 16:29:05 +02:00
|
|
|
|
2017-03-20 22:45:24 +01:00
|
|
|
if ($("#upload-file").length) {
|
2017-03-21 23:08:37 +01:00
|
|
|
//AjaxUpload for files
|
2016-03-28 16:29:05 +02:00
|
|
|
var file_uploader = new window.AjaxUpload(
|
|
|
|
'upload-file',
|
2017-03-21 23:08:37 +01:00
|
|
|
{ action: 'wall_attach/' + FileBrowser.nickname + '?response=json',
|
2016-03-28 16:29:05 +02:00
|
|
|
name: 'userfile',
|
2017-03-25 19:12:16 +01:00
|
|
|
onSubmit: function(file, ext) {
|
2017-03-20 22:45:24 +01:00
|
|
|
$(".fbrowser-content").hide();
|
|
|
|
$(".fbrowser .profile-rotator-wrapper").show();
|
|
|
|
$(".error").addClass('hidden');
|
|
|
|
},
|
2016-03-28 16:29:05 +02:00
|
|
|
onComplete: function(file,response) {
|
|
|
|
if (response['error']!= undefined) {
|
|
|
|
$(".error span").html(response['error']);
|
|
|
|
$(".error").removeClass('hidden');
|
|
|
|
$('#profile-rotator').hide();
|
|
|
|
return;
|
|
|
|
}
|
2017-03-20 22:45:24 +01:00
|
|
|
|
2016-05-15 13:41:37 +02:00
|
|
|
// location = baseurl + "/fbrowser/file/?mode=none"+location['hash'];
|
2016-05-09 21:08:11 +02:00
|
|
|
// location.reload(true);
|
|
|
|
|
2017-03-21 23:08:37 +01:00
|
|
|
var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none";
|
2017-03-21 03:35:25 +01:00
|
|
|
// Load new content to fbrowser window
|
2017-03-21 23:08:37 +01:00
|
|
|
FileBrowser.loadContent(url);
|
2016-03-28 16:29:05 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-20 22:45:24 +01:00
|
|
|
);
|
|
|
|
}
|
2017-03-21 03:35:25 +01:00
|
|
|
},
|
|
|
|
|
2017-03-21 23:08:37 +01:00
|
|
|
// Stuff which should be executed if ne content was loaded
|
2017-03-21 03:35:25 +01:00
|
|
|
postLoad: function() {
|
2017-03-21 20:39:31 +01:00
|
|
|
FileBrowser.initGallery();
|
2017-03-21 03:35:25 +01:00
|
|
|
$(".fbrowser .fbswitcher .btn").removeClass("active");
|
|
|
|
$(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active");
|
|
|
|
// We need to add the AjaxUpload to the button
|
|
|
|
FileBrowser.uploadButtons();
|
2017-03-21 20:39:31 +01:00
|
|
|
|
2017-03-21 03:35:25 +01:00
|
|
|
},
|
|
|
|
|
2017-03-21 23:08:37 +01:00
|
|
|
// Load new content (e.g. change photo album)
|
2017-03-21 03:35:25 +01:00
|
|
|
loadContent: function(url) {
|
|
|
|
$(".fbrowser-content").hide();
|
|
|
|
$(".fbrowser .profile-rotator-wrapper").show();
|
|
|
|
|
|
|
|
// load new content to fbrowser window
|
2017-03-25 19:12:16 +01:00
|
|
|
$(".fbrowser").load(url, function(responseText, textStatus) {
|
2017-03-21 03:35:25 +01:00
|
|
|
$(".profile-rotator-wrapper").hide();
|
|
|
|
if (textStatus === 'success') {
|
|
|
|
$(".fbrowser_content").show();
|
|
|
|
FileBrowser.postLoad();
|
|
|
|
}
|
|
|
|
});
|
2017-03-21 20:39:31 +01:00
|
|
|
},
|
|
|
|
|
2017-03-21 23:08:37 +01:00
|
|
|
// Initialize justified Gallery
|
2017-03-21 20:39:31 +01:00
|
|
|
initGallery: function() {
|
|
|
|
$(".fbrowser.image .fbrowser-content-container").justifiedGallery({
|
|
|
|
'rowHeight': 80,
|
2017-03-26 14:00:00 +02:00
|
|
|
'margins': 2,
|
2017-03-21 20:39:31 +01:00
|
|
|
'border': 0
|
|
|
|
});
|
2017-03-20 22:45:24 +01:00
|
|
|
}
|
2016-03-28 16:29:05 +02:00
|
|
|
};
|