/** * Classe per il supporto al funzionamento di un sito AJAX */ MOWAJAXSiteSupport = Class.create(); MOWAJAXSiteSupport.prototype = { initialize: function() { this.options = Object.extend({ loaderIcon: 'images/loader.gif', loaderSize: 100, useRSH: true, GMapLoaded: false }, arguments[0] || {}); // Associo al caricamento della pagina l'handler onWindowLoad della classe //Event.observe(window, 'load', this.onWindowLoad.bindAsEventListener(this)); }, onWindowLoad: function() { if (this.options.useRSH) { dhtmlHistory.initialize(); // Sovrascrivo l'handler di RSH chiamato al cambiamento di link/pagina dovuto a back/forth (o accesso diretto con #...) dhtmlHistory.addListener(this.historyChange.bindAsEventListener(this)); //historyChange = this.historyChange.bindAsEventListener(this); if (dhtmlHistory.isFirstLoad()) { dhtmlHistory.add('home', ''); } } }, onMenuChangeActions: function(CategoryName, SiteBackground) { $$('.mselected').each(function(e){e.removeClassName('mselected')}); if (CategoryName != 4) $('m'+CategoryName).addClassName('mselected'); if (!!SiteBackground) $('SiteBackground').src = 'images/SiteBackgrounds/'+SiteBackground+'.jpg'; else $('SiteBackground').src = 'images/SiteBackgrounds/Default.jpg'; }, open: function(url) { this.historyChange(url, url); if (!dhtmlHistory.isSafari) dhtmlHistory.add(url); }, historyChange: function(newLocation, historyData) { if (!newLocation) newLocation = 'home'; switch(newLocation) { /* case 'home': theHomeSlide.start(); new Effect.Morph(theHomeSlide.holderDiv, {style:'opacity:1;'}); new Effect.Morph('SecondaryMenuHolder', {style:'opacity:0;'}); this.call('ContentLayer', {CMD:'ShowContent', nid:newLocation}); this.call('SecondaryMenu', {CMD:'ShowSecondaryBar', nid:newLocation}, {useLoader:false}); break; */ default: //theHomeSlide.stop(); //new Effect.Morph(theHomeSlide.holderDiv, {style:'opacity:0;'}); //new Effect.Morph('SecondaryMenuHolder', {style:'opacity:.7;'}); this.call('ContentLayer', {CMD:'ShowContent', nid:newLocation}); this.call('SecondaryMenu', {CMD:'ShowSecondaryBar', nid:newLocation}, {useLoader:false}); break; } //$('FocusHere').focus(); pageTracker._trackPageview('?nid='+newLocation); }, call: function(Element) { var CallParameters = Object.extend({ }, arguments[1] || {}); var pars = Object.extend({ loaderIcon: this.options.loaderIcon, loaderSize: this.options.loaderSize, useLoader: true, replace: false, evalJS: true }, arguments[2] || {}); if (Element && pars.useLoader) { $(Element).innerHTML = ''; } if (Element && !$(Element).visible()) { new Effect.Appear(Element, {duration:0.5}); } new Ajax.Request('_com.php', { method: 'post', parameters: CallParameters, evalJS: pars.evalJS, onFailure: this.AjaxError.bindAsEventListener(this), onComplete: function(transport) { if (Element) { if (pars.replace) { $(Element).replace(transport.responseText); } else { $(Element).innerHTML = transport.responseText; } if (pars.evalJS) transport.responseText.evalScripts(); } } }); }, AjaxError: function(transport) { alert('E\' avvenuto un errore di comunicazione AJAX'); }, findRealPosition: function(obj) { var curleft = curtop = 0; if (obj.offsetParent) { curleft = obj.offsetLeft curtop = obj.offsetTop while (obj = obj.offsetParent) { curleft += obj.offsetLeft curtop += obj.offsetTop } } return {'x': curleft, 'y': curtop}; } } MOWSite = new MOWAJAXSiteSupport(); //////////////////////////////////////////////////////////////////// // Editing inline dei contenuti currentEditingID = 0; currentEditingType = ''; currentEditingField = ''; currentEditingDivID = 0; openContentEditor = function(contentType, contentField, contentID, divID) { if (currentEditingID != 0) { alert("E' possibile editare un articolo alla volta"); return; } currentEditingType = contentType; currentEditingField = contentField; currentEditingID = contentID; currentEditingDivID = divID; $(divID).parentNode.absolutize(); $(divID).absolutize(); // Allunga l'editor se non c'è spazio.. //if ($(divID).getStyle('height').substr(0,$(divID).getStyle('height').length-2) < 400) $(divID).setStyle({height:'600px'}); new Ajax.Request('includes/_getContent.php', { method: 'post', parameters: { 'contentType':currentEditingType, 'contentField':currentEditingField, 'contentID': currentEditingID }, onSuccess: function(transport) { FCKCreate(divID, 'editor1', transport.responseText, saveContentEditing); } }); } saveContentEditing = function() { new Ajax.Request('includes/_commitContent.php', { method: 'post', parameters: { 'contentType':currentEditingType, 'contentField':currentEditingField, 'contentID': currentEditingID, 'editing': FCKGetContents('editor1', false) }, onSuccess: function(transport) { $(currentEditingDivID).innerHTML = FCKGetContents('editor1', false); currentEditingID = 0; currentEditingField = ''; currentEditingType = ''; currentEditingDivID = 0; } }); return false; }