mirror of
https://github.com/humhub/humhub.git
synced 2025-04-19 22:54:25 +02:00
Fix: MarkdownEditor cursor position after inserting file/image
This commit is contained in:
parent
782549f206
commit
a061076bf4
@ -43,6 +43,7 @@ Important note for LDAP users: There is a new setting "ID Attribute" which shoul
|
||||
- Fix: `humhub\modules\live\Module::getLegitimateContentContainerIds` behaviour with friendship module enabled
|
||||
- Enh: Added `BaseNotification:priority` to mark high priority notifications
|
||||
- Enh: Added new `User::isVisible` and `ActiveQueryUser::visible` methods
|
||||
- Fix: MarkdownEditor cursor position after inserting file/image
|
||||
|
||||
1.2.2 (August 2, 2017)
|
||||
--------------------------------
|
||||
|
@ -3,8 +3,8 @@ var newFile = "";
|
||||
|
||||
function initMarkdownEditor(elementId) {
|
||||
|
||||
if(!$('#addFileModal_'+elementId).length) {
|
||||
$("body").append($("#markdownEditor_dialogs_"+elementId).html());
|
||||
if (!$('#addFileModal_' + elementId).length) {
|
||||
$("body").append($("#markdownEditor_dialogs_" + elementId).html());
|
||||
}
|
||||
|
||||
$("#" + elementId).markdown({
|
||||
@ -17,8 +17,8 @@ function initMarkdownEditor(elementId) {
|
||||
name: "cmdLinkWiki",
|
||||
title: "URL/Link",
|
||||
icon: {glyph: 'glyphicon glyphicon-link', fa: 'fa fa-link', 'fa-3': 'icon-link'},
|
||||
callback: function(e) {
|
||||
addLinkModal = $('#addLinkModal_'+elementId);
|
||||
callback: function (e) {
|
||||
addLinkModal = $('#addLinkModal_' + elementId);
|
||||
linkTitleField = addLinkModal.find('.linkTitle');
|
||||
linkTargetField = addLinkModal.find('.linkTarget');
|
||||
|
||||
@ -36,7 +36,7 @@ function initMarkdownEditor(elementId) {
|
||||
}
|
||||
|
||||
addLinkModal.find('.addLinkButton').off('click');
|
||||
addLinkModal.find('.addLinkButton').on('click', function() {
|
||||
addLinkModal.find('.addLinkButton').on('click', function () {
|
||||
chunk = "[" + linkTitleField.val() + "](" + linkTargetField.val() + ")";
|
||||
selected = e.getSelection(), content = e.getContent(),
|
||||
e.replaceSelection(chunk);
|
||||
@ -45,7 +45,7 @@ function initMarkdownEditor(elementId) {
|
||||
addLinkModal.modal('hide')
|
||||
});
|
||||
|
||||
addLinkModal.on('hide.bs.modal', function(ee) {
|
||||
addLinkModal.on('hide.bs.modal', function (ee) {
|
||||
linkTitleField.val("");
|
||||
linkTargetField.val("");
|
||||
})
|
||||
@ -55,25 +55,23 @@ function initMarkdownEditor(elementId) {
|
||||
name: "cmdImgWiki",
|
||||
title: "Image/File",
|
||||
icon: {glyph: 'glyphicon glyphicon-picture', fa: 'fa fa-picture-o', 'fa-3': 'icon-picture'},
|
||||
callback: function(e) {
|
||||
newFile = "";
|
||||
callback: function (e) {
|
||||
|
||||
addFileModal = $('#addFileModal_'+elementId);
|
||||
addFileModal = $('#addFileModal_' + elementId);
|
||||
addFileModal.modal('show');
|
||||
addFileModal.find(".uploadForm").show();
|
||||
addFileModal.find(".uploadProgress").hide();
|
||||
|
||||
addFileModal.on('hide.bs.modal', function(ee) {
|
||||
addFileModal.on('hide.bs.modal', function (ee) {
|
||||
if (newFile != "") {
|
||||
if (newFile.mimeType.substring(0,6) == "image/") {
|
||||
chunk = "";
|
||||
var chunk;
|
||||
if (newFile.mimeType.substring(0, 6) == "image/") {
|
||||
chunk = " ";
|
||||
} else {
|
||||
chunk = "[" + newFile.name + "](file-guid-" + newFile.guid + ")";
|
||||
chunk = "[" + newFile.name + "](file-guid-" + newFile.guid + ") ";
|
||||
}
|
||||
selected = e.getSelection(), content = e.getContent(),
|
||||
e.replaceSelection(chunk);
|
||||
cursor = selected.start;
|
||||
e.setSelection(cursor, cursor + chunk.length);
|
||||
insertAtCaret(e.$textarea[0], chunk)
|
||||
newFile = "";
|
||||
}
|
||||
})
|
||||
}
|
||||
@ -82,30 +80,30 @@ function initMarkdownEditor(elementId) {
|
||||
}]
|
||||
],
|
||||
reorderButtonGroups: ["groupFont", "groupCustom", "groupMisc", "groupUtil"],
|
||||
onPreview: function(e) {
|
||||
onPreview: function (e) {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: markdownPreviewUrl,
|
||||
data: {
|
||||
markdown: e.getContent(),
|
||||
}
|
||||
}).done(function(previewHtml) {
|
||||
$('#markdownpreview_'+elementId).html(previewHtml);
|
||||
}).done(function (previewHtml) {
|
||||
$('#markdownpreview_' + elementId).html(previewHtml);
|
||||
});
|
||||
var previewContent = "<div id='markdownpreview_"+elementId+"'><div class='loader'></div></div>";
|
||||
var previewContent = "<div id='markdownpreview_" + elementId + "'><div class='loader'></div></div>";
|
||||
return previewContent;
|
||||
}
|
||||
});
|
||||
|
||||
$('#addFileModal_'+elementId).find(".uploadProgress").hide();
|
||||
$('#addFileModal_'+elementId).find('.fileUploadButton').fileupload({
|
||||
$('#addFileModal_' + elementId).find(".uploadProgress").hide();
|
||||
$('#addFileModal_' + elementId).find('.fileUploadButton').fileupload({
|
||||
dataType: 'json',
|
||||
done: function(e, data) {
|
||||
$.each(data.result.files, function(index, file) {
|
||||
addFileModal = $('#addFileModal_'+elementId);
|
||||
done: function (e, data) {
|
||||
$.each(data.result.files, function (index, file) {
|
||||
addFileModal = $('#addFileModal_' + elementId);
|
||||
if (!file.error) {
|
||||
newFile = file;
|
||||
hiddenValueField = $('#fileUploaderHiddenGuidField_'+elementId);
|
||||
hiddenValueField = $('#fileUploaderHiddenGuidField_' + elementId);
|
||||
hiddenValueField.val(hiddenValueField.val() + "," + file.guid);
|
||||
addFileModal.modal('hide');
|
||||
} else {
|
||||
@ -113,9 +111,9 @@ function initMarkdownEditor(elementId) {
|
||||
}
|
||||
});
|
||||
},
|
||||
progressall: function(e, data) {
|
||||
progressall: function (e, data) {
|
||||
newFile = "";
|
||||
addFileModal = $('#addFileModal_'+elementId);
|
||||
addFileModal = $('#addFileModal_' + elementId);
|
||||
|
||||
var progress = parseInt(data.loaded / data.total * 100, 10);
|
||||
addFileModal.find(".uploadForm").hide();
|
||||
@ -128,3 +126,39 @@ function initMarkdownEditor(elementId) {
|
||||
}).prop('disabled', !$.support.fileInput).parent().addClass($.support.fileInput ? undefined : 'disabled');
|
||||
|
||||
}
|
||||
function insertAtCaret(txtarea, text) {
|
||||
if (!txtarea) {
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollPos = txtarea.scrollTop;
|
||||
var strPos = 0;
|
||||
var br = ((txtarea.selectionStart || txtarea.selectionStart == '0') ? "ff" : (document.selection ? "ie" : false));
|
||||
if (br == "ie") {
|
||||
txtarea.focus();
|
||||
var range = document.selection.createRange();
|
||||
range.moveStart('character', -txtarea.value.length);
|
||||
strPos = range.text.length;
|
||||
} else if (br == "ff") {
|
||||
strPos = txtarea.selectionStart;
|
||||
}
|
||||
|
||||
var front = (txtarea.value).substring(0, strPos);
|
||||
var back = (txtarea.value).substring(strPos, txtarea.value.length);
|
||||
txtarea.value = front + text + back;
|
||||
strPos = strPos + text.length;
|
||||
if (br == "ie") {
|
||||
txtarea.focus();
|
||||
var ieRange = document.selection.createRange();
|
||||
ieRange.moveStart('character', -txtarea.value.length);
|
||||
ieRange.moveStart('character', strPos);
|
||||
ieRange.moveEnd('character', 0);
|
||||
ieRange.select();
|
||||
} else if (br == "ff") {
|
||||
txtarea.selectionStart = strPos;
|
||||
txtarea.selectionEnd = strPos;
|
||||
txtarea.focus();
|
||||
}
|
||||
|
||||
txtarea.scrollTop = scrollPos;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user