Gadget ids in Div attributs

Got an idea for enhancing SpiderBasic? New command(s) you'd like to see?
cederavic
Posts: 30
Joined: Tue Feb 25, 2014 6:49 am

Gadget ids in Div attributs

Post by cederavic »

It would be very usefull if the ids of gadget can be put int the generated divs attribut. We could easily change css properties and do more stuff with direct js.
Actualy i made myself a small plugin wich edit the generated spider.js to do it (in PB, for sure!). It looks like :

Code: Select all

OpenFile(0, dirname + "SpiderBasic.js")
Repeat
	line.s = ReadString(0)
	;avoid asm generated lines on "js" procedures
	If FindString(line, "equ esp") : Continue : EndIf
	
	;retrieve "CreateGadget" content in current line
	CreateRegularExpression(0, "spider_[A-Z][a-zA-Z]*Gadget.*document\.createElement\(" + Chr(34) + "div" + Chr(34) + "\);")
	Dim result.s(0)
    If ExtractRegularExpression(0, line, result()) >= 1
		gadget.s = result(0)
		
		;retrieve gadget object
		CreateRegularExpression(1, "[a-z]{1}[=]{1}spider\.gadget\.objects\.Allocate\([a-z]{1}\)")
		Dim result2.s(0)
		If ExtractRegularExpression(1, gadget, result2()) >= 1
			gadgetObj.s = Mid(result2(j), 1, 1)
		EndIf
		FreeRegularExpression(1)
		
		;retrieve div object
		CreateRegularExpression(1, "[a-z]{1}[=]{1}document\.createElement\(" + Chr(34) + "div" + Chr(34) + "\)")
		Dim result2.s(0)
		If ExtractRegularExpression(1, gadget, result2()) >= 1
			divObj.s = Mid(result2(j), 1, 1)
		EndIf
		FreeRegularExpression(1)
		
		;add the gadget id to the div in the "CreateGadget" 
		line = ReplaceString(line, gadget, gadget + divObj + ".id=" + Chr(34) + "gadget_" + Chr(34) + " + " + gadgetObj + ".id;")
    Next
	FreeRegularExpression(0)
	
	content + line + Chr(10)
Until Eof(0)
CloseFile(0)

With that i can do easy proc likes :

Code: Select all

Procedure GadgetFadeIn(gID.i, time.i)
	!$("#gadget_" + v_gID).fadeIn(v_time);	
EndProcedure

Procedure GadgetFadeOut(gID.i, time.i)
	!$("#gadget_" + v_gID).fadeOut(v_time);	
EndProcedure
And so more!
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Gadget ids in Div attributs

Post by Fred »

You can use "spider_GadgetID(yourGadget).div" to get the div easily. Every Gadget got this field. Is it enough for your needs ?
User avatar
Arbrakaan
Posts: 91
Joined: Mon Feb 24, 2014 10:54 pm
Location: Geneva
Contact:

Re: Gadget ids in Div attributs

Post by Arbrakaan »

Awesome !
cederavic
Posts: 30
Joined: Tue Feb 25, 2014 6:49 am

Re: Gadget ids in Div attributs

Post by cederavic »

Exactly what I needed, Thanks! :)
karu
Posts: 40
Joined: Mon Feb 24, 2014 10:16 pm

Re: Gadget ids in Div attributs

Post by karu »

Fred wrote: Every Gadget got this field.
Also webgadget?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Gadget ids in Div attributs

Post by Fred »

Yes
Post Reply