commit 49319a08905fe6eb70a437ca5454df3f2a7497e6 Author: Messerbill Date: Sat Jun 13 15:39:04 2015 +0200 added lib/bootstrap_growl diff --git a/autoload.inc b/autoload.inc new file mode 100644 index 0000000..7e21dd5 --- /dev/null +++ b/autoload.inc @@ -0,0 +1,3 @@ + [:minify] + +desc "coffee2js" +task :coffee2js do + coffee2js +end + +desc "Minify" +task :minify do + minify +end + +desc "Build" +task :build do + coffee2js + minify +end + +# method definitions + +def coffee2js + begin + require 'coffee-script' + rescue LoadError => e + if verbose + puts "\nYou'll need the 'coffee-script' gem for translate the coffeescript file to js. Just run:\n\n" + puts " $ gem install coffee-script" + puts "\nand you should be all set.\n\n" + exit + end + return false + end + puts "Translating jquery.bootstrap-growl.coffee to jquery.bootstrap-growl.js..." + File.open("jquery.bootstrap-growl.js", "w") do |f| + f.puts CoffeeScript.compile(File.read("jquery.bootstrap-growl.coffee")) + end +end + +def minify + begin + require 'uglifier' + rescue LoadError => e + if verbose + puts "\nYou'll need the 'uglifier' gem for minification. Just run:\n\n" + puts " $ gem install uglifier" + puts "\nand you should be all set.\n\n" + exit + end + return false + end + puts "Minifying jquery.bootstrap-growl.js with UglifyJS..." + File.open("jquery.bootstrap-growl.min.js", "w") do |f| + f.puts Uglifier.new.compile(File.read("jquery.bootstrap-growl.js")) + end +end + diff --git a/lib/composer.json b/lib/composer.json new file mode 100644 index 0000000..4726b65 --- /dev/null +++ b/lib/composer.json @@ -0,0 +1,8 @@ +{ + "name": "ifightcrime/bootstrap-growl", + "description": "Pretty simple jQuery plugin that turns standard Bootstrap alerts into 'Growl-like' notifications.", + "keywords": ["bootstrap", "growl", "notifications"], + "homepage": "https://github.com/ifightcrime/bootstrap-growl", + "author": "Nick Larson", + "license": "MIT" +} \ No newline at end of file diff --git a/lib/demo.html b/lib/demo.html new file mode 100644 index 0000000..bb69378 --- /dev/null +++ b/lib/demo.html @@ -0,0 +1,43 @@ + + + + jquery.bootstrap-growl Demo + + + + + + + + + + + + diff --git a/lib/jquery.bootstrap-growl.coffee b/lib/jquery.bootstrap-growl.coffee new file mode 100644 index 0000000..6dd3048 --- /dev/null +++ b/lib/jquery.bootstrap-growl.coffee @@ -0,0 +1,73 @@ +# https://github.com/ifightcrime/bootstrap-growl + +$ = jQuery + +$.bootstrapGrowl = (message, options) -> + options = $.extend({}, $.bootstrapGrowl.default_options, options) + + $alert = $("
") + $alert.attr "class", "bootstrap-growl alert" + $alert.addClass "alert-" + options.type if options.type + if options.allow_dismiss + $alert.addClass "alert-dismissible" + $alert.append "" + + $alert.append message + + # Prevent BC breaks + if options.top_offset + options.offset = + from: "top" + amount: options.top_offset + + # calculate any 'stack-up' + offsetAmount = options.offset.amount + $(".bootstrap-growl").each -> + offsetAmount = Math.max(offsetAmount, parseInt($(this).css(options.offset.from)) + $(this).outerHeight() + options.stackup_spacing) + + css = + "position": (if options.ele is "body" then "fixed" else "absolute") + "margin": 0 + "z-index": "9999" + "display": "none" + + css[options.offset.from] = offsetAmount + "px" + + $alert.css css + + $alert.css "width", options.width + "px" if options.width isnt "auto" + + # have to append before we can use outerWidth() + $(options.ele).append $alert + + switch options.align + when "center" + $alert.css + "left": "50%" + "margin-left": "-#{$alert.outerWidth() / 2}px" + when "left" + $alert.css "left", "20px" + else + $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 -> + $(this).alert "close" + + $alert + +$.bootstrapGrowl.default_options = + ele: "body" + type: "info" + offset: + from: "top" + amount: 20 + align: "right" # (left, right, or center) + width: 250 + delay: 4000 + allow_dismiss: true + stackup_spacing: 10 + diff --git a/lib/jquery.bootstrap-growl.js b/lib/jquery.bootstrap-growl.js new file mode 100644 index 0000000..b396ba8 --- /dev/null +++ b/lib/jquery.bootstrap-growl.js @@ -0,0 +1,77 @@ +(function() { + var $; + + $ = jQuery; + + $.bootstrapGrowl = function(message, options) { + var $alert, css, offsetAmount; + options = $.extend({}, $.bootstrapGrowl.default_options, options); + $alert = $("
"); + $alert.attr("class", "bootstrap-growl alert"); + if (options.type) { + $alert.addClass("alert-" + options.type); + } + if (options.allow_dismiss) { + $alert.addClass("alert-dismissible"); + $alert.append(""); + } + $alert.append(message); + if (options.top_offset) { + options.offset = { + from: "top", + amount: options.top_offset + }; + } + offsetAmount = options.offset.amount; + $(".bootstrap-growl").each(function() { + return offsetAmount = Math.max(offsetAmount, parseInt($(this).css(options.offset.from)) + $(this).outerHeight() + options.stackup_spacing); + }); + css = { + "position": (options.ele === "body" ? "fixed" : "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"); + } + $(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(); + if (options.delay > 0) { + $alert.delay(options.delay).fadeOut(function() { + return $(this).alert("close"); + }); + } + return $alert; + }; + + $.bootstrapGrowl.default_options = { + ele: "body", + type: "info", + offset: { + from: "top", + amount: 20 + }, + align: "right", + width: 250, + delay: 4000, + allow_dismiss: true, + stackup_spacing: 10 + }; + +}).call(this); diff --git a/lib/jquery.bootstrap-growl.min.js b/lib/jquery.bootstrap-growl.min.js new file mode 100644 index 0000000..67837e5 --- /dev/null +++ b/lib/jquery.bootstrap-growl.min.js @@ -0,0 +1 @@ +(function(){var c;c=jQuery;c.bootstrapGrowl=function(f,a){var b,e,d;a=c.extend({},c.bootstrapGrowl.default_options,a);b=c("
");b.attr("class","bootstrap-growl alert");a.type&&b.addClass("alert-"+a.type);a.allow_dismiss&&(b.addClass("alert-dismissible"),b.append(''));b.append(f);a.top_offset&&(a.offset={from:"top",amount:a.top_offset});d=a.offset.amount;c(".bootstrap-growl").each(function(){return d= Math.max(d,parseInt(c(this).css(a.offset.from))+c(this).outerHeight()+a.stackup_spacing)});e={position:"body"===a.ele?"fixed":"absolute",margin:0,"z-index":"9999",display:"none"};e[a.offset.from]=d+"px";b.css(e);"auto"!==a.width&&b.css("width",a.width+"px");c(a.ele).append(b);switch(a.align){case "center":b.css({left:"50%","margin-left":"-"+b.outerWidth()/2+"px"});break;case "left":b.css("left","20px");break;default:b.css("right","20px")}b.fadeIn();0github commit';}}