/* * Javascript implementations for WhatAMan 2008 website * (c) Papercut Media. No reproduction without permission. Feel free to ask. * Author: Patrick Pittman * Date: October 2007 * Version: 1.0 * Requires: Prototype.js framework, ufo.js for flash loading, Dreamgirl on the other end for AJAXy JSON communication */ function WhatAMan() { this.loaderlock = false; this.baseHref = "http://www.whatamansgottado.com.au/"; this.ajaxBase = this.baseHref+"js/ajax/"; this.ajaxProgress = document.createElement('img'); this.ajaxProgress.src = this.baseHref+"images/icons/ajax-loader.gif"; this.anchors = $H({}); } WhatAMan.prototype.init = function(e) { Element.extend(document.body); this.loadPlayer(); if (!document.location.href.match('login') && !document.body.hasClassName('editmode')) { /* this.loadMBBox(); this.loadBanners(); this.progress = Builder.node('div',{ id: 'ajaxContainer', display: 'none' },[Builder.node('img',{src: this.baseHref+"images/icons/ajax-loader.gif",alt:"Request in Progress"})]); $('wrapper').appendChild(this.progress); if (document.location.href.lastIndexOf('#') < 1) { this.anchors['l'] = this.stripAnchors(document.location.href).replace(this.baseHref,""); document.location.href = this.writeAnchors(this.baseHref+"main"); } else if (document.location.href == this.baseHref+"main") { this.anchors['l'] = "main"; document.location.href = this.writeAnchors(document.location.href); } $('content').innerHTML = ''; this.baseTitle = document.title; this.getAjax = this.getAjaxLink.bindAsEventListener(WhatAMan); this.watchAnchors(); this.ajaxLinks(); */ } // this.glueMenu(); } WhatAMan.prototype.watchFilters = function() { // alert('running filter watch'); $$('a.filterLink').each(this.stickFilters,this); } WhatAMan.prototype.stickFilters = function(element) { element.stopObserving('click',WhatAMan.updateFilter); element.observe('click',WhatAMan.updateFilter); } WhatAMan.prototype.updateFilter = function(e) { // alert('hello'); e.stop(); el = Event.element(e); // alert('click on '+el.href); // el.stopObserving('click',this.updateFilter); new Ajax.Updater('locFilter',el.href,{ method: 'get', encoding: 'UTF-8', parameters: { ajax: 1 }, onSuccess: WhatAMan.resetFilters }); } WhatAMan.prototype.resetFilters = function(transport,json) { // alert('running success'); WhatAMan.watchFilters(); new Ajax.Updater('bandPopout',WhatAMan.ajaxBase+"menu",{ onSuccess: function(transport,json) { // alert("received "+transport.responseText); } }); WhatAMan.loadAjax(WhatAMan.baseHref+WhatAMan.anchors['l']); } WhatAMan.prototype.watchAnchors = function() { new PeriodicalExecuter(function() { WhatAMan.parseAnchor(); }, 0.2); } WhatAMan.prototype.getAnchorReqs = function() { var reqUri = document.location.href; reqAnchor = reqUri.lastIndexOf('#'); if (reqAnchor) { return reqUri.substr((reqAnchor + 1),reqUri.length).split('::'); } } WhatAMan.prototype.parseAnchor = function() { var reqState = this.getAnchorReqs(); if (reqState) { for (var i = 0; i < reqState.length; i++) { if (reqState[i].match("=")) { var reqString = reqState[i].split("="); reqArg = reqString[0]; reqVal = reqString[1]; } else { reqArg = reqState[i]; reqVal = null; } if (!this.anchors) { this.anchors = {}; } switch(reqArg) { case "g" : this.anchors["g"] = reqVal; break; case "l" : this.anchors["l"] = reqVal; this.loadAnchor(reqVal); break; case "j" : this.anchors["j"] = reqVal; this.jumpToAnchor(reqVal); break; } } } } WhatAMan.prototype.jumpToAnchor = function(anchor) { var allLinks = $('content').getElementsByTagName('a'); var destinationLink = null; for (var i=0;i 0) { return href.substr(0,reqAnchor); } else { return href; } } WhatAMan.prototype.stripQuery = function(href) { // strip existing anchors // alert('inspecting '+href); reqQ = href.lastIndexOf('?'); if (reqQ > 0) { return href.substr(0,reqQ); } else { alert("returning "+href); return href; } } WhatAMan.prototype.addAnchor = function(anchors) { if (WhatAMan.anchors) { anchors.each(function(anchor) { WhatAMan.anchors[anchor.key] = anchor.value; }); } else { WhatAMan.anchors = anchors; } } WhatAMan.prototype.getAjaxLink = function(e) { Event.stop(e); element = Event.element(e); if (element.nodeName.toUpperCase() != 'A') { element = element.up('a'); } // alert(element.inspect()); if (element.up('ul')) { if (element.up('ul').hasClassName('popout')) { // alert('pop out'); popout = element.up('ul'); popout.hide(); popout.up('li').observe('mouseover',function(e){ if (this.up('li')) { if (this.up('li').down('ul')) { this.up('li').down('ul').show(); } } }); popout.observe('mouseout',function(e){ // alert(this.inspect()); if(this.nodeName.toUpperCase() == 'UL') { // alert('list'); this.hide(); } }); } } this.lastReq = element.href; if (this.lastReq) { reqAnchor = this.lastReq.lastIndexOf('#'); if (reqAnchor > 0) { this.anchors['j'] = this.lastReq.substr((reqAnchor + 1),this.lastReq.length); this.lastReq = this.stripAnchors(this.lastReq); } else { this.anchors.remove('j'); } this.getParams = this.lastReq.toQueryParams(); params = $H({}); if (this.getParams) { gPar = Object.toJSON(this.getParams); // alert(this.getParams); if (!gPar.match('{}')) { this.anchors['g'] = encodeURIComponent(gPar); params = this.getParams; this.lastReq = this.stripQuery(this.lastReq); } else { this.anchors.remove('g'); } } else { this.anchors.remove('g'); } params['ajax'] = 1; newL = this.lastReq.replace(this.baseHref,""); // alert(newL); if (!newL) { newL = this.lastAnchor; } // if (newL != this.anchors['l']) { this.anchors['l'] = newL; this.loadAnchor(newL,params); document.location.href = this.writeAnchors(document.location.href); // } } else { alert("no last req"); } } WhatAMan.prototype.loadAnchor = function(anchor,params) { if (params || anchor != this.lastAnchor) { this.lastAnchor = anchor; if (!params) { params = $H({ajax: 1}); if (this.anchors['g']) { params = decodeURIComponent(this.anchors['g']).evalJSON(); } } this.loadAjax(this.baseHref+anchor,params); } } function isDefined(variable) { return (!(!( variable||false ))) } WhatAMan.prototype.loadAjax = function(link,params) { /* if (typeof(Mint) != 'undefined') { Mint.TT.behavior.record(link,"/"+link); } */ new Ajax.Updater('content',link,{ method: 'get', encoding: 'UTF-8', parameters: params, onCreate: function() { // $('content') = ''; $('content').hide(); //progressDiv = $('content').clone() // progressDiv.insert({top: WhatAMan.progress}); // progressDiv.show(); // $('content').update(progress); $('ajaxContainer').show(); }, onComplete: function(transport,json) { //fixIEPNG(); $('ajaxContainer').hide(); $('content').show(); WhatAMan.ajaxLinks($('content')); if (json.title) { document.title = json.title; } document.body.className = json.bodyclass; window.scrollTo(0,0); } }); } WhatAMan.prototype.ajaxLinks = function(wrapper) { if (!wrapper) { wrapper = $('wrapper'); } docLinks = wrapper.getElementsByTagName('A'); if (docLinks) { $A(docLinks).each( function(element) { var reqUri = element.href; var reqAnchor = reqUri.lastIndexOf('#'); if (element.href.match("/filter/")) { // alert("Filter link"); } else if (!element.href.match("/filesend/")){ if (element.href.startsWith(WhatAMan.baseHref)) { Element.extend(element); element.observe('click',WhatAMan.getAjax); } } }); } } WhatAMan.prototype.loadPlayer = function() { var xspf = { movie:this.baseHref+"wamgtd-music-player.swf?playlist_url="+this.baseHref+"xspf/wam.xspf&autoresume=1&autoplay=1", id:"xspf", width:"240", height:"270", majorversion:"8", build:"0", allowscriptaccess: "always", wmode: "transparent" }; UFO.create(xspf,'musicBox'); } WhatAMan.prototype.loadBanners = function() { UFO.create({ movie:this.baseHref+"swf/sponsors_fade.swf", id:"xspf", width:"155", height:"90", majorversion:"8", build:"0", allowscriptaccess: "always", wmode: "transparent" },'sponsors'); UFO.create({ movie:this.baseHref+"swf/tickets-on-sale-november-8.swf", id:"xspf", width:"180", height:"110", majorversion:"8", build:"0", allowscriptaccess: "always", wmode: "transparent" },'tix'); UFO.create({ movie:this.baseHref+"swf/pix-from-the-past.swf", id:"xspf", width:"180", height:"110", majorversion:"8", build:"0", allowscriptaccess: "always", wmode: "transparent" },'comp'); new Ajax.PeriodicalUpdater('banner',this.baseHref+'js/ajax/module/Banners/',{ method: 'get', evalScripts: true, frequency: 30, onSuccess: function(transport,json) { } }); } WhatAMan.prototype.loadMBBox = function() { UFO.create({ movie:this.baseHref+"swf/mailinglist.swf?callbackUrl="+this.baseHref+"catchswfemail", id:"xspf", width:"112", height:"200", majorversion:"8", build:"0", allowscriptaccess: "always", wmode: "transparent", flashvars: { callbackUrl: this.baseHref+"catchswfemail" } },'mailBox'); } WhatAMan.prototype.glueMenu = function() { var selector = "li.bandsNav"; // change this only to any css selector you like $$(selector).each(function(element) { ['mouseover','mousedown','mouseup'].each(function(action) { element.observe(action,function(e) { $$(selector).each(function(el) { el.addClassName('sfhover'); }); }); }); element.observe('mouseout',function(e) { $$(selector).each(function(el) { el.removeClassName('sfhover'); }); }); }); } function cleanupFP9IELeaks() { __flash_unloadHandler = function() {}; __flash_savedUnloadHandler = function() {}; } function fixIEPNG() { var version = parseFloat(navigator.appVersion.split('MSIE')[1]); if ((version >= 5.5) && (document.body.filters)) { for(var i=0; i" img.outerHTML = strNewHTML i = i-1 } } } } function initWhatAMan() { WhatAMan.init(); setupZoom(); } var WhatAMan = new WhatAMan(); document.observe('contentloaded',initWhatAMan);