Dashcode User Guide
Dashcode User Guide
Contents
Contents
Create the First Binding 38 Create the Remaining Bindings 40 Test the Safari Web Application 41 Customize the User Interface of the Mobile Safari Web Application 41 Create Bindings for the Mobile Safari Web Application 43 Create a Binding to an Element on the Master List Page 43 Create Four Bindings to Elements on the Detail Page 43 Test the Mobile Safari Web Application 44 Next Steps 45
Starting a Project 46
Creating a Project from a Template 46 Creating a Project from an Existing Dashboard Widget 47 Providing Attributes for a Dashboard Widget 47 Providing Attributes for a Web Application 48 Application Attributes for Safari Web Applications 48 Application Attributes for Mobile Safari Web Applications 49 Opening an Existing Dashboard Widget 50
Contents
Adding a Data Source 64 Creating Bindings 65 Adding a Value Transformer 67 Adding a Handler for an Event 68 Supporting Offline Usage of a Web Application 68 Adding or Removing a Web Application Product 69 Adding Code for Custom Controllers 70 Code Completion Using Code Sense 70 Code Snippets 71 Adding and Moving Files and Folders 71 Resource Access for Widgets 72 Code Editing Preferences 73
Dashcode Templates 83
Widget Templates 83 The Custom Widget Template 83 The Countdown Template 83 The Maps Template 84 The RSS Widget Template 84 The Podcast Widget Template 85 The Photocast Template 85 The Quartz Composer Template 86 The Video Podcast Template 86 The Gauge Template 86 The Daily Feed Template 87 Web Application Templates 87
Contents
The Custom Web Application Template 87 The Browser Template 88 The Podcast Web Application Template 88 The RSS Web Application Template 88 The Utility Template 89
Dashcode Parts 90
Activity Indicator 90 Back Button 90 Box 91 Browser 91 Canvas 91 Call Button 92 Column Layout 92 Edge-to-Edge List 92 Forward Button 93 Gauge 93 Grid 94 Image 94 Indicator 94 Level Indicators 94 Mail Button 95 Map Button 95 Quartz Composer 95 QuickTime 96 Rounded-Rectangle List 96 Split Layout 97 Stack Layout 97 Stack Layout Methods 98 Stack Layout Transitions 98 Video 100
Figures
This document provides an overview of the Dashcode development environment. It describes how to use Dashcode to create two types of projects:
Dashboard widgetssimple, lightweight applications that perform a single task in the Mac OS X Dashboard environment. Widgets are actually packaged webpages powered by standard web technologies such as Hypertext Markup Language (HTML), Cascading Style Sheets (CSS), and JavaScript. Web applicationswebpages that provide discrete functionality to users. Web applications also make use of web technologies such as HTML, CSS, and JavaScript. Dashcode helps you create mobile Safari web applications, which are also known as iPhone web applications (that is, web applications optimized to run in Safari on iPhone), and Safari web applications (that is, web applications optimized to run in Safari).
Dashcodes integrated environment allows you to lay out, code, and even test widgets and web applications without opening any other applications. Its layout tools, composers, and editors simplify the process of creating all the resources these projects need. Dashcode also includes handy coding and debugging tools that help you manage and test the code you write.
Dashboard Widget Tutorial (page 10) walks you through creating your first Dashboard widget with Dashcode. Mobile Safari Web Application Tutorial (page 16) shows you how to create a simple mobile Safari web application with Dashcode.
Dual-Product Web Application Tutorial (page 25) shows you how to create a project that produces both a mobile Safari web application and a Safari web application. Starting a Project (page 46) discusses the different starting points when working with Dashcode. Designing the User Interface of a Widget or Web Application (page 52) shows you the tools Dashcode provides for designing the user interface of a widget or web application. Adding Source Code and Creating Bindings (page 61) details the source code editing tools included with Dashcode. Testing and Sharing (page 74) includes information on testing, debugging, and distributing a widget or web application. Advanced Topics for Widgets (page 81) talks about localizing a widget using Dashcode and including a widget plug-in.
Dashcode Templates (page 83) describes the project templates included with Dashcode. Dashcode Parts (page 90) includes information on Dashcode-originated elements, called parts, and how to customize them.
Reporting Bugs
If you encounter bugs in Apple software or documentation, you are encouraged to report them to Apple. You can also file enhancement requests to describe features you would like to see in future revisions of a product or document. To file bugs or enhancement requests, go to the Bug Reporting page of the ADC website, which is at the following URL: http://developer.apple.com/bugreporter/ You must have a valid ADC login name and password to file bugs. You can obtain a login name for free by following the instructions found on the Bug Reporting page. To file a bug for Dashcode, use the Dashcode component, version X.
See Also
For in-depth information on how to create web applications that work well on iPhone and iPod touch, see Safari Web Content Guide . For guidance on how to design the user interface of such an application, see iOS Human Interface Guidelines . Read Dashboard Programming Topics for information on the technologies available to you when creating a Dashboard widget. All of the Dashboard-specific information discussed in this document is covered in more depth in Dashboard Reference . The Safari Dev Center contains useful information on WebKit, the technology that powers Dashboard widgets, and other Safari-related topics. For more information on the HTML, CSS, and JavaScript capabilities found in WebKit, consult:
Safari HTML Reference Safari CSS Reference Safari DOM Additions Reference
The XMLHttpRequest object allows you to parse XML in JavaScript and use the results. Read the ADC article Dynamic HTML and XML: The XMLHttpRequest Object for more information.
This tutorial walks you through using Dashcode to create a Dashboard widget. As you follow the steps, you learn how to choose a widget template, customize your widgets appearance and code, and share your widget with others. Completing this tutorial is a quick and easy way to get started building Dashboard widgets in Dashcode. This document includes two additional tutorials, Mobile Safari Web Application Tutorial (page 16) and Dual-Product Web Application Tutorial (page 25), which follow this one. The remainder of the document delves more deeply into the Dashcode development environment, describing how it supports both widget and web application development. If you dont want to learn how to create a web application, you can continue learning more about Dashcode by reading Starting a Project (page 46).
Before continuing, make sure that you have Dashcode installed on your Mac. If you dont have Dashcode installed, read Getting and Running Dashcode (page 8) to learn how to get and install Dashcode.
Choose a Template
To start, double-click the Dashcode icon to open it. A new project window opens and displays a dialog in which you first select the type of project youre interested inin this case, Dashboardand then, the kind of widget you want to create from an assortment of templates. Templates are handy starting points for creating common types of widgets. Select a templates icon to show a short description of what that template does.
10
To make the Birthday widget, this tutorial uses the Countdown template. Select its icon and click Choose. A project window opens with a new widget based on the Countdown template, as shown in Figure 1-2.
Figure 1-2 A project window showing a new Dashboard widget
Along the left side of the project window is the navigator, which you use to switch between the various tools available when youre designing a widget. The main portion of the window is the canvas, which you use to design your widgets interface. At the bottom of the navigator in Figure 1-2 you can see the Workflow Steps list, which guides you through the widget development process. Each step is a milestone in creating a widget, telling you what to do and where to do it. When you complete a step, mark it as done and move on to the next step.
11
Note If you dont want to see the Workflow Steps list, you can hide it by choosing View > Steps or by clicking the button that looks like a checkbox at the bottom edge of the project window (this button is highlighted in Figure 1-2). Alternatively, you can view a list of the widgets files in place of the Workflow Steps list. If you want to see the Files list, choose View > Files or click the list button in the bottom edge of the project window (its the button that looks like a bulleted list).
12
When youre finished customizing your widgets body, add a photo of yourself from iPhoto to the widget. Your iPhoto library is available from the Library window. To show your iPhoto library, choose Window > Show Library; then click the Photos button. Find a photo and drag it to your widget on the canvas. Resize it by dragging any of the resize handles on the photo.
13
Finally, change the Event Label text to something like ...days until my birthday. You can do this by selecting the Event Label text, clicking the Attributes button in the inspector window (its the leftmost button), and entering the text in the Value field, or by double-clicking the text in the widget body itself and entering the new text.
14
The code in the source code editor should look like that in Figure 1-5.
Figure 1-5 A function in the source code editor
Test your widget again by choosing Debug > Run. Click the button you added and make sure a new Safari window opens with the Apple Store website displayed. Be sure you save your project often to preserve the changes you make.
15
This tutorial walks you through using Dashcode to create project that produces a mobile Safari web application. A mobile Safari web application (also known as an iPhone web application) is web content that is optimized for Safari on iPhone and that offers users an application-like experience. As you follow the steps, you learn how to choose a template, customize your code, and share your application with others. Completing this tutorial is a quick and easy way to get started building mobile Safari web applications in Dashcode. This is the second of three tutorials in this document. If youre interested in learning how to start developing Dashboard widgets, be sure to read Dashboard Widget Tutorial (page 10). If you want to learn how to create a project that produces both a mobile Safari web application and a Safari web application, read Dual-Product Web Application Tutorial (page 25). The remainder of the document, beginning with Starting a Project (page 46), delves more deeply into the Dashcode development environment, describing how it supports both widget and web application development.
Choose a Template
To start, double-click the Dashcode icon to open it. A new project window opens and displays a dialog that displays two types of projectsSafari and Dashboardand an assortment of templates for each project type. Templates are handy starting points for creating common types of web applications and widgets. (To find out what a template does, select it to show a short description of its capabilities.) For this tutorial, select the Safari project type. Then, to create a browser-type web application thats optimized to run in Safari on iPhone:
16
1. 2.
Select the Browser template. Click the Develop for: Safari checkbox to deselect it. (Make sure the Develop for: Mobile Safari checkbox is still selected.) Click Choose.
3.
A project window opens, displaying the first page of a new mobile Safari web application based on the Browser template, as shown in Figure 2-1.
Figure 2-1 A new mobile Safari web application project based on the Browser template
Along the left side of the project window is the navigator, which you use to switch between the various tools available when youre designing a web application. The main portion of the window is the canvas, which you use to design your web applications interface. At the bottom of the navigator in Figure 2-1 you can see the Workflow Steps list, which guides you through the web application development process. Each step is a milestone in creating a web application, telling you what to do and where to do it. When you complete a step, mark it as done and move on to the next step.
17
Note If you dont want to see the Workflow Steps list, you can hide it by choosing View > Steps or by clicking the button that looks like a checkbox at the bottom edge of the project window (this button is highlighted in Figure 2-1). Alternatively, you can view a list of the web applications files in place of the Workflow Steps list. If you want to see the Files list, choose View > Files or click the list button in the bottom edge of the project window (its the button that looks like a bulleted list).
18
Note If you've installed the iOS SDK on your computer, Dashcode opens the mobile Safari web application in the iOS Simulator application provided by the SDK. If you do not have the iOS SDK installed on your computer, Dashcode opens the mobile Safari web application in its own simulator application.
Take a few moments to use the application. You should see Parks (or a different title you typed in) displayed in the header of the first page and you should see National Parks (or a different title you gave the webpage) in the title bar area, if this area is visible. Notice that when you click a row item in the first page, a new page appears that gives details about the item. There are a few other things you should notice about the second page:
The title of the second page is the same as the name of the row item you selected in the first page. A back button has appeared to the left of the title and its label is Parks, which is the title of the first page. You can click this button to return to the first page. The text in the middle of the second page includes the name of the row item you selected.
The two pages of your web application should look similar to those shown in Figure 2-2.
Figure 2-2 The default Browser-based mobile Safari web application contains a top-level page (left) and a detail page (right)
19
Mobile Safari Web Application Tutorial Explore the Views in the Stack Layout
Although the information about national parks is just placeholder information provided by the Browser template, it helps you see some of the connections between the pages. Youll learn a bit more about these connections in the next step, Explore the Views in the Stack Layout (page 20). Before you continue, quit the simulation by choosing Quit from the simulation application menu or pressing Command-Q. Or, in Dashcode, you can click the red Stop button.
Make sure the inspector is open. If it isnt, click the blue Info button in Dashcodes toolbar. Select stackLayout in the navigator. Click the Attributes toolbar item in the inspector (its the one on the left). This should change the inspectors title to Attributes (stackLayout).
At the bottom of the inspector is a section titled Subview Transition. The values in this section control the transitions between pages. You can choose to have pages slide in from right to left (this is the default) or other ways, such as from top to bottom. Note that you may not be able to see the effect of changing the transition type in the simulator application, but you will see the effect when you view your application on an actual device.
20
Note The transitions described in this step are based on CSS transitions and animations. In the stack layout Attributes inspector, Dashcode gives you a way to specify attributes of the transitions you want to use, but does not provide a user interface for manipulating them directly. After you complete this tutorial, you might want to access the code for these transitions to make finer-grained adjustments. Before you do this, you should read Safari CSS Visual Effects Guide for more information.
21
Double-click the button on your detail page and give it a label (you can also do this by typing the label in the Label field of the Attributes inspector for the button). You may need to resize the button to fit the label you choose. Figure 2-3 shows the new button in the detail view, before it receives a new label.
Figure 2-3 Adding a part to the mobile Safari web applications user interface
22
The first line of code creates a local variable named dsource, and gives it the value of the data source named list. In the Browser template, the list data source supplies the detail page with the static information about the selected park.
The second line of code creates a local variable named name, and gives it the value of the name property of the currently selected park. In a data source, each category of data is represented by a different property. In the list data source, the name property contains the name of the selected park.
The third line of code tells the web application to display the search results for the park specified in name.
Note You dont need to understand anything about data sources or properties to complete this tutorial. Later, you can begin learning about them in Viewing a Projects Data Sources and Bindings (page 62).
After you add the code for the buttons event handler, the source code editor should look similar to Figure 2-4.
Figure 2-4 Adding code to handle the buttons click event
23
Mobile Safari Web Application Tutorial Deploy Your Mobile Safari Web Application
Test your web application again by clicking Run (or by choosing Debug > Run). In the detail page for a park, click the button you added and make sure it displays the results of a Google search on the featured park (be sure youre connected to the Internet before you try this).
24
This tutorial walks you through using Dashcode version 3.0 or later to create a project that produces two products: a Safari web application and a mobile Safari web application. A Safari web application is a dedicated part of a website that provides Safari users with interactivity and discrete functionality. A mobile Safari web application (also known as an iPhone web application) is web content optimized for Safari on iPhone that provides users of iOS-based devices with interactivity and discrete functionality. As you follow the steps in this tutorial, you learn:
How to set up and work with a dual-product project How to customize the user interface of both products How to specify a data source How to use bindings to automatically update each products user interface with data from a server
This is the third of three tutorials in this document. If youre interested in learning how to develop a Dashboard widget, read the first tutorial, Dashboard Widget Tutorial (page 10). If you want to learn how to create a mobile Safari web application only and not a Safari web application, read the second tutorial, Mobile Safari Web Application Tutorial (page 16).
25
The project you create in this tutorial is based on the browser style of web application and displays current movie trailers available on Apples website. When youre finished, the products will look similar to those shown in Figure 3-1.
26
Figure 3-1
The finished products: Safari web application (top) and mobile Safari web application (bottom)
27
Important Although you can see current movie trailer information when you test your new products in Dashcode, you cannot deploy such web applications unless you do additional work that is beyond the scope of this document. This is because your web applications cannot request information from a domain other than the one theyre running on unless you make changes to your server configuration and to your code. Before continuing, make sure that you have Dashcode version 3.0 or later installed on your Mac. If you dont have Dashcode installed, read Getting and Running Dashcode (page 8) to learn how to get and install Dashcode.
Choose a Template
To start, double-click the Dashcode icon to open it. A new project window opens and a dialog appears that displays two types of projectsSafari and Dashboardand an assortment of templates for each project type. Templates are handy starting points for creating common types of web applications and widgets. (To find out what a template does, select its icon to show a short description of its capabilities.) For this tutorial, select the Safari project type. Then, to create a browser-type, dual-product web application project:
1. 2. 3.
Select the Browser template. Make sure both Develop for: checkboxes are selected (they are selected by default). Click Choose.
28
The dialog disappears and the project window displays the first page of a new web application based on the Browser template, as shown in Figure 3-2.
Figure 3-2 A new dual-product project
The main portion of the window is the canvas, which you use to design your web applications interface. The bar between the canvas and the toolbar is the product bar, which contains buttons you use to switch between the products of a dual-product project. As shown in Figure 3-2 (page 29), the user interface of the Safari web application is displayed on the canvas by default (note that the Safari button is selected). To see the user interface of the mobile Safari web application, click the Mobile Safari button in the product bar. Along the left side of the project window is the navigator, which you use to switch between the various tools available when youre designing a web application. When you switch between products in a dual-product project, the contents of the navigator changes appropriately.
29
Dual-Product Web Application Tutorial Save and Test the Default Web Applications
At the bottom of the navigator in Figure 3-2 you can see the Workflow Steps list, which guides you through the development process. If you dont want to see the Workflow Steps list, you can hide it by choosing View > Steps or by clicking the button that looks like a box with a checkmark in it at the bottom edge of the project window (this button is highlighted in Figure 3-2). Alternatively, you can view a list of the current products data sources or code files in place of the Workflow Steps list. If you want to see the Data Sources list, click the data source button in the bottom edge of the project window (its to the left of the workflow steps button and it looks like a circle with a square inside it). If you want to see the Files list, choose View > Files or click the list button in the bottom edge of the project window (its the button to the left of the data sources button and it looks like a bulleted list).
Make sure the Safari button is selected in the product bar. Click the green Run button in the Dashcode toolbar (alternatively, you can choose Debug > Run).
When you do this, Dashcode opens the Safari web application in a simulator application. Take a few moments to use the web application. Notice that when you click the name of a park in the list along the left edge of the window, the area to the right displays information about that park. The list on the left is known as the master list, because it contains the complete list of items you can view. The right portion of the
30
Dual-Product Web Application Tutorial Save and Test the Default Web Applications
window is known as the detail area or detail view, because it shows details about the item selected in the master list. Figure 3-3 shows the default Safari web application running in the Dashcode simulator (the simulator displays the saved project name, in this case MyMovieTrailersProject, in the title bar).
Figure 3-3 The default Safari web application running in the Dashcode simulator application
After youve tested the Safari web application, stop the simulation and test the mobile Safari web application. To stop the simulation, you can choose Quit from the simulation application menu, press Command-Q, or click the red close button in the upper-left corner of the simulator window. Alternatively, in Dashcode, you can click the red Stop button in the toolbar. To test the mobile Safari web application:
1. 2.
Select the Mobile Safari button in the product bar. Click the green Run button in the Dashcode toolbar or choose Debug > Run.
31
Dual-Product Web Application Tutorial Save and Test the Default Web Applications
Note If you've installed the iOS SDK on your computer, Dashcode opens the mobile Safari web application in the iOS Simulator the SDK provides. If you do not have the iOS SDK installed on your computer, Dashcode opens the mobile Safari web application in its own simulator application. (Dashcode always opens a Safari web application in its own simulator application.)
As you use the mobile Safari web application, you see that the master list of parks takes up the entire first page. When you click a park name, a new page slides in that displays details about that park. Notice that a back button appears near the upper-left corner of the detail page and that its label is the same as the title of the first page. You click this button to return to the previous page. The two pages of the default mobile Safari web application should look similar to those shown in Figure 3-4.
Figure 3-4 The default mobile Safari web application running in the iOS Simulator
Now that youve seen the default appearance and behavior of both of your products, its time to customize them to display the movie trailer data similar to the data shown in Figure 3-1 (page 27). Before you do this, be sure to quit the simulation of the mobile Safari web application. As you did after testing the Safari web application, quit the simulation by choosing Quit from the simulation application menu, pressing Command-Q, or clicking the red close button in the upper-left corner of the simulator window. Or, in Dashcode, you can click the red Stop button in the toolbar.
32
Dual-Product Web Application Tutorial Customize the User Interface of the Safari Web Application
This section shows you how to change the default user interface to resemble the user interface of the finished product. Before you begin, make sure the Safari button is selected in the product bar. To make enough room to display the poster of the selected movie trailer to the left of the description, you need to move the description element to the right. Follow these steps to do this:
1.
Click the word Description on the canvas. This displays a rectangular outline around the detailDescription element. Look closely at this rectangle and notice the small, circular resize handles that Dashcode displays at intervals along the perimeter. Using the resize handle on the left edge of the outlined detailDescription element, drag to the right until the word Description is centered horizontally in the detail area on the canvas.
2.
Now you need to add two new parts to the canvas. If the Library isnt open already, open it by clicking the Library button in the Dashcode toolbar or by choosing Window > Show Library. Click the Parts tab in the Library window to see the Dashcode parts you can use. You need to add the Image part to display the selected movies poster in your web application. To find the Image part, you can scroll through the list of parts in the Library until you find it or you can type image in the search field at the bottom of the Library window. Drag the Image part onto the canvas and place it to the left of the description element you moved earlier. Use the resize handles on the perimeter of the image to adjust its size until you think it looks good. Before you can align the top edge of the image with the top edge of the description, you need to change the way Dashcode displays the Image part in relation to the other parts on the canvas. To do this, follow these steps:
1.
If the inspector isnt open already, click the blue Info button in the Dashcode toolbar, or choose Window > Show Inspector. Open the Metrics inspector by clicking the button that looks like a ruler in the inspectors toolbar.
33
Dual-Product Web Application Tutorial Customize the User Interface of the Safari Web Application
2. 3.
Select the Image part on the canvas. The title of the inspector changes to Metrics (image). In the Layout section of the Metrics inspector, choose Absolute from the pop-up menu.
After youve done this, you can move the Image part so that its top edge aligns with the top edge of the description element. To do this, drag from the center of the Image part (dont use the resize handles). Go back to the Library and find the Video part. This part displays the selected movies trailer and includes playback controls. Drag the Video part onto the bottom half of the canvas, into the area below the Image part you added and below the word Description. Using its resize handles, adjust the size of the Video part until you think it fits well in the lower half of the canvas. In the navigator, make sure both the image and the video elements that you added are inside the detailBox element. To do this, follow these steps:
1.
In the navigator, slowly drag the image element straight upwards until the detailBox element is highlighted and a blue line appears below the detailDescription element, as shown in Figure 3-5.
Figure 3-5
In the navigator, drag the image element into the detailBox element
2.
Release the mouse button. In the navigator, the image element is now directly below the detailDescription element. Similarly, slowly drag the video element straight upwards until the detailBox element is highlighted and a blue line appears below the image element. Release the mouse button. In the navigator, the video element is now directly below the image element.
3.
4.
34
Dual-Product Web Application Tutorial Specify a Data Source and Examine the Data Model
After youve placed the new parts appropriately, the project window should look similar to the project window shown in Figure 3-6. (Note the placement of the image and video elements in the navigator.)
Figure 3-6 The canvas of the Safari web application after the new parts are added
You do not need to add any more parts to your web application, so you might want to close the Library window. However, youll need to open it again when you customize the user interface of the mobile Safari web application.
35
Dual-Product Web Application Tutorial Specify a Data Source and Examine the Data Model
1.
Show the Data Sources list in the navigator. To do this, click the data sources button in the lower-left corner of the project window (its the one that looks like a circle with a square inside it). After you do this, you should see two data sources in the Data Sources list, one named dataSource and one named itemsList. Select dataSource in the Data Sources list. This reveals a view below the canvas, which contains the layout of data in the data source. This layout is called the data model. Paste the following URL into the URL field at the top of the data model view:
http://www.apple.com/trailers/home/xml/current.xml
2.
3.
4.
Click the Reload button to the right of the URL field or press Return.
If youve entered the URL correctly, Dashcode refreshes the data model view to display the layout of the new data source and some current movie-trailer data from Apples website. Take some time to look at the data model. Notice that it is a hierarchy with each member, called a property, displayed on a separate line. A property that contains other properties has a disclosure triangle to the left of it.
36
Dual-Product Web Application Tutorial Specify a Data Source and Examine the Data Model
The data model also displays bindings and binding controls. As you can see in Figure 3-7, a gray capsule that contains the text itemsList.dataArray is displayed to the right of the top-level content property. This capsule represents a completed binding that Dashcode provides by default in the Browser template. This binding means that the itemsList element on the canvas can get its information from the content property in the data source.
Figure 3-7 Completed bindings and binding controls are visible in the data model
If a property in the data model does not already have a binding, moving the mouse pointer over the property reveals a circular binding control to the right of the property. For example, in Figure 3-7 you can see a binding control revealed next to the poster property. Because the data source youve specified is available to both products your project creates, you do not have to perform the steps in this section again when you switch to the mobile Safari product. However, you must create a separate set of bindings in each product. This is because bindings connect properties in the data source with elements in the user interface, and each product can have a different set of elements in its user interface.
37
Dual-Product Web Application Tutorial Create Bindings for the Safari Web Application
As mentioned in Specify a Data Source and Examine the Data Model (page 35), there is already a binding in the data model view of the data source named dataSource. In this tutorial, you do not change this existing binding between the content property and the itemsList element, but you do create a few new bindings.
If its not already pointing down, click the disclosure triangle next to the movieinfo property to open it. Then, click the disclosure triangle next to the info property (its inside the movieinfo property). Press and hold the mouse button on the binding control next to the title property (its the first property inside the info property). Without releasing the mouse button, drag from the binding control to the item title element on the canvas (its the first occurrence of the word Title in the master list on the canvas).
2.
3.
38
Dual-Product Web Application Tutorial Create Bindings for the Safari Web Application
When you do this, you should see a blue connection line extend from the binding control to the item title element and a little gray box that contains the elements name, itemTitle, as shown in Figure 3-8.
Figure 3-8
Dashcode displays a blue connection line between a data source property and an element on the canvas
4.
Release the mouse button while the item title element is highlighted. Immediately, Dashcode displays a contextual menu that lists the bindable properties for this element. In this case, you should see a contextual menu that contains: text, editable, visible, enabled, html, and class.
5.
In this contextual menu, choose text. Note that if you click outside the contextual menu, the binding does not complete and you must start over from step 2.
After you finish these steps, you should see a new gray capsule in the data model. This capsule should be next to the title property and should contain the text itemTitle.text.
39
Dual-Product Web Application Tutorial Create Bindings for the Safari Web Application
Note If you see different text inside the gray capsule next to the title property, erase the binding (by clicking the delete control inside the left end of the capsule) and try the steps again. (The delete control looks like an X.) You can be sure that youre binding to the correct element when you see the elements name in the little gray box that Dashcode displays as you drag over the canvas.
Bind the title of the selected movie to the title in the detail header.
a. b.
In the data model, find the title property inside the info property. Drag from the title propertys binding control to the detailTitle element on the canvas. (On the canvas, the detailTitle element displays the word Title in a large font, and appears above the word Location.) Choose text from the contextual menu that appears when you release the mouse button.
c. 2.
Bind the description of the selected movie to the description that appears above the video.
a. b.
In the data model, find the description property inside the info property. Drag from the description propertys binding control to the detailDescription element on the canvas. (The detailDescription element is the one you moved to the right to make room for the Image part in Customize the User Interface of the Safari Web Application (page 33)). Choose text from the contextual menu that appears when you release the mouse button.
c. 3.
In the data model, find the xlarge property inside the poster property. Drag from the xlarge propertys binding control to the image element on the canvas (this is the Image part you added in Customize the User Interface of the Safari Web Application (page 33)). Choose src from the contextual menu that appears when you release the mouse button.
c.
40
4.
In the data model, find the large property inside the preview property. Drag from the large propertys binding control to the video element on the canvas (this is the Video part you added in Customize the User Interface of the Safari Web Application (page 33)) Choose src from the contextual menu that appears when you release the mouse button.
c.
After youve finished creating these bindings, youve completed all the steps necessary to produce a Safari web application that looks similar to the one shown in Figure 3-1 (page 27).
41
Dual-Product Web Application Tutorial Customize the User Interface of the Mobile Safari Web Application
Place the Image part inside the white box on the detail page, below the title, location, and description elements. To do this, drag the Image part onto the canvas and, without releasing the mouse button, drag it towards the bottom edge of the white box until the title, location, and description elements jump above the Image part. If you happen to release the mouse button before you finish placing the Image part, delete the Image part, drag in a new one, and try again. Adjust the size of the Image part by using its resize handles until you think it fits well into the space inside the white box. After you do this, your project window should look something like the project window shown in Figure 3-9:
Figure 3-9 The canvas of the mobile Safari web application after the Image part is added to the detail page
42
Dual-Product Web Application Tutorial Create Bindings for the Mobile Safari Web Application
In this section, youll create five bindings: one to an element on the master list page and four to elements on the detail page. Before you begin, make sure the Mobile Safari button is selected in the product bar.
In the data model, find the title property inside the info property. Drag from the title propertys binding control to the rowTitle element on the canvas. (The rowTitle element contains the first occurrence of the word Item in the list.) Choose text from the contextual menu that appears when you release the mouse button.
3.
Bind the title of the selected movie to the title in the white box.
a.
In the data model, find the title property inside the info property.
43
Dual-Product Web Application Tutorial Test the Mobile Safari Web Application
b.
Drag from the title propertys binding control to the detailTitle element on the canvas. (The detailTitle element contains the word Title on the canvas.) Choose text from the contextual menu that appears when you release the mouse button.
c. 2.
Bind the rating of the selected movie to the subtitle in the white box.
a. b.
In the data model, find the rating property inside the info property. Drag from the rating propertys binding control to the detailSubtitle element on the canvas. (The detailSubtitle element contains the word Location on the canvas.) Choose text from the contextual menu that appears when you release the mouse button.
c. 3.
Bind the description of the selected movie to the description in the white box.
a. b.
In the data model, find the description property inside the info property. Drag from the description propertys binding control to the detailDescription element on the canvas. (The detailDescription element contains the word Description" on the canvas.) Choose text from the contextual menu that appears when you release the mouse button.
c. 4.
In the data model, find the xlarge property inside the poster property. Drag from the xlarge propertys binding control to the image element on the canvas (this is the Image part that you added in Customize the User Interface of the Mobile Safari Web Application (page 41)). Choose src from the contextual menu that appears when you release the mouse button.
c.
After youve finished creating these bindings, youve completed all the steps necessary to produce a mobile Safari web application that looks similar to the one shown in Figure 3-1 (page 27).
44
Next Steps
Congratulations! Youve learned how to use Dashcode to create a dual-product project that produces two web application products. To learn about deploying your products, see Deploying a Web Application (page 79).
45
Starting a Project
When you start a new project, you base it on a Dashcode template or, in the case of Dashboard widgets, you can also base it on an existing widget. A project encapsulates all the files and resources that Dashcode uses to build a widget or web application for you. This chapter discusses the options you have when you start a project. It also discusses opening a Dashboard widget in Dashcode, a feature that allows you to forgo Dashcodes design tools to code, test, and debug an existing widget.
46
Once you import your widget into a Dashcode project, use the widget attributes pane, as discussed in Providing Attributes for a Dashboard Widget (page 47), to edit your widgets Identity values.
Properties Template-specific options are in this section. If youre using an imported or opened widget or the Custom template, this section is absent. For each templates specific properties, read Dashcode Templates (page 83).
47
48
Adjust page width to fit. When you choose this option, your web application resizes (that is, increases or decreases in width) when the device orientation changes. This option is generally recommended for mobile Safari web applications, because it enhances the users perception of the web application as a standalone application and not a webpage. "Zoom page to fit. When you choose this option, the width of your mobile Safari web application does not change when the device orientation changes, but the scale does. In other words, the content of your web application will appear a bit bigger. You might want to choose this option if your web application has a complicated layout that you dont want to change in width when the device orientation changes.
The Page Zooming value in this section controls whether users can zoom your web application when they view it on iPhone or iPod touch. In general, because you want iPhone and iPod touch users to view your web application as a standalone application and not as a webpage, its recommended that you turn off Page Zooming (that is, deselect Allow users to adjust page zoom). Web Clip The values in this section control how your web application can be displayed on iPhone and iPod touch and how your Web Clip icon is created and displayed. In iOS 2.0 and later you can choose to make your mobile Safari web application available in a full-screen mode, which hides the Safari toolbar and navigation bar. If you want to do this, you must also provide a Web Clip icon, because tapping a Web Clip icon is the only way users can open a web application in full-screen mode (navigating to the application in Safari on iPhone does not open it in full-screen mode).
49
If you choose not to support full-screen mode, you should still consider providing a Web Clip icon so users have a convenient way to open your web application. To make your mobile Safari web application available in full-screen mode, select the Show as full screen application (hide Safari toolbar and navigation bar) checkbox. This allows users to open your web application in full-screen mode when they tap the Web Clip icon. Note that users press the Home button to leave a web application that is running in full-screen mode. If you selected the Show as full screen application (hide Safari toolbar and navigation bar) checkbox, you can also specify one of the following three styles for the status bar:
Use the pop-up menu to choose the status bar style that best coordinates with the appearance of your web application. You can specify a status bar style only if you selected the Show as full screen application (hide Safari toolbar and navigation bar) checkbox. This is because the status bar appearance automatically matches the appearance of the Safari navigation bar when it is visible. The two options for the Icon value are:
"Use custom icon. Choose this option if you want to design your own Web Clip icon to represent your mobile Safari web application. See Designing a Web Clip Icon for an iPhone Web Application (page 58) for more information on how to do this. If you choose this option, you can also specify whether you want the shiny glass overlay effect to be added automatically by selecting the Add glass visual effect checkbox. Note that you do not have control over a Web Clip icons rounded corners and drop shadow; these are always added automatically.
"Use Safari generated icon. Choose this option if you want to allow users to create their own Web Clip icon to represent your mobile Safari web application.
50
To open a widget in Dashcode, choose File > Open and select a widget in the Open dialog, or choose File > New Project and click the Open Existing button at the bottom of the template chooser dialog. When you open a widget with Dashcode, the canvas is locked. This means that Dashcodes design tools, responsible for generating HTML, CSS, and images for a widget, are turned off. When you open an existing widget instead of importing it into a new project, Dashcode displays a lock over the bottom of the canvas.
51
52
Designing the User Interface of a Widget or Web Application Adding Parts to an Interface
The Attributes inspector allows you to modify the selected elements ID (used in JavaScript to reference the element), its CSS class, whether its shown in the widget or web application and in the default image, and any parameters that are unique to the element. If its appropriate for the selected element, the Fill & Stroke inspector allows you to adjust its style and add effects. Style adjustments you can make include:
53
Designing the User Interface of a Widget or Web Application Changing an Elements Properties
Fill, such as solid, gradient, or image Corner roundness, opacity, and reflection Stroke color and width
Glass, including control over shine, tone, horizon, and curvature Recess, including control over depth, shadow, and highlights
The Metrics inspector allows you to modify the selected elements size and position, as well as its behavior if the widget or webpage is resized. The Layout pop-up menu allows you to select whether the element should be positioned using absolute or document-flow positioning (learn about these positioning styles in Absolute versus Document-Flow Positioning (page 55)). The Autoresize settings affect how an element behaves when the widget or webpage is resized on the canvas. Note that the values in the Size section reflect the actual dimensions of the selected element, including borders. If the selected element displays text, you can adjust the texts font, style, color, size, shadow, alignment, and spacing in the Text inspector. You can also set whether text wraps or not and how to handle text overflow. Setting the text overflow to Clip cuts any string in the selected element at its bounds, allowing for no overflow, whereas setting the text overflow to Ellipsis appends an ellipsis character () to the selected elements text when it reaches the elements bounds. Note If you plan to share a widget or deploy a web application, be careful to use fonts that are standard in Mac OS X, such as Helvetica Neue, Times, and Monaco.
The Bindings inspector allows you to set and adjust bindings between a data source and specific properties of the selected element. For each bindable property of the element, you can specify the data source to bind to, the key path of the item in the data source, a value transformer, and placeholder values. (To learn about value transformers, see Adding a Value Transformer (page 67).) You do not have to use the Bindings inspector to create bindings. Instead, you can drag connections from items in the data model view to elements on the canvas or listed in the navigator. (To learn how to show the data model view, see Viewing a Projects Data Sources and Bindings (page 62); to learn how to create bindings, see Creating Bindings (page 65).) However, you must use the Bindings inspector to specify a value transformer or supply placeholder values.
The Behaviors inspector allows you to assign to the selected element JavaScript handlers for various events. For each event, you can assign an existing JavaScript function as its handler or create an empty function thats automatically added to the projects JavaScript code. After you assign a handler to an event, click the arrow next to the handlers name to reveal the function in the source code editor. Working with code is discussed in Adding Source Code and Creating Bindings (page 61).
54
Designing the User Interface of a Widget or Web Application Arranging and Locking Elements
55
Designing the User Interface of a Widget or Web Application Searching for Elements
The default positioning style used in a project does not mean that there are no variations, however. In the Browser template web application project, for example, the elements in the list row (the row title and the row arrow) are absolutely positioned to ensure a consistent layout. When you customize a project, you should be aware of the positioning style of the element youre changing. This is because dragging a part into an existing container element on the canvas causes the part to adopt the prevailing positioning style of its new siblings. If you want the new part to adopt the alternate positioning style, hold down the Shift key while you drag the part onto the canvas.
56
Designing the User Interface of a Widget or Web Application Disabling the Canvas
Select the widget item in the navigator to show the canvas. Select the element on the canvas that you want removed from the default image. Show the Attributes inspector (as discussed in Changing an Elements Properties (page 53)). Deselect Show in Default Image.
The toolbar below the default image preview offers additional configuration options for default images: Start Sync / Stop Sync By default, Dashcode updates a widgets default image whenever the widgets interface changes. To turn this behavior off, click Stop Sync. To enable this behavior if its been turned off, click Start Sync. Import If you already have an image that you want to use as a widgets default image, click the Import button and select it in the dialog that appears. Open in External Editor If you want to tweak your default image in an application other than Dashcode, click the Open in External Editor button. When you do, the default image as shown in Dashcode is opened in your default PNG-handling application.
57
Designing the User Interface of a Widget or Web Application Designing a Widget Icon
58
Note Because iPhone and iPod touch add the appropriate corner radius and drop shadow to the icon you provide, you should not add these effects yourself. However, you can control whether the shiny glass overlay effect is added automatically by specifying a value in the application attributes pane (for more information about this, see Application Attributes for Mobile Safari Web Applications (page 49)).
You can use the Web Clip Icon composer to design your applications icon. To show the Web Clip Icon composer, select Web Clip Icon in the navigator. To modify the appearance of the body of the icon, show the Fill & Stroke inspector and change the fill style, opacity, and stroke style. The toolbar at the bottom of the Web Clip Icon composer offers additional configuration options for these icons: Place To put an image, such as a logo, on a web applications icon, click the Place button and select the image file. Once the image is placed, you can move and resize it. Import If you already have an image that you want to use as a web applications icon, click the Import button and select it in the dialog that appears. Open in External Editor If you want to customize a web application icon in an application other than Dashcode, click the Open in External Editor button. When you do this, the icon is opened in your default PNG-handling application.
Designing a Favicon
A Safari web application should include a favicon (an abbreviation of the term favorites icon), which visually identifies the web application in the browser. Typically, a browser that supports favicons displays them in the address field and in bookmarks or history lists. A browser that supports tabbed browsing may also display a favicon next to the web applications title in a tab. Providing a distinctive favicon is a good idea because it helps users recognize your web application. You can specify your favicon in Dashcodes Favicon composer. To show the Favicon composer, select Favicon in the navigator. You can create your favicon in two sizes: 32 x 32 pixels and 16 x 16 pixels. The smaller size can be used by all browsers that support favicons. Creating a 32 x 32 pixel version of your favicon is optional, because some browsers ignore it or merely scale it down before displaying it. The toolbar at the bottom of the Favicon composer offers the following options for designing a favicon:
59
Import If you have an image that you want to use as a favicon, click the Import button and select it in the dialog that appears. Open in External Editor If you want to customize a favicon in an application other than Dashcode, click the Open in External Editor button. When you do this, the favicon is opened in your default ICO-handling application. Dashcode updates the favicon in your project when you save the changes you made in an external editing application.
60
After youve started a project and designed the user interface, you may need to customize the implementation by adding code, data sources, or bindings to your widget or web application. This chapter describes how to:
View the files and data sources that make up your project Write custom code to perform tasks that arent automatically provided by the template Add data sources and bind them to elements in the user interface Write a value transformer that converts the value of a property to a version thats appropriate for display
This chapter also shows you how to turn on access to resources, such as files outside of the project and the network. Finally, it covers the application preferences that affect your code editing experience in Dashcode.
When you select an HTML, CSS, JavaScript, or property list file in the Files list, the source code editor appears below the canvas showing the selected files contents. In the code editor you can edit the actual HTML, CSS, and JavaScript files that implement your widget or web application. For more on coding using HTML, CSS, and JavaScript, read Using HTML, CSS, and JavaScript Programming Interfaces (page 64). Above the text view portion of the source code editor are two pop-up menus, a file history menu on the left and, in some cases, a function menu to the right of that. The file history menu lists the text files and data sources that you've recently edited or viewed in the source code editor. When you select a file or data source in the file history menu, its displayed in the source code editor. When you first open a project, the file history
61
Adding Source Code and Creating Bindings Viewing a Projects Data Sources and Bindings
menu contains the files youre most likely to open, such as main.js, main.css, and index.html or main.html. Depending on the file youre currently viewing in the source code editor, the function menu lists the names of all the functions in a JavaScript file or all the rules in a CSS file. Note that the function menu is not available when viewing HTML files, property list files, or data sources. One common way to add code is to add an event handler to an element in the user interface. You do this using the Behaviors inspector, as discussed in Adding a Handler for an Event (page 68). If youre using Dashcode version 3.0 and later, a common reason to add code is when you need a value transformer to provide an appropriate value to display, based on other information in your project. You do this using the Bindings inspector, as discussed in Adding a Value Transformer (page 67). When working with resources originating outside a widget or web applicationXMLHttpRequest, command-line tools, Java applets, and suchyou need to explicitly turn on access to these items. To learn more about resource access and what elements need activation, read Resource Access (page 72). You can also modify how the source code editor looks and behaves, as described in Code Editing Preferences (page 73).
62
Adding Source Code and Creating Bindings Viewing a Projects Data Sources and Bindings
In the data model view, Dashcode displays the hierarchical organization of the data source, using disclosure triangles to indicate properties that contain children. Open a disclosure triangle to reveal a box containing a list of child properties. When you move the pointer over a child property, Dashcode highlights all its ancestor properties. Each property is accompanied by an icon that indicates its data type:
(Attribute)
(Boolean)
(Number)
(Object)
(String) When a data source contains an array of properties of the same type, the array is represented by an icon that looks like a stack of data type icons. For example, an array of strings is represented by this icon: If a data source has access to actual data (when, for example, youve specified a feed URL or you supply static data), data is displayed to the right of a propertys name. When the property value is an array, Dashcode displays the total number of array members and provides arrow controls you can use to step through the array. One array member at a time is displayed in a box revealed by a disclosure triangle. When you hover over a property name, Dashcode displays a help tag that provides the key path of the property and its data type. The key path represents the propertys position in the hierarchy. A key path for a property named property_n is of the form property_1.property_2.[...].property_n, where property_1 is the root-level ancestor. For example, the Podcast template contains a data source that represents podcast data. The key path that locates the podcast title property in the data hierarchy is content.channel.title. Dashcode displays all existing bindings to the far right of a data source property. When no binding yet exists, Dashcode displays a binding control (a small circle) when you move the pointer over a propertys row. When you position the pointer over the binding control itself, it displays a plus symbol (+). Existing bindings are displayed in a capsule to the right of a property; the capsule is visible until you remove the binding. Usually, the binding capsule contains a delete control on the left (it looks like an X), the property of the user interface element to which the item is bound, and a binding control on the right. However, if a single data source property has multiple bindings the capsule displays a disclosure triangle on the left and the word Multiple in place of the user interface property. Open the disclosure triangle in the capsule to reveal the set of bindings for that data source property.
63
Adding Source Code and Creating Bindings Using HTML, CSS, and JavaScript Programming Interfaces
A good example of a property with multiple bindings is the queryInProgress property of the feed data source in the RSS template for web applications. This data source property is bound to both the visible and animating properties of the activity indicator part on the canvas. This ensures that when the application runs, the activity indicator is visible only while a query is in progress and that it spins until the query is finished. As mentioned in Changing an Elements Properties (page 53), you can also view and change bindings in the Bindings inspector. Whereas the data model view gives you a bindings-centric perspective on these connections, the Bindings inspector gives you an element-centric perspective. The Bindings inspector displays the bindable properties of the currently selected element and provides controls to create and change bindings. If a binding already exists on a property, the Bindings inspector displays the data source name and the complete key path of the bound property in the data source.
Safari FAQ WebKit DOM Programming Topics Safari HTML Reference Safari Web Content Guide WebKit DOM Reference
To learn more about creating a webpage or web application optimized to run in Safari on iPhone, see Safari Web Content Guide . In addition to WebKits HTML, CSS, and JavaScript programming interfaces, Apple offers Dashboard-specific programming interfaces for use in widgets. For more on these programming interfaces, read Dashboard Programming Topics and Dashboard Reference .
64
For your convenience, all project templates include at least one data source, even if the data source does not represent any actual data. For example, the Browser template includes a data source that represents static data from a JavaScript file included in the default project. The RSS template includes a data source that can represent data from an RSS feed; you see actual data when you supply a specific feed URL. To add a new data source, reveal the Data Sources list in the navigator (as described in Viewing a Projects Data Sources and Bindings (page 62)) and select New Data Source in the action menu below the list. Or, select File > New > Data Source. When you do this, the new data source appears in the list. (If you have a dual-product project, the new data source is automatically available in both products.) Note If you add a list or grid part to the canvas and you bind to it an array in an existing data source, the list or grid itself becomes a data source. This is because Dashcode implements list and grid parts using data sources and bindings, instead of controllers. This means that you can bind the selection property of a list or grid data source (which represents the object selected in a row or cell) to another element on the canvas, such as a part in a detail view.
To specify the location of a data source, you supply a URL for a JSON or XML feed. Note that you can also supply the local path of a file of static data to serve as the data source. You do not need to specify a location for a data source that represents a list or grid part. There are two ways to supply the location of a data source, depending on the template your project uses. For all projects, you can enter a URL in the data model view of the new data source (you reveal the data model view when you select the data source in the Data Sources list). For projects based on RSS, Podcast, Maps, Photocast, Video Podcast, or Daily Feed templates, you can also enter a URL in the Properties section of the widget attributes or application attributes pane. If youve entered a valid URL, Dashcode updates the data model view to display the available properties and attributes of the data, along with some actual data when possible.
Creating Bindings
All Dashcode templates support bindings, which allow a user interface element to get specific items of data from a data source and automatically update its display when that data changes. Dashcode offers an easy way to create bindings in the data model view. To find out how to reveal this view and for a description of its contents, see Viewing a Projects Data Sources and Bindings (page 62). To create a binding between a data source property and an element on the canvas:
1.
Press and hold the mouse button on the circular binding control next to the data source property, and drag the pointer to the element on the canvas that you want to bind to.
65
As you drag, a connection line extends from the binding control, and each element on the canvas highlights as you pass the pointer over it. (You can see an example of how this looks in Figure 3-8 (page 39).)
2.
Release the mouse button when the element you want to bind to is highlighted. As soon as you stop dragging, Dashcode displays a contextual menu that lists the bindable properties of the selected element.
3.
Choose the appropriate property to complete the binding. If you choose not to complete the binding after you stop dragging, simply click outside of the contextual menu and the binding is not created.
Note You can also create a binding by dragging from a binding control in the data model view to an element in the navigator. You might need to do this if the element you want to bind to is difficult to see on the canvas. When you create a binding to an element in the navigator, you complete the binding as described in steps 2 and 3 above.
If the Bindings inspector wasnt visible before, it opens when you complete a binding, allowing you to specify a value transformer and placeholder text or values. You can also create bindings in the Bindings inspector, without dragging from the data model view. To do this, follow these steps:
1.
Select the element you want to bind to on the canvas or in the navigator. When you do this, the Bindings inspector displays the bindable properties of the element.
2.
In the Bindings inspector, open the disclosure triangle to the left of the element property you want to bind to. Select the Bind to checkbox and choose a data source from the pop-up menu. Open the Key Path pop-down menu to reveal the top-level properties of the selected data source. Choose a data source property in the Key Path menu. If the data source property youre interested in is a child of a top-level property, click the pop-down control again to see a list of the current propertys children. Continue choosing child properties until you reach the one you want.
3. 4. 5.
Because bindings are tightly integrated with user interface objects, you must create bindings separately in both products of a dual-product project. This is because each product uses different parts to display data, even though they can share a single data source.
66
Note If you copy a part from one product of a dual-product project to the other, any bindings you made are not included in the copy of the part.
Select the user interface element that is bound to the data source item you want to transform. Click the Value Transformer text field. Dashcode displays the generic value transformers, along with any value transformers youve already included in your project, in a pop-down list.
3.
Select an existing function or type the name of the function you plan to write and press Return. If you select an existing value transformer, Dashcode displays an arrow control that you can click to see the function in the source code editor. If you supply the name of a new value transformer, Dashcode inserts the new function in your projects JavaScript file and displays it in the source code editor. You can then add custom code that performs the transformation.
Dashcode includes several built-in value transformers in the transformers.js file. You can customize some of these transformers by changing the default parameters. For example, the truncation value transformer (DC.transformer.Truncated) automatically truncates the passed-in string to 10 characters, but you can change this by editing the transformer function. The transformers.js file contains the following value transformers:
DC.transformer.Boolean returns the Boolean value TRUE if the passed-in value is equal to a value
you supply as the true value. For example, you might designate the string red as the true value. Changing the Boolean value transformer to use this string, this value transformer returns TRUE when the passed-in value is red. You can also specify a reverse transformation for this function. If you want to do this, you also need to supply a false value that the function can use to test the passed-in value against. In this case, the transformer returns either the true or false value that you supplied, depending on which one the passed-in value matches.
67
Adding Source Code and Creating Bindings Adding a Handler for an Event
DC.transformer.FirstObject returns the first object in an array. DC.transformer.Matches returns the Boolean value TRUE if the passed-in value matches a regular
DC.transformer.Not returns the opposite Boolean value of the passed-in value (that is, it returns TRUE
DC.transformer.Truncated truncates the passed-in string to a number of characters that you define
68
Adding Source Code and Creating Bindings Adding or Removing a Web Application Product
Note Dashcode automatically includes in the manifest all files your project needs. If necessary, you can modify the manifest after you deploy your project or save it to disk. By default, Dashcode names the manifest file OfflineApp.manifest and includes it in the appropriate product folder (Safari or Mobile) in your saved project and deployed project folders.
To enable offline usage of your web application, select the Offline Viewing checkbox in the General section of the application attributes pane. Dashcode adds the manifest attribute to the HTML element in the index.html file. Dashcode helps you support offline usage of your web application by providing some code snippets you can use to query and respond to changes in online status. You can elect to receive these events when the user goes online or offline, and you can write code to update the user interface or access different resources, as necessary.
The safari folder contains all the files and parts that are unique to the Safari web application. The Images folder contains all the images that are common to both products. The index.html file is the main HTML file for the project. The mobile folder contains all the files and parts that are unique to the mobile Safari web application. The Parts folder contains Dashcode parts and other code files that are common to both products.
As you can imagine, a project that creates only a mobile Safari web application does not contain a safari folder, and a project that creates only a Safari web application does not contain a mobile folder.
69
Adding Source Code and Creating Bindings Adding Code for Custom Controllers
Important The root-level index.html file is considered the main HTML file for the project. In a dual-product or Safari-only project, the main index.html file contains a base tag whose href attribute references the safari/ location on your server. In a mobile Safarionly project, the base tag in the main index.html file references the mobile/ location on your server. Dashcode includes this default location so your applications URL can be, for example, http://myserver.com/ instead of http://myserver.com/safari/. Be sure to take this into account when you refer to resources on your server. If you have a dual-product project, you can remove a product by choosing File > Delete Current Product, where Current is Safari or Mobile Safari, depending on which product is currently selected. If you want to add a product to a single-destination project, choose File > Add Other Product, where Other is Safari or Mobile Safari, and represents the product you want to add.
70
Code Snippets
Dashcode includes a set of reusable code snippets. Each code snippet provides a bit of functionality that you can use to enhance your widget or web application. To show the code snippets, choose Window > Show Library and click the Code button. To add a code snippet to your project, drag it from the Code Library to the source code editor. In addition to the code snippets included with Dashcode, you can save your own snippets for later use by dragging them from the source code editor to a group you create in the Code Library. To create a new group, choose New Group from the action menu under the listings in the Code Library.
71
Adding Source Code and Creating Bindings Resource Access for Widgets
Note Dashcode does not manage references to files and folders in a widget or web application. If you remove, rename, or move a file or folder, you need to remove, rename, or update the reference to the file or folder in the projects main HTML file. Failure to update a reference to a removed, renamed, or moved file or folder may result in unexpected behavior. When you add a new JavaScript or CSS file, you need to include a reference to the file for it to be used by your widget or web application. Add a reference to the new file at the top of the projects main HTML file. In a widget, the main HTML file is the file paired with the MainHTML key in the widgets Info.plist file. In a web application, the main HTML file is the index.html file at the root level of the Files list. In your projects main HTML file, add a reference to a new CSS file using the @import directive using the <style> tags. Add a reference to a new JavaScript file using the <script> tag.
Network resources (including XMLHttpRequest) External files Internet plug-ins, such as QuickTime and Quartz Composer Java applets Command-line applications
Important In general, Safari on iPhone does not support any third-party plug-ins or features that require access to the file system, so most of these resources are not appropriate for mobile Safari web applications. However, Safari on iPhone does support XMLHttpRequest. To learn more about unsupported technologies in a mobile Safari web application, see Safari Web Content Guide . Turn on access to these resources, select Widget Attributes in the navigator. Then select the option for the resource you want to use. Options include: Network / Disk Access If your widget requires access to network resources or files on disk, select the appropriate item. Unless your template already needs access to network resources (such as XMLHttpRequest) and files on disk outside of your widget bundle, these resources are turned off.
72
Extensions If your widget uses content provided through an Internet plug-in or a Java applet, or uses a command-line utility via widget.system, select the appropriate option. Unless your template already needs access to plug-ins (such as QuickTime), Java, and command-line utilities, these resources are turned off.
General preferences include an option for opening source code files in Dashcode or in a helper application. The source code editor has various visibility and behavior preferences, including the visibility of the gutter and line number next to your source code, the source code editors line wrapping, and the Tab keys indentation behavior. You can set these preferences in Editing preferences. Your source code can be colored based on the codes syntax. You can adjust text font, size, and color in Formatting preferences. Dashcode offers a code completion feature called Code Sense (as described in Code Completion Using Code Sense (page 70)). At the top of the source code editor, a pop-up menu shows the symbols in a file. Code Sense preferences include a setting for how these symbols are organized. This pane also includes settings for code completion.
73
After youve written code for your widget or web application, test it to ensure that it works as you expect. Dashcode includes its own Dashboard environment so you can run and test a widget in Dashcode without having to open it in Dashboard. Similarly, Dashcode includes a simulator application that simulates Safari and Safari on iPhone, so you can easily test both products of a dual-product web application project. Note If youve installed the iOS SDK on the same computer on which you use Dashcode, Dashcode opens the iOS Simulator application in the SDK when you run a mobile Safari web application. If you dont have the SDK installed, your mobile Safari web application is opened in the Dashcode simulator application.
In addition to running widgets and web applications, Dashcode also includes tools that help you debug and fix problems that may arise. This chapter includes information on how to trace events and inspect variable values while a widget or web application executes. It also includes information on sharing a widget and deploying a web application.
For widgets, this runs the widget in Dashcode without having to open it in Dashboard. The widget behaves here as it would in Dashboard. For web applications, this runs the web application in the appropriate simulator application without having to deploy it and run it in a device. The simulator allows your web application to behave as it would in Safari on iPhone or in Safari.
If youve installed the iOS SDK on your computer, you have two display options when testing a mobile Safari web application in Dashcode version 3.0 and later:
Run with the Safari interface visible (that is, with the Safari toolbar and navigation bar visible). This simulates what users can see when they use Safari on iPhone to navigate to your web application.
74
Run with the Safari interface hidden (that is, in full-screen mode). This simulates what users can see when they tap a Web Clip icon to open a mobile Safari web application that can run in full-screen mode.
You can access these options by clicking and holding the Run button in the Dashcode project window. From the menu that appears, choose Run or Run Full-screen. After you make your choice, clicking Run or choosing Debug > Run runs your web application in that mode until you change it. In Dashcode version 3.0 and later you can simulate running a web application on the same server that hosts the applications data sources. This allows the application to bypass the same source restriction imposed by web browsers and fetch data from an external server (see Deploying a Web Application (page 79) for more information on this restriction). When you run the application in Dashcode for the first time, Dashcode displays a dialog that asks whether you want to simulate running on a remote server or on your local computer.
Click Simulate to simulate running on the remote server you identified in the application attributes pane or in the URL field of a data source. Dashcode uses this remote server for simulation until you specify a different one, or until you deselect the Simulation checkbox in the Running section of the Run & Share pane. If you do either of these things, Dashcode displays a dialog asking for confirmation of your simulation choice the next time you run your web application.
Click Continue to run the application on your local computer. Note that this can prevent the application from loading external resources.
Note When you run a web application in the Dashcode simulator application, you have access to the Web Inspector that is also available in Safari. In the Dashcode simulator, choose View > Show Web Inspector to open the Web Inspector. To learn more about this tool, see Using the Web Inspector.
When your widget or web application loads, test it out to see if it functions as you expect. When an error occurs, an exception is thrown and, by default, execution pauses. When this happens, there are a number of tools at your disposal that help you see where the problem is and inspect variable values:
The run log lists errors and other useful information. If you enable tracing, the run log notes the invocation of functions as well. See The Run Log and Tracing Execution (page 76) for details. The Stackframe & Variables table shows you the value of any variable a widget or web application uses. See Checking Values in Memory (page 77) for details. Step-by-step execution enables walking through the execution line-by-line so you can see the effects of the code. See Pausing and Step-by-Step Execution (page 76) for details. The Evaluator is a console where you enter individual lines of code to be executed immediately. See The Code Evaluator (page 78) for details.
75
To continue a paused widget or web application, choose Debug > Continue or click Continue in the toolbar. To turn off pausing when an exception occurs, deselect Debug > Break on Exceptions. To pause a widget or web application at any time, choose Debug > Pause or click the pause button in the toolbar. While a widget or web application is paused, you can step through its code line-by-line as discussed in Pausing and Step-by-Step Execution (page 76). You can also pause a widget or web application when execution reaches a specific line of code using a breakpoint, as discussed in Breakpoints (page 77). To stop running a widget or web application in its testing environment, choose Debug > Stop or click Stop in the toolbar.
76
When youre finished examining variables, you can continue executing the widget or web application in a few different ways: Continue Choose Debug > Continue or click Continue in the toolbar to continue execution with no interruption. Step Into Choose Debug > Step Into or click Step Into in the toolbar to execute the next line of code and step into function calls so you can see the effect that line of code has. Step Over Choose Debug > Step Over or click Step Over in the toolbar to execute the next line of code so you can see the effects that line of code has. Step to End Choose Debug > Step to End or click Step to End in the toolbar to execute the rest of the current function; execution pauses when the function is finished so that you can inspect its variables before they are relinquished. Also, execution pauses whenever an exception occurs. When an exception occurs, the execution of a web application or widget is paused and an entry in the run log explains what the problem is. If you click the entry, the line of code in which the exception occurred is highlighted. By default, this option is enabled. You can control this option by choosing Debug > Break on Exceptions.
Breakpoints
In addition to pausing the execution of a widget or web application using the Pause option, you can set places in your code for execution to pause, called breakpoints. You can add a breakpoint in two ways. One way is to click in the gutter of the source code editor. If the gutter is not showing, go to Editing preferences and select the Show Gutter option.
77
A blue arrow in the gutter means that before that line of code is executed, execution will halt. To temporarily disable the breakpoint, click it; it turns from blue to gray to indicate that its disabled. To remove the breakpoint, drag it outside of the gutter. The other way to set a breakpoint is to use the Breakpoints window. To show the Breakpoints window choose Debug > Show Breakpoints Window or double-click in the gutter. In the Breakpoints window, click the plus (+) button and specify either a filename and line number or a function name to break on. For instance, if you wanted to break in Untitled.js on line 42, you enter Untitled.js:42. Alternatively, you can supply the name of the function you want to break on (for instance, showFront in a widget). In addition to the breakpoint, you can set a condition for the breakpoint. A condition is a JavaScript statement that evaluates to either true or false. If the condition evaluates to true when execution passes the breakpoint, execution pauses. In the Breakpoints Window, you can remove a breakpoint by selecting a breakpoint from the table and clicking the minus (-) button or you can disable it by deselecting the checkbox next to a breakpoints item in the table.
Sharing a Widget
When youre finished developing a widget, you can share it with others. There are two commands for deploying a widget, and both export the widget from the project as a .wdgt bundle, ready to run in Dashboard. Click Run & Share in the navigator to see a pane that gives you the choice of deploying the widget for use in Mac OS X v10.4.3 or later or for use in all versions of Mac OS X v10.4. In most cases, deploying a widget for use in Mac OS X v10.4.3 or later is advisable, because it results in a smaller widget.
78
If you want to share your widget by, for example, sending it in an email, click Save to Disk in the Run & Share pane and choose a convenient save location. If you want to make sure the widget project is automatically saved to disk before deploying, select the Save project to disk before deploying checkbox. Note that this checkbox is available after youve saved the widget project for the first time. If the widget is for your use only, choose File > Deploy Widget to install it on your computer.
Deploy to a local destination. Dashcode places your web application files in a folder you specify for the default local destination or a local destination you create. Deploy to a remote server. Dashcode uses WebDAV, FTP, or MobileMe to upload your web application files to a server you specify. Save to disk. Dashcode saves your web application files in a folder whose name and location you supply.
If you want to save a copy of your web application files in a folder on disk, click Save to Disk at the bottom of the Run & Share pane and supply a folder name and location. If you want to deploy the application to a local or remote server, you can customize the deployment behavior in the Deploy section of the Run & Share pane:
Use the Destination pop-up menu if you want to select a destination other than the default. (Unless youve already changed the default destination, this is the localhost account.) To add a new destination, select Add destination in the pop-up menu to open Dashcodes Destinations preferences and set up a new destination. In Destinations preferences, you can specify an additional local destination or a WebDAV, FTP, or MobileMe destination. You can also set whether Dashcode should use the new destination as the default destination for new projects.
Use the Application Path field to supply a name for the application folder (otherwise, Dashcode creates a folder called Untitled). Dashcode creates this folder in the path specified by the currently selected destination.
79
In the Options section of the Run & Share pane, you can determine the save behavior and the deployment notification:
Select the Save behavior checkbox if you want your web application project to be saved before every deployment (this checkbox is available after youve saved the project for the first time). Select the Compression checkbox if you want Dashcode to compress the JavaScript code in the parts files. This can reduce network latency during multiple file requests. Note that selecting this checkbox does not compress main.js or any JavaScript code you supply. Select the Notification checkbox if you want Dashcode to send an email message containing a link to your application every time you deploy it. Use the field below the Notification checkbox to supply the recipients email address (or multiple email addresses, separated by commas).
After you finish making your selections, click Deploy at the bottom of the Run & Share pane, or choose File > Deploy, to deploy your web application. To view your web application, navigate to the index.html file on the designated server (for example, http://myserver.com/myapp/index.html). Your web application automatically detects the identity of the browser and opens a mobile Safari web application in Safari on iPhone and a Safari web application in Safari. Note As mentioned above, Dashcode uses WebDAV, FTP, or MobileMe to upload your application files to a remote server. Dashcode does not support SSH or SFTP.
Warning Web browsers, including Safari on iPhone, implement a security model known as same source. This means that webpages are not allowed to request information from Internet domains other than the one from which they came. If you have built a web application that fetches information from other websites to display, be sure to tell Dashcode to simulate running on that server, as described in Testing a Widget or a Web Application (page 74).
There are ways to configure your web server and alter your web application to make it possible to fetch information from other websites, but these techniques are beyond the scope of this document. Contact the administrator of your web server for advice.
80
In addition to the core tasks of designing, coding, and testing a widget, Dashcode offers additional, advanced features that help you develop a widget that fits your users needs. This chapter covers localization techniques and how to include a plug-in written in Objective-C.
Localization
You supply localized strings for your widget in the Localization section of the widget attributes pane. To show the widget attributes pane, click Widget Attributes in the navigator. To localize your widget for other languages, click the plus (+) button and choose the language. Next to the language name in the first table, you provide a localized name for your widget. This name is used for your widget in the Finder and in the widget bar in Dashboard. The table on the right shows all the strings used in your widget. In this table, you double-click a term in the Value column and provide localized versions of your widgets strings. You add key-value combinations for localization by clicking the plus button, providing a unique key name, and entering the localized version of the string next to its key. When you add a language for localization, a language project folder is added to the widget. In addition to the strings, you can place any localized resources, such as style sheets or images, in a language project folder. To show the language project folder, choose View > Files and look for the folders that end with the .lproj extension. For more information on widget localization, read Localizing Widgets in Dashboard Programming Topics . To make it easy to test your widgets localization, choose View > Customize Toolbar. In the dialog, drag the Language pop-up menu to the project windows toolbar, then click Done. Now you can choose a language from the Language pop-up menu to see your widget in that language. If you click Run in the toolbar, your widget runs in the selected language.
81
Widget Plug-ins
Dashcode offers a place to associate a widget plug-in with your widget. If youve built a custom widget plug-in with Xcode and want to include it with your widget, select Widget Attributes from the navigator and, in the Widget Plugin section, click the Choose button and select a built widget plug-in. For more information about widget plug-ins, read Creating a Widget Plug-in in Dashboard Programming Topics .
82
Dashcode Templates
Apple provides a number of templates with Dashcode. Read this appendix to learn more about the features of each of the Dashcode templates.
Widget Templates
All widget templates allow you to set values that identify the widget in the widget attributes pane. To learn about these, see Providing Widget Attributes (page 47). Some widget templates include template-specific attributes you can set in the Properties section of widget attributes; these are described below.
83
Display Select whether the separator colons between the units of time flash and whether leading zero characters for each single-digit unit of time are shown.
84
Display Select whether date and time and whether a new content badge is shown with articles.
85
86
87
88
Show Articles Adjust how many articles to display in your web application, within what time period the articles originate, and how many top stories to display. You can also specify the feed URL in the URL field of the data model view for the feed data source. See Viewing a Projects Data Sources and Bindings (page 62) to learn how to reveal this view.
89
Dashcode Parts
Dashcode includes a number of unique elements that you use on your widgets or web applications interface to display information. Some of these elements, called Dashcode parts, can be modified programmatically. For those that can be modified programmatically, this appendix describes some of the methods you can use to do so. To look at the code that implements these parts, choose the Files view in the navigator and select the appropriate file. Note In Dashcode version 3.0 and later, you can often avoid making programmatic changes to modify a part by using data sources and bindings instead. See Adding a Data Source (page 64) and Creating Bindings (page 65) for more information on how to do this.
Some parts listed in this appendix are specifically designed to work with web applications, not widgets, and are described as such. After you add a part to the canvas, you can change its attributes using the Attributes inspector, create bindings to it using the Bindings inspector, and assign to it event handlers using the Behaviors inspector. For more information about the inspector window, read Changing an Elements Properties (page 53).
Activity Indicator
The Activity Indicator part is designed for use in a web application. An activity indicator shows the user that a task or process is progressing, but does not indicate when it will finish. The Activity Indicator part includes JavaScript code that starts and stops the spinning action. You can use the startAnimation and stopAnimation methods to coordinate the spinning of an activity indicator with the progress of a task or process.
Back Button
The Back button part is designed for use in a mobile Safari web application. In a mobile Safari web application that displays multiple levels of information, a back button gives users a convenient way to retrace their steps within the application. This allows an application to present its own navigational hierarchy within a single URL.
90
The Back button part is automatically included in the code for a mobile Safari project based on the Browser template. It is set up to appear on all levels except the first.
Box
The Box part is an area that is optionally wrapped with scroll bars, meant for showing content larger than a widgets or web applications interface. You can customize a boxs appearance using the Attributes inspector. Options you can set include whether the box automatically hides when its contents fit in its bounds and the dimensions of its bounds and margins. To change the contents of a box, use the content property from the boxs object, as shown here:
var content = document.getElementById("box").object.content; content.innerText = someText;
Once you obtain the boxs content property, you have access to the <div> element that is inside the box. From there, you can use the innerText or innerHTML properties to change the boxs contents.
Browser
The Browser part is designed for use in a web application. A browser provides an area for grouping elements and browsing back and forth. When you select the Browser web application template, a Browser part is included automatically. The Browser part includes JavaScript code to perform some standard actions. In particular, a browser supplies a method you can use to reveal the next level in a hierarchy of information. Typically, you call the goForward method in the controller code for a list part, assigning it to handle the onclick event associated with a list row. The Browser part handles the analogous go back functionality automatically.
Canvas
The Canvas part is a custom drawing region you can add to your widget. Using the Canvas in WebKit DOM Programming Topics discusses how to draw on a canvas using JavaScript.
91
Call Button
The Call button part is designed for use in a web application. A call button gives users a convenient way to initiate a phone call. In the Attributes inspector, you can specify a default phone number to dial when users tap the button. The Call button part includes JavaScript code to perform some standard actions, such as methods to get and set the phone number. If the button is enabled, the default action is to initiate a phone call to the currently set phone number when the user taps it. You can use the setPhoneNumber method to allow users to change the phone number dynamically.
Column Layout
The Column Layout part is an area you can use for laying out content side by side. This part is especially useful for web applications because each column can be set to position its content absolutely or relatively. If, for example, you wanted to provide one column to display fixed-size images and another column to display variably sized descriptions about the images, you could specify the first column to use absolute positioning and the second column to use relative positioning. The Column Layout part handles much of this for you.
Edge-to-Edge List
The Edge-to-Edge List part provides a list format in which each row stretches from one side of its container to the other. An edge-to-edge list contains a customizable row template that is used to create new rows in the list. You can specify static data to display in each row, or you can set up your web application to provide data dynamically at runtime. If youre using Dashcode version 3.0 and later, you can provide data dynamically using data sources and bindings. To learn how to do this, see Adding a Data Source (page 64) and Creating Bindings (page 65). Alternatively, you can customize the lists controller code to provide data dynamically at runtime. You can set this in the Attributes inspector. The remainder of this section describes how to customize a lists controller code. An edge-to-edge list that receives data dynamically needs a controller object (a static edge-to-edge list does not need a controller object). The list controller object must implement two required data source methods: numberOfRows and prepareRow. The numberOfRows callback method returns the total number of rows in the list. The prepareRow method is called once for each row as it is being prepared and it uses the values it is passed to populate the row. Specifically, the prepareRow method requires the following three arguments:
92
rowElement. This is the enclosing element for the entire row. You can use this element to install click
rowIndex. This is the zero-based index of the row. You can use this value to find the appropriate row
templateElements. This is a dictionary that contains an entry for each element in the template row that
has an ID. Each key in the dictionary is an ID and the associated value is the element within rowElement that corresponds to the original template elements, such as rowTitle. You can use the values associated with these elements to fill in the appropriate places in the row. An edge-to-edge list also contains the public rows property, which gives you access to each row element in the list. If the list is dynamic, you can use the rows property to view currently filled rows in your prepareRow callback method while the list is filling, but you wont be able to see all the rows until the list is completely filled. For both static and dynamic lists, the rows property is most useful for getting access to specific rows after the list is filled. If your edge-to-edge list receives data dynamically, be sure to call the reloadData function to force the list to reload and display the updated content. (Note that reloadData is called automatically when the list part is initialized.) To do this, add this line of code to your list controller:
document.getElementById("myList").object.reloadData();
Forward Button
The Forward button part is designed for use in web applications. A forward button gives users a convenient way to move forward through the multiple levels of a web application.
Gauge
The Gauge part is a dial with a pointer that indicates a value in a range of values. You can edit a gauges appearance and range of values using the Attributes inspector. If youre using a gauge as a control, select the Track Mouse Down option in the Attributes inspector and supply your own handler function for the onchange event in the Behaviors inspector. Your handler is called whenever the gauges value changes. If youre using a gauge to graphically represent data, you need to update its value using JavaScript. Use the setValue method to update a gauges value, as shown here:
document.getElementById("gauge").object.setValue(50);
93
Note that the value provided to setValue should lie within the range specified in the Attributes inspector for the gauge.
Grid
The Grid part formats data in a grid of cells. You can edit a grids appearance, and specify whether it receives data statically or dynamically, in the Attributes inspector.
Image
The Image part defines an area that receives an image at runtime (or, you can provide a static image resource by specifying the source location in the Attributes inspector). You can adjust the style and effects applied to the image in the Fill & Stroke inspector.
Indicator
The Indicator part is a light that changes color at different values. You can edit an indicators appearance and range of values using the Attributes inspector. When using an indicator, you need to update its value using JavaScript, as shown here:
document.getElementById("indicator").object.setValue(10);
Note that the value provided to setValue should lie within the range specified in the Attributes inspector for the indicator.
Level Indicators
The Horizontal and Vertical Level Indicator parts are linear indicators that show a value in a range of values. You can edit a level indicators appearance and range of values using the Attributes inspector. If youre using a level indicator as a control, select the Track Mouse Down option in the Attributes inspector and supply your own handler function for the onchange event in the Behaviors inspector. Your handler is called whenever the level indicators value changes.
94
If youre using a level indicator to graphically represent data, you need to update its value using JavaScript. Use the setValue method to update a level indicators value, as shown here:
document.getElementById("horizontalLevelIndicator").object.setValue(10)
Note that the value provided to setValue should lie within the range specified in the Attributes inspector for the level indicator.
Mail Button
The Mail button part is designed for use in a web application. A mail button gives users a convenient way to initiate an email message. In the Attributes inspector, you can specify a default recipient (email address) and subject to use when users tap the button. The Mail button part includes JavaScript code to perform some standard actions, such as methods to get and set the email address and to get and set the subject. If the button is enabled, the default action is to open a message composing view, with the To and Subject fields filled in with the currently set address and subject. You can use the setEmailAddress and setSubject methods to allow users to change the email address and subject dynamically.
Map Button
The Map button part is designed for use in a web application. A map button gives users a convenient way to view a map for a location. In the Attributes inspector, you can specify a default location to display when users tap the button. The Map button part includes JavaScript code to perform some standard actions, such as methods to get and set the address to display. If the button is enabled, the default action is to display a map for the currently set location. You can use the setAddress method to allow users to change the map location dynamically.
Quartz Composer
The Quartz Composer part is an area that contains a Quartz Composer composition. To manipulate a composition while your widget runs, use the Quartz Composer WebKit plug-ins JavaScript API. You can learn more about the Quartz Composer WebKit plug-ins JavaScript API by reading Quartz Composer WebKit Plug-in JavaScript Reference .
95
QuickTime
Note The QuickTime part is deprecated in Dashcode 3.0. It is still supported in existing projects, but it is not available in the Library. See Video (page 100) for information about a similar part you can use instead.
The QuickTime part is an area used for playback of QuickTime media. Use the QuickTime JavaScript methods to control the playback of the movie or change its properties. To learn more about the QuickTime plug-ins JavaScript methods, read JavaScript Scripting Guide for QuickTime .
Rounded-Rectangle List
The Rounded-Rectangle List part provides a list in which a group of rows is inset from the edges of its container and is bordered by a rounded rectangle. A rounded-rectangle list part contains a customizable row template you can use to create new rows in the list. You can specify static data to display in each row, or you can set up your web application to provide data dynamically at runtime. If youre using Dashcode version 3.0 and later, you can provide data dynamically using data sources and bindings. To learn how to do this, see Adding a Data Source (page 64) and Creating Bindings (page 65). Alternatively, you can customize the lists controller code to provide data dynamically at runtime. You can set this in the Attributes inspector. The remainder of this section describes how to customize a lists controller code. A rounded-rectangle list that receives data dynamically needs a controller object (a static rounded-rectangle list does not need a controller object). The list controller object must implement two required data source methods: numberOfRows and prepareRow. The numberOfRows callback method returns the total number of rows in the list. The prepareRow method is called once for each row as it is being prepared and it uses the values it is passed to populate the row. These values are passed to the prepareRow method in the following three arguments:
rowElement. This is the enclosing element for the entire row. You can use this element to install click
rowIndex. This is the zero-based index of the row. You can use this value to find the appropriate row
96
templateElements. This is a dictionary that contains an entry for each element in the template row that
has an ID. Each key in the dictionary is an ID and the associated value is the element within rowElement that corresponds to the original template elements, such as rowTitle. You can use the values associated with these elements to fill in the appropriate places in the row. A rounded-rectangle list also contains the public rows property, which gives you access to each row element in the list. If the list is dynamic, you can use the rows property to view currently filled rows in your prepareRow callback method while the list is filling, but you wont be able to see all the rows until the list is completely filled. For both static and dynamic lists, the rows property is most useful for getting access to specific rows after the list is filled. If your rounded-rectangle list receives data dynamically, be sure to call the reloadData function to force the list to reload and display the updated content. (Note that reloadData is called automatically when the list part is initialized.) To do this, add this line of code to your list controller:
document.getElementById("myList").object.reloadData();
Split Layout
The Split Layout part is designed for use in Safari web applications. A split layout is an area that contains two resizable views that are separated by a splitter. You can use the Attributes inspector to adjust the orientation of the split layout and to determine which of the two resizable views is flexible (that is, can be completely hidden when the window is resized).
Stack Layout
The Stack Layout part is designed for use in web applications. A stack layout is an area that contains views that can be swapped. You can use the Attributes inspector to add and remove views in the stack layout, and you can specify transition styles to be used while swapping. For example, you can change the transition between views from a push (in which the new view pushes the old view from the side) to a fade (in which the new view fades in over the top of the old view).
97
Note Although you can adjust aspects such as color, background, or text attributes, its not recommended to change the layout or margins of the stack layouts built-in views. If you need margins, add a box part to the view and change its margins.
getCurrentView. This method returns the currently active view. getAllViews. This method returns a JavaScript array of views in the stack layout. You might want to use
newView. The new view to display. isReverse. A Boolean value that specifies whether the transition should be performed in reverse
makeTopVisible. A Boolean value that specifies whether the new view should be scrolled to the
top. The setCurrentView method sets the current view to the passed-in view and sets the transition and scroll position appropriately.
a transition parameter after the newView parameter that allows you to specify a transition. (See Stack Layout Transitions for more information about transition objects.)
The parameters of the Transition function specify the type of transition, the length of time the transition takes, and the acceleration curve of the transition. Note that you can also set these properties in the inspector after a transition object has been created. The available transition types are:
98
Transition.NONE_TYPE. The new view simply appears in place of the old view. Transition.PUSH_TYPE. A two-dimensional transition in which the new view pushes the old view off
Transition.DISSOLVE_TYPE. A two-dimensional transition in which the old view dissolves into the
new view.
Transition.SLIDE_TYPE. A two-dimensional transition in which the new view slides in over the old
Transition.FADE_TYPE. A two-dimensional transition in which the new view fades in over the old view. Transition.FLIP_TYPE. A three-dimensional transition in which the old view flips over to reveal the
new view.
Transition.CUBE_TYPE. A three-dimensional transition in which the old view and new view appear as
if they are adjacent faces of a cube, which rotates to reveal the new view.
Transition.SWAP_TYPE. A three-dimensional transition in which both views move away from each
other horizontally and then swap positions vertically, leaving the new view on top.
Transition.REVOLVE_TYPE. A three-dimensional transition in which the old view and the new view
share an axis on one edge, about which the old view revolves out as the new view revolves in. The duration parameter should contain the number of seconds the transition should take, from start to finish. Finally, for the timing parameter, you can specify a timing function that controls the speed and acceleration of the transition (the timing functions are defined in the WebKit CSS animation specification). The available transition timing functions are:
The timing functions determine the acceleration curve of the transition. A linear curve means constant speed (that is, no acceleration), and ease means gaining or losing speed gradually. For example, the Transition.EASE_IN_TIMING function means that the transition starts slow and gradually gets faster, whereas the Transition.EASE_OUT_TIMING function means that the transition gradually slows down near the end. You can also specify a direction for the Transition.PUSH_TYPE and Transition.SLIDE_TYPE transitions. The available directions are:
99
Finally, you specify a direction for the four three-dimensional transitions. The available directions for these transitions are:
Transition.RIGHT_TO_LEFT_DIRECTION Transition.LEFT_TO_RIGHT_DIRECTION
The transition object includes the perform method that performs the transition. You pass in the following parameters to the perform method:
newView. The view that will be visible after the transition. oldView. The view that is visible now (before the transition). isReverse. A Boolean flag that specifies whether the transition should be performed in reverse. (The
push transition, for example, can be performed in reverse; the cross-fade transition is the same either way.) The perform method ensures that the passed-in views share a common parent container element, which is important because the transition is constrained by the dimensions of the parent container. In particular, the container must constrain the transitions for overflow content. Note that you can use transition objects to pass in for the transition parameter of the stack layout setCurrentViewWithTransition method. For more information about the stack layout methods, see Stack Layout Methods (page 98).
Video
The video part is an area that handles video playback and provides playback controls. The Video part uses the HTML 5 video element, which means that the video is embedded in the web-view area and does not require the QuickTime plug-in to render it. This provides greater integration with the rest of your web content and makes possible sophisticated layouts and effects.
100
Notes Updated installation location information. Made minor corrections. Updated for Dashcode 3.0. Made minor corrections. Corrected the description of web application deployment. Updated for Dashcode 2.0.1. Added a new tutorial for web applications and descriptions for new templates and parts introduced in Dashcode 2.0. New document that describes how to create Dashboard widgets with Dashcode.
2007-08-07
101
Apple Inc. 2012 Apple Inc. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, mechanical, electronic, photocopying, recording, or otherwise, without prior written permission of Apple Inc., with the following exceptions: Any person is hereby authorized to store documentation on a single computer for personal use only and to print copies of documentation for personal use provided that the documentation contains Apples copyright notice. The Apple logo is a trademark of Apple Inc. No licenses, express or implied, are granted with respect to any of the technology described in this document. Apple retains all intellectual property rights associated with the technology described in this document. This document is intended to assist application developers to develop applications only for Apple-labeled computers. Apple Inc. 1 Infinite Loop Cupertino, CA 95014 408-996-1010 MobileMe is a service mark of Apple Inc. Apple, the Apple logo, Dashcode, Finder, iCal, iPhone, iPhoto, iPod, iPod touch, Mac, Mac OS, Monaco, Objective-C, OS X, Quartz, QuickTime, Safari, and Xcode are trademarks of Apple Inc., registered in the United States and other countries. Adobe, Acrobat, and PostScript are trademarks or registered trademarks of Adobe Systems Incorporated in the U.S. and/or other countries. Helvetica and Times are registered trademarks of Heidelberger Druckmaschinen AG, available from Linotype Library GmbH. IOS is a trademark or registered trademark of Cisco in the U.S. and other countries and is used under license. Java is a registered trademark of Oracle and/or its affiliates.
Even though Apple has reviewed this document, APPLE MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS OR IMPLIED, WITH RESPECT TO THIS DOCUMENT, ITS QUALITY, ACCURACY, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. AS A RESULT, THIS DOCUMENT IS PROVIDED AS IS, AND YOU, THE READER, ARE ASSUMING THE ENTIRE RISK AS TO ITS QUALITY AND ACCURACY. IN NO EVENT WILL APPLE BE LIABLE FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES RESULTING FROM ANY DEFECT OR INACCURACY IN THIS DOCUMENT, even if advised of the possibility of such damages. THE WARRANTY AND REMEDIES SET FORTH ABOVE ARE EXCLUSIVE AND IN LIEU OF ALL OTHERS, ORAL OR WRITTEN, EXPRESS OR IMPLIED. No Apple dealer, agent, or employee is authorized to make any modification, extension, or addition to this warranty.
Some states do not allow the exclusion or limitation of implied warranties or liability for incidental or consequential damages, so the above limitation or exclusion may not apply to you. This warranty gives you specific legal rights, and you may also have other rights which vary from state to state.