app:message
| Widget Name | appcelerator message |
| Element | <app:message> |
| Author | Jeff Haynie |
| Homepage | http://www.appcelerator.org |
| Description | message widget for generating messages (either remote or local) |
- Required Attributes (1)
- Optional Attributes (4)
- Examples (1)
- Source code
| Name | Type | Description | Default value |
|---|---|---|---|
| name | Appcelerator Message Send | The name of the message to be fired. | Not specified |
| Name | Type | Description | Default value |
|---|---|---|---|
| on | On Expression | May be used to express when the message should be fired (executed). | Not specified |
| args | JSON Object | The argument payload of the message. | Not specified |
| version | Unknown | The version attached to the message. | Not specified |
| interval | Time value | Indicates that an time interval that the message will continously be fired. | Not specified |
Back to menuExample: Simple Example
This is a simple example that uses the <app:message>.
<app:message on="l:message.trigger then execute" name="l:message.example" args="{'message':'You will enjoy financial success','answer':'haha. just kidding.'}"> </app:message> <span on="click then l:message.trigger or l:message.example then hide or l:reset.message.example then show"> <a style="text-decoration: underline">Click me to trigger your fortune</a> </span> <span on="l:reset.message.example then hide or l:message.example then show" style="display:none"> <span on="l:message.example then value[message] or l:reset.message.example then clear"></span> <span style="color:red" on="l:message.example then value[answer] after 1s or l:reset.message.example then clear"></span> <a on="click then l:reset.message.example">Reset Example</a> </span>
1 /* 2 * This file is part of Appcelerator. 3 * 4 * Copyright (C) 2006-2008 by Appcelerator, Inc. All Rights Reserved. 5 * For more information, please visit http://www.appcelerator.org 6 * 7 * Appcelerator is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 * 20 */ 21 22 23 Appcelerator.Widget.Message = 24 { 25 getName: function() 26 { 27 return 'appcelerator message'; 28 }, 29 getDescription: function() 30 { 31 return 'message widget for generating messages (either remote or local)'; 32 }, 33 getVersion: function() 34 { 35 return '1.0.2'; 36 }, 37 getSpecVersion: function() 38 { 39 return 1.0; 40 }, 41 getAuthor: function() 42 { 43 return 'Jeff Haynie'; 44 }, 45 getModuleURL: function () 46 { 47 return 'http://www.appcelerator.org'; 48 }, 49 isWidget: function () 50 { 51 return true; 52 }, 53 getWidgetName: function() 54 { 55 return 'app:message'; 56 }, 57 getActions: function() 58 { 59 return ['execute','stop']; 60 }, 61 getAttributes: function() 62 { 63 var T = Appcelerator.Types; 64 return [{ 65 name: 'on', 66 optional: true, 67 type: T.onExpr, 68 description: "May be used to express when the message should be fired (executed)." 69 }, { 70 name: 'name', 71 optional: false, 72 type: T.messageSend, 73 description: "The name of the message to be fired." 74 }, { 75 name: 'args', 76 optional: true, 77 type: T.json, 78 description: "The argument payload of the message." 79 }, { 80 name: 'version', 81 optional: true, 82 description: "The version attached to the message." 83 }, { 84 name: 'interval', 85 optional: true, 86 type: T.time, 87 description: "Indicates that an time interval that the message will continously be fired." 88 }] 89 }, 90 91 execute: function(id,parameterMap,data,scope,version) 92 { 93 Appcelerator.Widget.Message.sendMessage(parameterMap); 94 }, 95 stop: function(id,parameterMap,data,scope,version) 96 { 97 var timer = parameterMap['timer']; 98 if(timer) 99 { 100 clearInterval(timer); 101 parameterMap['timer'] = null; 102 } 103 else 104 { 105 $D('Message '+parameterMap['name']+' is not currently sending, cannot stop'); 106 } 107 }, 108 compileWidget: function(parameters) 109 { 110 Appcelerator.Widget.Message.sendMessage(parameters); 111 }, 112 buildWidget: function(element, attributes) 113 { 114 var name = attributes['name']; 115 var args = attributes['args']; 116 var version = attributes['version']; 117 var on = attributes['on']; 118 119 if (args) 120 { 121 args = String.unescapeXML(args).replace(/\n/g,'').replace(/\t/g,''); 122 } 123 124 var interval = attributes['interval']; 125 126 var parameters = {args:args, name:name, scope:element.scope, interval:interval,version:version}; 127 128 if (on) 129 { 130 return { 131 'position' : Appcelerator.Compiler.POSITION_REMOVE, 132 'parameters': parameters 133 }; 134 } 135 else 136 { 137 return { 138 'position' : Appcelerator.Compiler.POSITION_REMOVE, 139 'compile': true, 140 'parameters': parameters 141 }; 142 } 143 }, 144 /* 145 * If the widget has an interval set, begin sending polling messages, 146 * otherwise send a one-shot message. 147 */ 148 sendMessage: function(params) 149 { 150 var name = params.name; 151 var args = params.args; 152 var version = params.version; 153 var scope = params.scope; 154 var interval = params.interval; 155 var data = null; 156 157 if (args && args != 'null') 158 { 159 data = Object.evalWithinScope(args, window); 160 } 161 162 if (interval == null || !params['timer']) $MQ(name, data, scope, version); 163 if (interval != null) 164 { 165 var time = Appcelerator.Util.DateTime.timeFormat(interval); 166 167 if (time > 0 && !params['timer']) 168 { 169 params['timer'] = setInterval(function() 170 { 171 if (args && args != 'null') 172 { 173 // re-evaluate each time so you can dynamically change data each interval 174 data = Object.evalWithinScope(args, window); 175 } 176 $MQ(name, data, scope, version); 177 }, time); 178 } 179 } 180 } 181 }; 182 183 Appcelerator.Widget.register('app:message',Appcelerator.Widget.Message); 184
Chapters
- Web Expressions (Interaction)
- Web Expressions (Visual)
- Web Expression Macros
-
Widget Reference
- app:as_flexflow
- app:box
- app:button
- app:calendar
- app:chart
- app:content
- app:datacache
- app:datatable
- app:download
- app:editinplace
- app:ext_grid
- app:ext_paging_grid
- app:ext_tree
- app:field
- app:folder
- app:graphical_music_player
- app:http
- app:if
- app:imagetransition
- app:iterator
- » app:message
- app:modalbox
- app:modaldialog
- app:mp3player
- app:music_player
- app:pagination
- app:panel
- app:progressbar
- app:script
- app:search
- app:security
- app:shadowbox
- app:simple_panel
- app:statemachine
- app:stopwatch
- app:tabpanel
- app:template
- app:tooltip
- app:upload
- app:validation
- app:widget
- app:yui_map
- CSS Helper Classes
- Advanced Configuration
- Debugging
- Forms
- Localization
- Interpolation
- Javascript Variables
- Javascript Functions
- Service Broker