diff --git a/bricks/bricks.js b/bricks/bricks.js index 967f460..fe8aefe 100755 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -211,7 +211,7 @@ bricks.buildEventHandler = async function(w, desc, event){ return bricks.buildBricksHandler(w, target, rtdata, desc); break; case 'registerfunction': - return bricks.buildRegisterFunction(w, target, rtdata, desc); + return bricks.buildRegisterFunctionHandler(w, target, rtdata, desc); break; case 'method': return bricks.buildMethodHandler(w, target, rtdata, desc); @@ -311,7 +311,7 @@ bricks.buildBricksHandler = function(w, target, rtdata, desc){ return _buildWidget.bind(w, target, target, desc.mode || 'replace', options); } bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){ - var f = objget(registerfunctions, desc.rfname); + var f = bricks.RF.get(desc.rfname); if( ! f){ bricks.debug('rfname:', desc.rfname, 'not registed', desc); return null; diff --git a/bricks/registerfunction.js b/bricks/registerfunction.js index 3a04e31..6d39d1e 100755 --- a/bricks/registerfunction.js +++ b/bricks/registerfunction.js @@ -1,11 +1,19 @@ +var bricks = window.bricks || {}; + class RegisterFunction { constructor(){ this.rfs = {}; } register(n, f){ - bricks.extend(this.rfs, {n:f}); + this.rfs[n] = f; } get(n){ - return objget(this.rfs, n); + try { + return this.rfs[n]; + } catch(e){ + return null; + } } } + +bricks.RF = new RegisterFunction(); diff --git a/docs/cn/descjson.md b/docs/cn/descjson.md index e69ffd5..c7fa598 100644 --- a/docs/cn/descjson.md +++ b/docs/cn/descjson.md @@ -1,12 +1,12 @@ # 创建控件的Json文件格式说明 -Bricks在服务器端使用Json文件格式存储控件描述文件,前端获得json文件后转化为json对象,并用词json对象调用widgetBuild函数创建Bricks控件。 +Bricks在服务器端使用Json文件格式存储控件描述文件,前端获得json文件后转化为json对象,并用此json对象调用widgetBuild函数创建Bricks控件。 控件描述json文件必须含有“widgettype” 和”options“两个属性。“subwidgets”属性用来定义此控件包含的子控件。“binds”用于定义此控件或其子控件的事件处理 ## widgettype说明 widgettype是一个字符串属性。其值为Bricks中的所有控件类型或"urlwidget" -可用的控件类型可以在[控件类型清单](widgettypes.md)中查找 +可用的控件类型可以在[控件类型清单](widgets.md)中查找 ## options 对象类型,每个控件有特定的options属性,清参看每个控件的说明 diff --git a/examples/aaa.ui b/examples/aaa.ui new file mode 100644 index 0000000..fe1632a --- /dev/null +++ b/examples/aaa.ui @@ -0,0 +1,38 @@ +{ + "widgettype":"VBox", + "options":{}, + "subwidgets":[ + { + "id":"btn1", + "widgettype":"Button", + "options":{ + "label":"press me" + } + }, + { + "id":"txt1", + "widgettype":"Text", + "options":{ + "otext":"I will dispatch a event when btn1 pressed", + "i18n":true + } + } + ], + "binds":[ + { + "wid":"btn1", + "event":"click", + "actiontype":"script", + "target":"txt1", + "script":"this.set_text('estrdyfguihojkl')", + "dispatch_event":"gpc" + }, + { + "wid":"txt1", + "event":"gpc", + "actiontype":"script", + "target":"self", + "script":"alert('yield');" + } + ] +} diff --git a/examples/event_action.ui b/examples/event_action.ui new file mode 100644 index 0000000..ba7a7d9 --- /dev/null +++ b/examples/event_action.ui @@ -0,0 +1,37 @@ +{ + "widgettype":"VBox", + "options":{}, + "subwidgets":[ + { + "id":"btn1", + "widgettype":"Button", + "options":{ + "label":"press me" + } + }, + { + "id":"txt1", + "widgettype":"Text", + "options":{ + "otext":"I will dispatch a event when btn1 pressed", + "i18n":true + } + } + ], + "binds":[ + { + "wid":"btn1", + "event":"click", + "actiontype":"event", + "target":"txt1", + "dispatch_event":"gpc" + }, + { + "wid":"txt1", + "event":"gpc", + "actiontype":"script", + "target":"self", + "script":"alert('yield');" + } + ] +} diff --git a/examples/insert_text.ui b/examples/insert_text.ui new file mode 100644 index 0000000..02d1362 --- /dev/null +++ b/examples/insert_text.ui @@ -0,0 +1,6 @@ +{ + "widgettype":"Text", + "options":{ + "text":"urlwidget insert mode text" + } +} diff --git a/examples/method_action.ui b/examples/method_action.ui new file mode 100644 index 0000000..3b414b0 --- /dev/null +++ b/examples/method_action.ui @@ -0,0 +1,85 @@ +{ + "widgettype":"VBox", + "options":{ + "width":"100%", + "height":"100%" + }, + "subwidgets":[ + { + "widgettype":"HBox", + "options":{ + "height":"40px" + }, + "subwidgets":[ + { + "id":"changetext", + "widgettype":"Button", + "options":{ + "dynsize":false, + "width":"80px", + "i18n":true, + "label":"Change text" + } + }, + { + "id":"smaller", + "widgettype":"Button", + "options":{ + "dynsize":false, + "width":"80px", + "i18n":true, + "label":"Small size" + } + }, + { + "id":"larger", + "widgettype":"Button", + "options":{ + "dynsize":false, + "width":"80px", + "i18n":true, + "label":"larger size" + } + } + ] + }, + { + "widgettype":"Filler", + "options":{}, + "subwidgets":[ + { + "id":"text_1", + "widgettype":"Text", + "options":{ + "dynsize":true, + "text":"original text" + } + } + ] + } + ], + "binds":[ + { + "wid":"changetext", + "event":"click", + "actiontype":"method", + "target":"text_1", + "params":"new text", + "method":"set_text" + }, + { + "wid":"smaller", + "event":"click", + "actiontype":"method", + "target":"app", + "method":"textsize_smaller" + }, + { + "wid":"larger", + "event":"click", + "actiontype":"method", + "target":"app", + "method":"textsize_bigger" + } + ] +} diff --git a/examples/replace_text.ui b/examples/replace_text.ui new file mode 100644 index 0000000..d8780ef --- /dev/null +++ b/examples/replace_text.ui @@ -0,0 +1,6 @@ +{ + "widgettype":"Text", + "options":{ + "text":"urlwidget replace mode text" + } +} diff --git a/examples/rf.html b/examples/rf.html new file mode 100644 index 0000000..216b0f8 --- /dev/null +++ b/examples/rf.html @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + diff --git a/examples/script_action_1.ui b/examples/script_action_1.ui new file mode 100644 index 0000000..fe1632a --- /dev/null +++ b/examples/script_action_1.ui @@ -0,0 +1,38 @@ +{ + "widgettype":"VBox", + "options":{}, + "subwidgets":[ + { + "id":"btn1", + "widgettype":"Button", + "options":{ + "label":"press me" + } + }, + { + "id":"txt1", + "widgettype":"Text", + "options":{ + "otext":"I will dispatch a event when btn1 pressed", + "i18n":true + } + } + ], + "binds":[ + { + "wid":"btn1", + "event":"click", + "actiontype":"script", + "target":"txt1", + "script":"this.set_text('estrdyfguihojkl')", + "dispatch_event":"gpc" + }, + { + "wid":"txt1", + "event":"gpc", + "actiontype":"script", + "target":"self", + "script":"alert('yield');" + } + ] +} diff --git a/examples/test.ws b/examples/test.ws new file mode 100644 index 0000000..cfa42b2 --- /dev/null +++ b/examples/test.ws @@ -0,0 +1,2 @@ +resp = 'resp:' + ws_data +ws_pool.sendto(resp) diff --git a/examples/urlwidget_action.ui b/examples/urlwidget_action.ui new file mode 100644 index 0000000..e759f6d --- /dev/null +++ b/examples/urlwidget_action.ui @@ -0,0 +1,88 @@ +{ + "widgettype":"VBox", + "options":{ + "width":"100%", + "height":"100%" + }, + "subwidgets":[ + { + "widgettype":"HBox", + "options":{ + "height":"40px" + }, + "subwidgets":[ + { + "id":"replace", + "widgettype":"Button", + "options":{ + "width":"80px", + "i18n":true, + "label":"replace mode" + } + }, + { + "id":"insert", + "widgettype":"Button", + "options":{ + "width":"80px", + "i18n":true, + "label":"insert mode" + } + }, + { + "id":"append", + "widgettype":"Button", + "options":{ + "width":"80px", + "i18n":true, + "label":"append mode" + } + } + ] + }, + { + "id":"main", + "widgettype":"Filler" + } + ], + "binds":[ + { + "wid":"replace", + "event":"click", + "actiontype":"urlwidget", + "target":"main", + "options":{ + "url":"{{entire_url('replace_text.ui')}}", + "params":{ + "text":"Insert before" + } + } + }, + { + "wid":"insert", + "event":"click", + "actiontype":"urlwidget", + "target":"main", + "options":{ + "url":"{{entire_url('insert_text.ui')}}", + "params":{ + "text":"Insert before" + } + }, + "mode":"insert" + }, + { + "wid":"append", + "event":"click", + "actiontype":"urlwidget", + "target":"main", + "options":{ + "url":"{{entire_url('subtext.ui')}}", + "params":{ + "text":"Append After" + } + }, + "mode":"append" + } + ] +}