attachment preview: frio- initialize linkPreview on jot modal open (so we can use the linkPreview for new posts and edit post modal)

This commit is contained in:
rabuzarus 2019-02-02 03:12:36 +01:00
parent b065356c28
commit 3a15c22028
4 changed files with 43 additions and 27 deletions

View 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; var linkPreview;
$(document).ready(function() {
linkPreview = $('#profile-jot-text').linkPreview();
});
/** /**
* Insert a link into friendica jot. * Insert a link into friendica jot.
* *
@ -25,7 +23,17 @@ function jotGetLink() {
// We use the linkPreview library to have a preview // We use the linkPreview library to have a preview
// of the attachments. // 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")); autosize.update($("#profile-jot-text"));
} }
} }

View File

@ -22,6 +22,10 @@ $(document).ready(function(){
$("#jot-content").append(jotcache); $("#jot-content").append(jotcache);
// Clear the jotcache. // Clear the jotcache.
jotcache = ''; jotcache = '';
// Destroy the attachment linkPreviw for Jot.
if (typeof linkPreview === 'object') {
linkPreview.destroy();
}
}); });
// Add Colorbox for viewing Network page images. // Add Colorbox for viewing Network page images.
@ -292,6 +296,7 @@ function editpost(url) {
modal.show(); modal.show();
$("#jot-popup").show(); $("#jot-popup").show();
linkPreview = $('#profile-jot-text').linkPreview();
} }
}); });
} }

View File

@ -46,34 +46,34 @@ function commentGetLink(id, prompttext) {
} }
function addCommentText(data, id) { function addCommentText(data, id) {
// get the textfield // get the textfield
var textfield = document.getElementById("comment-edit-text-" + id); var textfield = document.getElementById("comment-edit-text-" + id);
// check if the textfield does have the default-value // check if the textfield does have the default-value
commentOpenUI(textfield, id); commentOpenUI(textfield, id);
// save already existent content // save already existent content
var currentText = $("#comment-edit-text-" + id).val(); var currentText = $("#comment-edit-text-" + id).val();
//insert the data as new value //insert the data as new value
textfield.value = currentText + data; textfield.value = currentText + data;
autosize.update($("#comment-edit-text-" + id)); autosize.update($("#comment-edit-text-" + id));
} }
function commentLinkDrop(event, id) { function commentLinkDrop(event, id) {
var reply = event.dataTransfer.getData("text/uri-list"); var reply = event.dataTransfer.getData("text/uri-list");
event.target.textContent = reply; event.target.textContent = reply;
event.preventDefault(); event.preventDefault();
if (reply && reply.length) { if (reply && reply.length) {
reply = bin2hex(reply); reply = bin2hex(reply);
$.get('parse_url?noAttachment=1&binurl=' + reply, function(data) { $.get('parse_url?noAttachment=1&binurl=' + reply, function(data) {
addCommentText(data, id); addCommentText(data, id);
}); });
} }
} }
function commentLinkDropper(event) { function commentLinkDropper(event) {
var linkFound = event.dataTransfer.types.contains("text/uri-list"); var linkFound = event.dataTransfer.types.contains("text/uri-list");
if (linkFound) { if (linkFound) {
event.preventDefault(); event.preventDefault();
} }
} }

View File

@ -273,6 +273,9 @@
.find('#jot-modal-content') .find('#jot-modal-content')
.append(jotcache) .append(jotcache)
.modal.show; .modal.show;
// Jot attachment live preview.
linkPreview = $('#profile-jot-text').linkPreview();
} }
// Activate the jot text section in the jot modal // Activate the jot text section in the jot modal