app:script
| Widget Name | appcelerator script |
| Element | <app:script> |
| Author | Jeff Haynie |
| Homepage | http://www.appcelerator.org |
| Description | script widget |
- Required Attributes (0)
- Optional Attributes (1)
- Examples (2)
- Source code
| Name | Type | Description | Default value |
|---|---|---|---|
| There are no required attributes | |||
| Name | Type | Description | Default value |
|---|---|---|---|
| on | On Expression | May be used to execute the script's content. | Not specified |
Back to menuExample: Simple Example
var date = new Date();
$MQ('l:show.current.datetime',{'datetime':date});
This is a simple example that uses the <app:script>.
Current Date Time =
Reset Example
<button on="click then l:get.current.datetime"> Get time and date </button> <div style="border:1px solid #ccc;background-color:#f6f6f6;padding:10px;margin-top:10px;display:none" on="l:show.current.datetime then show and effect[Highlight] or l:reset.script.example then hide"> <span style="color:#000"> Current Date Time = <span on="l:show.current.datetime then value[datetime]"></span> <a on="click then l:reset.script.example">Reset Example</a> </span> </div> <app:script on="l:get.current.datetime then execute"> var date = new Date(); $MQ('l:show.current.datetime',{'datetime':date}); </app:script>
Back to menuExample: Accessing Properties inside an app
alert(this.data.text + ', ' + this.data.name);
You can access the properties of a data payload inside an app:script:
<button on="click then l:hey.there[text='Hi There',name=Steve]">Click Me!</button> <app:script on="l:hey.there then execute"> alert(this.data.text + ', ' + this.data.name); </app:script>
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.Script = 24 { 25 getName: function() 26 { 27 return 'appcelerator script'; 28 }, 29 getDescription: function() 30 { 31 return 'script widget'; 32 }, 33 getVersion: function() 34 { 35 return 1.0; 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:script'; 56 }, 57 getActions: function() 58 { 59 return ['execute']; 60 }, 61 getAttributes: function() 62 { 63 return [{ 64 name: 'on', 65 optional: true, 66 type: Appcelerator.Types.onExpr, 67 description: "May be used to execute the script's content." 68 }]; 69 }, 70 execute: function(id,parameterMap,data,scope,version) 71 { 72 var code = parameterMap['code']; 73 var script = code.toFunction(true); 74 if (script == true) return; 75 script.call({data:data||{},scope:scope,version:version}); 76 }, 77 compileWidget: function(params) 78 { 79 eval(params['code']); 80 }, 81 buildWidget: function(element,parameters) 82 { 83 var code = Appcelerator.Compiler.getHtml(element); 84 code = code.replace(/\/\*.*\*\//g,''); 85 86 if (code && code.trim().length > 0) 87 { 88 parameters['code'] = String.unescapeXML(code); 89 90 if (parameters['on']) 91 { 92 return { 93 'position' : Appcelerator.Compiler.POSITION_REMOVE 94 }; 95 } 96 else 97 { 98 return { 99 'position' : Appcelerator.Compiler.POSITION_REMOVE, 100 'compile' : true 101 }; 102 } 103 } 104 105 return { 106 'position' : Appcelerator.Compiler.POSITION_REMOVE 107 }; 108 } 109 }; 110 111 Appcelerator.Widget.register('app:script',Appcelerator.Widget.Script); 112
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