var dlib = { roar: null, currentTimestamp: parseInt($time() / 1000), init: function() { //Init für JS Messages (dlib.addMessage()) if(typeof Roar != 'undefined') { dlib.roar = new Roar(); } //Benutzername und Passwort Formular mit dummydaten füllen if($('loginform')) { $('benutzername').addEvents({ 'focus': function() { if ($('benutzername').get('value') == 'Benutzername') { $('benutzername').set('value', ''); } }, 'blur': function() { if ($('benutzername').get('value') == '') { $('benutzername').set('value', 'Benutzername'); } } }); $('passwort').addEvents({ 'focus': function() { if ($('passwort').get('value') == 'Passwort') { $('passwort').set('value', ''); } }, 'blur': function() { if ($('passwort').get('value') == '') { $('passwort').set('value', 'Passwort'); } } }); } //Mouseovereffekt vom menu if($('mainmenu')) { dlib.addmenuover(); } //Tooltips anzeigen if($$('.tooltip')) { new Tips('.tooltip', {'width': 250}); } //accordion initialisieren if($('accordion')) { var myAccordion = new Accordion($$('.accordiontoggler'), $$('.accordionelements'), { opacity: false, alwaysHide: true, duration: 0, show: -1 }); } //Simple MochaUI Fenster if($$('.mochawindow').length > 0) { dlib.initmochawindows(); } if($$('.mochaui_iframewindow').length > 0) { dlib.initMochaIframeWindows(); } //Funktion um einen Link zu einer seite hinzuzufügen if($('addpagelink')) { $('addpagelink').addEvent('click', function(e){ new Event(e).stop(); new MochaUI.Window({ id: 'linklist', loadMethod: 'xhr', contentURL: '/index/linklist/', title: 'Linkliste', height: 350, width: 600, onContentLoaded: function() { if($$('.pageaddlink').length > 0) { $$('.pageaddlink').addEvent('click', function(e){ new Event(e).stop(); $('textfeld').set('value', $('textfeld').get('value') + '[link=' + this.get('href') + ']' + this.get('title') + '[/link]'); MochaUI.closeWindow($('linklist')); }); } if($$('.previewlink').length > 0) { $$('.previewlink').addEvent('click', function(e){ new Event(e).stop(); new MochaUI.Window({ id: this.get('title'), loadMethod: 'xhr', contentURL: '/index/preview/' + this.get('name') + '.html', title: this.get('title'), height: 350, width: 600 }); }); } } }); }); } //Seitenauswahl liste if($('pageselectbutton')) { $('pageselectbutton').addEvent('click', function(e){ new Event(e).stop(); new MochaUI.Window({ id: 'linklist', loadMethod: 'xhr', contentURL: '/index/linklist/', title: 'Linkliste', height: 350, width: 600, onContentLoaded: function() { if($$('.pageaddlink').length > 0) { $$('.pageaddlink').addEvent('click', function(e){ new Event(e).stop(); $('pagename').set('value', this.get('name')); MochaUI.closeWindow($('linklist')); }); } if($$('.previewlink').length > 0) { $$('.previewlink').addEvent('click', function(e){ new Event(e).stop(); new MochaUI.Window({ id: this.get('title'), loadMethod: 'xhr', contentURL: '/index/preview/' + this.get('name') + '.html', title: this.get('title'), height: 350, width: 600 }); }); } } }); }) } //Hilfe bereich über content if($('helpToggle') && $('helpContent')) { var slider = new Fx.Slide($('helpContent')).hide(); $('helpContent').setStyles({'display':'block'}); $('helpToggle').setStyles({'cursor': 'pointer'}); $('helpToggle').removeEvents('click').addEvent('click', function(e){ new Event(e).stop(); slider.toggle(); }); } }, /** * Schreibt nachrichten raus */ addMessage: function(title, text, type) { type = type || ''; text = text || ''; title = title || ''; if(dlib.roar != null && title != '') { switch(type) { case 'msg_info': dlib.roar.alert(title, text, {'class': 'roar_msg_info'}); break; case 'msg_warnung': dlib.roar.alert(title, text, {'class': 'roar_msg_warning'}); break; case 'msg_fehler': dlib.roar.alert(title, text, {'class': 'roar_msg_error'}); break; default: dlib.roar.alert(title, text); break; } } else { alert(title + '\n' + text); } }, /** * initfunction für mouseovereffekt im menu */ addmenuover: function() { $('mainmenu').getChildren('li').addEvents({ 'mouseover': function(e){ this.morph('ul#mainmenu li.over'); }, 'mouseout': function(e){ this.morph('ul#mainmenu li'); } }); }, /** * Einfach MochaUI fenster erstellen */ initmochawindows: function() { $$('.mochawindow').addEvent('click', function(e){ new Event(e).stop(); var windowtype = 'window'; if(this.hasClass('dlibmodal')) { //windowtype = 'modal'; //@todo: bug beheben //Fehler: $("modalOverlay") is null } var scrollposX = 0; var scrollposY = 0; var elementToScroll = $(document.body); var myFx = new Fx.Scroll(elementToScroll); new MochaUI.Window({ 'loadMethod': 'xhr', 'contentURL': this.get('href'), 'title': this.get('title'), 'height': 350, 'width': 400, 'type': windowtype, 'onContentLoaded': function() { //@todo: allgemeiner halten if($('accordion')) { var myAccordion = new Accordion($$('.accordiontoggler'), $$('.accordionelements')); } }, 'onBeforeBuild': function() { var scroll = window.getScroll(); scrollposX = scroll.x; scrollposY = scroll.y; myFx.start(0,0); }, 'onClose': function(){ myFx.start(scrollposX,scrollposY); } }); }); }, /** * nimmt aus einem Link die URL und erstellt damit ein IFrame MochaUI Fenster */ initMochaIframeWindows: function() { $$('.mochaui_iframewindow').addEvent('click', function(e){ new Event(e).stop(); var windowtype = 'window'; if(this.hasClass('dlibmodal')) { //windowtype = 'modal'; //@todo: bug beheben //Fehler: $("modalOverlay") is null } var scrollposX = 0; var scrollposY = 0; var elementToScroll = $(document.body); var myFx = new Fx.Scroll(elementToScroll); new MochaUI.Window({ 'loadMethod': 'iframe', 'contentURL': this.get('href'), 'title': this.get('title'), 'height': 500, 'width': 700, 'type': windowtype, 'onContentLoaded': function() { //@todo: allgemeiner halten if($('accordion')) { var myAccordion = new Accordion($$('.accordiontoggler'), $$('.accordionelements')); } }, 'onBeforeBuild': function() { var scroll = window.getScroll(); scrollposX = scroll.x; scrollposY = scroll.y; myFx.start(0,0); }, 'onClose': function(){ myFx.start(scrollposX,scrollposY); } }); }); }, /** * Geht mitgeliefertes Element (tabelle) durch und setzt bei den TRs die entsprechenden even/odd klassen */ evenOddTable: function(table) { //@todo: checken ob es ein Element ist if(typeof table == 'object') { if(table.get('tag') == 'table') { var count = 0; table.getChildren('tbody').each(function(tbody){ tbody.getChildren('tr').each(function(elem){ elem.removeClass((count%2 != 1 ? 'even' : 'odd')); elem.addClass((count%2 == 1 ? 'even' : 'odd')); count += 1; }) }); } } }, /** * Schreibt in das mitgegebene Element den countdown rein, beginend rückwerts bei restzeit */ countdown: function(elem, restzeit, endstring) { if(typeof endstring == 'undefined') { endstring = 'jetzt'; } output = endstring; if(restzeit > 0) { var timeDiff = (dlib.currentTimestamp + parseInt(restzeit)) - (parseInt($time() / 1000)); if(timeDiff > 0) { output = ''; var stunden = 0; var minuten = 0; var sekunden = 0; if(timeDiff > 3600) { output += parseInt(timeDiff/3600) + 'h '; timeDiff = timeDiff%3600; output = stunden } if(timeDiff > 60) { output += parseInt(timeDiff/60) + 'm '; timeDiff = timeDiff%60; } output += timeDiff + 's'; dlib.countdown.delay(1000, this, [elem, restzeit, endstring]); } } elem.set('html', output); }, str_replace: function(search, replace, subject) { return subject.split(search).join(replace); } }; window.addEvent('load', dlib.init);