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