require.config({ baseUrl: "/assets/js", paths: { jquery: "jquery-1.10.2.min", bootstrap: "bootstrap.min", }, shim: { bootstrap: ["jquery"], }, waitSeconds: 0, }); stogram = function () { var self = this; self.plugins = {}; self.init = function (container) { $("[data-selected]").each(function (idx) { var v = $(this).data("selected"); if ($(this).prop("tagName") == "SELECT") { $("option", this).each(function () { if ($(this).val() == v) { $(this).prop("selected", 1); } }); } else if ($(this).hasClass("radio")) { $("[type=radio]", this).each(function () { if ($(this).val() == v) { $(this).prop("checked", 1); } }); } else if ($(this).hasClass("checkbox")) { v = v.split(","); $("[type=checkbox]", this).each(function () { if (v.include($(this).val())) { $(this).prop("checked", 1); } }); } }); require(["bootstrap"], function () { $('[data-toggle="tooltip"]').tooltip(); $('[data-spy="affix"]').affix(); }); $("a").each(function () { var href = $(this).attr("href"); var url = window.location.pathname; if ($(this).attr("role") != "nav") { return; } if ( (url == href || (window.location.href.indexOf(window.location.host + href) >= 0 && href != "/" && !$(this).data("exact")) || (href == "/" && url == window.location.origin + "/")) && $(this).attr("role") == "nav" ) { $(this).addClass("active"); $(this).parent().addClass("active"); } }); $("[data-plugin]", container).each(function (idx) { var plugin = $(this).attr("data-plugin"); var opts = $(this).data(); opts.el = $(this); if (!opts.id) { opts.id = "st-plugin-" + plugin + "-" + idx; $(this).attr("data-id", opts.id); } self.plugin(plugin, opts); }); }; self.plugin = function (name, opts, callback) { var fa = name.match(/\-(\w)/g); var plugin = {}; if (fa) { for (var x in fa) { func = name.replace(fa[x], fa[x].toUpperCase()).replace("-", ""); } } var func = eval("self." + func); if (func) { func(el, opts); } else { require(["stogram/plugins/" + name], function (plugin) { plugin = new plugin(opts); if (callback) { callback(plugin); } self.plugins[opts.id] = plugin; }); } }; var num = 0; self.message = function (msg, timeout, type) { num++; var id = "message-" + num; var className = "message-" + (type ? type : "info"); if (!$(".message").length) { $("body").append('
'); } $(".message").append('
' + msg + "
"); var el = $("#" + id); setTimeout(function () { el.addClass("move-enter"); }, 100); setTimeout( function () { el.remove(); }, timeout ? timeout : 5000 ); return {}; }; self.message.info = function (msg, timeout) { self.message(msg, timeout, "info"); }; self.message.error = function (msg, timeout) { self.message(msg, timeout, "error"); }; self.message.success = function (msg, timeout) { self.message(msg, timeout, "success"); }; self.message.warning = function (msg, timeout) { self.message(msg, timeout, "warning"); }; self.dialog = function (params) { self.plugin("dialog", params, function (dialog) { dialog.open(); }); }; self.init("body"); return self; }; var stogram = new stogram(); window.stogram = stogram;