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

feat: 🗑️ add warning when using deprecated html setting #99

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions js/toasts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@
*/
this.options = $.extend({}, Toast.defaults, options);
this.htmlMessage = this.options.html;
// Warn when using html
if (!!this.options.html)
console.warn(
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
);
// If the new unsafeHTML is used, prefer that
if (!!this.options.unsafeHTML){
if (!!this.options.unsafeHTML) {
this.htmlMessage = this.options.unsafeHTML;
}
this.message = this.options.text;
Expand Down Expand Up @@ -205,9 +210,11 @@
this.htmlMessage !== null &&
this.htmlMessage.nodeType === 1 &&
typeof this.htmlMessage.nodeName === 'string'
) { //if the htmlMessage is an HTML node, append it directly
) {
//if the htmlMessage is an HTML node, append it directly
toast.appendChild(this.htmlMessage);
} else if (!!this.htmlMessage.jquery) { // Check if it is jQuery object, append the node
} else if (!!this.htmlMessage.jquery) {
// Check if it is jQuery object, append the node
$(toast).append(this.htmlMessage[0]);
} else {
// Append as unsanitized html;
Expand Down
8 changes: 6 additions & 2 deletions js/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,14 @@

_setTooltipContent(tooltipContentEl) {
tooltipContentEl.textContent = this.options.text;
if (!!this.options.html){
if (!!this.options.html) {
// Warn when using html
console.warn(
'The html option is deprecated and will be removed in the future. See https://github.com/materializecss/materialize/pull/49'
);
$(tooltipContentEl).append(this.options.html);
}
if (!!this.options.unsafeHTML){
if (!!this.options.unsafeHTML) {
$(tooltipContentEl).append(this.options.unsafeHTML);
}
}
Expand Down
13 changes: 9 additions & 4 deletions test/html/tooltip.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,23 @@
<body>

<div class="container">
<a class="btn tooltipped" data-position="bottom" data-tooltip="I am a tooltip">Hover me!</a>
<a class="btn tooltipped" data-position="bottom" data-tooltip="<span class='color: red'>I am a tooltip</span>">Hover me!</a>
<a class="btn tooltipped" data-position="bottom">unsafeHTML</a>
<a class="btn tooltipped" data-position="bottom">html</a>
<a class="btn tooltipped" data-position="bottom">text</a>
<a class="btn tooltipped" data-position="bottom" data-tooltip="<span class='color: red'>I am a tooltip</span>">data-tooltip</a>
</div>

<!-- Scripts-->
<script src="../../bin/materialize.js"></script>
<script type="text/javascript">
document.addEventListener('DOMContentLoaded', function () {
var elems = document.querySelectorAll('.tooltipped');
var instances = M.Tooltip.init(elems, {unsafeHTML: "<span class='color: red'>I am a tooltip</span>"});
var instances = M.Tooltip.init(elems[0], {unsafeHTML: "<span class='color: red'>I am a tooltip</span>"});
var instances = M.Tooltip.init(elems[1], {html: "<span class='color: red'>I am a tooltip</span>"});
var instances = M.Tooltip.init(elems[2], {text: "<span class='color: red'>I am a tooltip</span>"});
var instances = M.Tooltip.init(elems[3]);
});
</script>
</body>

</html>
</html>