patch: document addDomreadyScriptDeclaration method

2 views
Skip to first unread message

pollen8

unread,
Jun 5, 2009, 4:11:14 AM6/5/09
to Joomla! CMS Development
Hello all

I'm not sure if this is the correct etiquette but I'm submitted a
patch to the JoomlaCode project:
http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEdit&tracker_item_id=16624

Which I'd be really happy if anyone wants to take a look at and
discuss


Its an extension to the document class, allowing the addition of js
code that is dependant upon being surrounded by a widow.addEvent
('domready', function(){.....}); declaration.

So you can do this:

$document =& JFactory::getDocument();
$document->addDomreadyScriptDeclaration("new JTable(document.getElement
('.adminlist'), {})");
$document->addDomreadyScriptDeclaration("alert('bar')");

and this will be rendered as:

window.addEvent('domready', function(){
new JTable(document.getElement('.adminlist'), {});
alert('bar');
})

Ercan Özkaya

unread,
Jun 5, 2009, 5:05:29 AM6/5/09
to Joomla! CMS Development
Well it would be a time-saver for me too as I use Mootools much. But I
think coupling JDocumentHTML to specific Mootools code is not a good
idea.

On 5 June, 11:11, pollen8 <r...@pollen-8.co.uk> wrote:
> Hello all
>
> I'm not sure if this is the correct etiquette but I'm submitted a
> patch to the JoomlaCode project:http://joomlacode.org/gf/project/joomla/tracker/?action=TrackerItemEd...

dukeofgaming

unread,
Jun 5, 2009, 7:56:56 AM6/5/09
to joomla-...@googlegroups.com
How about something that supports both domready & load?, the second one is not so used but... you never know. I see the need of this btw, I know I would use it, and a LOT.

Rob Schley

unread,
Jun 5, 2009, 12:14:01 PM6/5/09
to joomla-...@googlegroups.com
I'm with Ercan, while it might be a slight timesaver, JDocumentHTML is not the place for that because it would couple JDocument with MooTools. If you can figure out a way to make it work in JHtmlBehavior which is already coupled with Mootools but, as we discussed previously, can be swapped out, we could probably use it.

Best,
Rob

pollen8

unread,
Jun 6, 2009, 10:59:40 AM6/6/09
to Joomla! CMS Development
Not sure it works in JHTMLBehaviour either - its purpose isn't to add
html behaviour to the page per see but to enable easier loading of
scripts into the head.

I understand the point about it tying JDocument to mootools though.

Almost all js libraries have a similar event to the mootools js
domready event, so could I not pass that method in as a variable, so
if you really really wanted to use jquery you could pass in

"$(document).ready(function () {
%s
}"

as your method and that would be inserted in the head as:

"$(document).ready(function () {
alert('bar');
}"


On 5 June, 18:14, Rob Schley <rob.sch...@community.joomla.org> wrote:
> I'm with Ercan, while it might be a slight timesaver, JDocumentHTML is not
> the place for that because it would couple JDocument with MooTools. If you
> can figure out a way to make it work in JHtmlBehavior which is already
> coupled with Mootools but, as we discussed previously, can be swapped out,
> we could probably use it.
> Best,
> Rob
>
> On Fri, Jun 5, 2009 at 6:56 AM, dukeofgaming <dukeofgam...@gmail.com> wrote:
> > How about something that supports both domready & load?, the second one is
> > not so used but... you never know. I see the need of this btw, I know I
> > would use it, and a LOT.
>

pollen8

unread,
Jun 6, 2009, 11:00:36 AM6/6/09
to Joomla! CMS Development
ah its not also just a timesaver for the devloper - its acutaully cuts
down the size of the page, as you arent continually adding in
window.addEvent('domready') to each little js snippet you want to
include n the head


On 5 June, 18:14, Rob Schley <rob.sch...@community.joomla.org> wrote:
> I'm with Ercan, while it might be a slight timesaver, JDocumentHTML is not
> the place for that because it would couple JDocument with MooTools. If you
> can figure out a way to make it work in JHtmlBehavior which is already
> coupled with Mootools but, as we discussed previously, can be swapped out,
> we could probably use it.
> Best,
> Rob
>
> On Fri, Jun 5, 2009 at 6:56 AM, dukeofgaming <dukeofgam...@gmail.com> wrote:
> > How about something that supports both domready & load?, the second one is
> > not so used but... you never know. I see the need of this btw, I know I
> > would use it, and a LOT.
>
Reply all
Reply to author
Forward
0 new messages