ok, I found couple problems with my previous realization, and think the dance around 'domchanged' event was to tricky ...
in current realization:
- automatically subscribe all "domready" events to the "load" event
- use Joomla.fireEvent('load', element) for notify the script about the changes in DOM
- all "initial" events put in to the "jinit" namespace, that will fire on "initial" "domready" or "load" ..... this allow divide the "domready" event subscribed to "load" and "load" event
- use namespace tree, without any the depth limitation
- it is the framework independent, so can work if no framework connected and used only pure JavaScript
now for the init we just use:
Joomla.addEvent('domready', callback);
instead of mixes with:
jQuery(document).ready(callback);
and
window.addEvent('domready', callback);
after some DOM manipulation we need tell for a scripts that we changed something, like:
Joomla.fireEvent('unload', 'element-that-will-be-changed') // before changes
Joomla.fireEvent('load', 'changed-element') // after changes
that not possible if used mixed initialization (that is the main cause of current suggestion)...
this + the namespace tree allow more simple interact between different extensions, if needed
namespace example:
we have:
Joomla.addEvent('domready.extension1', callback1)
Joomla.addEvent('domready.extension1.gallery', callback2)
Joomla.addEvent('domready.extension1.slider', callback3)
Joomla.addEvent('domready.extension2', callback4)
here on "domready" will be called all these callbacks ...
if after some DOM manipulation we need re-init only the "extension1" and they children, then we can just fire:
Joomla.fireEvent('load.extension1', 'changed-element')
if need re-init only callback2 then just fire:
Joomla.fireEvent('load.extension1.gallery', 'changed-element')
There no limitation for the depth of the namespace.
Also there no limitation for used events, so can be used the "fake events" ... not sure that it will use some one, it's just a side result of the current implementation :)
in next hour I will try update post on joomlacode site and upload the plugin that I used for testing and some simple demonstration module
Пʼятниця, 8 лютого 2013 р. 19:04:50 UTC+2 користувач Fedir написав: