]> git.mxchange.org Git - friendica.git/commitdiff
Convert filebrowser.js to unix format
authorMichael <heluecht@pirati.ca>
Mon, 29 Jul 2019 20:41:19 +0000 (20:41 +0000)
committerMichael <heluecht@pirati.ca>
Mon, 29 Jul 2019 20:41:19 +0000 (20:41 +0000)
view/theme/frio/js/filebrowser.js

index 16d60b61d1014585c781a99a47f16a61b624f978..c036d181753e2d35910f4595d15090c0bb23b11d 100644 (file)
-/**\r
- * Filebrowser - Friendica Communications Server\r
- *\r
- * Copyright (c) 2010-2015 the Friendica Project\r
- *\r
- * This program is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU Affero General Public License as published by\r
- * the Free Software Foundation, either version 3 of the License, or\r
- * (at your option) any later version.\r
- *\r
- * This code handle user interaction for image/file upload/browser dialog.\r
- * Is loaded from filebrowser_plain.tpl\r
- *\r
- * To load filebrowser in colorbox, call\r
- *\r
- *      Dialog.doImageBrowser(eventname, id);\r
- *\r
- * or\r
- *\r
- *      Dialog.doFileBrowser(eventname, id);\r
- *\r
- * where:\r
- *\r
- *             eventname: event name to catch return value\r
- *             id: id returned to event handler\r
- *\r
- * When user select an item, an event in fired in parent page, on body element\r
- * The event is named\r
- *\r
- *             fbrowser.<type>.[<eventname>]\r
- *\r
- * <type> will be one of "image" or "file", and the event handler will\r
- * get the following params:\r
- *\r
- *             filemane: filename of item choosed by user\r
- *             embed: bbcode to embed element into posts\r
- *             id: id from caller code\r
- *\r
- * example:\r
- *\r
- *             // open dialog for select an image for a textarea with id "myeditor"\r
- *             var id="myeditor";\r
- *             Dialog.doImageBrowser("example", id);\r
- *\r
- *             // setup event handler to get user selection\r
- *             $("body").on("fbrowser.image.example", function(event, filename, bbcode, id) {\r
- *                     // close colorbox\r
- *                     $.colorbox.close();\r
- *                     // replace textxarea text with bbcode\r
- *                     $(id).value = bbcode;\r
- *             });\r
- **/\r
-\r
-\r
-/*\r
- * IMPORTANT\r
- *\r
- *  This is a modified version to work with\r
- *  the frio theme.and bootstrap modals\r
- *\r
- *  The origninal file is under:\r
- *  js/filebrowser.js\r
- *\r
- */\r
-\r
-\r
-var FileBrowser = {\r
-       nickname : "",\r
-       type : "",\r
-       event: "",\r
-       folder: "",\r
-       id : null,\r
-\r
-       init: function(nickname, type, hash) {\r
-               FileBrowser.nickname = nickname;\r
-               FileBrowser.type = type;\r
-               FileBrowser.event = "fbrowser."+type;\r
-\r
-               if (hash!=="") {\r
-                       var h = hash.replace("#","");\r
-                       var destination = h.split("-")[0];\r
-                       FileBrowser.id = h.split("-")[1];\r
-                       FileBrowser.event = FileBrowser.event + "." + destination;\r
-                       if (destination === "comment") {\r
-                               // Get the comment textimput field\r
-                               var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id);\r
-                       }\r
-               };\r
-\r
-               console.log("FileBrowser: " + nickname,  type, FileBrowser.event, FileBrowser.id);\r
-\r
-               FileBrowser.postLoad();\r
-\r
-               $(".error .close").on("click", function(e) {\r
-                       e.preventDefault();\r
-                       $(".error").addClass("hidden");\r
-               });\r
-\r
-               // Click on album link\r
-               $(".fbrowser").on("click", ".folders a, .path a", function(e) {\r
-                       e.preventDefault();\r
-                       var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none&theme=frio";\r
-                       FileBrowser.folder = this.dataset.folder;\r
-\r
-                       FileBrowser.loadContent(url);\r
-               });\r
-\r
-               //Embed on click\r
-               $(".fbrowser").on('click', ".photo-album-photo-link", function(e) {\r
-                       e.preventDefault();\r
-\r
-                       var embed = "";\r
-                       if (FileBrowser.type === "image") {\r
-                               embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]";\r
-                       }\r
-                       if (FileBrowser.type === "file") {\r
-                               // attachment links are "baseurl/attach/id"; we need id\r
-                               embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]";\r
-                       }\r
-\r
-                       // Delete prefilled Text of the comment input\r
-                       // Note: not the best solution but function commentOpenUI don't\r
-                       // work as expected (we need a way to wait until commentOpenUI would be finished).\r
-                       // As for now we insert pieces of this function here\r
-                       if ((commentElm !== null) && (typeof commentElm !== "undefined")) {\r
-                               if (commentElm.value === "") {\r
-                                       $("#comment-edit-text-" + FileBrowser.id).addClass("comment-edit-text-full").removeClass("comment-edit-text-empty");\r
-                                       $("#comment-edit-submit-wrapper-" + FileBrowser.id).show();\r
-                                       $("#comment-edit-text-" + FileBrowser.id).attr('tabindex','9');\r
-                                       $("#comment-edit-submit-" + FileBrowser.id).attr('tabindex','10');\r
-                               }\r
-\r
-                       }\r
-\r
-                       console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);\r
-\r
-                       $("body").trigger(FileBrowser.event, [\r
-                               this.dataset.filename,\r
-                               embed,\r
-                               FileBrowser.id,\r
-                               this.dataset.img\r
-                       ]);\r
-\r
-                       // Close model\r
-                       $('#modal').modal('hide');\r
-                       // Update autosize for this textarea\r
-                       autosize.update($(".text-autosize"));\r
-               });\r
-\r
-               // EventListener for switching between image and file mode\r
-               $(".fbrowser").on('click', ".fbswitcher .btn", function(e) {\r
-                       e.preventDefault();\r
-                       FileBrowser.type = this.getAttribute("data-mode");\r
-                       $(".fbrowser").removeClass().addClass("fbrowser " + FileBrowser.type);\r
-                       url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio";\r
-\r
-                       FileBrowser.loadContent(url);\r
-               });\r
-       },\r
-\r
-       // Initialize the AjaxUpload for the upload buttons\r
-       uploadButtons: function() {\r
-               if ($("#upload-image").length) {\r
-                       // To get the albumname we need to convert it from hex\r
-                       var albumname = hex2bin(FileBrowser.folder);\r
-                       //AjaxUpload for images\r
-                       var image_uploader = new window.AjaxUpload(\r
-                               'upload-image',\r
-                               {       action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname,\r
-                                       name: 'userfile',\r
-                                       responseType: 'json',\r
-                                       onSubmit: function(file, ext) {\r
-                                               $(".fbrowser-content").hide();\r
-                                               $(".fbrowser .profile-rotator-wrapper").show();\r
-                                               $(".error").addClass('hidden');\r
-                                       },\r
-                                       onComplete: function(file,response) {\r
-                                               if (response['error'] != undefined) {\r
-                                                       $(".error span").html(response['error']);\r
-                                                       $(".error").removeClass('hidden');\r
-                                                       $(".fbrowser .profile-rotator-wrapper").hide();\r
-                                                       $(".fbrowser-content").show();\r
-                                                       return;\r
-                                               }\r
-\r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none&theme=frio";\r
-                                               // load new content to fbrowser window\r
-                                               FileBrowser.loadContent(url);\r
-                                       }\r
-                               }\r
-                       );\r
-               }\r
-\r
-               if ($("#upload-file").length) {\r
-                       //AjaxUpload for files\r
-                       var file_uploader = new window.AjaxUpload(\r
-                               'upload-file',\r
-                               {       action: 'wall_attach/' + FileBrowser.nickname + '?response=json',\r
-                                       name: 'userfile',\r
-                                       onSubmit: function(file, ext) {\r
-                                               $(".fbrowser-content").hide();\r
-                                               $(".fbrowser .profile-rotator-wrapper").show();\r
-                                               $(".error").addClass('hidden');\r
-                                       },\r
-                                       onComplete: function(file,response) {\r
-                                               if (response['error']!= undefined) {\r
-                                                       $(".error span").html(response['error']);\r
-                                                       $(".error").removeClass('hidden');\r
-                                                       $('#profile-rotator').hide();\r
-                                                       $(".fbrowser-content").show();\r
-                                                       return;\r
-                                               }\r
-\r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio";\r
-                                               // Load new content to fbrowser window\r
-                                               FileBrowser.loadContent(url);\r
-                                       }\r
-                               }\r
-                       );\r
-               }\r
-       },\r
-\r
-       // Stuff which should be executed if ne content was loaded\r
-       postLoad: function() {\r
-               FileBrowser.initGallery();\r
-               $(".fbrowser .fbswitcher .btn").removeClass("active");\r
-               $(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active");\r
-               // We need to add the AjaxUpload to the button\r
-               FileBrowser.uploadButtons();\r
-       },\r
-\r
-       // Load new content (e.g. change photo album)\r
-       loadContent: function(url) {\r
-               $(".fbrowser-content").hide();\r
-               $(".fbrowser .profile-rotator-wrapper").show();\r
-\r
-               // load new content to fbrowser window\r
-               $(".fbrowser").load(url, function(responseText, textStatus) {\r
-                       $(".profile-rotator-wrapper").hide();\r
-                       if (textStatus === 'success') {\r
-                               $(".fbrowser_content").show();\r
-                               FileBrowser.postLoad();\r
-                       }\r
-               });\r
-       },\r
-\r
-       // Initialize justified Gallery\r
-       initGallery: function() {\r
-               $(".fbrowser.image .fbrowser-content-container").justifiedGallery({\r
-                       'rowHeight': 80,\r
-                       'margins': 4,\r
-                       'border': 0\r
-               });\r
-       }\r
-};\r
+/**
+ * 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
+ *
+ *  This is a modified version to work with
+ *  the frio theme.and bootstrap modals
+ *
+ *  The origninal file is under:
+ *  js/filebrowser.js
+ *
+ */
+
+
+var FileBrowser = {
+       nickname : "",
+       type : "",
+       event: "",
+       folder: "",
+       id : null,
+
+       init: function(nickname, type, hash) {
+               FileBrowser.nickname = nickname;
+               FileBrowser.type = type;
+               FileBrowser.event = "fbrowser."+type;
+
+               if (hash!=="") {
+                       var h = hash.replace("#","");
+                       var destination = h.split("-")[0];
+                       FileBrowser.id = h.split("-")[1];
+                       FileBrowser.event = FileBrowser.event + "." + destination;
+                       if (destination === "comment") {
+                               // Get the comment textimput field
+                               var commentElm = document.getElementById("comment-edit-text-" + FileBrowser.id);
+                       }
+               };
+
+               console.log("FileBrowser: " + nickname,  type, FileBrowser.event, FileBrowser.id);
+
+               FileBrowser.postLoad();
+
+               $(".error .close").on("click", function(e) {
+                       e.preventDefault();
+                       $(".error").addClass("hidden");
+               });
+
+               // Click on album link
+               $(".fbrowser").on("click", ".folders a, .path a", function(e) {
+                       e.preventDefault();
+                       var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + this.dataset.folder + "?mode=none&theme=frio";
+                       FileBrowser.folder = this.dataset.folder;
+
+                       FileBrowser.loadContent(url);
+               });
+
+               //Embed on click
+               $(".fbrowser").on('click', ".photo-album-photo-link", function(e) {
+                       e.preventDefault();
+
+                       var embed = "";
+                       if (FileBrowser.type === "image") {
+                               embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]";
+                       }
+                       if (FileBrowser.type === "file") {
+                               // attachment links are "baseurl/attach/id"; we need id
+                               embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]";
+                       }
+
+                       // 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")) {
+                               if (commentElm.value === "") {
+                                       $("#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');
+                               }
+
+                       }
+
+                       console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);
+
+                       $("body").trigger(FileBrowser.event, [
+                               this.dataset.filename,
+                               embed,
+                               FileBrowser.id,
+                               this.dataset.img
+                       ]);
+
+                       // Close model
+                       $('#modal').modal('hide');
+                       // Update autosize for this textarea
+                       autosize.update($(".text-autosize"));
+               });
+
+               // 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&theme=frio";
+
+                       FileBrowser.loadContent(url);
+               });
+       },
+
+       // Initialize the AjaxUpload for the upload buttons
+       uploadButtons: function() {
+               if ($("#upload-image").length) {
+                       // To get the albumname we need to convert it from hex
+                       var albumname = hex2bin(FileBrowser.folder);
+                       //AjaxUpload for images
+                       var image_uploader = new window.AjaxUpload(
+                               'upload-image',
+                               {       action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname,
+                                       name: 'userfile',
+                                       responseType: 'json',
+                                       onSubmit: function(file, ext) {
+                                               $(".fbrowser-content").hide();
+                                               $(".fbrowser .profile-rotator-wrapper").show();
+                                               $(".error").addClass('hidden');
+                                       },
+                                       onComplete: function(file,response) {
+                                               if (response['error'] != undefined) {
+                                                       $(".error span").html(response['error']);
+                                                       $(".error").removeClass('hidden');
+                                                       $(".fbrowser .profile-rotator-wrapper").hide();
+                                                       $(".fbrowser-content").show();
+                                                       return;
+                                               }
+
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none&theme=frio";
+                                               // load new content to fbrowser window
+                                               FileBrowser.loadContent(url);
+                                       }
+                               }
+                       );
+               }
+
+               if ($("#upload-file").length) {
+                       //AjaxUpload for files
+                       var file_uploader = new window.AjaxUpload(
+                               'upload-file',
+                               {       action: 'wall_attach/' + FileBrowser.nickname + '?response=json',
+                                       name: 'userfile',
+                                       onSubmit: function(file, ext) {
+                                               $(".fbrowser-content").hide();
+                                               $(".fbrowser .profile-rotator-wrapper").show();
+                                               $(".error").addClass('hidden');
+                                       },
+                                       onComplete: function(file,response) {
+                                               if (response['error']!= undefined) {
+                                                       $(".error span").html(response['error']);
+                                                       $(".error").removeClass('hidden');
+                                                       $('#profile-rotator').hide();
+                                                       $(".fbrowser-content").show();
+                                                       return;
+                                               }
+
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none&theme=frio";
+                                               // Load new content to fbrowser window
+                                               FileBrowser.loadContent(url);
+                                       }
+                               }
+                       );
+               }
+       },
+
+       // Stuff which should be executed if ne content was loaded
+       postLoad: function() {
+               FileBrowser.initGallery();
+               $(".fbrowser .fbswitcher .btn").removeClass("active");
+               $(".fbrowser .fbswitcher [data-mode=" + FileBrowser.type + "]").addClass("active");
+               // We need to add the AjaxUpload to the button
+               FileBrowser.uploadButtons();
+       },
+
+       // Load new content (e.g. change photo album)
+       loadContent: function(url) {
+               $(".fbrowser-content").hide();
+               $(".fbrowser .profile-rotator-wrapper").show();
+
+               // load new content to fbrowser window
+               $(".fbrowser").load(url, function(responseText, textStatus) {
+                       $(".profile-rotator-wrapper").hide();
+                       if (textStatus === 'success') {
+                               $(".fbrowser_content").show();
+                               FileBrowser.postLoad();
+                       }
+               });
+       },
+
+       // Initialize justified Gallery
+       initGallery: function() {
+               $(".fbrowser.image .fbrowser-content-container").justifiedGallery({
+                       'rowHeight': 80,
+                       'margins': 4,
+                       'border': 0
+               });
+       }
+};