Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When I set config.stylesSet in Custom javascript configuration in the Advanced options it has no effect.
For example :
config.stylesSet = [
{ name : 'CSS Style', element : 'span', attributes : { 'class' : 'my_style' } },
{ name : 'Marker: Yellow', element : 'span', styles : { 'background-color' : 'Yellow' } }
];
Comments
Comment #1
mkesicki CreditAttribution: mkesicki commentedTo add your style to style drop down / select box please use "Predefined styles " and/or "Predefined styles path " options from CKEditor's profile configuration ("CSS" tab). Styles should be defined in JavaScript file. Please read description of those options in profile configuration. If you have more question please ask.
Comment #2
syngi CreditAttribution: syngi commentedThis does work in the replace function, so I think it is misleading that it doesn't work there.
Comment #3
SammMoney CreditAttribution: SammMoney commentedAm I not able to use a css files.
I'm completely confused.
Perhaps someone could help me out here if I post some of the code I have?
Below is the code I want to to show in the drop down. What is it that I have to do for that CSS to show up?
Would it look like this?
Comment #4
seancr CreditAttribution: seancr commentedI'm having trouble with this too; I just posted on IRC:
<du> it seems like ckeditor isn't acknowledging the different ckeditor.styles.js file I'm specifying, - I can edit the default one and the changes get picked up - but that's it. I'm trying to have two different text formats with two different ckeditors and two different sets of styles
I have also tried adding styles, as the initial starter of this thread did, with no success. To me, it seems like you can either add your styles to the ckeditor.styles.js in the module directory or ... have nothing. I've been poking around and doing a little debugging, trying to narrow the problem down, and there are indicators that support this.
I've:
Comment #5
seancr CreditAttribution: seancr commentedPredefined Styles
Finally figured out by analyzing the CKEDITOR object in FireBug. If you add the following code to the "Custom JavaScript Configuration" it will load up different styles.
Here's a breakdown of how that code works, or at least the parts you'll (you, the user (not module developer)) need to change.
"name" is the name of a set of styles added via CKEDITOR.addStylesSet( ..., example:
This is similar to the default one, except, "drupal" is the default name.
Update: even though I was successful in accomplishing what I wanted, the forms on the CKEDITOR edit page do not appear to work correctly. Adding a path to different styles doesn't seem to make a difference.
Comment #6
Jorenm CreditAttribution: Jorenm commented@seancr's suggestion worked like a charm for me.
All of these other suggestions had my .js file loading properly, but I'd get a "Uncaught TypeError: Cannot read property 'length' of null" and the styles wouldn't appear. This was with the default styles copied into my own file.
Comment #7
altavis CreditAttribution: altavis commentedsorry, different version
Comment #8
kurtfoster CreditAttribution: kurtfoster commentedI have been trying to change the content of the Style list in CKEditor for a couple of hours, the only solution that works so far has been to change the ckeditor.js file, which is not ideal. I am a noob to CKEditor, if someone could explain in a bit more detail that would be great as I don't understand what seancr is doing that is making this work. I have tried adding
to config.js in the root folder of the ckeditor library but this has no effect. As i mentioned the only thing that actually changes the style is changing it in the main config file, then every time I upgrade to the new library I will have to do it all again. I know that the my style.js file works because when I make the change in ckeditor.js it works exactly as I want it to. I am desperate for any assistance as this is driving me crazy. thanks.
Comment #9
sgriffin CreditAttribution: sgriffin commentedCkeditor CSS predefined styles STILL do not work "at least in chrome" with the styles.js file provided in the latest dev version.
Uncaught TypeError: Cannot read property 'length' of null
Comment #10
sgriffin CreditAttribution: sgriffin commentedFigured it out. This error is if you try to use styles.js from the library instead of the MODULES ckeditor.style.js!
Comment #11
brycefisherfleig CreditAttribution: brycefisherfleig commented@sgriffin, I don't totally follow but I'm still having issues related to this. Can you post the relative paths that should and should NOT be used to reference ckeditor.style.js? Thanks so much!
Comment #12
sgriffin CreditAttribution: sgriffin commentedCopy and upload the styles.js from the ckeditor module folder to your theme folder... Not the styles.js from the download of ckeditor.
Comment #13
trkest CreditAttribution: trkest commentedHi
I had a similar issue but wanted the customer styles to be content editable via the JS injector module.
The solution was to define the path to the ckeditor.styles.js like this:
%hsites/default/files/js_injector/js_injector_3.js
Then start a JS injector rule (#3) like this:
if (typeof (CKEDITOR) !== 'undefined') {
CKEDITOR.addStylesSet( 'drupal',
[
/* Block Styles */
{ name: 'Demo: Info Description', element: 'div', attributes : { 'class' : 'infodescription' } },
{ name: 'Click for More', element : 'div', attributes : { 'class' : 'showcontent' } }
]);
}
My custom styles are now about 40 long allowing for tables, images, lists etc
hope this helps.
Comment #14
Agogo CreditAttribution: Agogo commentedOh god, sgriffin, you totaly nailed it in #10 and #12. Thanks alot for that info! I've been riping my hair out on this one!
Comment #15
4aficiona2 CreditAttribution: 4aficiona2 commentedThis is still an issue. Using CKEditor 4.4.7 (using the libraries module with a local version of CKEditor, not CDN linked one(default since version 7.x.-1.14)) and the CKEditor Drupal module, version 7.x-1.16.
After quite some debugging because my changes were not reflected in the styles dropdown I started to search for the terms "Marker" & "Yellow" which are kind of unique in my Drupal installation ... but they still showed up even after removing all the styles in the styles.js file (CKEditor JS library in sites/all/libraries) and in the ckeditor.styles.js file in the module directory (sites/all/modules/contrib/ckeditor).
The styles.js from sites/all/libraries which I copied before contained only two predefined styles but was for some reasons empty, depending on the configuration of the CSS settings of CKEditor (I assume it was when I specified the direct path to the file). When I used the default settings the dropdown still contained all the predefined styles.
So I searched in the filesystem for those terms (before mentioned, marker & yellow) but could not find those in the CKEditor context. So it was obviously not delivered from the filesystem. Clearing the caches with drush (dr cc all) plenty of times and truncating the DB cache tables did not change anything.
So I started with clearing the browser cache and renaming the files. This finally worked for me. And I copied the styles.js from the CKEditor lib download, not from the module directory.
Comment #16
jvolker CreditAttribution: jvolker commentedI copied the ckeditor.styles.js to my theme folder from the CKEditor module, but without luck.
But fortunately
renaming the fileclearing the browsers cache as mentioned by 4aficiona2 in #15 worked!