var helpIndex = 0; var HelpsAjaxLoaded = new Array(); var Help = Class.create(); Help.prototype = { TipCreated: false, Closable: false, ManualOn: false, initialize: function(tag, hook, content, ajax_page, onclick, closable, manual){ this.onclick = onclick; if (closable != undefined) this.Closable = closable; if (manual != undefined) this.ManualOn = manual; 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; this.isShowed = false; 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.contentdiv_id = 'con_div_'+this.tip_id; this.timer = 500; this.timeForHelp = 1; if (!this.onclick){ if (!this.ManualOn){ 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'; cap = ''; if (params != null){ cap = params[0]; content = params[1];} if (params != null || this.Closable){ if (this.onclick){ cap = '<div class="jhcancel"><a href="#" class="block" title="Скрыть" id="'+this.closelink_id+'" onclick="return false;"><img src="/e.gif" class="jhcancel" alt="Скрыть" /></a></div><div class="caption_m">'+cap+'</div>';} content = '<div class="caption">'+cap+'</div><div class="jhcontent">' + content+'</div>'; width = ' style="width:350px;" '; nowrap = '';} return this.contentBlock(width, content, nowrap);}, contentBlock: function(width, content, nowrap){ { return '<table'+width+' id="'+this.tip_id+'" cellpadding="0" cellspacing="0" class="table"><tr><td><div class="box '+nowrap+'" id="'+this.contentdiv_id+'">' + content + '</div></td></tr></table>';}}, appearBlock: function(){ if (this.stmtForHelp == 2){ this.createTip(); if (HelpsAjaxLoaded[this.ajax_page] != null){ $(this.tip).innerHTML = this.contentBox(HelpsAjaxLoaded[this.ajax_page], ''); this.isShowed = true; this.ajax_loaded = true; this.wh_style(this.tip);} else if (!this.ajax_loaded && this.ajax){ this.stmtForHelp = 1; this.isShowed = false; SimpleAjax(this.ajax_page, this.ajaxhelp , '', this, undefined, true);} try{ if (this.onclick || this.Closable) $(this.closelink_id).observe('click', (function(event){ event.stop(); this.fadeBlock();}).bind(this));}catch(e){} 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, '<div class="jhloading">Загрузка <img src="/e.gif" class="ajaxLoader" /></div>');} 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; if (this.isShowed){ var cwidth = $(this.contentdiv_id).offsetWidth; var d = $(this.tip_id); d.style.width = cwidth + 'px';} 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);
