Fix popup add to cart
This commit is contained in:
@@ -5,214 +5,262 @@ Copyright 2013 Kevin Sylvestre
|
||||
1.1.4
|
||||
*/
|
||||
|
||||
;(function () {
|
||||
'use strict'
|
||||
var $,
|
||||
Animation,
|
||||
Growl,
|
||||
__bind = function (fn, me) {
|
||||
return function () {
|
||||
return fn.apply(me, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
(function() {
|
||||
"use strict";
|
||||
var $, Animation, Growl,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
$ = jQuery
|
||||
|
||||
$ = jQuery;
|
||||
Animation = (function () {
|
||||
function Animation() {}
|
||||
|
||||
Animation = (function() {
|
||||
function Animation() {}
|
||||
Animation.transitions = {
|
||||
webkitTransition: 'webkitTransitionEnd',
|
||||
mozTransition: 'mozTransitionEnd',
|
||||
oTransition: 'oTransitionEnd',
|
||||
transition: 'transitionend',
|
||||
}
|
||||
|
||||
Animation.transitions = {
|
||||
"webkitTransition": "webkitTransitionEnd",
|
||||
"mozTransition": "mozTransitionEnd",
|
||||
"oTransition": "oTransitionEnd",
|
||||
"transition": "transitionend"
|
||||
};
|
||||
Animation.transition = function ($el) {
|
||||
var el, result, type, _ref
|
||||
el = $el[0]
|
||||
_ref = this.transitions
|
||||
for (type in _ref) {
|
||||
result = _ref[type]
|
||||
if (el.style[type] != null) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Animation.transition = function($el) {
|
||||
var el, result, type, _ref;
|
||||
el = $el[0];
|
||||
_ref = this.transitions;
|
||||
for (type in _ref) {
|
||||
result = _ref[type];
|
||||
if (el.style[type] != null) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
};
|
||||
return Animation
|
||||
})()
|
||||
|
||||
return Animation;
|
||||
Growl = (function () {
|
||||
Growl.settings = {
|
||||
namespace: 'growl',
|
||||
duration: 3200,
|
||||
close: '×',
|
||||
location: 'default',
|
||||
style: 'default',
|
||||
size: 'medium',
|
||||
}
|
||||
|
||||
})();
|
||||
Growl.growl = function (settings) {
|
||||
if (settings == null) {
|
||||
settings = {}
|
||||
}
|
||||
this.initialize()
|
||||
return new Growl(settings)
|
||||
}
|
||||
|
||||
Growl = (function() {
|
||||
Growl.settings = {
|
||||
namespace: 'growl',
|
||||
duration: 3200,
|
||||
close: "×",
|
||||
location: "default",
|
||||
style: "default",
|
||||
size: "medium"
|
||||
};
|
||||
Growl.initialize = function () {
|
||||
return $('body:not(:has(#growls))').append('<div id="growls" />')
|
||||
}
|
||||
|
||||
Growl.growl = function(settings) {
|
||||
if (settings == null) {
|
||||
settings = {};
|
||||
}
|
||||
this.initialize();
|
||||
return new Growl(settings);
|
||||
};
|
||||
function Growl(settings) {
|
||||
if (settings == null) {
|
||||
settings = {}
|
||||
}
|
||||
this.html = __bind(this.html, this)
|
||||
this.$growl = __bind(this.$growl, this)
|
||||
this.$growls = __bind(this.$growls, this)
|
||||
this.animate = __bind(this.animate, this)
|
||||
this.remove = __bind(this.remove, this)
|
||||
this.dismiss = __bind(this.dismiss, this)
|
||||
this.present = __bind(this.present, this)
|
||||
this.close = __bind(this.close, this)
|
||||
this.cycle = __bind(this.cycle, this)
|
||||
this.unbind = __bind(this.unbind, this)
|
||||
this.bind = __bind(this.bind, this)
|
||||
this.render = __bind(this.render, this)
|
||||
this.settings = $.extend({}, Growl.settings, settings)
|
||||
this.$growls().attr('class', this.settings.location)
|
||||
this.render()
|
||||
}
|
||||
|
||||
Growl.initialize = function() {
|
||||
return $("body:not(:has(#growls))").append('<div id="growls" />');
|
||||
};
|
||||
Growl.prototype.render = function () {
|
||||
var $growl
|
||||
$growl = this.$growl()
|
||||
this.$growls().append($growl)
|
||||
this.cycle($growl)
|
||||
}
|
||||
|
||||
function Growl(settings) {
|
||||
if (settings == null) {
|
||||
settings = {};
|
||||
}
|
||||
this.html = __bind(this.html, this);
|
||||
this.$growl = __bind(this.$growl, this);
|
||||
this.$growls = __bind(this.$growls, this);
|
||||
this.animate = __bind(this.animate, this);
|
||||
this.remove = __bind(this.remove, this);
|
||||
this.dismiss = __bind(this.dismiss, this);
|
||||
this.present = __bind(this.present, this);
|
||||
this.close = __bind(this.close, this);
|
||||
this.cycle = __bind(this.cycle, this);
|
||||
this.unbind = __bind(this.unbind, this);
|
||||
this.bind = __bind(this.bind, this);
|
||||
this.render = __bind(this.render, this);
|
||||
this.settings = $.extend({}, Growl.settings, settings);
|
||||
this.$growls().attr('class', this.settings.location);
|
||||
this.render();
|
||||
}
|
||||
Growl.prototype.bind = function ($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl()
|
||||
}
|
||||
return $growl
|
||||
.find('.' + this.settings.namespace + '-close')
|
||||
.on('click', this.close)
|
||||
}
|
||||
|
||||
Growl.prototype.render = function() {
|
||||
var $growl;
|
||||
$growl = this.$growl();
|
||||
this.$growls().append($growl);
|
||||
this.cycle($growl);
|
||||
};
|
||||
Growl.prototype.unbind = function ($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl()
|
||||
}
|
||||
return $growl
|
||||
.find('.' + (this.settings.namespace - close))
|
||||
.off('click', this.close)
|
||||
}
|
||||
|
||||
Growl.prototype.bind = function($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl();
|
||||
}
|
||||
return $growl.find("." + this.settings.namespace + "-close").on("click", this.close);
|
||||
};
|
||||
Growl.prototype.cycle = function ($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl()
|
||||
}
|
||||
return $growl
|
||||
.queue(this.present)
|
||||
.delay(this.settings.duration)
|
||||
.queue(this.dismiss)
|
||||
.queue(this.remove)
|
||||
}
|
||||
|
||||
Growl.prototype.unbind = function($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl();
|
||||
}
|
||||
return $growl.find("." + (this.settings.namespace - close)).off("click", this.close);
|
||||
};
|
||||
Growl.prototype.close = function (event) {
|
||||
var $growl
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
$growl = this.$growl()
|
||||
return $growl.stop().queue(this.dismiss).queue(this.remove)
|
||||
}
|
||||
|
||||
Growl.prototype.cycle = function($growl) {
|
||||
if ($growl == null) {
|
||||
$growl = this.$growl();
|
||||
}
|
||||
return $growl.queue(this.present).delay(this.settings.duration).queue(this.dismiss).queue(this.remove);
|
||||
};
|
||||
Growl.prototype.present = function (callback) {
|
||||
var $growl
|
||||
$growl = this.$growl()
|
||||
this.bind($growl)
|
||||
return this.animate(
|
||||
$growl,
|
||||
'' + this.settings.namespace + '-incoming',
|
||||
'out',
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
Growl.prototype.close = function(event) {
|
||||
var $growl;
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
$growl = this.$growl();
|
||||
return $growl.stop().queue(this.dismiss).queue(this.remove);
|
||||
};
|
||||
Growl.prototype.dismiss = function (callback) {
|
||||
var $growl
|
||||
$growl = this.$growl()
|
||||
this.unbind($growl)
|
||||
return this.animate(
|
||||
$growl,
|
||||
'' + this.settings.namespace + '-outgoing',
|
||||
'in',
|
||||
callback
|
||||
)
|
||||
}
|
||||
|
||||
Growl.prototype.present = function(callback) {
|
||||
var $growl;
|
||||
$growl = this.$growl();
|
||||
this.bind($growl);
|
||||
return this.animate($growl, "" + this.settings.namespace + "-incoming", 'out', callback);
|
||||
};
|
||||
Growl.prototype.remove = function (callback) {
|
||||
this.$growl().remove()
|
||||
return callback()
|
||||
}
|
||||
|
||||
Growl.prototype.dismiss = function(callback) {
|
||||
var $growl;
|
||||
$growl = this.$growl();
|
||||
this.unbind($growl);
|
||||
return this.animate($growl, "" + this.settings.namespace + "-outgoing", 'in', callback);
|
||||
};
|
||||
Growl.prototype.animate = function ($element, name, direction, callback) {
|
||||
var transition
|
||||
if (direction == null) {
|
||||
direction = 'in'
|
||||
}
|
||||
transition = Animation.transition($element)
|
||||
$element[direction === 'in' ? 'removeClass' : 'addClass'](name)
|
||||
$element.offset().position
|
||||
$element[direction === 'in' ? 'addClass' : 'removeClass'](name)
|
||||
if (callback == null) {
|
||||
return
|
||||
}
|
||||
if (transition != null) {
|
||||
$element.one(transition, callback)
|
||||
} else {
|
||||
callback()
|
||||
}
|
||||
}
|
||||
|
||||
Growl.prototype.remove = function(callback) {
|
||||
this.$growl().remove();
|
||||
return callback();
|
||||
};
|
||||
Growl.prototype.$growls = function () {
|
||||
return this.$_growls != null
|
||||
? this.$_growls
|
||||
: (this.$_growls = $('#growls'))
|
||||
}
|
||||
|
||||
Growl.prototype.animate = function($element, name, direction, callback) {
|
||||
var transition;
|
||||
if (direction == null) {
|
||||
direction = 'in';
|
||||
}
|
||||
transition = Animation.transition($element);
|
||||
$element[direction === 'in' ? 'removeClass' : 'addClass'](name);
|
||||
$element.offset().position;
|
||||
$element[direction === 'in' ? 'addClass' : 'removeClass'](name);
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (transition != null) {
|
||||
$element.one(transition, callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
Growl.prototype.$growl = function () {
|
||||
return this.$_growl != null
|
||||
? this.$_growl
|
||||
: (this.$_growl = $(this.html()))
|
||||
}
|
||||
|
||||
Growl.prototype.$growls = function() {
|
||||
return this.$_growls != null ? this.$_growls : this.$_growls = $('#growls');
|
||||
};
|
||||
Growl.prototype.html = function () {
|
||||
return (
|
||||
"<div class='" +
|
||||
this.settings.namespace +
|
||||
' ' +
|
||||
this.settings.namespace +
|
||||
'-' +
|
||||
this.settings.style +
|
||||
' ' +
|
||||
this.settings.namespace +
|
||||
'-' +
|
||||
this.settings.size +
|
||||
"'>\n <div class='" +
|
||||
this.settings.namespace +
|
||||
"-close'>" +
|
||||
this.settings.close +
|
||||
"</div>\n <div class='" +
|
||||
this.settings.namespace +
|
||||
"-title'>" +
|
||||
this.settings.title +
|
||||
"</div>\n <div class='" +
|
||||
this.settings.namespace +
|
||||
"-message'>" +
|
||||
this.settings.message +
|
||||
'</div>\n</div>'
|
||||
)
|
||||
}
|
||||
|
||||
Growl.prototype.$growl = function() {
|
||||
return this.$_growl != null ? this.$_growl : this.$_growl = $(this.html());
|
||||
};
|
||||
return Growl
|
||||
})()
|
||||
|
||||
Growl.prototype.html = function() {
|
||||
return "<div class='" + this.settings.namespace + " " + this.settings.namespace + "-" + this.settings.style + " " + this.settings.namespace + "-" + this.settings.size + "'>\n <div class='" + this.settings.namespace + "-close'>" + this.settings.close + "</div>\n <div class='" + this.settings.namespace + "-title'>" + this.settings.title + "</div>\n <div class='" + this.settings.namespace + "-message'>" + this.settings.message + "</div>\n</div>";
|
||||
};
|
||||
$.growl = function (options) {
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
return Growl.growl(options)
|
||||
}
|
||||
|
||||
return Growl;
|
||||
$.growl.error = function (options) {
|
||||
var settings
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
settings = {
|
||||
title: 'Error!',
|
||||
style: 'error',
|
||||
}
|
||||
return $.growl($.extend(settings, options))
|
||||
}
|
||||
|
||||
})();
|
||||
$.growl.notice = function (options) {
|
||||
var settings
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
settings = {
|
||||
title: 'Notice!',
|
||||
style: 'notice',
|
||||
}
|
||||
return $.growl($.extend(settings, options))
|
||||
}
|
||||
|
||||
$.growl = function(options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
return Growl.growl(options);
|
||||
};
|
||||
|
||||
$.growl.error = function(options) {
|
||||
var settings;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
settings = {
|
||||
title: "Error!",
|
||||
style: "error"
|
||||
};
|
||||
return $.growl($.extend(settings, options));
|
||||
};
|
||||
|
||||
$.growl.notice = function(options) {
|
||||
var settings;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
settings = {
|
||||
title: "Notice!",
|
||||
style: "notice"
|
||||
};
|
||||
return $.growl($.extend(settings, options));
|
||||
};
|
||||
|
||||
$.growl.warning = function(options) {
|
||||
var settings;
|
||||
if (options == null) {
|
||||
options = {};
|
||||
}
|
||||
settings = {
|
||||
title: "Warning!",
|
||||
style: "warning"
|
||||
};
|
||||
return $.growl($.extend(settings, options));
|
||||
};
|
||||
|
||||
}).call(this);
|
||||
$.growl.warning = function (options) {
|
||||
var settings
|
||||
if (options == null) {
|
||||
options = {}
|
||||
}
|
||||
settings = {
|
||||
title: 'Warning!',
|
||||
style: 'warning',
|
||||
}
|
||||
return $.growl($.extend(settings, options))
|
||||
}
|
||||
}).call(this)
|
||||
|
||||
Reference in New Issue
Block a user