﻿
function AntaRegisterWebSearchWebPart(partClientId,query,enabled)
{
var webPart=GetDomData($(partClientId),AntaWebPartKey);
webPart.WebSearch=new AntaWebSearch(webPart,query,enabled);
}
function AntaWebSearch(webPart,query,enabled)
{
this.WebPart=webPart;
this.SearchInputNode=this.WebPart.Child("SearchInput");
this.Query=query;
this.SearchFormNode=this.WebPart.Child("SearchForm");
SetDomEventData(this.SearchInputNode,this);
this.SearchActive=false;
if(enabled)
{
this.SearchInputNode.onfocus=AntaHandleSearchInputFocus
this.SearchInputNode.onblur=AntaHandleSearchInputBlur
this.WebPart.KeyDownHandler=this;
this.WebPart.InitializationHandler=this;
}
}
AntaWebSearch.prototype.HandlePartInitialize=function()
{
var searchInputNode=this.SearchInputNode;
var webPart=this.WebPart;
if(!IsNullOrEmpty(this.Query))
{
this.SearchInputNode.value=this.Query;
setTimeout(function()
{
webPart.WebForm.Window.WindowNode.document.body.style.visibility="visible";
if(IsDefined(typeof(searchInputNode.select)))
{
searchInputNode.select();
}
searchInputNode.focus()
},10);
}
}
AntaWebSearch.prototype.HandlePartKeyDown=function AntaWebSearch_HandlePartKeyDown()
{
switch(AntaEvent.KeyCode)
{
case 13:
if(this.SearchActive)
{
this.SearchFormNode.submit();
return true;
}
break;
}
return false;
}
function AntaHandleSearchInputFocus(e)
{
if(!IsDefined(typeof(e))){var e=this.document.parentWindow.event;}
StoreEvent(e);
var webSearch=GetDomEventData(this);
webSearch.WebPart.Activate();
webSearch.SearchActive=true;
e.cancelBubble=true;
return false;
}
function AntaHandleSearchInputBlur(e)
{
if(!IsDefined(typeof(e))){var e=this.document.parentWindow.event;}
StoreEvent(e);
var webSearch=GetDomEventData(this);
webSearch.SearchActive=false;
e.cancelBubble=true;
return false;
}


