/** * Track Links window.addEvent('domready', function() { var links = $$('a[rel*=external]'); if(links) { var path = window.location.pathname; var match; var page = 1; var category = ''; var action = ''; var type = 'Outbound Links'; path = path.replace(/\.html$/, ''); if(match = path.match(/([^\/]+)(\/page_(\d+))?$/)) { if(path.match(/^\/companies\//)) { if(path.match(/\/product\//)) { type = 'Product Snapshot'; } else { type = 'Company Profile'; } } if(match[3]) { page = match[3]; } if(match[1]) { action = match[1]; } } links.each(function(link) { new ExternalLink(link, { type: type, action: action, page: page }); }); } }); */ window.addEvent('domready', function() { //Auto funds and smooth scrolls to hash (#) link elements in window instead of jumping to them when clicked var sScroll = new Fx.Scroll(window, { wait:false, duration:500, transition: Fx.Transitions.Quad.easeInOut }); $$("a[href^=#]").each(function(el){ var sEL = $$(el.getAttribute('href')); if(sEL.length > 0){ el.addEvent('click', function(e){ e = new Event(e).stop(); sScroll.toElement(sEL[0]); }); } }); }); /** * Menu */ window.addEvent('domready', function() { var menu = $$('section#left-section ul.menu'); if(menu) { new LeftMenu(menu); } }); /** * FP Pop ups */ window.addEvent('domready', function() { var children = $$('body#frontpage div.children'); if(children) { children.each(function(c) { new CategoryChild(c); }); } }); /** * Bookmark Show */ window.addEvent('domready', function() { var noteHandles = $$('ul.sobi2Listing div.note div.handle'); if(noteHandles) { noteHandles.each(function(h) { h.addEvent('click', function() { this.getNext().toggleClass('hidden'); }); }); } }); /** * Highlight Entry */ window.addEvent('domready', function() { var hash = window.location.hash; if(hash && $$(hash)) { $$(hash).addClass('highlight'); } }); /** * Solr Description Popup * window.addEvent('domready', function() { var description = $$('header div.description'); if(description && description.length) { // should only be one... description[0].addEvent('click', function() { this.setStyle('display', 'none'); }); } }); */ var LeftMenu = new Class({ options: { delay: 200, timeoutId: 0 }, initialize: function(el) { this.element = el; this.attachEvents(); }, attachEvents: function() { var that = this; var parents = this.element.getElements('li.parent'); if(this.element && parents) { parents.each(function(l) { var timeoutId; var hoverEvents = { mouseenter: function(e) { var item = this; timeoutId = setTimeout(function() { if(!item.hasClass('active')) { item.addClass('hover'); var children = item.getElement('ul.children'); if(!children) { var id = item.getProperty('id').match(/\d+$/); if(id) { var xhr = new Ajax("index.php?option=com_sobi2&sobi2Task=pw_dmenu&format=raw&parentid=" + id, { onComplete: function(response) { if(response) { var d = new Element('div'); d.setHTML(response); item.adopt(d.getChildren()); children = item.getElement('ul.children'); var c = item.getElements('li.parent'); if(c) { c.addEvents(hoverEvents); } that.fitToWindow(children, item); } } }); xhr.request(); } } that.fitToWindow(children, item); } }, that.options.delay); }, mouseleave: function(e) { var item = this; if(timeoutId) { clearTimeout(timeoutId); } timeoutId = setTimeout(function() { item.removeClass('hover'); }, that.options.delay); } }; l.addEvents(hoverEvents); }); } }, fitToWindow: function(el, parent) { if(el && parent) { el.setStyle('top', 0); // reset to default var coords = el.getCoordinates(); var winSize = window.getSize(); var bdiff = coords.bottom - (winSize.size.y + winSize.scroll.y); var tdiff = coords.top - winSize.scroll.y; if(bdiff > 0) { el.setStyle('top', -(bdiff + 10) + 'px'); } else if(tdiff < 0) { el.setStyle('top', -(tdiff) + 'px'); } } } }); LeftMenu.implement(new Options); var ExternalLink = new Class({ options: {}, initialize: function(el, options) { this.element = el; this.setOptions(options); this.attachEvents(); }, attachEvents: function() { if(this.element) { var that = this; var url = this.element.getProperty('href'); this.element.addEvents({ click: function(e) { var url = this.getProperty('href'); _gaq.push(['_trackEvent', that.options.type, that.options.action, url]); return true; } }); } } }); ExternalLink.implement(new Options); var CategoryChild = new Class({ initialize: function(el) { this.element = el; this.attachEvents(); }, attachEvents: function() { var container = this.element; var that = this; if(container) { var clickable = this.element.getElement('h5'); if(clickable) { clickable.addEvent('click', function(e) { container.toggleClass('opened'); that.fitToWindow(clickable.getNext()); }); } } }, fitToWindow: function(el) { if(el) { var coords = el.getCoordinates(); var winSize = window.getSize(); var diff = winSize.scroll.y - coords.top; // - (winSize.size.y + winSize.scroll.y); el.setStyle('bottom', 10); if(diff > 0) { el.setStyle('bottom', -diff + 'px'); } } } }); CategoryChild.implement(new Options); var Drawer = new Class({ options: { handleClass: 'a.handle', drawerClass: 'div.drawer', fx: { duration: 500 } }, initialize: function(element, options) { this.element = element; this.setOptions(options); this.handle = this.element.getElement(this.options.handleClass); this.drawer = this.element.getElement(this.options.drawerClass); this.attachEvents(); }, attachEvents: function() { if(this.handle && this.drawer) { this.handle.addEvents({ click: function(e) { if(e) { e = new Event(e); e.stop(); } this.toggle(); }.bind(this) }); } }, getDrawerHeight:function() { var size = this.drawer.getSize(); return size.size.y + 1; }, close: function() { var height = this.getDrawerHeight(); var fx = new Fx.Style(this.element, 'margin-top', { duration: this.options.fx.duration }); fx.start(0, -height); this.element.addClass('closed'); }, open: function() { var height = this.getDrawerHeight(); var fx = new Fx.Style(this.element, 'margin-top', { duration: this.options.fx.duration }); fx.start(-height, 0); this.element.removeClass('closed'); }, toggle: function() { if(this.element.hasClass('closed')) { this.open(); } else { this.close(); } } }); Drawer.implement(new Options);