//fix for IE console.log var log = Function.prototype.bind.call(console.log, console); // basic function e$(id) { return document.getElementById(id); } jQuery.fn.tagName = function() { return this.prop("tagName"); }; $.urlParam = function(name){ var results = new RegExp('[\?&]' + name + '=([^]*)').exec(window.location.href); if (results==null){ return null; } else{ return results[1] || 0; } } /* prototype: startsWith */ String.prototype.startsWith = function(str) { if (this.length>=str.length) { return (str==this.substring(0,str.length)); } return false; } /* prototype: endsWith */ String.prototype.endsWith = function(str) { if (this.length>=str.length) { var src = this; var pos = src.length-str.length; return (str==src.substring(pos,pos+str.length)); } return false; } /* Dialog and Input functions */ function getKeyCode(event) { if (window.event) { // IE return event.keyCode; } // Netscape/Firefox/Opera return event.which; } function cancelEvent(event) { if(event.preventDefault) { // Chrome, FF event.preventDefault(); } else { // IE event.returnValue = false; } return false; } function isVisible(elem) { return (elem.is(":visible")); } /** * Page */ const Page = { prevSection: null, scrollParent: "html, body", // init init: function(menuId) { // init all this.initMenu(menuId); this.initNavbarToogle(); this.initNavbarAnimate(); this.initGotoTop(); this.initPageLinks(menuId); this.initSectionLinks(); this.initMailLinks(); this.initShowMeLinks(); // controls TabView.init(); Checkbox.init(); LayoutResize.init(); // scroll to section var section = $.urlParam('sec'); if (section) { this.scrollToSection("#sec"+section); } }, // initNavbarToogle initMenu: function(menuId) { log("initMenu: "+menuId); var mi = e$(menuId); if (mi) { $(mi).addClass("active"); } }, // initNavbarToogle initNavbarToogle: function() { // Navbar toggle var nbt = $('.navbar-toggle'); nbt.each(function() { var btn = $(this); var menu = $(btn.attr('data-target')); if (menu.find(".navbar-nav > li").length==0) btn.hide(); }); nbt.click(function() { var btn = $(this); var menu = $(btn.attr('data-target')); // alert(menu.length); var open = menu.hasClass('open'); if (open) { menu.slideUp(300, function() { menu.removeClass('open'); }); } else { menu.slideDown(300, function() { menu.addClass('open'); }); } // expanded btn.attr('aria-expanded', open); }); }, // initNavbarAnimate initNavbarAnimate: function() { /* delayed */ var navbar = $("#navbar-main"); // or ".navbar-main-style" var animate = navbar.find(".navbar-link, .navbar-link img, .navbar-toggle, .navbar-nav-wrapper, .navbar-nav"); animate = animate.add(".nav-indicator span"); // also applies to sub-menu! /* delayed */ setTimeout(function() { // enableTransformation(); animate.addClass("animate"); }, 500); /* mouse-triggered $("#navigation").mouseenter(function() { var navb = $(this); animate.addClass("animate"); nav.off( "mouseenter" ); }); */ }, // initGotoTop initGotoTop: function() { var button = $('#goto-top'); // scroll event $(document).on('scroll', function() { var view = $(window); var show = (view.scrollTop() > 250); var visible = isVisible(button); if (show == visible) return; // show or hide if (show) { button.fadeIn(); } else { button.fadeOut(); } }); // onclick-event button.on('click', function(){ $('html, body').stop().animate({ scrollTop: 0 }, 800); return false; }); }, // initPageLinks initPageLinks: function(menuId) { var linkSelector; var otherSelector; if (menuId=="mi.home") { linkSelector = "a.pageLink"; otherSelector = "a.homeLink"; } else { linkSelector = "a.homeLink"; otherSelector = "a.pageLink"; } $(linkSelector).click(function() { var link = this; // make target active var target = link.getAttribute("data-target"); if (target) { var tmi = e$(target); if (tmi) { $(tmi).addClass("active"); } } // animate $("#navbar-main").removeClass("navbar-main-style"); window.setTimeout(function(){ Page.execPageLink(link); }, 300); return false; }); /* - for debugging only - $(otherSelector ).click(function() { var link = this; $("#navbar-main").addClass("navbar-main-style"); return false; }); */ }, // execPageLink execPageLink: function(a) { // Execute Link if (a==null || a.href==null) { alert(anchor_id + ' is not a valid anchor element!'); return; } window.location = a.href; }, // initSectionLinks initSectionLinks: function() { // smoothscroll $('a.sectionLink').bind('click.smoothscroll',function (e) { e.preventDefault(); var target = this.hash; // close the menu var btn = $('#navbar-sub .navbar-toggle:visible'); if (btn.length>0) { var navbar = $(btn.data("target")); if (navbar.hasClass("open")) btn.click(); } // scroll now Page.scrollToSection(target); }); }, // initMailLinks initMailLinks: function() { $("a.mailLink").each( function(/* index, element */){ var link = $( this ); var target = link.data("target"); var domain = "empire-db.apache.org"; link.text(target+"@"+domain); link.click(function() { var link = $( this ); var url = "mailto:"+link.text(); window.location = url; }); }); }, // initShowMeLinks initShowMeLinks: function() { // smoothscroll $('a.showMe').each( function(/* index, element */){ var link = $( this ); link.click(function() { var link = $( this ); var content = link.closest('.content-block'); if (content.length==0) content = link.closest('.content'); if (content.length==0) return; link.hide(); content.find(".optional").slideDown(500, function() { // content.next(".content.optional").show(); content.find("a.hideMe").show(); }); }); }); $('a.hideMe').each( function(/* index, element */){ var link = $( this ); link.click(function() { var link = $( this ); var content = link.closest('.content-block'); if (content.length==0) content = link.closest('.content'); if (content.length==0) return; Page.scrollIntoView(content); content.find(".optional").slideUp(500, function() { // content.next(".content.optional").hide(); link.hide(); content.find("a.showMe").show(); }); }); link.hide(); }); }, // scrollToSection scrollToSection: function(target) { // get target $target = $(target); if ($target.length==0) { alert("Unknown target:"+target); return; } // remove active if (this.prevSection) this.prevSection.removeClass("active"); this.prevSection = null; // set active var miid = target.replace('#', 'mi.'); var mi = e$(miid); if (mi) { this.prevSection = $(mi); this.prevSection.addClass("active"); } // scroll to position $('html, body').stop().animate( { 'scrollTop': $target.offset().top-121 }, 900); }, // scrollToTop scrollToTop: function() { var scrollParent = $(Page.scrollParent); scrollParent.animate({ scrollTop: 0 }); }, // scrollToBottom scrollToBottom: function() { var scrollParent = $(Page.scrollParent); var scrollContent = scrollParent.children().first(); var contentHeight = $(scrollContent).outerHeight(true); // height including margin scrollParent.animate({ scrollTop: Math.max(contentHeight - $(scrollParent).height(), 0) }); }, // scrollTo scrollIntoView: function(elem) { // scroll now var scrollParent = $(Page.scrollParent); var topPos = $(elem).offset().top -121; if (topPos>scrollParent.scrollTop()) return; scrollParent.stop().animate( { 'scrollTop': topPos }, 600); return false; }, // reload reload: function() { var loc = window.location; window.location = loc; }, // resizeContent resizeContent: function() { var winHeight = $(window).height(); var content = $("#pscroll"); var height = winHeight-content.offset().top; // footer /* var footer = $("#appfooter"); if (footer.is(":visible")) height-= footer.outerHeight(); */ // check if (height<10) height=10; /* var dbg = $("#debugOut"); dbg.text(height); */ content.height(height); // Repositoin popups if (Popup.open) Popup.repositionAll(winHeight); }, print: function() { var win = window.open("", "Druckansicht", "toolbar=yes, location=no, directories=yes, status=yes, menubar=yes, scrollbars=yes, resizable=yes, width=1030, height=600"); win.document.open(); win.document.write('
'); win.document.write(''); win.document.write(''); win.document.write(''); win.document.write(''); win.document.write('Ansicht drucken') win.document.write('