mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
closes #1444
This commit is contained in:
@@ -7,7 +7,9 @@ define(['taskbar'], function(taskbar) {
|
|||||||
active: undefined,
|
active: undefined,
|
||||||
posts: {},
|
posts: {},
|
||||||
saving: undefined
|
saving: undefined
|
||||||
};
|
},
|
||||||
|
controls = {};
|
||||||
|
|
||||||
|
|
||||||
function initialise() {
|
function initialise() {
|
||||||
socket.on('event:composer.ping', function(post_uuid) {
|
socket.on('event:composer.ping', function(post_uuid) {
|
||||||
@@ -418,7 +420,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
/*************************************************/
|
/*************************************************/
|
||||||
/* Rich Textarea Controls */
|
/* Rich Textarea Controls */
|
||||||
/*************************************************/
|
/*************************************************/
|
||||||
function insertIntoTextarea(textarea, value) {
|
controls.insertIntoTextarea = function(textarea, value) {
|
||||||
var $textarea = $(textarea);
|
var $textarea = $(textarea);
|
||||||
var currentVal = $textarea.val();
|
var currentVal = $textarea.val();
|
||||||
|
|
||||||
@@ -427,34 +429,34 @@ define(['taskbar'], function(taskbar) {
|
|||||||
value +
|
value +
|
||||||
currentVal.slice(textarea.selectionStart)
|
currentVal.slice(textarea.selectionStart)
|
||||||
);
|
);
|
||||||
}
|
};
|
||||||
|
|
||||||
function wrapSelectionInTextareaWith(textarea, leading, trailing){
|
controls.wrapSelectionInTextareaWith = function(textarea, leading, trailing){
|
||||||
if(trailing === undefined){
|
if(trailing === undefined){
|
||||||
trailing = leading;
|
trailing = leading;
|
||||||
}
|
|
||||||
|
|
||||||
var $textarea = $(textarea);
|
|
||||||
var currentVal = $textarea.val()
|
|
||||||
|
|
||||||
$textarea.val(
|
|
||||||
currentVal.slice(0, textarea.selectionStart) +
|
|
||||||
leading +
|
|
||||||
currentVal.slice(textarea.selectionStart, textarea.selectionEnd) +
|
|
||||||
trailing +
|
|
||||||
currentVal.slice(textarea.selectionEnd)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTextareaSelection(textarea, start, end){
|
var $textarea = $(textarea);
|
||||||
textarea.setSelectionRange(start, end);
|
var currentVal = $textarea.val()
|
||||||
$(textarea).focus();
|
|
||||||
}
|
$textarea.val(
|
||||||
|
currentVal.slice(0, textarea.selectionStart) +
|
||||||
|
leading +
|
||||||
|
currentVal.slice(textarea.selectionStart, textarea.selectionEnd) +
|
||||||
|
trailing +
|
||||||
|
currentVal.slice(textarea.selectionEnd)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
controls.updateTextareaSelection = function(textarea, start, end){
|
||||||
|
textarea.setSelectionRange(start, end);
|
||||||
|
$(textarea).focus();
|
||||||
|
};
|
||||||
|
|
||||||
var formattingDispatchTable = {
|
var formattingDispatchTable = {
|
||||||
'fa fa-bold': function(textarea, selectionStart, selectionEnd){
|
'fa fa-bold': function(textarea, selectionStart, selectionEnd){
|
||||||
if(selectionStart === selectionEnd){
|
if(selectionStart === selectionEnd){
|
||||||
insertIntoTextarea(textarea, '**bolded text**');
|
composer.insertIntoTextarea(textarea, '**bolded text**');
|
||||||
updateTextareaSelection(textarea, selectionStart + 2, selectionStart + 13);
|
updateTextareaSelection(textarea, selectionStart + 2, selectionStart + 13);
|
||||||
} else {
|
} else {
|
||||||
wrapSelectionInTextareaWith(textarea, '**');
|
wrapSelectionInTextareaWith(textarea, '**');
|
||||||
@@ -464,7 +466,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
|
|
||||||
'fa fa-italic': function(textarea, selectionStart, selectionEnd){
|
'fa fa-italic': function(textarea, selectionStart, selectionEnd){
|
||||||
if(selectionStart === selectionEnd){
|
if(selectionStart === selectionEnd){
|
||||||
insertIntoTextarea(textarea, "*italicised text*");
|
composer.insertIntoTextarea(textarea, "*italicised text*");
|
||||||
updateTextareaSelection(textarea, selectionStart + 1, selectionStart + 16);
|
updateTextareaSelection(textarea, selectionStart + 1, selectionStart + 16);
|
||||||
} else {
|
} else {
|
||||||
wrapSelectionInTextareaWith(textarea, '*');
|
wrapSelectionInTextareaWith(textarea, '*');
|
||||||
@@ -474,7 +476,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
|
|
||||||
'fa fa-list': function(textarea, selectionStart, selectionEnd){
|
'fa fa-list': function(textarea, selectionStart, selectionEnd){
|
||||||
if(selectionStart === selectionEnd){
|
if(selectionStart === selectionEnd){
|
||||||
insertIntoTextarea(textarea, "\n* list item");
|
composer.insertIntoTextarea(textarea, "\n* list item");
|
||||||
|
|
||||||
// Highlight "list item"
|
// Highlight "list item"
|
||||||
updateTextareaSelection(textarea, selectionStart + 3, selectionStart + 12);
|
updateTextareaSelection(textarea, selectionStart + 3, selectionStart + 12);
|
||||||
@@ -486,7 +488,7 @@ define(['taskbar'], function(taskbar) {
|
|||||||
|
|
||||||
'fa fa-link': function(textarea, selectionStart, selectionEnd){
|
'fa fa-link': function(textarea, selectionStart, selectionEnd){
|
||||||
if(selectionStart === selectionEnd){
|
if(selectionStart === selectionEnd){
|
||||||
insertIntoTextarea(textarea, "[link text](link url)");
|
composer.insertIntoTextarea(textarea, "[link text](link url)");
|
||||||
|
|
||||||
// Highlight "link url"
|
// Highlight "link url"
|
||||||
updateTextareaSelection(textarea, selectionStart + 12, selectionEnd + 20);
|
updateTextareaSelection(textarea, selectionStart + 12, selectionEnd + 20);
|
||||||
@@ -507,6 +509,8 @@ define(['taskbar'], function(taskbar) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var customButtons = [];
|
||||||
|
|
||||||
function handleFormattingBarClick() {
|
function handleFormattingBarClick() {
|
||||||
var iconClass = $(this).find('i').attr('class');
|
var iconClass = $(this).find('i').attr('class');
|
||||||
var textarea = $(this).parents('.composer').find('textarea')[0];
|
var textarea = $(this).parents('.composer').find('textarea')[0];
|
||||||
@@ -516,6 +520,20 @@ define(['taskbar'], function(taskbar) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addComposerButtons() {
|
||||||
|
for (var button in customButtons) {
|
||||||
|
if (customButtons.hasOwnProperty(button)) {
|
||||||
|
$('.formatting-bar .btn-group form').before('<span class="btn btn-link" tabindex="-1"><i class="' + customButtons[button].iconClass + '"></i></span>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
composer.addButton = function(iconClass, onClick) {
|
||||||
|
formattingDispatchTable[iconClass] = onClick;
|
||||||
|
customButtons.push({
|
||||||
|
iconClass: iconClass
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
composer.newTopic = function(cid) {
|
composer.newTopic = function(cid) {
|
||||||
if(!allowed()) {
|
if(!allowed()) {
|
||||||
@@ -860,6 +878,8 @@ define(['taskbar'], function(taskbar) {
|
|||||||
$(window).trigger('action:composer.loaded', {
|
$(window).trigger('action:composer.loaded', {
|
||||||
post_uuid: post_uuid
|
post_uuid: post_uuid
|
||||||
});
|
});
|
||||||
|
|
||||||
|
addComposerButtons();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@@ -1015,7 +1035,9 @@ define(['taskbar'], function(taskbar) {
|
|||||||
newReply: composer.newReply,
|
newReply: composer.newReply,
|
||||||
addQuote: composer.addQuote,
|
addQuote: composer.addQuote,
|
||||||
editPost: composer.editPost,
|
editPost: composer.editPost,
|
||||||
|
addButton: composer.addButton,
|
||||||
load: composer.load,
|
load: composer.load,
|
||||||
minimize: composer.minimize
|
minimize: composer.minimize,
|
||||||
|
controls: controls
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user