').addClass(vex.baseClassNames.content).addClass(options.contentClassName).css(options.contentCSS).append(options.content).data({
vex: options
});
options.$vex.append(options.$vexContent);
if (options.showCloseButton) {
options.$closeButton = $('
').addClass(vex.baseClassNames.close).addClass(options.closeClassName).css(options.closeCSS).data({
vex: options
}).bind('click.vex', function() {
return vex.close($(this).data().vex.id);
});
options.$vexContent.append(options.$closeButton);
}
$(options.appendLocation).append(options.$vex);
vex.setupBodyClassName(options.$vex);
if (options.afterOpen) {
options.afterOpen(options.$vexContent, options);
}
setTimeout((function() {
return options.$vexContent.trigger('vexOpen', options);
}), 0);
return options.$vexContent;
},
getAllVexes: function() {
return $("." + vex.baseClassNames.vex + ":not(\"." + vex.baseClassNames.closing + "\") ." + vex.baseClassNames.content);
},
getVexByID: function(id) {
return vex.getAllVexes().filter(function() {
return $(this).data().vex.id === id;
});
},
close: function(id) {
var $lastVex;
if (!id) {
$lastVex = vex.getAllVexes().last();
if (!$lastVex.length) {
return false;
}
id = $lastVex.data().vex.id;
}
return vex.closeByID(id);
},
closeAll: function() {
var ids;
ids = vex.getAllVexes().map(function() {
return $(this).data().vex.id;
}).toArray();
if (!(ids != null ? ids.length : void 0)) {
return false;
}
$.each(ids.reverse(), function(index, id) {
return vex.closeByID(id);
});
return true;
},
closeByID: function(id) {
var $vex, $vexContent, beforeClose, close, options;
$vexContent = vex.getVexByID(id);
if (!$vexContent.length) {
return;
}
$vex = $vexContent.data().vex.$vex;
options = $.extend({}, $vexContent.data().vex);
beforeClose = function() {
if (options.beforeClose) {
return options.beforeClose($vexContent, options);
}
};
close = function() {
$vexContent.trigger('vexClose', options);
$vex.remove();
$('body').trigger('vexAfterClose', options);
if (options.afterClose) {
return options.afterClose($vexContent, options);
}
};
if (animationEndSupport) {
beforeClose();
$vex.unbind(vex.animationEndEvent).bind(vex.animationEndEvent, function() {
return close();
}).addClass(vex.baseClassNames.closing);
} else {
beforeClose();
close();
}
return true;
},
closeByEscape: function() {
var $lastVex, id, ids;
ids = vex.getAllVexes().map(function() {
return $(this).data().vex.id;
}).toArray();
if (!(ids != null ? ids.length : void 0)) {
return false;
}
id = Math.max.apply(Math, ids);
$lastVex = vex.getVexByID(id);
if ($lastVex.data().vex.escapeButtonCloses !== true) {
return false;
}
return vex.closeByID(id);
},
setupBodyClassName: function($vex) {
return $('body').bind('vexOpen.vex', function() {
return $('body').addClass(vex.baseClassNames.open);
}).bind('vexAfterClose.vex', function() {
if (!vex.getAllVexes().length) {
return $('body').removeClass(vex.baseClassNames.open);
}
});
},
hideLoading: function() {
return $('.vex-loading-spinner').remove();
},
showLoading: function() {
vex.hideLoading();
return $('body').append("
");
}
};
};
if (typeof define === 'function' && define.amd) {
define(['jquery'], vexFactory);
} else if (typeof exports === 'object') {
module.exports = vexFactory(require('jquery'));
} else {
window.vex = vexFactory(jQuery);
}
}).call(this);