|
1 |
|
2 <!DOCTYPE html |
|
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="mobileconcept"/><meta name="DC.Title" content="onSelect"/><meta name="DC.Relation" scheme="URI" content="GUID-BE6DC1F8-A847-49B5-A3BF-318D0D1E9D8A"/><meta name="DC.Relation" scheme="URI" content="GUID-7C69DDA4-16F1-4A8F-BDB2-4CB0015B4E81"/><meta name="DC.Relation" scheme="URI" content="GUID-111DE423-9C84-4E4B-A45E-15081FE2A30D"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-A022ED1B-E618-4C44-A437-78393900599C"/><title>onSelect </title><script type="text/javascript"> |
|
5 function initPage() {} |
|
6 </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-A022ED1B-E618-4C44-A437-78393900599C">onSelect</h1><div> |
|
7 <p><strong>Description:</strong></p> |
|
8 <p>The <code>onSelect</code> property of the <a href="GUID-111DE423-9C84-4E4B-A45E-15081FE2A30D.html#GUID-111DE423-9C84-4E4B-A45E-15081FE2A30D"><code>MenuItem</code></a> object is an event handler for the event of when the menu item is selected. |
|
9 In other words, when the end user opens the options menu and selects a menu |
|
10 item either from the top-level menu list or from a submenu list, the system |
|
11 will fire an event and a widget can catch the event by providing a callback |
|
12 function.</p> |
|
13 <p>The callback function is passed with an argument, which is an integer |
|
14 identifier identifying the menu item that was just selected. </p> |
|
15 <p>It is possible to assign an individual callback function for each menu |
|
16 item so that the <code>id</code> argument can be ignored.</p> |
|
17 <p><strong>Syntax:</strong></p> |
|
18 <pre class="codeblock" id="GUID-0A790E5F-77BF-437D-A0BF-2D859FB63D32">MenuItem.onSelect = function(Integer id) { }</pre> |
|
19 <p>or</p> |
|
20 <pre class="codeblock" id="GUID-34A713EA-E992-4944-8A88-08FD4F1DE666">MenuItem.onSelect = onMenuItemSelected;</pre> |
|
21 <pre class="codeblock" id="GUID-2A4AEE42-F882-4CE9-9EA1-8261F56BA332">function onMenuItemSelected(id) |
|
22 { |
|
23 // ... |
|
24 }</pre> |
|
25 <p><strong>Remarks:</strong></p> |
|
26 <p>Submenu item's callback function must be assigned to the <code>onSelect</code> property |
|
27 after the parent menu item is appended to the main menu pane.</p> |
|
28 <p>For more general information on constructing an options menu, see <a href="GUID-94946735-D23B-49C6-BB65-8BE31737AE42.html#GUID-94946735-D23B-49C6-BB65-8BE31737AE42">Using softkeys</a>.</p> |
|
29 <p><strong>Example code:</strong></p> |
|
30 <p><em>Creating a menu:</em></p> |
|
31 <pre class="codeblock" id="GUID-EAF0A325-47DD-4AA7-81FA-D26EE10DECB6">window.onload = createMenu();</pre> |
|
32 <pre class="codeblock" id="GUID-82C1CA79-4F88-4547-8A43-5960CDF26296">// function to create a menu |
|
33 function createMenu() |
|
34 { |
|
35 // Create a Menu Object |
|
36 var optionsMenu = window.menu; |
|
37 |
|
38 // Set a callback function for Menu |
|
39 optionsMenu.onShow = function() |
|
40 { |
|
41 alert('Event Trigger: optionsMenu.onShow'); |
|
42 } |
|
43 |
|
44 // Create two Menu items |
|
45 var m1 = new MenuItem('Beverages', 2001); |
|
46 var m2 = new MenuItem('Snacks', 2002); |
|
47 |
|
48 // Assign a callback function for the menu items |
|
49 m1.onSelect = menuEventHandler; |
|
50 m2.onSelect = menuEventHandler; |
|
51 |
|
52 // Append two Menu items to Menu |
|
53 optionsMenu.append(m1); |
|
54 optionsMenu.append(m2); |
|
55 |
|
56 // Create two more Menu items for Sub-Menu |
|
57 var m11 = new MenuItem('Coca Cola', 3001); |
|
58 var m12 = new MenuItem('Pepsi', 3002); |
|
59 |
|
60 // Append two Sub Menu Items to Menu 'Beverages' |
|
61 // get Menu Item reference by ID |
|
62 optionsMenu.getMenuItemById(2001).append(m11); |
|
63 |
|
64 // get Menu Item reference by Name |
|
65 optionsMenu.getMenuItemByName('Beverages').append(m12); |
|
66 |
|
67 // Assign a callback function for the submenu items |
|
68 m11.onSelect = submenuEventHandler; |
|
69 m12.onSelect = submenuEventHandler; |
|
70 }</pre> |
|
71 <p><em>Implement menu event handler:</em></p> |
|
72 <pre class="codeblock" id="GUID-646EDADD-F105-4946-A09D-8E087BD1E033">function menuEventHandler(id) |
|
73 { |
|
74 switch (id) |
|
75 { |
|
76 case 2001: |
|
77 break; |
|
78 case 2002: |
|
79 // do something |
|
80 break; |
|
81 } |
|
82 } |
|
83 </pre> |
|
84 </div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html> |