Sciter帮助文档笔记2
Script 语法之Decorators:
主要是简化函数的调用关系,看起来更明确:
@key('S') @CTRL @SHIFT: { stdout.println("Ctrl+Shift+S"); return true; } // Ctrl+Shift+S
其中: @key(‘S’)、@CTRL、@SHIFT分别是单独的函数,最后在:之后跟着一个匿名函数。它所表示的函数调用关系为:@key('S') (@CTRL ( @SHIFT ( xxx ) ) ); 它最需要注意的问题在于函数的编写:
function@CTRL(func) { return function(evt) { if( evt.ctrlKey == true ) returnfunc.call(this,evt); } }
function @key(func,keyCode = undefined )
{
function t(evt)
{
var r = false;
if( evt.type == Event.KEY_DOWN &&(keyCode === undefined || (keyCode == evt.keyCode)) )
r = func.call(this,evt);
if(t.next) return t.next.call(this,evt) ||r;
returnr;
}
// note 'this' in decorators is a currentnamespace - class or global (ns)
var principal = this instanceof Behavior ?this : self;
t.next = principal.onKey;
principal.onKey = t;
}
DOM
Script Dom之Sciter:
常量:
VERSION // 版本,integer. High word is versionnumber, low word is a sub-version number
REVISION// 版次, integer. High word is arevision number and low word is a sequential build number.
LICENSEE // string, name oflicensee organization/person of the Sciter.
方法:
1、this // N/A, non constructible for a while.
2、userName () returns:string // 登陆这台电脑的用户名
3、machineName ([full]) returns:string // true, 显示含有网络路径的全称
4、home ([rel:string]) returns:string // 运行Sciter的路径,参数会被附加到路径之后
5、launch ( filename: string )returns: true/false // 启动外部程序
Script Dom之View:
view.state 的值 WINDOW_MINIMIZED WINDOW_MAXIMIZED WINDOW_HIDDEN
属性:
1、root r - Element // 当前加载到视图的文档的root
2、state r/w - state of the view's window // 顶层窗口仅有
3、focus r/w - Element // 当前获取输入焦点的元素,如果想让其他元素获取焦点,可以view.focus = el;
4、eventsRoot r/w - Element // 用于modal document loops
例子:view.eventsRoot =dlg; while (dlg.isVisible)view.doEvent();
dlg.style#display = "none"; view.eventsRoot = null;
5、sip r/w - show/hide SIP button of dialog // 默认hide , (Windows MobileProfessional only!)
6、sipUp r/w - show/hide SIP of dialog (keyboard). // 默认hidden. (Windows MobileProfessional only!)
7、fullscreen r/w - window/dialog fullscreen // 菜单需要设置 view.menu.visible. (WindowsMobile Professional only!)
8、menu r - returns an object of type Menu of theview. // (Windows Mobile Professionalonly!)
Script Dom之Element:
常量:(通过get/setState()读写)
STATE_LINK
STATE_HOVER
STATE_ACTIVE
STATE_FOCUS
STATE_VISITED
STATE_CURRENT
STATE_CHECKED
STATE_DISABLED
STATE_READONLY
STATE_EXPANDED
STATE_COLLAPSED
STATE_INCOMPLETE
STATE_ANIMATING
STATE_FOCUSABLE
STATE_ANCHOR
STATE_POPUP
STATE_OWNS_POPUP
STATE_EMPTY
STATE_BUSY
属性:
1、length r - integer // Read-only 子元素的个数
2、[index] rw - Element // Read-write index accessor. 从0开始
3、root r - Element // Read-only. 所属节DOM元素的root
4、parent r - Element // Read-only. 父节点
5、index r - Integer // 当前元素在父节点的序号
6、tag r - String // Read-only. 元素的名称
7、id r - String // Read-only.,id
8、next r - Element // 相邻的下一个节点
9、prior r - Element // 相邻的上一个节点
10、first r - Element // 第一个子节点
11、last r - Element // 最后一个子节点
12、attributes c - Attributes // 元素的属性
13、@ c - short form to access Attributes // 一种获取属性的简写方式
例子:
this.@["selected"] = true or this.@#selected = true
等价于
this.attributes["selected"] =true
14、style c - Style // CSS属性等
15、state c - States // 元素的状态,可参考开头的常量值
16、x c - Extenders // interface to collection of native behaviors attached to the element:
element.x.length - reports number ofnative behaviors attached to the element;
element.x[n] - reports name of n-thnative behavior attached to the element.
element.x.funcname(....) - call ofmethods implemented by native behaviors.
// Main purpose of this interfaceis to provide function call mechanism that is using separate namespace.
17、text rw - String // 元素的内部文本内容
18、html rw - String // (inner HTML) html source 不包含头尾的标签部分
19、outerHtml rw - String, (outer HTML) html source 包含头尾的标签部分
20、value rw - String by default // 如果元素有其他动作关联,可能返回 integer, boolean, array等,例如
21、prototype rw - Either Instance of Behavior or Elementclass object // 可以通过CSS设置
22、isVisible r - true if element and all its containersare in visible state // 所有的都可视返回true
23、isEnabled r - true if element and all its containersare not in :disabled state ( setState(Element.STATE_DISABLED)).
24、ns r - Object, namespace object of the element// 所在的命名空间
25、rows r - integer // dom元素中的行数,如果是table则返回rows,如果是CSS布局则反应flow CSS property.
26、columns r - integer // dom中的列数,同rows
27、contentModel r - symbol // Model as in HTML5 spec
#block-inside - the element can containblock elements (e.g. #inline-inside - the element cancontain inline elements (e.g. ). #transparent - the content model of atransparent element is derived from the content model of its parent element(e.g. ). #text-only - the element can containonly plain text (e.g. #table, #table-section and #table-row - 28、selection r - null | Selection // 针对有behavior (htmlarea orrichtext) 的元素 29、firstCaretPos r - null | bookmark // 第一个插入符的位置 30、lastCaretPos r - null | bookmark // 最后一个插入符的位置 31、paintBackground w - null | function(gfx), assigns backgroundlayer painting function // 该函数通过Graphics object 绘制层. 如果函数返回true则会替代默认绘制过程。 32、paintContent w - null | function(gfx), assigns contentlayer painting function. // 同上 33、paintForeground w - null | function(gfx), assigns foregroundlayer painting function. // 同上 34、paintOutline w - null | function(gfx), assigns outlinelayer painting function. // 同上 枚举: for ... in for(var node in element) { /* loop body */ } 方法: 1、this (tagname[, text]) // 构造函数,var el = newElement("option"); // or varel = new Element(#option); 2、create (object) : Element //var para = Element.create { p, "paragraph text" }; // or if text is avariable: var para = Element.create {p, [paragraphText] }; 3、clear () : undefined //移除所有的子节点 4、toString () : string // outer html 包涵外部标签 5、clone () :Element // 深度复制一个元素,但返回的元素不在dom之中 6、select (CSSselector:string [,argument1 [, argument2, ... ]]) : Element // 返回第一个匹配的元素, %d, %s 代表后面的参数列表. 规则同 Stream.printf . // 例子:查找 则可以 var inp =self.select("input[type='text']"); 7、$ ( CSSselector ) : Element //select的简化版, // 如: var n = 3; var li3 = self.$( ul > li:nth-child({n})); //得到第三个元素 8、select (func , CSSselector:string [, argument1 [, argument2, ... ]]) returns: integer // 通过选择器, 枚举, func返回true则停止 // 如打印所有input的name function printel(el) { stdout.println(el.attributes["name"] ); } document.select(printel,"input"); 9、selectAll (CSSselector: string[, argument1 [, argument2, ... ]]) returns: Array// 返回所有匹配的元素, %d, %s 代表后面的参数列表. 规则同 Stream.printf . 10、$$ ( CSSselector ) returns:Array // selectAll的简版形式 11、selectParent (CSSselector:string [, argument1 [, argument2, ... ]]) returns: Element// 返回第一个 12、$p ( CSSselector ) returns:Element // selectParent的简版 13、selectParent (func ,CSSselector: string [, argument1 [, argument2, ... ]]) returns: integer// 枚举形式的selectParent 14、$$p ( CSSselector ) returns:Array of Elements // 这个针对parent和child 15、match ( CSSselector: string [,argument1 [, argument2, ... ]]) returns: true | false // 检查是否符合 16、$is ( CSSselector ) returns:true | false // match的简版 17、belongsTo ( parent: Element [,useUITree: true | false ] ) : true | false // 检查是否是某节点的子节点 18、find (x, y) returns:Element. // x,y是相对于元素的原点,如果找不到返回元素自身 19、update ([deep]) returns:undefined // 重新计算和绘制 20、update (stateUpdateFunction)returns: undefined 21、refresh ( [x, y, width,height] ) returns: true|false // 重绘制整体或部分内容 22、animate ( nextStep: function[,duration: integer] ) : undefined // 启动动画,如果function返回int的事件间隔则继续, 0或其他的都停止, 每次的返回值都是下次动作的时间间隔 23、box ( part [, edge [,relativeTo ]] ) returns: integer, device pixels // 根据盒子模型得到的坐标和大小 例子: var (x1,y1,x2,y2) =this.box(#rect, #inner, #view); var(x,y,w,h) = this.box(#rectw, #inner, #view); 所有可用数据: #margin - margin box edge, #border - border box edge, #padding - padding box edge, #inner, default value - inner boxedge, #content - content box edge.Content box here is outline of the content of the element and this is notВ an inner box ofthe element. E.g. content box can be bigger than inner box if the element hasoverflow attribute set. #client - client area, that is#inner box minus areas taken by [optional] scrollbars. #icon -area covered by element's icon. Iconhere is element's foreground image with foreground-repeat: no-repeat. Ifelement has no such image the function returns #width and #height equals tozero. relativeTo, one of: #screen - returns coordinaterelative to the origin of the screen, #root - returns coordinate relativeto the origin of root element (view), #parent - returns coordinaterelative to the origin of its parent element. Note: parent scroll positionrelative. #content - returns coordinate ofthe element in content of its parent. Note: is not dependent on parent scrollposition. #container - returns coordinate ofthe element relative to layout parent. Layout parent can be different from DOMparent element. E.g. position:absolute elements may have positioning layoutparent different from DOM parent. #self, default value - allcoordinates are relative to the origin of inner box of the element. #view - returns coordinate relativeto the origin of the sciter window (view object). or if relativeTo equals one of the following values: #margin - margin box edge, #border - border box edge, #padding - padding box edge, #inner - inner box edge 24、intrinsicWidthMin ( ) :integer, device pixels 25、intrinsicWidthMax ( ) :integer, device pixels 26、intrinsicHeight ( forWidth:integer ) : integer, device pixels 27、toPixels ( length : length |string | symbol [, #width | #height ] ) : integer, device pixels 28、scroll (part) returns:integer, device pixels 可以使用的定量: #left - left position of the viewrelative to content origin, #top - top position, #right - offset of right edge of theview from right edge ofВ the content box, #bottom - offset of bottom edge of theview from bottom edge of the content box, #width - width of scrollable area, #height - height of scrollable area. 29、scrollTo ( x:int, y:int [,smooth:bool] ) : void // overflow: hidden-scroll, scroll or auto to be able toscroll its content. 30、scrollToView ( [toTop:bool,smooth: bool = true ] ) 31、insert ( element | html |object [,index = Integer.MAX]) returns: true | false. 32、append ( element | html | object) returns: true | false. 33、prepend ( element | html |object ) returns: true | false. 34、content ( element [, element2[, element3, ... ]] ) returns: true | false. 35、$content ( .. inline html .. ): Element // replaced by the inline html. 如: var el = ... , num = ...; el.$content(This is item number { num }); 36、$append ( .. html .. ) :Element // adds content defined by theinline html to the end of the list of children of the element. 37、$prepend ( .. html .. ) :Element 38、$after ( .. html .. ) :Element 39、$before ( .. html .. ) :Element 40、$replace ( .. html .. ) :Element 41、detach ( ) : Element 42、remove ( ) : Element 43、load ( url: string ) returns:true/false 44、load ( stream: Stream )returns: true/false 45、load ( html: string,url:string ) returns: true/false 46、loadImage ( url: string [,callback: function ) returns: Image | null 47、request ( callback: function |integer, #get | #post | #post-data | #put-data | #post-json | #put-json |#delete, url: string [, params: object [, headers: object] ] ) : Object |Stream | Bytes | Error 请求http data GET/POST request tothe server/page (url), a.k.a. JSON-RPC calls. #get, #post, #post-data #json areliteral symbols - type of http request to be sent: #get - sends plain HTTP GET request,url-encoded params (if any) are appended to the url to form the request; #post - sends HTTP POST requestwith params serialized as Content-Type:application/x-www-form-urlencoded;charset=utf-8; #post-data - sends HTTP POST requestwith params serialized as Content-Type: multipart/form-data; boundary= ...; #put-data - sends HTTP PUT requestwith params serialized as Content-Type: multipart/form-data; boundary= ...; #post-json - sends HTTP POSTrequest with params serialized as JSON,В Content-Type: application/json;charset=utf-8; #put-json - sends HTTP PUT requestwith params serialized as JSON, Content-Type: application/json;charset=utf-8; #delete - - sends HTTP DELETErequest. url is a string - url of the page(location) on the server handling HTTP requests. params is an object, its properties areserving role of parameters of HTTP request. headers is an object - a map ofadditional header key/value pairs to send along with the request. returns: true|false for asynchronousrequests or pair of (status:integer,data:any) - result of the request (see databelow) and HTTP status code (e.g. 200 - OK, 404 - resource was not found on theserver). 回调函数: function dataArrivedCallback( data: any,status: integer ); data的内容: instanceof Error object, in case ofdata response parsing problems; stream, if data returned by the serveris of textual type (text/plain, text/html, text/xml, etc.) instanceof Object, Array, etc. ifresponse has content type text/javascript, text/ecmascript, text/tiscript orapplication/json and was successfully parsed into data object. Bytes, if data returned by the serveris of binary type (image/*, etc.). Bytes.type in this case will contain astring - mime-type of the data reported by the server. status code is an integer - HTTP statuscode (e.g. 200 - OK, 404 - resource was not found on the server) or if code isgreater than 12000 it is a WinInet error code, see:http://support.microsoft.com/kb/193625. 48、getState ( [stateFlags:int] ):int 49、setState ( stateFlags:int):void 50、clearState ( stateFlags:int ):void 51、capture ( onOff: true|false ):void // 捕获鼠标 52、popup ( el: Element,placement: int ) :void // 弹出xxx 参数的含义: 2 - popup element below this element(anchor); 8 - popup element above this element; 4 - popup element on the left side ofthis element; 6 - popup element on right side of thiselement; 53、popup ( el: Element, x:int,y:int ) :void 54、closePopup () :void 55、timer ( milliseconds: integer,callback: function ) // 回调函数返回true则继续timer, 否则停止, milliseconds = 0 则停止timer 56、graphics ( [ color: integer |color: color[, forceInitialization:bool = true ]] ) : Graphics 57、graphics ( #destroy ) :Graphics | null 58、swap (other: Element ) : null// positions of two elements 59、sendEvent ( eventCode:int [,reason: int [, owner: Element | null [, data:value ]]] ) : true | false | value// 遍历 parent/child 该事件可以被onControlEvent() 方法处理. 60、sendEvent ( event:string [,data:value ] ) : true | false | value 61、postEvent ( event:string [,data:value ] ) : true 62、postEvent ( eventCode:int [,reason: int [, owner: Element | null [, data:value ]]] ) : undefined 63、sendKeyEvent ( eventDef:object ) : true | false | undefined sendKeyEvent 可以是以下几种类型: { type: Event.KEY_DOWN, Event.KEY_UP,Event.KEY_CHAR; // type if key event keyCode: int; // Key or char code, e.g.'O' altKey: true or false; // optional, 'ALT'key pressed flag shiftKey: true or false; // optional,'SHIFT' key pressed flag ctrlKey: true or false; // optional,'CTRL' key pressed flag } 64、sendMouseEvent ( eventDef:object ) : true | false | undefined 65、post ( callback: function[,only_if_not_there:boolean] ) : undefined 66、url ( [ relativeUrl: string ]) : string 67、sort ( comparator: function [,fromIndex: integer [, numOfElements:integer]] ) : void 68、move ( [x: int, y: int [, w:int, h: int] [, #view | #root | #screen]] ) : void 69、textWidth ( text: string ) :int 70、textHeight ( text: string ) :int 71、subscribe ( handler: function,eventGroup : int [, eventType: int] ) : 72、unsubscribe (handler: function) or (eventGroup : int [, eventType: int]) : 73、unsubscribe (event : string [,selector: string]) : 74、rowElements (rowNo: integer) :array of Elements 75、columnElements (colNo:integer) : array of Elements 76、rowY (rowNo: integer) : (y:integer, height: integer) 77、columnX (colNo: integer) : (x:integer, width: integer) 78、transact ( action:function [, name:string]) : true | false 79、onGesture(event): true|false 80、onScroll(event) : true|false 81、attached() : void 82、onTimer() 83、onSize() 84、self.ready() 85、self.closing() // 返回false可以阻止窗口关闭 Script Dom之 Attributes: 属性:(element.attribytes访问) Length, [index] 方法: 1、name (index) returns: string // 序号从0开始 2、clear () returns: N/A 3、remove (attr) returns: N/A // 参数可以是name或index 4、exists (attr) returns: true|false // 参数可以是name或index 5、addClass (className1: string [, ... classNameN: string] ) 6、removeClass (className1: string [, ... classNameN:string ] ) 7、toggleClass (className: string [, on: boolean ] ) //on == true 则添加,false删除 8、hasClass (className: string ) : boolean // 是否有对应的类名 Script Dom之 Style: 属性:(element.style访问) [attname] string // 属性的名称,参看 list of supported names of CSS attributes. // 在TIScript中,可以通过以下方式修改: el.style["background-color"]= "red"; 等价于 el.style#background-color ="red"; // 清除属性值,可以这样设置: el.style#background-color= undefined; // 清除运行时属性,其样式决定于CSS设置 方法: 1、clear ()returns: Style // 清除所有通过 [] 和 Set() 设置的属性值 2、set (attributes: Object ) returns: Style // 设置或清除多个属性值,其调用可用如下形式: // 多个属性同时设置: el.style.set { display: "block", width: px(40), height: px(20) }; 3、rules ( )returns: Array // 按照指定形式返回规则 { type:#style-rule, selector: { type:#inline-style, text: { type:#runtime-style } - designates that the element has styles set in runtimethrough script. 4、all ( )returns: Object 5、constant ( name:string | symbol ) returns: value | array // 返回在CSS中定义的常量值 @const SINGLE: #ff007f; @const MULTY: 12px 14px; 6、dimension (width:length | int | undefined, height: length | int | undefined [, delayed: false |true] ) // 等价于下面,不同的是delayed=true时,在需要刷新时才更新,适用于频繁设置的场合 elem.style.width = ... ; elem.style.height = ... ; Script Dom之 States: 属性:(element.states访问) 1、link rw - true/false, // 如果是超链接,true 2、hover rw - true/false, // 如果是鼠标悬停状态,true 3、active rw - true/false, // 如果是选中,true 4、focus rw - true/false, // 如果是焦点,true , el.state.focus = true; 5、tabfocus r - true/false, // 如果是可以Tab选中,true , TAB/SHIFT+TAB key handling. 6、visited rw - true/false, // 访问过了 7、current rw - true/false, 8、checked rw - true/false, 9、disabled rw - true/false, 10、readonly rw - true/false, 11、expanded rw - true/false, 12、collapsed rw - true/false, 13、incomplete rw - true/false, 14、animating r - true/false, // 元素正在执行动画 15、focusable rw - true/false, // 可以处于focus状态 16、anchor rw - true/false, //元素是一个锚(第一个元素)的选择 17、synthetic rw - true/false, // 元素是合成的 18、popup rw - true/false, // 元素是一个弹出窗口,false就会关闭窗口 // el.state.popup= false; 19、ownspopup r - true/false, // el.popup(elementToPopup,pos); will cause this flag to be set for the element el. 20、empty r - true/false, // 没有子节点和文本 21、busy rw - true/false, // by calling el.request(...) ,数据没准备好 22、dragover r - true/false, // 被拖拽的元素放到了这个元素上面 23、droptarget r - true/false // 元素正在被拖拽 24、moving、copying r - true/false, // 元素或者它的副本正在被拖拽 25、dragsource r - true/false, // 元素也是其中被拖拽的对象 26、pressed rw - true/false, // 鼠标在元素上面按下了 27、isltr、isrtl r - true/false, // elementis in directional environment - itself or one of its parents has attribute dirdefined. 28、value rw - "raw" value ofthe element. // 有动作则动作名称,否则是文本内容,(参考 Element.text). 方法: get () returns: int set (flags:int) returns: undefined clear (flags:int) returns: undefined Script Dom之 Selection: 属性:(element.states访问) 1、type null | symbol, read-onlyproperty. // 选区的类型: #text, #cells, #blocks. 2、isCollapsed true | false, read-onlyproperty. // 选区收缩状态,selection.start ==selection.end. 3、anchor null | bookmark, read-onlyproperty. // DOM position of selection anchor. 锚点 4、caret null | bookmark, read-onlyproperty. // DOM position of selection caret. 插入符 5、start null | bookmark, read-onlyproperty. // caret or anchor, whichever is lower in DOM order. 起始位置 6、end null | bookmark, read-onlyproperty. // caret or anchor, whichever is greater in DOM order. 结束位置 7、text string, read-only property. // 文本内容 8、html string, read-only property. // HTML片段 方法: collapse (towhat:symbol ) returns: bookmark. // 设置选区位置 #toCaret, #toAnchor,#toStartor #toEnd select (caret:bookmark [ , anchor:bookmark ] ) returns: true | false // 设置选区范围 advance (what:symbol, direction:symbol [, units:symbol] ) returns: true | false. // var bm = [bookmark: node,index, after]; , , , and
elements.
你可能感兴趣的:(界面库,跨平台)