/* * Javascript implementations for FTI website * (c) Papercut Media. No reproduction without permission. Feel free to ask. * Author: Patrick Pittman * Date: June 2007 * Version: 1.0 * Requires: Prototype.js framework, ufo.js for flash loading, Dreamgirl on the other end for AJAXy JSON communication */ function FTI() { this.loaderlock = false; this.baseHref = "http://www.fti.asn.au/"; this.ajaxBase = this.baseHref+"js/ajax/"; this.i = 0; this.complete = []; this.ajaxProgress = new Image(); this.ajaxProgress.src = this.baseHref+"images/icons/ajax-loader.gif"; } FTI.prototype.init = function(e) { // this.watchCartLinks(); this.watchTopLogin(); this.watchSearchBoxes(); } FTI.prototype.watchCartLinks = function() { cartLoop = $$('.addToCart').each(this.cartLoop); } FTI.prototype.cartLoop = function(element) { linkObj = element; glueCart = this.glueCartLinks.bindAsEventListener(this); Event.observe(linkObj,'click',glueCart); } FTI.prototype.glueCartLinks = function(e) { Event.stop(e); src = unescape(Event.element(e).up('a').href); Event.element(e).src = this.baseHref+"images/icons/ajax-loader.gif"; prodID = /\[additem\]\=(\d+)\&/i.exec(src); aisle = /\[fromaisle\]\=([A-Za-z]+)/i.exec(src); variant = /\[variant\]\=([A-Za-z]+)/i.exec(src); // alert('variant '+variant[1]+' prodid '+prodID[1]+' aisle '+aisle[1]); this.addToCart(prodID[1],aisle[1],variant[1]); } FTI.prototype.addToCart = function(prodid,aisle,variant) { alert('in here'); url = this.ajaxBase+'addToCart/'+prodid+'/aisle/'+aisle+'/variant/'+variant; if (!$('cartList')) { cartList = Builder.node('div',{id: 'cartList'}); $('extras').insertBefore(cartList,$('extras').firstDescendant()); } new Ajax.Updater('cartList',url, { onComplete: function(transport, json) { new Effect.Highlight('cartList', { duration: 0.5, startcolor: '#7e6a2c', endcolor:'#5c1111'}) $$('.addToCart').each(function(element) { element.src = FTI.baseHref+"images/icons/add-to-cart.gif"; }); } }); } FTI.prototype.watchSearchBoxes = function() { var searchString = 'SEARCH'; $('searchKeywords').value=searchString; $('searchKeywords').observe('focus',function(e){ if (this.value==searchString) { this.value = ''; } }); $('searchKeywords').observe('blur',function(e){ if (this.value=='') { this.value = searchString; } }); if ($('keywords')) { if ($('bookSearch')) { var keywords = "enter title, author or ISBN"; } else if ($('newsSearch')) { var keywords = "enter title, keywords"; } else { var keywords = "enter keywords"; } if ($('keywords').value=='') { $('keywords').value = keywords; } $('keywords').observe('focus',function(e){ if (this.value==keywords) { this.value = ''; } }); $('keywords').observe('blur',function(e){ if (this.value=='') { this.value = keywords; } }); } } FTI.prototype.watchTopLogin = function() { Event.observe($('topLogin'),'click',function(e) { Event.stop(e); element = Event.element(e); FTI.topLogin = $('topLoginContainer').innerHTML; $('searchBox').hide(); new Ajax.Updater('topLoginContainer',FTI.baseHref+'js/ajaxComponents/login', { onComplete: function(transport) { FTI.loginSetup(); } }) }); } FTI.prototype.addToCart = function(prodid,aisle) { url = this.ajaxBase+'addToCart/'+prodid+'/aisle/'+aisle; new Ajax.Updater('cart',url, { onComplete: function(transport, json) { $('cart').addClassName('box'); new Effect.Highlight('cart', { duration: 0.5, startcolor: '#7e6a2c', endcolor:'#5c1111'}) $$('.addToCart').each(function(element) { element.src = FTI.baseHref+"images/icons/add-to-cart.gif"; }); } }); } /* This is a lot of code just to switch out values in a couple of forms, but we need to change the password field's input type from 'text' to 'password'. IE doesn't let you do this on existing elements, so instead we have to destroy and recreate the element and rebind event listeners -- also have to make sure we unbind listeners before destruction or IE complains about type mismatches. Ouch, thanks MS. */ FTI.prototype.loginSetup = function() { if ($('loginClose')) { Event.observe($('loginClose'),'click',function(e) { $('searchBox').show(); $('topLoginContainer').replace("