]> git.mxchange.org Git - friendica.git/blobdiff - view/theme/frio/js/jot.js
Merge pull request #6949 from MrPetovan/bug/6947-frio-fix-fake-form
[friendica.git] / view / theme / frio / js / jot.js
index f63ed5356926946372c1376552eb3fa98af35b90..d55e5098a28b89c96f9b6cb836ce0c4fbe412d05 100644 (file)
@@ -1,10 +1,8 @@
+// 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.
  * 
@@ -25,70 +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"));
        }
 }
-
-/**
- * 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);
-}