var helpIndex = 0; var HelpsAjaxLoaded = new Array(); var Help = Class.create(); Help.prototype = { TipCreated: false, initialize: function(tag, hook, content, ajax_page, onclick){ this.onclick = onclick; this.ajax_loaded = false; this.ajax = false; this.ajax_page = ajax_page; if (ajax_page.length > 0) this.ajax = true; this.tag = tag; this.hook = hook; this.stmtForHelp = 2; helpIndex++; this.tip = 'tip_' + helpIndex+'_'+tag.id; this.tip_id = 'tip_id' + helpIndex+'_'+tag.id; this.tip_content = 'tip_c' + helpIndex+'_'+tag.id; this.tip_title = 'tipt_' + helpIndex+'_'+tag.id; this.content = content; this.closelink_id = 'close'+this.tip_id; this.timer = 500; this.timeForHelp = 1; if (!this.onclick){ Event.observe(tag, 'mouseover', this.appearBlock.bindAsEventListener(this)); Event.observe(tag, 'mouseout', this.fadeBlock.bindAsEventListener(this));} else { Event.observe(tag, 'click', this.appearBlock.bindAsEventListener(this));}}, togglingBlock: function(){ this.validateplace(); this.stmtForHelp = 0;}, validateplace : function(){ place = validatePlace(this.tip, this.tag, this.hook, 0, this.width, this.height); this.hook = place.hook;}, fadeBlock: function(){ if (this.stmtForHelp == 1){ this.togglingBlock(); this.helpEffect = Effect.Fade(this.tip, {duration: 0.2, afterFinish: (function(){this.stmtForHelp = 2;}).bind(this)});} else setTimeout(this.fadeBlock.bind(this), this.timer);}, ajaxhelp: function(response){ var answer = unescape(response.responseText); vars = answer.split('#?content?#'); HelpsAjaxLoaded[this.ajax_page] = vars; if (this.stmtForHelp == 1){ this.helpEffect = Effect.Fade(this.tip, {duration: 0.2, afterFinish: (function(){this.stmtForHelp = 2; this.appearBlock();}).bind(this)});} this.ajax_loaded = true;}, contentBox:function (params, content){ var width = ''; var nowrap = 'nowrap'; if (params != null){ cap = params[0]; if (this.onclick){ cap = '<div class="left">'+cap+'</div><div class="right"><a id="'+this.closelink_id+'" href="/" class="link" title="Закрыть">Закрыть</a></div>';} content = '<div class="caption p100">'+cap+'</div><div class="p100">' + params[1]+'</div>'; width = ' style="width:350px;" '; nowrap = '';} return this.contentBlock(width, content, nowrap);}, contentBlock: function(width, content, nowrap){ switch (this.hook){ case 'tl': case 't': case 'l': case 'b': case 'bl': return '<table'+width+' id="'+this.tip_id+'" cellpadding="0" cellspacing="0" class="table"><tr><td></td><td class="cube_td"><img src="/e.gif" class="cube" /></td></tr><tr><td><div class="box '+nowrap+'">' + content + '</div></td><td></td></tr></table>'; break; case 'r': case 'tr': case 'br': return '<table'+width+' id="'+this.tip_id+'" cellpadding="0" cellspacing="0" class="table"><tr><td class="cube_td"><img src="/e.gif" class="cube" /></td><td></td></tr><tr><td></td><td><div class="box '+nowrap+'">' + content + '</div></td></tr></table>'; break;}}, appearBlock: function(){ if (this.stmtForHelp == 2){ this.createTip(); if (HelpsAjaxLoaded[this.ajax_page] != null){ $(this.tip).innerHTML = this.contentBox(HelpsAjaxLoaded[this.ajax_page], ''); if (this.onclick) Event.observe($(this.closelink_id), 'click', this.fadeBlock.bindAsEventListener(this)); this.ajax_loaded = true; this.wh_style(this.tip);} else if (!this.ajax_loaded && this.ajax){ new Ajax.Request( this.ajax_page, { requestHeaders: "", onComplete: this.ajaxhelp.bind(this) });} this.togglingBlock(); this.helpEffect = Effect.Appear(this.tip, {duration: 0.2, afterFinish: (function(){this.stmtForHelp = 1;}).bind(this)});}}, createTip: function(){ if (!this.TipCreated){ this.TipCreated = true; tip = this.tip; content = this.content; if (!this.ajax){ var html = this.contentBox(null, content);} else { var html = this.contentBox(null, 'Загрузка <img src="/e.gif" class="ajaxLoader" />');;} objBody = $$('body')[0]; objBody.appendChild(Builder.node('div',{id:tip})); $(tip).className = 'jhelp'; $(tip).innerHTML = html; this.wh_style(tip);}}, wh_style: function(name){ var tag = $(name); tag.style.display = ''; var height = $(this.tip_id).offsetHeight; tag.style.height = height + 'px'; var width = $(this.tip_id).offsetWidth; this.width = width; this.height = height; tag.style.width = width + 'px'; tag.style.display = 'none';}}; var detectedHelps = new Array(); var detectHelp = function(tag){ if (tag.getAttribute && tag.getAttribute("rel")){ var name = 'help'; var rel = tag.getAttribute("rel").toLowerCase(); var content = ''; if (tag.getAttribute("title")){ content = tag.getAttribute("title");} var i = rel.indexOf(name); if (i != -1){ if (!detectedHelps[tag.id]){ var onclick = false; if (rel.substring(0,1) == 'c'){ onclick = true;} if (!onclick) tag.setAttribute("title", ''); var params = rel.substring(name.length + i + 1, rel.length - 1).split('#'); var hook = params[0]; hook = hook.toLowerCase(); var h = new Help(tag, hook, content, params[1], onclick); this.Add('group', h); detectedHelps[tag.id] = true;}} }}; var helpsCollection = new TagCollection("helpsCollection1"); helpsCollection.SetDetector(detectHelp); TagDetect.Add(helpsCollection);