Tinymce Angular7: Not loading custom css file via content_css property - css

How do I load custom CSS file to use with content_css property?
I have been searching around the web, but I can't seem to get the answer to this question or at least I couldn't understand it.
So I have a public editorConfig obj which gets called in the init function of the HTML
<editor
[init]="editorConfig"
[(ngModel)]="articleObj.text" name="text" id="text"
(ngModelChange)="onChangeWordCount()">
</editor >
public editorConfig = {
plugins: 'lists advlist image code media link table wordcount',
menubar: false,
statusbar: false,
branding: false,
browser_spellcheck: true,
content_css: 'src/assets/content.css',
This loads TinyMCE and my editor works great. I followed the docs and the scripts load with the lazy loading.
"assets": [
"src/favicon.ico",
"src/assets",
{ "glob": "**/*", "input": "node_modules/tinymce/skins", "output": "/skins/" },
{ "glob": "**/*", "input": "node_modules/tinymce/themes", "output": "/themes/" },
{ "glob": "**/*", "input": "node_modules/tinymce/plugins", "output": "/plugins/" }
],
However, I am not able to load my src/assets/content.css file. I keep getting a 404 (file not found).
I have added the path to my angular.json file
"styles": [
"src/styles.scss",
"src/assets/content.css"
],
--- Update ---
I updated the angular.json file:
"assets": [
"src/favicon.ico",
"src/assets",
{ "glob": "**/*", "input": "node_modules/tinymce/skins", "output": "/skins/" },
{ "glob": "**/*", "input": "node_modules/tinymce/themes", "output": "/themes/" },
{ "glob": "**/*", "input": "node_modules/tinymce/plugins", "output": "/plugins/" },
{ "glob": "**/*", "input": "src/assets", "output": "/src/assets" }
],
"styles": [
"src/styles.scss"
],
Then in the editor component, I am updating content_css property as:
content_css: 'src/assets/content.css',
Now the file is getting loaded and I am no longer getting a 404.
However, my CSS code doesn't seem to update the toolbar as I wanted. The change I was hoping for, was to change the toolbar background color.
CSS Code
/* toolbar */
.mce-toolbar-grp {
background-color:#efeeee !important; /* uses !important or override .mce-panel background-color/image */
background-image: none !important;
}
Which I got from here: Changing background toolbar colour and text colour in tinymce editor
In short, I am not sure if my CSS is wrong or is the configuration/loading of the file which is wrong.

Old question but for those interested, above fail is due to the fact that you can't use a scss here. You need to convert it to css before.

It looks like you are loading your content_css from a relative URL. When you enter a relative URL for content_css, it is resolved in relation to the URL of the HTML file that includes TinyMCE, not relative to TinyMCE itself (source).
So, your URL of src/assets/content.css is getting called as http://example.com/src/assets/content.css.
You can either set the content_css part of your config to where that CSS file will be after it is outputted from the bundler, or host that CSS file outside of the bundling process, and set its URL directly.

Related

angular 10: image url given from assets after `Ng build` is listing directly under `dist` folder and `dist->assets`

I found one scenario where images are getting listed directly under the dist folder after ng build.
I have created a sample angular app. Below are the details. Even the image is there inside the assets folder. It is getting copied directly under dist. This way, its getting duplicated which also causes build size increase.
How to avoid this? I need the image only under assets folder. Outside should be clean. Please help if anyone faced a similar issue.
project structure
angular.json
"myapp": {
"projectType": "application",
"schematics": {
"#schematics/angular:component": {
"style": "scss"
}
},
"root": "projects/myapp",
"sourceRoot": "projects/myapp/src",
"prefix": "app",
"architect": {
"build": {
"builder": "#angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/myapp",
"index": "projects/myapp/src/index.html",
"main": "projects/myapp/src/main.ts",
"polyfills": "projects/myapp/src/polyfills.ts",
"tsConfig": "projects/myapp/tsconfig.app.json",
"aot": true,
"assets": [
"projects/myapp/src/favicon.ico",
"projects/myapp/src/assets"
],
"styles": [
"projects/myapp/src/styles.scss",
"projects/myapp/src/assets/theme/victor-theme/style.scss"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "projects/myapp/src/environments/environment.ts",
"with": "projects/myapp/src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2mb",
"maximumError": "5mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "6kb",
"maximumError": "10kb"
}
]
}
}
},
CSS
.tree_status_ico:disabled {
opacity: 0.6;
background-size: 18px;
background: transparent url(assets/img/agg_status.svg) no-repeat center;
}
after ng build
I created a test project using Angular 12 and it seems that it does have the same issue. But I found a solution that should work:
background: transparent url("/assets/img/agg_status.svg") no-repeat center;
Can you try these 2 options?
"outputPath": "dist",
"resourcesOutputPath": "images"
https://angular.io/cli/build
When you are doing ng build what angular CLI is doing is performing AOT(Ahead of Time compilation) and converting your angular app code to HTML, CSS, and JS. That's what your dist folder has. The image you have in the asset folder will be linked to the HTML IMG tag and in src property you will be providing the image path which will be 'assets/imgName.jpg'. Thus the section of the compiled code will also be using the same image source URL. Thus you cant get rid of that folder coz doing so your app will break i.e The image won't be fetched since the assets folder is missing in dist. Now a possible solution to this problem is-
Publish your image online and use that link as the img src URL in the CSS file and delete the image from asset file.
Alternatively remove the "projects/myapp/src/assets" line in the assets array from the angular.json file and build the app again but to avoid your app failing simply copy-paste the assets file to dist file before publishing.
The Asset Array if you follow solution 2 will be
"assets": [
"projects/myapp/src/favicon.ico",
],

Load CSS files instead of inline css for verse on prem customizations

We need to customize IBM Verse on prem for our corporate design. The documentation show how to add customized inline css. But that's not maintainable for larger customizations. I want to load css files, that could be generated by sass for keeping development DRY.
I tried the following in the example from the official docs:
[
{
"name": "CSS Extension Sample",
"description": "The sample shows how to customize Verse UI",
"title": "CSS Extension Sample",
"extensions": [
{
"type": "com.ibm.verse.ext.css",
"name": "CSS extension sample",
"payload": {
"url": "{extensionPath}/samples/test.css"
}
}
],
"services": ["Verse"]
}
]
And I also did some experiments with css import like this:
"payload": {
"css": "#import url('{extensionPath}/samples/test.css');"
}
with corresponding include of the file in manifest.json
"web_accessible_resources": ["page.js", "applications.json", "style.css"]
But test.css doesn't get loaded. The code itself works when using inline css:
"payload": {
"css": ".ics-scbanner {background-color:green!important;}"
}
How can I load the css file instead of inline css?

Chrome background-color changing extension

I'm new to chrome extensions. My target is to develop simple extensions that changes the page background color on load.
I have problem which you can see in the picture.
The problem
The Folder locally
{
"manifest_version": 2,
"name": "My Cool Extension",
"version": "0.1"
}
"content_scripts": [
{
"css": [ "main.css" ],
"matches": [
"<all_urls>",
],
}
]
The Css
*{background-color:black}
How to solve the problem, where is my problem?

Material Styles are not being applied in angular app after being correctly imported

My problem is that my stylesheet are getting correctly included in the webpage, but the styles are not getting applied. The problem is as follows:
I am trying to use Angular material, i've correctly setup my app as was shown in the begginer's guide.
I inspected my app and the stylesheets are correctly getting imported (included). However, the styles are not being appplied.
A Screenshot of my network tab:
the application tab also tells that stylesheets have been applied:
I have tried to include the theme designs via three ways:
1) using #import "~#angular/material/prebuilt-themes/indigo-pink.css"; in styles.css
2) using link element in index.html like: <link href="node_modules/#angular/material/prebuilt-themes/indigo-pink.css" rel="stylesheet"> (it didnot worked out)
3) so i made an assets folder and placed all my files there like:
and then in my angular-cli.json file i have gulp configured like:
"assets": [
{ "glob": "**/*", "input": "./assets/Images/", "output": "./assets/Images/" },
{ "glob": "**/*", "input": "./assets/StyleSheets/", "output": "./assets/StyleSheets/" },
{ "glob": "**/*", "input": "./assets/Javascript/", "output": "./assets/Javascript/" },
{ "glob": "**/*", "input": "./assets/Json/", "output": "./assets/Json/" },
"favicon.ico"
]
and i included my stylesheet afterwards like: <link rel="stylesheet" type="text/css" href="assets/StyleSheets/deeppurple-amber.css"> and it worked.
However, when i tried to use the styles like:
<button md-raised-button color="primary">Click me!</button>
the styles were not getting applied.
please help me to find out what wrong am i doing.
And let me know if you need the repository link for re-producing the problem.
I had the same problem. I solved it putting the style in the angular-cli.json file:
"styles": [
"styles.scss",
"../node_modules/#angular/material/prebuilt-themes/indigo-pink.css"
],
There is a Bug in Angular Material I was able to fix it by remove '~' in import
#import "~#angular/material/prebuilt-themes/indigo-pink.css";
to
#import "#angular/material/prebuilt-themes/indigo-pink.css";

Adding CSS file to Chrome extension manifest not working

I'm attempting to get an external CSS file to load in Chrome. To do this, it would seem I have to edit an existing Chrome extension's manifest.json file and minimally add the following to the content_scripts node:
{
"css": [ "Theme.css" ]
}
From what I understand, this will add the Theme.css file (which is in the same root directory as the manifest.json file) to all pages accessed in Chrome. I saw that I could additionally qualify the json block by including a matches key-value pair, but I've omitted that here.
This doesn't appear to be working because I'm not seeing the styles. To start, my Theme.css file contains this:
span {
color: green !important;
}
Additionally, I've confirmed that the extension I added it to (AngularJS Batarang FWIW) is recognized as "Enabled" by Chrome.
I also tried the solution explained here where you load the CSS as an accessible resource via a JS file, but that doesn't work either.
What am I missing? Or is there an easier way to do this?
FWIW: here is the entire manifiest:
{
"background": {
"scripts": [ "background.js" ]
},
"content_scripts": [ {
"js": [ "inject.js" ],
"matches": [ "<all_urls>" ],
"run_at": "document_start"
}, {
"matches": [ "http://*/*", "https://*/*"],
"css": [ "Theme.css" ]
} ],
"description": "Extends the Developer Tools, adding tools for debugging and profiling AngularJS applications.",
"devtools_page": "devtoolsBackground.html",
"icons": {
"128": "img/webstore-icon.png",
"16": "img/webstore-icon.png",
"48": "img/webstore-icon.png"
},
"key": "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC9hsXx3+F75DyGto3mkm0FB2sycQzyMqXQAySn2Qj67vIHFMSrVZ0ItPzGnWJwoRoaDI7cQF9c/WLDpLJQwGe5CV5z84MueOME3e45JJEwN+YsW5ufEavmp+pk1c9h/Wyi8bMoSWJGIrOG72wCTFOdnyN6nocA0dm4w7UWsxLLEQIDAQAB",
"manifest_version": 2,
"minimum_chrome_version": "21.0.1180.57",
"name": "AngularJS Batarang",
"page_action": {
"default_icon": {
"19": "img/icon19.png",
"38": "img/icon38.png"
},
"default_title": "AngularJS Super-Powered"
},
"permissions": [ "tabs", "<all_urls>" ],
"update_url": "https://clients2.google.com/service/update2/crx",
"version": "0.10.6",
"web_accessible_resources": [ "dist/hint.js" ]
}
You have a problem with your content_scripts key, you should wrap your matches, css and js together under content_scripts key, like this:
"content_scripts": [
{
"matches": ["http://*/*"],
"css": ["./Theme.css"],
"js": ["./inject.js"]
}
],
Also, don't forget to write ./ before your CSS/JS File to point to your root directory!
You did not register any pages to apply the CSS file to. The matches section is required.
If you want to apply it to all pages, use "matches": ["<all_urls>"]

Resources