2 * Filebrowser - Friendica Communications Server
\r
4 * Copyright (c) 2010-2015 the Friendica Project
\r
6 * This program is free software: you can redistribute it and/or modify
\r
7 * it under the terms of the GNU Affero General Public License as published by
\r
8 * the Free Software Foundation, either version 3 of the License, or
\r
9 * (at your option) any later version.
\r
11 * This code handle user interaction for image/file upload/browser dialog.
\r
12 * Is loaded from filebrowser_plain.tpl
\r
14 * To load filebrowser in colorbox, call
\r
16 * Dialog.doImageBrowser(eventname, id);
\r
20 * Dialog.doFileBrowser(eventname, id);
\r
24 * eventname: event name to catch return value
\r
25 * id: id returned to event handler
\r
27 * When user select an item, an event in fired in parent page, on body element
\r
28 * The event is named
\r
30 * fbrowser.<type>.[<eventname>]
\r
32 * <type> will be one of "image" or "file", and the event handler will
\r
33 * get the following params:
\r
35 * filemane: filename of item choosed by user
\r
36 * embed: bbcode to embed element into posts
\r
37 * id: id from caller code
\r
41 * // open dialog for select an image for a textarea with id "myeditor"
\r
42 * var id="myeditor";
\r
43 * Dialog.doImageBrowser("example", id);
\r
45 * // setup event handler to get user selection
\r
46 * $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {
\r
48 * $.colorbox.close();
\r
49 * // replace textxarea text with bbcode
\r
50 * $(id).value = bbcode;
\r
58 * This is a modified version to work with
\r
59 * the frio theme.and bootstrap modals
\r
61 * The origninal file is under:
\r
73 init: function(nickname, type, hash) {
\r
74 FileBrowser.nickname = nickname;
\r
75 FileBrowser.type = type;
\r
76 FileBrowser.event = "fbrowser."+type;
\r
79 var h = hash.replace("#","");
\r
80 FileBrowser.event = FileBrowser.event + "." + h.split("-")[0];
\r
81 FileBrowser.id = h.split("-")[1];
\r
84 console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id );
\r
86 $(".error a.close").on("click", function(e) {
\r
88 $(".error").addClass("hidden");
\r
91 $(".folders a, .path a").on("click", function(e){
\r
93 var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=modal"+ location['hash'];
\r
95 // load new content to modal
\r
96 $('.modal-body').load(url,function(){
\r
98 FileBrowser.init(nickname, type, hash);
\r
103 $(".photo-album-photo-link").on('click', function(e){
\r
104 e.preventDefault();
\r
107 if (FileBrowser.type == "image") {
\r
108 embed = "[url="+this.dataset.link+"][img]"+this.dataset.img+"[/img][/url]";
\r
110 if (FileBrowser.type=="file") {
\r
111 // attachment links are "baseurl/attach/id"; we need id
\r
112 embed = "[attachment]"+this.dataset.link.split("/").pop()+"[/attachment]";
\r
114 console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);
\r
115 parent.$("body").trigger(FileBrowser.event, [
\r
116 this.dataset.filename,
\r
122 $('#modal').modal('hide');
\r
124 $("#comment-edit-text-" + FileBrowser.id).empty();
\r
125 commentExpand(FileBrowser.id);
\r
126 //$("#comment-edit-text-558").empty();
\r
131 if ($("#upload-image").length)
\r
132 var image_uploader = new window.AjaxUpload(
\r
134 { action: 'wall_upload/'+FileBrowser.nickname+'?response=json',
\r
136 responseType: 'json',
\r
137 onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },
\r
138 onComplete: function(file,response) {
\r
139 if (response['error']!= undefined) {
\r
140 $(".error span").html(response['error']);
\r
141 $(".error").removeClass('hidden');
\r
142 $('#profile-rotator').hide();
\r
145 location = baseurl + "/fbrowser/image/?mode=minimal"+location['hash'];
\r
146 location.reload(true);
\r
151 if ($("#upload-file").length)
\r
152 var file_uploader = new window.AjaxUpload(
\r
154 { action: 'wall_attach/'+FileBrowser.nickname+'?response=json',
\r
156 onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },
\r
157 onComplete: function(file,response) {
\r
158 if (response['error']!= undefined) {
\r
159 $(".error span").html(response['error']);
\r
160 $(".error").removeClass('hidden');
\r
161 $('#profile-rotator').hide();
\r
164 location = baseurl + "/fbrowser/file/?mode=minimal"+location['hash'];
\r
165 location.reload(true);
\r