/*
Javascript functionality common to all files
If adding to this, please bear in mind progressive enhancement
- test for functionality before using it to avoid errors
*/
function bookmarkPage(){
//used by "bookmark page" link in page tools
if(window.sidebar){
//syntax for FF. 3rd empty string argument is required
window.sidebar.addPanel(document.title, location.href,'');
}else{
if(window.external){
//syntax for IE
window.external.AddFavorite(location.href,document.title);
}
}
}
function printPage(){
//used by "print page" link in page tools
window.print();
}
function findExitRamps(){
//identify any links with an exit ramp
aryExtLinks=getElementsByClassName(document,'external');
/*
possible HTML is:
*/
for(i=0;i0){
selectBox.options[i].selected=false;
}
//record setting of each option in array
selectBoxSelected[i]=selectBox.options[i].selected;
}
}
}
function toggleRelatedSelects(){
//checks whether "this site only" in site select box is selected
//if so, enables audience and area select boxes
//if not, disables them
var siteSelectBox=document.getElementById('rskey');
var areaSelectBox=getNamedElementId('select','sakey');
var audienceSelectBox=document.getElementById('saudkey');
if(siteSelectBox.options[0].selected==true){
if(areaSelectBox){
areaSelectBox.disabled=false;
}
if(audienceSelectBox){
audienceSelectBox.disabled=false;
}
}else{
if(areaSelectBox){
areaSelectBox.disabled=true;
}
if(audienceSelectBox){
audienceSelectBox.disabled=true;
}
}
return true;
}
function showHelp(){
//shows or hides the help popup for form field onclick
//popup also appears on hover - this is for keyboard users
//get a reference to the a tag which was clicked
el=this;
//switch off any other help popups
els=getElementsByClassName(document,'inhelplink');
already_set=false;
if(els){
for(var i=0,j=els.length; i0 && currentClass.indexOf(oldValue)!==-1){
//replace it
newClass=currentClass.replace(oldValue,newValue);
}else{
if(currentClass.indexOf(newValue)==-1){
//newValue not already in the className
//add it
newClass=currentClass+' '+newValue;
}else{
//newValue is already there so keep it as it is
newClass=currentClass;
}
}
}
setAttributeCrossBrowser(element,'class',newClass);
break;
default:
//this isn't finished - doesn't toggle at the moment, just overwrites
setAttributeCrossBrowser(element,attribute,newValue);
break;
}
}
function addPrototypeEffects(){
if(prototypeAZFunctions && prototypeAZFunctions.hasPrototype()){
prototypeAZFunctions.addDatePickers();
prototypeAZFunctions.addTimePickers();
prototypeAZFunctions.addExitRamps();
prototypeAZFunctions.addOverlayBackgroundLoader();
prototypeAZFunctions.addPdfBasket();
prototypeAZFunctions.applyEvents();
/*$$('.blind').each(function(el){
el.observe('click',toggleBlinds);
});
*/
/*something like this
new Effect.Move($('event_details'),{ x: 0, y: 0, mode: 'absolute' });
replace the X and Y values with Event.pointerX(event);
see http://www.prototypejs.org/api/event/pointerX
maybe combine with effect.appear - move it first then make it appear
try to make this generic - maybe a class on the link?
http://wiki.github.com/madrobby/scriptaculous/effect-appear
also have a think about absolutise in prototype
*/
}
}
var minOpacity = 0.3;
var prototypeAZFunctions = function(){
//anything here is private
var default_container_name = 'overlay_container';
return{
//anything here is public. Call using prototypeAZFunctions.functionName();
hasPrototype : function(){
return typeof Prototype !== 'undefined';
},
addDatePickers : function(){
$$('.datepicker').each(function(el){
var picker = new Control.DatePicker(el, {datePicker: true,
timePicker: false,
locale: 'en_GB'
});
});
},
addTimePickers : function(){
$$('.timepicker').each(function(el){
var picker = new Control.DatePicker(el, {datePicker: false,
timePicker: true,
use24hrs:true,
locale: 'en_GB'
});
});
},
addPdfBasket : function(){
var callBacks = [prototypeAZFunctions.addPdfBasket,prototypeAZFunctions.pdfBasket];
$$('.ajax_pdf_basket').each(function(el){
//this is the element where the response should be directed
//replace the existing link with an AJAX request
el.observe(
'click',
//this will add in the passed arguments to the default argument of the event
//trouble is that the event is the last argument.
//Convention is that it is the first
prototypeAZFunctions.simpleAjaxUpdater.curry(callBacks)
);
});
},
addExitRamps : function(){
var callBacks = [prototypeAZFunctions.exitRamp];
$$('.exit_ramp').each(function(el){
//this is the element where the response should be directed
//replace the existing link with an AJAX request
el.observe('click', prototypeAZFunctions.simpleAjaxUpdater.curry(callBacks)
);
});
},
addOverlayBackgroundLoader : function(){
//simply detects the presence of an anchor with ID loadUrl containing a URL
//and loads it in a div named overlay_background
//which is created on the fly
var anchor = $('loadUrl');
var outerDiv = document.body.firstDescendant();
if(anchor){
var url = anchor.href;
if(url != ''){
var targetName = 'overlay_background';
anchor.remove();
target = new Element('div');
//native JS method here
target.setAttribute('id',targetName);
document.body.insertBefore(target,outerDiv);
var updater = new Ajax.Updater(target,url,{
method: 'get',
parameters: {ajaxRequestFromOverlay:true},
onSuccess: function(){prototypeAZFunctions.fadeOutElement(target);}
});
}
}
},
fadeOutElement : function(el){
//check whether the body is already faded
var fadedSelector = new Selector('.faded');
var docBody = document.body;
if(!fadedSelector.match(docBody)){
el.fade({duration:0.5, from:1, to:minOpacity});
docBody.addClassName('faded');
docBody.firstDescendant().addClassName('bottomlayer');
}
},
fadeOutBackground : function(){
prototypeAZFunctions.fadeOutElement(document.body.firstDescendant());
},
fadeInBackground : function(){
document.body.removeClassName('faded');
document.body.firstDescendant().fade({duration:0.5, from:minOpacity, to:1});
document.body.firstDescendant().removeClassName('bottomlayer');
},
hideOverlay : function(el, event, stopEvent){
if(stopEvent){
event.stop();
}
//fade out the link, then remove it
$(default_container_name).fade({duration:1.0, from:1, to:0});
$(default_container_name).remove();
prototypeAZFunctions.fadeInBackground();
},
exitRamp : function(){
//make cancel button just empty the overlay
$$('div[id="' + default_container_name + '"] .cancel').each(function(el){
el.observe('click',function(event){
prototypeAZFunctions.hideOverlay(el, event, true);
});
});
},
simpleAjaxUpdater : function(callBacks, event){
//event last as a result of use of curry
//pull the necessary information from the updater
//this format should be used for all requests which are AJAX enabled
//first of all, kill the request
event.stop();
var anchor = event.findElement('a');
var newWindow = anchor.readAttribute('target');
var params = {};
params['ajaxSource'] = true;//makes webapp believe this is an AJAX request (same syntax as a Spring AJAX request)
if(newWindow != ''){
params['newWindow'] = true;
}
var target;
if(!$(default_container_name)){
target = new Element('div');
//native JS method here
target.setAttribute('id',default_container_name);
document.body.appendChild(target);
}else{
target = $(default_container_name);
}
var updater = new Ajax.Updater(target,anchor.href,{
method: 'get',
parameters: params,
onSuccess: function(){prototypeAZFunctions.fadeOutBackground();},
onComplete: function(){
//TODO refactor this
for(j=0;j