]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frio/js/filebrowser.js
Merge pull request #4929 from annando/diaspora-rework
[friendica.git] / view / theme / frio / js / filebrowser.js
index 0fe501d548906379693703ac1e47b286b5f41139..270172072d5ac72073a58f6f80e353a877199114 100644 (file)
 \r
 /*\r
  * IMPORTANT\r
- * \r
- *  This is a modified version to work with \r
+ *\r
+ *  This is a modified version to work with\r
  *  the frio theme.and bootstrap modals\r
- *  \r
+ *\r
  *  The origninal file is under:\r
  *  js/filebrowser.js\r
- * \r
+ *\r
  */\r
 \r
 \r
@@ -68,6 +68,7 @@ var FileBrowser = {
        nickname : "",\r
        type : "",\r
        event: "",\r
+       folder: "",\r
        id : null,\r
 \r
        init: function(nickname, type, hash) {\r
@@ -80,40 +81,41 @@ var FileBrowser = {
                        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
+                       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
+               console.log("FileBrowser: " + nickname,  type, FileBrowser.event, FileBrowser.id);\r
+\r
+               FileBrowser.postLoad();\r
 \r
-               $(".error a.close").on("click", function(e) {\r
+               $(".error .close").on("click", function(e) {\r
                        e.preventDefault();\r
                        $(".error").addClass("hidden");\r
                });\r
 \r
-               $(".folders a, .path a").on("click", function(e){\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";\r
+                       FileBrowser.folder = this.dataset.folder;\r
 \r
-                       // load new content to fbrowser window\r
-                       $(".fbrowser").load(url,function(){\r
-                               $(function() {FileBrowser.init(nickname, type, hash);});\r
-                       });\r
+                       FileBrowser.loadContent(url);\r
                });\r
 \r
-               //embed on click\r
-               $(".photo-album-photo-link").on('click', function(e){\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
+                       if (FileBrowser.type === "image") {\r
+                               embed = "[url=" + this.dataset.link + "][img]" + this.dataset.img + "[/img][/url]";\r
                        }\r
-                       if (FileBrowser.type=="file") {\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
+                               embed = "[attachment]" + this.dataset.link.split("/").pop() + "[/attachment]";\r
                        }\r
 \r
                        // Delete prefilled Text of the comment input\r
@@ -121,8 +123,7 @@ var FileBrowser = {
                        // 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 == aStr.comment){\r
-                                       commentElm.value = "";\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
@@ -130,7 +131,9 @@ var FileBrowser = {
                                }\r
 \r
                        }\r
+\r
                        console.log(FileBrowser.event, this.dataset.filename, embed, FileBrowser.id);\r
+\r
                        parent.$("body").trigger(FileBrowser.event, [\r
                                this.dataset.filename,\r
                                embed,\r
@@ -138,47 +141,69 @@ var FileBrowser = {
                                this.dataset.img\r
                        ]);\r
 \r
-                       // close model\r
+                       // Close model\r
                        $('#modal').modal('hide');\r
-//                     if (id!=="") {\r
-//                             commentExpand(FileBrowser.id);\r
-//                             //$("#comment-edit-text-558").empty();\r
-//                     };\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";\r
+\r
+                       FileBrowser.loadContent(url);\r
                });\r
+       },\r
 \r
-               if ($("#upload-image").length)\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',\r
+                               {       action: 'wall_upload/' + FileBrowser.nickname + '?response=json&album=' + albumname,\r
                                        name: 'userfile',\r
                                        responseType: 'json',\r
-                                       onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },\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
+                                               if (response['error'] != undefined) {\r
                                                        $(".error span").html(response['error']);\r
                                                        $(".error").removeClass('hidden');\r
-                                                       $('#profile-rotator').hide();\r
+                                                       $(".fbrowser .profile-rotator-wrapper").hide();\r
                                                        return;\r
                                                }\r
+\r
 //                                             location = baseurl + "/fbrowser/image/?mode=none"+location['hash'];\r
 //                                             location.reload(true);\r
 \r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"\r
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "/" + FileBrowser.folder + "?mode=none";\r
                                                // load new content to fbrowser window\r
-                                               $(".fbrowser").load(url,function(){\r
-                                                       $(function() {FileBrowser.init(nickname, type, hash);});\r
-                                               });\r
+                                               FileBrowser.loadContent(url);\r
                                        }\r
                                }\r
                        );\r
+               }\r
 \r
-               if ($("#upload-file").length)\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
+                               {       action: 'wall_attach/' + FileBrowser.nickname + '?response=json',\r
                                        name: 'userfile',\r
-                                       onSubmit: function(file,ext) { $('#profile-rotator').show(); $(".error").addClass('hidden'); },\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
@@ -186,17 +211,49 @@ var FileBrowser = {
                                                        $('#profile-rotator').hide();\r
                                                        return;\r
                                                }\r
+\r
 //                                             location = baseurl + "/fbrowser/file/?mode=none"+location['hash'];\r
 //                                             location.reload(true);\r
 \r
-                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none"\r
-                                               // load new content to fbrowser window\r
-                                               $(".fbrowser").load(url,function(){\r
-                                                       $(function() {FileBrowser.init(nickname, type, hash);});\r
-                                               });\r
+                                               var url = baseurl + "/fbrowser/" + FileBrowser.type + "?mode=none";\r
+                                               // Load new content to fbrowser window\r
+                                               FileBrowser.loadContent(url);\r
                                        }\r
                                }\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