Moved to noty support for notifications.

This commit is contained in:
Martin Edenhofer 2012-04-24 01:46:15 +02:00
parent 5a16d06e72
commit 3a6a3e94d4
7 changed files with 512 additions and 13 deletions

View file

@ -1,5 +1,4 @@
$ = jQuery.sub() $ = jQuery.sub()
#Post = App.Post
class App.Notify extends Spine.Controller class App.Notify extends Spine.Controller
events: events:
@ -11,7 +10,6 @@ class App.Notify extends Spine.Controller
super super
Spine.bind 'notify', (data) => Spine.bind 'notify', (data) =>
# @log 'bind notify', data
@[data.type] data.msg @[data.type] data.msg
Spine.bind 'notify:removeall', => Spine.bind 'notify:removeall', =>
@ -19,26 +17,42 @@ class App.Notify extends Spine.Controller
@destroyAll() @destroyAll()
info: (data) -> info: (data) ->
@render( text: arguments[0], type: 'alert-info' ) @render( text: arguments[0], type: 'information' )
warning: (data) -> warning: (data) ->
@render( text: arguments[0], type: 'alert-warning' ) @render( text: arguments[0], type: 'alert' )
error: (data) -> error: (data) ->
@render( text: arguments[0], type: 'alert-error' ) @render( text: arguments[0], type: 'error' )
success: (data) -> success: (data) ->
@render( text: arguments[0], type: 'alert-success' ) @render( text: arguments[0], type: 'success' )
render: (data) -> render: (data) ->
notify = App.view('notify')(data: data) # notify = App.view('notify')(data: data)
@append( notify ) # @append( notify )
# notify.html('') $.noty.closeAll()
$('#notify').noty(
{
text: data.text,
layout: 'top',
type: data.type,
theme: 'noty_theme_twitter',
animateOpen: { height: 'toggle' },
animateClose: { height: 'toggle' },
speed: 450,
timeout: 3600,
closeButton: false,
closeOnSelfClick: true,
closeOnSelfOver: false,
}
)
destroy: (e) -> destroy: (e) ->
e.preventDefault() e.preventDefault()
$(e.target).parents('.alert').remove(); # $(e.target).parents('.alert').remove();
destroyAll: -> destroyAll: ->
$(@el).find('.alert').remove(); $.noty.closeAll()
# $(@el).find('.alert').remove();

View file

@ -15,6 +15,7 @@
#= require ./lib/underscore.coffee #= require ./lib/underscore.coffee
#= require ./lib/ba-linkify.js #= require ./lib/ba-linkify.js
#= require ./lib/jquery.tagsinput.js #= require ./lib/jquery.tagsinput.js
#= require ./lib/jquery.noty.js
#= require ./lib/fileuploader.js #= require ./lib/fileuploader.js
#not_used= require_tree ./lib #not_used= require_tree ./lib
@ -158,7 +159,6 @@ class App.Run extends Spine.Controller
# start content # start content
new App.Content( el: @el.find('#content') ); new App.Content( el: @el.find('#content') );
#class App.Content extends Spine.Stack #class App.Content extends Spine.Stack
class App.Content extends Spine.Controller class App.Content extends Spine.Controller
className: 'container' className: 'container'

View file

@ -0,0 +1,220 @@
/**
* jQuery Noty Plugin v1.1.1
* Authors: Nedim Arabacı (http://ned.im), Muhittin Özer (http://muhittinozer.com)
*
* Examples and Documentation - http://needim.github.com/noty/
*
* Licensed under the MIT licenses:
* http://www.opensource.org/licenses/mit-license.php
*
**/
(function($) {
$.noty = function(options, customContainer) {
var base = this;
var $noty = null;
var isCustom = false;
base.init = function(options) {
base.options = $.extend({}, $.noty.defaultOptions, options);
base.options.type = base.options.cssPrefix+base.options.type;
base.options.id = base.options.type+'_'+new Date().getTime();
base.options.layout = base.options.cssPrefix+'layout_'+base.options.layout;
if (base.options.custom.container) customContainer = base.options.custom.container;
isCustom = ($.type(customContainer) === 'object') ? true : false;
return base.addQueue();
};
// Push notification to queue
base.addQueue = function() {
var isGrowl = ($.inArray(base.options.layout, $.noty.growls) == -1) ? false : true;
if (!isGrowl) (base.options.force) ? $.noty.queue.unshift({options: base.options}) : $.noty.queue.push({options: base.options});
return base.render(isGrowl);
};
// Render the noty
base.render = function(isGrowl) {
// Layout spesific container settings
var container = (isCustom) ? customContainer.addClass(base.options.theme+' '+base.options.layout+' noty_custom_container') : $('body');
if (isGrowl) {
if ($('ul.noty_cont.' + base.options.layout).length == 0)
container.prepend($('<ul/>').addClass('noty_cont ' + base.options.layout));
container = $('ul.noty_cont.' + base.options.layout);
} else {
if ($.noty.available) {
var fromQueue = $.noty.queue.shift(); // Get noty from queue
if ($.type(fromQueue) === 'object') {
$.noty.available = false;
base.options = fromQueue.options;
} else {
$.noty.available = true; // Queue is over
return base.options.id;
}
} else {
return base.options.id;
}
}
base.container = container;
// Generating noty bar
base.bar = $('<div class="noty_bar"/>').attr('id', base.options.id).addClass(base.options.theme+' '+base.options.layout+' '+base.options.type);
$noty = base.bar;
$noty.append(base.options.template).find('.noty_text').html(base.options.text);
$noty.data('noty_options', base.options);
// Close button display
(base.options.closeButton) ? $noty.addClass('noty_closable').find('.noty_close').show() : $noty.find('.noty_close').remove();
// Bind close event to button
$noty.find('.noty_close').bind('click', function() { $noty.trigger('noty.close'); });
// If we have a button we must disable closeOnSelfClick and closeOnSelfOver option
if (base.options.buttons) base.options.closeOnSelfClick = base.options.closeOnSelfOver = false;
// Close on self click
if (base.options.closeOnSelfClick) $noty.bind('click', function() { $noty.trigger('noty.close'); }).css('cursor', 'pointer');
// Close on self mouseover
if (base.options.closeOnSelfOver) $noty.bind('mouseover', function() { $noty.trigger('noty.close'); }).css('cursor', 'pointer');
// Set buttons if available
if (base.options.buttons) {
$buttons = $('<div/>').addClass('noty_buttons');
$noty.find('.noty_message').append($buttons);
$.each(base.options.buttons, function(i, button) {
bclass = (button.type) ? button.type : 'gray';
$button = $('<button/>').addClass(bclass).html(button.text).appendTo($noty.find('.noty_buttons'))
.bind('click', function() {
if ($.isFunction(button.click)) {
button.click.call($button, $noty);
}
});
});
}
return base.show(isGrowl);
};
base.show = function(isGrowl) {
// is Modal?
if (base.options.modal) $('<div/>').addClass('noty_modal').addClass(base.options.theme).prependTo($('body')).fadeIn('fast');
$noty.close = function() { return this.trigger('noty.close'); };
// Prepend noty to container
(isGrowl) ? base.container.prepend($('<li/>').append($noty)) : base.container.prepend($noty);
// topCenter and center specific options
if (base.options.layout == 'noty_layout_topCenter' || base.options.layout == 'noty_layout_center') {
$.noty.reCenter($noty);
}
$noty.bind('noty.setText', function(event, text) {
$noty.find('.noty_text').html(text); $.noty.reCenter($noty);
});
$noty.bind('noty.getId', function(event) {
return $noty.data('noty_options').id;
});
// Bind close event
$noty.one('noty.close', function(event) {
var options = $noty.data('noty_options');
// Modal Cleaning
if (options.modal) $('.noty_modal').fadeOut('fast', function() { $(this).remove(); });
$noty.clearQueue().stop().animate(
$noty.data('noty_options').animateClose,
$noty.data('noty_options').speed,
$noty.data('noty_options').easing,
$noty.data('noty_options').onClose)
.promise().done(function() {
// Layout spesific cleaning
if ($.inArray($noty.data('noty_options').layout, $.noty.growls) > -1) {
$noty.parent().remove();
} else {
$noty.remove();
// queue render
$.noty.available = true;
base.render(false);
}
});
});
// Start the show
$noty.animate(base.options.animateOpen, base.options.speed, base.options.easing, base.options.onShow);
// If noty is have a timeout option
if (base.options.timeout) $noty.delay(base.options.timeout).promise().done(function() { $noty.trigger('noty.close'); });
return base.options.id;
};
// Run initializer
return base.init(options);
};
// API
$.noty.get = function(id) { return $('#'+id); };
$.noty.close = function(id) {
$.noty.get(id).trigger('noty.close');
};
$.noty.setText = function(id, text) {
$.noty.get(id).trigger('noty.setText', text);
};
$.noty.closeAll = function() {
$.noty.clearQueue();
$('.noty_bar').trigger('noty.close');
};
$.noty.reCenter = function(noty) {
noty.css({'left': ($(window).width() - noty.outerWidth()) / 2 + 'px'});
};
$.noty.clearQueue = function() {
$.noty.queue = [];
};
$.noty.queue = [];
$.noty.growls = ['noty_layout_topLeft', 'noty_layout_topRight', 'noty_layout_bottomLeft', 'noty_layout_bottomRight'];
$.noty.available = true;
$.noty.defaultOptions = {
layout: 'top',
theme: 'noty_theme_default',
animateOpen: {height: 'toggle'},
animateClose: {height: 'toggle'},
easing: 'swing',
text: '',
type: 'alert',
speed: 500,
timeout: 5000,
closeButton: false,
closeOnSelfClick: true,
closeOnSelfOver: false,
force: false,
onShow: false,
onClose: false,
buttons: false,
modal: false,
template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
cssPrefix: 'noty_',
custom: {
container: null
}
};
$.fn.noty = function(options) {
return this.each(function() {
(new $.noty(options, $(this)));
});
};
})(jQuery);
//Helper
function noty(options) {
return jQuery.noty(options); // returns an id
}

View file

@ -6,6 +6,8 @@
*= require ./bootstrap.css *= require ./bootstrap.css
*= require ./fileuploader.css *= require ./fileuploader.css
*= require ./ui-lightness/jquery-ui-1.8.18.custom.css *= require ./ui-lightness/jquery-ui-1.8.18.custom.css
*= require ./jquery.noty.css
*= require ./noty_theme_twitter.css
*= require ./zzz.css *= require ./zzz.css
* *
*= require_tree ./custom/ *= require_tree ./custom/

View file

@ -0,0 +1,105 @@
/* CORE STYLES */
/* noty bar */
.noty_bar {
position: fixed;
display: none;
z-index: 9999999;
}
/* noty_message */
.noty_bar .noty_message {
text-align: center;
}
/* noty close button */
.noty_bar .noty_close {
cursor: pointer;
}
/* noty modal */
.noty_modal {
position: fixed;
width: 100%;
height: 100%;
background-color: #000;
z-index: 10000;
opacity: 0.6;
display: none;
left: 0;
top: 0;
}
/* noty container for noty_layout_topLeft & noty_layout_topRight */
ul.noty_cont {
position: fixed;
z-index: 10000000;
margin: 0px;
padding: 0px;
list-style: none;
width: 300px;
}
ul.noty_cont li {
position: relative;
float: left;
clear: both;
list-style: none;
padding: 0px;
margin: 10px 0 0 0;
width: 300px; /* Fix for: http://bugs.jquery.com/ticket/2278 */
}
ul.noty_cont.noty_layout_topLeft {left:20px; top:20px;}
ul.noty_cont.noty_layout_topRight {right:40px; top:20px;}
ul.noty_cont.noty_layout_bottomLeft {left:20px; bottom:20px}
ul.noty_cont.noty_layout_bottomRight {right:40px; bottom:20px}
ul.noty_cont.noty_layout_topRight li {float:right}
/* LAYOUTS */
/* noty_layout_top */
.noty_bar.noty_layout_top {
top: 0;
left: 0;
width: 100%;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
}
/* noty_layout_bottom */
.noty_bar.noty_layout_bottom {
bottom: 0;
left: 0;
width: 100%;
-webkit-border-radius: 0px;
-moz-border-radius: 0px;
border-radius: 0px;
}
/* noty_layout_center */
.noty_bar.noty_layout_center {
top: 40%;
}
/* noty_layout_topLeft & noty_layout_topRight */
.noty_bar.noty_layout_topLeft,
.noty_bar.noty_layout_topRight,
.noty_bar.noty_layout_bottomLeft,
.noty_bar.noty_layout_bottomRight {
width: 100%;
clear: both;
position: relative;
}
.noty_bar.noty_layout_topLeft .noty_message,
.noty_bar.noty_layout_topRight .noty_message,
.noty_bar.noty_layout_bottomLeft .noty_message,
.noty_bar.noty_layout_bottomRight .noty_message {
text-align: left;
}
/* noty_layout_topCenter */
.noty_bar.noty_layout_topCenter {
top: 20px;
}

View file

@ -0,0 +1,137 @@
/* CORE STYLES*/
/* noty bar */
.noty_bar.noty_theme_twitter {
font-size: 13px;
line-height: 18px;
text-shadow: 0 1px 0 #fff;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
/* custom container */
.noty_custom_container.noty_theme_twitter.noty_layout_inline {
position: relative;
}
/* custom growl container */
.noty_custom_container.noty_theme_twitter.noty_layout_inline .noty_cont.noty_layout_inline {
position: static;
}
/* custom noty bar */
.noty_custom_container.noty_theme_twitter.noty_layout_inline .noty_bar {
position: static;
}
.noty_custom_container.noty_theme_twitter.noty_layout_inline .noty_bar .noty_message {
font-size: 13px;
padding: 4px;
}
.noty_custom_container.noty_theme_twitter.noty_layout_inline .noty_bar .noty_message .noty_buttons {
margin-top: -1px;
}
/* noty_message */
.noty_bar.noty_theme_twitter .noty_message {
padding: 8px 14px;
}
/* noty_has_close_button */
.noty_bar.noty_theme_twitter.noty_closable .noty_message {
padding: 8px 35px 8px 14px;
}
/* noty_buttons */
.noty_bar.noty_theme_twitter .noty_message .noty_buttons {
float: right;
margin-top: -5px;
margin-left: 4px;
}
/* noty_button */
.noty_bar.noty_theme_twitter .noty_message .noty_buttons button {
margin-left: 5px;
}
/* noty close button */
.noty_bar.noty_theme_twitter .noty_close {
position: absolute;
top: 7px;
right: 16px;
font-size: 18px;
line-height: 18px;
font-weight: bold;
color: #000;
opacity: 0.2;
text-shadow: 0 1px 0 #fff;
}
/* noty close button hover */
.noty_bar.noty_theme_twitter .noty_close:hover {
opacity: 0.4;
}
.noty_bar.noty_theme_twitter .noty_close:after {
content: "x";
}
/* noty modal */
.noty_modal.noty_theme_twitter {
opacity: 0.7;
}
/* LAYOUTS */
/* noty_layout_topLeft & noty_layout_topRight */
.noty_bar.noty_theme_twitter.noty_layout_center,
.noty_bar.noty_theme_twitter.noty_layout_topCenter,
.noty_bar.noty_theme_twitter.noty_layout_topLeft,
.noty_bar.noty_theme_twitter.noty_layout_topRight,
.noty_bar.noty_theme_twitter.noty_layout_bottomLeft,
.noty_bar.noty_theme_twitter.noty_layout_bottomRight {
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.noty_bar.noty_theme_twitter.noty_layout_topLeft .noty_message .noty_buttons,
.noty_bar.noty_theme_twitter.noty_layout_topRight .noty_message .noty_buttons,
.noty_bar.noty_theme_twitter.noty_layout_bottomLeft .noty_message .noty_buttons,
.noty_bar.noty_theme_twitter.noty_layout_bottomRight .noty_message .noty_buttons {
float: none;
border-top: 1px solid #FBEED5;
margin-left: 0;
margin-top: 10px;
padding-top: 10px;
text-align: right;
}
.noty_bar.noty_theme_twitter.noty_layout_center .noty_message .noty_buttons,
.noty_bar.noty_theme_twitter.noty_layout_topCenter .noty_message .noty_buttons {
margin-left: 15px;
margin-top: -2px
}
/* NOTIFICATION TYPES */
/* noty_alert */
.noty_bar.noty_theme_twitter.noty_alert {
background-color: #FCF8E3;
border: 1px solid #FBEED5;
color: #C09853;
}
/* noty_error */
.noty_bar.noty_theme_twitter.noty_error {
background-color: #F2DEDE;
border: 1px solid #EED3D7;
color: #B94A48;
}
/* noty_success */
.noty_bar.noty_theme_twitter.noty_success {
background-color: #DFF0D8;
border: 1px solid #D6E9C6;
color: #468847;
}
/* noty_information */
.noty_bar.noty_theme_twitter.noty_information {
background-color: #D9EDF7;
border: 1px solid #BCE8F1;
color: #3A87AD;
}

View file

@ -175,3 +175,24 @@ footer {
padding-left: 20px; padding-left: 20px;
padding-right: 10px; padding-right: 10px;
} }
/*
* noty changes
*/
.noty_bar.noty_layout_top {
top: 48px;
position: fixed;
left: 50%;
margin-left: -350px;
width: 700px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.noty_bar.noty_theme_twitter {
font-size: 14px;
line-height: 14px;
text-shadow: 0 1px 0 #fff;
opacity: 0.9;
}