Chathura Prabuddha wrote:
Hai...
I tried to use the xwiki.javascrpitextention object to separate my
javascript code.But it didn't work correctly.I included the whole javascript
code in (Document Type Manager Demo)
http://gsoc.myxwiki.org/xwiki/bin/view/DocTypeManagerDemo to here:
http://gsoc.myxwiki.org/xwiki/bin/edit/DocTypeManagerDemo/DocTypeManagerScr…
and then tried the
$xwiki.jsx.use("DocTypeManagerDemo.DocTypeManagerScript"). you can see it in
here (I commented it)
http://gsoc.myxwiki.org/xwiki/bin/edit/DocTypeManagerDemo/WebHome?&edit…
please give me some hints to fix this issue... :).
Hi Chathura,
One of the reasons why the code is not working is that the code is
executed before the HTML elements it concerns are loaded. That happens
because $xwiki.jsx.use("DocTypeManagerDemo.DocTypeManagerScript")
generates a <script type="text/javascript"
href="..."></script> element
and inserts it in the <head> of the HTML document.
So, what you need to do is make sure the code in the extension is
executed at the right time (when the whole dom tree is available) and
not at the moment when it is referred. For this, you can start by
wrapping it in a function that you will call when the xwiki:dom:loaded
event is fired:
document.observe('xwiki:dom:loaded', function() {
// your code here
});
Afterwards, when this works fine, you can reorganize the javascript code
to comply with our javascript code practices, including
http://dev.xwiki.org/xwiki/bin/view/Community/DevelopmentPractices#HJavaScr…
--
Sergiu Dumitriu
http://purl.org/net/sergiu/