Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
lectus is currently offline  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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile 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 #38434 is a reply to message #38200] Sat, 15 December 2012 17:17 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hi!

I think I detected some incompatibility between Skylark Witz and Jquery-Ui library.

Here's my index.witz:
<!doctype html>
 
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>jQuery UI Button - Default functionality</title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.3.js"></script>
    <script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />
    <script>
        $(function() {
        $( "input[type=submit], a, button" )
            .button()
            .click(function( event ) {
                event.preventDefault();
            });
    });
    </script>
</head>
<body>
 
<button>A button element</button>
 
<input type="submit" value="A submit button" />
 
<a href="#">An anchor</a>
 
 
</body>
</html>


When I run my app and access this page I get:
Quote:

Internal server error
(12,11): function nor link not found 'function'


I think it's because of the $ character. Is there any way to escape it for JS code? Skylark is probably seeking for something like $for.
Re: Can I use Javascript frameworks with Skylark? [message #38438 is a reply to message #38434] Sat, 15 December 2012 17:41 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile 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 Wink

Honza

Re: Can I use Javascript frameworks with Skylark? [message #38446 is a reply to message #38199] Mon, 17 December 2012 16:56 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
I got to work some basic CSS to create an interactive menu with Skylark. But still no jquery.

I'm afraid I'll need some guidance with sample code.

I'm mainly struggling with the paths, like where should I put each file to be recognized by Skylark.

[Updated on: Mon, 17 December 2012 16:57]

Report message to a moderator

Re: Can I use Javascript frameworks with Skylark? [message #38447 is a reply to message #38446] Mon, 17 December 2012 18:02 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Wink

Honza
Re: Can I use Javascript frameworks with Skylark? [message #38450 is a reply to message #38199] Tue, 18 December 2012 01:31 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
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. Confused
Re: Can I use Javascript frameworks with Skylark? [message #38453 is a reply to message #38450] Tue, 18 December 2012 07:25 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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. Confused

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. Confused " Doesn't give me any information to begin with Wink

Honza
Re: Can I use Javascript frameworks with Skylark? [message #38455 is a reply to message #38199] Tue, 18 December 2012 14:02 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hi Honza!

Here's a test case package that in my opinion should work:
http://www34.zippyshare.com/v/42084894/file.html

I tested it in pure html and loaded in Google Chrome and it works just fine without Skylark.

I uploaded it to zippyshare so it doesn't bloat the forum.

Inside the 7zip file there's a U++ Skylark package bundled with JQuery and Jquery-UI.

The code in the template is taken from Jquery-UI demos page.

Thanks

[Updated on: Tue, 18 December 2012 14:07]

Report message to a moderator

Re: Can I use Javascript frameworks with Skylark? [message #38457 is a reply to message #38455] Tue, 18 December 2012 15:43 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile

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 Smile

Honza
Re: Can I use Javascript frameworks with Skylark? [message #38458 is a reply to message #38199] Tue, 18 December 2012 16:46 Go to previous messageGo to next message
lectus is currently offline  lectus
Messages: 329
Registered: September 2006
Location: Brazil
Senior Member
Hi!
Thanks for your quick and precise answer!
Yes, it now works!

I applied your fix to Skylark/compile.icpp and it works. (glad one bug will now be fixed, it means my testing was useful)

Also, by using $CachedStatic() it found the files and I don't need to add handlers manually! Much better!

Very Happy Very Happy Very Happy
Now my web apps can start getting fancy with cool GUI.

BTW, I don't know if it's a good idea, but we could have (or maybe not... it could make U++ more bloated, since those libraries are readly/freely available anyway):
plugin/jquery
plugin/jquery-ui
plugin/jquery-mobile

Those frameworks are good for developing web/mobile apps.
But that decision is up to the authors of U++.

[Updated on: Tue, 18 December 2012 16:47]

Report message to a moderator

Re: Can I use Javascript frameworks with Skylark? [message #38459 is a reply to message #38458] Tue, 18 December 2012 17:10 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile

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 Wink

Honza
Re: Can I use Javascript frameworks with Skylark? [message #38476 is a reply to message #38457] Wed, 19 December 2012 21:47 Go to previous message
mirek is currently offline  mirek
Messages: 12124
Registered: November 2005
Ultimate Member
dolik.rce wrote on Tue, 18 December 2012 09:43



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.



Patch applied. Needless to say, perhaps choosing '$' for template commands was not as good idea, jquery considered...

Mirek
Previous Topic: U++ on Android with Ubuntu
Next Topic: Is this a intended behavior for Upp widgets?
Goto Forum:
  


Current Time: Fri Dec 13 14:52:54 CET 2019

Total time taken to generate the page: 0.01586 seconds