Re-packaged achtung
bzr revid: nicolas.vanhoren@openerp.com-20130812152102-p9v8cpck3uezb45q
This commit is contained in:
parent
3fa7930823
commit
7795418aab
|
@ -7,7 +7,7 @@ require.config({
|
|||
underscore: "im_livechat/static/ext/static/lib/underscore/underscore",
|
||||
qweb2: "im_livechat/static/ext/static/lib/qweb/qweb2",
|
||||
openerp: "web/static/src/js/openerpframework",
|
||||
"jquery.achtung": "im_livechat/static/ext/static/lib/achtung/jquery.achtung",
|
||||
"jquery.achtung": "im_livechat/static/ext/static/lib/jquery-achtung/src/ui.achtung",
|
||||
livesupport: "im_livechat/static/ext/static/js/livesupport",
|
||||
},
|
||||
shim: {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"jquery": "1.8.3",
|
||||
"underscore": "1.3.1",
|
||||
"qweb": "git@github.com:OpenERP/qweb.git#~1.0.0"
|
||||
"qweb": "git@github.com:OpenERP/qweb.git#~1.0.0",
|
||||
"jquery-achtung": "git://github.com/joshvarner/jquery-achtung.git"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,273 +0,0 @@
|
|||
/**
|
||||
* achtung 0.3.0
|
||||
*
|
||||
* Growl-like notifications for jQuery
|
||||
*
|
||||
* Copyright (c) 2009 Josh Varner <josh@voxwerk.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @author Josh Varner <josh@voxwerk.com>
|
||||
*/
|
||||
|
||||
/*globals jQuery,clearTimeout,document,navigator,setTimeout
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/**
|
||||
* This is based on the jQuery UI $.widget code. I would have just made this
|
||||
* a $.widget but I didn't want the jQuery UI dependency.
|
||||
*/
|
||||
$.fn.achtung = function(options)
|
||||
{
|
||||
var isMethodCall = (typeof options === 'string'),
|
||||
args = Array.prototype.slice.call(arguments, 0),
|
||||
name = 'achtung';
|
||||
|
||||
// handle initialization and non-getter methods
|
||||
return this.each(function() {
|
||||
var instance = $.data(this, name);
|
||||
|
||||
// prevent calls to internal methods
|
||||
if (isMethodCall && options.substring(0, 1) === '_') {
|
||||
return this;
|
||||
}
|
||||
|
||||
// constructor
|
||||
(!instance && !isMethodCall &&
|
||||
$.data(this, name, new $.achtung(this))._init(args));
|
||||
|
||||
// method call
|
||||
(instance && isMethodCall && $.isFunction(instance[options]) &&
|
||||
instance[options].apply(instance, args.slice(1)));
|
||||
});
|
||||
};
|
||||
|
||||
$.achtung = function(element)
|
||||
{
|
||||
var args = Array.prototype.slice.call(arguments, 0), $el;
|
||||
|
||||
if (!element || !element.nodeType) {
|
||||
$el = $('<div />');
|
||||
return $el.achtung.apply($el, args);
|
||||
}
|
||||
|
||||
this.$container = $(element);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static members
|
||||
**/
|
||||
$.extend($.achtung, {
|
||||
version: '0.3.0',
|
||||
$overlay: false,
|
||||
defaults: {
|
||||
timeout: 10,
|
||||
disableClose: false,
|
||||
icon: false,
|
||||
className: '',
|
||||
animateClassSwitch: false,
|
||||
showEffects: {'opacity':'toggle','height':'toggle'},
|
||||
hideEffects: {'opacity':'toggle','height':'toggle'},
|
||||
showEffectDuration: 500,
|
||||
hideEffectDuration: 700
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Non-static members
|
||||
**/
|
||||
$.extend($.achtung.prototype, {
|
||||
$container: false,
|
||||
closeTimer: false,
|
||||
options: {},
|
||||
|
||||
_init: function(args)
|
||||
{
|
||||
var o, self = this;
|
||||
|
||||
args = $.isArray(args) ? args : [];
|
||||
|
||||
|
||||
args.unshift($.achtung.defaults);
|
||||
args.unshift({});
|
||||
|
||||
o = this.options = $.extend.apply($, args);
|
||||
|
||||
if (!$.achtung.$overlay) {
|
||||
$.achtung.$overlay = $('<div id="achtung-overlay"></div>').appendTo(document.body);
|
||||
}
|
||||
|
||||
if (!o.disableClose) {
|
||||
$('<span class="achtung-close-button ui-icon ui-icon-close" />')
|
||||
.click(function () { self.close(); })
|
||||
.hover(function () { $(this).addClass('achtung-close-button-hover'); },
|
||||
function () { $(this).removeClass('achtung-close-button-hover'); })
|
||||
.prependTo(this.$container);
|
||||
}
|
||||
|
||||
this.changeIcon(o.icon, true);
|
||||
|
||||
if (o.message) {
|
||||
this.$container.append($('<span class="achtung-message">' + o.message + '</span>'));
|
||||
}
|
||||
|
||||
(o.className && this.$container.addClass(o.className));
|
||||
(o.css && this.$container.css(o.css));
|
||||
|
||||
this.$container
|
||||
.addClass('achtung')
|
||||
.appendTo($.achtung.$overlay);
|
||||
|
||||
if (o.showEffects) {
|
||||
this.$container.toggle();
|
||||
} else {
|
||||
this.$container.show();
|
||||
}
|
||||
|
||||
if (o.timeout > 0) {
|
||||
this.timeout(o.timeout);
|
||||
}
|
||||
},
|
||||
|
||||
timeout: function(timeout)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if (this.closeTimer) {
|
||||
clearTimeout(this.closeTimer);
|
||||
}
|
||||
|
||||
this.closeTimer = setTimeout(function() { self.close(); }, timeout * 1000);
|
||||
this.options.timeout = timeout;
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the CSS class associated with this message, using
|
||||
* a transition if available (not availble in Safari/Webkit).
|
||||
* If no transition is available, the switch is immediate.
|
||||
*
|
||||
* #LATER Check if this has been corrected in Webkit or jQuery UI
|
||||
* #TODO Make transition time configurable
|
||||
* @param newClass string Name of new class to associate
|
||||
*/
|
||||
changeClass: function(newClass)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if (this.options.className === newClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.$container.queue(function() {
|
||||
if (!self.options.animateClassSwitch ||
|
||||
/webkit/.test(navigator.userAgent.toLowerCase()) ||
|
||||
!$.isFunction($.fn.switchClass)) {
|
||||
self.$container.removeClass(self.options.className);
|
||||
self.$container.addClass(newClass);
|
||||
} else {
|
||||
self.$container.switchClass(self.options.className, newClass, 500);
|
||||
}
|
||||
|
||||
self.options.className = newClass;
|
||||
self.$container.dequeue();
|
||||
});
|
||||
},
|
||||
|
||||
changeIcon: function(newIcon, force)
|
||||
{
|
||||
var self = this;
|
||||
|
||||
if ((force !== true || newIcon === false) && this.options.icon === newIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (force || this.options.icon === false) {
|
||||
this.$container.prepend($('<span class="achtung-message-icon ui-icon ' + newIcon + '" />'));
|
||||
this.options.icon = newIcon;
|
||||
return;
|
||||
} else if (newIcon === false) {
|
||||
this.$container.find('.achtung-message-icon').remove();
|
||||
this.options.icon = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.$container.queue(function() {
|
||||
var $span = $('.achtung-message-icon', self.$container);
|
||||
|
||||
if (!self.options.animateClassSwitch ||
|
||||
/webkit/.test(navigator.userAgent.toLowerCase()) ||
|
||||
!$.isFunction($.fn.switchClass)) {
|
||||
$span.removeClass(self.options.icon);
|
||||
$span.addClass(newIcon);
|
||||
} else {
|
||||
$span.switchClass(self.options.icon, newIcon, 500);
|
||||
}
|
||||
|
||||
self.options.icon = newIcon;
|
||||
self.$container.dequeue();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
changeMessage: function(newMessage)
|
||||
{
|
||||
this.$container.queue(function() {
|
||||
$('.achtung-message', $(this)).html(newMessage);
|
||||
$(this).dequeue();
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
update: function(options)
|
||||
{
|
||||
(options.className && this.changeClass(options.className));
|
||||
(options.css && this.$container.css(options.css));
|
||||
(typeof(options.icon) !== 'undefined' && this.changeIcon(options.icon));
|
||||
(options.message && this.changeMessage(options.message));
|
||||
(options.timeout && this.timeout(options.timeout));
|
||||
},
|
||||
|
||||
close: function()
|
||||
{
|
||||
var o = this.options, $container = this.$container;
|
||||
|
||||
if (o.hideEffects) {
|
||||
this.$container.animate(o.hideEffects, o.hideEffectDuration);
|
||||
} else {
|
||||
this.$container.hide();
|
||||
}
|
||||
|
||||
$container.queue(function() {
|
||||
$container.removeData('achtung');
|
||||
$container.remove();
|
||||
|
||||
if ($.achtung.$overlay && $.achtung.$overlay.is(':empty')) {
|
||||
$.achtung.$overlay.remove();
|
||||
$.achtung.$overlay = false;
|
||||
}
|
||||
|
||||
$container.dequeue();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
|
@ -1,6 +1,6 @@
|
|||
/**
|
||||
* achtung 0.3.0
|
||||
*
|
||||
* achtung %%VERSION%%
|
||||
*
|
||||
* Growl-like notifications for jQuery
|
||||
*
|
||||
* Copyright (c) 2009 Josh Varner <josh@voxwerk.com>
|
||||
|
@ -11,10 +11,10 @@
|
|||
* 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
|
||||
|
@ -29,43 +29,138 @@
|
|||
* @author Josh Varner <josh@voxwerk.com>
|
||||
*/
|
||||
|
||||
#achtung-overlay {
|
||||
overflow: hidden;
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
/* IE 6 doesn't support position: fixed */
|
||||
* html #achtung-overlay {
|
||||
position:absolute;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
/* IE6 includes padding in width */
|
||||
* html .achtung {
|
||||
width: 280px;
|
||||
width: 260px;
|
||||
}
|
||||
|
||||
#achtung-overlay {
|
||||
#achtung-wrapper {
|
||||
overflow: hidden;
|
||||
position: fixed;
|
||||
top: 15px;
|
||||
right: 15px;
|
||||
width: 280px;
|
||||
z-index:50;
|
||||
padding: 25px 30px 10px 10px;
|
||||
}
|
||||
|
||||
.achtung {
|
||||
display:none;
|
||||
display: none;
|
||||
float: right;
|
||||
clear: right;
|
||||
margin-bottom: 8px;
|
||||
padding: 15px 15px;
|
||||
background-color: #000;
|
||||
color: white;
|
||||
width: 250px;
|
||||
font-weight: bold;
|
||||
position:relative;
|
||||
overflow: hidden;
|
||||
-moz-box-shadow: #aaa 1px 1px 2px;
|
||||
-webkit-box-shadow: #aaa 1px 1px 2px;
|
||||
box-shadow: #aaa 1px 1px 2px;
|
||||
-moz-border-radius: 4px; -webkit-border-radius: 4px; border-radius: 4px;
|
||||
padding: 15px;
|
||||
background: #000;
|
||||
background: rgba(0,0,0,.95);
|
||||
color: white;
|
||||
width: 230px;
|
||||
font-weight: normal;
|
||||
font-style: italic;
|
||||
font-size: 1.05em;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
text-shadow: -1px -1px 0 rgba(0,0,0,.3);
|
||||
box-shadow: rgba(0,0,0,.3) 0 1px 4px;
|
||||
-moz-box-shadow: rgba(0,0,0,.3) 0 1px 4px;
|
||||
-webkit-box-shadow: rgba(0,0,0,.3) 0 1px 4px;
|
||||
border-radius: 4px;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
opacity: 1.0;
|
||||
filter:Alpha(Opacity=100);
|
||||
}
|
||||
|
||||
.achtung-default {
|
||||
background: #000;
|
||||
background: -moz-linear-gradient(top, rgba(150,150,150,.9), rgba(120,120,120,.9) 70%);
|
||||
background: -webkit-gradient(linear, left top, left bottom,
|
||||
from(rgba(150,150,150,.9)),
|
||||
color-stop(70%, rgba(120,120,120,.9)),
|
||||
to(rgba(120,120,120,.9))
|
||||
) no-repeat;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.achtung .achtung-message-icon {
|
||||
float: left;
|
||||
margin: 0 .8em 0 -.5em;
|
||||
zoom: 1;
|
||||
}
|
||||
|
||||
.achtung .ui-icon.achtung-close-button {
|
||||
overflow: hidden;
|
||||
float: right;
|
||||
position: relative;
|
||||
top: -8px;
|
||||
right: -8px;
|
||||
cursor: pointer;
|
||||
background-image: url('images/ui-icons_cccccc_256x240.png');
|
||||
}
|
||||
|
||||
.achtung .ui-icon.achtung-close-button:hover {
|
||||
background-image: url('images/ui-icons_ffffff_256x240.png');
|
||||
}
|
||||
|
||||
/* Slightly darker for these colors (readability) */
|
||||
.achtungSuccess, .achtungFail, .achtungWait {
|
||||
/* Note that if using show/hide animations, IE will lose
|
||||
this setting */
|
||||
opacity: .85;
|
||||
filter:Alpha(Opacity=85);
|
||||
opacity: 1.0;
|
||||
filter:Alpha(Opacity=100);
|
||||
}
|
||||
|
||||
.achtungSuccess {
|
||||
background: #6a5;
|
||||
background: #6a5 -moz-linear-gradient(top, #8c7, #6a5 70%);
|
||||
background: #6a5 -webkit-gradient(linear, left top, left bottom,
|
||||
from(#8c7),
|
||||
color-stop(70%, #6a5),
|
||||
to(#6a5)
|
||||
) no-repeat;
|
||||
}
|
||||
.achtungFail {
|
||||
background: #a55;
|
||||
background: #a55 -moz-linear-gradient(top, #c66, #a44 70%);
|
||||
background: #789 -webkit-gradient(linear, left top, left bottom,
|
||||
from(#c66),
|
||||
color-stop(70%, #a44),
|
||||
to(#a44)
|
||||
) no-repeat;
|
||||
}
|
||||
.achtungWait {
|
||||
background: #789;
|
||||
background: #789 -moz-linear-gradient(top, #89a, #678 70%);
|
||||
background: #789 -webkit-gradient(linear, left top, left bottom,
|
||||
from(#89a),
|
||||
color-stop(70%, #678),
|
||||
to(#678)
|
||||
) no-repeat;
|
||||
}
|
||||
|
||||
.achtungSuccess .ui-icon.achtung-close-button,
|
||||
.achtungFail .ui-icon.achtung-close-button {
|
||||
background-image: url('images/ui-icons_444444_256x240.png');
|
||||
}
|
||||
|
||||
.achtungSuccess .ui-icon.achtung-close-button:hover,
|
||||
.achtungFail .ui-icon.achtung-close-button:hover {
|
||||
background-image: url('images/ui-icons_ffffff_256x240.png');
|
||||
}
|
||||
|
||||
.achtung .wait-icon {
|
||||
background-image: url('images/wait.gif');
|
||||
}
|
||||
|
||||
.achtung .achtung-message {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -74,8 +169,8 @@
|
|||
* Can (and should) be removed if you are already loading the jQuery UI CSS
|
||||
* to reduce payload size.
|
||||
*/
|
||||
.ui-icon { display: block; overflow: hidden; background-repeat: no-repeat; }
|
||||
.ui-icon { width: 16px; height: 16px; }
|
||||
.ui-icon { display: block; text-indent: -99999px; overflow: hidden; background-repeat: no-repeat; }
|
||||
.ui-icon { width: 16px; height: 16px; background-image: url('images/ui-icons_222222_256x240.png'); }
|
||||
.ui-icon-carat-1-n { background-position: 0 0; }
|
||||
.ui-icon-carat-1-ne { background-position: -16px 0; }
|
||||
.ui-icon-carat-1-e { background-position: -32px 0; }
|
||||
|
@ -249,58 +344,3 @@
|
|||
.ui-icon-grip-solid-horizontal { background-position: -48px -224px; }
|
||||
.ui-icon-gripsmall-diagonal-se { background-position: -64px -224px; }
|
||||
.ui-icon-grip-diagonal-se { background-position: -80px -224px; }
|
||||
|
||||
.achtung .achtung-message-icon {
|
||||
margin-top: 0px;
|
||||
margin-left: -.5em;
|
||||
margin-right: .5em;
|
||||
float: left;
|
||||
zoom: 1;
|
||||
}
|
||||
|
||||
.achtung .ui-icon.achtung-close-button {
|
||||
float: right;
|
||||
margin-right: -8px;
|
||||
margin-top: -12px;
|
||||
cursor: pointer;
|
||||
color: white;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
.achtung .ui-icon.achtung-close-button:after {
|
||||
content: "x"
|
||||
}
|
||||
|
||||
/* Slightly darker for these colors (readability) */
|
||||
.achtungSuccess, .achtungFail, .achtungWait {
|
||||
/* Note that if using show/hide animations, IE will lose
|
||||
this setting */
|
||||
opacity: .93; filter:Alpha(Opacity=93);
|
||||
}
|
||||
|
||||
.achtungSuccess {
|
||||
background-color: #4DB559;
|
||||
}
|
||||
|
||||
.achtungFail {
|
||||
background-color: #D64450;
|
||||
}
|
||||
|
||||
.achtungWait {
|
||||
background-color: #658093;
|
||||
}
|
||||
|
||||
.achtungSuccess .ui-icon.achtung-close-button,
|
||||
.achtungFail .ui-icon.achtung-close-button {
|
||||
}
|
||||
|
||||
.achtungSuccess .ui-icon.achtung-close-button-hover,
|
||||
.achtungFail .ui-icon.achtung-close-button-hover {
|
||||
}
|
||||
|
||||
.achtung .wait-icon {
|
||||
}
|
||||
|
||||
.achtung .achtung-message {
|
||||
display: inline;
|
||||
}
|
|
@ -0,0 +1,282 @@
|
|||
/**
|
||||
* achtung %%VERSION%%
|
||||
*
|
||||
* Growl-like notifications for jQuery
|
||||
*
|
||||
* Copyright (c) 2009 Josh Varner <josh@voxwerk.com>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* @license http://www.opensource.org/licenses/mit-license.php
|
||||
* @author Josh Varner <josh@voxwerk.com>
|
||||
*/
|
||||
|
||||
/*jslint browser:true, white:false, onevar:false, nomen:false, bitwise:false, plusplus:false, immed: false */
|
||||
/*globals window, jQuery */
|
||||
(function ($) {
|
||||
|
||||
var widgetName = 'achtung';
|
||||
|
||||
/**
|
||||
* This is based on the jQuery UI $.widget code. I would have just made this
|
||||
* a $.widget but I didn't want the jQuery UI dependency.
|
||||
*/
|
||||
$.fn.achtung = function (options) {
|
||||
var isMethodCall = (typeof options === 'string'),
|
||||
args = Array.prototype.slice.call(arguments, isMethodCall ? 1 : 0);
|
||||
|
||||
// handle initialization and non-getter methods
|
||||
return this.each(function () {
|
||||
// prevent calls to internal methods
|
||||
if (isMethodCall && options.substring(0, 1) === '_') {
|
||||
return;
|
||||
}
|
||||
|
||||
var instance = $.data(this, widgetName);
|
||||
|
||||
// constructor
|
||||
if (!instance && !isMethodCall) {
|
||||
$.data(this, widgetName, new $.achtung(this))._init(args);
|
||||
}
|
||||
|
||||
if (!!instance && isMethodCall && $.isFunction(instance[options])) {
|
||||
instance[options].apply(instance, args);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$.achtung = function (element) {
|
||||
if (!element || !element.nodeType) {
|
||||
var el = $('<div>');
|
||||
return el.achtung.apply(el, arguments);
|
||||
}
|
||||
|
||||
this.container = $(element);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Static members
|
||||
**/
|
||||
$.extend($.achtung, {
|
||||
version: '%%VERSION%%',
|
||||
overlay: false,
|
||||
wrapper: false,
|
||||
defaults: {
|
||||
timeout: 10,
|
||||
disableClose: false,
|
||||
icon: false,
|
||||
className: 'achtung-default',
|
||||
crossFadeMessage: 500, // 0 to disable
|
||||
animateClassSwitch: 0, // 0 to disable (doesn't work with gradient backgrounds)
|
||||
showEffects: {'opacity':'toggle'}, // ,'height':'toggle'},
|
||||
hideEffects: {'opacity':'toggle'}, // ,'height':'toggle'},
|
||||
showEffectDuration: 300,
|
||||
hideEffectDuration: 500
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* Non-static members
|
||||
**/
|
||||
$.extend($.achtung.prototype, {
|
||||
container: false,
|
||||
icon: false,
|
||||
message: false,
|
||||
closeTimer: false,
|
||||
options: {},
|
||||
|
||||
_init: function (args) {
|
||||
var o, self = this;
|
||||
|
||||
o = this.options = $.extend.apply($, [{}, $.achtung.defaults].concat(args));
|
||||
|
||||
if ((o.animateClassSwitch > 0) && !('switchClass' in $.fn)) {
|
||||
o.animateClassSwitch = this.options.animateClassSwitch = 0;
|
||||
}
|
||||
|
||||
if (!o.disableClose) {
|
||||
$('<span class="achtung-close-button ui-icon ui-icon-close" />')
|
||||
.prependTo(this.container)
|
||||
.bind({
|
||||
click: function () { self.close(); }
|
||||
});
|
||||
}
|
||||
|
||||
this.changeIcon(o.icon, true);
|
||||
|
||||
if (o.message) {
|
||||
this.message = $('<span>', {
|
||||
'class': 'achtung-message',
|
||||
html: o.message
|
||||
}).appendTo(this.container);
|
||||
}
|
||||
|
||||
if ('className' in o) {
|
||||
this.container.addClass(o.className);
|
||||
}
|
||||
|
||||
if ('css' in o) {
|
||||
this.container.css(o.css);
|
||||
}
|
||||
|
||||
if (!$.achtung.overlay) {
|
||||
$.achtung.overlay = $('<div id="achtung-overlay"><div id="achtung-wrapper"></div></div>');
|
||||
$.achtung.overlay.appendTo(document.body);
|
||||
$.achtung.wrapper = $('#achtung-wrapper');
|
||||
}
|
||||
|
||||
this.container.addClass('achtung').hide().appendTo($.achtung.wrapper);
|
||||
|
||||
if (o.showEffects) {
|
||||
this.container.animate(o.showEffects, o.showEffectDuration);
|
||||
} else {
|
||||
this.container.show();
|
||||
}
|
||||
|
||||
this.timeout(o.timeout);
|
||||
},
|
||||
|
||||
timeout: function (timeout) {
|
||||
var self = this;
|
||||
|
||||
if (this.closeTimer) {
|
||||
clearTimeout(this.closeTimer);
|
||||
}
|
||||
|
||||
if (timeout > 0) {
|
||||
this.closeTimer = setTimeout(function () { self.close(); }, timeout * 1000);
|
||||
this.options.timeout = timeout;
|
||||
} else if (timeout < 0) {
|
||||
this.close();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Change the CSS class associated with this message.
|
||||
*
|
||||
* @param newClass string Name of new class to associate
|
||||
*/
|
||||
changeClass: function (newClass) {
|
||||
var oldClass = '' + this.options.className,
|
||||
self = this;
|
||||
|
||||
if (oldClass === newClass) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.container.queue(function (next) {
|
||||
if (self.options.animateClassSwitch > 0) {
|
||||
$(this).switchClass(oldClass, newClass, self.options.animateClassSwitch);
|
||||
} else {
|
||||
$(this).removeClass(oldClass).addClass(newClass);
|
||||
}
|
||||
next();
|
||||
});
|
||||
|
||||
this.options.className = newClass;
|
||||
},
|
||||
|
||||
changeIcon: function (newIcon, force) {
|
||||
if (!force && this.options.icon === newIcon) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!!this.icon) {
|
||||
if (newIcon) {
|
||||
this.icon.removeClass(this.options.icon).addClass(newIcon);
|
||||
} else {
|
||||
this.icon.remove();
|
||||
this.icon = false;
|
||||
}
|
||||
} else if (newIcon) {
|
||||
this.icon = $('<span class="achtung-message-icon ui-icon ' + newIcon + '" />');
|
||||
this.container.prepend(this.icon);
|
||||
}
|
||||
|
||||
this.options.icon = newIcon;
|
||||
},
|
||||
|
||||
changeMessage: function (newMessage) {
|
||||
if (this.options.crossFadeMessage > 0) {
|
||||
this.message.clone()
|
||||
.css('position', 'absolute')
|
||||
.insertBefore(this.message)
|
||||
.fadeOut(this.options.crossFadeMessage, function () { $(this).remove(); });
|
||||
|
||||
this.message.hide().html(newMessage).fadeIn(this.options.crossFadeMessage);
|
||||
} else {
|
||||
this.message.html(newMessage);
|
||||
}
|
||||
|
||||
this.options.message = newMessage;
|
||||
},
|
||||
|
||||
update: function () {
|
||||
var options = $.extend.apply($, [{}].concat(Array.prototype.slice.call(arguments, 0))),
|
||||
map = {
|
||||
className: 'changeClass',
|
||||
css: 'css',
|
||||
icon: 'changeIcon',
|
||||
message: 'changeMessage',
|
||||
timeout: 'timeout'
|
||||
};
|
||||
|
||||
for (var prop in map) {
|
||||
if (prop in options) {
|
||||
this[map[prop]](options[prop]);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
isVisible: function () {
|
||||
return (true === this.container.is(':visible'));
|
||||
},
|
||||
|
||||
_trigger: function (type, data) {
|
||||
this.container.trigger(widgetName + type, data);
|
||||
},
|
||||
|
||||
close: function () {
|
||||
var o = this.options, self = this;
|
||||
|
||||
this._trigger('close');
|
||||
|
||||
if (o.hideEffects) {
|
||||
this.container.animate(o.hideEffects, o.hideEffectDuration, function () {
|
||||
self.remove();
|
||||
});
|
||||
} else {
|
||||
this.container.hide();
|
||||
this.remove();
|
||||
}
|
||||
},
|
||||
|
||||
remove: function () {
|
||||
this.container.remove();
|
||||
|
||||
if ($.achtung.wrapper && !($.achtung.wrapper.contents().length)) {
|
||||
$.achtung.wrapper = false;
|
||||
$.achtung.overlay.remove();
|
||||
$.achtung.overlay = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
})(jQuery);
|
Loading…
Reference in New Issue