Page 1 of 1

Gadget ids in Div attributs

Posted: Tue Feb 25, 2014 9:28 pm
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!

Re: Gadget ids in Div attributs

Posted: Tue Feb 25, 2014 11:10 pm
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 ?

Re: Gadget ids in Div attributs

Posted: Tue Feb 25, 2014 11:23 pm
by Arbrakaan
Awesome !

Re: Gadget ids in Div attributs

Posted: Wed Feb 26, 2014 6:08 am
by cederavic
Exactly what I needed, Thanks! :)

Re: Gadget ids in Div attributs

Posted: Thu Feb 27, 2014 1:37 pm
by karu
Fred wrote: Every Gadget got this field.
Also webgadget?

Re: Gadget ids in Div attributs

Posted: Thu Feb 27, 2014 2:13 pm
by Fred
Yes