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

Document selection "lost" in filemanager when a filter is applied #3253

Closed
robertogerola opened this issue Aug 18, 2015 · 7 comments
Closed

Comments

@robertogerola
Copy link

Scenario :
WYSIWYG text area, click the image button, click in the input filter
At this point the original document selection is gone and the filemanager doesn't know where to insert the image.

Solution :
Add this code in admin/view/common.js file

var document_selection;

function saveSelection() {
    if (window.getSelection) {
        sel = window.getSelection();
        if (sel.getRangeAt && sel.rangeCount) {
            return sel.getRangeAt(0);
        }
    } else if (document.selection && document.selection.createRange) {
        return document.selection.createRange();
    }
    return null;
}

function restoreSelection(range) {
    if (range) {
        if (window.getSelection) {
            sel = window.getSelection();
            sel.removeAllRanges();
            sel.addRange(range);
        } else if (document.selection && range.select) {
            range.select();
        }
    }
}

In the same file at the beginning of the function

$(document).delegate('button[data-toggle=\'image\']', 'click', function() {

add

document_selection = saveSelection();

In file admin/view/filemanager.tpl
in function

$('a.thumbnail').on('click', function(e) {

before

var range, sel = document.getSelection(); 

add

restoreSelection(document_selection);
@danielkerr
Copy link
Member

great possible fix for something i can not replicate.

maybe if you gave a better description and details of browser used. possibly even a video.

@danielkerr
Copy link
Member

ok i see. you mean the image manager search text field

@danijelGombac
Copy link
Contributor

Confirm this in OC demo page wtih Firefox 40.0.2. If click in search input field in filemaneger then you can't add image to summernote editor.

@danielkerr
Copy link
Member

@GomDani

did you read where i said

"ok i see. you mean the image manager search text field"

no need for confirmation

@danijelGombac
Copy link
Contributor

I didn't see your second message when i started writing.

@danielkerr
Copy link
Member

sorry.

this fix does not seem to work

@aymouna
Copy link

aymouna commented Jan 27, 2017

Scenario :
WYSIWYG text area, click the image button, click in the input filter
At this point the original document selection is gone and the filemanager doesn't know where to insert the image. Version(2.0.2.0)
Solution :
Change this code in admin/view/template/commen/filemanager.tpl to :

$('a.thumbnail').on('click', function(e) {

var htmlimage='< img src="'+$(this).attr('href');+'" >'; // NB:Remove space between < and img
$('.note-editable').append(htmlimage);
$('#modal-image').modal('hide');

});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants