+// We append 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.
*
// 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"));
}
}
-
-/**
- * Get in a textarea the previous word before the cursor.
- *
- * @param {object} text Textarea elemet.
- * @param {integer} caretPos Cursor position.
- *
- * @returns {string} Previous word.
- */
-function returnWord(text, caretPos) {
- var index = text.indexOf(caretPos);
- var preText = text.substring(0, caretPos);
- // If the last charachter is a space remove the one space
- // We need this in friendica for the url preview.
- if (preText.slice(-1) == " ") {
- preText = preText.substring(0, preText.length -1);
- }
-// preText = preText.replace(/^\s+|\s+$/g, "");
- if (preText.indexOf(" ") > 0) {
- var words = preText.split(" ");
- return words[words.length - 1]; //return last word
- }
- else {
- return preText;
- }
-}
-
-/**
- * Get in a textarea the previous word before the cursor.
- *
- * @param {string} id The ID of a textarea element.
- * @returns {sting|null} Previous word or null if no word is available.
- */
-function getPrevWord(id) {
- var text = document.getElementById(id);
- var caretPos = getCaretPosition(text);
- var word = returnWord(text.value, caretPos);
- if (word != null) {
- return word
- }
-
-}
-
-/**
- * Get the cursor posiotion in an text element.
- *
- * @param {object} ctrl Textarea elemet.
- * @returns {integer} Position of the cursor.
- */
-function getCaretPosition(ctrl) {
- var CaretPos = 0; // IE Support
- if (document.selection) {
- ctrl.focus();
- var Sel = document.selection.createRange();
- Sel.moveStart('character', -ctrl.value.length);
- CaretPos = Sel.text.length;
- }
- // Firefox support
- else if (ctrl.selectionStart || ctrl.selectionStart == '0') {
- CaretPos = ctrl.selectionStart;
- }
- return (CaretPos);
-}