Skip to content

Commit

Permalink
Merge pull request #2106 from rsynnest/master
Browse files Browse the repository at this point in the history
Changes cursor position to end of inserted image syntax, implements #2079
  • Loading branch information
splitbrain committed Mar 6, 2018
2 parents dfeb484 + d52bcd4 commit a53b370
Showing 1 changed file with 18 additions and 3 deletions.
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

0 comments on commit a53b370

Please sign in to comment.