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

Add support for messages without title, straight text, other fixes. #24

Merged
merged 3 commits into from
Jun 4, 2012
Merged
Changes from 1 commit
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
Next Next commit
Add support for messages without title, minor cleanup.
  • Loading branch information
Thinkscape committed May 28, 2012
commit 8bc06099231c7338cd1a705f50a6e5ae84296715
21 changes: 14 additions & 7 deletions js/jquery.gritter.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
_item_count: 0,
_is_setup: 0,
_tpl_close: '<div class="gritter-close"></div>',
_tpl_item: '<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[close]][[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',
_tpl_title: '<span class="gritter-title">[[title]]</span>',
_tpl_item: '<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[close]][[image]]<div class="[[class_name]]">[[title]]<p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',
_tpl_wrap: '<div id="gritter-notice-wrapper"></div>',

/**
Expand All @@ -90,8 +91,8 @@
add: function(params){

// We might have some issues if we don't have a title or text!
if(!params.title || !params.text){
throw 'You need to fill out the first 2 params: "title" and "text"';
if(!params.text){
throw 'You must supply "text" parameter.';
}

// Check the options and set them once
Expand All @@ -100,12 +101,12 @@
}

// Basics
var user = params.title,
var title = params.title,
text = params.text,
image = params.image || '',
sticky = params.sticky || false,
item_class = params.class_name || $.gritter.options.class_name,
position = $.gritter.options.position,
position = $.gritter.options.position,
time_alive = params.time || '';

this._verifyWrapper();
Expand All @@ -131,9 +132,15 @@
class_name = (image != '') ? 'gritter-with-image' : 'gritter-without-image';

// String replacements on the template
if(title){
title = this_str_replace('[[title]]',title,this._tpl_title);
}else{
title = '';
}

tmp = this._str_replace(
['[[username]]', '[[text]]', '[[close]]', '[[image]]', '[[number]]', '[[class_name]]', '[[item_class]]'],
[user, text, this._tpl_close, image_str, this._item_count, class_name, item_class], tmp
['[[title]]', '[[text]]', '[[close]]', '[[image]]', '[[number]]', '[[class_name]]', '[[item_class]]'],
[title, text, this._tpl_close, image_str, this._item_count, class_name, item_class], tmp
);

// If it's false, don't show another gritter message
Expand Down