-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Providing fallback CSS for inlinetoolbar #1136
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manual test is failing, inline toolbar is not working:
Also I don't think copying whole skin for test is a good idea, maybe it will be possible to overwrite appendStyleSheet
method to just not load skin CSS file for inlinetoolbar
?
This task is about inlinetoolbar
and from what I recall the default CSS was supposed to be added only for inlinetoolbar
plugin. If there are some additional styles from balloonpanel
needed they probably should be placed in inlinetoolbar
CSS file too.
Would it be possible to add unit test, which checks if specific styling was applied to inline toolbar (so basically two test, one with default CSS and one with skin)?
@@ -0,0 +1,61 @@ | |||
/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simply name this file default.css
as it is already in the inlinetoolbar
directory so the prefix seems redundant.
<p> </p> | ||
<p> </p> | ||
</div> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also add inline editor here.
@mlewand what do you think about that?
Inline toolbar inheritance styles from balloon panel related to:
|
I haven't notice that after rebase there was change in API so I have to prepare 2 separate test suites with css. Unfortunately skins cannot be changed after loading, so I have to made proper thing at the very begging of each test suite. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there are some failing tests in Edge/IE realm:
Edge/IE11/IE10
IE9
And manual one as it seems default CSS is always used:
IE8
And manual to as the default skin CSS seems to be always used over specific skin CSS:
The manual tests on which I checked how default CSS works with specific skin are tests/plugins/inlinetoolbar/manual/[kama|moono|moono-lisa]
.
|
||
( function() { | ||
'use strict'; | ||
// Please be aware that entire test suite has to use the same skin. That's why tests are separate between 2 files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is unnecessary. As it makes sense in the context of the whole PR, when someone will look at the test itself its lacks this context (same for the other test).
} | ||
}; | ||
|
||
// We need to set up skin at the very beginning befor files start to load. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo "before".
// Overwrite prototype to simulate missing css file. | ||
var oldFn = CKEDITOR.dom.document.prototype.appendStyleSheet; | ||
CKEDITOR.dom.document.prototype.appendStyleSheet = function( cssFileUrl ) { | ||
// Simualate missing css in skin. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in "Simulate".
if ( cssFileUrl.indexOf( 'inlinetoolbar.css' ) > -1 || cssFileUrl.indexOf( 'balloonpanel.css' ) > -1 ) { | ||
cssFileUrl = ''; | ||
} | ||
oldFn.call( CKEDITOR.document, cssFileUrl ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could simplify it a little:
if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) {
oldFn.call( CKEDITOR.document, cssFileUrl );
}
no need to call original function with empty file path.
CKEDITOR.skinName = 'moono'; | ||
|
||
var tests = { | ||
'test check default css usage': function( editor ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be test check specific|moono skin css usage
?
cssFileUrl = ''; | ||
} | ||
|
||
if ( this.$.createStyleSheet ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't you use call to original function here same as in unit test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it earlier with stub and forget about it. I think option with calling origin function is simpler, and can be resistant for possible method changes.
I've update this to looks like in Unit test.
@bender-ckeditor-plugins: wysiwygarea,toolbar,basicstyles,floatingspace,inlinetoolbar,link,image,resize,language,stylescombo | ||
|
||
Perform below steps in both editors: | ||
1. Click into image. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Click on image or just Click image.
As I talk with @mlewand we currently should focus on most popular browsers, and older IE left for further improvements. That's why I ignore tests on IE below 11.
Those are also happen on t/933 without introducing I have add different assertion for the IE envs to have sure that "transparent" will be matched. I also a little tune our tools method, which converts rgb to hex to also support rgba. If you consider it as separate issue, give me an info I'll extract it, but this might extend realisation of this issue. As this introduce dependancy here. Another option would be creating specific function just for those test purposes, but I'm not think is a good option, because this will duplicate the code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I talk with @mlewand we currently should focus on most popular browsers, and older IE left for further improvements. That's why I ignore tests on IE below 11.
👍
Additional info, all those errors which looks like default.css are used in IE8 (...) are also happen on t/933 without introducing default.css.
Ok, haven't checked that, in this case it ok to leave it as is 👍
I also a little tune our tools method, which converts rgb to hex to also support rgba. If you consider it as separate issue, give me an info I'll extract it, but this might extend realisation of this issue.
It should be extracted, because it affects much wider part of the code. convertRgbToHex
method is used together with CSS normalization which is used in many places in CKEditor. Also you can see that one unit test is failing:
The other problem is that your solution just ignores the alpha part, always producing hex
representation from rgb
part. But two colors with different transparency (e.g. rgba(150, 150, 150, 1)
and rgba(150, 150, 150, 0.5)
) are just different colors and their hex
representation is also different.
Another option would be creating specific function just for those test purposes, but I'm not think is a good option, because this will duplicate the code.
Usually it is not the best approach, however I would go this way in this case. As we need this specific functionality only in this test you could create a function which will filter rgba
and pass only rgb
to convertRgbToHex
function (regex or some split/replace).
You could extract it to some helper as it will be used in both unit tests. I would also place appendStyleSheet
stub (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-497cd1ab5d84223f82e739984c6dd387R64) in this helper file as it is also used in two test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there;)
margin-left: -20px; | ||
} | ||
|
||
.cke_balloon.cke_inlinetoolbar |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same selector as in line 6 (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-a222e1835c2e1c3b856fdaf98d45e2faR6), it should be merged into one rule.
} | ||
|
||
/* align: [ hcenter ] */ | ||
.cke_balloon.cke_inlinetoolbar .cke_balloon_triangle_outer.cke_balloon_triangle_align_hcenter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same selector as in line 28 (https://github.com/ckeditor/ckeditor-dev/pull/1136/files#diff-a222e1835c2e1c3b856fdaf98d45e2faR28), it should be merged into one rule.
|
||
'use strict'; | ||
|
||
function replaceAppendStyleSheet() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, however it doesn't provide a possibility to clean up after running tests (restore original function). You could do two things:
- This function might return a function which will restore original one when called:
return function() {
CKEDITOR.dom.document.prototype.appendStyleSheet = oldFn;
}
- Use sinon stub which has
stub.restore()
method.
It is good practise to always clean up after test run (especially for unit tests, for manual you may skip it). So after changing it, please add clean up to unit test (you may use tearDown
function).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I decided to not use sinon.stub
, because I wasn't able to find possibility to fire origin function within stub.
In documentation I found only possibility how to replace the method, with own function.
That's why I wrote some similar wrapper which could execute native method. I'll extend it a little bit to restore native method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works fine but it's a little over complicated for me. You have to create new instance, it has two methods which you have to call, etc. plus you reinvented a wheel (well, a part of it:D).
In documentation I found only possibility how to replace the method, with own function.
That's exactly where you can call the original function, the stub could look like this:
function stubAppendStyleSheet() {
var originFn = CKEDITOR.dom.document.prototype.appendStyleSheet;
return sinon.stub( CKEDITOR.dom.document.prototype, 'appendStyleSheet', function( cssFileUrl ) {
// Simulate missing css in skin.
if ( !cssFileUrl.match( /(inlinetoolbar|balloonpanel)\.css/ ) ) {
originFn.call( CKEDITOR.document, cssFileUrl );
}
} );
}
and then you can use it like:
var stub = stubAppendStyleSheet();
CKEDITOR.once( 'instanceReady', stub.restore );
It is shorter and simpler IMHO. Plus for everybody who knows sinon
, you just take a look at the usage and it should be clear that these two lines stubs appendStyleSheet
method and then restores it. With custom code you always have to dive in to check what's going on.
I can use neither |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check this comment: #1136 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
…d intgrate everything inside inlinetoolbar.
Providing fallback CSS for inlinetoolbar
What is the purpose of this pull request?
Bug fix
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
inlinetoolbar
andballoonpanel
(inline toolbar require it to proper work). CSS base on moono-lisa skin.I thought to force loading
moono-lisa
as fallback, but it might be confusing if user will remove those css folders thinking that are unnecessary for his configuration. That's why I add-default
suffix and separate files.