|
|
Home » Community » Newbie corner » Can I use Javascript frameworks with Skylark?
Can I use Javascript frameworks with Skylark? [message #38199] |
Wed, 05 December 2012 16:13 |
lectus
Messages: 329 Registered: September 2006 Location: Brazil
|
Senior Member |
|
|
This is probably a beginners question.
But if I can use for example Jquery, which is a JavaScript framework, with U++/Skylark it's a huge motivation for me to learn Jquery. And then I can create really cool UIs for my Skylark apps.
Is it possible? (it probably is possible because javascript runs on the browser... but still I'd like to confirm)
Thanks
[Updated on: Wed, 05 December 2012 16:14] Report message to a moderator
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38200 is a reply to message #38199] |
Wed, 05 December 2012 17:19 |
|
lectus wrote on Wed, 05 December 2012 16:13 | This is probably a beginners question.
But if I can use for example Jquery, which is a JavaScript framework, with U++/Skylark it's a huge motivation for me to learn Jquery. And then I can create really cool UIs for my Skylark apps.
Is it possible? (it probably is possible because javascript runs on the browser... but still I'd like to confirm)
Thanks
|
Hi lectus,
I don't see any reason why there should be a problem JS frameworks are client-side code, it should pretty much ignore anything that happens on the backend.
Honza
|
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38438 is a reply to message #38434] |
Sat, 15 December 2012 17:41 |
|
Yes, '$' designates beginning of skylark code in the templates. You can escape it by writing two dollar signs instead:
$$(function() {
$$( "input[type=submit], a, button" )
.button()
.click(function( event ) {
event.preventDefault();
});
Or better, put the javascript code in separate file and include it:<script>
#include someframeworkcode.js
</script>
Honza
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38439 is a reply to message #38438] |
Sat, 15 December 2012 17:46 |
|
dolik.rce wrote on Sat, 15 December 2012 17:41 | Or better, put the javascript code in separate file and include it:<script>
#include someframeworkcode.js
</script>
|
Actually, I'm not sure if that helps, but it might I'm not sure if it will be processed as a template or not when including and I don't have time to look at it right now... You'll have to test it
Honza
|
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38447 is a reply to message #38446] |
Mon, 17 December 2012 18:02 |
|
Skylark is always looking for the witz files on SkylarkApp::Config().path which is initialized to the value of Ini::path (which can be set in configuration file for your application). If not set, the default is to use UPP_ASSEMBLY__ environment variable if set or the executable directory. The path variable can contain multiple directories, separated by ';' (on POSIX you can also use ':' as divider).
If you test your application by running it from TheIDE, it sets UPP_ASSEMBLY__ to the directories where your packages reside, so you can refer to file "foo.js" in application "MyApp" simply as "MyApp/foo.js". If you run your application in some other way, or if you are deploying the application, you have to set the path in configuration file, or set the environment variable.
You can read more about the configuration options here. Also, all of the information above are present in the Skylark tutorial, you should definitely (re)read it
Honza
|
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38453 is a reply to message #38450] |
Tue, 18 December 2012 07:25 |
|
lectus wrote on Tue, 18 December 2012 01:31 | This is really weird.
I got the paths right for Jquery and Jquery-UI.
In the log Skylark says
GET /jquery-ui.js
=== Response: 200
which means it found the file.
But it doesn't work.
|
Well, then it probably means your problem is somewhere else. If you post a complete package, so I can try to run it, I can try to help. Simply saying "But it doesn't work. " Doesn't give me any information to begin with
Honza
|
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38457 is a reply to message #38455] |
Tue, 18 December 2012 15:43 |
|
Hi lectus,
I found at least 2 problems.
1) You call LoadFile('js/...') etc., but that fails to load anything, since it searches relative to the executable, which is most probably somewhere else then js folder. You should use the static/** handler from Skylark/static.icpp for this, it is much better (can even manage caching for you). To use it, you have to just use correct paths in you templates, e.g.:
<script src="/TestingJqueryUI/static/TestingJqueryUI/js/jquery-1.8.3.js"></script>
<script src="$CachedStatic("TestingJqueryUI/js/jquery-ui-1.9.2.custom.js")"></script> The second takes advantage of the caching, if it is configured.
2) There is a bug in the witz parsing, that causes "$$" to be interpreted as "" instead of "$", I'll send a fix to Mirek ASAP.
3) This is not really a problem, but you should now that your template uses link tags outside of head, which IIRC is not valid... But it works in most browsers
So the corrected template should look like this:
#include Skylark/Base
<link href="$CachedStatic("TestingJqueryUI/css/ui-lightness/jquery-ui-1.9.2.custom.css")" rel="stylesheet">
<script src="$CachedStatic("TestingJqueryUI/js/jquery-1.8.3.js")"></script>
<script src="$CachedStatic("TestingJqueryUI/js/jquery-ui-1.9.2.custom.js")"></script>
<script>
$$(function() {
$$( "#dialog" ).dialog();
});
</script>
<!-- I'm trying to run the example from: http://jqueryui.com/dialog/ -->
#define TITLE TestingJqueryUI application
#define BODY
<div id="dialog" title="Basic dialog">
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>
To fix the parsing error before it gets into svn, just change Skylark/Compile.cpp around line 362 from this:
if(s[1] == '$')
s += 2;
else {
to this:
if(s[1] == '$') {
blk.AddText(b, s+1);
p.Set(s+2, NULL, line);
b = s = p.GetSpacePtr();
} else {
Hope this will finally solve it for you
Honza
|
|
|
|
Re: Can I use Javascript frameworks with Skylark? [message #38459 is a reply to message #38458] |
Tue, 18 December 2012 17:10 |
|
The plugin/jquery is possible, but given how often it's code changes and how little advantages it would bring (I can imagine better base.witz + saving couple mouseclicks to download the files), it's probably not worth it. But that is just my opinion... I'm a person who is not very happy about all the JS bloat in his browser, so my opinion is probably not very objective
Also, if you like the CachedStatic, try to set SkylarkApp::Config().caching = 2; it'll save your users even more bandwidth than the default setting
Honza
|
|
|
|
Goto Forum:
Current Time: Fri Mar 29 06:10:17 CET 2024
Total time taken to generate the page: 0.01589 seconds
|
|
|