Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes cursor position to end of inserted image syntax, implements #2079 #2106

Merged
merged 2 commits into from Mar 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 18 additions & 3 deletions lib/scripts/media.js
Expand Up @@ -272,7 +272,8 @@ var dw_mediamanager = {
cb = String.prototype.match.call(document.location, /&onselect=([^&]+)/);
cb = cb ? cb[1].replace(/[^\w]+/, '') : 'dw_mediamanager_item_select';

opener[cb](edid, id, opts, dw_mediamanager.align);
// arguments here only match the dw_mediamanager_item_select function, these will need to change if you override cb with onselect GET param
opener[cb](edid, id, opts, dw_mediamanager.align, dw_mediamanager.keepopen);
if (!dw_mediamanager.keepopen) {
window.close();
}
Expand Down Expand Up @@ -937,14 +938,28 @@ var dw_mediamanager = {
* @param {string} opts
* @param {string} align [none, left, center, right]
*/
function dw_mediamanager_item_select(edid, mediaid, opts, align) {
function dw_mediamanager_item_select(edid, mediaid, opts, align, keepopen) {
var alignleft = '';
var alignright = '';

// Get the 2 characters after the cursor to check if we're currently inside an image tag
var cursorInImageTag = false;
var textArea = jQuery('#' + edid)[0];
var selection = DWgetSelection(textArea);
selection.end = selection.end + 2;
var charsAfterCursor = selection.getText();
if (charsAfterCursor === '}}') {
cursorInImageTag = true;
}

if (align !== '1') {
alignleft = align === '2' ? '' : ' ';
alignright = align === '4' ? '' : ' ';
}

if (keepopen && cursorInImageTag) {
selection.start = selection.start + 2;
DWsetSelection(selection);
}
insertTags(edid, '{{' + alignleft + mediaid + opts + alignright + '|', '}}', '');
}

Expand Down