This commit is contained in:
yumoqing 2024-03-08 10:54:16 +08:00
parent 15e64a16f9
commit 278a520138
27 changed files with 223 additions and 166 deletions

View File

@ -42,7 +42,7 @@ bricks.Accordion = class oops extends bricks.VBox {
async change_content(evnet){
var b = event.target.bricks_widget;
var name = b.opts.name;
console.log('accordion: button=', b, 'name=', name);
bricks.debug('accordion: button=', b, 'name=', name);
var pos = -1;
for (var i=0; i< this.opts.items.length; i++){
if (name == this.opts.items[i].name){

View File

@ -41,6 +41,6 @@ bricks.AG_Grid = class oops extends bricks.JsWidget {
});
}
cell_clicked(params){
console.log('clicked, params=', params);
bricks.debug('clicked, params=', params);
}
}

View File

@ -36,7 +36,7 @@ bricks.AudioPlayer = class oops extends bricks.JsWidget {
}
set_source(url){
this.audio.src = url;
console.log(this.audio.src,' new src seted');
bricks.debug(this.audio.src,' new src seted');
}
play(){
this.audio.play();
@ -84,7 +84,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
this.bind('record_finished', this.upload.bind(this));
}
rec_btn_pressed(){
console.log(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon);
bricks.debug(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon);
if(this.rec_btn.url == this.start_icon){
this.rec_btn.set_url(this.stop_icon);
this.start_recording();
@ -119,7 +119,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
//此处创建这些音频可视化图形绘制浏览器支持妥妥的
//this.wave=Recorder.FrequencyHistogramView({elem:".recwave"});
}.bind(this),function(msg,isUserNotAllow){//用户拒绝未授权或不支持
console.log('open recorder failed');
bricks.debug('open recorder failed');
});
}
recClose(){
@ -128,7 +128,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
this.rec = null;
this.mic_opened = false;
}else{
console.log('close recorder error');
bricks.debug('close recorder error');
};
}
recoding(){
@ -149,19 +149,19 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
if(this.rec&&Recorder.IsOpen()){
this.rec.pause();
}else{
console.log("gCAR::未打开录音");
bricks.debug("gCAR::未打开录音");
};
}
resume_recording(){
if(this.rec&&Recorder.IsOpen()){
this.rec.resume();
}else{
console.log("Ob6S::未打开录音");
bricks.debug("Ob6S::未打开录音");
};
}
stop_recording(){
if(!(this.rec&&Recorder.IsOpen())){
console.log("5JuL::未打开录音");
bricks.debug("5JuL::未打开录音");
return;
};
this.rec.stop(function(blob,duration){
@ -176,32 +176,32 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
this.dispatch('record_finished', d);
}.bind(this),function(msg){
console.log("kGZO::录音失败:");
bricks.debug("kGZO::录音失败:");
});
}
upload = async function(){
if(!this.recordData){
console.log("DUTn::请先录音,然后停止后再上传");
bricks.debug("DUTn::请先录音,然后停止后再上传");
return;
};
if(!this.upload_url){
return;
}
var blob=this.recordData.data;
console.log('blob=', blob, this.recordData);
bricks.debug('blob=', blob, this.recordData);
var form=new FormData();
form.append("audiofile",blob,"recorder.wav");
var jpost = bricks.jpost
var ret = await jpost(this.upload_url,{
params:form
});
console.log('ret=', ret);
bricks.debug('ret=', ret);
this.recClose();
this.dispatch('updated', ret)
}
download(){
if(!this.recordData){
console.log('recorder not opened');
bricks.debug('recorder not opened');
return;
};
var fileName="recorder-"+Date.now()+".wav";
@ -211,7 +211,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
downA.download=fileName;
// document.querySelector("."+cls).appendChild(downA);
if(/mobile/i.test(navigator.userAgent)){
console.log('mobile device');
bricks.debug('mobile device');
}
downA.click();
//不用了时需要revokeObjectURL否则霸占内存

View File

@ -87,7 +87,7 @@ bricks.widgetBuild = async function(desc, widget){
}
let klass = bricks.Factory.get(desc.widgettype);
if (! klass){
console.log('widgetBuild():',desc.widgettype, 'not registered', bricks.Factory.widgets_kw);
bricks.debug('widgetBuild():',desc.widgettype, 'not registered', bricks.Factory.widgets_kw);
return null;
}
var options = desc.options || {};
@ -103,7 +103,7 @@ bricks.widgetBuild = async function(desc, widget){
if ( sw ){
w.add_widget(sw);
} else {
console.log('widgetBuild() error: sdesc=', sdesc);
bricks.debug('widgetBuild() error: sdesc=', sdesc);
}
}
}
@ -141,7 +141,7 @@ bricks.universal_handler = function(from_widget, widget, desc, event){
if (f){
return f(event);
}
console.log('universal_handler() error', 'from_widget=',
bricks.debug('universal_handler() error', 'from_widget=',
from_widget,
'widget=', widget,
'desc=', desc,
@ -150,7 +150,7 @@ bricks.universal_handler = function(from_widget, widget, desc, event){
bricks.buildEventHandler = function(w, desc){
var target = bricks.getWidgetById(desc.target, w);
if (! target){
console.log('target miss desc=', desc, 'w=', w);
bricks.debug('target miss desc=', desc, 'w=', w);
return null
}
var rtdata = null;
@ -185,16 +185,16 @@ bricks.buildEventHandler = function(w, desc){
return bricks.buildDispatchEventHandler(w, target, rtdata, desc);
break;
default:
console.log('invalid actiontype', target, desc);
bricks.debug('invalid actiontype', target, desc);
break;
}
}
bricks.getRealtimeData = function(w, desc){
var target = bricks.getWidgetById(desc.widget, w);
var f;
console.log('getRealtimeData() calling ...');
bricks.debug('getRealtimeData() calling ...');
if (! target){
console.log('target miss', desc);
bricks.debug('target miss', desc);
return null
}
if (desc.method){
@ -210,10 +210,10 @@ bricks.getRealtimeData = function(w, desc){
}
var _buildWidget = async function(from_widget, target, mode, options){
console.log('target=', target, 'mode=', mode, 'options=', options);
bricks.debug('target=', target, 'mode=', mode, 'options=', options);
var w = await (bricks.widgetBuild(options, from_widget));
if (!w){
console.log('options=', options, 'widgetBuild() failed');
bricks.debug('options=', options, 'widgetBuild() failed');
return;
}
if (mode == 'replace'){
@ -228,10 +228,10 @@ var _buildWidget = async function(from_widget, target, mode, options){
bricks.buildUrlwidgetHandler = function(w, target, rtdata, desc){
var f = async function(target, mode, options){
console.log('target=', target, 'mode=', mode, 'options=', options);
bricks.debug('target=', target, 'mode=', mode, 'options=', options);
var w = await (bricks.widgetBuild(options, w));
if (!w){
console.log('options=', options, 'widgetBuild() failed');
bricks.debug('options=', options, 'widgetBuild() failed');
return;
}
if (mode == 'replace'){
@ -253,10 +253,10 @@ bricks.buildUrlwidgetHandler = function(w, target, rtdata, desc){
}
bricks.buildBricksHandler = function(w, target, rtdata, desc){
var f = async function(target, mode, options){
console.log('target=', target, 'mode=', mode, 'options=', options);
bricks.debug('target=', target, 'mode=', mode, 'options=', options);
var w = await (bricks.widgetBuild(options, wa));
if (!w){
console.log('options=', options, 'widgetBuild() failed');
bricks.debug('options=', options, 'widgetBuild() failed');
return;
}
if (mode == 'replace'){
@ -271,7 +271,7 @@ bricks.buildBricksHandler = function(w, target, rtdata, desc){
bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){
var f = objget(registerfunctions, desc.rfname);
if( ! f){
console.log('rfname:', desc.rfname, 'not registed', desc);
bricks.debug('rfname:', desc.rfname, 'not registed', desc);
return null;
}
var params = {};
@ -286,7 +286,7 @@ bricks.buildRegisterFunctionHandler = function(w, target, rtdata, desc){
bricks.buildMethodHandler = function(w, target, rtdata, desc){
var f = target[desc.method];
if (! f){
console.log('desc:', desc, 'not exists in', target, 'w=', w);
bricks.debug('desc:', desc, 'not exists in', target, 'w=', w);
return null;
}
var params = {};
@ -299,7 +299,7 @@ bricks.buildScriptHandler = function(w, target, rtdata, desc){
bricks.extend(params, desc.params)
bricks.extend(params, rtdata);
var f = new Function('target', 'params', 'event', desc.script);
console.log('params=', params, 'buildScriptHandler() ..........');
bricks.debug('params=', params, 'buildScriptHandler() ..........');
return f.bind(target, target, params);
}
bricks.buildDispatchEventHandler = function(w, target, rtdata, desc){
@ -352,11 +352,11 @@ bricks.getWidgetById = function(id, from_widget){
}
}
catch(err){
console.log('getWidgetById():i=', ids[i], id, 'not found', err);
bricks.debug('getWidgetById():i=', ids[i], id, 'not found', err);
return null;
}
if ( new_el == null ){
console.log('getWidgetById():', id, from_widget, 'el=', el, 'id=', ids[i]);
bricks.debug('getWidgetById():', id, from_widget, 'el=', el, 'id=', ids[i]);
return null;
}
el = new_el;
@ -364,7 +364,7 @@ bricks.getWidgetById = function(id, from_widget){
if (typeof(el.bricks_widget) !== 'undefined'){
return el.bricks_widget;
}
console.log('********', id, 'el=', el, 'found, but not a bricks class with dom element');
bricks.debug('********', id, 'el=', el, 'found, but not a bricks class with dom element');
return el;
}
@ -425,7 +425,7 @@ bricks.App = class extends bricks.Layout {
var opts = structuredClone(this.opts.widget);
var w = await (bricks.widgetBuild(opts, bricks.Body));
if (!w){
console.log('w=', w, 'Body=', bricks.Body, 'Factory=', bricks.Factory)
bricks.debug('w=', w, 'Body=', bricks.Body, 'Factory=', bricks.Factory)
}
return w;
}
@ -434,7 +434,7 @@ bricks.App = class extends bricks.Layout {
var w = await (this.build());
this.root = w;
if (!w){
console.log('w=', w, 'Body=', bricks.Body, 'Factory=', bricks.Factory)
bricks.debug('w=', w, 'Body=', bricks.Body, 'Factory=', bricks.Factory)
return null;
}
bricks.Body.add_widget(w);

View File

@ -78,12 +78,12 @@ bricks.Button = class extends bricks.Layout {
}
}
target_clicked(event){
console.log('target_clicked() .... called ');
bricks.debug('target_clicked() .... called ');
event.stopPropagation();
this.dispatch('click', this.opts);
if (this.opts.action){
if (this.opts.debug){
console.log('debug:opts=', this.opts);
bricks.debug('debug:opts=', this.opts);
}
}
}

View File

@ -283,7 +283,7 @@ bricks.DataGrid = class extends bricks.VBox {
}
this.freeze_part = null;
this.normal_part = null;
console.log('width=', this.freeze_width, '-', this.normal_width, '...');
bricks.debug('width=', this.freeze_width, '-', this.normal_width, '...');
if (this.freeze_fields.length > 0) {
this.freeze_part = new bricks.VBox({});
this.freeze_part.set_css('datagrid-left');
@ -325,11 +325,11 @@ bricks.DataGrid = class extends bricks.VBox {
}
}
load_previous_data() {
console.log('event min_threshold fired ........');
bricks.debug('event min_threshold fired ........');
this.loader.previousPage();
}
load_next_data() {
console.log('event max_threshold fired ........');
bricks.debug('event max_threshold fired ........');
this.loader.nextPage();
}
coscroll(event) {
@ -378,7 +378,7 @@ bricks.DataGrid = class extends bricks.VBox {
this.selected_row = row;
this.selected_row.selected();
this.dispatch('row_click', row);
console.log('DataGrid():click_handler, row=', row, 'event=', event);
bricks.debug('DataGrid():click_handler, row=', row, 'event=', event);
}
}

View File

@ -40,7 +40,7 @@ bricks.DataViewer = class extends bricks.VScrollPanel {
fetch(this.opts.viewer_url)
.then(response => response.text())
.then(data => {
console.log('viewer_tmpl=', data);
bricks.debug('viewer_tmpl=', data);
this.viewer_tmpl = data
schedule_once(this.loader.loadData.bind(this.loader), 0.01);
});
@ -58,13 +58,13 @@ bricks.DataViewer = class extends bricks.VScrollPanel {
var desc = JSON.parse(s);
var w = await bricks.widgetBuild(desc, this);
if (! w){
console.log(desc, 'widgetBuild() failed...........');
bricks.debug(desc, 'widgetBuild() failed...........');
return;
}
w.row_data = row;
var index = null;
if (direction == 'down') index = 0;
console.log('w=', w, 'this=', this);
bricks.debug('w=', w, 'this=', this);
this.add_widget(w, index);
}
}

View File

@ -56,24 +56,24 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
}
this.bind('min_threshold', this.load_previous_page.bind(this));
this.bind('max_threshold', this.load_next_page.bind(this));
this.oldscrollY = null;
this.render();
}
render(params) {
console.log('params=', params, 'render() called');
bricks.debug('params=', params, 'render() called');
this.clear_widgets();
this.pages = new Map(); // 用于存储已加载的页面数据
this.pageContents = new Map(); // 用于存储已加载的页面内容
params = params || {};
this.params = bricks.extend(this.base_params, params);
this.loadPage(1);
this.dom_element.scrollTop = 0;
}
async loadPage(page) {
if (this.loading){
return;
}
this.loading = true;
// 检查页面是否在缓存中
if (! this.pages.has(page)) {
var jc = new bricks.HttpJson();
@ -84,7 +84,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
});
var d = await jc.get(this.dataUrl,{params:params});
if (!d){
console.log(this.dataUrl,{params:params}, 'error');
bricks.debug(this.dataUrl,{params:params}, 'error');
this.loading = false;
return;
}
@ -100,30 +100,30 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
max = Math.max(...pages);
min = Math.min(...pages);
const farthestPage = page == max? min : max;
var w = this.pageContents.get(farthestPage);
this.remove_widget(w);
this.delete_page(farthestPage);
this.pages.delete(farthestPage);
this.pageContents.delete(farthestPage);
}
var pages = Array.from(this.pages.keys());
if (page == Math.min(pages)){
this.scrollY = 1 / pages.length;
if (this.scrollY == 1){
this.scrollY = 0;
}
} else {
this.scrollY = (pages.length - 1) / pages.length;
}
} else {
bricks.debug(page, 'already n buffer, do not thing');
}
this.loading = false;
return;
}
is_max_page(page){
const pages = Array.from(this.pages.keys());
return page == Math.max(...pages);
}
is_min_page(page){
const pages = Array.from(this.pages.keys());
return page == Math.min(...pages);
}
async renderAccordionItems(data, page) {
const pageContent = new bricks.PageContent({height:"auto"});
pageContent.page = page;
var pos;
for (var i=0;i<data.length;i++){
if (this.is_max_page(page)){
pos = -1;
} else {
pos = i;
}
const record = data[i];
const item = new bricks.AccordionItem({});
const header = new bricks.AccordionHeader({});
@ -134,7 +134,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
if (w){
header.add_widget(w);
} else {
console.log('bricks.widgetBuildWithData(), tmpl=', this.record_view_tmpl, 'record=', record);
bricks.debug('bricks.widgetBuildWithData(), tmpl=', this.record_view_tmpl, 'record=', record);
}
}
header.textContent = record.title; // 使用数据记录的标题字段
@ -147,17 +147,23 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
header.bind('click', this.toggle_content.bind(this, header, content, record));
item.add_widget(header);
item.add_widget(content);
pageContent.add_widget(item);
item.set_attribute('data-page', page);
this.add_widget(item, pos);
if (pos >= 0){
this.dom_element.scrollTop += item.get_height();
} else {
this.dom_element.scrollTop -= item.get_height();
}
};
this.pageContents.set(page, pageContent);
var pages = Array.from(this.pages.keys());
if (page == Math.min(...pages)){
this.add_widget(pageContent, 0);
} else {
this.add_widget(pageContent);
}
delete_page(page){
var items = this.dom_element.querySelectorAll('[data-page="' + page + '"]');
for (var i=0;i<items.length;i++) {
var w = items[i].bricks_widget;
this.remove_widget(w);
}
}
async toggle_content(header, content, record, event){
var h = this.dom_element.offsetHeight - 3 * header.dom_element.offsetHeight;
content.set_style('height', h + 'px');
@ -170,7 +176,7 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
}
content.toggle_hide();
if (content.dom_element.style.display == 'none'){
console.log('content just collapsed');
bricks.debug('content just collapsed');
content.clear_widgets();
this.active_content = null;
return;
@ -199,44 +205,69 @@ bricks.DynamicAccordion = class extends bricks.VScrollPanel {
}
get_load_page(dir){
var pages = Array.from(this.pages.keys());
if (pages.length == 0){
return 1;
}
if (dir=='up'){
var page = Math.min(...pages);
console.log('page=', page, pages, 'dir=', dir);
bricks.debug('page=', page, pages, 'dir=', dir);
return page - 1;
} else {
var page = Math.max(...pages);
console.log('page=', page, pages, 'dir=', dir);
bricks.debug('page=', page, pages, 'dir=', dir);
return page + 1;
}
}
async load_previous_page(){
var pages = Array.from(this.pages.keys());
var page = this.get_load_page('up');
if (page > 0){
await this.loadPage(page);
console.log('page loaded, page=', page);
} else {
var pages = Array.from(this.pages.keys());
console.log('page NOT loaded, page=', page,
'lastPage=', this.lastPage,
'rows=', this.rows,
'cacheLimit=', this.cacheLimit,
'buffered page=', pages.length);
if (this.loading){
bricks.debug('this.loading is set, do not thing');
return;
}
this.loading = true;
try {
var page = this.get_load_page('up');
if (page > 0){
await this.loadPage(page);
var pages = Array.from(this.pages.keys());
bricks.debug('load_previous_page():page loaded, page=', page, pages);
} else {
var pages = Array.from(this.pages.keys());
bricks.debug('page NOT loaded, page=', page,
'lastPage=', this.lastPage,
'rows=', this.rows,
'cacheLimit=', this.cacheLimit,
'buffered page=', pages.length);
}
} catch(e){
bricks.debug('error happened', e);
}
this.loading = false;
}
async load_next_page(){
var pages = Array.from(this.pages.keys());
var page = this.get_load_page('down');
if (page <= this.lastPage){
await this.loadPage(page);
console.log('page Loaded, page=', page);
} else {
console.log('page=', page,
'lastPage=', this.lastPage,
'rows=', this.rows,
'cacheLimit=', this.cacheLimit,
'buffered page=', pages);
if (this.loading){
bricks.debug('this.loading is set, do not thing');
return;
}
this.loading = true;
try {
var page = this.get_load_page('down');
if (page <= this.lastPage){
await this.loadPage(page);
var pages = Array.from(this.pages.keys());
bricks.debug('load_next_page():page Loaded, page=', page, pages);
} else {
var pages = Array.from(this.pages.keys());
bricks.debug('page=', page,
'lastPage=', this.lastPage,
'rows=', this.rows,
'cacheLimit=', this.cacheLimit,
'buffered page=', pages);
}
} catch (e){
bricks.debug('error happened', e);
}
this.loading = false;
bricks.debug('load_next_page() finished');
}
}
bricks.Factory.register('DynamicAccordion', bricks.DynamicAccordion);

View File

@ -36,7 +36,7 @@ bricks.FieldGroup = class extends bricks.VBox {
box.add_widget(w);
form.name_inputs[fields[i].name] = w;
} else {
console.log(fields[i], 'createInput failed');
bricks.debug(fields[i], 'createInput failed');
}
}
}
@ -141,7 +141,7 @@ bricks.Form = class extends bricks.VBox {
}
command_handle(event){
var params = event.params;
console.log('Form(): click_handle() params=', params);
bricks.debug('Form(): click_handle() params=', params);
if (!params){
error('click_handle() get a null params');
return
@ -181,7 +181,7 @@ bricks.Form = class extends bricks.VBox {
var w = this.name_inputs[name];
var d = w.getValue();
if (w.required && ( d[name] == '' || d[name] === null)){
console.log('data=', data, 'd=', d);
bricks.debug('data=', data, 'd=', d);
w.focus();
return;
}

View File

@ -19,5 +19,10 @@
<!--- <script src="{{entire_url('/bricks/3parties/videojs-contrib-hls.min.js')}}"></script> --->
<script src="{{entire_url('/bricks/bricks.js')}}"></script>
<script>
/*
if (bricks.is_mobile()){
alert('wh=' + window.innerWidth + ':' + window.innerHeight);
}
*/
const opts = {
"widget":

View File

@ -507,7 +507,7 @@ bricks.UiText =class extends bricks.UiType {
}
resultValue(){
var e = this.dom_element;
console.log('UiText(), element=', e, 'value=', e.value);
bricks.debug('UiText(), element=', e, 'value=', e.value);
this.value = e.value;
return this.value;
}
@ -629,11 +629,11 @@ bricks._Input = class {
register(name, Klass){
if (! Klass){
console.log('Klass not defined', name);
bricks.debug('Klass not defined', name);
return;
}
if (! Klass.uitype){
console.log('uitype of Klass not defined', name);
bricks.debug('uitype of Klass not defined', name);
return;
}
@ -645,7 +645,7 @@ bricks._Input = class {
if (klass){
return new klass(options);
}
console.log('create input for:', options.uitype, 'failed');
bricks.debug('create input for:', options.uitype, 'failed');
return null;
}
}

View File

@ -107,7 +107,7 @@ bricks.HttpText = class {
}
async withLoginInfo(url, params){
var get_login_info = function(e){
console.log('login info:', e.target.getValue());
bricks.debug('login info:', e.target.getValue());
return e.target.getValue();
}
var w = await bricks.widgetBuild({

View File

@ -7,10 +7,10 @@ bricks.Layout = class extends bricks.JsWidget {
}
add_widget(w, index){
if (index >=0 && index < this.children.length){
if (index !== null && index >=0 && index < this.children.length){
var pos_w = this.children[index];
this.dom_element.insertBefore(w.dom_element, pos_w.dom_element);
this.children.insert(index+1, w);
this.children.insert(index, w);
} else {
// append child at end
w.parent = this;

View File

@ -23,7 +23,7 @@ bricks.MdText = class extends bricks.JsWidget {
schedule_once(f, 0.01);
}
show_scroll(event){
console.log('scrollY=', window.scrollY);
bricks.debug('scrollY=', window.scrollY);
}
build = async function(){
this._build(this.opts.md_url);
@ -69,7 +69,7 @@ bricks.MarkdownViewer = class extends bricks.VBox {
this.bind('scroll', this.show_scroll.bind(this));
}
show_scroll(event){
console.log('scrollY=', window.scrollY);
bricks.debug('scrollY=', window.scrollY);
}
createBackButton = async function(){
var desc = {
@ -85,15 +85,15 @@ bricks.MarkdownViewer = class extends bricks.VBox {
]
}
var w = await bricks.widgetBuild(desc);
console.log('createBackButton():error, desc=', desc, 'w=', w);
bricks.debug('createBackButton():error, desc=', desc, 'w=', w);
var t = w.children[0];
console.log('createBackButton():text=',t);
bricks.debug('createBackButton():text=',t);
t.bind('click',this.go_back.bind(this));
this.add_widget(w);
console.log('createBackButton():desc=',desc, 'w=', w);
bricks.debug('createBackButton():desc=',desc, 'w=', w);
}
add_back_stack(event){
console.log('go_back_stack():event=', event);
bricks.debug('go_back_stack():event=', event);
var url = event.params.url;
this.back_stack.push(url);
}

View File

@ -34,10 +34,10 @@ bricks.Menu = class extends bricks.VBox {
}
return
}
console.log('item clicked');
bricks.debug('item clicked');
}
create_children(p, items){
console.log('create_children():items=', items, 'p=', p);
bricks.debug('create_children():items=', items, 'p=', p);
for (let i=0;i<items.length;i++){
let item = items[i];
let menu_item = this.create_menuitem(item);
@ -51,11 +51,11 @@ bricks.Menu = class extends bricks.VBox {
}
create_menuitem(item){
let i18n = bricks.app.i18n;
console.log('i18n=', i18n);
bricks.debug('i18n=', i18n);
let e = document.createElement('div');
e.textContent = i18n._(item.label || item.name);
// e.description = item
console.log('create_menuitem():item=', item, 'obj=', e);
bricks.debug('create_menuitem():item=', item, 'obj=', e);
return e;
}
}

View File

@ -61,7 +61,7 @@ bricks.MiniForm = class extends bricks.HBox {
this.add_widget(w);
}
show_options(e){
console.log('show_options() called ...');
bricks.debug('show_options() called ...');
this.choose.show();
}
change_input(e){
@ -70,7 +70,7 @@ bricks.MiniForm = class extends bricks.HBox {
}
input_handle(e){
var d = this.getValue();
console.log('input_handle() ..', d);
bricks.debug('input_handle() ..', d);
this.dispatch('input', d);
}
getValue(){

View File

@ -72,7 +72,7 @@ bricks.Modal = class extends bricks.Layout {
if (event.target == this.dom_element){
this.dismiss();
} else {
console.log('modal():click_handler()');
bricks.debug('modal():click_handler()');
}
}
open(){

View File

@ -1,16 +1,14 @@
var bricks = window.bricks || {};
var low_handle = function(widget, dim, last_pos, cur_pos, maxlen, winsize){
var dir = cur_pos - last_pos;
var max_rate = cur_pos / (maxlen - winsize);
var min_rate = cur_pos / maxlen;
if (!widget.threshold && dir > 0 && max_rate >= widget.max_threshold){
widget.thresgold = true;
if (Math.abs(cur_pos + winsize - maxlen) < 1){
bricks.debug('fire max_threshold ......');
widget.dispatch('max_threshold');
return
}
if (!widget.threshold && dir < 0 && min_rate <= widget.min_threshold){
widget.thresgold = true;
if (cur_pos < 1) {
bricks.debug('fire min_threshold ......');
widget.dispatch('min_threshold');
return
}
@ -28,20 +26,20 @@ bricks.HScrollPanel = class extends bricks.HBox {
opts.height = '100%';
opts.overflow = 'auto';
super(opts);
this.min_threshold = opts.min_threshold || 0.02;
this.max_threshold = opts.max_threshold || 0.95;
this.min_threshold = opts.min_threshold || 0.01;
this.max_threshold = opts.max_threshold || 0.99;
this.bind('scroll', this.scroll_handle.bind(this))
this.last_scrollLeft = this.dom_element.scrollLeft;
this.threshold = false;
}
scroll_handle(event){
if (event.target != this.dom_element){
// console.log('HScroll():scroll on other', event.target);
// bricks.debug('HScroll():scroll on other', event.target);
return;
}
var e = this.dom_element;
if ( e.scrollWidth - e.clientWidth < 1) {
// console.log('HScroll():same size');
// bricks.debug('HScroll():same size');
return;
}
low_handle(this, 'x', this.last_scrollLeft,
@ -68,16 +66,16 @@ bricks.VScrollPanel = class extends bricks.VBox {
this.min_threshold = opts.min_threshold || 0.02;
this.max_threshold = opts.max_threshold || 0.95;
this.bind('scroll', this.scroll_handle.bind(this))
this.last_scrollTop = this.dom_element.scrollTop;
this.last_scrollY = this.dom_element.scrollY;
}
scroll_handle(event){
if (event.target != this.dom_element){
// console.log('scroll on other', event.target);
// bricks.debug('scroll on other', event.target);
return;
}
var e = this.dom_element;
if ( e.scrollHeight - e.clientHeight < 2) {
// console.log('same size');
// bricks.debug('same size');
return;
}
low_handle(this, 'y', this.last_scrollTop,

View File

@ -82,7 +82,7 @@ bricks.TabPanel = class extends bricks.Layout {
var tdesc = event.params;
var items = this.opts.items;
if (tdesc.name == this.cur_tab_name){
console.log('TabPanel(): click duplication click on same tab', tdesc)
bricks.debug('TabPanel(): click duplication click on same tab', tdesc)
return;
}
for (var i=0;i<items.length;i++){
@ -96,7 +96,7 @@ bricks.TabPanel = class extends bricks.Layout {
}
w = await bricks.widgetBuild(items[i].content);
if (! w){
console.log('TabPanel():create content error', items[i].content);
bricks.debug('TabPanel():create content error', items[i].content);
return;
}
this.content_buffer[tdesc.name] = w;
@ -106,7 +106,7 @@ bricks.TabPanel = class extends bricks.Layout {
return;
}
}
console.log('TabPanel(): click event handled but noting to do', tdesc)
bricks.debug('TabPanel(): click event handled but noting to do', tdesc)
}
add_tab(desc){
var item = this.toolbar.createTool(desc);

View File

@ -65,7 +65,7 @@ bricks.Toolbar = class extends bricks.Layout {
};
var w = await bricks.widgetBuild(options);
if (! w){
console.log('Toolbar(): build widget failed', options);
bricks.debug('Toolbar(): build widget failed', options);
return
}
w.bind('click', this.do_handle.bind(this, w));
@ -85,7 +85,7 @@ bricks.Toolbar = class extends bricks.Layout {
}
do_handle(tool, event){
// var tool = event.target;
console.log('Toolbar() onclick,target=', event.target, tool);
bricks.debug('Toolbar() onclick,target=', event.target, tool);
var d = {};
bricks.extend(d, tool.tool_opts);
if (this.opts.target){
@ -93,7 +93,7 @@ bricks.Toolbar = class extends bricks.Layout {
}
this.dispatch('command', d);
this.dispatch(tool.tool_opts.name, d);
console.log('event ', tool.tool_opts.name, ' fired ...')
bricks.debug('event ', tool.tool_opts.name, ' fired ...')
if (this.clicked_btn){
this.clicked_btn.set_css(this.preffix_css + '-button-active', true);
}
@ -107,9 +107,9 @@ bricks.Toolbar = class extends bricks.Layout {
if (image){
item.add_widget(image);
image.bind('click',this.remove_item.bind(this, item));
console.log('Toolbar(): add_removable() for ', img_src);
bricks.debug('Toolbar(): add_removable() for ', img_src);
} else {
console.log('Toolbar(): Image create error', img_src);
bricks.debug('Toolbar(): Image create error', img_src);
}
}
click(name){

View File

@ -259,7 +259,7 @@ bricks. EditableTree = class extends bricks.Tree {
this.add_widget(this.toolbar, 0);
}
command_handle(e){
console.log('command event fire ...', e);
bricks.debug('command event fire ...', e);
var name = e.params.name;
switch (name) {
case 'add':
@ -294,7 +294,7 @@ bricks. EditableTree = class extends bricks.Tree {
var n = new bricks.TreeNode(this, node, data);
node.container.add_widget(n);
n.edit();
console.log('add_node() finished ...');
bricks.debug('add_node() finished ...');
}
edit_node(){
if (! this.selected_node){

View File

@ -1,5 +1,17 @@
var bricks = window.bricks || {};
bricks.isMobile = () => /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
bricks.bug = false;
bricks.debug = function(...args){
if (! bricks.bug){
return;
}
var callInfo;
try {
throw new Error();
} catch (e) {
callInfo = e.stack.split('\n')[2].trim();
}
console.log(callInfo, ...args);
}
bricks.is_mobile = function(){
var userAgent = navigator.userAgent;
@ -9,8 +21,10 @@ bricks.is_mobile = function(){
if (('ontouchstart' in window) || (navigator.maxTouchPoints > 0) || (navigator.msMaxTouchPoints > 0)) {
return true;
}
if (window.innerWidth <= 768 && window.innerHeight <= 1024) {
return true;
}
return false;
}
class _TypeIcons {
@ -39,7 +53,7 @@ var currentScriptPath = function () {
if (document.currentScript){
currentScript = document.currentScript.src;
} else {
console.log('has not currentScriot');
bricks.debug('has not currentScriot');
var scripts = document.querySelectorAll( 'script[src]' );
if (scripts.length < 1){
return null;
@ -67,7 +81,7 @@ function querySelectorAllShadows(selector, el = document.body) {
const childShadows = Array.from(el.querySelectorAll('*')).
map(el => el.shadowRoot).filter(Boolean);
console.log('[querySelectorAllShadows]', selector, el, `(${childShadows.length} shadowRoots)`);
bricks.debug('[querySelectorAllShadows]', selector, el, `(${childShadows.length} shadowRoots)`);
const childResults = childShadows.map(child => querySelectorAllShadows(selector, child));
@ -93,7 +107,7 @@ var schedule_interval = function(f, t){
}
var debug = function(){
console.log(...arguments);
bricks.debug(...arguments);
}
var import_cache = new Map()
@ -210,7 +224,7 @@ var archorize = function(ele,archor){
'y':y
}
var tsf = bricks.obj_fmtstr(o, 'translateY(-${y}) translateX(-${x})');
console.log('archorize(): tsf=', tsf);
bricks.debug('archorize(): tsf=', tsf);
ele.style.transform = tsf;
ele.style.position = "absolute";
}
@ -243,7 +257,7 @@ var absurl = function(url, widget){
}
var debug = function(...args){
console.log(...args);
bricks.debug(...args);
}
var convert2int = function(s){
@ -298,7 +312,7 @@ var objcopy = function(obj){
bricks.playResponseAudio = async function(response, target){
var widget = null;
if (response.status != 200){
console.log('playResponseAudio(): response.status != 200', response.status);
bricks.debug('playResponseAudio(): response.status != 200', response.status);
return;
}
if (typeof target == typeof ''){
@ -307,7 +321,7 @@ bricks.playResponseAudio = async function(response, target){
widget = bricks.widgetBuild(target);
}
if (! widget){
console.log('playResponseAudio():', target, 'can not found or build a widget');
bricks.debug('playResponseAudio():', target, 'can not found or build a widget');
return;
}
const blob = await response.blob();
@ -318,13 +332,13 @@ bricks.playResponseAudio = async function(response, target){
bricks.widgetBuildWithData = async function(desc_tmpl, from_widget, data){
if (!desc_tmpl){
console.log('bricks.widgetBuildWithData():data=', data, 'desc_tmpl=', desc_tmpl);
bricks.debug('bricks.widgetBuildWithData():data=', data, 'desc_tmpl=', desc_tmpl);
}
var s = bricks.obj_fmtstr(data, desc_tmpl);
var desc = JSON.parse(s);
var w = await bricks.widgetBuild(desc, from_widget);
if (! w){
console.log(desc, 'widgetBuild() failed...........');
bricks.debug(desc, 'widgetBuild() failed...........');
return;
}
w.row_data = data;

View File

@ -40,7 +40,7 @@ bricks.Video = class extends bricks.Layout {
destroy_resource(params, event){
var w = event.target.bricks_widget;
if (! w.parent){
console.log('destroy resource .......');
bricks.debug('destroy resource .......');
this.player.pause();
this.player.dispose();
this.player = null;
@ -49,7 +49,7 @@ bricks.Video = class extends bricks.Layout {
disable_captions(){
this.player.nativeTextTracks = false;
var tt = this.player.textTracks()
console.log('textTracks=', tt);
bricks.debug('textTracks=', tt);
if (tt){
for(var i=0;i<tt.length;i++){
tt[i].mode = 'disabled';

View File

@ -207,6 +207,12 @@ bricks.JsWidget = class {
e.params = params;
this.dom_element.dispatchEvent(e);
}
set_attribute(attr, value){
this.dom_element.setAttribute(attr, value);
}
get_attribute(attr) {
this.dom_element.getAttribute(attr);
}
}

View File

@ -20,7 +20,7 @@ bricks.Wterm = class extends bricks.JsWidget {
this.term = term;
term.open(this.dom_element);
var ws = new WebSocket(this.opts.ws_url);
console.log('FitAddon=', FitAddon);
bricks.debug('FitAddon=', FitAddon);
this.fitAddon = new FitAddon.FitAddon()
term.loadAddon(this.fitAddon)
// this.fitAddon.fit()
@ -44,7 +44,7 @@ bricks.Wterm = class extends bricks.JsWidget {
try {
this.fitAddon.fit();
} catch(e){
console.log('resize error', e);
bricks.debug('resize error', e);
}
}
}

View File

@ -2,7 +2,9 @@
{
"widgettype":"MarkdownViewer",
"options":{
"width":"100%",
"height":"100%",
"navigator":true,
"md_url":"../docs/index.md"
"md_url":"../docs/README.md"
}
}

View File

@ -4,6 +4,7 @@
"options":{
"tab_wide":"auto",
"height":"100%",
"width":"100%",
"tab_long":"70%",
"tab_pos":"top",
"items":[