CKEditor: Check if elements path contains element with special attribute and value

StackOverflow https://stackoverflow.com/questions/23473492

  •  15-07-2023
  •  | 
  •  

سؤال

I have a CKEditor plugin and want to check, if the element at the current cursor position has a parent element with a special attribute and value.

I know, that I can check the path with editor.elementsPath().contains('tagname') but I not only want to check for the tagname but also for an attribute and an attributes value like tagname[attribute=value]. But it looks like this spelling does not work with the contains()function.

Any idea how to achive this?

هل كانت مفيدة؟

المحلول

You can pass evaluator function as a parameter of editor.elementPath().contains():

editor.elementPath().contains( function( element ) {        
    if ( element.is( 'tagname' ) && element.getAttribute( 'attribute' ) == 'value' )
        return true;
} ); // -> element or null
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top