简体   繁体   中英

How to select an CKEditor toolbar item using javascript?

I'm implementing CKEditor on my iOS application,the problem is that i need to detect touches on the toolbar items.I have a UIWebView which displays the CKEditor 'demo.html' and one button for testing the procedure,when the button is clicked it fires a javascript function on the 'demo.html' file,the code is below:

Javascript from 'demo.html':

<script type="text/javascript">

    function mateus(){

        // SIMULATE TOUCH ON TOOLBAR ITEM

    }

    CKEDITOR.replace( 'editor1',
            {
                extraPlugins : 'uicolor',
                removePlugins: 'elementspath',
                toolbar :
                [
                    [ 'Bold', 'Italic', 'Underline','NumberedList','BulletedList']
                ]
});
</script>

UIButton action:

-(IBAction)buttonTester:(id)sender{

    [webView stringByEvaluatingJavaScriptFromString:@"mateus()"];

}

This part is working fine,the problem is,like i said before,i need to simulate the touch on the toolbar item and i don't know how to do such thing!

Simplifying:

How to select an CKEditor toolbar item using javascript?

EDIT ----------------------------------------------------------------------

I searched a bit more and i found in the CKEditor docs this snippet:

editorInstance.execCommand( 'bold' );

But i couldn't put it to work,here's my new try:

function mateus(){

            CKEDITOR.instances.editor1.execCommand('bold');

}

Finally i gotcha,as simple as look:

To select a toolbar item thought a javascript function simple use the following snippet:

function mateus(){

    //Desired item from toolbar, like:('Italic','Underline','Image');
    CKEDITOR.instances.editor1.execCommand('bold');

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM