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

allow image_html option #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion css/jquery.gritter.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
display:block;
text-shadow:1px 1px 0 #000; /* Not supported by IE :( */
}
.gritter-image {
.gritter-image,
.gritter-custom-image {
width:48px;
height:48px;
float:left;
Expand Down
16 changes: 16 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ <h1>Gritter Demo</h1>
<li>
<a href="#" id="add-without-image">Add notification without image</a>
</li>
<li>
<a href="#" id="add-custom-image">Add notification with custom HTML for the image</a>
</li>
<li>
<a href="#" id="add-gritter-light">Add a white notification</a>: has a 'gritter-light' class_name applied to it.
</li>
Expand Down Expand Up @@ -165,6 +168,19 @@ <h1>Gritter Demo</h1>

return false;
});

$('#add-custom-image').click(function(){

$.gritter.add({
// (string | mandatory) the heading of the notification
title: 'This is a notice with custom HTML in the image area!',
// (string | mandatory) the text inside the notification
text: 'This will fade out after a certain amount of time. Vivamus eget tincidunt velit. Cum sociis natoque penatibus et <a href="#" style="color:#ccc">magnis dis parturient</a> montes, nascetur ridiculus mus.',
image_html: '<div class="custom-image" style="height:100%; background:green; text-align:center">custom HTML</div>'
});

return false;
});

$('#add-gritter-light').click(function(){

Expand Down
8 changes: 7 additions & 1 deletion js/jquery.gritter.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
var title = params.title,
text = params.text,
image = params.image || '',
image_html = params.image_html || '',
sticky = params.sticky || false,
item_class = params.class_name || $.gritter.options.class_name,
position = $.gritter.options.position,
Expand All @@ -133,7 +134,12 @@
}

var image_str = (image != '') ? '<img src="' + image + '" class="gritter-image" />' : '',
class_name = (image != '') ? 'gritter-with-image' : 'gritter-without-image';
class_name = (image != '' || image_html != '') ? 'gritter-with-image' : 'gritter-without-image';

// Check for custom image html override. If it exists, insert it instead of our generated IMG tag.
if(image_html !== ''){
image_str = '<div class="gritter-custom-image">' + image_html + '</div>'
}

// String replacements on the template
if(title){
Expand Down