1
0
mirror of https://github.com/SuperBFG7/ympd synced 2024-12-29 12:20:26 +00:00
ympd/htdocs/js/bootstrap-notify.js

94 lines
2.8 KiB
JavaScript
Raw Normal View History

2014-01-16 17:53:59 +00:00
/**
* bootstrap-notify.js v1.0
* --
* Copyright 2012 Goodybag, Inc.
* --
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2014-01-16 17:53:59 +00:00
(function ($) {
var Notification = function (element, options) {
// Element collection
this.$element = $(element);
this.$note = $('<div class="alert"></div>');
this.options = $.extend(true, {}, $.fn.notify.defaults, options);
// Setup from options
if(this.options.transition)
if(this.options.transition == 'fade')
this.$note.addClass('in').addClass(this.options.transition);
else this.$note.addClass(this.options.transition);
else this.$note.addClass('fade').addClass('in');
if(this.options.type)
this.$note.addClass('alert-' + this.options.type);
else this.$note.addClass('alert-success');
if(!this.options.message && this.$element.data("message") !== '') // dom text
this.$note.html(this.$element.data("message"));
else
if(typeof this.options.message === 'object')
if(this.options.message.html)
this.$note.html(this.options.message.html);
else if(this.options.message.text)
this.$note.text(this.options.message.text);
else
this.$note.html(this.options.message);
if(this.options.closable)
2014-01-17 15:26:26 +00:00
var link = $('<a class="close pull-right" href="#">&nbsp;&times;</a>');
2014-01-16 17:53:59 +00:00
$(link).on('click', $.proxy(onClose, this));
this.$note.prepend(link);
return this;
};
2014-01-16 17:53:59 +00:00
var onClose = function() {
this.options.onClose();
$(this.$note).remove();
this.options.onClosed();
return false;
};
2014-01-16 17:53:59 +00:00
Notification.prototype.show = function () {
if(this.options.fadeOut.enabled)
this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', $.proxy(onClose, this));
2014-01-16 17:53:59 +00:00
this.$element.append(this.$note);
this.$note.alert();
};
2014-01-16 17:53:59 +00:00
Notification.prototype.hide = function () {
if(this.options.fadeOut.enabled)
this.$note.delay(this.options.fadeOut.delay || 3000).fadeOut('slow', $.proxy(onClose, this));
else onClose.call(this);
};
2014-01-16 17:53:59 +00:00
$.fn.notify = function (options) {
return new Notification(this, options);
};
2014-01-16 17:53:59 +00:00
$.fn.notify.defaults = {
type: 'success',
closable: true,
transition: 'fade',
fadeOut: {
enabled: true,
delay: 3000
},
2014-01-16 17:53:59 +00:00
message: null,
onClose: function () {},
onClosed: function () {}
}
2014-01-16 17:53:59 +00:00
})(window.jQuery);