1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| this.close = function(id, callback) {
// Shift callback arguments
if (typeof id === 'function') {
callback = id;
id = null;
}
// Check Slidebars has been initialized
if (!initialized) {
throw "Slidebars has not been initialized.";
}
// Check to see if the Slidebar exists
if (id && !offCanvas.hasOwnProperty(id)) {
throw "Error closing Slidebar, there is no Slidebar with id '" + id + "'.";
}
// If no id was passed, get the active Slidebar
if (!id) {
id = this.active('slidebar');
}
// Close a Slidebar
if (id && offCanvas[id].active) {
// Set active state to false
offCanvas[id].active = false;
// Trigger event
$(events).trigger('closing', [offCanvas[id].id]);
// Get animation properties
var animationProperties = getAnimationProperties(id);
// Apply css
animationProperties.elements.css('transform', '');
// Transition completetion
setTimeout(function() {
// Remove transition duration
animationProperties.elements.css('transition-duration', '');
// Hide the Slidebar
offCanvas[id].element.css('display', 'none');
// Trigger event
$(events).trigger('closed', [offCanvas[id].id]);
// Run callback
if (typeof callback === 'function') {
callback();
}
}, animationProperties.duration);
}
}; |
Partager