Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it( 'should be false when schema disallows image', () => {
model.schema.register( 'block', { inheritAllFrom: '$block' } );
model.schema.extend( 'paragraph', { allowIn: 'block' } );
// Block image in block.
model.schema.addChildCheck( ( context, childDefinition ) => {
if ( childDefinition.name === 'image' && context.last.name === 'block' ) {
return false;
}
} );
editor.conversion.for( 'downcast' ).elementToElement( { model: 'block', view: 'block' } );
setModelData( model, '[]' );
expect( command.isEnabled ).to.be.false;
} );
} );
it( 'should return null if figcaption\'s parent is not a figure', () => {
const element = new ViewElement( 'figcaption' );
new ViewElement( 'div', null, element ); // eslint-disable-line no-new
expect( matchImageCaption( element ) ).to.be.null;
} );
it( 'should return null if figcaption\'s parent is not a figure', () => {
const element = new ViewElement( 'figcaption' );
new ViewElement( 'div', null, element ); // eslint-disable-line no-new
expect( matchImageCaption( element ) ).to.be.null;
} );
it( 'should return null if parent has no image class', () => {
const element = new ViewElement( 'figcaption' );
new ViewElement( 'figure', null, element ); // eslint-disable-line no-new
expect( matchImageCaption( element ) ).to.be.null;
} );
it( 'should do nothing with an image when changes are in the other parent', () => {
setData(
view,
'foo<img src="/assets/sample.png">'
);
const viewP = viewRoot.getChild( 0 );
const viewDiv = viewRoot.getChild( 1 );
const mapSpy = sinon.spy( view.domConverter, 'mapViewToDom' );
// Change only the paragraph.
view.change( writer => {
const text = writer.createText( 'foo', { b: true } );
writer.insert( writer.createPositionAt( viewRoot.getChild( 0 ).getChild( 0 ), 0 ), text );
writer.wrap( writer.createRangeOn( text ), writer.createAttributeElement( 'b' ) );
} );
it( 'should return true when image widget is the only element in the selection', () => {
// We need to create a container for the element to be able to create a Range on this element.
frag = new ViewDocumentFragment( [ element ] );
const selection = writer.createSelection( element, 'on' );
expect( getSelectedImageWidget( selection ) ).to.equal( element );
} );
function testMediaUpcast( urls, expected ) {
for ( const url of urls ) {
editor.setData( `<figure class="media"><div data-oembed-url="${ url }"></div></figure>` );
const viewData = getViewData( view, { withoutSelection: true, renderUIElements: true } );
let expectedRegExp;
const expectedUrl = url.match( /^https?:\/\// ) ? url : 'https://' + url;
if ( expected ) {
expectedRegExp = new RegExp(
']+>' +
']+>' +
normalizeHtml( expected ) +
'' +
'' );
} else {
expectedRegExp = new RegExp(
']+>' +
']+>' +
'<div class="ck ck-media__placeholder ck-reset_all">' +</div>
form = document.createElement( 'form' );
textarea = document.createElement( 'textarea' );
form.appendChild( textarea );
document.body.appendChild( form );
submitStub = sinon.stub( form, 'submit' );
// Prevents page realods in Firefox ;|
form.addEventListener( 'submit', evt => {
evt.preventDefault();
} );
class CustomEditor extends Editor {}
mix( CustomEditor, ElementApiMixin );
editor = new CustomEditor();
editor.data.processor = new HtmlDataProcessor();
editor.model.document.createRoot();
editor.model.schema.extend( '$text', { allowIn: '$root' } );
editor.fire( 'ready' );
editor.data.set( 'foo bar' );
} );
constructor( sourceElementOrData, config ) {
super( config );
if ( isElement( sourceElementOrData ) ) {
this.sourceElement = sourceElementOrData;
}
// Use the HTML data processor in this editor.
this.data.processor = new HtmlDataProcessor();
// Create the ("main") root element of the model tree.
this.model.document.createRoot();
this.ui = new ClassicTestEditorUI( this, new BoxedEditorUIView( this.locale ) );
// Expose properties normally exposed by the ClassicEditorUI.
this.ui.view.editable = new InlineEditableUIView( this.ui.view.locale, this.editing.view );
}
constructor( config ) {
super( config );
// Use the HTML data processor in this editor.
this.data.processor = new HtmlDataProcessor();
// Create the ("main") root element of the model tree.
this.model.document.createRoot();
}