Creating a Mobile HTML5 Application with App Framework

What is App Framework?

App Framework is a JavaScript library for mobile HTML5 app development. It allows you to build simple, rich and full HTML5/JavaScript mobile applications. This short tutorial is an introduction to the App Framework, and it presents the basic concepts and its main concepts.

App Framework library is inspired by jQuery. App Framework can design powerful interfaces for mobile devices such as Android or iOS. App Framework is composed of three elements: a library of queries and event management, a library of graphical interface and a plugin for WebKit library.

The library is functionally richer than jQuery Mobile. Another strong point of App Framework is that it requires only 3KB of memory against 35KB for jQuery. Scripts are also three times faster than jQuery on Android, and 2.2 times more faster on iOS.

Competing Frameworks

There are several competing frameworks to App Framework. These frameworks have more or less the same functionality as App Framework. We can mention among the best known: jQuery Mobile, Sencha Touch, jQTouch. The biggest advantage of App Framework is its weight and its execution speed. App Framework is the most powerful solution for mobile HTML 5 frameworks.

Prerequisites

Creation of a proxy

For the specific needs of the tutorial, we will need to make cross-domain requests through Ajax. To set up an Apache and PHP server is necessary in order to process these requests. Since JavaScript does not directly manage the cross-domain requests, we will set up a small proxy through php. Copy and paste the following code into a server.php file located in the same place as our HTML page. The “php_curl” module must be enabled in php.ini.

App Framework

App Framework is a mobile adaptation of jQuery, so, both Frameworks use the same syntax. For this tutorial it is better to have some knowledge of jQuery. The App Framework can be downloaded at this address. Copy and paste into the directory of your site the following folders and files:

kitchensink

plugins

ui

Note: To test, you need a browser compatible with webkit and HTML5.

Tutorial

We will show you through this example how you can use App Framework to build your mobile application. Briefly, our example will be based on the conception of a small reader of RSS feeds. This is just to give you a basic knowledge of App Framework. Firstly we will build our GUI with jqUI and implement some features with App Framework.

Create a page

As a first step, we will create our page and configure our App Framework. Here is the skeleton of an App Framework Application:

Create a page “index.html” in the root of your server and add the code above. This code is the base of our page, it imports the scripts that are necessary to use App Framework.Our application will be decomposed into two components: a page and its content and a menu. With App Framework, in order to create a page, we will create several divs inside the “content” div of our HTML file.

We’ll start by creating our main page “RSS” It will contain an input that allow the user to enter an RSS link and a panel containing the list of titles in the RSS flow. In the “afui” div we will add the “content” div. It is within this specific div that we will create the different pages of our application. Our first page will be titled “RSS”.

The input and label tags are classic HTML tags, to which we added classes provided directly by afui. The “Rssparse ()” function will be implemented later.

Now that we have the first part of our page, we will have to create the part that displays the results of the RSS feed. We want to display, in the form of list, the various titles in the RSS feed. This section will mainly be created dynamically, but we have to prepare the ground. In the same way as for the form, we will add to the existing fieldset a second fieldset.

<fieldset>
<legend> Rss Feed
<ul id="flux">
</ul>
</ fieldset>

We have added the HTML tag “ul” because our content is a list of titles. App Framework will insert the “li” tags.

Creating a Menu

We are going to create a menu to our application. App Framework can easily create two types of menu. The first one is a navigation bar at the bottom of the application. The second is a menu on the left side of our application. The second menu is constantly displayed on the big screens but is retractable on smaller screens (smart phone). We will create this second type of menu.

Firstly we will start by creating a second page to our application. Just create a second div with a class “panel”.

<div title="Project" class="panel" id="test">

We will now add our menu through a tag “nav”. This tag is to be placed outside of #content. The menu is created automatically by afui. The class “title” allow us to define a section title. In afui the links between the internal pages of the application are specified by their id. So the call of our page test will be made by href =”# test”.

When the user will click on the submit button, the Rssparse() function will be called automatically. So we need to implement it. We will now turn to JavaScript. We will implement the parserRss() function at the end of our index.html file, after the closing tag “/html”. Initially this function will display the URL validated by the user.

<script>
function Rssparse ()
{
alert ($ ("# link1").val ())
}

The syntax is the same as jQuery. These selectors will allow us to get different objects of the DOM, from their id, their classes or their tag type.

Remember that during the creation of our form, we assigned to the input of type text, an id = link. By calling the selector $ (“# link1″ ), it is our input text containing the url entered by the user that is returned. Once this element was selected, we call val() function, that returns us the value of the selected item. $ (” # link1″ ).val ( ) returns the URL entered by the user!

Ajax request

In the same way as jQuery, App Framework can make Ajax requests. Due to cross-domain restrictions of the browsers, App Framework, just like jQuery, does not allow to make cross-domain Ajax requests.In our case, to get a RSS feed from a URL, we want to make a request on a server that is not ours. To make this request, we will use our proxy (cf. prerequisites ).

Here we make an intermediate request on our proxy specifying him the true URL of the request. Our proxy will then, take care, in PHP, to make the request and send us the result.

Xml parser and dynamic modification of the DOM

Having collected our xml data, we must now deal with them. App Framework provide us with a method named parseXML which allow, from a xml text, to build a DOM Document object. We can call directly on the object resulting from parseXML function, methods such as getElementsByTagName.

Conclusion

App Framework offers most of the features of jQuery adapted to mobile devices.Its rich libraries and its unmatched performance, make it a comprehensive mobile HTML5 framework. This framework will allow you to build mobile applications in a very short time.

Free Guide:

7 Habits of Successful CTOs

"What makes a great CTO?" Engineering skills? Business savvy? An innate tendency to channel a mythical creature (ahem, unicorn)? All of the above? Discover the top traits of the most successful CTOs in this free guide.

Anonymous

“The library is functionally richer than jQuery Mobile. Another strong point of App Framework is that it requires only 3KB of memory against 35KB for jQuery. Scripts are also three times faster than jQuery on Android, and 2.2 times more faster on iOS”

If an article is going to make sweeping statments such as “the library is functionally richer than…” it should quantify why it believes it to be so. In addition if you’re going to make claims such as “three times faster than jQuery on Android” and “2.2 time faster on iOS” link to some proof or documentation that backs up those claims. (Even if they are somewhere on the intel site, don’t make readers hunt for facts to validate claims being made.)

adrien

Hello
thank you very much for all the comments . I would like to said that by reading the documentation carefully , you wil find a lot of information about this framework .

Jo Werner

Lots of erors (spaces, missing trailing semi-colons) in the first index.html.
Please check the code!

Anonymous

Thanks for the tutorial, but can u please fix the code indentation and bizarre spacing please?

adrien

yes thank you for pointing this error : on line 4 we must have #link1 and we must have url1.
there are some space which come from the fact that I submit the article through word format and therefore I take it for granted that all was correct .In taking on the code on word format, There are errors that occur automatically, especially spaces that are created . So, thanks for pointing some of them. It will help me to improve

Anonymous

also, found 2 errors. Line 4 of the last snippet should be #links and on the php, line 4 as well, should be $url1.
And on line 4 (LOL) of the AJAX thing, the url has the “?” missplaced.

I know this comment is going to be reviewed and I dont intend it to be published, is just to let the author know.

Anonymous

Sure Adrien, no problem. Glad to help :) One more comment on this tutorial if you allow me: it would’ve been nice to have the files available to download. Have a nice weekend :)

phonegap application development

Thanks very much for the valuable info about app framework. There is much I still need to learn and having everything set out clearly and in the one place should really help.

payong

I will create a distinctive tutorial base upon this framework later

Anonymous

Why are you loading the external scripts in the HEAD of the HTML code?