. .

smalltalk

Javascripted Anchors in Seaside

June 14, 2010 9:08:54.543

When I updated the Seaside tutorial, I ran into an interesting change from Seaside 2.8 - the way anchors work when you have an onClick Javacript action. If you don't include an #url: call with some string, you don't get an anchor. In Seaside 2.8, that wasn't the case - look at the code in WAAnchorTag in 2.8:


with: aBlock
	url isNil
		ifTrue: [
			((self attributes includesKey: 'href') or: [ self attributes includesKey: 'name' ])
				ifFalse: [ self attributes at: 'href' put: 'javascript:void(0)' ] ]
		ifFalse: [ self attributes at: 'href' put: url ].
	super with: aBlock


And now look at the 3.0 version:


with: aBlock
	url isNil
		ifFalse: [ self attributes at: 'href' put: url ].
	super with: aBlock

There was an explanation (I missed it; I don't track the Seaside mailing list that closely):

We removed that because it was causing unwanted side-effects in some cases. I suggest that you create your own #onClick: method that sets the 'href'.

However, for many applications (most, I daresay), it's simpler to just restore the 2.8 behavior. If you don't, you need to do something like this (note the usage of #url: below):


renderContentOn: html

	html paragraph: 
			[(html anchor)
				onClick: ((html jQuery: #count) load
							html: [:h | h render: (count := count - 1)]);
				url: '#'; 
				with: '--'.
			(html span)
				id: #count;
				with: count.
			(html anchor)
				onClick: ((html jQuery: #count) load
							html: [:h | h render: (count := count + 1)]);
				url: '#'; 
				with: '++']

Before you can get the anchor to render. You need to do the same using older Scriptaculous/Prototype code - because the change is in the way anchors render. When I do screencasts on JQuery in seaside, I won't be including this change; I don't want to force people down that path. However, I think it's useful to know. Hat tip to Boris Popov for pointing me in the right direction on this stuff.

Technorati Tags: , ,

posted by James Robertson

 Share Tweet This