##// END OF EJS Templates
Additinal JS refactoring
neko259 -
r1082:66eb05a4 default
parent child Browse files
Show More
@@ -37,7 +37,8 b' function addImgPreview() {'
37 var el = $(this);
37 var el = $(this);
38 var thumb_id = 'full' + el.find('img').attr('alt');
38 var thumb_id = 'full' + el.find('img').attr('alt');
39
39
40 if(!$('#'+thumb_id).length) {
40 var existingPopups = $('#' + thumb_id);
41 if(!existingPopups.length) {
41 var imgElement= el.find('img');
42 var imgElement= el.find('img');
42
43
43 var img_w = imgElement.attr('data-width');
44 var img_w = imgElement.attr('data-width');
@@ -88,12 +89,13 b' function addImgPreview() {'
88
89
89 return false;
90 return false;
90 }
91 }
91 ).draggable({
92 )
92 addClasses: false,
93 .draggable({
93 stack: '.img-full'
94 addClasses: false,
94 })
95 stack: '.img-full'
96 });
95 } else {
97 } else {
96 $('#'+thumb_id).remove();
98 existingPopups.remove();
97 }
99 }
98 //prevent default
100 //prevent default
99 return false;
101 return false;
@@ -30,10 +30,6 b''
30 * @param end End (right) text
30 * @param end End (right) text
31 */
31 */
32 function addMarkToMsg(start, end) {
32 function addMarkToMsg(start, end) {
33 if (end.length == 0) {
34 return addTextToEachLineOfSelection(start);
35 }
36
37 var textareas = $('textarea');
33 var textareas = $('textarea');
38
34
39 for (var i = 0; i < textareas.length; i++) {
35 for (var i = 0; i < textareas.length; i++) {
@@ -62,41 +58,3 b' function addMarkToMsg(start, end) {'
62 return false;
58 return false;
63 }
59 }
64
60
65 /**
66 * Add text to the beginning of each selected line. Partially selected lines
67 * are included
68 *
69 * @param textToAdd Text to add to the each line
70 */
71 function addTextToEachLineOfSelection(textToAdd) {
72 var textareas = $('textarea');
73
74 for (var i = 0; i < textareas.length; i++) {
75 var textarea = textareas[i];
76
77 if (document.selection) {
78 textarea.focus();
79
80 var sel = document.selection.createRange();
81 sel.text = start + sel.text + end;
82 } else if (textarea.selectionStart || textarea.selectionStart == '0') {
83 textarea.focus();
84
85 var startPos = textarea.selectionStart;
86 var endPos = textarea.selectionEnd;
87
88 var oldValue = textarea.value;
89
90 var textBeforeSelection = oldValue.substring(0, startPos);
91 var selectionText = oldValue.substring(startPos, endPos)
92 .replace(/\n/g, '\n' + textToAdd);
93 textarea.value = textBeforeSelection + textToAdd +
94 selectionText +
95 oldValue.substring(endPos, oldValue.length);
96 } else {
97 textarea.value += textToAdd;
98 }
99 }
100
101 return false;
102 }
General Comments 0
You need to be logged in to leave comments. Login now