]> git.mxchange.org Git - friendica.git/blob - js/filebrowser.js
Set "hide" in noscrape
[friendica.git] / js / filebrowser.js
1 /**\r
2  * Filebrowser - Friendica Communications Server\r
3  *\r
4  * Copyright (c) 2010-2015 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  *      Dialog.doImageBrowser(eventname, id);\r
17  *\r
18  * or\r
19  *\r
20  *      Dialog.doFileBrowser(eventname, id);\r
21  *\r
22  * where:\r
23  *\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  * <type> will be one of "image" or "file", and the event handler will\r
33  * get the following params:\r
34  *\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
38  *\r
39  * example:\r
40  *\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
44  *\r
45  *              // setup event handler to get user selection\r
46  *              $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {\r
47  *                      // close colorbox\r
48  *                      $.colorbox.close();\r
49  *                      // replace textxarea text with bbcode\r
50  *                      $(id).value = bbcode;\r
51  *              });\r
52  **/\r
53 \r
54 var FileBrowser = {\r
55         nickname : "",\r
56         type : "",\r
57         event: "",\r
58         id : null,\r
59 \r
60         init: function(nickname, type) {\r
61                 FileBrowser.nickname = nickname;\r
62                 FileBrowser.type = type;\r
63                 FileBrowser.event = "fbrowser."+type;\r
64                 if (location['hash']!=="") {\r
65                         var h = location['hash'].replace("#","");\r
66                         FileBrowser.event = FileBrowser.event + "." + h.split("-")[0];\r
67                         FileBrowser.id = h.split("-")[1];\r
68                 }\r
69 \r
70                 console.log("FileBrowser:", nickname, type,FileBrowser.event, FileBrowser.id );\r
71 \r
72                 $(".error a.close").on("click", function(e) {\r
73                         e.preventDefault();\r
74                         $(".error").addClass("hidden");\r
75                 });\r
76 \r
77                 $(".folders a, .path a").on("click", function(e){\r
78                         e.preventDefault();\r
79                         var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=minimal" + location['hash'];\r
80                         location.href = url;\r
81                 });\r
82 \r
83                 $(".photo-album-photo-link").on('click', function(e){\r
84                         e.preventDefault();\r
85 \r
86                         var embed = "";\r
87                         if (FileBrowser.type == "image") {\r
88                                 embed = "[url="+this.dataset.link+"][img]"+this.dataset.img+"[/img][/url]";\r
89                         }\r
90                         if (FileBrowser.type=="file") {\r
91                                 // attachment links are "baseurl/attach/id"; we need id\r
92                                 embed = "[attachment]"+this.dataset.link.split("/").pop()+"[/attachment]";\r
93                         }\r
94                         console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);\r
95                         parent.$("body").trigger(FileBrowser.event, [\r
96                                 this.dataset.filename,\r
97                                 embed,\r
98                                 FileBrowser.id\r
99                         ]);\r
100 \r
101                 });\r
102 \r
103                 if ($("#upload-image").length)\r
104                         var image_uploader = new window.AjaxUpload(\r
105                                 'upload-image',\r
106                                 { action: 'wall_upload/'+FileBrowser.nickname+'?response=json',\r
107                                         name: 'userfile',\r
108                                         responseType: 'json',\r
109                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },\r
110                                         onComplete: function(file,response) {\r
111                                                 if (response['error']!= undefined) {\r
112                                                         $(".error span").html(response['error']);\r
113                                                         $(".error").removeClass('hidden');\r
114                                                         $('#profile-rotator').hide();\r
115                                                         return;\r
116                                                 }\r
117                                                 location = baseurl + "/fbrowser/image/?mode=minimal"+location['hash'];\r
118                                                 location.reload(true);\r
119                                         }\r
120                                 }\r
121                         );\r
122 \r
123                 if ($("#upload-file").length)\r
124                         var file_uploader = new window.AjaxUpload(\r
125                                 'upload-file',\r
126                                 { action: 'wall_attach/'+FileBrowser.nickname+'?response=json',\r
127                                         name: 'userfile',\r
128                                         onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },\r
129                                         onComplete: function(file,response) {\r
130                                                 if (response['error']!= undefined) {\r
131                                                         $(".error span").html(response['error']);\r
132                                                         $(".error").removeClass('hidden');\r
133                                                         $('#profile-rotator').hide();\r
134                                                         return;\r
135                                                 }\r
136                                                 location = baseurl + "/fbrowser/file/?mode=minimal"+location['hash'];\r
137                                                 location.reload(true);\r
138                                         }\r
139                                 }\r
140                 );\r
141         }\r
142 };\r
143 \r