D
D
Dmitry Filandor2018-05-16 17:21:08
CKEditor
Dmitry Filandor, 2018-05-16 17:21:08

How to change the CKEDITOR parameter?

Hello!
The form has a text box in which the user enters the URL and a text area that is filled using the CKEDITOR editor.
Here is how the editor is initiated:

CKEDITOR.replace('ae-textarea-text', {
        filebrowserImageUploadUrl: '/Sites/UploadImgToSite?Site=' + $("#SiteName").val(),
        height: 850,
        width: 800       
    });

/Sites/UploadImgToSite?Site is the path on the controller that should save the image with the "Site" parameter, the
image is saved, but the "Site" parameter always comes empty. But if I pre-register the value in the box url text, then everything is ok.
It turns out that when the page is loaded, CKEDITOR is initiated by an empty #SiteName value and does not take it further. What can be done? In addition to splitting the operation into two steps, taking the url in the first and passing it to the second page, where CKEDITOR is initiated .... which I really would not like.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Valery, 2018-05-16
@LifeAct

CKEDITOR has no way to change filebrowserImageUploadUrl dynamically.
The simplest solution:

$("#SiteName").change(function () {
  setcookie('upload_site', $(this).val());
}).change();

And on the server side, getting the upload_site value from cookies instead of getting it from GET['Site'] as it is now.
Just in case, the implementation of setcookie
function setcookie(name, value, expires, path, domain, secure) {
    expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString());
    var r = [name + "=" + escape(value)], s, i;
    for(i in s = {expires: expires, path: path, domain: domain}){
        s[i] && r.push(i + "=" + s[i]);
    }
    return secure && r.push("secure"), document.cookie = r.join(";"), true;
}

R
Ruslan, 2018-05-16
@Sect0R

Try like this:

var editor = CKEDITOR.replace('ae-textarea-text', {
        filebrowserImageUploadUrl: '/Sites/UploadImgToSite',
        height: 850,
        width: 800       
    });
$('#SiteName').change(function() {
  editor.config.filebrowserImageUploadUrl = '/Sites/UploadImgToSite?Site=' + $("#SiteName").val();
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question