added lib/bootstrap_growl

This commit is contained in:
Messerbill 2015-06-13 15:39:04 +02:00
commit 49319a0890
11 changed files with 358 additions and 0 deletions

3
autoload.inc Normal file
View File

@ -0,0 +1,3 @@
<?php
\SYSTEM\autoload::registerFolder(dirname(__FILE__),'LIB');
\LIB\lib_controll::register('\LIB\lib_bootstrap_growl');

21
lib/LICENSE.md Normal file
View File

@ -0,0 +1,21 @@
The MIT License
Copyright (c) Nick Larson, http://github.com/ifightcrime
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

51
lib/README.md Normal file
View File

@ -0,0 +1,51 @@
#bootstrap-growl
Pretty simple jQuery plugin that turns standard Bootstrap alerts into hovering "Growl-like" notifications.
##Demo
I have a basic demo set up at jsfiddle for the time being which you can view here: http://jsfiddle.net/ifightcrime/Us6WX/1008/
##Features
* Uses standard [Twitter Bootstrap alerts](http://twitter.github.com/bootstrap/components.html#alerts) which provides 'info', 'danger', and 'success' styles.
* Multiple growls called consecutively are stacked up one after another in a list.
* Automatically fades growls away after a default of 4 seconds.
##Dependencies
1. Latest version of jQuery. (tested on 1.11.0)
2. [Twitter Bootstrap](http://twitter.github.com/bootstrap/index.html). (current rev tested with 3.3.1)
##Usage
Include the dependencies and `jquery.bootstrap-growl.min.js` into your page and call the following:
```javascript
$.bootstrapGrowl("My message");
```
##Available Options
By default, growls use the standard 'alert' Bootstrap style, are 250px wide, right aligned, and are positioned 20px from the top right of the page.
```javascript
$.bootstrapGrowl("another message, yay!", {
ele: 'body', // which element to append to
type: 'info', // (null, 'info', 'danger', 'success')
offset: {from: 'top', amount: 20}, // 'top', or 'bottom'
align: 'right', // ('left', 'right', or 'center')
width: 250, // (integer, or 'auto')
delay: 4000, // Time while the message will be displayed. It's not equivalent to the *demo* timeOut!
allow_dismiss: true, // If true then will display a cross to close the popup.
stackup_spacing: 10 // spacing between consecutively stacked growls.
});
```
Note: Previous ```top_offset``` is not broken by this latest change.
##Additional Contributors
* Jose Martinez https://github.com/callado4
* Lloyd Watkin https://github.com/lloydwatkin
* TruongSinh Tran-Nguyen https://github.com/tran-nguyen

57
lib/Rakefile Normal file
View File

@ -0,0 +1,57 @@
# special thanks to https://github.com/tuupola/jquery_lazyload for this cool Rakefile
task :default => [: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

8
lib/composer.json Normal file
View File

@ -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"
}

43
lib/demo.html Normal file
View File

@ -0,0 +1,43 @@
<!DOCTYPE html>
<html>
<head>
<title>jquery.bootstrap-growl Demo</title>
<link rel="stylesheet" type="text/css" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
</head>
<body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<script src="jquery.bootstrap-growl.js"></script>
<script type="text/javascript">
$(function() {
$.bootstrapGrowl("This is a test.");
setTimeout(function() {
$.bootstrapGrowl("This is another test.", { type: 'success' });
}, 1000);
setTimeout(function() {
$.bootstrapGrowl("Danger, Danger!", {
type: 'danger',
align: 'center',
width: 'auto',
allow_dismiss: false
});
}, 2000);
setTimeout(function() {
$.bootstrapGrowl("Danger, Danger!", {
type: 'info',
align: 'left',
stackup_spacing: 30
});
}, 3000);
});
</script>
</body>
</html>

View File

@ -0,0 +1,73 @@
# https://github.com/ifightcrime/bootstrap-growl
$ = jQuery
$.bootstrapGrowl = (message, options) ->
options = $.extend({}, $.bootstrapGrowl.default_options, options)
$alert = $("<div>")
$alert.attr "class", "bootstrap-growl alert"
$alert.addClass "alert-" + options.type if options.type
if options.allow_dismiss
$alert.addClass "alert-dismissible"
$alert.append "<button class=\"close\" data-dismiss=\"alert\" type=\"button\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>"
$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

View File

@ -0,0 +1,77 @@
(function() {
var $;
$ = jQuery;
$.bootstrapGrowl = function(message, options) {
var $alert, css, offsetAmount;
options = $.extend({}, $.bootstrapGrowl.default_options, options);
$alert = $("<div>");
$alert.attr("class", "bootstrap-growl alert");
if (options.type) {
$alert.addClass("alert-" + options.type);
}
if (options.allow_dismiss) {
$alert.addClass("alert-dismissible");
$alert.append("<button class=\"close\" data-dismiss=\"alert\" type=\"button\"><span aria-hidden=\"true\">&times;</span><span class=\"sr-only\">Close</span></button>");
}
$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);

1
lib/jquery.bootstrap-growl.min.js vendored Normal file
View File

@ -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("<div>");b.attr("class","bootstrap-growl alert");a.type&&b.addClass("alert-"+a.type);a.allow_dismiss&&(b.addClass("alert-dismissible"),b.append('<button class="close" data-dismiss="alert" type="button"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>'));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();0<a.delay&&b.delay(a.delay).fadeOut(function(){return c(this).alert("close")}); return b};c.bootstrapGrowl.default_options={ele:"body",type:"info",offset:{from:"top",amount:20},align:"right",width:250,delay:4E3,allow_dismiss:!0,stackup_spacing:10}}).call(this);

15
lib/package.json Normal file
View File

@ -0,0 +1,15 @@
{
"name": "bootstrap-growl",
"description": "Pretty simple jQuery plugin that turns standard Bootstrap alerts into hovering 'Growl-like' notifications.",
"version": "0.0.1",
"license": "MIT",
"homepage": "http://ifightcrime.github.io/bootstrap-growl",
"author": { "name": "Nick Larson" },
"main": "jquery.bootstrap-growl.js",
"repositories": [
{
"type": "git",
"url": "http://github.com/ifightcrime/bootstrap-growl"
}
]
}

9
lib_bootstrap_growl.php Normal file
View File

@ -0,0 +1,9 @@
<?php
namespace LIB;
class lib_bootstrap_growl extends \LIB\lib_js{
public static function get_class(){
return self::class;}
public static function js_path(){
return \SYSTEM\WEBPATH(new \SYSTEM\PLIB(),'bootstrap-growl/lib/animate.min.css');}
public static function version(){
return '<a href="https://github.com/ifightcrime/bootstrap-growl/tree/162daa41cd1155fe308ef14daea6296fbaa3d756" target="_blank">github commit</a>';}}