|
|
|
@ -7,61 +7,15 @@ define('composer/formatting', ['composer/controls', 'composer/preview'], functio
|
|
|
|
|
var formatting = {};
|
|
|
|
|
|
|
|
|
|
var formattingDispatchTable = {
|
|
|
|
|
'fa fa-bold': function(textarea, selectionStart, selectionEnd){
|
|
|
|
|
if(selectionStart === selectionEnd){
|
|
|
|
|
controls.insertIntoTextarea(textarea, '**bolded text**');
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 2, selectionStart + 13);
|
|
|
|
|
} else {
|
|
|
|
|
controls.wrapSelectionInTextareaWith(textarea, '**');
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 2, selectionEnd + 2);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-italic': function(textarea, selectionStart, selectionEnd){
|
|
|
|
|
if(selectionStart === selectionEnd){
|
|
|
|
|
controls.insertIntoTextarea(textarea, "*italicised text*");
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 1, selectionStart + 16);
|
|
|
|
|
} else {
|
|
|
|
|
controls.wrapSelectionInTextareaWith(textarea, '*');
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 1, selectionEnd + 1);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-list': function(textarea, selectionStart, selectionEnd){
|
|
|
|
|
if(selectionStart === selectionEnd){
|
|
|
|
|
controls.insertIntoTextarea(textarea, "\n* list item");
|
|
|
|
|
|
|
|
|
|
// Highlight "list item"
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 3, selectionStart + 12);
|
|
|
|
|
} else {
|
|
|
|
|
controls.wrapSelectionInTextareaWith(textarea, '\n* ', '');
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 3, selectionEnd + 3);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-link': function(textarea, selectionStart, selectionEnd){
|
|
|
|
|
if(selectionStart === selectionEnd){
|
|
|
|
|
controls.insertIntoTextarea(textarea, "[link text](link url)");
|
|
|
|
|
|
|
|
|
|
// Highlight "link url"
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionStart + 12, selectionEnd + 20);
|
|
|
|
|
} else {
|
|
|
|
|
controls.wrapSelectionInTextareaWith(textarea, '[', '](link url)');
|
|
|
|
|
|
|
|
|
|
// Highlight "link url"
|
|
|
|
|
controls.updateTextareaSelection(textarea, selectionEnd + 3, selectionEnd + 11);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-picture-o': function(){
|
|
|
|
|
'picture-o': function(){
|
|
|
|
|
$('#files').click();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-upload': function(){
|
|
|
|
|
upload: function(){
|
|
|
|
|
$('#files').click();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
'fa fa-tags': function() {
|
|
|
|
|
tags: function() {
|
|
|
|
|
$('.tags-container').toggleClass('hidden');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
@ -69,27 +23,35 @@ define('composer/formatting', ['composer/controls', 'composer/preview'], functio
|
|
|
|
|
var customButtons = [];
|
|
|
|
|
|
|
|
|
|
formatting.addComposerButtons = function() {
|
|
|
|
|
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>');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for(var x=0,numButtons=customButtons.length;x<numButtons;x++) {
|
|
|
|
|
$('.formatting-bar .btn-group form').before('<span class="btn btn-link" tabindex="-1" data-format="' + customButtons[x].name + '"><i class="' + customButtons[x].iconClass + '"></i></span>');
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formatting.addButton = function(iconClass, onClick) {
|
|
|
|
|
formattingDispatchTable[iconClass] = onClick;
|
|
|
|
|
var name = iconClass.replace('fa fa-', '');
|
|
|
|
|
|
|
|
|
|
formattingDispatchTable[name] = onClick;
|
|
|
|
|
customButtons.push({
|
|
|
|
|
name: name,
|
|
|
|
|
iconClass: iconClass
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formatting.addButtonDispatch = function(name, onClick) {
|
|
|
|
|
formattingDispatchTable[name] = onClick;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
formatting.addHandler = function(postContainer) {
|
|
|
|
|
postContainer.on('click', '.formatting-bar span', function () {
|
|
|
|
|
var iconClass = $(this).find('i').attr('class');
|
|
|
|
|
var textarea = $(this).parents('.composer').find('textarea')[0];
|
|
|
|
|
var format = $(this).attr('data-format'),
|
|
|
|
|
textarea = $(this).parents('.composer').find('textarea')[0];
|
|
|
|
|
console.log('handling', format);
|
|
|
|
|
|
|
|
|
|
console.log(formattingDispatchTable);
|
|
|
|
|
|
|
|
|
|
if(formattingDispatchTable.hasOwnProperty(iconClass)){
|
|
|
|
|
formattingDispatchTable[iconClass](textarea, textarea.selectionStart, textarea.selectionEnd);
|
|
|
|
|
if(formattingDispatchTable.hasOwnProperty(format)){
|
|
|
|
|
formattingDispatchTable[format](textarea, textarea.selectionStart, textarea.selectionEnd);
|
|
|
|
|
preview.render(postContainer);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|