grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

Improper Bg Repeat CSS Being Set

Open Coyote6 opened this issue 8 years ago • 4 comments

When importing components and initializing grapesjs, the css background-repeat property is being changed to background-repeat-x and background-repeat-y, which breaks on iOS.

Import components:

<div id="izmt">Test Begin<br />
<br />
<br />
<br />
Test End</div>
<style type="text/css">#izmt{background-image:url("/path/to/img.jpg");background-repeat:repeat-x;}
</style>

This is how it looks before:

Mobile mobile-before

Desktop desktop-before

Initialize GrapesJs, select an element, and then get the output code, and it comes back:

<div id="izmt">Test Begin<br />
<br />
<br />
<br />
Test End</div><style>* { box-sizing: border-box; } #izmt{background-image:url("/path/to/img.jpg");background-repeat-x:repeat;background-repeat-y:no-repeat;}</style>

This is how it is rendered after:

Mobile mobile-after

Desktop desktop-after

Coyote6 avatar May 01 '18 18:05 Coyote6

Thanks @Coyote6 we're already aware of this issue. This happens due to the browser's CSS parser and I can't do much about until there will be a possibility to attach custom CSS parsers, hope to implement it soon.

artf avatar May 03 '18 21:05 artf

Thanks. I added this to my storage manager function... I think it patches the problem for the time being... I am not quite awake yet, so please let me know if I messed something up.

var css = editor.getCss();

// Fix the JavaScript Parser for the background repeat.
var noRepeat = /background-repeat-x:no-repeat;background-repeat-y:no-repeat;/g;
var repeat = /background-repeat-x:repeat;background-repeat-y:repeat;/g;
var repeatX = /background-repeat-x:repeat;background-repeat-y:no-repeat;/g;
var repeatY = /background-repeat-x:no-repeat;background-repeat-y:repeat;/g;
css = css.replace(noRepeat, 'background-repeat:no-repeat;');
css = css.replace(repeat, 'background-repeat:repeat;');
css = css.replace(repeatX, 'background-repeat:repeat-x;');
css = css.replace(repeatY, 'background-repeat:repeat-y;');

Coyote6 avatar May 07 '18 13:05 Coyote6

From https://github.com/artf/grapesjs/releases/tag/v0.14.33 you can use custom CSS parsers, the first to be released is grapesjs-parser-postcss

artf avatar Oct 07 '18 23:10 artf

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

lock[bot] avatar Oct 07 '19 23:10 lock[bot]