]> git.mxchange.org Git - friendica.git/blob - js/filebrowser.js
fix folder links in filebrowser dialog
[friendica.git] / js / filebrowser.js
1 /**\r
2  * Filebrowser - Friendica Communications Server\r
3  * \r
4  * Copyright (c) 2010-2013 the Friendica Project\r
5  *\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
10  *\r
11  * This code handle user interaction for image/file upload/browser dialog.\r
12  * Is loaded from filebrowser_plain.tpl\r
13  *\r
14  * To load filebrowser in colorbox, call\r
15  *\r
16  *     $.colorbox({href: ulr, iframe:true,innerWidth:'500px',innerHeight:'400px'})\r
17  *\r
18  * where url is:\r
19  *\r
20  *              <baseurl>/fbrowser/<type>/?mode=minimal[#<eventname>-<id>]\r
21  *\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
26  *\r
27  *      When user select an item, an event in fired in parent page, on body element\r
28  *      The event is named\r
29  *\r
30  *              fbrowser.<type>.[<eventname>]\r
31  *              \r
32  *      with params:\r
33  *\r
34  *              filemane: filename of item choosed by user\r
35  *              embed: bbcode to embed element into posts\r
36  *              id: id from url\r
37  *\r
38  *  example:\r
39  *\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
43  *\r
44  *              // setup event handler to get user selection\r
45  *              $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {\r
46  *                      // close colorbox\r
47  *                      $.colorbox.close();\r
48  *                      // replace textxarea text with bbcode\r
49  *                      $(id).value = bbcode;\r
50  *              });\r
51  **/\r
52  \r
53 var FileBrowser = {\r
54         nickname : "",\r
55         type : "",\r
56         event: "",\r
57         id : null,\r
58         \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
67                 }\r
68                 \r
69                 console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id );\r
70                 \r
71                 $(".folders a, .path a").on("click", function(e){\r
72                         e.preventDefault();\r
73                         var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=minimal" + location['hash'];\r
74                         location.href = url;\r
75                 });\r
76                 \r
77                 $(".photo-album-photo-link").on('click', function(e){\r
78                         e.preventDefault();\r
79                         \r
80                         var embed = "";\r
81                         if (FileBrowser.type == "image") {\r
82                                 embed = "[url="+this.dataset.link+"][img]"+this.dataset.img+"[/img][/url]";\r
83                         }\r
84                         if (FileBrowser.type=="file") {\r
85                                 // attachment links are "baseurl/attach/id"; we need id\r
86                                 embed = "[attachment]"+this.dataset.link.split("/").pop()+"[/attachment]";\r
87                         }\r
88                         console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);\r
89                         parent.$("body").trigger(FileBrowser.event, [\r
90                                 this.dataset.filename,\r
91                                 embed,\r
92                                 FileBrowser.id\r
93                         ]);\r
94                         \r
95                 });\r
96                 \r
97                 if ($("#upload-image").length)\r
98                         var image_uploader = new window.AjaxUpload(\r
99                                 'upload-image',\r
100                                 { action: 'wall_upload/'+FileBrowser.nickname,\r
101                                         name: 'userfile',\r
102                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },\r
103                                         onComplete: function(file,response) {\r
104                                                 location = baseurl + "/fbrowser/image/?mode=minimal"+location['hash'];\r
105                                                 location.reload(true);\r
106                                         }                                \r
107                                 }\r
108                         );\r
109 \r
110                 if ($("#upload-file").length)\r
111                         var file_uploader = new window.AjaxUpload(\r
112                                 'upload-file',\r
113                                 { action: 'wall_attach/'+FileBrowser.nickname,\r
114                                         name: 'userfile',\r
115                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); },\r
116                                         onComplete: function(file,response) {\r
117                                                 location = baseurl + "/fbrowser/file/?mode=minimal"+location['hash'];\r
118                                                 location.reload(true);                          }                                \r
119                                 }\r
120                 );\r
121         }\r
122 };\r
123 \r