Skip to content
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

HTML Config as option #130

Open
drveresh opened this issue Apr 8, 2020 · 12 comments
Open

HTML Config as option #130

drveresh opened this issue Apr 8, 2020 · 12 comments

Comments

@drveresh
Copy link

drveresh commented Apr 8, 2020

Hi,

Please add a new option "html=true" along with existing ones to render given notification text as HTML, mainly for bold, italic, and other basic and frequently used HTML tags.

Due to this limitation, current we cannot even do anything except passing plain text, and even want to embed a for spinner or loading icon and use it as a notification.

So, there are many use cases to render text as HTML, and I hope you consider this request.

Thanks.

@drveresh
Copy link
Author

drveresh commented Apr 8, 2020

Though there are some alternatives, it would be nice to achieve this in just one line like:
$.notify("My bold <b>HTML</b> message", {html: true});

@fglueck
Copy link

fglueck commented Apr 21, 2020

$.notify.defaults({ className: "info", position:"right", style: 'metro', autoHideDelay: 5000});
$.notify({
  title: 'title', text:'<h2 class="red">text</h2>'
})

Works fine for me.

@drveresh
Copy link
Author

Thanks, @fglueck, but for some reason, it didn't work for me. Can you please verify it here - https://jsfiddle.net/veeresh/3qywza57/16/ ?

@fglueck
Copy link

fglueck commented Jun 3, 2020

@drveresh there is no notify-metro loaded in your jsfiddle, so it can't run:

10:47:37.298 Beim Laden von "https://fiddle.jshell.net/veeresh/3qywza57/16/show/?editor_console=" wurde eine ungültige X-Frame-Options-Kopfzeile gefunden: "ALLOWALL" ist keine gültige Direktive.
show
10:47:37.389
TypeError: can't access property "addStyle", $.notify is undefined
notify-metro.js:1:1
10:47:37.398
uncaught exception: Missing style: metro notify.js:457:3

@drveresh
Copy link
Author

drveresh commented Jun 7, 2020

$.notify.defaults({ className: "info", position:"right", style: 'metro', autoHideDelay: 5000});
$.notify({
  title: 'title', text:'<h2 class="red">text</h2>'
})

Works fine for me.

I tried this, but now everything is empty without text, and below is the HTML when called:

<div class="notifyjs-corner" style="right: 0px; top: 45%;"><div class="notifyjs-wrapper notifyjs-hidable">
	<div class="notifyjs-arrow"></div>
	<div class="notifyjs-container" style=""><div class="notifyjs-bootstrap-base notifyjs-bootstrap-info">
<span data-notify-text=""></span>
</div></div>
</div></div>

@drveresh
Copy link
Author

drveresh commented Jun 7, 2020

@drveresh there is no notify-metro loaded in your jsfiddle, so it can't run:

10:47:37.298 Beim Laden von "https://fiddle.jshell.net/veeresh/3qywza57/16/show/?editor_console=" wurde eine ungültige X-Frame-Options-Kopfzeile gefunden: "ALLOWALL" ist keine gültige Direktive.
show
10:47:37.389
TypeError: can't access property "addStyle", $.notify is undefined
notify-metro.js:1:1
10:47:37.398
uncaught exception: Missing style: metro notify.js:457:3

It's there already, please double, both metro js and css are added. Here is the rebase version - https://jsfiddle.net/veeresh/3qywza57/

@drveresh
Copy link
Author

drveresh commented Jun 7, 2020

Even "$.notify('<h2 class="red">text</h2>');" should be working with title or with 'html' option if provided.

@stosef
Copy link

stosef commented Nov 17, 2020

Even "$.notify('<h2 class="red">text</h2>');" should be working with title or with 'html' option if provided.

With this code notify.js gets initialized with the default style, which is "bootstrap". The "bootstrap" style does not have the ability to render the content as HTML.

First you need to make sure that the "metro" style is loaded correctly (or any other style that supports HTML content). With the "metro" style loaded $.notify({ title: 'title', text:'<h2 class="red">text</h2>' }) will work.

@drveresh
Copy link
Author

@stosef, @fglueck, the fiddle https://jsfiddle.net/veeresh/3qywza57/ now has required libs, but still not working. Can you please clone it and make it work?

Notification with Bold/Italic/Links as part of the messages are very basic use cases and it will be better if it can be enabled by default or with an extra 'html' flag.

@stosef
Copy link

stosef commented Nov 24, 2020

There you go, with Metro style: https://jsfiddle.net/stosef/7ghdue5f/
If you want to use the regular Bootstrap style but with HTML instead of text: https://jsfiddle.net/stosef/bfmqyjak/

@drveresh
Copy link
Author

Thanks for the fix. My recommendation is to make the HTML message part of the core API itself by default, else we have to get/set the bootstrap class every time on page load.

@rokobuljan
Copy link

rokobuljan commented Apr 20, 2021

I created a pull request - seems like an easy addon.

// Use like:
$.notify("Lorem<br><b>Ipsum</b>", {encode: false});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants