user1234
user1234

Reputation:

How to convert JavaScript to jQuery

How can I convert the JavaScript code below to jQuery? I'm not a JavaScript or jQuery expert.

Here is the JavaScript code.

CKEDITOR.on('instanceReady', function( ev ) {
  var blockTags = ['div','h1','h2','h3','h4','h5','h6','p','pre','li','blockquote','ul','ol',
  'table','thead','tbody','tfoot','td','th',];

  for (var i = 0; i < blockTags.length; i++)
  {
     ev.editor.dataProcessor.writer.setRules( blockTags[i], {
        indent : false,
        breakBeforeOpen : true,
        breakAfterOpen : false,
        breakBeforeClose : false,
        breakAfterClose : true
     });
  }
});

Upvotes: 0

Views: 2659

Answers (2)

CSS
CSS

Reputation: 11

You could put it in the JQuery $(document).ready() function without having to change the code at all

$(document).ready(function() {
    CKEDITOR.on('instanceReady', function( ev ) {
      var blockTags = ['div','h1','h2','h3','h4','h5','h6','p','pre','li','blockquote','ul','ol','table','thead','tbody','tfoot','td','th',];

      for (var i = 0; i < blockTags.length; i++)
      {
         ev.editor.dataProcessor.writer.setRules( blockTags[i], {
            indent : false,
            breakBeforeOpen : true,
            breakAfterOpen : false,
            breakBeforeClose : false,
            breakAfterClose : true
         });
      }
    });
});

This will affect all instances of CKeditor if that is what you want.

Upvotes: 1

Willem Mulder
Willem Mulder

Reputation: 13994

I wouldn't change this to JQuery as it has nothing to do with the DOM, DOM manipulation or DOM traversal.

It's only configuring the CKEditor, and JQuery can't help with that...

Upvotes: 4

Related Questions