fixed admin page loading

v1.18.x
Baris Usakli 12 years ago
parent aaae9e0c83
commit 37b5680db0

@ -302,65 +302,69 @@ var socket,
var formattingBar = document.querySelector('.formatting-bar'), var formattingBar = document.querySelector('.formatting-bar'),
postContentEl = document.getElementById('post_content'); postContentEl = document.getElementById('post_content');
jQuery('#post_window').slideToggle(0); jQuery('#post_window').slideToggle(0);
formattingBar.addEventListener('click', function(e) {
if (e.target.nodeName === 'I' || e.target.nodeName === 'SPAN') { if(formattingBar) {
var cursorEnd = postContentEl.value.length,
selectionStart = postContentEl.selectionStart, formattingBar.addEventListener('click', function(e) {
selectionEnd = postContentEl.selectionEnd, if (e.target.nodeName === 'I' || e.target.nodeName === 'SPAN') {
selectionLength = selectionEnd - selectionStart, var cursorEnd = postContentEl.value.length,
target; selectionStart = postContentEl.selectionStart,
if (e.target.nodeName === 'I') target = e.target; selectionEnd = postContentEl.selectionEnd,
else if (e.target.nodeName === 'SPAN') target = e.target.querySelector('i'); selectionLength = selectionEnd - selectionStart,
switch(target.className) { target;
case 'icon-bold': if (e.target.nodeName === 'I') target = e.target;
if (selectionStart === selectionEnd) { else if (e.target.nodeName === 'SPAN') target = e.target.querySelector('i');
// Nothing selected switch(target.className) {
postContentEl.value = postContentEl.value + '**bolded text**'; case 'icon-bold':
postContentEl.selectionStart = cursorEnd+2; if (selectionStart === selectionEnd) {
postContentEl.selectionEnd = postContentEl.value.length - 2; // Nothing selected
} else { postContentEl.value = postContentEl.value + '**bolded text**';
// Text selected postContentEl.selectionStart = cursorEnd+2;
postContentEl.value = postContentEl.value.slice(0, selectionStart) + '**' + postContentEl.value.slice(selectionStart, selectionEnd) + '**' + postContentEl.value.slice(selectionEnd); postContentEl.selectionEnd = postContentEl.value.length - 2;
postContentEl.selectionStart = selectionStart + 2; } else {
postContentEl.selectionEnd = selectionEnd + 2; // Text selected
} postContentEl.value = postContentEl.value.slice(0, selectionStart) + '**' + postContentEl.value.slice(selectionStart, selectionEnd) + '**' + postContentEl.value.slice(selectionEnd);
break; postContentEl.selectionStart = selectionStart + 2;
case 'icon-italic': postContentEl.selectionEnd = selectionEnd + 2;
if (selectionStart === selectionEnd) { }
// Nothing selected break;
postContentEl.value = postContentEl.value + '*italicised text*'; case 'icon-italic':
postContentEl.selectionStart = cursorEnd+1; if (selectionStart === selectionEnd) {
postContentEl.selectionEnd = postContentEl.value.length - 1; // Nothing selected
} else { postContentEl.value = postContentEl.value + '*italicised text*';
// Text selected postContentEl.selectionStart = cursorEnd+1;
postContentEl.value = postContentEl.value.slice(0, selectionStart) + '*' + postContentEl.value.slice(selectionStart, selectionEnd) + '*' + postContentEl.value.slice(selectionEnd); postContentEl.selectionEnd = postContentEl.value.length - 1;
postContentEl.selectionStart = selectionStart + 1; } else {
postContentEl.selectionEnd = selectionEnd + 1; // Text selected
} postContentEl.value = postContentEl.value.slice(0, selectionStart) + '*' + postContentEl.value.slice(selectionStart, selectionEnd) + '*' + postContentEl.value.slice(selectionEnd);
break; postContentEl.selectionStart = selectionStart + 1;
case 'icon-list': postContentEl.selectionEnd = selectionEnd + 1;
// Nothing selected }
postContentEl.value = postContentEl.value + "\n\n* list item"; break;
postContentEl.selectionStart = cursorEnd+4; case 'icon-list':
postContentEl.selectionEnd = postContentEl.value.length;
break;
case 'icon-link':
if (selectionStart === selectionEnd) {
// Nothing selected // Nothing selected
postContentEl.value = postContentEl.value + '[link text](link url)'; postContentEl.value = postContentEl.value + "\n\n* list item";
postContentEl.selectionStart = cursorEnd+12; postContentEl.selectionStart = cursorEnd+4;
postContentEl.selectionEnd = postContentEl.value.length - 1; postContentEl.selectionEnd = postContentEl.value.length;
} else { break;
// Text selected case 'icon-link':
postContentEl.value = postContentEl.value.slice(0, selectionStart) + '[' + postContentEl.value.slice(selectionStart, selectionEnd) + '](link url)' + postContentEl.value.slice(selectionEnd); if (selectionStart === selectionEnd) {
postContentEl.selectionStart = selectionStart + selectionLength + 3; // Nothing selected
postContentEl.selectionEnd = selectionEnd + 11; postContentEl.value = postContentEl.value + '[link text](link url)';
} postContentEl.selectionStart = cursorEnd+12;
break; postContentEl.selectionEnd = postContentEl.value.length - 1;
} else {
// Text selected
postContentEl.value = postContentEl.value.slice(0, selectionStart) + '[' + postContentEl.value.slice(selectionStart, selectionEnd) + '](link url)' + postContentEl.value.slice(selectionEnd);
postContentEl.selectionStart = selectionStart + selectionLength + 3;
postContentEl.selectionEnd = selectionEnd + 11;
}
break;
}
} }
} }, false);
}, false); }
}) });

Loading…
Cancel
Save