-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #12. fix growls to top of screen by default, unless ele is set …
…to something other than 'body'
- Loading branch information
1 parent
40a56a4
commit d3edb2a
Showing
3 changed files
with
5 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1 @@ | ||
/* https://github.com/ifightcrime/bootstrap-growl */ | ||
|
||
|
||
(function($) { | ||
$.bootstrapGrowl = function(message, options) { | ||
|
||
var options = $.extend({}, $.bootstrapGrowl.default_options, options); | ||
|
||
var $alert = $('<div>'); | ||
|
||
$alert.attr('class', 'bootstrap-growl alert'); | ||
|
||
if (options.type) { | ||
$alert.addClass('alert-' + options.type); | ||
} | ||
|
||
if (options.allow_dismiss) { | ||
$alert.append('<a class="close" data-dismiss="alert" href="#">×</a>'); | ||
} | ||
|
||
$alert.append(message); | ||
|
||
// Prevent BC breaks | ||
if (options.top_offset) { | ||
options.offset = {from: 'top', amount: options.top_offset}; | ||
} | ||
var current = $('.bootstrap-growl', options.ele); | ||
|
||
// calculate any 'stack-up' | ||
var offsetAmount = options.offset.amount; | ||
$.each(current, function() { | ||
offsetAmount = Math.max(offsetAmount, parseInt($(this).css(options.offset.from)) + $(this).outerHeight() + options.stackup_spacing); | ||
}); | ||
|
||
css = { | ||
'position': 'absolute', | ||
'margin': 0, | ||
'z-index': '9999', | ||
'display': 'none' | ||
}; | ||
css[options.offset.from] = offsetAmount + 'px'; | ||
$alert.css(css); | ||
|
||
if (options.width !== 'auto') { | ||
$alert.css('width', options.width + 'px'); | ||
} | ||
|
||
// have to append before we can use outerWidth() | ||
$(options.ele).append($alert); | ||
|
||
switch(options.align) { | ||
case 'center': | ||
$alert.css({ | ||
'left': '50%', | ||
'margin-left': '-' + ($alert.outerWidth() / 2) + 'px' | ||
}); | ||
break; | ||
case 'left': | ||
$alert.css('left', '20px'); | ||
break; | ||
default: | ||
$alert.css('right', '20px'); | ||
} | ||
|
||
$alert.fadeIn(); | ||
// Only remove after delay if delay is more than 0 | ||
if(options.delay >= 0){ | ||
$alert.delay(options.delay).fadeOut('slow', function() { | ||
$(this).remove(); | ||
}); | ||
} | ||
|
||
}; | ||
|
||
$.bootstrapGrowl.default_options = { | ||
ele: 'body', | ||
type: null, | ||
offset: {from: 'top', amount: 20}, | ||
align: 'right', // (left, right, or center) | ||
width: 250, | ||
delay: 4000, | ||
allow_dismiss: true, | ||
stackup_spacing: 10 | ||
}; | ||
|
||
})(jQuery); | ||
; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.