...

View Full Version : Javascript modification/search function problems



tarnis
06-18-2008, 01:04 AM
Hello all,

Been working on a project, and have needed to make some modifications to the guy I had hired a ways back's work. Anyways fixxed a few things, but the final one continues to elude me and was really pretty desperate for some help.

This is a map running through MS live maps, need a small hand with making the search function work properly. As it is, when you search for something it searches all the nodes from what I can tell in the XML file where I need it to only search the "Keywords" node. So far anything that looked like the right place to edit this has broken things... would appreciate a hand very much.

tomws
06-18-2008, 04:44 AM
Posting code is better than a file. Paranoids like me won't risk downloading a file from a first-post member.

tarnis
06-18-2008, 12:38 PM
I don't mind posting it, it's just a huge chunk of code, and afraid of leaving anything out. here's a link to where I'm testing things out to see what's going on. http://www.metagraphical.com/boca/jupiter

tarnis
06-18-2008, 12:50 PM
///////////////////////////////////////////////////////////
///Version 1.2
///Platform: Virtual Earth 6
///////////////////////////////////////////////////////////
var MetaGraphical=new Object()
var Mainmap=null
var Minimap=null
var Data=new Array()
var DataIndex=0
var firstSearchFocus=true
function Page_Load(){
var layer=new VETileSourceSpecification("FAU","http://www.metagraphical.com/boca/jupiter/tiles/%4.gif")
layer.NumServers=1
layer.Bounds=[new VELatLongRectangle(new VELatLong(26.8877,-80.1179),new VELatLong(26.36141,-80.09497))]
layer.MinZoomLevel=9
layer.MaxZoomLevel=19
layer.Opacity=1.0
layer.ZIndex=100
var mapArgs=new MetaGraphical.MapArgs("MainMap",new

VELatLong(26.8863,-80.1186),14,VEMapStyle.Road,false,VEMapMode.Mode2D,VEDistanceUnit.Miles)
Mainmap=new MetaGraphical.Map(mapArgs,layer)
onloadXML(XML.load("xml/JupiterBuildings.xml"))}
function onloadXML(xmldoc){
makeTreeview(xmldoc.getElementsByTagName("FAUMap")[0],document.getElementById("ObjectList"))}
function makeTreeview(tree,element){
var masterUL=document.createElement("ul")
element.appendChild(masterUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addTypeNodes(tree.childNodes[i],masterUL,true)}}
function addTypeNodes(tree,masterUL,skipAZ){
if(tree.nodeType<3){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("displayname")
if(skipAZ){
childLI.className="Collapsed"
}else{
childLI.className="Expanded"}
childLI.onclick=ToggleNodeStateHandler
masterUL.appendChild(childLI)
if(tree.hasChildNodes()){
var childUL=document.createElement("ul")
childLI.appendChild(childUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addLetterNodes(tree.childNodes[i],childUL,skipAZ)}}}}
function addLetterNodes(tree,masterUL,skip){
if(tree.nodeType<3){
if(!skip){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("name")
childLI.className="Collapsed"
childLI.onclick=ToggleNodeStateHandler
masterUL.appendChild(childLI)
if(tree.hasChildNodes()){
var childUL=document.createElement("ul")
childLI.appendChild(childUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addNodes(tree.childNodes[i],childUL)}}
}else{
if(tree.hasChildNodes()){
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addNodes(tree.childNodes[i],masterUL)}}}}}
function addNodes(tree,masterUL){
if(tree.nodeType<3){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("name")
childLI.setAttribute("dataid",DataIndex++)
childLI.onclick=LaunchBuilding
masterUL.appendChild(childLI)
var name=tree.getAttribute("name")
var num=tree.getAttribute("num")
var id=tree.getAttribute("id")
var bgswf=""
var xmlcell=tree.getElementsByTagName("bgswf")[0]
if(xmlcell){
bgswf=xmlcell.getAttribute("url")}
var desc=GetNullElement(tree,"desc")
var links=GetNullElement(tree,"links")
var movieClipvalue=GetNullElement(tree,"movieClipvalue")
var photovalue=GetNullElement(tree,"photovalue")
var latitude=GetNullElement(tree,"latitude")
var longitude=GetNullElement(tree,"longitude")
var keywords=GetNullElement(tree,"keywords")
var loc
if(latitude.length>0&&longitude.length>0){
loc=new VELatLong(parseFloat(latitude),parseFloat(longitude))}
Data.push(new MetaGraphical.Building(name,num,id,bgswf,desc,links,movieClipvalue,photovalue,loc,keywords))}}
function LaunchBuilding(event){
PreventBubbleHandler(event)
SetBuilding(this.getAttribute("dataid"))}
function SetBuilding(index){
Mainmap.SetLocation(Data[index].Loc)
document.getElementById("BuildingName").innerHTML=""
document.getElementById("BuildingDesc").innerHTML=""
document.getElementById("BuildingLinks").innerHTML=""
var buildingimg=document.getElementById("BuildingPhoto")
buildingimg.style.display="none"
window.setTimeout("SetBuildingCallback("+index+")",200)}
function SetBuildingCallback(index){
var buildingimg=document.getElementById("BuildingPhoto")
buildingimg.style.display="none"
document.getElementById("BuildingName").innerHTML=Data[index].Name
document.getElementById("BuildingDesc").innerHTML=Data[index].Desc
document.getElementById("BuildingLinks").innerHTML=Data[index].Links
if(Data[index].Photovalue.length>0){
buildingimg.src="buildingimages/"+Data[index].Photovalue
buildingimg.style.display="block"
}else{
buildingimg.style.display="none"}
document.getElementById("MapDescribeContainer").style.display="block"
document.getElementById("searchresults").style.display="none"
document.getElementById("FAUSearchbox").value="Search Map"}
function onSearchFocus(){
document.getElementById("searchresults").style.display="none"
if(firstSearchFocus){
firstSearchFocus=false
document.getElementById("FAUSearchbox").value=""}}
function SearchFAU(searchtext){
var str=""
for(var x=0;x<DataIndex;x++){
if(Data[x].Keywords.toLowerCase().indexOf(searchtext.toLowerCase())!=-1 ||

Data[x].Name.toLowerCase().indexOf(searchtext.toLowerCase())!=-1){
str+="<a href='#' title='"+Data[x].Keywords.replace("'","&#39;")+"'

onclick='javascript:SetBuilding("+x+")'>"+Data[x].Name+"</a><br />"}}
document.getElementById("searchresults").innerHTML=str
document.getElementById("searchresults").style.display="block"}
function Page_Unload(){
if(Mainmap!=null){
Mainmap.Dispose()
Mainmap=null}
if(Minimap!=null){
Minimap.Dispose()
Minimap=null}}
if(window.attachEvent){
window.attachEvent("onload",Page_Load)
window.attachEvent("onunload",Page_Unload)
}else{
window.addEventListener("DOMContentLoaded",Page_Load,false)
window.addEventListener("unload",Page_Unload,false)}
MetaGraphical.Building=function(name,num,id,bgswf,desc,links,movieClipvalue,photovalue,loc,keywords) {
this.Name=name
this.Num=num
this.Id=id
this.Bgswf=bgswf
this.Desc=desc
this.Links=links
this.MovieClipvalue=movieClipvalue
this.Photovalue=photovalue
this.MovieClipvalue=movieClipvalue
this.Loc=loc
this.Keywords=keywords}
MetaGraphical.Map=function(mapArgs,layer){
this._mapArgs=mapArgs
this._layer=layer
this._map=null
this._pin=null
this._init()}
MetaGraphical.Map.prototype={
_init: function(){
this._map=new VEMap(this._mapArgs.DivID)
this._map.LoadMap(this._mapArgs.Center,this._mapArgs.Zoomlevel,this._mapArgs.Style,this._mapArgs.Fix ed,this._mapArgs.Mode)
this._map.SetScaleBarDistanceUnit(this._mapArgs.Scale)
if(!this._mapArgs.Showdashboard){
this._map.HideDashboard()}
this._map.AttachEvent("onmouseover",this._onMapMouseOver)
this._map.AddTileLayer(this._layer,true)
},
ZoomIn: function(){
this._map.ZoomIn()
},
ZoomOut: function(){
this._map.ZoomOut()
},
Zoom: function(level){
this._map.SetZoomLevel(level)
},
PanNorth: function(){
this._map.Pan(0,-200)
},
PanEast: function(){
this._map.Pan(200,0)
},
PanSouth: function(){
this._map.Pan(0,200)
},
PanWest: function(){
this._map.Pan(-200,0)
},
SetLocation: function(loc){
if(loc){
this._map.SetCenterAndZoom(loc,17)
if(this._pin){
this._pin.SetPoints(loc)
}else{
this._pin=new VEShape(VEShapeType.Pushpin,loc)
if(isIE6){
this._pin.SetCustomIcon("images/crosshair.gif")
}else{
this._pin.SetCustomIcon("images/crosshair.png")}
this._map.AddShape(this._pin)}
}else if(this._pin){
this._map.DeleteShape(this._pin)
this._pin=null}
},
_onMapMouseOver: function(e){
if(e.elementID){
return true}
},
Dispose: function(){
if(this._map !=null){
this._map.Dispose()}
this._mapArgs=null
this._pin=null
this._map=null
this._layer=null}}
MetaGraphical.MapArgs=function(divID,center,zoomlevel,style,fixed,mode,scale,showdashboard){
this.DivID=divID
this.Center=center
this.Zoomlevel=zoomlevel
this.Style=style
this.Fixed=fixed
this.Scale=scale
this.Showdashboard=showdashboard}
var XML=new Object()
XML.newDocument=function(rootTagName,namespaceURL){
if(!rootTagName)rootTagName=""
if(!namespaceURL)namespaceURL=""
if(document.implementation&&document.implementation.createDocument){
return document.implementation.createDocument(namespaceURL,rootTagName,null)}
else{
var doc=new ActiveXObject("MSXML2.DOMDocument")
if(rootTagName){
var prefix=""
var tagname=rootTagName
var p=rootTagName.indexOf(':')
if(p !=-1){
prefix=rootTagName.substring(0,p)
tagname=rootTagName.substring(p+1)}
if(namespaceURL){
if(!prefix)prefix="a0"}
else prefix=""
var text="<"+(prefix?(prefix+":"):"")+tagname+
(namespaceURL
?(" xmlns:"+prefix+'="'+namespaceURL+'"')
:"")+
"/>"
doc.loadXML(text)}
return doc}}
XML.load=function(url){
var xmldoc=XML.newDocument()
xmldoc.async=false
xmldoc.load(url)
return xmldoc}
XML.loadAsync=function(url,callback){
var xmldoc=XML.newDocument()
if(document.implementation&&document.implementation.createDocument){
xmldoc.onload=function(){callback(xmldoc);}}
else{
xmldoc.onreadystatechange=function(){
if(xmldoc.readyState==4)callback(xmldoc)}}
xmldoc.load(url)}
Array.prototype.indexOf=IndexOf
function ToggleClass(element,firstClass,secondClass,event){
event.cancelBubble=true
var classes=element.className.split(" ")
var firstClassIndex=classes.indexOf(firstClass)
var secondClassIndex=classes.indexOf(secondClass)
if(firstClassIndex==-1&&secondClassIndex==-1){
classes[classes.length]=firstClass}
else if(firstClassIndex !=-1){
classes[firstClassIndex]=secondClass}
else{
classes[secondClassIndex]=firstClass}
element.className=classes.join(" ")}
function IndexOf(item){
for(var i=0;i<this.length;i++){
if(this[i]==item){
return i}}
return-1}
function ToggleNodeStateHandler(event){
ToggleClass(this,"Collapsed","Expanded",(event==null)? window.event : event)}
function PreventBubbleHandler(event){
if(!event)event=window.event
event.cancelBubble=true}
function GetNullElement(xmlrow,tagname){
var xmlcell=xmlrow.getElementsByTagName(tagname)[0]
return(xmlcell&&xmlcell.firstChild)? xmlcell.firstChild.data : ""}

tomws
06-18-2008, 03:24 PM
One more helpful task would be to wrap your code in [code] tags as mentioned in one of the upper stickies in the forum. It preserves spacing, so it makes for less bleeding eyes while looking at stacks of code.

As for the problem, I'm having trouble tracing through the javascript, so I'll be no help to you. Perhaps the cleaner (wrapped) code will allow someone else to identify your problem.

tarnis
06-21-2008, 02:38 PM
I'd of edited the last reply with the code, but it won't let me edit it for some reason now. (on the other hand I can PM myself so I dunno what's up with that) so here's the code in blocks. was actually looking for something like that but didn't see it in the help, but did just notice the sticky now that you mention it.



///////////////////////////////////////////////////////////
///Version 1.2
///Platform: Virtual Earth 6
///////////////////////////////////////////////////////////
var MetaGraphical=new Object()
var Mainmap=null
var Minimap=null
var Data=new Array()
var DataIndex=0
var firstSearchFocus=true
function Page_Load(){
var layer=new VETileSourceSpecification("FAU","http://www.metagraphical.com/boca/tiles/&#37;4.gif")
layer.NumServers=1
layer.Bounds=[new VELatLongRectangle(new VELatLong(26.38733,-80.12132),new VELatLong(26.36141,-80.09497))]
layer.MinZoomLevel=9
layer.MaxZoomLevel=19
layer.Opacity=1.0
layer.ZIndex=100
var mapArgs=new MetaGraphical.MapArgs("MainMap",new VELatLong(26.3745,-80.1033),14,VEMapStyle.Road,false,VEMapMode.Mode2D,VEDistanceUnit.Miles)
Mainmap=new MetaGraphical.Map(mapArgs,layer)
onloadXML(XML.load("xml/BocaBuildings.xml"))}
function onloadXML(xmldoc){
makeTreeview(xmldoc.getElementsByTagName("FAUMap")[0],document.getElementById("ObjectList"))}
function makeTreeview(tree,element){
var masterUL=document.createElement("ul")
element.appendChild(masterUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addTypeNodes(tree.childNodes[i],masterUL,true)}}
function addTypeNodes(tree,masterUL,skipAZ){
if(tree.nodeType<3){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("displayname")
if(skipAZ){
childLI.className="Collapsed"
}else{
childLI.className="Expanded"}
childLI.onclick=ToggleNodeStateHandler
masterUL.appendChild(childLI)
if(tree.hasChildNodes()){
var childUL=document.createElement("ul")
childLI.appendChild(childUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addLetterNodes(tree.childNodes[i],childUL,skipAZ)}}}}
function addLetterNodes(tree,masterUL,skip){
if(tree.nodeType<3){
if(!skip){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("name")
childLI.className="Collapsed"
childLI.onclick=ToggleNodeStateHandler
masterUL.appendChild(childLI)
if(tree.hasChildNodes()){
var childUL=document.createElement("ul")
childLI.appendChild(childUL)
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addNodes(tree.childNodes[i],childUL)}}
}else{
if(tree.hasChildNodes()){
var nodes=tree.childNodes.length
for(var i=0;i<nodes;i++){
addNodes(tree.childNodes[i],masterUL)}}}}}
function addNodes(tree,masterUL){
if(tree.nodeType<3){
var childLI=document.createElement("li")
childLI.innerHTML=tree.getAttribute("name")
childLI.setAttribute("dataid",DataIndex++)
childLI.onclick=LaunchBuilding
masterUL.appendChild(childLI)
var name=tree.getAttribute("name")
var num=tree.getAttribute("num")
var id=tree.getAttribute("id")
var bgswf=""
var xmlcell=tree.getElementsByTagName("bgswf")[0]
if(xmlcell){
bgswf=xmlcell.getAttribute("url")}
var desc=GetNullElement(tree,"desc")
var links=GetNullElement(tree,"links")
var movieClipvalue=GetNullElement(tree,"movieClipvalue")
var photovalue=GetNullElement(tree,"photovalue")
var latitude=GetNullElement(tree,"latitude")
var longitude=GetNullElement(tree,"longitude")
var keywords=GetNullElement(tree,"keywords")
var loc
if(latitude.length>0&&longitude.length>0){
loc=new VELatLong(parseFloat(latitude),parseFloat(longitude))}
Data.push(new MetaGraphical.Building(name,num,id,bgswf,desc,links,movieClipvalue,photovalue,loc,keywords))}}
function LaunchBuilding(event){
PreventBubbleHandler(event)
SetBuilding(this.getAttribute("dataid"))}
function SetBuilding(index){
Mainmap.SetLocation(Data[index].Loc)
document.getElementById("BuildingName").innerHTML=""
document.getElementById("BuildingDesc").innerHTML=""
document.getElementById("BuildingLinks").innerHTML=""
var buildingimg=document.getElementById("BuildingPhoto")
buildingimg.style.display="none"
window.setTimeout("SetBuildingCallback("+index+")",200)}
function SetBuildingCallback(index){
var buildingimg=document.getElementById("BuildingPhoto")
buildingimg.style.display="none"
document.getElementById("BuildingName").innerHTML=Data[index].Name
document.getElementById("BuildingDesc").innerHTML=Data[index].Desc
document.getElementById("BuildingLinks").innerHTML=Data[index].Links
if(Data[index].Photovalue.length>0){
buildingimg.src="buildingimages/"+Data[index].Photovalue
buildingimg.style.display="block"
}else{
buildingimg.style.display="none"}
document.getElementById("MapDescribeContainer").style.display="block"
document.getElementById("searchresults").style.display="none"
document.getElementById("FAUSearchbox").value="Search Map"}
function onSearchFocus(){
document.getElementById("searchresults").style.display="none"
if(firstSearchFocus){
firstSearchFocus=false
document.getElementById("FAUSearchbox").value=""}}
function SearchFAU(searchtext){
var str=""
for(var x=0;x<DataIndex;x++){
if(Data[x].Keywords.toLowerCase().indexOf(searchtext.toLowerCase())!=-1 || Data[x].Name.toLowerCase().indexOf(searchtext.toLowerCase())!=-1){
str+="<a href='#' title='"+Data[x].Keywords.replace("'","&#39;")+"' onclick='javascript:SetBuilding("+x+")'>"+Data[x].Name+"</a><br />"}}
document.getElementById("searchresults").innerHTML=str
document.getElementById("searchresults").style.display="block"}
function Page_Unload(){
if(Mainmap!=null){
Mainmap.Dispose()
Mainmap=null}
if(Minimap!=null){
Minimap.Dispose()
Minimap=null}}
if(window.attachEvent){
window.attachEvent("onload",Page_Load)
window.attachEvent("onunload",Page_Unload)
}else{
window.addEventListener("DOMContentLoaded",Page_Load,false)
window.addEventListener("unload",Page_Unload,false)}
MetaGraphical.Building=function(name,num,id,bgswf,desc,links,movieClipvalue,photovalue,loc,keywords) {
this.Name=name
this.Num=num
this.Id=id
this.Bgswf=bgswf
this.Desc=desc
this.Links=links
this.MovieClipvalue=movieClipvalue
this.Photovalue=photovalue
this.MovieClipvalue=movieClipvalue
this.Loc=loc
this.Keywords=keywords}
MetaGraphical.Map=function(mapArgs,layer){
this._mapArgs=mapArgs
this._layer=layer
this._map=null
this._pin=null
this._init()}
MetaGraphical.Map.prototype={
_init: function(){
this._map=new VEMap(this._mapArgs.DivID)
this._map.LoadMap(this._mapArgs.Center,this._mapArgs.Zoomlevel,this._mapArgs.Style,this._mapArgs.Fix ed,this._mapArgs.Mode)
this._map.SetScaleBarDistanceUnit(this._mapArgs.Scale)
if(!this._mapArgs.Showdashboard){
this._map.HideDashboard()}
this._map.AttachEvent("onmouseover",this._onMapMouseOver)
this._map.AddTileLayer(this._layer,true)
},
ZoomIn: function(){
this._map.ZoomIn()
},
ZoomOut: function(){
this._map.ZoomOut()
},
Zoom: function(level){
this._map.SetZoomLevel(level)
},
PanNorth: function(){
this._map.Pan(0,-200)
},
PanEast: function(){
this._map.Pan(200,0)
},
PanSouth: function(){
this._map.Pan(0,200)
},
PanWest: function(){
this._map.Pan(-200,0)
},
SetLocation: function(loc){
if(loc){
this._map.SetCenterAndZoom(loc,15)
if(this._pin){
this._pin.SetPoints(loc)
}else{
this._pin=new VEShape(VEShapeType.Pushpin,loc)
if(isIE6){
this._pin.SetCustomIcon("images/crosshair.gif")
}else{
this._pin.SetCustomIcon("images/crosshair.png")}
this._map.AddShape(this._pin)}
}else if(this._pin){
this._map.DeleteShape(this._pin)
this._pin=null}
},
_onMapMouseOver: function(e){
if(e.elementID){
return true}
},
Dispose: function(){
if(this._map !=null){
this._map.Dispose()}
this._mapArgs=null
this._pin=null
this._map=null
this._layer=null}}
MetaGraphical.MapArgs=function(divID,center,zoomlevel,style,fixed,mode,scale,showdashboard){
this.DivID=divID
this.Center=center
this.Zoomlevel=zoomlevel
this.Style=style
this.Fixed=fixed
this.Scale=scale
this.Showdashboard=showdashboard}
var XML=new Object()
XML.newDocument=function(rootTagName,namespaceURL){
if(!rootTagName)rootTagName=""
if(!namespaceURL)namespaceURL=""
if(document.implementation&&document.implementation.createDocument){
return document.implementation.createDocument(namespaceURL,rootTagName,null)}
else{
var doc=new ActiveXObject("MSXML2.DOMDocument")
if(rootTagName){
var prefix=""
var tagname=rootTagName
var p=rootTagName.indexOf(':')
if(p !=-1){
prefix=rootTagName.substring(0,p)
tagname=rootTagName.substring(p+1)}
if(namespaceURL){
if(!prefix)prefix="a0"}
else prefix=""
var text="<"+(prefix?(prefix+":"):"")+tagname+
(namespaceURL
?(" xmlns:"+prefix+'="'+namespaceURL+'"')
:"")+
"/>"
doc.loadXML(text)}
return doc}}
XML.load=function(url){
var xmldoc=XML.newDocument()
xmldoc.async=false
xmldoc.load(url)
return xmldoc}
XML.loadAsync=function(url,callback){
var xmldoc=XML.newDocument()
if(document.implementation&&document.implementation.createDocument){
xmldoc.onload=function(){callback(xmldoc);}}
else{
xmldoc.onreadystatechange=function(){
if(xmldoc.readyState==4)callback(xmldoc)}}
xmldoc.load(url)}
Array.prototype.indexOf=IndexOf
function ToggleClass(element,firstClass,secondClass,event){
event.cancelBubble=true
var classes=element.className.split(" ")
var firstClassIndex=classes.indexOf(firstClass)
var secondClassIndex=classes.indexOf(secondClass)
if(firstClassIndex==-1&&secondClassIndex==-1){
classes[classes.length]=firstClass}
else if(firstClassIndex !=-1){
classes[firstClassIndex]=secondClass}
else{
classes[secondClassIndex]=firstClass}
element.className=classes.join(" ")}
function IndexOf(item){
for(var i=0;i<this.length;i++){
if(this[i]==item){
return i}}
return-1}
function ToggleNodeStateHandler(event){
ToggleClass(this,"Collapsed","Expanded",(event==null)? window.event : event)}
function PreventBubbleHandler(event){
if(!event)event=window.event
event.cancelBubble=true}
function GetNullElement(xmlrow,tagname){
var xmlcell=xmlrow.getElementsByTagName(tagname)[0]
return(xmlcell&&xmlcell.firstChild)? xmlcell.firstChild.data : ""}

tomws
06-24-2008, 04:06 AM
I'm not sure how you can tell it's searching outside of the keywords node. Looking at the xml on the live site, it looks like the only data in the keywords node is used in the rest of the parent node somewhere.

That being said, if I'm reading the javascript correctly, it's searching the keywords node and the name attribute of the bldg node - both of which seem to be the same data, at least on a cursory glance of the xml. I'm unsure why it's set up like that. Looks like it's about line 123 of scripts/FAUMap002.js. If you're just wanting to reduce the number of nodes hit during a search, here's the before and after that might do it:

//before
if(Data[x].Keywords.toLowerCase().indexOf(searchtext.toLowerCase())!=-1 || Data[x].Name.toLowerCase().indexOf(searchtext.toLowerCase())!=-1){

//after
if(Data[x].Keywords.toLowerCase().indexOf(searchtext.toLowerCase())!=-1){

If you're after some other result, there may need to be more/different changes, but they could be difficult. I find it hard to believe that someone wrote their code in such an unreadable manner as if whitespace were cumbersome, which leads me to think your coder purposefully modified his code to make it troublesome to navigate in order to force the client (you) into using his services for later debugging and/or improvement rather than DIY. I rather hope I'm wrong, though, and the code is just accidentally sloppy. But that's just a rant at the coder and has nothing to do with you.

tarnis
06-25-2008, 01:48 PM
Thanks that did the trick...for a client whom can't be satisfied *sigh*. I appreciate your help...just wondering if it were on that line, is there something I can do easily-ish enough to make it only recognize whole words?

In a nutshell you're pretty much right...kept jacking up the rates when work was never really done and other issues galore to the point I couldn't get paid to pay him and won't answer me since he didn't get anything past the hefty deposit. Developer one bailed when I got started and gave me a price I used for my budget that was way too low...developer two bombed and then found this guy on the MS Live forum who pretty much was eating up most of what I might have made but needed to get it done. To be honest I'd of just dropped out of this project but they won't stop nagging me. Just trying to pay what I owe and have it done with at this point as I'm not getting a dime. *sigh* First realy freelance sorta thing, and learned a lesson or two the hardway.

Thanks again for your help...really appreciate it and sorry about the rant :)

tomws
06-25-2008, 02:13 PM
just wondering if it were on that line, is there something I can do easily-ish enough to make it only recognize whole words?

Can you clarify what you're asking here? I'm not sure which direction you're wanting to go.


First realy freelance sorta thing, and learned a lesson or two the hardway.

That's why I'm still gun-shy of doing any freelance. I have the skillset to do some of the simpler jobs, but am wary of getting involved with the wrong people. My time (and sanity) are still more valuable than the imagined trouble, at this point. :(

tarnis
06-25-2008, 07:19 PM
Looking for it not to show College if just "CO' is typed...CO is a building code and is another keyword. basically have things come up only when the whole word's typed in.

tomws
06-26-2008, 03:31 PM
I think this will work. I've tested something similar on an easier example. If it doesn't work, you might try starting a new thread and asking for help with searching whole words.

if(Data[x].Keywords.toLowerCase().search( eval("/\\b"+searchtext+"\\b/i") )!=-1){

The difference is that indexOf() becomes search(), use the eval statement, use a concat, and remove toLowerCase().

In the concat, the outer forward slashes denote a regex. Each backslash-b (\b) signifies a word boundary. The extra backslash un-escapes the word boundary backslash. The trailing 'i' means case-insensitive, which replaces toLowerCase(). Someone else can tell you which of those is the faster option. Either should work, but I made the assumption that a regex is faster than the function call overhead.

The eval turns the concat string into a regex that will search for words with a word boundary on each side. This site (http://javascript.about.com/library/blre13.htm) defines a boundary like this: "A word boundary can be either whitespace or the start or end of the string...". That sounds like what you want.

Dropping indexOf() in favor of search() allows the use of a regex, which seems to me to be the only way to determine whole words. Someone more experienced may have better info.

EDIT: I'm not experienced with using eval, but I would think it could be prone to injection in this context since it's executing user input. However, it input is flanked by the forward slashes which is supposed to denote a regex, so I don't imagine that javascript would actually execute a command entered as the search text. Then again, could a sophisticated regex be built to access something you don't want revealed? I still don't think so. But you might take a bit to explore the security issues surrounding using eval(). As I said, I'm not experienced enough with it to give you a solid answer.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum