var gastrosourceLocalFunctions = function(){ return{ //this function is production ready moveAddFavouritesSuccessMessage : function(){ //check if the path is like http://www.gastrosource.com/favourites/slides/add/ if(location.href.include('/favourites/slides/')){ $$('#page_tools .links_message').each(function(el){ //move this element to be first child of contentholder var ul = new Element('ul'); ul.appendChild(el); $('contentholder').insert({top: ul}); } ); } }, //the next three are non-production ready functions which are mocking up functionality in the media gallery area //among the problems are //page refresh in the media gallery causes the zoomed image to load (if present) //clicking a link containing tiles.media_gallery_item also causes the zoomed image to load. //This could happen if a user sent the URL of a gallery page to someone else. setUpSimulateImageZoomMediaGallery : function(){ //this is the link which launches the popup image $$('.media_zoom').each(function(el){ el.stopObserving(); el.observe('custom:click',prototypeAZFunctions.simpleAjaxUpdater.curry([prototypeAZFunctions.applyEvents, prototypeAZFunctions.zoomedImage])); }); if(location.search.include('tiles.media_gallery_item')){ //this page has been refreshed, and the image has been changed, so fire the zoom event gastrosourceLocalFunctions.simulateImageZoomMediaGallery(); } }, simulateImageZoomMediaGallery : function(){ //assume one per page in the media gallery Event.fire($$('.media_zoom')[0],'custom:click'); }, setUpMediaGalleryCallbacks : function(){ $$('#media_gallery_viewer .ajax_tile').each(function(el){ el.stopObserving(); el.observe('click',prototypeAZFunctions.ajaxTileUpdater.curry([prototypeAZFunctions.applyEvents, gastrosourceLocalFunctions.setUpSimulateImageZoomMediaGallery, gastrosourceLocalFunctions.simulateImageZoomMediaGallery])); }); } }; }(); //redefine a couple of functions here from the root prototypeAZFunctions.ajaxTileUpdater = function (callBacks, event){ //first of all, kill the request event.stop(); //the link which was clicked var anchor = event.findElement('a'); //its querystring var qs = anchor.search; //as an associative array var qsParams = qs.toQueryParams(); //the desired action //link format //?itemId=7038166&action=remove&tileRefresh=true&panelItemId=8408399 var params = {}; params['tileRefresh'] = true; if(qsParams.tileDefinition){ params['tileDefinition'] = qsParams.tileDefinition; }else{ params['tileDefinition'] = 'tiles.panel.decorator'; } if(qsParams.panelItemId){ params['panelItemId'] = qsParams.panelItemId; } if(qsParams.requestItemKey){ params['requestItemKey'] = qsParams.requestItemKey; }else{ params['requestItemKey'] = qsParams.itemId; } //branchItemKey: "${pageHelper.branchItem.itemId}"} params['ajaxSource'] = true; //to fool app into thinking this is a Spring AJAX request //TODO this probably won't work on a branch so work something out here params['itemId'] = qsParams.itemId; //TODO get the other qs params and make sure they are on the request as well. hard-coded for now if(qsParams.action){ params['action'] = qsParams.action; } if(qsParams.mediaItem){ params['mediaItem'] = qsParams.mediaItem; } //try to get link's parent here? might be easier/more portable //target actually needs to be the parent of this panel as it will write the whole of the panel back in. //might be better to subclass the updater so it can replace an element rather than just replace its contents //this would not work if the parent item contained more than just this panel. I don't think that will happen var targetNode; if(null != qsParams.panelItemId){ targetNode = $('panel' + qsParams.panelItemId).parentNode; }else if (qsParams.targetNode){ targetNode = $(qsParams.targetNode); }else{ //TODO make this work properly targetNode = $('media_gallery_item_holder'); } //in the meantime var targetUrl = ""; // TODO : fix this is a more generic way. if (params['tileDefinition'] == 'tiles.favourites_one_click') { targetUrl = "/"; } var updater = new Ajax.Updater(targetNode,targetUrl,{ method: 'get', parameters: params, onComplete: function(){ //TODO refactor this for(j=0;j