BootstrapQ 封裝Bootstrap tree,dialog等,bootstrapdialog
【前言】
使用bootstrap有兩年時間了,積累了一些經驗,做下分享。
計劃會開源,這篇文章先簡單介紹一下。
【軟肋】
其實bootstrap已經很好了,唯一的軟肋就是js方面有些薄弱,對比easyui就知道了,
可以很明顯的知道bootstrap是前端人員建立的,而easyui是偏後端人員建立的。
【積累】
對bootstrap做了一些封裝,可以使大家使用更方便,如下:
1.封裝了alert
2.封裝了confirm
3.封裝了dialog
4.封裝了msg
5.封裝了tooltip
6.封裝了popover
7.封裝了bstree
8.封裝了bstro
【alert】
理由:bootstrap是沒有alert外掛程式的,基於模態框封裝了一下
效果:
使用方法:
// 無回調qiao.bs.alert('這是一個提示');// 有回調qiao.bs.alert('這是一個提示',function(){alert(1);});
【confirm】
理由:同alert
效果:
使用方法:
qiao.bs.confirm('確定要這樣嗎?',function(){alert('點擊了確定');},function(){alert('點擊了取消');});
【dialog】
理由:同上
效果:
用法:
qiao.bs.dialog({url : '/ucenter/role/setUrl/' + id,title : '設定Url',okbtn : '儲存'}, qiao.role.addUrl);
參數:
qiao.bs.dialog(options,func);
其中options有:
qiao.bs.modaloptions = {url : '',fade: 'fade',close: true,title: 'title',btn: false,okbtn: '確定',qubtn: '取消',msg: 'msg',big: false,show: false,remote: false,backdrop: 'static',keyboard: true,style: ''};
func是回呼函數,
返回true,關閉dialog
返回false,不關閉dialog
【msg】
理由:bootstrap沒有提示訊息的js組件,封裝了一個
效果:
用法:
// 只有提示qiao.bs.msg('一個提示');// 自訂配置qiao.bs.msg({msg : '危險提示',type : 'danger',time : 2000});
【tooltip】
理由:bootstrap的tooltip每次都需要手動啟用,比較麻煩
效果:
用法:
// 預設提示$('#test1').bstip('123');// 可配置$('#test1').bstip({animation : true,container : 'body',content: 'content',html: true,placement: 'bottom',title: '',trigger: 'hover'//click | hover | focus | manual.});
【popover】
理由:同上
效果:
用法:
// 預設提示$('#test1').bspop('123');// 可配置$('#test1').bspop({animation : true,container : 'body',content: 'content',html: true,placement: 'bottom',title: '',trigger: 'hover'//click | hover | focus | manual.});
【bstree】
理由:
bootstrap最大的軟肋就是做後台ui的時候功能太弱,例如tree組件,datagrid組件都沒有,在這點上easyui完勝bootstrap,
封裝了tree,這個比較複雜。
效果:
可編輯效果:
選擇效果:
用法:
資料結構:
以java為例,需要有這幾個屬性:
private int id;private String url;private String text;private boolean checked = false;private List<QTree> children;
js參數:
qiao.bs.tree.options = {url : '/ucenter/menu/',height : '600px',open: true,edit: false,checkbox: false,showurl: true};
【bstro】
理由:這個是封裝了一個網站引導外掛程式bootstro
效果:
看這裡:http://zhidao.beiwaionline.com/
或者:
用法:
var isbstro = $.cookie('bootstro');if(!isbstro){qiao.bs.bstro([['#md5input','<h3 style="margin-top:10px;">使用關鍵字檢索問題或知識點~</h3>'],['.breadcrumb','<h3 style="margin-top:10px;">也可以分類檢索問題知識點喲~</h3>'],['#questionsDiv',{content:'<h3 style="margin-top:10px;">這裡是問題知識點列表~</h3>',place:'right'}],['#addQuestionLi','<h3 style="margin-top:10px;">提問,或添加知識點在這裡~</h3>'],['#userRankLi','<h3 style="margin-top:10px;">使用者最佳回答熱門排行榜~</h3>'],['#userLoginLi','<h3 style="margin-top:10px;">從這裡登入哦~</h3>']],{obtn : '我已瞭解,下次不再提示!',exit : function(){$.cookie('bootstro','ok',{expires:30, path:'/'});}});}
【效果】
總得來說,有幾點效果:
1.大大簡化使用bootstrap的方法
2.封裝了一些常用外掛程式
【開源】
等時間充足,和BootstrapQ更加完善後會開源。
【更多】
更多文章請看:http://uikoo9.com/blog/list