]> git.mxchange.org Git - friendica.git/commitdiff
attachment preview: frio- initialize linkPreview on jot modal open (so we can use...
authorrabuzarus <trebor@central-unit>
Sat, 2 Feb 2019 02:12:36 +0000 (03:12 +0100)
committerrabuzarus <trebor@central-unit>
Sat, 2 Feb 2019 02:12:36 +0000 (03:12 +0100)
view/theme/frio/js/jot.js
view/theme/frio/js/modal.js
view/theme/frio/js/textedit.js
view/theme/frio/templates/jot-header.tpl

index 25db2382419d74c836e085c195ea194fc320e59c..08ed6f2215b0898028955b517a9bc5e4b25d733c 100644 (file)
@@ -1,10 +1,8 @@
+// We apptend the linkPreview to a global Variable to make linkPreview
+// accessable on other places. Note: search on other places before you
+// delete or move the variable.
 var linkPreview;
 
-$(document).ready(function() {
-       linkPreview = $('#profile-jot-text').linkPreview();
-});
-
-
 /**
  * Insert a link into friendica jot.
  * 
@@ -25,7 +23,17 @@ function jotGetLink() {
 
                // We use the linkPreview library to have a preview
                // of the attachments.
-               linkPreview.crawlText(reply + noAttachment);
+               if (typeof linkPreview === 'object') {
+                       linkPreview.crawlText(reply + noAttachment);
+
+               // Fallback: insert the attachment bbcode directly into the textarea
+               // if the attachment live preview isn't available
+               } else {
+                       $.get('parse_url?binurl=' + bin2hex(reply) + noAttachment, function(data) {
+                               addeditortext(data);
+                               $('#profile-rotator').hide();
+                       });
+               }
                autosize.update($("#profile-jot-text"));
        }
 }
index 80694b64da52971d890adf9be0fa130975b15b0d..1c5314c4b410b6052a86830b44e867ffe01dddaf 100644 (file)
@@ -22,6 +22,10 @@ $(document).ready(function(){
                $("#jot-content").append(jotcache);
                // Clear the jotcache.
                jotcache = '';
+               // Destroy the attachment linkPreviw for Jot.
+               if (typeof linkPreview === 'object') {
+                       linkPreview.destroy();
+               }
        });
 
        // Add Colorbox for viewing Network page images.
@@ -292,6 +296,7 @@ function editpost(url) {
 
                                modal.show();
                                $("#jot-popup").show();
+                               linkPreview = $('#profile-jot-text').linkPreview();
                        }
                });
 }
index 76a04a32f2887b49913c6e80bed291184c692881..e0c06af581f134ce8a7e9750beab82d0c0488336 100644 (file)
@@ -46,34 +46,34 @@ function commentGetLink(id, prompttext) {
 }
 
 function addCommentText(data, id) {
-    // get the textfield
-    var textfield = document.getElementById("comment-edit-text-" + id);
-    // check if the textfield does have the default-value
-    commentOpenUI(textfield, id);
-    // save already existent content
-    var currentText = $("#comment-edit-text-" + id).val();
-    //insert the data as new value
-    textfield.value = currentText + data;
-    autosize.update($("#comment-edit-text-" + id));
+       // get the textfield
+       var textfield = document.getElementById("comment-edit-text-" + id);
+       // check if the textfield does have the default-value
+       commentOpenUI(textfield, id);
+       // save already existent content
+       var currentText = $("#comment-edit-text-" + id).val();
+       //insert the data as new value
+       textfield.value = currentText + data;
+       autosize.update($("#comment-edit-text-" + id));
 }
 
 function commentLinkDrop(event, id) {
-    var reply = event.dataTransfer.getData("text/uri-list");
-    event.target.textContent = reply;
-    event.preventDefault();
-    if (reply && reply.length) {
-        reply = bin2hex(reply);
-        $.get('parse_url?noAttachment=1&binurl=' + reply, function(data) {
+       var reply = event.dataTransfer.getData("text/uri-list");
+       event.target.textContent = reply;
+       event.preventDefault();
+       if (reply && reply.length) {
+               reply = bin2hex(reply);
+               $.get('parse_url?noAttachment=1&binurl=' + reply, function(data) {
                        addCommentText(data, id);
-        });
-    }
+               });
+       }
 }
 
 function commentLinkDropper(event) {
-    var linkFound = event.dataTransfer.types.contains("text/uri-list");
-    if (linkFound) {
-        event.preventDefault();
-    }
+       var linkFound = event.dataTransfer.types.contains("text/uri-list");
+       if (linkFound) {
+               event.preventDefault();
+       }
 }
 
 
index 548ff264ab0db6bacce0c650c7f1dda2f8b60470..ac59caed8e16dd18ff32052ce925088d41caed70 100644 (file)
                        .find('#jot-modal-content')
                        .append(jotcache)
                        .modal.show;
+
+               // Jot attachment live preview.
+               linkPreview = $('#profile-jot-text').linkPreview();
        }
 
        // Activate the jot text section in the jot modal