/* SnackbarJS - MIT LICENSE (https://github.com/FezVrasta/snackbarjs/blob/master/LICENSE.md) */ (function (factory) { if (typeof define === 'function' && define.amd) { // AMD. Register as an anonymous module. define(['jquery'], factory); } else if (typeof exports === 'object') { // Node/CommonJS module.exports = factory(require('jquery')); } else { // Browser globals factory(jQuery); } }(function( $ ){ $(document).ready(function() { $("body").append("
" + options.content + "
").text(); if (isset(options.content)) { if ($snackbar.find(".snackbar-content").length) { $snackbar.find(".snackbar-content").html(options.content); } else { $snackbar.prepend(" "); } } if (!isset(options.id)) { $snackbar.appendTo("#snackbar-container"); } else { $snackbar.insertAfter("#snackbar-container .snackbar:last-child"); } // Show or hide item if (isset(options.action) && options.action == "toggle") { if (snackbarStatus) { options.action = "hide"; } else { options.action = "show"; } } var animationId1 = Date.now(); $snackbar.data("animationId1", animationId1); setTimeout(function() { if ($snackbar.data("animationId1") === animationId1) { if (!isset(options.action) || options.action == "show") { $snackbar.addClass("snackbar-opened"); } else if (isset(options.action) && options.action == "hide") { $snackbar.removeClass("snackbar-opened"); } } }, 50); // Set timer for item autohide var animationId2 = Date.now(); $snackbar.data("animationId2", animationId2); if (options.timeout !== 0) { setTimeout(function() { if ($snackbar.data("animationId2") === animationId2) { $snackbar.removeClass("snackbar-opened"); } }, options.timeout); } return $snackbar; } else { return false; } }; $.fn.snackbar = function(action) { var options = {}; if (!this.hasClass("snackbar")) { if (!isset(action) || action === "show" || action === "hide" || action == "toggle") { options = { content: $(this).attr("data-content"), style: $(this).attr("data-style"), timeout: $(this).attr("data-timeout"), htmlAllowed: $(this).attr("data-html-allowed") }; } if (isset(action)) { options.id = this.attr("data-snackbar-id"); if(action === "show" || action === "hide" || action == "toggle") { options.action = action; } } var $snackbar = $.snackbar(options); this.attr("data-snackbar-id", $snackbar.attr("id")); return $snackbar; } else { options.id = this.attr("id"); if(action === "show" || action === "hide" || action == "toggle") { options.action = action; } return $.snackbar(options); } }; }));