[Solar-talk] agnostic js helper
Rodrigo Moraes
rodrigo.moraes at gmail.com
Tue Dec 5 04:54:20 PST 2006
Hi,
I have a suggestion that would help those working with different
javascript libraries than the default Protaculous combo. Most of the
View_Js helper methods are truly agnostic and perfect to deal with
javascript inclusion and management; the exception are the $selectors
and $objects properties and how they are fetched. Depending on the
library, there are more simplified/complex ways to deal with events or
selector rules, and currently the Js helper imposes a Prototype 1.5
way.
The problem is in fetchInline(), which includes calls for $$() and
JsPrototype()->event->observeObject(). Different libraries will use
different event handlers and methods to set selector rules. I found
that it would be a pity to change or duplicate the Js helper, because
it is the base helper for all javascripts in Solar.
A quick solution to make the Js helper more agnostic is to delegate
part of fetchInline() and specific stuff to the library helper
(JsPrototype by default), defined in the config. The simple part is:
$library = $this->_config['library'];
$scripts = $this->_view->getHelper($library)->fetchInline();
if(!empty($scripts)) {
$this->scripts = array_merge($this->scripts, $scripts);
}
...but maybe I'm going too far. Do you think the Js helper should be
more library-agnostic?
regards,
rodrigo
---------------------------------------------------------------------
Solar has now a Community Wiki: solarphp.org
---------------------------------------------------------------------
Join the #solarphp IRC channel on freenode.org
---------------------------------------------------------------------
More information about the solar-talk
mailing list