Skip to content

Commit

Permalink
issue #12. fix growls to top of screen by default, unless ele is set …
Browse files Browse the repository at this point in the history
…to something other than 'body'
  • Loading branch information
longlostnick committed Jan 22, 2013
1 parent 40a56a4 commit d3edb2a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 89 deletions.
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ task :minify do
end
return false
end
puts "Minifying touch-sroll.js with UglifyJS..."
File.open("jquery.bootstrap-growl.min.js", "w"){|f| f.puts Uglifier.new.compile(File.read("jquery.bootstrap-growl.js"))}
file = "jquery.bootstrap-growl.js"
puts "Minifying #{file} with UglifyJS..."
File.open(file, "w"){|f| f.puts Uglifier.new.compile(File.read("jquery.bootstrap-growl.js"))}
end
87 changes: 1 addition & 86 deletions jquery.bootstrap-growl.js
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="#">&times;</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);
;
2 changes: 1 addition & 1 deletion jquery.bootstrap-growl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d3edb2a

Please sign in to comment.