2 * Filebrowser - Friendica Communications Server
\r
4 * Copyright (c) 2010-2013 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 * $.colorbox({href: ulr, iframe:true,innerWidth:'500px',innerHeight:'400px'})
\r
20 * <baseurl>/fbrowser/<type>/?mode=minimal[#<eventname>-<id>]
\r
22 * baseurl: baseurl from friendica
\r
23 * type: one of "image", "file"
\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
34 * filemane: filename of item choosed by user
\r
35 * embed: bbcode to embed element into posts
\r
40 * // open dialog for select an image for a textarea with id "myeditor"
\r
41 * var id="myeditor";
\r
42 * $.colorbox({href: baseurl + "/fbrowser/image/?mode=minimal#example-"+id, iframe:true,innerWidth:'500px',innerHeight:'400px'})
\r
44 * // setup event handler to get user selection
\r
45 * $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {
\r
47 * $.colorbox.close();
\r
48 * // replace textxarea text with bbcode
\r
49 * $(id).value = bbcode;
\r
59 init: function(nickname, type) {
\r
60 FileBrowser.nickname = nickname;
\r
61 FileBrowser.type = type;
\r
62 FileBrowser.event = "fbrowser."+type;
\r
63 if (location['hash']!=="") {
\r
64 var h = location['hash'].replace("#","");
\r
65 FileBrowser.event = FileBrowser.event + "." + h.split("-")[0];
\r
66 FileBrowser.id = h.split("-")[1];
\r
69 console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id );
\r
71 $(".error a.close").on("click", function(e) {
\r
73 $(".error").addClass("hidden");
\r
76 $(".folders a, .path a").on("click", function(e){
\r
78 var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=minimal" + location['hash'];
\r
79 location.href = url;
\r
82 $(".photo-album-photo-link").on('click', function(e){
\r
86 if (FileBrowser.type == "image") {
\r
87 embed = "[url="+this.dataset.link+"][img]"+this.dataset.img+"[/img][/url]";
\r
89 if (FileBrowser.type=="file") {
\r
90 // attachment links are "baseurl/attach/id"; we need id
\r
91 embed = "[attachment]"+this.dataset.link.split("/").pop()+"[/attachment]";
\r
93 console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);
\r
94 parent.$("body").trigger(FileBrowser.event, [
\r
95 this.dataset.filename,
\r
102 if ($("#upload-image").length)
\r
103 var image_uploader = new window.AjaxUpload(
\r
105 { action: 'wall_upload/'+FileBrowser.nickname+'?response=json',
\r
107 responseType: 'json',
\r
108 onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },
\r
109 onComplete: function(file,response) {
\r
110 if (response['error']!= undefined) {
\r
111 $(".error span").html(response['error']);
\r
112 $(".error").removeClass('hidden');
\r
113 $('#profile-rotator').hide();
\r
116 location = baseurl + "/fbrowser/image/?mode=minimal"+location['hash'];
\r
117 location.reload(true);
\r
122 if ($("#upload-file").length)
\r
123 var file_uploader = new window.AjaxUpload(
\r
125 { action: 'wall_attach/'+FileBrowser.nickname+'?response=json',
\r
127 onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },
\r
128 onComplete: function(file,response) {
\r
129 if (response['error']!= undefined) {
\r
130 $(".error span").html(response['error']);
\r
131 $(".error").removeClass('hidden');
\r
132 $('#profile-rotator').hide();
\r
135 location = baseurl + "/fbrowser/file/?mode=minimal"+location['hash'];
\r
136 location.reload(true);
\r