i have javascript file main.js. main.js contains this:
$(document).ready(function() { cufon.replace('#myform p.head', { fontfamily: 'helveticaneuelt std thin' }); ...... });
i suppose run method after whole page loaded , apply change css elements.
but found out works when script loaded before html elements, e.g.:
<body> html...... <script type="text/javascript" src="js/main.js"></script> </body>
however, if script put on top of html, stops working:
<body> <script type="text/javascript" src="js/main.js"></script> html...... </body>
this happens on both static html , gwt page. because gwt put generated html stuff @ end of body contents, script before html, hence not work. example, html gwt module this:
<body> <script type="text/javascript" src="js/main.js"></script> </body>
and after compiled, generated html uibinding gives html page like:
<body> <script type="text/javascript" src="js/main.js"></script> generated html.... </body>
my questions are:
- is there anyway in gwt can specify generated html goes between statements in tag.
- is there other ways instead of $(document).ready can guarantee called last thing happened in page load?
many thanks
while find strange script doesn't work intended when moved in static page ($(document).ready(…)
supposed wait </html>
reached –aka domcontentloaded
– before running function passed it), it's not reason doesn't work gwt application (in other words, diagnostic wrong).
gwt's onmoduleload
runs @ domcontentloaded
(or later, never earlier) have race condition between app's onmoduleload
, jquery's $(document).ready(…)
. try putting <script>
gwt app before main.js
, because onmoduleload
might run after domcontentloader
anyway, there's no guarantee it'll work (even less in crossbrowser way).
i think you'd better remove main.js
or replace $(document).ready(…)
simple function
, , call cufon
(and/or whatever else doing in $(document).ready(…)
) within gwt app, @ moment appropriate needs (i.e. after attached #myform p.head
element/widget document).
the easiest way put script in jsni method , call method appropriate. make sure use $wnd.cufon
instead of cufon
(and other globals), , replace occurrences of document
$doc
, window
$wnd
.
public static void cufon() /*-{ $wnd.cufon.replace('#myform p.head', { fontfamily: 'helveticaneuelt std thin' }); }-*/;
Comments
Post a Comment