var publicPath = "/"; var AjaxRequest = Class.create( { initialize: function(url, options) { this.url = url || ''; this.options = options || { }; this.onSuccess = Object.isFunction(this.options.onSuccess) ? this.options.onSuccess : Prototype.emptyFunction; this.onFailure = Object.isFunction(this.options.onFailure) ? this.options.onFailure : Prototype.emptyFunction; this.parameters = this.options.parameters || { }; this.method = this.options.method || 'post'; this.caching = this.options.caching || false; this.loader = this.options.loader || null; this.user = this.options.user || null; this.password = this.options.password || null; this.async = this.options.password || true; this.send(); }, send: function() { var req = new JsHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { if (!req.responseText.strip().empty()) { this.onFailure(req); } else { this.onSuccess(req.responseJS); } } } var fx = req.onreadystatechange; req.onreadystatechange = fx.bind(this); req.loader = this.loader; req.caching = this.caching; req.open(this.method, this.url, this.async, this.user, this.password); req.send(this.parameters); } }); function pr(obj) { var res = ''; if (Object.isString(obj) || Object.isNumber(obj)) { res += obj; } else { $H(obj).each(function(el) { res += el.key + ' = ' + el.value + '
'; }); } var debug = $('debug'); if (!debug) { debug = new Element('div', { id: 'debug' }); $(document.body).insert(debug); } debug.update(res); } Element.addMethods({ eventFire: function(element, eventName) { element = $(element); if (element == document && document.createEvent && !element.dispatchEvent) element = document.documentElement; var event; eventName = eventName.toLowerCase(); if (document.createEvent) { var eventType; eventName = eventName.replace(/^on/, ''); event = document.createEvent('HTMLEvents'); event.initEvent(eventName, true, true); } else { if (!eventName.match(/^on/)) eventName = 'on' + eventName; event = document.createEventObject(); } if (document.createEvent) element.dispatchEvent(event); else element.fireEvent(eventName, event); return Event.extend(event); } }); // main menu var loadedNodes = new Object(); var hideUniqNodes = new Array(); var nodesInfo = new Object(); function setChildrenUniqNames(uniqName) { for (var i in loadedNodes) { if (i == uniqName) { $A(loadedNodes[i]).each(function(n) { hideUniqNodes.push(n); setChildrenUniqNames(n); }); } } } function switchNodes(event) { Event.stop(event); var elm = Event.element(event); while (elm.id.empty() && !elm.id.match(/menuLeft_/)) { elm = elm.up(); } var uniqName = elm.id.substr(9); if (nodesInfo[uniqName]['open']) { hideNodes(uniqName); } else { showNodes(uniqName); } } function hideNodes(uniqName) { setChildrenUniqNames(uniqName); nodesInfo[uniqName]['closed'] = true; nodesInfo[uniqName]['open'] = false; hideUniqNodes.each(function(n) { if ($('menuLeft_' + n)) { $('menuLeft_' + n).hide(); if (!nodesInfo[n]) nodesInfo[n] = new Object(); } }); hideUniqNodes.clear(); } function showNodes(uniqName) { var ids = loadedNodes[uniqName]; nodesInfo[uniqName]['closed'] = false; nodesInfo[uniqName]['open'] = true; ids.each(function(n) { if ($('menuLeft_' + n)) { $('menuLeft_' + n).show(); nodesInfo[n]['closed'] = false; nodesInfo[n]['open'] = true; } }) } function getChildren(event) { var args = $A(arguments); args.shift(); var lang = args.first() || 'ru'; Event.stop(event); var elm = Event.element(event); elm.stopObserving('click', getChildren); elm.observe('click', switchNodes); while (elm.id.empty() && !elm.id.match(/menuLeft_/)) { elm = elm.up(); } var uniqName = elm.id.substr(9); var req = new JsHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { if (req.responseJS) { new Insertion.After("menuLeft_" + uniqName, req.responseJS.children); var mas = $A(req.responseJS.childrenArray); loadedNodes[uniqName] = new Array(); nodesInfo[uniqName] = new Object(); nodesInfo[uniqName]['open'] = true; nodesInfo[uniqName]['closed'] = false; mas.each(function(n) { loadedNodes[uniqName].push(n.uniqName); }); } if (req.responseText) { $("debug").innerHTML = req.responseText; } } } req.open(null, 'form.POST '+publicPath+'_ajax/menu.php?lang='+lang+'', true); req.send( { action: "getChildren", ajax: "1", uniqName: uniqName }); } // main menu