Sencha Touch: Crafting Your First 'Hello World'
Learn how to create a basic 'Hello World' application using Sencha Touch, a powerful JavaScript library for mobile app development.
This post is a fun and simplified adaptation of the content found on http://www.sencha.com/learn/hello-world. It omits basic concepts for brevity and aims to make understanding more accessible. If you're not yet familiar with HTML, CSS, or JS, some sections might require additional clarification, so feel free to leave your questions in the comments below.
Welcome to the World of Sencha Touch!
Today, we'll learn how to craft a simple application that displays 'Hello World' on your screen.
Downloading Sencha Touch
Haven't got the Sencha Touch SDK yet? Make sure to download it. The package comes with documentation, sample applications, resource files, and the crucial JavaScript library and CSS files needed to run Sencha Touch.
Although the SDK might seem large at first glance, it's primarily due to the example files. Unlike jQuery UI or ExtJS, which require numerous CSS, JS, and image files, Sencha Touch operates with just one CSS (sencha-touch.css) and one JavaScript file (sencha-touch.js), totalling two files.
Application Structure
Let's try creating a HelloWorld project. First, create a folder named hello-world, then within it, an empty file named index.html and another folder named lib. Inside lib, insert the Sencha Touch library files as shown below. Actually, you only need these three selected files:
The HTML File
Sencha Touch is based on HTML5. You can start with the following basic document structure in any editor of your choice like Notepad or Notepad+. Populate your index.html file according.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello World</title>
<script src="lib/touch/sencha-touch.js" type="text/javascript"></script>
<link href="lib/touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
</html>
If you're unfamiliar with the elements such as head, title, script, link, and body tags, this might be challenging. It's advisable to familiarize yourself with HTML before diving into Sencha Touch.
Application Code
Usually, JavaScript code for applications or web pages is linked separately through script tags like with the sencha-touch.js file. However, for simplicity, let's include the script directly in the document for now. Be mindful that embedding JavaScript files directly can significantly impact loading times and bandwidth.
Replace the above code with the following to implement our 'Hello World' feature. Take a moment to compare the changes:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hello World</title>
<script src="lib/touch/sencha-touch.js" type="text/javascript"></script>
<link href="lib/touch/resources/css/sencha-touch.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
new Ext.Application({
launch: function() {
new Ext.Panel({
fullscreen: true,
html: 'Hello World!'
});
}
});
</script>
</head>
<body></body>
</html>
The notable addition is the JavaScript code embedded using new Ext.Application, marking the beginning of utilizing Sencha Touch. It acts as an initializer. Questions about why it starts with Ext.Application instead of something like new ST.Application are valid, given that Ext. originates from Ext.js, another JavaScript library by the same company that created Sencha Touch.
Viewing the Results
Open your newly created page in a web browser. Remember, it must be a Webkit-based browser like Google Chrome or Safari for proper rendering. The page should display as follows:
The same application can be viewed on smartphones, including iPhones and Android phones, by accessing the web server where the files are hosted:
It's also compatible with iPads, appearing quite similar to the desktop version due to the larger screen size:
This concludes our brief yet intriguing journey through creating a basic 'Hello World' project with Sencha Touch. This is just the beginning; there's much more to explore and create.
Web Content Disappears Post-loading on Android Browsers
Investigating a peculiar issue where text and content disappear on websites viewed with Android 4.0.3 and 4.0.4 browsers, potentially linked to CSS Animation support.
Detect Mobile Browsers: The Script for Mobile Browser Detection
Learn about Detect Mobile Browsers script for creating seamless mobile experiences by automatically redirecting mobile users to dedicated mobile sites.
Exploring HTML5 Notifications
Explore the introduction and implementation of notifications in HTML5, including how they enhance desktop interaction and browser specific support.