guy
8 years ago
commit
63ac6fcb87
507 changed files with 174455 additions and 0 deletions
@ -0,0 +1,125 @@
|
||||
module.exports = function (grunt) { |
||||
|
||||
// Project configuration.
|
||||
grunt.initConfig({ |
||||
pkg: grunt.file.readJSON('package.json'), |
||||
concat: { |
||||
options: { |
||||
separator: '' |
||||
}, |
||||
coreJs: { |
||||
src: [ |
||||
'src/core/jquery.js', |
||||
'src/core/underscore.js', |
||||
'src/core/foundation.js', |
||||
'src/core/mvc/**/*.js', |
||||
'src/core/base.js', |
||||
'src/core/ob.js', |
||||
'src/core/widget.js', |
||||
'src/core/model.js', |
||||
'src/core/view.js', |
||||
'src/core/shortcut.js', |
||||
'src/core/utils/*.js', |
||||
'src/core/behavior/behavior.js', |
||||
'src/core/wrapper/layout.js', |
||||
'src/core/**/*.js', |
||||
|
||||
'src/data/data.js', |
||||
'src/data/**/*.js' |
||||
], |
||||
dest: 'dist/core.js' |
||||
}, |
||||
//最基础的控件
|
||||
baseJs: { |
||||
src: [ |
||||
'src/third/codemirror/codemirror.js', |
||||
'src/third/**/*.js', |
||||
'src/base/pane.js', |
||||
'src/base/single/single.js', |
||||
'src/base/single/text.js', |
||||
'src/base/single/button/button.basic.js', |
||||
'src/base/single/button/button.node.js', |
||||
'src/base/**/*.js' |
||||
], |
||||
dest: 'dist/base.js' |
||||
}, |
||||
//实现好的一些基础实例
|
||||
caseJs: { |
||||
src: [ |
||||
'src/case/**/*.js' |
||||
], |
||||
dest: 'dist/case.js' |
||||
}, |
||||
coreCss: { |
||||
src: ['src/css/core/**/*.css'], |
||||
dest: 'dist/core.css' |
||||
}, |
||||
baseCss: { |
||||
src: ['src/css/base/**/*.css'], |
||||
dest: 'dist/base.css' |
||||
} |
||||
}, |
||||
|
||||
uglify: { |
||||
options: { |
||||
banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */\n' |
||||
}, |
||||
dist: { |
||||
files: { |
||||
'dist/core.min.js': ['<%= concat.coreJs.dest %>'], |
||||
'dist/base.min.js': ['<%= concat.baseJs.dest %>'], |
||||
'dist/case.min.js': ['<%= concat.caseJs.dest %>'] |
||||
} |
||||
} |
||||
}, |
||||
|
||||
cssmin: { |
||||
|
||||
coreCss: { |
||||
|
||||
src: '<%= concat.coreCss.dest %>', |
||||
|
||||
dest: 'dist/core.min.css' |
||||
|
||||
}, |
||||
baseCss: { |
||||
|
||||
src: '<%= concat.baseCss.dest %>', |
||||
|
||||
dest: 'dist/base.min.css' |
||||
|
||||
} |
||||
|
||||
}, |
||||
|
||||
jshint: { |
||||
files: ['Gruntfile.js', 'src/**/*.js'], |
||||
options: { |
||||
globals: { |
||||
jQuery: true, |
||||
console: true, |
||||
module: true, |
||||
document: true |
||||
} |
||||
} |
||||
}, |
||||
watch: { |
||||
scripts: { |
||||
files: ['src/**/*.js'], |
||||
tasks: ['concat'], |
||||
options: { |
||||
spanw: true, |
||||
interrupt: true |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
|
||||
grunt.loadNpmTasks('grunt-contrib-uglify'); |
||||
grunt.loadNpmTasks('grunt-contrib-jshint'); |
||||
grunt.loadNpmTasks('grunt-contrib-watch'); |
||||
grunt.loadNpmTasks('grunt-contrib-concat'); |
||||
grunt.loadNpmTasks('grunt-contrib-cssmin'); |
||||
|
||||
grunt.registerTask('default', ['concat', 'watch']); |
||||
}; |
@ -0,0 +1,21 @@
|
||||
MIT License |
||||
|
||||
Copyright (c) 2016 gittz |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
of this software and associated documentation files (the "Software"), to deal |
||||
in the Software without restriction, including without limitation the rights |
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
copies of the Software, and to permit persons to whom the Software is |
||||
furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all |
||||
copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
||||
SOFTWARE. |
Binary file not shown.
File diff suppressed because one or more lines are too long
@ -0,0 +1,450 @@
|
||||
/****添加计算宽度的--运算符直接需要space****/ |
||||
/****** common color(常用颜色,可用于普遍场景) *****/ |
||||
/**** custom color(自定义颜色,用于特定场景) ****/ |
||||
@font-face { |
||||
font-family: 'bi'; |
||||
src: url('${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */ url('${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.woff') format('woff'), /* chrome、firefox */ url('${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.ttf') format('truetype'), /* chrome、firefox、opera、Safari, Android, iOS 4.2+*/ url('${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.svg#svgFontName') format('svg'); |
||||
|
||||
/* iOS 4.1- */ |
||||
} |
||||
.b-font { |
||||
font-family: "bi"; |
||||
font-style: normal; |
||||
-webkit-font-smoothing: antialiased; |
||||
-webkit-text-stroke-width: 0.2px; |
||||
-moz-osx-font-smoothing: grayscale; |
||||
} |
||||
html, |
||||
button, |
||||
input, |
||||
select, |
||||
textarea, |
||||
* { |
||||
font-family: "Microsoft YaHei", "Hiragino Sans GB W3"; |
||||
} |
||||
html, |
||||
body, |
||||
div, |
||||
ul, |
||||
li, |
||||
img, |
||||
a, |
||||
span, |
||||
p, |
||||
* { |
||||
margin: 0px; |
||||
} |
||||
html { |
||||
height: 100%; |
||||
overflow: hidden; |
||||
} |
||||
body { |
||||
position: absolute; |
||||
width: 100%; |
||||
height: 100%; |
||||
margin: 0; |
||||
padding: 0; |
||||
top: 0; |
||||
left: 0; |
||||
background-repeat: repeat; |
||||
-webkit-user-select: none; |
||||
-khtml-user-select: none; |
||||
-moz-user-select: none; |
||||
-ms-user-select: none; |
||||
-o-user-select: none; |
||||
user-select: none; |
||||
color: #1a1a1a; |
||||
font: normal 12px "Microsoft YaHei", "Hiragino Sans GB W3"; |
||||
-webkit-font-smoothing: antialiased; |
||||
-moz-osx-font-smoothing: grayscale; |
||||
text-decoration: none; |
||||
-kthml-user-focus: normal; |
||||
-moz-user-focus: normal; |
||||
-moz-outline: 0 none; |
||||
outline: 0 none; |
||||
} |
||||
#wrapper { |
||||
position: absolute; |
||||
left: 0; |
||||
right: 0; |
||||
top: 0; |
||||
bottom: 0; |
||||
overflow: hidden; |
||||
overflow-x: hidden; |
||||
overflow-y: hidden; |
||||
} |
||||
a { |
||||
outline: none; |
||||
text-decoration: none; |
||||
} |
||||
a:focus { |
||||
outline: 0; |
||||
} |
||||
input, |
||||
textarea { |
||||
margin: 0; |
||||
padding: 0; |
||||
outline: none; |
||||
border: 1px solid #cccccc; |
||||
} |
||||
ul, |
||||
ol { |
||||
margin: 0; |
||||
padding: 0; |
||||
} |
||||
ul { |
||||
list-style: disc; |
||||
} |
||||
li { |
||||
list-style-type: none; |
||||
} |
||||
i { |
||||
font-style: normal; |
||||
-webkit-font-smoothing: antialiased; |
||||
-webkit-text-stroke-width: 0.2px; |
||||
-moz-osx-font-smoothing: grayscale; |
||||
} |
||||
div::-webkit-scrollbar, |
||||
textarea::-webkit-scrollbar { |
||||
-webkit-appearance: none; |
||||
background-color: #f4f4f4; |
||||
width: 6px; |
||||
height: 6px; |
||||
} |
||||
div::-webkit-scrollbar-thumb, |
||||
textarea::-webkit-scrollbar-thumb { |
||||
-webkit-border-radius: 0; |
||||
-moz-border-radius: 0; |
||||
border-radius: 0; |
||||
background-color: #e2e2e2; |
||||
} |
||||
/****添加计算宽度的--运算符直接需要space****/ |
||||
/****** common color(常用颜色,可用于普遍场景) *****/ |
||||
/**** custom color(自定义颜色,用于特定场景) ****/ |
||||
/************hing light*****************/ |
||||
.bi-flex-center-layout { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: center; |
||||
/* 12版 */ |
||||
-webkit-justify-content: center; |
||||
-moz-justify-content: center; |
||||
-ms-justify-content: center; |
||||
-o-justify-content: center; |
||||
justify-content: center; |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
} |
||||
.bi-flex-horizontal-layout { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: flex-start; |
||||
/* 12版 */ |
||||
-webkit-justify-content: flex-start; |
||||
-moz-justify-content: flex-start; |
||||
-ms-justify-content: flex-start; |
||||
-o-justify-content: flex-start; |
||||
justify-content: flex-start; |
||||
/* 09版 */ |
||||
-webkit-box-align: flex-start; |
||||
/* 12版 */ |
||||
-webkit-align-items: flex-start; |
||||
-moz-align-items: flex-start; |
||||
-ms-align-items: flex-start; |
||||
-o-align-items: flex-start; |
||||
align-items: flex-start; |
||||
/* 09版 */ |
||||
/*-webkit-box-lines: multiple;*/ |
||||
/* 12版 */ |
||||
-webkit-flex-wrap: nowrap; |
||||
-moz-flex-wrap: nowrap; |
||||
-ms-flex-wrap: nowrap; |
||||
-o-flex-wrap: nowrap; |
||||
flex-wrap: nowrap; |
||||
} |
||||
.bi-flex-horizontal-layout.middle { |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
} |
||||
.bi-flex-horizontal-layout.bottom { |
||||
/* 09版 */ |
||||
-webkit-box-align: flex-end; |
||||
/* 12版 */ |
||||
-webkit-align-items: flex-end; |
||||
-moz-align-items: flex-end; |
||||
-ms-align-items: flex-end; |
||||
-o-align-items: flex-end; |
||||
align-items: flex-end; |
||||
} |
||||
.bi-flex-vertical-center { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: flex-start; |
||||
/* 12版 */ |
||||
-webkit-justify-content: flex-start; |
||||
-moz-justify-content: flex-start; |
||||
-ms-justify-content: flex-start; |
||||
-o-justify-content: flex-start; |
||||
justify-content: flex-start; |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
/* 09版 */ |
||||
/*-webkit-box-lines: multiple;*/ |
||||
/* 12版 */ |
||||
-webkit-flex-wrap: nowrap; |
||||
-moz-flex-wrap: nowrap; |
||||
-ms-flex-wrap: nowrap; |
||||
-o-flex-wrap: nowrap; |
||||
flex-wrap: nowrap; |
||||
} |
||||
.bi-flex-wrapper-center-layout .flex-wrapper-center-layout-wrapper { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: center; |
||||
/* 12版 */ |
||||
-webkit-justify-content: center; |
||||
-moz-justify-content: center; |
||||
-ms-justify-content: center; |
||||
-o-justify-content: center; |
||||
justify-content: center; |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
min-width: 100%; |
||||
min-height: 100%; |
||||
float: left; |
||||
} |
||||
.bi-flex-wrapper-horizontal-layout .flex-wrapper-horizontal-layout-wrapper { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: flex-start; |
||||
/* 12版 */ |
||||
-webkit-justify-content: flex-start; |
||||
-moz-justify-content: flex-start; |
||||
-ms-justify-content: flex-start; |
||||
-o-justify-content: flex-start; |
||||
justify-content: flex-start; |
||||
/* 09版 */ |
||||
-webkit-box-align: flex-start; |
||||
/* 12版 */ |
||||
-webkit-align-items: flex-start; |
||||
-moz-align-items: flex-start; |
||||
-ms-align-items: flex-start; |
||||
-o-align-items: flex-start; |
||||
align-items: flex-start; |
||||
/* 09版 */ |
||||
/*-webkit-box-lines: multiple;*/ |
||||
/* 12版 */ |
||||
-webkit-flex-wrap: nowrap; |
||||
-moz-flex-wrap: nowrap; |
||||
-ms-flex-wrap: nowrap; |
||||
-o-flex-wrap: nowrap; |
||||
flex-wrap: nowrap; |
||||
min-height: 100%; |
||||
} |
||||
.bi-flex-wrapper-horizontal-layout .flex-wrapper-horizontal-layout-wrapper.middle { |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
} |
||||
.bi-flex-wrapper-horizontal-layout .flex-wrapper-horizontal-layout-wrapper.bottom { |
||||
/* 09版 */ |
||||
-webkit-box-align: flex-end; |
||||
/* 12版 */ |
||||
-webkit-align-items: flex-end; |
||||
-moz-align-items: flex-end; |
||||
-ms-align-items: flex-end; |
||||
-o-align-items: flex-end; |
||||
align-items: flex-end; |
||||
} |
||||
.bi-flex-wrapper-vertical-center .flex-wrapper-vertical-center-wrapper { |
||||
display: box; |
||||
/* OLD - Android 4.4- */ |
||||
display: -webkit-box; |
||||
/* OLD - iOS 6-, Safari 3.1-6 */ |
||||
display: -moz-box; |
||||
/* OLD - Firefox 19- (buggy but mostly works) */ |
||||
display: -ms-flexbox; |
||||
/* TWEENER - IE 10 */ |
||||
display: -webkit-flex; |
||||
/* NEW - Chrome */ |
||||
display: flex; |
||||
/* NEW, Spec - Opera 12.1, Firefox 20+ */ |
||||
/* 09版 */ |
||||
-webkit-box-orient: horizontal; |
||||
/* 12版 */ |
||||
-webkit-flex-direction: row; |
||||
-moz-flex-direction: row; |
||||
-ms-flex-direction: row; |
||||
-o-flex-direction: row; |
||||
flex-direction: row; |
||||
/* 09版 */ |
||||
-webkit-box-pack: flex-start; |
||||
/* 12版 */ |
||||
-webkit-justify-content: flex-start; |
||||
-moz-justify-content: flex-start; |
||||
-ms-justify-content: flex-start; |
||||
-o-justify-content: flex-start; |
||||
justify-content: flex-start; |
||||
/* 09版 */ |
||||
-webkit-box-align: center; |
||||
/* 12版 */ |
||||
-webkit-align-items: center; |
||||
-moz-align-items: center; |
||||
-ms-align-items: center; |
||||
-o-align-items: center; |
||||
align-items: center; |
||||
/* 09版 */ |
||||
/*-webkit-box-lines: multiple;*/ |
||||
/* 12版 */ |
||||
-webkit-flex-wrap: nowrap; |
||||
-moz-flex-wrap: nowrap; |
||||
-ms-flex-wrap: nowrap; |
||||
-o-flex-wrap: nowrap; |
||||
flex-wrap: nowrap; |
||||
min-height: 100%; |
||||
float: left; |
||||
} |
||||
/****添加计算宽度的--运算符直接需要space****/ |
||||
/****** common color(常用颜色,可用于普遍场景) *****/ |
||||
/**** custom color(自定义颜色,用于特定场景) ****/ |
||||
.bi-inline-center-adapt-layout:after { |
||||
display: inline-block; |
||||
width: 0; |
||||
min-height: 100%; |
||||
vertical-align: middle; |
||||
content: ' '; |
||||
} |
||||
/****添加计算宽度的--运算符直接需要space****/ |
||||
/****** common color(常用颜色,可用于普遍场景) *****/ |
||||
/**** custom color(自定义颜色,用于特定场景) ****/ |
||||
.bi-inline-vertical-adapt-layout:after { |
||||
display: inline-block; |
||||
width: 0; |
||||
min-height: 100%; |
||||
vertical-align: middle; |
||||
content: ' '; |
||||
} |
@ -0,0 +1 @@
|
||||
body,html{height:100%}#wrapper,body{position:absolute;left:0;top:0}#wrapper,html{overflow:hidden}a,body{text-decoration:none}body,input,ol,textarea,ul{margin:0;padding:0}.b-font,i{-webkit-text-stroke-width:.2px;-moz-osx-font-smoothing:grayscale}.b-font,body,i{-moz-osx-font-smoothing:grayscale}@font-face{font-family:bi;src:url(${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.eot?#iefix) format('embedded-opentype'),url(${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.woff) format('woff'),url(${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.ttf) format('truetype'),url(${servletURL}?op=resource&resource=/com/fr/bi/web/resources/fonts/iconfont.svg#svgFontName) format('svg')}.b-font{font-family:bi;font-style:normal;-webkit-font-smoothing:antialiased}*,button,html,input,select,textarea{font-family:"Microsoft YaHei","Hiragino Sans GB W3"}*,a,body,div,html,img,li,p,span,ul{margin:0}body{width:100%;background-repeat:repeat;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;color:#1a1a1a;font:400 12px "Microsoft YaHei","Hiragino Sans GB W3";-webkit-font-smoothing:antialiased;-kthml-user-focus:normal;-moz-user-focus:normal;-moz-outline:0 none;outline:0}a,a:focus{outline:0}#wrapper{right:0;bottom:0;overflow-x:hidden;overflow-y:hidden}input,textarea{outline:0;border:1px solid #ccc}ul{list-style:disc}li{list-style-type:none}i{font-style:normal;-webkit-font-smoothing:antialiased}div::-webkit-scrollbar,textarea::-webkit-scrollbar{-webkit-appearance:none;background-color:#f4f4f4;width:6px;height:6px}div::-webkit-scrollbar-thumb,textarea::-webkit-scrollbar-thumb{-webkit-border-radius:0;-moz-border-radius:0;border-radius:0;background-color:#e2e2e2} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html> |
||||
<html lang="en"> |
||||
<head> |
||||
<meta charset="utf-8"> |
||||
<title></title> |
||||
|
||||
<link rel="stylesheet" type="text/css" |
||||
href="dist/core.css"/> |
||||
<link rel="stylesheet" type="text/css" |
||||
href="dist/base.css"/> |
||||
|
||||
<script src="dist/core.js"></script> |
||||
<script src="dist/base.js"></script> |
||||
<script src="dist/case.js"></script> |
||||
<script src="index.js"></script> |
||||
</head> |
||||
<body> |
||||
<div id="wrapper"></div> |
||||
<div id="container"></div> |
||||
</body> |
||||
</html> |
@ -0,0 +1,57 @@
|
||||
$(function(){ |
||||
var items = [], header = [], columnSize = []; |
||||
|
||||
var rowCount = 100, columnCount = 100; |
||||
for (var i = 0; i < 1; i++) { |
||||
header[i] = []; |
||||
for (var j = 0; j < columnCount; j++) { |
||||
header[i][j] = { |
||||
type: "bi.label", |
||||
text: "表头" + i + "-" + j |
||||
} |
||||
columnSize[j] = 100; |
||||
} |
||||
} |
||||
for (var i = 0; i < rowCount; i++) { |
||||
items[i] = []; |
||||
for (var j = 0; j < columnCount; j++) { |
||||
items[i][j] = { |
||||
type: "bi.label", |
||||
text: (i < 3 ? 0 : i) + "-" + j |
||||
} |
||||
} |
||||
} |
||||
|
||||
var table = BI.createWidget({ |
||||
type: "bi.resizable_table", |
||||
el: { |
||||
type: "bi.collection_table", |
||||
isNeedMerge: true, |
||||
mergeCols: [0, 1], |
||||
mergeRule: function (col1, col2) { |
||||
return BI.isEqual(col1, col2); |
||||
} |
||||
}, |
||||
width: 600, |
||||
height: 500, |
||||
isResizeAdapt: true, |
||||
isNeedResize: true, |
||||
isNeedMerge: true, |
||||
isNeedFreeze: true, |
||||
freezeCols: [0, 1], |
||||
columnSize: columnSize, |
||||
items: items, |
||||
header: header |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: "#wrapper", |
||||
items: [{ |
||||
el: table, |
||||
left: 10, |
||||
right: 10, |
||||
top: 10, |
||||
bottom: 10 |
||||
}] |
||||
}) |
||||
}) |
@ -0,0 +1,22 @@
|
||||
{ |
||||
"name": "index", |
||||
"version": "1.0.0", |
||||
"description": "BI4.0测试", |
||||
"main": "index.js", |
||||
"dependencies": { |
||||
|
||||
}, |
||||
"devDependencies": { |
||||
"grunt": "^1.0.1", |
||||
"grunt-contrib-concat": "^1.0.1", |
||||
"grunt-contrib-cssmin": "^1.0.1", |
||||
"grunt-contrib-jshint": "^1.0.0", |
||||
"grunt-contrib-uglify": "^1.0.1", |
||||
"grunt-contrib-watch": "^1.0.0" |
||||
}, |
||||
"scripts": { |
||||
"grunt": "grunt" |
||||
}, |
||||
"author": "", |
||||
"license": "ISC" |
||||
} |
@ -0,0 +1,7 @@
|
||||
BI.Resizers = new BI.ResizeController(); |
||||
BI.Layers = new BI.LayerController(); |
||||
BI.Maskers = new BI.MaskersController(); |
||||
BI.Bubbles = new BI.BubblesController(); |
||||
BI.Tooltips = new BI.TooltipsController(); |
||||
BI.Popovers = new BI.FloatBoxController(); |
||||
BI.Broadcasts = new BI.BroadcastController(); |
@ -0,0 +1,132 @@
|
||||
/** |
||||
* canvas绘图 |
||||
* |
||||
* Created by GUY on 2015/11/18. |
||||
* @class BI.Canvas |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Canvas = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Canvas.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-canvas" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Canvas.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
var canvas = document.createElement("canvas"); |
||||
if (!document.createElement('canvas').getContext) { |
||||
canvas = window.G_vmlCanvasManager.initElement(canvas); |
||||
} |
||||
this.element.append(canvas); |
||||
canvas.width = o.width; |
||||
canvas.height = o.height; |
||||
$(canvas).width("100%"); |
||||
$(canvas).height("100%"); |
||||
this.canvas = canvas; |
||||
this._queue = []; |
||||
}, |
||||
|
||||
_getContext: function () { |
||||
if (!this.ctx) { |
||||
this.ctx = this.canvas.getContext('2d'); |
||||
} |
||||
return this.ctx; |
||||
}, |
||||
|
||||
_attr: function (key, value) { |
||||
var self = this; |
||||
if (BI.isNull(key)) { |
||||
return; |
||||
} |
||||
if (BI.isObject(key)) { |
||||
BI.each(key, function (k, v) { |
||||
self._queue.push({k: k, v: v}); |
||||
}); |
||||
return; |
||||
} |
||||
this._queue.push({k: key, v: value}); |
||||
}, |
||||
|
||||
_line: function (x0, y0) { |
||||
var self = this; |
||||
var args = [].slice.call(arguments, 2); |
||||
if (BI.isOdd(args.length)) { |
||||
this._attr(BI.last(args)); |
||||
args = BI.initial(args); |
||||
} |
||||
this._attr("moveTo", [x0, y0]); |
||||
var odd = BI.filter(args, function (i) { |
||||
return i % 2 === 0; |
||||
}); |
||||
var even = BI.filter(args, function (i) { |
||||
return i % 2 !== 0; |
||||
}); |
||||
args = BI.zip(odd, even); |
||||
BI.each(args, function (i, point) { |
||||
self._attr("lineTo", point); |
||||
}); |
||||
}, |
||||
|
||||
line: function (x0, y0, x1, y1) { |
||||
this._line.apply(this, arguments); |
||||
this._attr("stroke", []); |
||||
}, |
||||
|
||||
rect: function (x, y, w, h, color) { |
||||
this._attr("fillStyle", color); |
||||
this._attr("fillRect", [x, y, w, h]); |
||||
}, |
||||
|
||||
circle: function (x, y, radius, color) { |
||||
this._attr({ |
||||
fillStyle: color, |
||||
beginPath: [], |
||||
arc: [x, y, radius, 0, Math.PI * 2, true], |
||||
closePath: [], |
||||
fill: [] |
||||
}); |
||||
}, |
||||
|
||||
hollow: function () { |
||||
this._attr("beginPath", []); |
||||
this._line.apply(this, arguments); |
||||
this._attr("closePath", []); |
||||
this._attr("stroke", []); |
||||
}, |
||||
|
||||
solid: function () { |
||||
this.hollow.apply(this, arguments); |
||||
this._attr("fill", []); |
||||
}, |
||||
|
||||
gradient: function (x0, y0, x1, y1, start, end) { |
||||
var grd = this._getContext().createLinearGradient(x0, y0, x1, y1); |
||||
grd.addColorStop(0, start); |
||||
grd.addColorStop(1, end); |
||||
return grd; |
||||
}, |
||||
|
||||
reset: function () { |
||||
this._getContext().clearRect(0, 0, this.canvas.width, this.canvas.height); |
||||
}, |
||||
|
||||
stroke: function (callback) { |
||||
var self = this; |
||||
BI.nextTick(function () { |
||||
var ctx = self._getContext(); |
||||
BI.each(self._queue, function (i, q) { |
||||
if (BI.isFunction(ctx[q.k])) { |
||||
ctx[q.k].apply(ctx, q.v); |
||||
} else { |
||||
ctx[q.k] = q.v; |
||||
} |
||||
}); |
||||
self._queue = []; |
||||
callback && callback(); |
||||
}); |
||||
} |
||||
}); |
||||
$.shortcut("bi.canvas", BI.Canvas); |
@ -0,0 +1,89 @@
|
||||
/** |
||||
* 图表控件 |
||||
* @class BI.Chart |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Chart = BI.inherit(BI.Pane, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Chart.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-chart" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Chart.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
|
||||
this.isInit = false; |
||||
this.isSetOptions = false; |
||||
this.wants2SetData = false; |
||||
var width = 0; |
||||
var height = 0; |
||||
|
||||
this._resizer = BI.debounce(function () { |
||||
if (self.element.is(":visible") && self.vanCharts) { |
||||
self.vanCharts.resize(); |
||||
} |
||||
}, 30); |
||||
BI.Resizers.add(this.getName(), function (e) { |
||||
if (BI.isWindow(e.target) && self.element.is(":visible")) { |
||||
var newW = self.element.width(), newH = self.element.height(); |
||||
if (newW > 0 && newH > 0 && (width !== newW || height !== newH)) { |
||||
self._resizer(); |
||||
width = newW; |
||||
height = newH; |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
_setData: function () { |
||||
this.vanCharts && this.vanCharts.setData(this.config); |
||||
}, |
||||
|
||||
resize: function () { |
||||
if (this.element.is(":visible") && this.isSetOptions === true) { |
||||
this._resizer(); |
||||
} |
||||
}, |
||||
|
||||
magnify: function () { |
||||
this.vanCharts && this.vanCharts.charts[0] && this.vanCharts.charts[0].refreshRestore(); |
||||
}, |
||||
|
||||
populate: function (items, options) { |
||||
var self = this, o = this.options; |
||||
o.items = items; |
||||
this.config = options || {}; |
||||
this.config.series = o.items; |
||||
|
||||
var setOptions = function () { |
||||
self.vanCharts.setOptions(self.config); |
||||
self.isSetOptions = true; |
||||
//if (self.wants2SetData === true) {
|
||||
// self._setData();
|
||||
//}
|
||||
}; |
||||
var init = function () { |
||||
if (self.element.is(":visible")) { |
||||
self.vanCharts = VanCharts.init(self.element[0]); |
||||
BI.nextTick(setOptions); |
||||
self.isInit = true; |
||||
} |
||||
}; |
||||
|
||||
if (this.isInit === false) { |
||||
BI.nextTick(init); |
||||
} |
||||
|
||||
if (this.element.is(":visible") && this.isSetOptions === true) { |
||||
this._setData(); |
||||
this.wants2SetData = null; |
||||
} else { |
||||
this.wants2SetData = true; |
||||
} |
||||
} |
||||
}); |
||||
BI.Chart.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut('bi.chart', BI.Chart); |
@ -0,0 +1,296 @@
|
||||
/** |
||||
* Collection |
||||
* |
||||
* Created by GUY on 2016/1/15. |
||||
* @class BI.Collection |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Collection = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Collection.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-collection", |
||||
width: 400, |
||||
height: 300, |
||||
overflowX: true, |
||||
overflowY: true, |
||||
cellSizeAndPositionGetter: BI.emptyFn, |
||||
horizontalOverscanSize: 0, |
||||
verticalOverscanSize: 0, |
||||
scrollLeft: 0, |
||||
scrollTop: 0, |
||||
items: [] |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Collection.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.renderedCells = []; |
||||
this.renderedKeys = []; |
||||
this._scrollLock = false; |
||||
this._debounceRelease = BI.debounce(function () { |
||||
self._scrollLock = false; |
||||
}, 150); |
||||
this.container = BI.createWidget({ |
||||
type: "bi.absolute" |
||||
}); |
||||
this.element.scroll(function () { |
||||
if (self._scrollLock === true) { |
||||
return; |
||||
} |
||||
o.scrollLeft = self.element.scrollLeft(); |
||||
o.scrollTop = self.element.scrollTop(); |
||||
self._calculateChildrenToRender(); |
||||
self.fireEvent(BI.Collection.EVENT_SCROLL, { |
||||
scrollLeft: o.scrollLeft, |
||||
scrollTop: o.scrollTop |
||||
}); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
scrollable: o.overflowX === true && o.overflowY === true, |
||||
scrolly: o.overflowX === false && o.overflowY === true, |
||||
scrollx: o.overflowX === true && o.overflowY === false, |
||||
items: [this.container] |
||||
}); |
||||
if (o.items.length > 0) { |
||||
this._calculateSizeAndPositionData(); |
||||
this._populate(); |
||||
} |
||||
if (o.scrollLeft !== 0 || o.scrollTop !== 0) { |
||||
BI.nextTick(function () { |
||||
self.element.scrollTop(o.scrollTop); |
||||
self.element.scrollLeft(o.scrollLeft); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_calculateSizeAndPositionData: function () { |
||||
var o = this.options; |
||||
var cellMetadata = []; |
||||
var sectionManager = new BI.SectionManager(); |
||||
var height = 0; |
||||
var width = 0; |
||||
|
||||
for (var index = 0, len = o.items.length; index < len; index++) { |
||||
var cellMetadatum = o.cellSizeAndPositionGetter(index); |
||||
|
||||
if ( |
||||
cellMetadatum.height == null || isNaN(cellMetadatum.height) || |
||||
cellMetadatum.width == null || isNaN(cellMetadatum.width) || |
||||
cellMetadatum.x == null || isNaN(cellMetadatum.x) || |
||||
cellMetadatum.y == null || isNaN(cellMetadatum.y) |
||||
) { |
||||
throw Error(); |
||||
} |
||||
|
||||
height = Math.max(height, cellMetadatum.y + cellMetadatum.height); |
||||
width = Math.max(width, cellMetadatum.x + cellMetadatum.width); |
||||
|
||||
cellMetadatum.index = index; |
||||
cellMetadata[index] = cellMetadatum; |
||||
sectionManager.registerCell(cellMetadatum, index); |
||||
} |
||||
|
||||
this._cellMetadata = cellMetadata; |
||||
this._sectionManager = sectionManager; |
||||
this._height = height; |
||||
this._width = width; |
||||
}, |
||||
|
||||
_cellRenderers: function (height, width, x, y) { |
||||
this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y); |
||||
return this._cellGroupRenderer() |
||||
}, |
||||
|
||||
_cellGroupRenderer: function () { |
||||
var self = this, o = this.options; |
||||
var rendered = []; |
||||
BI.each(this._lastRenderedCellIndices, function (i, index) { |
||||
var cellMetadata = self._sectionManager.getCellMetadata(index); |
||||
rendered.push(cellMetadata); |
||||
}); |
||||
return rendered; |
||||
}, |
||||
|
||||
_calculateChildrenToRender: function () { |
||||
var self = this, o = this.options; |
||||
var scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()); |
||||
var scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()); |
||||
var left = Math.max(0, scrollLeft - o.horizontalOverscanSize); |
||||
var top = Math.max(0, scrollTop - o.verticalOverscanSize); |
||||
var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize); |
||||
var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize); |
||||
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top); |
||||
var renderedCells = [], renderedKeys = []; |
||||
for (var i = 0, len = childrenToDisplay.length; i < len; i++) { |
||||
var datum = childrenToDisplay[i]; |
||||
var index = BI.deepIndexOf(this.renderedKeys, datum.index); |
||||
if (index > -1) { |
||||
if (datum.width !== this.renderedCells[index]._width) { |
||||
this.renderedCells[index]._width = datum.width; |
||||
this.renderedCells[index].el.setWidth(datum.width); |
||||
} |
||||
if (datum.height !== this.renderedCells[index]._height) { |
||||
this.renderedCells[index]._height = datum.height; |
||||
this.renderedCells[index].el.setHeight(datum.height); |
||||
} |
||||
if (this.renderedCells[index].left !== datum.x) { |
||||
this.renderedCells[index].el.element.css("left", datum.x + "px"); |
||||
} |
||||
if (this.renderedCells[index].top !== datum.y) { |
||||
this.renderedCells[index].el.element.css("top", datum.y + "px"); |
||||
} |
||||
renderedCells.push(this.renderedCells[index]); |
||||
} else { |
||||
var child = BI.createWidget(BI.extend({ |
||||
type: "bi.label", |
||||
width: datum.width, |
||||
height: datum.height |
||||
}, o.items[datum.index], { |
||||
cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), |
||||
_left: datum.x, |
||||
_top: datum.y |
||||
})); |
||||
renderedCells.push({ |
||||
el: child, |
||||
left: datum.x, |
||||
top: datum.y, |
||||
_width: datum.width, |
||||
_height: datum.height |
||||
}); |
||||
} |
||||
renderedKeys.push(datum.index); |
||||
} |
||||
//已存在的, 需要添加的和需要删除的
|
||||
var existSet = {}, addSet = {}, deleteArray = []; |
||||
BI.each(renderedKeys, function (i, key) { |
||||
if (BI.deepContains(self.renderedKeys, key)) { |
||||
existSet[i] = key; |
||||
} else { |
||||
addSet[i] = key; |
||||
} |
||||
}); |
||||
BI.each(this.renderedKeys, function (i, key) { |
||||
if (BI.deepContains(existSet, key)) { |
||||
return; |
||||
} |
||||
if (BI.deepContains(addSet, key)) { |
||||
return; |
||||
} |
||||
deleteArray.push(i); |
||||
}); |
||||
BI.each(deleteArray, function (i, index) { |
||||
self.renderedCells[index].el.destroy(); |
||||
}); |
||||
var addedItems = []; |
||||
BI.each(addSet, function (index) { |
||||
addedItems.push(renderedCells[index]) |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.container, |
||||
items: addedItems |
||||
}); |
||||
this.renderedCells = renderedCells; |
||||
this.renderedKeys = renderedKeys; |
||||
}, |
||||
|
||||
_getMaxScrollLeft: function () { |
||||
return Math.max(0, this._width - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0)); |
||||
}, |
||||
|
||||
_getMaxScrollTop: function () { |
||||
return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); |
||||
}, |
||||
|
||||
_populate: function () { |
||||
var o = this.options; |
||||
if (o.items.length > 0) { |
||||
this.container.setWidth(this._width); |
||||
this.container.setHeight(this._height); |
||||
|
||||
this._calculateChildrenToRender(); |
||||
this.element.scrollTop(o.scrollTop); |
||||
this.element.scrollLeft(o.scrollLeft); |
||||
} |
||||
}, |
||||
|
||||
setScrollLeft: function (scrollLeft) { |
||||
if (this.options.scrollLeft === scrollLeft) { |
||||
return; |
||||
} |
||||
this._scrollLock = true; |
||||
this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getMaxScrollLeft()); |
||||
this.element.scrollLeft(this.options.scrollLeft); |
||||
this._debounceRelease(); |
||||
this._calculateChildrenToRender(); |
||||
}, |
||||
|
||||
setScrollTop: function (scrollTop) { |
||||
if (this.options.scrollTop === scrollTop) { |
||||
return; |
||||
} |
||||
this._scrollLock = true; |
||||
this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop()); |
||||
this.element.scrollTop(this.options.scrollTop); |
||||
this._debounceRelease(); |
||||
this._calculateChildrenToRender(); |
||||
}, |
||||
|
||||
setOverflowX: function (b) { |
||||
var self = this; |
||||
if (this.options.overflowX !== !!b) { |
||||
this.options.overflowX = !!b; |
||||
BI.nextTick(function () { |
||||
self.element.css({overflowX: !!b ? "auto" : "hidden"}); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
setOverflowY: function (b) { |
||||
var self = this; |
||||
if (this.options.overflowY !== !!b) { |
||||
this.options.overflowY = !!b; |
||||
BI.nextTick(function () { |
||||
self.element.css({overflowY: !!b ? "auto" : "hidden"}); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
getScrollLeft: function () { |
||||
return this.options.scrollLeft; |
||||
}, |
||||
|
||||
getScrollTop: function () { |
||||
return this.options.scrollTop; |
||||
}, |
||||
|
||||
getMaxScrollLeft: function () { |
||||
return this._getMaxScrollLeft(); |
||||
}, |
||||
|
||||
getMaxScrollTop: function () { |
||||
return this._getMaxScrollTop(); |
||||
}, |
||||
|
||||
restore: function () { |
||||
BI.each(this.renderedCells, function (i, cell) { |
||||
cell.el.destroy(); |
||||
}); |
||||
this.renderedCells = []; |
||||
this.renderedKeys = []; |
||||
this._scrollLock = false; |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
if (items && items !== this.options.items) { |
||||
this.options.items = items; |
||||
this._calculateSizeAndPositionData(); |
||||
} |
||||
this._populate(); |
||||
} |
||||
}); |
||||
BI.Collection.EVENT_SCROLL = "EVENT_SCROLL"; |
||||
$.shortcut('bi.collection_view', BI.Collection); |
@ -0,0 +1,382 @@
|
||||
/** |
||||
* @class BI.Combo |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Combo = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-combo", |
||||
trigger: "click", |
||||
toggle: true, |
||||
direction: "bottom", //top||bottom||left||right||top,left||top,right||bottom,left||bottom,right
|
||||
isDefaultInit: false, |
||||
isNeedAdjustHeight: true,//是否需要高度调整
|
||||
isNeedAdjustWidth: true, |
||||
adjustLength: 0,//调整的距离
|
||||
adjustXOffset: 0, |
||||
adjustYOffset: 0, |
||||
hideChecker: BI.emptyFn, |
||||
offsetStyle: "left", //left,right,center
|
||||
el: {}, |
||||
popup: {}, |
||||
comboClass: "bi-combo-popup", |
||||
hoverClass: "bi-combo-hover" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Combo.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this._initCombo(); |
||||
this._initPullDownAction(); |
||||
this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (self.isEnabled() && this.isEnabled()) { |
||||
if (type === BI.Events.EXPAND) { |
||||
self._popupView(); |
||||
} |
||||
if (type === BI.Events.COLLAPSE) { |
||||
self._hideView(); |
||||
} |
||||
if (type === BI.Events.EXPAND || type === BI.Events.COLLAPSE) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
} |
||||
|
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Combo.EVENT_TRIGGER_CHANGE, obj); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
self.element.on("mouseenter." + self.getName(), function (e) { |
||||
if (self.isEnabled() && self.combo.isEnabled()) { |
||||
self.element.addClass(o.hoverClass); |
||||
} |
||||
}); |
||||
self.element.on("mouseleave." + self.getName(), function (e) { |
||||
if (self.isEnabled() && self.combo.isEnabled()) { |
||||
self.element.removeClass(o.hoverClass); |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.combo} |
||||
] |
||||
}); |
||||
o.isDefaultInit && (this._assertPopupView()); |
||||
BI.Resizers.add(this.getName(), BI.bind(function () { |
||||
if (this.isViewVisible()) { |
||||
this._hideView(); |
||||
} |
||||
}, this)); |
||||
}, |
||||
|
||||
_toggle: function () { |
||||
this._assertPopupViewRender(); |
||||
if (this.popupView.isVisible()) { |
||||
this._hideView(); |
||||
} else { |
||||
if (this.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
_initPullDownAction: function () { |
||||
var self = this, o = this.options; |
||||
var evs = this.options.trigger.split(","); |
||||
BI.each(evs, function (i, ev) { |
||||
switch (ev) { |
||||
case "hover": |
||||
self.element.on("mouseenter." + self.getName(), function (e) { |
||||
if (self.isEnabled() && self.combo.isEnabled()) { |
||||
self._popupView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); |
||||
self.fireEvent(BI.Combo.EVENT_EXPAND); |
||||
} |
||||
}); |
||||
self.element.on("mouseleave." + self.getName(), function (e) { |
||||
if (self.isEnabled() && self.combo.isEnabled() && o.toggle === true) { |
||||
self._hideView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); |
||||
self.fireEvent(BI.Combo.EVENT_COLLAPSE); |
||||
} |
||||
}); |
||||
break; |
||||
case "click": |
||||
if (ev) { |
||||
self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), BI.debounce(function (e) { |
||||
if (self.combo.element.__isMouseInBounds__(e)) { |
||||
if (self.isEnabled() && self.combo.isEnabled()) { |
||||
o.toggle ? self._toggle() : self._popupView(); |
||||
if (self.isViewVisible()) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo); |
||||
self.fireEvent(BI.Combo.EVENT_EXPAND); |
||||
} else { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo); |
||||
self.fireEvent(BI.Combo.EVENT_COLLAPSE); |
||||
} |
||||
} |
||||
} |
||||
}, BI.EVENT_RESPONSE_TIME, true)); |
||||
} |
||||
break; |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_initCombo: function () { |
||||
this.combo = BI.createWidget(this.options.el); |
||||
}, |
||||
|
||||
_assertPopupView: function () { |
||||
var self = this; |
||||
if (this.popupView == null) { |
||||
this.popupView = BI.createWidget(this.options.popup, { |
||||
type: "bi.popup_view" |
||||
}); |
||||
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (type === BI.Events.CLICK) { |
||||
self.combo.setValue(self.getValue()); |
||||
self.fireEvent(BI.Combo.EVENT_CHANGE, value, obj); |
||||
} |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.popupView.setVisible(false); |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.Combo.EVENT_AFTER_INIT); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_assertPopupViewRender: function () { |
||||
this._assertPopupView(); |
||||
if (!this._rendered) { |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.popupView} |
||||
] |
||||
}); |
||||
this._rendered = true; |
||||
} |
||||
}, |
||||
|
||||
_hideIf: function (e) { |
||||
if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) { |
||||
return; |
||||
} |
||||
if (this.element.find(e.target).length > 0) { |
||||
return; |
||||
} |
||||
var isHide = this.options.hideChecker.apply(this, [e]); |
||||
if (isHide === false) { |
||||
return; |
||||
} |
||||
this._hideView(); |
||||
}, |
||||
|
||||
_hideView: function () { |
||||
this.fireEvent(BI.Combo.EVENT_BEFORE_HIDEVIEW); |
||||
this.popupView && this.popupView.invisible(); |
||||
this.element.removeClass(this.options.comboClass); |
||||
|
||||
$(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName()); |
||||
this.fireEvent(BI.Combo.EVENT_AFTER_HIDEVIEW); |
||||
}, |
||||
|
||||
_popupView: function () { |
||||
this._assertPopupViewRender(); |
||||
this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW); |
||||
|
||||
this.popupView.visible(); |
||||
this.adjustWidth(); |
||||
this.adjustHeight(); |
||||
|
||||
this.element.addClass(this.options.comboClass); |
||||
$(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this)); |
||||
this.fireEvent(BI.Combo.EVENT_AFTER_POPUPVIEW); |
||||
}, |
||||
|
||||
adjustWidth: function () { |
||||
var o = this.options; |
||||
if (!this.popupView) { |
||||
return; |
||||
} |
||||
if (o.isNeedAdjustWidth === true) { |
||||
this.resetListWidth(""); |
||||
var width = this.popupView.element.outerWidth(); |
||||
var maxW = this.element.outerWidth() || o.width; |
||||
if (width > maxW + 80) { |
||||
maxW = maxW + 80; |
||||
} else if (width > maxW) { |
||||
maxW = width; |
||||
} |
||||
this.resetListWidth(maxW < 100 ? 100 : maxW); |
||||
} |
||||
}, |
||||
|
||||
adjustHeight: function () { |
||||
var o = this.options, p = {}; |
||||
if (!this.popupView) { |
||||
return; |
||||
} |
||||
var isVisible = this.popupView.isVisible(); |
||||
this.popupView.visible(); |
||||
switch (o.direction) { |
||||
case "bottom": |
||||
case "bottom,right": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ['bottom', 'top', 'right', 'left'], o.offsetStyle); |
||||
break; |
||||
case "top": |
||||
case "top,right": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength,o.isNeedAdjustHeight, ['top', 'bottom', 'right', 'left'], o.offsetStyle); |
||||
break; |
||||
case "left": |
||||
case "left,bottom": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset|| o.adjustLength, o.adjustYOffset,o.isNeedAdjustHeight, ['left', 'right', 'bottom', 'top'], o.offsetStyle); |
||||
break; |
||||
case "right": |
||||
case "right,bottom": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset|| o.adjustLength, o.adjustYOffset,o.isNeedAdjustHeight, ['right', 'left', 'bottom', 'top'], o.offsetStyle); |
||||
break; |
||||
case "top,left": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset|| o.adjustLength,o.isNeedAdjustHeight, ['top', 'bottom', 'left', 'right'], o.offsetStyle); |
||||
break; |
||||
case "bottom,left": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset|| o.adjustLength,o.isNeedAdjustHeight, ['bottom', 'top', 'left', 'right'], o.offsetStyle); |
||||
break; |
||||
case "left,top": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset|| o.adjustLength, o.adjustYOffset,o.isNeedAdjustHeight, ['left', 'right', 'top', 'bottom'], o.offsetStyle); |
||||
break; |
||||
case "right,top": |
||||
p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset|| o.adjustLength, o.adjustYOffset,o.isNeedAdjustHeight, ['right', 'left', 'top', 'bottom'], o.offsetStyle); |
||||
break; |
||||
case "top,custom": |
||||
case "custom,top": |
||||
p = $.getTopAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength,o.isNeedAdjustHeight); |
||||
break; |
||||
case "custom,bottom": |
||||
case "bottom,custom": |
||||
p = $.getBottomAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength,o.isNeedAdjustHeight); |
||||
break; |
||||
case "left,custom": |
||||
case "custom,left": |
||||
p = $.getLeftAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength); |
||||
delete p.top; |
||||
delete p.adaptHeight; |
||||
break; |
||||
case "custom,right": |
||||
case "right,custom": |
||||
p = $.getRightAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength); |
||||
delete p.top; |
||||
delete p.adaptHeight; |
||||
break; |
||||
} |
||||
|
||||
if ("adaptHeight" in p) { |
||||
this.resetListHeight(p['adaptHeight']); |
||||
} |
||||
if ("left" in p) { |
||||
this.popupView.element.css({ |
||||
left: p.left |
||||
}); |
||||
} |
||||
if ("top" in p) { |
||||
this.popupView.element.css({ |
||||
top: p.top |
||||
}); |
||||
} |
||||
this.popupView.setVisible(isVisible); |
||||
}, |
||||
|
||||
resetListHeight: function (h) { |
||||
this._assertPopupView(); |
||||
this.popupView.resetHeight && this.popupView.resetHeight(h); |
||||
}, |
||||
|
||||
resetListWidth: function (w) { |
||||
this._assertPopupView(); |
||||
this.popupView.resetWidth && this.popupView.resetWidth(w); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this._assertPopupView(); |
||||
this.popupView.populate.apply(this.popupView, arguments); |
||||
this.combo.populate.apply(this.combo, arguments); |
||||
}, |
||||
|
||||
setEnable: function (arg) { |
||||
BI.Combo.superclass.setEnable.apply(this, arguments); |
||||
this.combo && this.combo.setEnable(arg); |
||||
this.popupView && this.popupView.setEnable(arg); |
||||
!arg && this._hideView(); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this._assertPopupView(); |
||||
this.combo.setValue(v); |
||||
this.popupView && this.popupView.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
this._assertPopupView(); |
||||
return this.popupView && this.popupView.getValue(); |
||||
}, |
||||
|
||||
isViewVisible: function () { |
||||
return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible(); |
||||
}, |
||||
|
||||
showView: function () { |
||||
if (this.isEnabled() && this.combo.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
}, |
||||
|
||||
hideView: function () { |
||||
this._hideView(); |
||||
}, |
||||
|
||||
getView: function () { |
||||
return this.popupView; |
||||
}, |
||||
|
||||
doBehavior: function () { |
||||
this._assertPopupView(); |
||||
this.popupView && this.popupView.doBehavior.apply(this.popupView, arguments); |
||||
}, |
||||
|
||||
toggle: function () { |
||||
this._toggle(); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
$(document).unbind("mousedown." + this.getName()) |
||||
.unbind("mousewheel." + this.getName()) |
||||
.unbind("mouseenter." + this.getName()) |
||||
.unbind("mousemove." + this.getName()) |
||||
.unbind("mouseleave." + this.getName()); |
||||
BI.Resizers.remove(this.getName()); |
||||
BI.Combo.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Combo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; |
||||
BI.Combo.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Combo.EVENT_EXPAND = "EVENT_EXPAND"; |
||||
BI.Combo.EVENT_COLLAPSE = "EVENT_COLLAPSE"; |
||||
BI.Combo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; |
||||
|
||||
|
||||
BI.Combo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
BI.Combo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; |
||||
BI.Combo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; |
||||
BI.Combo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; |
||||
|
||||
$.shortcut("bi.combo", BI.Combo); |
@ -0,0 +1,273 @@
|
||||
/** |
||||
* |
||||
* 某个可以展开的节点 |
||||
* |
||||
* Created by GUY on 2015/9/10. |
||||
* @class BI.Expander |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Expander = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Expander.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-expander", |
||||
trigger: "click", |
||||
toggle: true, |
||||
//direction: "bottom", //top,bottom四个方向
|
||||
isDefaultInit: false, //是否默认初始化子节点
|
||||
el: {}, |
||||
popup: {}, |
||||
expanderClass: "bi-expander-popup", |
||||
hoverClass: "bi-expander-hover" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Expander.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this._expanded = !!o.el.open; |
||||
this._initExpander(); |
||||
this._initPullDownAction(); |
||||
this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (type === BI.Events.EXPAND) { |
||||
self._popupView(); |
||||
} |
||||
if (type === BI.Events.COLLAPSE) { |
||||
self._hideView(); |
||||
} |
||||
if (self.isEnabled() && this.isEnabled()) { |
||||
if (type === BI.Events.EXPAND || type === BI.Events.COLLAPSE) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
} |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Expander.EVENT_TRIGGER_CHANGE, value, obj); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
this.element.hover(function () { |
||||
if (self.isEnabled() && self.expander.isEnabled()) { |
||||
self.element.addClass(o.hoverClass); |
||||
} |
||||
}, function () { |
||||
if (self.isEnabled() && self.expander.isEnabled()) { |
||||
self.element.removeClass(o.hoverClass); |
||||
} |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.expander} |
||||
] |
||||
}); |
||||
o.isDefaultInit && this._assertPopupView(); |
||||
if (this.expander.isOpened() === true) { |
||||
this._popupView(); |
||||
} |
||||
}, |
||||
|
||||
_toggle: function () { |
||||
this._assertPopupViewRender(); |
||||
if (this.popupView.isVisible()) { |
||||
this._hideView(); |
||||
} else { |
||||
if (this.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
_initPullDownAction: function () { |
||||
var self = this, o = this.options; |
||||
var evs = this.options.trigger.split(","); |
||||
BI.each(evs, function (i, e) { |
||||
switch (e) { |
||||
case "hover": |
||||
self.element[e](function (e) { |
||||
if (self.isEnabled() && self.expander.isEnabled()) { |
||||
self._popupView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, '', self.expander); |
||||
self.fireEvent(BI.Expander.EVENT_EXPAND); |
||||
} |
||||
}, function () { |
||||
if (self.isEnabled() && self.expander.isEnabled() && o.toggle) { |
||||
self._hideView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, '', self.expander); |
||||
self.fireEvent(BI.Expander.EVENT_COLLAPSE); |
||||
} |
||||
}); |
||||
break; |
||||
default : |
||||
if (e) { |
||||
self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { |
||||
if (self.expander.element.__isMouseInBounds__(e)) { |
||||
if (self.isEnabled() && self.expander.isEnabled()) { |
||||
o.toggle ? self._toggle() : self._popupView(); |
||||
if (self.isExpanded()) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander); |
||||
self.fireEvent(BI.Expander.EVENT_EXPAND); |
||||
} else { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, '', self.expander); |
||||
self.fireEvent(BI.Expander.EVENT_COLLAPSE); |
||||
} |
||||
} |
||||
} |
||||
}, BI.EVENT_RESPONSE_TIME, true)); |
||||
} |
||||
break; |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_initExpander: function () { |
||||
this.expander = BI.createWidget(this.options.el); |
||||
}, |
||||
|
||||
_assertPopupView: function () { |
||||
var self = this; |
||||
if (this.popupView == null) { |
||||
this.popupView = BI.createWidget(this.options.popup, { |
||||
type: "bi.button_group", |
||||
cls: "expander-popup", |
||||
layouts: [{ |
||||
type: "bi.vertical", |
||||
hgap: 0, |
||||
vgap: 0 |
||||
}] |
||||
}); |
||||
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
//self.setValue(self.getValue());
|
||||
self.fireEvent(BI.Expander.EVENT_CHANGE, value, obj); |
||||
} |
||||
}); |
||||
this.popupView.setVisible(this.isExpanded()); |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.Expander.EVENT_AFTER_INIT); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_assertPopupViewRender: function () { |
||||
this._assertPopupView(); |
||||
if (!this._rendered) { |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.popupView} |
||||
] |
||||
}); |
||||
this._rendered = true; |
||||
} |
||||
}, |
||||
|
||||
_hideView: function () { |
||||
this.fireEvent(BI.Expander.EVENT_BEFORE_HIDEVIEW); |
||||
this._expanded = false; |
||||
this.expander.setOpened(false); |
||||
this.popupView && this.popupView.invisible(); |
||||
this.element.removeClass(this.options.expanderClass); |
||||
|
||||
this.fireEvent(BI.Expander.EVENT_AFTER_HIDEVIEW); |
||||
}, |
||||
|
||||
_popupView: function () { |
||||
this._assertPopupViewRender(); |
||||
this.fireEvent(BI.Expander.EVENT_BEFORE_POPUPVIEW); |
||||
this._expanded = true; |
||||
this.expander.setOpened(true); |
||||
this.popupView.visible(); |
||||
this.element.addClass(this.options.expanderClass); |
||||
this.fireEvent(BI.Expander.EVENT_AFTER_POPUPVIEW); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
//this._assertPopupView();
|
||||
this.popupView && this.popupView.populate.apply(this.popupView, arguments); |
||||
this.expander.populate.apply(this.expander, arguments); |
||||
}, |
||||
|
||||
setEnable: function (arg) { |
||||
BI.Expander.superclass.setEnable.apply(this, arguments); |
||||
this.expander && this.expander.setEnable(arg); |
||||
this.popupView && this.popupView.setEnable(arg); |
||||
!arg && this._hideView(); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
//this._assertPopupView();
|
||||
this.expander.setValue(v); |
||||
this.popupView && this.popupView.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
//this._assertPopupView();
|
||||
return this.popupView ? this.popupView.getValue() : []; |
||||
}, |
||||
|
||||
isViewVisible: function () { |
||||
return this.isEnabled() && this.expander.isEnabled() && !!this.popupView && this.popupView.isVisible(); |
||||
}, |
||||
|
||||
isExpanded: function () { |
||||
return this._expanded; |
||||
}, |
||||
|
||||
showView: function () { |
||||
if (this.isEnabled() && this.expander.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
}, |
||||
|
||||
hideView: function () { |
||||
this._hideView(); |
||||
}, |
||||
|
||||
getView: function () { |
||||
return this.popupView; |
||||
}, |
||||
|
||||
doBehavior: function () { |
||||
//this._assertPopupView();
|
||||
this.popupView && this.popupView.doBehavior.apply(this.popupView, arguments); |
||||
}, |
||||
|
||||
getAllLeaves: function () { |
||||
return this.popupView && this.popupView.getAllLeaves(); |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
if (this.expander.options.id === id) { |
||||
return this.expander; |
||||
} |
||||
return this.popupView && this.popupView.getNodeById(id); |
||||
}, |
||||
|
||||
getNodeByValue: function (value) { |
||||
if (this.expander.getValue() === value) { |
||||
return this.expander; |
||||
} |
||||
return this.popupView && this.popupView.getNodeByValue(value); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.Expander.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Expander.EVENT_EXPAND = "EVENT_EXPAND"; |
||||
BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE"; |
||||
BI.Expander.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; |
||||
BI.Expander.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Expander.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; |
||||
|
||||
|
||||
BI.Expander.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
BI.Expander.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; |
||||
BI.Expander.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; |
||||
BI.Expander.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; |
||||
|
||||
$.shortcut("bi.expander", BI.Expander); |
@ -0,0 +1,316 @@
|
||||
/** |
||||
* Created by GUY on 2015/6/26. |
||||
* @class BI.ButtonGroup |
||||
* @extends BI.Widget |
||||
*/ |
||||
|
||||
BI.ButtonGroup = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ButtonGroup.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-button-group", |
||||
behaviors: {}, |
||||
items: [ |
||||
{ |
||||
el: {type: "bi.text_button", text: "", value: ""} |
||||
} |
||||
], |
||||
chooseType: BI.Selection.Single, |
||||
layouts: [{ |
||||
type: "bi.center", |
||||
hgap: 0, |
||||
vgap: 0 |
||||
}] |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ButtonGroup.superclass._init.apply(this, arguments); |
||||
var behaviors = {}; |
||||
BI.each(this.options.behaviors, function (key, rule) { |
||||
behaviors[key] = BI.BehaviorFactory.createBehavior(key, { |
||||
rule: rule |
||||
}) |
||||
}); |
||||
this.behaviors = behaviors; |
||||
this.populate(this.options.items); |
||||
}, |
||||
|
||||
_createBtns: function (items) { |
||||
var o = this.options; |
||||
return BI.createWidgets(BI.createItems(items, { |
||||
type: "bi.text_button" |
||||
})); |
||||
}, |
||||
|
||||
_btnsCreator: function (items) { |
||||
var self = this, args = Array.prototype.slice.call(arguments), o = this.options; |
||||
var buttons = this._createBtns(items); |
||||
args[0] = buttons; |
||||
|
||||
BI.each(this.behaviors, function (i, behavior) { |
||||
behavior.doBehavior.apply(behavior, args); |
||||
}); |
||||
BI.each(buttons, function (i, btn) { |
||||
btn.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (type === BI.Events.CLICK) { |
||||
switch (o.chooseType) { |
||||
case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: |
||||
self.setValue(btn.getValue()); |
||||
break; |
||||
case BI.ButtonGroup.CHOOSE_TYPE_NONE: |
||||
self.setValue([]); |
||||
break; |
||||
} |
||||
self.fireEvent(BI.ButtonGroup.EVENT_CHANGE, value, obj); |
||||
} |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
btn.on(BI.Events.DESTROY, function () { |
||||
BI.remove(self.buttons, btn); |
||||
}) |
||||
}); |
||||
|
||||
return buttons; |
||||
}, |
||||
|
||||
_packageBtns: function (btns) { |
||||
var o = this.options; |
||||
|
||||
for (var i = o.layouts.length - 1; i > 0; i--) { |
||||
btns = BI.map(btns, function (k, it) { |
||||
return BI.extend({}, o.layouts[i], { |
||||
items: [ |
||||
BI.extend({}, o.layouts[i].el, { |
||||
el: it |
||||
}) |
||||
] |
||||
}) |
||||
}) |
||||
} |
||||
return btns; |
||||
}, |
||||
|
||||
_packageItems: function (items, packBtns) { |
||||
return BI.createItems(BI.makeArrayByArray(items, {}), BI.clone(packBtns)); |
||||
}, |
||||
|
||||
_packageLayout: function (items) { |
||||
var o = this.options, layout = BI.deepClone(o.layouts[0]); |
||||
|
||||
var lay = BI.formatEL(layout).el; |
||||
while (lay && lay.items && !BI.isEmpty(lay.items)) { |
||||
lay = BI.formatEL(lay.items[0]).el; |
||||
} |
||||
lay.items = items; |
||||
return layout; |
||||
}, |
||||
|
||||
|
||||
doBehavior: function () { |
||||
var args = Array.prototype.slice.call(arguments); |
||||
args.unshift(this.buttons); |
||||
BI.each(this.behaviors, function (i, behavior) { |
||||
behavior.doBehavior.apply(behavior, args); |
||||
}) |
||||
}, |
||||
|
||||
prependItems: function (items) { |
||||
var o = this.options; |
||||
var btns = this._btnsCreator.apply(this, arguments); |
||||
this.buttons = BI.concat(btns, this.buttons); |
||||
|
||||
//如果是一个简单的layout
|
||||
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) |
||||
&& this.layouts && this.layouts.prependItems) { |
||||
this.layouts.prependItems(btns); |
||||
return; |
||||
} |
||||
|
||||
var items = this._packageItems(items, this._packageBtns(btns)); |
||||
BI.createWidget(BI.extend(this._packageLayout(items))).element.children().prependTo(this.element); |
||||
}, |
||||
|
||||
addItems: function (items) { |
||||
var o = this.options; |
||||
var btns = this._btnsCreator.apply(this, arguments); |
||||
this.buttons = BI.concat(this.buttons, btns); |
||||
|
||||
//如果是一个简单的layout
|
||||
if (o.layouts.length === 1 && !BI.isNotEmptyArray(o.layouts[0].items) |
||||
&& this.layouts && this.layouts.addItems) { |
||||
this.layouts.addItems(btns); |
||||
return; |
||||
} |
||||
|
||||
var items = this._packageItems(items, this._packageBtns(btns)); |
||||
BI.createWidget(BI.extend(this._packageLayout(items))).element.children().appendTo(this.element); |
||||
}, |
||||
|
||||
removeItemAt: function (indexes) { |
||||
var self = this; |
||||
indexes = BI.isArray(indexes) ? indexes : [indexes]; |
||||
var buttons = []; |
||||
BI.each(indexes, function (i, index) { |
||||
buttons.push(self.buttons[index]); |
||||
}); |
||||
BI.each(buttons, function (i, btn) { |
||||
btn && btn.destroy(); |
||||
}) |
||||
}, |
||||
|
||||
removeItems: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
var indexes = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
indexes.push(i); |
||||
} |
||||
}); |
||||
this.removeItemAt(indexes); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.options.items = items || []; |
||||
this.empty(); |
||||
|
||||
this.buttons = this._btnsCreator.apply(this, arguments); |
||||
var items = this._packageItems(items, this._packageBtns(this.buttons)); |
||||
|
||||
this.layouts = BI.createWidget(BI.extend({element: this.element}, this._packageLayout(items))); |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.ButtonGroup.superclass.setEnable.apply(this, arguments); |
||||
BI.each(this.buttons, function (i, item) { |
||||
item.setEnable(b); |
||||
}); |
||||
}, |
||||
|
||||
setNotSelectedValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setSelected && item.setSelected(false); |
||||
} else { |
||||
item.setSelected && item.setSelected(true); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setEnabledValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setEnable(true); |
||||
} else { |
||||
item.setEnable(false); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setSelected && item.setSelected(true); |
||||
} else { |
||||
item.setSelected && item.setSelected(false); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
getNotSelectedValue: function () { |
||||
var v = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !(item.isSelected && item.isSelected())) { |
||||
v.push(item.getValue()); |
||||
} |
||||
}); |
||||
return v; |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var v = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && item.isSelected && item.isSelected()) { |
||||
v.push(item.getValue()); |
||||
} |
||||
}); |
||||
return v; |
||||
}, |
||||
|
||||
getAllButtons: function () { |
||||
return this.buttons; |
||||
}, |
||||
|
||||
getAllLeaves: function () { |
||||
return this.buttons; |
||||
}, |
||||
|
||||
getSelectedButtons: function () { |
||||
var btns = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isSelected && item.isSelected()) { |
||||
btns.push(item); |
||||
} |
||||
}); |
||||
return btns; |
||||
}, |
||||
|
||||
getNotSelectedButtons: function () { |
||||
var btns = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isSelected && !item.isSelected()) { |
||||
btns.push(item); |
||||
} |
||||
}); |
||||
return btns; |
||||
}, |
||||
|
||||
getIndexByValue: function (value) { |
||||
var index = -1; |
||||
BI.any(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && item.getValue() === value) { |
||||
index = i; |
||||
return true; |
||||
} |
||||
}); |
||||
return index; |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
var node; |
||||
BI.any(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && item.options.id === id) { |
||||
node = item; |
||||
return true; |
||||
} |
||||
}); |
||||
return node; |
||||
}, |
||||
|
||||
getNodeByValue: function (value) { |
||||
var node; |
||||
BI.any(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && item.getValue() === value) { |
||||
node = item; |
||||
return true; |
||||
} |
||||
}); |
||||
return node; |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.ButtonGroup.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.extend(BI.ButtonGroup, { |
||||
CHOOSE_TYPE_SINGLE: BI.Selection.Single, |
||||
CHOOSE_TYPE_MULTI: BI.Selection.Multi, |
||||
CHOOSE_TYPE_ALL: BI.Selection.All, |
||||
CHOOSE_TYPE_NONE: BI.Selection.None, |
||||
CHOOSE_TYPE_DEFAULT: BI.Selection.Default |
||||
}); |
||||
BI.ButtonGroup.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.button_group", BI.ButtonGroup); |
@ -0,0 +1,101 @@
|
||||
/** |
||||
* Created by GUY on 2015/8/10. |
||||
*/ |
||||
|
||||
BI.ComboGroup = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ComboGroup.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-combo-group", |
||||
|
||||
//以下这些属性对每一个combo都是公用的
|
||||
trigger: "click,hover", |
||||
direction: "right", |
||||
adjustLength: 0, |
||||
isDefaultInit: false, |
||||
isNeedAdjustHeight: false, |
||||
isNeedAdjustWidth: false, |
||||
|
||||
el: {type: "bi.text_button", text: "", value: ""}, |
||||
children: [], |
||||
|
||||
popup: { |
||||
el: { |
||||
type: "bi.button_tree", |
||||
chooseType: 0, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ComboGroup.superclass._init.apply(this, arguments); |
||||
this.populate(this.options.el); |
||||
}, |
||||
|
||||
populate: function (item) { |
||||
var self = this, o = this.options; |
||||
var children = o.children; |
||||
if (BI.isEmpty(children)) { |
||||
throw new Error("ComboGroup构造错误"); |
||||
} |
||||
BI.each(children, function (i, ch) { |
||||
var son = BI.formatEL(ch).el.children; |
||||
ch = BI.formatEL(ch).el; |
||||
if (!BI.isEmpty(son)) { |
||||
ch.el = BI.clone(ch); |
||||
ch.children = son; |
||||
ch.type = "bi.combo_group"; |
||||
ch.action = o.action; |
||||
ch.height = o.height; |
||||
ch.direction = o.direction; |
||||
ch.isDefaultInit = o.isDefaultInit; |
||||
ch.isNeedAdjustHeight = o.isNeedAdjustHeight; |
||||
ch.isNeedAdjustWidth = o.isNeedAdjustWidth; |
||||
ch.adjustLength = o.adjustLength; |
||||
ch.popup = o.popup; |
||||
} |
||||
}) |
||||
this.combo = BI.createWidget({ |
||||
type: "bi.combo", |
||||
element: this.element, |
||||
height: o.height, |
||||
trigger: o.trigger, |
||||
direction: o.direction, |
||||
isDefaultInit: o.isDefaultInit, |
||||
isNeedAdjustWidth: o.isNeedAdjustWidth, |
||||
isNeedAdjustHeight: o.isNeedAdjustHeight, |
||||
adjustLength: o.adjustLength, |
||||
el: item, |
||||
popup: BI.extend({}, o.popup, { |
||||
el: BI.extend({ |
||||
items: children |
||||
}, o.popup.el) |
||||
}) |
||||
}) |
||||
this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.ComboGroup.EVENT_CHANGE, obj); |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.ComboGroup.superclass.setEnable.apply(this, arguments); |
||||
this.combo && this.combo.setEnable(b); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.combo.getValue(); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.combo.setValue(v); |
||||
} |
||||
}); |
||||
BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.combo_group", BI.ComboGroup); |
@ -0,0 +1,262 @@
|
||||
/** |
||||
* 加载控件 |
||||
* |
||||
* Created by GUY on 2015/8/31. |
||||
* @class BI.Loader |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Loader = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Loader.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-loader", |
||||
|
||||
direction: "top", |
||||
isDefaultInit: true,//是否默认初始化数据
|
||||
logic: { |
||||
dynamic: true, |
||||
scrolly: true |
||||
}, |
||||
|
||||
//下面是button_group的属性
|
||||
el: { |
||||
type: "bi.button_group" |
||||
}, |
||||
|
||||
items: [], |
||||
itemsCreator: BI.emptyFn, |
||||
onLoaded: BI.emptyFn, |
||||
|
||||
//下面是分页信息
|
||||
count: false, |
||||
prev: false, |
||||
next: {}, |
||||
hasPrev: BI.emptyFn, |
||||
hasNext: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_prevLoad: function () { |
||||
var self = this, o = this.options; |
||||
this.prev.setLoading(); |
||||
o.itemsCreator.apply(this, [{times: --this.times}, function () { |
||||
self.prev.setLoaded(); |
||||
self.prependItems.apply(self, arguments); |
||||
}]); |
||||
}, |
||||
|
||||
_nextLoad: function () { |
||||
var self = this, o = this.options; |
||||
this.next.setLoading(); |
||||
o.itemsCreator.apply(this, [{times: ++this.times}, function () { |
||||
self.next.setLoaded(); |
||||
self.addItems.apply(self, arguments); |
||||
}]); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Loader.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
if (o.itemsCreator === false) { |
||||
o.prev = false; |
||||
o.next = false; |
||||
} |
||||
if (o.prev !== false) { |
||||
this.prev = BI.createWidget(BI.extend({ |
||||
type: "bi.loading_bar" |
||||
}, o.prev)); |
||||
this.prev.on(BI.Controller.EVENT_CHANGE, function (type) { |
||||
if (type === BI.Events.CLICK) { |
||||
self._prevLoad(); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
this.button_group = BI.createWidget(o.el, { |
||||
type: "bi.button_group", |
||||
chooseType: 0, |
||||
items: o.items, |
||||
behaviors: {}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
}); |
||||
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Loader.EVENT_CHANGE, obj); |
||||
} |
||||
}); |
||||
|
||||
if (o.next !== false) { |
||||
this.next = BI.createWidget(BI.extend({ |
||||
type: "bi.loading_bar" |
||||
}, o.next)); |
||||
this.next.on(BI.Controller.EVENT_CHANGE, function (type) { |
||||
if (type === BI.Events.CLICK) { |
||||
self._nextLoad(); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ |
||||
scrolly: true |
||||
}, o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.prev, this.button_group, this.next) |
||||
})))); |
||||
|
||||
o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () { |
||||
o.isDefaultInit && BI.isEmpty(o.items) && this.populate(); |
||||
}, this)); |
||||
if (BI.isNotEmptyArray(o.items)) { |
||||
this.populate(o.items); |
||||
} |
||||
}, |
||||
|
||||
hasPrev: function () { |
||||
var o = this.options; |
||||
if (BI.isNumber(o.count)) { |
||||
return this.count < o.count; |
||||
} |
||||
return !!o.hasPrev.apply(this, [{ |
||||
times: this.times, |
||||
count: this.count |
||||
}]) |
||||
}, |
||||
|
||||
hasNext: function () { |
||||
var o = this.options; |
||||
if (BI.isNumber(o.count)) { |
||||
return this.count < o.count; |
||||
} |
||||
return !!o.hasNext.apply(this, [{ |
||||
times: this.times, |
||||
count: this.count |
||||
}]) |
||||
}, |
||||
|
||||
prependItems: function (items) { |
||||
this.count += items.length; |
||||
if (this.next !== false) { |
||||
if (this.hasPrev()) { |
||||
this.options.items = this.options.items.concat(items); |
||||
this.prev.setLoaded(); |
||||
} else { |
||||
this.prev.setEnd(); |
||||
} |
||||
} |
||||
this.button_group.prependItems.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
addItems: function (items) { |
||||
this.count += items.length; |
||||
if (BI.isObject(this.next)) { |
||||
if (this.hasNext()) { |
||||
this.options.items = this.options.items.concat(items); |
||||
this.next.setLoaded(); |
||||
} else { |
||||
this.next.setEnd(); |
||||
} |
||||
} |
||||
this.button_group.addItems.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
var self = this, o = this.options; |
||||
if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) { |
||||
o.itemsCreator.apply(this, [{times: 1}, function () { |
||||
if (arguments.length === 0) { |
||||
throw new Error("arguments can not be null!!!"); |
||||
} |
||||
self.populate.apply(self, arguments); |
||||
o.onLoaded(); |
||||
}]); |
||||
return; |
||||
} |
||||
this.options.items = items; |
||||
this.times = 1; |
||||
this.count = 0; |
||||
this.count += items.length; |
||||
if (BI.isObject(this.next)) { |
||||
if (this.hasNext()) { |
||||
this.next.setLoaded(); |
||||
} else { |
||||
this.next.invisible(); |
||||
} |
||||
} |
||||
if (BI.isObject(this.prev)) { |
||||
if (this.hasPrev()) { |
||||
this.prev.setLoaded(); |
||||
} else { |
||||
this.prev.invisible(); |
||||
} |
||||
} |
||||
this.button_group.populate.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
setEnable: function (v) { |
||||
this.button_group.setEnable(v); |
||||
}, |
||||
|
||||
doBehavior: function () { |
||||
this.button_group.doBehavior.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
setNotSelectedValue: function () { |
||||
this.button_group.setNotSelectedValue.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
getNotSelectedValue: function () { |
||||
return this.button_group.getNotSelectedValue(); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
this.button_group.setValue.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.button_group.getValue.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
getAllButtons: function () { |
||||
return this.button_group.getAllButtons(); |
||||
}, |
||||
|
||||
getAllLeaves: function () { |
||||
return this.button_group.getAllLeaves(); |
||||
}, |
||||
|
||||
getSelectedButtons: function () { |
||||
return this.button_group.getSelectedButtons(); |
||||
}, |
||||
|
||||
getNotSelectedButtons: function () { |
||||
return this.button_group.getNotSelectedButtons(); |
||||
}, |
||||
|
||||
getIndexByValue: function (value) { |
||||
return this.button_group.getIndexByValue(value); |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
return this.button_group.getNodeById(id); |
||||
}, |
||||
|
||||
getNodeByValue: function (value) { |
||||
return this.button_group.getNodeByValue(value); |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.button_group.empty(); |
||||
BI.each([this.prev, this.next], function (i, ob) { |
||||
ob && ob.setVisible(false); |
||||
}); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.Loader.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Loader.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.loader", BI.Loader); |
@ -0,0 +1,138 @@
|
||||
/** |
||||
* Created by GUY on 2015/6/26. |
||||
*/ |
||||
|
||||
BI.Navigation = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function(){ |
||||
return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this,arguments), { |
||||
direction: "bottom",//top, bottom, left, right, custom
|
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
defaultShowIndex: 0, |
||||
tab: { |
||||
type: "bi.button_group", |
||||
items: [], |
||||
layouts: [] |
||||
}, |
||||
cardCreator: function(v){ |
||||
return BI.createWidget(); |
||||
}, |
||||
|
||||
afterCardCreated: BI.emptyFn, |
||||
afterCardShow: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_init: function(){ |
||||
BI.Navigation.superclass._init.apply(this,arguments); |
||||
var self = this, o = this.options; |
||||
this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); |
||||
this.cardMap = {}; |
||||
this.showIndex = 0; |
||||
this.layout = BI.createWidget({ |
||||
type: "bi.card" |
||||
}); |
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) |
||||
})))); |
||||
|
||||
|
||||
new BI.ShowListener({ |
||||
eventObj: this.tab, |
||||
cardLayout: this.layout, |
||||
cardNameCreator: function(v){ |
||||
return self.showIndex + v; |
||||
}, |
||||
cardCreator: function(v){ |
||||
var card = o.cardCreator(v); |
||||
self.cardMap[v] = card; |
||||
return card; |
||||
}, |
||||
afterCardCreated: BI.bind(this.afterCardCreated, this), |
||||
afterCardShow: BI.bind(this.afterCardShow, this) |
||||
}) |
||||
if(o.defaultShowIndex !== false){ |
||||
this.setSelect(o.defaultShowIndex); |
||||
} |
||||
}, |
||||
|
||||
afterCardCreated: function(v){ |
||||
var self = this; |
||||
this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function(type, value, obj){ |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if(type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Navigation.EVENT_CHANGE, obj); |
||||
} |
||||
}) |
||||
this.options.afterCardCreated.apply(this, arguments); |
||||
}, |
||||
|
||||
afterCardShow: function(v){ |
||||
this.showIndex = v; |
||||
this.options.afterCardShow.apply(this, arguments); |
||||
}, |
||||
|
||||
populate: function(){ |
||||
var card = this.layout.getShowingCard(); |
||||
if(card){ |
||||
return card.populate.apply(card, arguments); |
||||
} |
||||
}, |
||||
|
||||
setSelect: function(v){ |
||||
this.showIndex = v; |
||||
if(!this.layout.isCardExisted(v)){ |
||||
var card = this.options.cardCreator(v); |
||||
this.cardMap[v] = card; |
||||
this.layout.addCardByName(v, card); |
||||
this.afterCardCreated(v); |
||||
} |
||||
this.layout.showCardByName(v); |
||||
BI.nextTick(BI.bind(this.afterCardShow, this, v)); |
||||
}, |
||||
|
||||
getSelect: function(){ |
||||
return this.showIndex; |
||||
}, |
||||
|
||||
getSelectedCard: function(){ |
||||
if(BI.isKey(this.showIndex)){ |
||||
return this.cardMap[this.showIndex]; |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* @override |
||||
*/ |
||||
setValue: function(v){ |
||||
var card = this.layout.getShowingCard(); |
||||
if(card){ |
||||
card.setValue(v); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* @override |
||||
*/ |
||||
getValue: function(){ |
||||
var card = this.layout.getShowingCard(); |
||||
if(card){ |
||||
return card.getValue(); |
||||
} |
||||
}, |
||||
|
||||
empty: function(){ |
||||
this.layout.deleteAllCard(); |
||||
this.cardMap = {}; |
||||
}, |
||||
|
||||
destroy: function(){ |
||||
BI.Navigation.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.navigation", BI.Navigation); |
@ -0,0 +1,298 @@
|
||||
/** |
||||
* 搜索逻辑控件 |
||||
* |
||||
* Created by GUY on 2015/9/28. |
||||
* @class BI.Searcher |
||||
* @extends BI.Widget |
||||
*/ |
||||
|
||||
BI.Searcher = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Searcher.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-searcher", |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
vgap: 0, |
||||
hgap: 0, |
||||
|
||||
isDefaultInit: false, |
||||
isAutoSearch: true, //是否自动搜索
|
||||
isAutoSync: true, //是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一
|
||||
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, |
||||
|
||||
//isAutoSearch为false时启用
|
||||
onSearch: function (op, callback) { |
||||
callback([]) |
||||
}, |
||||
|
||||
|
||||
el: { |
||||
type: "bi.search_editor" |
||||
}, |
||||
|
||||
popup: { |
||||
type: "bi.searcher_view" |
||||
}, |
||||
|
||||
adapter: null, |
||||
masker: { //masker层
|
||||
offset: {} |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Searcher.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
|
||||
this.editor = BI.createWidget(o.el, { |
||||
type: "bi.search_editor" |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
vgap: o.vgap, |
||||
hgap: o.hgap, |
||||
items: [this.editor] |
||||
}); |
||||
o.isDefaultInit && (this._assertPopupView()); |
||||
|
||||
var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, true); |
||||
this.editor.on(BI.Controller.EVENT_CHANGE, function (type) { |
||||
switch (type) { |
||||
case BI.Events.STARTEDIT: |
||||
self._startSearch(); |
||||
break; |
||||
case BI.Events.EMPTY: |
||||
self._stopSearch(); |
||||
break; |
||||
case BI.Events.CHANGE: |
||||
search(); |
||||
break; |
||||
case BI.Events.PAUSE: |
||||
self._pauseSearch(); |
||||
break; |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_assertPopupView: function () { |
||||
var self = this, o = this.options; |
||||
if (!BI.Maskers.has(this.getName())) { |
||||
this.popupView = BI.createWidget(o.popup, { |
||||
type: "bi.searcher_view", |
||||
chooseType: o.chooseType |
||||
}); |
||||
BI.Maskers.create(this.getName(), o.adapter, { |
||||
offset: o.masker.offset, |
||||
container: this, |
||||
render: this.popupView |
||||
}); |
||||
|
||||
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
if (o.isAutoSync) { |
||||
var values = o.adapter.getValue(); |
||||
if (!obj.isSelected()) { |
||||
o.adapter.setValue(BI.deepWithout(values, obj.getValue())); |
||||
} else { |
||||
switch (o.chooseType) { |
||||
case BI.ButtonGroup.CHOOSE_TYPE_SINGLE: |
||||
o.adapter.setValue([obj.getValue()]); |
||||
break; |
||||
case BI.ButtonGroup.CHOOSE_TYPE_MULTI: |
||||
values.push(obj.getValue()); |
||||
o.adapter.setValue(values); |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj); |
||||
} |
||||
}); |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_startSearch: function () { |
||||
this._assertPopupView(); |
||||
this._stop = false; |
||||
this._isSearching = true; |
||||
this.fireEvent(BI.Searcher.EVENT_START); |
||||
this.popupView.startSearch && this.popupView.startSearch(); |
||||
//搜索前先清空dom
|
||||
BI.Maskers.get(this.getName()).empty(); |
||||
BI.nextTick(function (name) { |
||||
BI.Maskers.show(name); |
||||
}, this.getName()); |
||||
}, |
||||
|
||||
_pauseSearch: function () { |
||||
var o = this.options, name = this.getName(); |
||||
this._stop = true; |
||||
BI.Maskers.hide(name); |
||||
if (BI.Maskers.has(name) && this._isSearching === true) { |
||||
this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); |
||||
this.fireEvent(BI.Searcher.EVENT_PAUSE); |
||||
} |
||||
this._isSearching = false; |
||||
}, |
||||
|
||||
_stopSearch: function () { |
||||
var o = this.options, name = this.getName(); |
||||
this._stop = true; |
||||
BI.Maskers.hide(name); |
||||
if (BI.Maskers.has(name) && this._isSearching === true) { |
||||
//搜索后清空dom
|
||||
BI.nextTick(function () { |
||||
BI.Maskers.has(name) && BI.Maskers.get(name).empty(); |
||||
}); |
||||
this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); |
||||
this.fireEvent(BI.Searcher.EVENT_STOP); |
||||
} |
||||
this._isSearching = false; |
||||
}, |
||||
|
||||
_search: function () { |
||||
var self = this, o = this.options, keyword = this.editor.getValue(); |
||||
if (keyword === "" || this._stop) { |
||||
return; |
||||
} |
||||
if (o.isAutoSearch) { |
||||
var items = (o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items") || []; |
||||
var finding = BI.Func.getSearchResult(items, keyword); |
||||
var matched = finding.matched, finded = finding.finded; |
||||
this.popupView.populate(finded, matched, keyword); |
||||
o.isAutoSync && this.popupView.setValue(o.adapter.getValue()); |
||||
self.fireEvent(BI.Searcher.EVENT_SEARCHING); |
||||
return; |
||||
} |
||||
this.popupView.loading && this.popupView.loading(); |
||||
o.onSearch({ |
||||
times: 1, |
||||
keyword: keyword, |
||||
selectedValues: o.adapter.getValue() |
||||
}, function (searchResult, matchResult) { |
||||
if (!self._stop) { |
||||
var args = [].slice.call(arguments); |
||||
if (args.length > 0) { |
||||
args.push(keyword); |
||||
} |
||||
BI.Maskers.show(self.getName()); |
||||
self.popupView.populate.apply(self.popupView, args); |
||||
o.isAutoSync && self.popupView.setValue(o.adapter.getValue()); |
||||
self.popupView.loaded && self.popupView.loaded(); |
||||
self.fireEvent(BI.Searcher.EVENT_SEARCHING); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setAdapter: function (adapter) { |
||||
this.options.adapter = adapter; |
||||
BI.Maskers.remove(this.getName()); |
||||
}, |
||||
|
||||
doSearch: function () { |
||||
if (this.isSearching()) { |
||||
this._search(); |
||||
} |
||||
}, |
||||
|
||||
stopSearch: function () { |
||||
this._stopSearch();//先停止搜索,然后再去设置editor为空
|
||||
//important:停止搜索必须退出编辑状态,这里必须加上try(input框不显示时blur会抛异常)
|
||||
try { |
||||
this.editor.blur(); |
||||
} catch (e) { |
||||
if (!this.editor.blur) { |
||||
throw new Error("editor没有实现blur方法"); |
||||
} |
||||
} finally { |
||||
this.editor.setValue(""); |
||||
} |
||||
}, |
||||
|
||||
isSearching: function () { |
||||
return this._isSearching; |
||||
}, |
||||
|
||||
isViewVisible: function () { |
||||
return this.editor.isEnabled() && BI.Maskers.isVisible(this.getName()); |
||||
}, |
||||
|
||||
getView: function () { |
||||
return this.popupView; |
||||
}, |
||||
|
||||
hasMatched: function () { |
||||
this._assertPopupView(); |
||||
return this.popupView.hasMatched(); |
||||
}, |
||||
|
||||
adjustHeight: function () { |
||||
if (BI.Maskers.has(this.getName()) && BI.Maskers.get(this.getName()).isVisible()) { |
||||
BI.Maskers.show(this.getName()); |
||||
} |
||||
}, |
||||
|
||||
adjustView: function () { |
||||
this.isViewVisible() && BI.Maskers.show(this.getName()); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this._assertPopupView(); |
||||
this.popupView && this.popupView.setValue(v); |
||||
}, |
||||
|
||||
getKeyword: function () { |
||||
return this.editor.getValue(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var o = this.options; |
||||
if (o.isAutoSync) { |
||||
return o.adapter.getValue(); |
||||
} |
||||
if (this.isSearching()) { |
||||
return this.popupView.getValue(); |
||||
} else { |
||||
return o.adapter.getValue(); |
||||
} |
||||
}, |
||||
|
||||
populate: function (result, searchResult, keyword) { |
||||
var o = this.options; |
||||
this._assertPopupView(); |
||||
this.popupView.populate.apply(this.popupView, arguments); |
||||
if (o.isAutoSync) { |
||||
this.popupView.setValue(o.adapter.getValue()); |
||||
} |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.popupView && this.popupView.empty(); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.Maskers.remove(this.getName()); |
||||
BI.Searcher.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Searcher.EVENT_START = "EVENT_START"; |
||||
BI.Searcher.EVENT_STOP = "EVENT_STOP"; |
||||
BI.Searcher.EVENT_PAUSE = "EVENT_PAUSE"; |
||||
BI.Searcher.EVENT_SEARCHING = "EVENT_SEARCHING"; |
||||
BI.Searcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; |
||||
|
||||
$.shortcut("bi.searcher", BI.Searcher); |
@ -0,0 +1,277 @@
|
||||
/** |
||||
* |
||||
* 切换显示或隐藏面板 |
||||
* |
||||
* Created by GUY on 2015/11/2. |
||||
* @class BI.Switcher |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Switcher = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Switcher.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-switcher", |
||||
direction: BI.Direction.Top, |
||||
trigger: "click", |
||||
toggle: true, |
||||
el: {}, |
||||
popup: {}, |
||||
adapter: null, |
||||
masker: {}, |
||||
switcherClass: "bi-switcher-popup", |
||||
hoverClass: "bi-switcher-hover" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Switcher.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this._initSwitcher(); |
||||
this._initPullDownAction(); |
||||
this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (self.isEnabled() && this.isEnabled()) { |
||||
if (type === BI.Events.EXPAND) { |
||||
self._popupView(); |
||||
} |
||||
if (type === BI.Events.COLLAPSE) { |
||||
self._hideView(); |
||||
} |
||||
if (type === BI.Events.EXPAND || type === BI.Events.COLLAPSE) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
} |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Switcher.EVENT_TRIGGER_CHANGE, value, obj); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
this.element.hover(function () { |
||||
if (self.isEnabled() && self.switcher.isEnabled()) { |
||||
self.element.addClass(o.hoverClass); |
||||
} |
||||
}, function () { |
||||
if (self.isEnabled() && self.switcher.isEnabled()) { |
||||
self.element.removeClass(o.hoverClass); |
||||
} |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.switcher} |
||||
] |
||||
}); |
||||
o.isDefaultInit && (this._assertPopupView()); |
||||
}, |
||||
|
||||
_toggle: function () { |
||||
this._assertPopupView(); |
||||
if (this.isExpanded()) { |
||||
this._hideView(); |
||||
} else { |
||||
if (this.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
_initPullDownAction: function () { |
||||
var self = this, o = this.options; |
||||
var evs = this.options.trigger.split(","); |
||||
BI.each(evs, function (i, e) { |
||||
switch (e) { |
||||
case "hover": |
||||
self.element[e](function (e) { |
||||
if (self.isEnabled() && self.switcher.isEnabled()) { |
||||
self._popupView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, '', self.switcher); |
||||
self.fireEvent(BI.Switcher.EVENT_EXPAND); |
||||
} |
||||
}, function () { |
||||
if (self.isEnabled() && self.switcher.isEnabled() && o.toggle) { |
||||
self._hideView(); |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, '', self.switcher); |
||||
self.fireEvent(BI.Switcher.EVENT_COLLAPSE); |
||||
} |
||||
}); |
||||
break; |
||||
default : |
||||
if (e) { |
||||
self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) { |
||||
if (self.switcher.element.__isMouseInBounds__(e)) { |
||||
if (self.isEnabled() && self.switcher.isEnabled()) { |
||||
o.toggle ? self._toggle() : self._popupView(); |
||||
if (self.isExpanded()) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, '', self.switcher); |
||||
self.fireEvent(BI.Switcher.EVENT_EXPAND); |
||||
} else { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, '', self.switcher); |
||||
self.fireEvent(BI.Switcher.EVENT_COLLAPSE); |
||||
} |
||||
} |
||||
} |
||||
}, BI.EVENT_RESPONSE_TIME, true)); |
||||
} |
||||
break; |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_initSwitcher: function () { |
||||
this.switcher = BI.createWidget(this.options.el); |
||||
}, |
||||
|
||||
_assertPopupView: function () { |
||||
var self = this, o = this.options; |
||||
if (!this._created) { |
||||
this.popupView = BI.createWidget(o.popup, { |
||||
type: "bi.button_group", |
||||
element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({container: this}, o.masker)), |
||||
cls: "switcher-popup", |
||||
layouts: [{ |
||||
type: "bi.vertical", |
||||
hgap: 0, |
||||
vgap: 0 |
||||
}] |
||||
}); |
||||
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.Switcher.EVENT_CHANGE, value, obj); |
||||
} |
||||
}); |
||||
if (o.direction !== BI.Direction.Custom && !o.adapter) { |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [ |
||||
{el: this.popupView} |
||||
] |
||||
}); |
||||
} |
||||
this._created = true; |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.Switcher.EVENT_AFTER_INIT); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_hideView: function () { |
||||
this.fireEvent(BI.Switcher.EVENT_BEFORE_HIDEVIEW); |
||||
var self = this, o = this.options; |
||||
o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); |
||||
BI.nextTick(function () { |
||||
o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false)); |
||||
self.element.removeClass(o.switcherClass); |
||||
self.fireEvent(BI.Switcher.EVENT_AFTER_HIDEVIEW); |
||||
}); |
||||
}, |
||||
|
||||
_popupView: function () { |
||||
var self = this, o = this.options; |
||||
this._assertPopupView(); |
||||
this.fireEvent(BI.Switcher.EVENT_BEFORE_POPUPVIEW); |
||||
o.adapter ? BI.Maskers.show(this.getName()) : self.popupView.setVisible(true); |
||||
BI.nextTick(function (name) { |
||||
o.adapter ? BI.Maskers.show(name) : self.popupView.setVisible(true); |
||||
self.element.addClass(o.switcherClass); |
||||
self.fireEvent(BI.Switcher.EVENT_AFTER_POPUPVIEW); |
||||
}, this.getName()); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this._assertPopupView(); |
||||
this.popupView.populate.apply(this.popupView, arguments); |
||||
this.switcher.populate.apply(this.switcher, arguments); |
||||
}, |
||||
|
||||
setEnable: function (arg) { |
||||
BI.Switcher.superclass.setEnable.apply(this, arguments); |
||||
this.switcher && this.switcher.setEnable(arg); |
||||
this.popupView && this.popupView.setEnable(arg); |
||||
!arg && this._hideView(); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this._assertPopupView(); |
||||
this.switcher.setValue(v); |
||||
this.popupView && this.popupView.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
this._assertPopupView(); |
||||
return this.popupView ? this.popupView.getValue() : []; |
||||
}, |
||||
|
||||
isViewVisible: function () { |
||||
return this.isEnabled() && this.switcher.isEnabled() && |
||||
(this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); |
||||
}, |
||||
|
||||
isExpanded: function () { |
||||
return this.isViewVisible(); |
||||
}, |
||||
|
||||
showView: function () { |
||||
if (this.isEnabled() && this.switcher.isEnabled()) { |
||||
this._popupView(); |
||||
} |
||||
}, |
||||
|
||||
hideView: function () { |
||||
this._hideView(); |
||||
}, |
||||
|
||||
getView: function () { |
||||
return this.popupView; |
||||
}, |
||||
|
||||
adjustView: function () { |
||||
this.isViewVisible() && BI.Maskers.show(this.getName()); |
||||
}, |
||||
|
||||
doBehavior: function () { |
||||
this._assertPopupView(); |
||||
this.popupView && this.popupView.doBehavior.apply(this.popupView, arguments); |
||||
}, |
||||
|
||||
getAllLeaves: function () { |
||||
return this.popupView && this.popupView.getAllLeaves(); |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
if (this.switcher.attr("id") === id) { |
||||
return this.switcher; |
||||
} |
||||
return this.popupView && this.popupView.getNodeById(id); |
||||
}, |
||||
|
||||
getNodeByValue: function (value) { |
||||
if (this.switcher.getValue() === value) { |
||||
return this.switcher; |
||||
} |
||||
return this.popupView && this.popupView.getNodeByValue(value); |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.popupView && this.popupView.empty(); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.Switcher.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND"; |
||||
BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE"; |
||||
BI.Switcher.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE"; |
||||
BI.Switcher.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Switcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT"; |
||||
|
||||
|
||||
BI.Switcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; |
||||
BI.Switcher.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW"; |
||||
BI.Switcher.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW"; |
||||
BI.Switcher.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; |
||||
|
||||
$.shortcut("bi.switcher", BI.Switcher); |
@ -0,0 +1,124 @@
|
||||
/** |
||||
* Created by GUY on 2015/6/26. |
||||
*/ |
||||
|
||||
BI.Tab = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-tab", |
||||
direction: "top",//top, bottom, left, right, custom
|
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
defaultShowIndex: 0, |
||||
tab: false, |
||||
cardCreator: function (v) { |
||||
return BI.createWidget(); |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Tab.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
if (BI.isObject(o.tab)) { |
||||
this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"}); |
||||
this.tab.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}) |
||||
} |
||||
this.cardMap = {}; |
||||
this.layout = BI.createWidget({ |
||||
type: "bi.card" |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout) |
||||
})))); |
||||
|
||||
var listener = new BI.ShowListener({ |
||||
eventObj: this.tab, |
||||
cardLayout: this.layout, |
||||
cardCreator: function (v) { |
||||
var card = o.cardCreator.apply(self, arguments); |
||||
self.cardMap[v] = card; |
||||
return card; |
||||
}, |
||||
afterCardShow: function (v) { |
||||
self.curr = v; |
||||
} |
||||
}); |
||||
listener.on(BI.ShowListener.EVENT_CHANGE, function (value) { |
||||
self.fireEvent(BI.Tab.EVENT_CHANGE, value, self); |
||||
}); |
||||
if (o.defaultShowIndex !== false) { |
||||
this.setSelect(o.defaultShowIndex); |
||||
} |
||||
}, |
||||
|
||||
_assertCard: function (v) { |
||||
if (!this.layout.isCardExisted(v)) { |
||||
var card = this.options.cardCreator(v); |
||||
this.cardMap[v] = card; |
||||
this.layout.addCardByName(v, card); |
||||
} |
||||
}, |
||||
|
||||
setSelect: function (v) { |
||||
this.tab && this.tab.setValue(v); |
||||
this._assertCard(v); |
||||
this.layout.showCardByName(v); |
||||
if (this.curr !== v) { |
||||
this.curr = v; |
||||
} |
||||
}, |
||||
|
||||
getSelect: function () { |
||||
return this.curr; |
||||
}, |
||||
|
||||
getSelectedTab: function () { |
||||
return this.layout.getShowingCard(); |
||||
}, |
||||
|
||||
getTab: function (v) { |
||||
this._assertCard(v); |
||||
return this.layout.getCardByName(v); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
var card = this.layout.getShowingCard(); |
||||
if (card) { |
||||
card.setValue(v); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var card = this.layout.getShowingCard(); |
||||
if (card) { |
||||
return card.getValue(); |
||||
} |
||||
}, |
||||
|
||||
populate: function () { |
||||
var card = this.layout.getShowingCard(); |
||||
if (card) { |
||||
return card.populate && card.populate.apply(card, arguments); |
||||
} |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.layout.deleteAllCard(); |
||||
this.cardMap = {}; |
||||
}, |
||||
|
||||
destroy: function () { |
||||
this.cardMap = {}; |
||||
BI.Tab.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.Tab.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.tab", BI.Tab); |
@ -0,0 +1,298 @@
|
||||
/** |
||||
* Created by GUY on 2015/8/10. |
||||
* @class BI.ButtonTree |
||||
* @extends BI.ButtonGroup |
||||
*/ |
||||
|
||||
BI.ButtonTree = BI.inherit(BI.ButtonGroup, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ButtonTree.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-button-tree" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ButtonTree.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
setNotSelectedValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (!BI.isFunction(item.setSelected)) { |
||||
item.setNotSelectedValue(v); |
||||
return; |
||||
} |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setSelected(false); |
||||
} else { |
||||
item.setSelected(true); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setEnabledValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (BI.isFunction(item.setEnabledValue)) { |
||||
item.setEnabledValue(v); |
||||
return; |
||||
} |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setEnable(true); |
||||
} else { |
||||
item.setEnable(false); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (!BI.isFunction(item.setSelected)) { |
||||
item.setValue(v); |
||||
return; |
||||
} |
||||
if (BI.deepContains(v, item.getValue())) { |
||||
item.setSelected(true); |
||||
} else { |
||||
item.setSelected(false); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
getNotSelectedValue: function () { |
||||
var v = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { |
||||
v = BI.concat(v, item.getNotSelectedValue()); |
||||
return; |
||||
} |
||||
if (item.isEnabled() && item.isSelected && !item.isSelected()) { |
||||
v.push(item.getValue()); |
||||
} |
||||
}); |
||||
return v; |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var v = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { |
||||
v = BI.concat(v, item.getValue()); |
||||
return; |
||||
} |
||||
if (item.isEnabled() && item.isSelected && item.isSelected()) { |
||||
v.push(item.getValue()); |
||||
} |
||||
}); |
||||
return v; |
||||
}, |
||||
|
||||
getSelectedButtons: function () { |
||||
var btns = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { |
||||
btns = btns.concat(item.getSelectedButtons()); |
||||
return; |
||||
} |
||||
if (item.isSelected && item.isSelected()) { |
||||
btns.push(item); |
||||
} |
||||
}); |
||||
return btns; |
||||
}, |
||||
|
||||
getNotSelectedButtons: function () { |
||||
var btns = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { |
||||
btns = btns.concat(item.getNotSelectedButtons()); |
||||
return; |
||||
} |
||||
if (item.isSelected && !item.isSelected()) { |
||||
btns.push(item); |
||||
} |
||||
}); |
||||
return btns; |
||||
}, |
||||
|
||||
//获取所有的叶子节点
|
||||
getAllLeaves: function () { |
||||
var leaves = []; |
||||
BI.each(this.buttons, function (i, item) { |
||||
if (item.isEnabled() && !BI.isFunction(item.setSelected)) { |
||||
leaves = leaves.concat(item.getAllLeaves()); |
||||
return; |
||||
} |
||||
if (item.isEnabled()) { |
||||
leaves.push(item); |
||||
} |
||||
}); |
||||
return leaves; |
||||
}, |
||||
|
||||
getIndexByValue: function (value) { |
||||
var index = -1; |
||||
BI.any(this.buttons, function (i, item) { |
||||
var vs = item.getValue(); |
||||
if (item.isEnabled() && (vs === value || BI.contains(vs, value))) { |
||||
index = i; |
||||
return true; |
||||
} |
||||
}); |
||||
return index; |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
var node; |
||||
BI.any(this.buttons, function (i, item) { |
||||
if (item.isEnabled()) { |
||||
if (item.attr("id") === id) { |
||||
node = item; |
||||
return true; |
||||
} else if (BI.isFunction(item.getNodeById)) { |
||||
if (node = item.getNodeById(id)) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
return node; |
||||
}, |
||||
|
||||
getNodeByValue: function (value) { |
||||
var node; |
||||
BI.any(this.buttons, function (i, item) { |
||||
if (item.isEnabled()) { |
||||
if (item.getValue() === value) { |
||||
node = item; |
||||
return true; |
||||
} else if (BI.isFunction(item.getNodeByValue)) { |
||||
if (node = item.getNodeByValue(value)) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
return node; |
||||
} |
||||
}); |
||||
BI.ButtonTree.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.button_tree", BI.ButtonTree); |
||||
|
||||
/** |
||||
* value作为key值缓存button, 不支持顺序读写 |
||||
* 适合用于频繁增删的一组button |
||||
* Created by GUY on 2015/8/10. |
||||
* @class BI.ButtonMap |
||||
* @extends BI.ButtonTree |
||||
*/ |
||||
|
||||
BI.ButtonMap = BI.inherit(BI.ButtonTree, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ButtonMap.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-button-map" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ButtonMap.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
_createBtns: function (items) { |
||||
var self = this, o = this.options; |
||||
var buttons = BI.createWidgets(BI.createItems(items, {type: "bi.text_button", once: o.chooseType === 0})); |
||||
var keys = BI.map(items, function (i, item) { |
||||
item = BI.stripEL(item); |
||||
if (!(item.id || item.value)) { |
||||
throw new Error("item必须包含id或value属性"); |
||||
} |
||||
return item.id || item.value; |
||||
}); |
||||
return BI.object(keys, buttons); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
var self = this; |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (val, item) { |
||||
if (!BI.isFunction(item.setSelected)) { |
||||
item.setValue(v); |
||||
return; |
||||
} |
||||
if (v.contains(val)) { |
||||
item.setSelected && item.setSelected(true); |
||||
} else { |
||||
item.setSelected && item.setSelected(false); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
setNotSelectedValue: function (v) { |
||||
var self = this; |
||||
v = BI.isArray(v) ? v : [v]; |
||||
BI.each(this.buttons, function (val, item) { |
||||
if (!BI.isFunction(item.setSelected)) { |
||||
item.setNotSelectedValue(v); |
||||
return; |
||||
} |
||||
if (v.contains(val)) { |
||||
item.setSelected && item.setSelected(false); |
||||
} else { |
||||
item.setSelected && item.setSelected(true); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
var self = this; |
||||
var args = [].slice.call(arguments); |
||||
var linkHashMap = new BI.LinkHashMap(); |
||||
var val = function (item) { |
||||
return item.id || item.value; |
||||
}; |
||||
if (!this.buttons) { |
||||
this.buttons = {}; |
||||
} |
||||
//所有已存在的和新添加的
|
||||
var willCreated = []; |
||||
BI.each(items, function (i, item) { |
||||
item = BI.stripEL(item); |
||||
if (self.buttons[val(item)]) { |
||||
var ob = self.buttons[val(item)]; |
||||
args[0] = item.items; |
||||
args[2] = item; |
||||
ob.populate && ob.populate.apply(ob, args); |
||||
} else { |
||||
willCreated.push(item); |
||||
} |
||||
}); |
||||
//创建新元素
|
||||
args[0] = willCreated; |
||||
var newBtns = this._btnsCreator.apply(this, args); |
||||
|
||||
//整理
|
||||
var array = []; |
||||
BI.each(items, function (i, item) { |
||||
item = BI.stripEL(item); |
||||
var button = self.buttons[val(item)] || newBtns[val(item)]; |
||||
linkHashMap.add(val(item), button); |
||||
array.push(button); |
||||
}); |
||||
this.buttons = linkHashMap.map; |
||||
|
||||
BI.DOM.hang(this.buttons); |
||||
this.empty(); |
||||
|
||||
var packages = this._packageItems(items, this._packageBtns(array)); |
||||
BI.createWidget(BI.extend({element: this.element}, this._packageLayout(packages))); |
||||
}, |
||||
|
||||
getIndexByValue: function (value) { |
||||
throw new Error("不能使用getIndexByValue方法"); |
||||
} |
||||
}); |
||||
BI.ButtonMap.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.button_map", BI.ButtonMap); |
@ -0,0 +1,42 @@
|
||||
/** |
||||
* 表示当前对象 |
||||
* |
||||
* Created by GUY on 2015/9/7. |
||||
* @class BI.EL |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.EL = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-el", |
||||
el: {}, |
||||
layout: {} |
||||
}); |
||||
}, |
||||
_init: function () { |
||||
BI.EL.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.ele = BI.createWidget(o.el); |
||||
BI.createWidget(o.layout, { |
||||
type: "bi.adaptive", |
||||
element: this.element, |
||||
items: [this.ele] |
||||
}); |
||||
this.ele.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}) |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.ele.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.ele.getValue(); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.ele.populate.apply(this, arguments); |
||||
} |
||||
}); |
||||
$.shortcut('bi.el', BI.EL); |
@ -0,0 +1,36 @@
|
||||
/** |
||||
* 选色控件 |
||||
* |
||||
* Created by GUY on 2015/11/16. |
||||
* @class BI.Farbtastic |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Farbtastic = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Farbtastic.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-farbtastic", |
||||
width: 195, |
||||
height: 195 |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Farbtastic.superclass._init.apply(this, arguments); |
||||
var self = this; |
||||
|
||||
this.farbtastic = $.farbtastic(this.element, function (v) { |
||||
self.fireEvent(BI.Farbtastic.EVENT_CHANGE, self.getValue(), self); |
||||
}); |
||||
}, |
||||
|
||||
setValue: function (color) { |
||||
this.farbtastic.setColor(color); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.farbtastic.color; |
||||
} |
||||
}); |
||||
BI.Farbtastic.EVENT_CHANGE = "Farbtastic.EVENT_CHANGE"; |
||||
$.shortcut("bi.farbtastic", BI.Farbtastic); |
@ -0,0 +1,228 @@
|
||||
; |
||||
(function ($) { |
||||
/** |
||||
* 公式编辑控件 |
||||
* @class BI.FormulaEditor |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.FormulaEditor = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
return $.extend(BI.FormulaEditor.superclass._defaultConfig.apply(), { |
||||
baseCls: 'bi-formula-editor', |
||||
watermark: '', |
||||
value: '', |
||||
fieldTextValueMap: {} |
||||
}); |
||||
}, |
||||
_init: function () { |
||||
BI.FormulaEditor.superclass._init.apply(this, arguments); |
||||
var o = this.options, self = this; |
||||
this.editor = CodeMirror(this.element[0], { |
||||
textWrapping: true, |
||||
lineWrapping: true, |
||||
lineNumbers: false, |
||||
mode: 'formula' |
||||
}); |
||||
this.editor.on("change", function (cm, change) { |
||||
self._checkWaterMark(); |
||||
CodeMirror.showHint(cm, CodeMirror.formulaHint, {completeSingle: false}); |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.FormulaEditor.EVENT_CHANGE) |
||||
}); |
||||
}); |
||||
|
||||
this.editor.on("focus", function () { |
||||
self._checkWaterMark(); |
||||
self.fireEvent(BI.FormulaEditor.EVENT_FOCUS); |
||||
}); |
||||
|
||||
this.editor.on("blur", function () { |
||||
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); |
||||
}); |
||||
|
||||
|
||||
if (BI.isKey(o.value)) { |
||||
self.setValue(o.value); |
||||
} |
||||
|
||||
if (BI.isKey(this.options.watermark)) { |
||||
var self = this; |
||||
this.watermark = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "bi-water-mark", |
||||
text: this.options.watermark, |
||||
whiteSpace: "nowrap", |
||||
textAlign: "left" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: self.element, |
||||
items: [{ |
||||
el: self.watermark, |
||||
left: 0, |
||||
top: 0 |
||||
}] |
||||
}); |
||||
|
||||
this.watermark.element.bind( |
||||
"mousedown", function (e) { |
||||
self.insertString(""); |
||||
self.editor.focus(); |
||||
e.stopEvent(); |
||||
} |
||||
); |
||||
this.watermark.element.bind("click", function (e) { |
||||
self.editor.focus(); |
||||
e.stopEvent(); |
||||
}); |
||||
this.watermark.element.css({ |
||||
position: "absolute", |
||||
left: 3, |
||||
right: 3, |
||||
top: 6, |
||||
bottom: 0 |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_checkWaterMark: function () { |
||||
var o = this.options; |
||||
if (!this.disabledWarterMark && BI.isEmptyString(this.editor.getValue()) && BI.isKey(o.watermark)) { |
||||
this.watermark && this.watermark.visible(); |
||||
} else { |
||||
this.watermark && this.watermark.invisible(); |
||||
} |
||||
}, |
||||
|
||||
disableWarterMark: function () { |
||||
this.disabledWarterMark = true; |
||||
this._checkWaterMark(); |
||||
}, |
||||
|
||||
/** |
||||
* 添加字段 |
||||
* @param field |
||||
*/ |
||||
insertField: function (field) { |
||||
var from = this.editor.getCursor(); |
||||
this.editor.replaceSelection(field); |
||||
var to = this.editor.getCursor(); |
||||
this.editor.markText(from, to, {className: 'fieldName', atomic: true, startStyle : "start", endStyle:"end"}); |
||||
this.editor.replaceSelection(" "); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
insertFunction: function (fn) { |
||||
var from = this.editor.getCursor(); |
||||
this.editor.replaceSelection(fn); |
||||
var to = this.editor.getCursor(); |
||||
this.editor.markText(from, to, {className: "#function", atomic: true}); |
||||
this.editor.replaceSelection("() "); |
||||
to = this.editor.getCursor(); |
||||
to.ch = to.ch - 2; |
||||
this.editor.setCursor(to); |
||||
this.editor.focus(); |
||||
}, |
||||
insertOperator: function (op) { |
||||
var from = this.editor.getCursor(); |
||||
this.editor.replaceSelection(op); |
||||
var to = this.editor.getCursor(); |
||||
this.editor.markText(from, to, {className: "%operator", atomic: true}); |
||||
this.editor.replaceSelection(" "); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
setFunction: function (v) { |
||||
var from = this.editor.getCursor(); |
||||
this.editor.replaceSelection(v); |
||||
var to = this.editor.getCursor(); |
||||
this.editor.markText(from, to, {className: "#function", atomic: true}); |
||||
}, |
||||
|
||||
insertString: function (str) { |
||||
this.editor.replaceSelection(str); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
getFormulaString: function () { |
||||
return this.editor.getValue(); |
||||
}, |
||||
|
||||
getUsedFields: function () { |
||||
var fieldMap = this.options.fieldTextValueMap; |
||||
var fields = []; |
||||
this.editor.getValue(true, function (line) { |
||||
var value = line.text; |
||||
_.forEach(line.markedSpans, function (i, ms) { |
||||
switch (i.marker.className) { |
||||
case "fieldName": |
||||
var dId = fieldMap[value.substr(i.from, i.to - i.from)]; |
||||
if (!fields.contains(dId)) { |
||||
fields.push(dId); |
||||
} |
||||
|
||||
} |
||||
}); |
||||
}); |
||||
return fields; |
||||
}, |
||||
|
||||
getCheckString: function () { |
||||
return this.editor.getValue(true, function (line) { |
||||
var rawText = line.text, value = line.text, num = 0; |
||||
value.text = rawText; |
||||
_.forEach(line.markedSpans, function (i, ms) { |
||||
|
||||
switch (i.marker.className) { |
||||
case "fieldName": |
||||
var fieldNameLength = i.to - i.from; |
||||
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); |
||||
num = num + 2 - fieldNameLength; |
||||
break; |
||||
} |
||||
|
||||
}); |
||||
return value; |
||||
}); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var fieldMap = this.options.fieldTextValueMap; |
||||
return this.editor.getValue("\n", function (line) { |
||||
var rawText = line.text, value = line.text, num = 0; |
||||
value.text = rawText; |
||||
_.forEach(line.markedSpans, function (i, ms) { |
||||
switch (i.marker.className) { |
||||
case "fieldName": |
||||
var fieldNameLength = i.to - i.from; |
||||
var fieldId = fieldMap[value.substr(i.from + num, fieldNameLength)]; |
||||
value = value.substr(0, i.from + num) + "$\{" + fieldMap[value.substr(i.from + num, fieldNameLength)] + "\}" + value.substr(i.to + num, value.length); |
||||
num += fieldId.length - fieldNameLength + 3; |
||||
break; |
||||
} |
||||
}); |
||||
return value; |
||||
}); |
||||
}, |
||||
|
||||
setValue: function (value) { |
||||
this.editor.setValue(value); |
||||
}, |
||||
|
||||
setFieldTextValueMap: function (fieldTextValueMap) { |
||||
this.options.fieldTextValueMap = fieldTextValueMap; |
||||
}, |
||||
|
||||
refresh: function () { |
||||
var self = this; |
||||
BI.nextTick(function () { |
||||
self.editor.refresh(); |
||||
}); |
||||
} |
||||
|
||||
}); |
||||
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
$.shortcut("bi.formula", BI.FormulaEditor); |
||||
})(jQuery); |
@ -0,0 +1,170 @@
|
||||
/** |
||||
* z-index在1亿层级 |
||||
* 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现) |
||||
* @class BI.Msg |
||||
*/ |
||||
$.extend(BI, { |
||||
Msg: function () { |
||||
|
||||
var messageShow, $mask, $pop; |
||||
|
||||
return { |
||||
toast: function (message, level, context) { |
||||
context = context || $("body"); |
||||
var toast = BI.createWidget({ |
||||
type: "bi.toast", |
||||
level: level, |
||||
text: message |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: context, |
||||
items: [{ |
||||
el: toast, |
||||
left: "50%", |
||||
top: 0 |
||||
}] |
||||
}); |
||||
if (toast.element.outerWidth() > context.outerWidth()) { |
||||
toast.setWidth(context.width()); |
||||
} |
||||
toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2}); |
||||
toast.invisible(); |
||||
toast.element.slideDown(500, function () { |
||||
BI.delay(function () { |
||||
toast.element.slideUp(500, function () { |
||||
toast.destroy(); |
||||
}) |
||||
}, 5000) |
||||
}) |
||||
}, |
||||
_show: function (hasCancel, title, message, callback) { |
||||
$mask = $('<div class="bi-message-mask">').css({ |
||||
position: 'absolute', |
||||
'zIndex': 99999998, |
||||
top: 0, |
||||
left: 0, |
||||
right: 0, |
||||
bottom: 0, |
||||
opacity: 0.1 |
||||
}).appendTo('body'); |
||||
$pop = $('<div class="bi-message-depend">').css({ |
||||
position: 'absolute', |
||||
'zIndex': 99999999, |
||||
top: 0, |
||||
left: 0, |
||||
right: 0, |
||||
bottom: 0 |
||||
}).appendTo('body'); |
||||
var close = function () { |
||||
messageShow.destroy(); |
||||
$mask.remove(); |
||||
}; |
||||
var controlItems = []; |
||||
if (hasCancel === true) { |
||||
controlItems.push({ |
||||
el: { |
||||
type: 'bi.button', |
||||
text: BI.i18nText("BI-Cancel"), |
||||
height: 30, |
||||
level: 'ignore', |
||||
handler: function () { |
||||
close(); |
||||
if (BI.isFunction(callback)) { |
||||
callback.apply(null, [false]); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
controlItems.push({ |
||||
el: { |
||||
type: 'bi.button', |
||||
text: BI.i18nText("BI-OK"), |
||||
height: 30, |
||||
handler: function () { |
||||
close(); |
||||
if (BI.isFunction(callback)) { |
||||
callback.apply(null, [true]); |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
var conf = { |
||||
element: $pop, |
||||
type: 'bi.center_adapt', |
||||
items: [ |
||||
{ |
||||
type: 'bi.border', |
||||
cls: 'bi-message-content', |
||||
items: { |
||||
'north': { |
||||
el: { |
||||
type: 'bi.border', |
||||
cls: 'bi-message-title', |
||||
items: { |
||||
center: { |
||||
el: { |
||||
type: 'bi.label', |
||||
text: title || BI.i18nText("BI-Prompt"), |
||||
textAlign: 'left', |
||||
hgap: 20, |
||||
height: 50 |
||||
} |
||||
}, |
||||
east: { |
||||
el: { |
||||
type: 'bi.icon_button', |
||||
cls: 'bi-message-close close-font', |
||||
// height: 50,
|
||||
handler: function () { |
||||
close(); |
||||
} |
||||
}, |
||||
width: 60 |
||||
} |
||||
} |
||||
}, |
||||
height: 50 |
||||
}, |
||||
'center': { |
||||
el: { |
||||
type: "bi.text", |
||||
cls: "bi-message-text", |
||||
tgap: 60, |
||||
hgap: 20, |
||||
lineHeight: 30, |
||||
whiteSpace: "normal", |
||||
text: message |
||||
} |
||||
}, |
||||
'south': { |
||||
el: { |
||||
type: "bi.absolute", |
||||
items: [{ |
||||
el: { |
||||
type: 'bi.right_vertical_adapt', |
||||
hgap: 5, |
||||
items: controlItems |
||||
}, |
||||
top: 0, |
||||
left: 20, |
||||
right: 20, |
||||
bottom: 0 |
||||
}] |
||||
|
||||
}, |
||||
height: 60 |
||||
} |
||||
}, |
||||
width: 400, |
||||
height: 300 |
||||
} |
||||
] |
||||
}; |
||||
|
||||
messageShow = BI.createWidget(conf); |
||||
} |
||||
}; |
||||
}() |
||||
}); |
@ -0,0 +1,298 @@
|
||||
/** |
||||
* Grid |
||||
* |
||||
* Created by GUY on 2016/1/11. |
||||
* @class BI.Grid |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Grid = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Grid.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-grid", |
||||
width: 400, |
||||
height: 300, |
||||
overflowX: true, |
||||
overflowY: true, |
||||
overscanColumnCount: 0, |
||||
overscanRowCount: 0, |
||||
rowHeightGetter: BI.emptyFn, |
||||
columnWidthGetter: BI.emptyFn, |
||||
estimatedColumnSize: 100, |
||||
estimatedRowSize: 30, |
||||
scrollLeft: 0, |
||||
scrollTop: 0, |
||||
items: [] |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Grid.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.renderedCells = []; |
||||
this.renderedKeys = []; |
||||
this._scrollLock = false; |
||||
this._debounceRelease = BI.debounce(function () { |
||||
self._scrollLock = false; |
||||
}, 150); |
||||
this.container = BI.createWidget({ |
||||
type: "bi.absolute" |
||||
}); |
||||
this.element.scroll(function () { |
||||
if (self._scrollLock === true) { |
||||
return; |
||||
} |
||||
o.scrollLeft = self.element.scrollLeft(); |
||||
o.scrollTop = self.element.scrollTop(); |
||||
self._calculateChildrenToRender(); |
||||
self.fireEvent(BI.Grid.EVENT_SCROLL, { |
||||
scrollLeft: o.scrollLeft, |
||||
scrollTop: o.scrollTop |
||||
}); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
scrollable: o.overflowX === true && o.overflowY === true, |
||||
scrolly: o.overflowX === false && o.overflowY === true, |
||||
scrollx: o.overflowX === true && o.overflowY === false, |
||||
items: [this.container] |
||||
}); |
||||
if (o.items.length > 0) { |
||||
this._populate(); |
||||
} |
||||
if (o.scrollLeft !== 0 || o.scrollTop !== 0) { |
||||
BI.nextTick(function () { |
||||
self.element.scrollTop(o.scrollTop); |
||||
self.element.scrollLeft(o.scrollLeft); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) { |
||||
return { |
||||
overscanStartIndex: Math.max(0, startIndex - overscanCellsCount), |
||||
overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount) |
||||
} |
||||
}, |
||||
|
||||
_calculateChildrenToRender: function () { |
||||
var self = this, o = this.options; |
||||
|
||||
var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()), scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()), |
||||
overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount; |
||||
|
||||
if (height > 0 && width > 0) { |
||||
var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft); |
||||
var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop); |
||||
|
||||
var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft); |
||||
var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop); |
||||
|
||||
this._renderedColumnStartIndex = visibleColumnIndices.start; |
||||
this._renderedColumnStopIndex = visibleColumnIndices.stop; |
||||
this._renderedRowStartIndex = visibleRowIndices.start; |
||||
this._renderedRowStopIndex = visibleRowIndices.stop; |
||||
|
||||
var overscanColumnIndices = this._getOverscanIndices(this.columnCount, overscanColumnCount, this._renderedColumnStartIndex, this._renderedColumnStopIndex) |
||||
|
||||
var overscanRowIndices = this._getOverscanIndices(this.rowCount, overscanRowCount, this._renderedRowStartIndex, this._renderedRowStopIndex); |
||||
|
||||
var columnStartIndex = overscanColumnIndices.overscanStartIndex; |
||||
var columnStopIndex = overscanColumnIndices.overscanStopIndex; |
||||
var rowStartIndex = overscanRowIndices.overscanStartIndex; |
||||
var rowStopIndex = overscanRowIndices.overscanStopIndex; |
||||
|
||||
var renderedCells = [], renderedKeys = []; |
||||
|
||||
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { |
||||
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); |
||||
|
||||
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) { |
||||
var key = [rowIndex, columnIndex]; |
||||
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); |
||||
|
||||
var index = BI.deepIndexOf(this.renderedKeys, key); |
||||
if (index > -1) { |
||||
if (columnDatum.size !== this.renderedCells[index]._width) { |
||||
this.renderedCells[index]._width = columnDatum.size; |
||||
this.renderedCells[index].el.setWidth(columnDatum.size); |
||||
} |
||||
if (rowDatum.size !== this.renderedCells[index]._height) { |
||||
this.renderedCells[index]._height = rowDatum.size; |
||||
this.renderedCells[index].el.setHeight(rowDatum.size); |
||||
} |
||||
if (this.renderedCells[index].left !== columnDatum.offset + horizontalOffsetAdjustment) { |
||||
this.renderedCells[index].el.element.css("left", (columnDatum.offset + horizontalOffsetAdjustment) + "px"); |
||||
} |
||||
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { |
||||
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); |
||||
} |
||||
renderedCells.push(this.renderedCells[index]); |
||||
} else { |
||||
var child = BI.createWidget(BI.extend({ |
||||
type: "bi.label", |
||||
width: columnDatum.size, |
||||
height: rowDatum.size |
||||
}, o.items[rowIndex][columnIndex], { |
||||
cls: (o.items[rowIndex][columnIndex].cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""), |
||||
_rowIndex: rowIndex, |
||||
_columnIndex: columnIndex, |
||||
_left: columnDatum.offset + horizontalOffsetAdjustment, |
||||
_top: rowDatum.offset + verticalOffsetAdjustment |
||||
})); |
||||
renderedCells.push({ |
||||
el: child, |
||||
left: columnDatum.offset + horizontalOffsetAdjustment, |
||||
top: rowDatum.offset + verticalOffsetAdjustment, |
||||
_width: columnDatum.size, |
||||
_height: rowDatum.size |
||||
}); |
||||
} |
||||
renderedKeys.push(key); |
||||
} |
||||
} |
||||
//已存在的, 需要添加的和需要删除的
|
||||
var existSet = {}, addSet = {}, deleteArray = []; |
||||
BI.each(renderedKeys, function (i, key) { |
||||
if (BI.deepContains(self.renderedKeys, key)) { |
||||
existSet[i] = key; |
||||
} else { |
||||
addSet[i] = key; |
||||
} |
||||
}); |
||||
BI.each(this.renderedKeys, function (i, key) { |
||||
if (BI.deepContains(existSet, key)) { |
||||
return; |
||||
} |
||||
if (BI.deepContains(addSet, key)) { |
||||
return; |
||||
} |
||||
deleteArray.push(i); |
||||
}); |
||||
BI.each(deleteArray, function (i, index) { |
||||
self.renderedCells[index].el.destroy(); |
||||
}); |
||||
var addedItems = []; |
||||
BI.each(addSet, function (index) { |
||||
addedItems.push(renderedCells[index]) |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.container, |
||||
items: addedItems |
||||
}); |
||||
this.renderedCells = renderedCells; |
||||
this.renderedKeys = renderedKeys; |
||||
} |
||||
}, |
||||
|
||||
_getMaxScrollLeft: function () { |
||||
return Math.max(0, this._columnSizeAndPositionManager.getTotalSize() - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0)); |
||||
}, |
||||
|
||||
_getMaxScrollTop: function () { |
||||
return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0)); |
||||
}, |
||||
|
||||
_populate: function () { |
||||
var self = this, o = this.options; |
||||
if (o.items.length > 0) { |
||||
this.columnCount = o.items[0].length; |
||||
this.rowCount = o.items.length; |
||||
this.container.setWidth(this.columnCount * o.estimatedColumnSize); |
||||
this.container.setHeight(this.rowCount * o.estimatedRowSize); |
||||
|
||||
this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.columnCount, o.columnWidthGetter, o.estimatedColumnSize); |
||||
this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.rowCount, o.rowHeightGetter, o.estimatedRowSize); |
||||
|
||||
this._calculateChildrenToRender(); |
||||
this.element.scrollTop(o.scrollTop); |
||||
this.element.scrollLeft(o.scrollLeft); |
||||
} |
||||
}, |
||||
|
||||
setScrollLeft: function (scrollLeft) { |
||||
if (this.options.scrollLeft === scrollLeft) { |
||||
return; |
||||
} |
||||
this._scrollLock = true; |
||||
this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getMaxScrollLeft()); |
||||
this.element.scrollLeft(this.options.scrollLeft); |
||||
this._debounceRelease(); |
||||
this._calculateChildrenToRender(); |
||||
}, |
||||
|
||||
setScrollTop: function (scrollTop) { |
||||
if (this.options.scrollTop === scrollTop) { |
||||
return; |
||||
} |
||||
this._scrollLock = true; |
||||
this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop()); |
||||
this.element.scrollTop(this.options.scrollTop); |
||||
this._debounceRelease(); |
||||
this._calculateChildrenToRender(); |
||||
}, |
||||
|
||||
setOverflowX: function (b) { |
||||
var self = this; |
||||
if (this.options.overflowX !== !!b) { |
||||
this.options.overflowX = !!b; |
||||
BI.nextTick(function () { |
||||
self.element.css({overflowX: !!b ? "auto" : "hidden"}); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
setOverflowY: function (b) { |
||||
var self = this; |
||||
if (this.options.overflowY !== !!b) { |
||||
this.options.overflowY = !!b; |
||||
BI.nextTick(function () { |
||||
self.element.css({overflowY: !!b ? "auto" : "hidden"}); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
getScrollLeft: function () { |
||||
return this.options.scrollLeft; |
||||
}, |
||||
|
||||
getScrollTop: function () { |
||||
return this.options.scrollTop; |
||||
}, |
||||
|
||||
getMaxScrollLeft: function () { |
||||
return this._getMaxScrollLeft(); |
||||
}, |
||||
|
||||
getMaxScrollTop: function () { |
||||
return this._getMaxScrollTop(); |
||||
}, |
||||
|
||||
setEstimatedColumnSize: function (width) { |
||||
this.options.estimatedColumnSize = width; |
||||
}, |
||||
|
||||
setEstimatedRowSize: function (height) { |
||||
this.options.estimatedRowSize = height; |
||||
}, |
||||
|
||||
restore: function () { |
||||
BI.each(this.renderedCells, function (i, cell) { |
||||
cell.el.destroy(); |
||||
}); |
||||
this.renderedCells = []; |
||||
this.renderedKeys = []; |
||||
this._scrollLock = false; |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
if (items && items !== this.options.items) { |
||||
this.options.items = items; |
||||
this.restore(); |
||||
} |
||||
this._populate(); |
||||
} |
||||
}); |
||||
BI.Grid.EVENT_SCROLL = "EVENT_SCROLL"; |
||||
$.shortcut('bi.grid_view', BI.Grid); |
@ -0,0 +1,146 @@
|
||||
/** |
||||
* floatBox弹出层, |
||||
* @class BI.FloatBox |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.FloatBox = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.FloatBox.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-float-box", |
||||
width: 600, |
||||
height: 500 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.FloatBox.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.showAction = new BI.ShowAction({ |
||||
tar: this |
||||
}); |
||||
this._center = BI.createWidget(); |
||||
this._north = BI.createWidget(); |
||||
this.element.draggable({ |
||||
cursor: BICst.cursorUrl, |
||||
handle: ".bi-message-title", |
||||
drag: function (e, ui) { |
||||
var W = $("body").width(), H = $("body").height(); |
||||
if (ui.position.left + o.width > W) { |
||||
ui.position.left = W - o.width; |
||||
} |
||||
if (ui.position.top + o.height > H) { |
||||
ui.position.top = H - o.height; |
||||
} |
||||
if (ui.position.left < 0) { |
||||
ui.position.left = 0; |
||||
} |
||||
if (ui.position.top < 0) { |
||||
ui.position.top = 0; |
||||
} |
||||
} |
||||
}); |
||||
this._south = BI.createWidget(); |
||||
BI.createWidget({ |
||||
type: 'bi.border', |
||||
element: this.element, |
||||
items: { |
||||
'north': { |
||||
el: { |
||||
type: 'bi.border', |
||||
cls: 'bi-message-title', |
||||
items: { |
||||
center: { |
||||
el: { |
||||
type: "bi.absolute", |
||||
items: [{ |
||||
el: this._north, |
||||
left: 10, |
||||
top: 0, |
||||
right: 0, |
||||
bottom: 0 |
||||
}] |
||||
} |
||||
}, |
||||
east: { |
||||
el: { |
||||
type: 'bi.icon_button', |
||||
cls: 'bi-message-close close-font', |
||||
height: 50, |
||||
handler: function () { |
||||
self.currentSectionProvider.close(); |
||||
} |
||||
}, |
||||
width: 60 |
||||
} |
||||
} |
||||
}, |
||||
height: 50 |
||||
}, |
||||
'center': { |
||||
el: { |
||||
type: "bi.absolute", |
||||
items: [{ |
||||
el: this._center, |
||||
left: 10, |
||||
top: 10, |
||||
right: 10, |
||||
bottom: 10 |
||||
}] |
||||
} |
||||
}, |
||||
'south': { |
||||
el: { |
||||
type: "bi.absolute", |
||||
items: [{ |
||||
el: this._south, |
||||
left: 10, |
||||
top: 0, |
||||
right: 10, |
||||
bottom: 0 |
||||
}] |
||||
}, |
||||
height: 60 |
||||
} |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
populate: function (sectionProvider) { |
||||
var self = this; |
||||
this.currentSectionProvider = sectionProvider; |
||||
sectionProvider.rebuildNorth(this._north); |
||||
sectionProvider.rebuildCenter(this._center); |
||||
sectionProvider.rebuildSouth(this._south); |
||||
if (sectionProvider instanceof BI.Widget) { |
||||
sectionProvider.on(BI.PopoverSection.EVENT_CLOSE, function () { |
||||
self.close(); |
||||
}) |
||||
} |
||||
}, |
||||
|
||||
show: function () { |
||||
this.showAction.actionPerformed(); |
||||
}, |
||||
|
||||
hide: function () { |
||||
this.showAction.actionBack(); |
||||
}, |
||||
|
||||
open: function () { |
||||
this.show(); |
||||
this.fireEvent(BI.FloatBox.EVENT_FLOAT_BOX_OPEN); |
||||
}, |
||||
|
||||
close: function () { |
||||
this.hide(); |
||||
this.fireEvent(BI.FloatBox.EVENT_FLOAT_BOX_CLOSED); |
||||
}, |
||||
|
||||
setZindex: function (zindex) { |
||||
this.element.css({"z-index": zindex}); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.float_box", BI.FloatBox); |
||||
|
||||
BI.FloatBox.EVENT_FLOAT_BOX_CLOSED = "EVENT_FLOAT_BOX_CLOSED"; |
||||
BI.FloatBox.EVENT_FLOAT_BOX_OPEN = "EVENT_FLOAT_BOX_CLOSED"; |
@ -0,0 +1,170 @@
|
||||
/** |
||||
* 下拉框弹出层, zIndex在1000w |
||||
* @class BI.PopupView |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.PopupView = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.PopupView.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-list-view", |
||||
maxWidth: 'auto', |
||||
minWidth: 100, |
||||
//maxHeight: 200,
|
||||
minHeight: 25, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
vgap: 0, |
||||
hgap: 0, |
||||
direction: BI.Direction.Top, //工具栏的方向
|
||||
stopEvent: false,//是否停止mousedown、mouseup事件
|
||||
stopPropagation: false, //是否停止mousedown、mouseup向上冒泡
|
||||
logic: { |
||||
dynamic: true |
||||
}, |
||||
|
||||
tool: false, //自定义工具栏
|
||||
tabs: [], //导航栏
|
||||
buttons: [], //toolbar栏
|
||||
|
||||
el: { |
||||
type: "bi.button_group", |
||||
items: [], |
||||
chooseType: 0, |
||||
behaviors: {}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.PopupView.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
var fn = function (e) { |
||||
e.stopPropagation(); |
||||
}, stop = function (e) { |
||||
e.stopEvent(); |
||||
return false; |
||||
}; |
||||
this.element.css({ |
||||
"z-index": BI.zIndex_popup, |
||||
"min-width": o.minWidth + "px", |
||||
"max-width": o.maxWidth + "px" |
||||
}).bind({"click": fn, "mousewheel": fn}); |
||||
|
||||
o.stopPropagation && this.element.bind({"mousedown": fn, "mouseup": fn, "mouseover": fn}); |
||||
o.stopEvent && this.element.bind({"mousedown": stop, "mouseup": stop, "mouseover": stop}); |
||||
this.tool = this._createTool(); |
||||
this.tab = this._createTab(); |
||||
this.view = this._createView(); |
||||
this.toolbar = this._createToolBar(); |
||||
|
||||
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.PopupView.EVENT_CHANGE); |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { |
||||
scrolly: false, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
vgap: o.vgap, |
||||
hgap: o.hgap, |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, |
||||
BI.extend({ |
||||
cls: "list-view-outer" |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tool, this.tab, this.view, this.toolbar) |
||||
}))) |
||||
) |
||||
})))); |
||||
}, |
||||
|
||||
_createView: function () { |
||||
var o = this.options; |
||||
this.button_group = BI.createWidget(o.el, {type: "bi.button_group"}); |
||||
this.button_group.element.css({"min-height": o.minHeight + "px"}); |
||||
return this.button_group; |
||||
}, |
||||
|
||||
_createTool: function () { |
||||
var o = this.options; |
||||
if (false === o.tool) { |
||||
return; |
||||
} |
||||
return BI.createWidget(o.tool) |
||||
}, |
||||
|
||||
_createTab: function () { |
||||
var o = this.options; |
||||
if (o.tabs.length === 0) { |
||||
return; |
||||
} |
||||
return BI.createWidget({ |
||||
type: "bi.center", |
||||
cls: "list-view-tab", |
||||
height: 25, |
||||
items: o.tabs |
||||
}) |
||||
}, |
||||
|
||||
_createToolBar: function () { |
||||
var o = this.options; |
||||
if (o.buttons.length === 0) { |
||||
return; |
||||
} |
||||
|
||||
return BI.createWidget({ |
||||
type: "bi.center", |
||||
cls: "list-view-toolbar", |
||||
height: 30, |
||||
items: BI.createItems(o.buttons, { |
||||
once: false, |
||||
shadow: true, |
||||
isShadowShowingOnSelected: true |
||||
}) |
||||
}) |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.button_group.populate.apply(this.button_group, arguments); |
||||
}, |
||||
|
||||
resetWidth: function (w) { |
||||
this.options.width = w; |
||||
this.element.width(w); |
||||
}, |
||||
|
||||
resetHeight: function (h) { |
||||
var tbHeight = 30 * (this.toolbar ? 1 : 0), |
||||
tabHeight = 25 * (this.tab ? 1 : 0), |
||||
toolHeight = ((this.tool && this.tool.element.outerHeight()) || 25) * ((this.tool && this.tool.isVisible()) ? 1 : 0); |
||||
this.view.resetHeight ? this.view.resetHeight(h - tbHeight - tabHeight - toolHeight - 2) : |
||||
this.view.element.css({"max-height": (h - tbHeight - tabHeight - toolHeight - 2) + "px"}) |
||||
}, |
||||
|
||||
setEnable: function (arg) { |
||||
BI.PopupView.superclass.setEnable.apply(this, arguments); |
||||
this.view && this.view.setEnable(arg); |
||||
}, |
||||
|
||||
setValue: function (selectedValues) { |
||||
this.tab && this.tab.setValue(selectedValues); |
||||
this.button_group.setValue(selectedValues); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.button_group.getValue(); |
||||
} |
||||
}); |
||||
BI.PopupView.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.popup_view", BI.PopupView); |
@ -0,0 +1,118 @@
|
||||
/** |
||||
* guy |
||||
* @class BI.ScrollView |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.ScrollView = BI.inherit(BI.Widget, { |
||||
|
||||
_const: { |
||||
dropDownHeight: 15, |
||||
expandIcon: "column-next-page-h-font", |
||||
collapseIcon: "column-pre-page-h-font" |
||||
}, |
||||
|
||||
_defaultConfig: function() { |
||||
return BI.extend(BI.ScrollView.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls:"bi-scroll-view", |
||||
scrollHeight: 50, |
||||
maxHeight: 300 |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.ScrollView.superclass._init.apply(this, arguments); |
||||
|
||||
this.scrollUp = false; |
||||
this.scroll = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
cls: "scroll-container", |
||||
scrolly: true |
||||
}) |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
scrolly: false, |
||||
items: [this.scroll] |
||||
}) |
||||
|
||||
this.dropdown = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
height: this._const.dropDownHeight, |
||||
cls: "scroll-drop-down-icon " + this._const.expandIcon, |
||||
handler: BI.bind(this._dropDownOrUp, this) |
||||
}) |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.dropdown, |
||||
left: 0, |
||||
right: 0, |
||||
bottom: -1 * this._const.dropDownHeight |
||||
}] |
||||
}) |
||||
this.populate(this.options.items); |
||||
}, |
||||
|
||||
_dropDownOrUp: function(){ |
||||
if(!this.scrollUp){ |
||||
var height = this.element.height(); |
||||
height += this.options.scrollHeight; |
||||
height = Math.min(height, this.scroll.element[0].scrollHeight, this.options.maxHeight); |
||||
this.element.height(height); |
||||
this._checkDropDownState(); |
||||
} else { |
||||
var height = this.element.height(); |
||||
height -= this.options.scrollHeight; |
||||
height = Math.max(height, this.options.height); |
||||
this.element.height(height); |
||||
this._checkDropDownState(); |
||||
} |
||||
}, |
||||
|
||||
_checkDropDownState: function(){ |
||||
var height = this.element.height(); |
||||
if(!this._checkScroll() || height >= this.options.maxHeight){ |
||||
this.scrollUp = true; |
||||
this.dropdown.element.removeClass(this._const.expandIcon).addClass(this._const.collapseIcon); |
||||
} else if(height <= this.options.height){ |
||||
this.scrollUp = false; |
||||
this.dropdown.element.addClass(this._const.expandIcon); |
||||
} else { |
||||
this.dropdown.element.addClass(this.scrollUp ? this._const.collapseIcon : this._const.expandIcon); |
||||
} |
||||
}, |
||||
|
||||
_checkScroll: function(){ |
||||
this.scroll.element.height(this.element.height()); |
||||
return this.scroll.element[0].scrollHeight > this.scroll.element[0].clientHeight; |
||||
}, |
||||
|
||||
_checkDropDown: function(){ |
||||
if(this._checkScroll()){ |
||||
this.dropdown.visible(); |
||||
//this.scrollUp = false;
|
||||
this._checkDropDownState(); |
||||
} else { |
||||
this.dropdown.invisible(); |
||||
} |
||||
}, |
||||
|
||||
populate: function(){ |
||||
this.scroll.populate.apply(this.scroll, arguments); |
||||
this.resize(); |
||||
}, |
||||
|
||||
resize: function(){ |
||||
this.element.height(this.options.height); |
||||
BI.nextTick(BI.bind(this._checkDropDown, this)); |
||||
}, |
||||
|
||||
addItem: function(){ |
||||
this.scroll.addItem.apply(this.scroll, arguments); |
||||
BI.nextTick(BI.bind(this._checkDropDown, this)); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.scroll_view", BI.ScrollView); |
@ -0,0 +1,139 @@
|
||||
/** |
||||
* 搜索面板 |
||||
* |
||||
* Created by GUY on 2015/9/28. |
||||
* @class BI.SearcherView |
||||
* @extends BI.Pane |
||||
*/ |
||||
|
||||
BI.SearcherView = BI.inherit(BI.Pane, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-searcher-view", |
||||
tipText: BI.i18nText("BI-No_Select"), |
||||
chooseType: BI.Selection.Single, |
||||
|
||||
matcher: {//完全匹配的构造器
|
||||
type: "bi.button_group", |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
}, |
||||
items: [], |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
}, |
||||
searcher: { |
||||
type: "bi.button_group", |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
}, |
||||
items: [], |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.SearcherView.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
|
||||
this.matcher = BI.createWidget(o.matcher, { |
||||
type: "bi.button_group", |
||||
chooseType: o.chooseType, |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
}); |
||||
this.matcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob); |
||||
} |
||||
}); |
||||
this.spliter = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
height: 1, |
||||
hgap: 10, |
||||
items: [{ |
||||
type: "bi.layout", |
||||
height: 1, |
||||
cls: "searcher-view-spliter" |
||||
}] |
||||
}); |
||||
this.searcher = BI.createWidget(o.searcher, { |
||||
type: "bi.button_group", |
||||
chooseType: o.chooseType, |
||||
behaviors: { |
||||
redmark: function () { |
||||
return true; |
||||
} |
||||
}, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
}); |
||||
this.searcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob); |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
items: [this.matcher, this.spliter, this.searcher] |
||||
}); |
||||
}, |
||||
|
||||
startSearch: function () { |
||||
|
||||
}, |
||||
|
||||
stopSearch: function () { |
||||
|
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.matcher.setValue(v); |
||||
this.searcher.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.matcher.getValue().concat(this.searcher.getValue()); |
||||
}, |
||||
|
||||
populate: function (searchResult, matchResult, keyword) { |
||||
searchResult || (searchResult = []); |
||||
matchResult || (matchResult = []); |
||||
this.setTipVisible(searchResult.length + matchResult.length === 0); |
||||
this.spliter.setVisible(BI.isNotEmptyArray(matchResult) && BI.isNotEmptyArray(searchResult)); |
||||
this.matcher.populate(matchResult, keyword); |
||||
this.searcher.populate(searchResult, keyword); |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.searcher.empty(); |
||||
this.matcher.empty(); |
||||
}, |
||||
|
||||
hasMatched: function () { |
||||
return this.matcher.getAllButtons().length > 0; |
||||
} |
||||
}); |
||||
BI.SearcherView.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.searcher_view", BI.SearcherView); |
@ -0,0 +1,286 @@
|
||||
/** |
||||
* 分页控件 |
||||
* |
||||
* Created by GUY on 2015/8/31. |
||||
* @class BI.Pager |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Pager = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Pager.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-pager", |
||||
behaviors: {}, |
||||
layouts: [{ |
||||
type: "bi.horizontal", |
||||
hgap: 10, |
||||
vgap: 0 |
||||
}], |
||||
|
||||
dynamicShow: true, //是否动态显示上一页、下一页、首页、尾页, 若为false,则指对其设置使能状态
|
||||
//dynamicShow为false时以下两个有用
|
||||
dynamicShowFirstLast: false,//是否动态显示首页、尾页
|
||||
dynamicShowPrevNext: false,//是否动态显示上一页、下一页
|
||||
pages: false, //总页数
|
||||
curr: function () { |
||||
return 1; |
||||
}, //初始化当前页
|
||||
groups: 0, //连续显示分页数
|
||||
jump: BI.emptyFn, //分页的回调函数
|
||||
|
||||
first: false, //是否显示首页
|
||||
last: false, //是否显示尾页
|
||||
prev: "上一页", |
||||
next: "下一页", |
||||
|
||||
firstPage: 1, |
||||
lastPage: function () { //在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法
|
||||
return 1; |
||||
}, |
||||
hasPrev: BI.emptyFn, //pages不可用时有效
|
||||
hasNext: BI.emptyFn //pages不可用时有效
|
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.Pager.superclass._init.apply(this, arguments); |
||||
var self = this; |
||||
this.currPage = BI.result(this.options, "curr"); |
||||
//翻页太灵敏
|
||||
this._lock = false; |
||||
this._debouce = BI.debounce(function () { |
||||
self._lock = false; |
||||
}, 300); |
||||
this._populate(); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.currPage = BI.result(this.options, "curr"); |
||||
this._populate(); |
||||
}, |
||||
|
||||
refresh: function () { |
||||
this._populate();
|
||||
}, |
||||
|
||||
_populate: function () { |
||||
var self = this, o = this.options, view = [], dict = {}; |
||||
this.empty(); |
||||
var pages = BI.result(o, "pages"); |
||||
var curr = BI.result(this, "currPage"); |
||||
var groups = BI.result(o, "groups"); |
||||
var first = BI.result(o, "first"); |
||||
var last = BI.result(o, "last"); |
||||
var prev = BI.result(o, "prev"); |
||||
var next = BI.result(o, "next"); |
||||
|
||||
if (pages === false) { |
||||
groups = 0; |
||||
first = false; |
||||
last = false; |
||||
} else { |
||||
groups > pages && (groups = pages); |
||||
} |
||||
|
||||
//计算当前组
|
||||
dict.index = Math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups)); |
||||
|
||||
//当前页非首页,则输出上一页
|
||||
if (((!o.dynamicShow && !o.dynamicShowPrevNext) || curr > 1) && prev !== false) { |
||||
if (BI.isKey(prev)) { |
||||
view.push({ |
||||
text: prev, |
||||
value: "prev", |
||||
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) |
||||
}) |
||||
} else { |
||||
view.push(BI.extend({ |
||||
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) |
||||
}, prev)); |
||||
} |
||||
} |
||||
|
||||
//当前组非首组,则输出首页
|
||||
if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (dict.index > 1 && groups !== 0)) && first) { |
||||
view.push({ |
||||
text: first, |
||||
value: "first", |
||||
disabled: !(dict.index > 1 && groups !== 0) |
||||
}); |
||||
if (dict.index > 1 && groups !== 0) { |
||||
view.push({ |
||||
type: "bi.label", |
||||
cls: "page-ellipsis", |
||||
text: "\u2026" |
||||
}); |
||||
} |
||||
} |
||||
|
||||
//输出当前页组
|
||||
dict.poor = Math.floor((groups - 1) / 2); |
||||
dict.start = dict.index > 1 ? curr - dict.poor : 1; |
||||
dict.end = dict.index > 1 ? (function () { |
||||
var max = curr + (groups - dict.poor - 1); |
||||
return max > pages ? pages : max; |
||||
}()) : groups; |
||||
if (dict.end - dict.start < groups - 1) { //最后一组状态
|
||||
dict.start = dict.end - groups + 1; |
||||
} |
||||
var s = dict.start, e = dict.end; |
||||
if (first && last && (dict.index > 1 && groups !== 0) && (pages > groups && dict.end < pages && groups !== 0)) { |
||||
s++; |
||||
e--; |
||||
} |
||||
for (; s <= e; s++) { |
||||
if (s === curr) { |
||||
view.push({ |
||||
text: s, |
||||
value: s, |
||||
selected: true |
||||
}) |
||||
} else { |
||||
view.push({ |
||||
text: s, |
||||
value: s |
||||
}) |
||||
} |
||||
} |
||||
|
||||
//总页数大于连续分页数,且当前组最大页小于总页,输出尾页
|
||||
if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (pages > groups && dict.end < pages && groups !== 0)) && last) { |
||||
if (pages > groups && dict.end < pages && groups !== 0) { |
||||
view.push({ |
||||
type: "bi.label", |
||||
cls: "page-ellipsis", |
||||
text: "\u2026" |
||||
}); |
||||
} |
||||
view.push({ |
||||
text: last, |
||||
value: "last", |
||||
disabled: !(pages > groups && dict.end < pages && groups !== 0) |
||||
}) |
||||
} |
||||
|
||||
//当前页不为尾页时,输出下一页
|
||||
dict.flow = !prev && groups === 0; |
||||
if (((!o.dynamicShow && !o.dynamicShowPrevNext) && next) || (curr !== pages && next || dict.flow)) { |
||||
view.push((function () { |
||||
if (BI.isKey(next)) { |
||||
if (pages === false) { |
||||
return {text: next, value: "next", disabled: o.hasNext(curr) === false} |
||||
} |
||||
return (dict.flow && curr === pages) |
||||
? |
||||
{text: next, value: "next", disabled: true} |
||||
: |
||||
{text: next, value: "next", disabled: !(curr !== pages && next || dict.flow)}; |
||||
} else { |
||||
return BI.extend({ |
||||
disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow) |
||||
}, next); |
||||
} |
||||
}())); |
||||
} |
||||
|
||||
this.button_group = BI.createWidget({ |
||||
type: "bi.button_group", |
||||
element: this.element, |
||||
items: BI.createItems(view, { |
||||
cls: "page-item", |
||||
height: 23, |
||||
hgap: 10 |
||||
}), |
||||
behaviors: o.behaviors, |
||||
layouts: o.layouts |
||||
}); |
||||
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { |
||||
if (self._lock === true) { |
||||
return; |
||||
} |
||||
self._lock = true; |
||||
self._debouce(); |
||||
if (type === BI.Events.CLICK) { |
||||
var v = self.button_group.getValue()[0]; |
||||
switch (v) { |
||||
case "first": |
||||
self.currPage = 1; |
||||
break; |
||||
case "last": |
||||
self.currPage = pages; |
||||
break; |
||||
case "prev": |
||||
self.currPage--; |
||||
break; |
||||
case "next": |
||||
self.currPage++; |
||||
break; |
||||
default: |
||||
self.currPage = v; |
||||
break; |
||||
} |
||||
o.jump.apply(self, [{ |
||||
pages: pages, |
||||
curr: self.currPage |
||||
}]); |
||||
self._populate(); |
||||
self.fireEvent(BI.Pager.EVENT_CHANGE, obj); |
||||
} |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.fireEvent(BI.Pager.EVENT_AFTER_POPULATE); |
||||
}, |
||||
|
||||
getCurrentPage: function () { |
||||
return this.currPage; |
||||
}, |
||||
|
||||
setAllPages: function (pages) { |
||||
this.options.pages = pages; |
||||
}, |
||||
|
||||
hasPrev: function (v) { |
||||
v || (v = 1); |
||||
var o = this.options; |
||||
var pages = this.options.pages; |
||||
return pages === false ? o.hasPrev(v) : v > 1; |
||||
}, |
||||
|
||||
hasNext: function (v) { |
||||
v || (v = 1); |
||||
var o = this.options; |
||||
var pages = this.options.pages; |
||||
return pages === false ? o.hasNext(v) : v < pages; |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
var o = this.options; |
||||
v = v | 0; |
||||
v = v < 1 ? 1 : v; |
||||
if (o.pages === false) { |
||||
var lastPage = BI.result(o, "lastPage"), firstPage = 1; |
||||
this.currPage = v > lastPage ? lastPage : ((firstPage = BI.result(o, "firstPage")), (v < firstPage ? firstPage : v)); |
||||
} else { |
||||
v = v > o.pages ? o.pages : v; |
||||
this.currPage = v; |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var val = this.button_group.getValue()[0]; |
||||
switch (val) { |
||||
case "prev": |
||||
return -1; |
||||
case "next": |
||||
return 1; |
||||
case "first": |
||||
return BI.MIN; |
||||
case "last": |
||||
return BI.MAX; |
||||
default : |
||||
return val; |
||||
} |
||||
} |
||||
}); |
||||
BI.Pager.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Pager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE"; |
||||
$.shortcut("bi.pager", BI.Pager); |
@ -0,0 +1,110 @@
|
||||
/** |
||||
* 当没有元素时有提示信息的view |
||||
* |
||||
* Created by GUY on 2015/9/8. |
||||
* @class BI.Pane |
||||
* @extends BI.Widget |
||||
* @abstract |
||||
*/ |
||||
BI.Pane = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Pane.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-pane", |
||||
tipText: BI.i18nText("BI-No_Selected_Item"), |
||||
overlap: true, |
||||
onLoaded: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Pane.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
_assertTip: function () { |
||||
var o = this.options; |
||||
if (!this._tipText) { |
||||
this._tipText = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "bi-tips", |
||||
text: o.tipText, |
||||
height: 25 |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
element: this.element, |
||||
items: [this._tipText], |
||||
bgap: 25 |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
loading: function () { |
||||
var self = this, o = this.options; |
||||
if (o.overlap === true) { |
||||
if (!BI.Maskers.has(this.getName())) { |
||||
BI.createWidget({ |
||||
type: 'bi.vtape', |
||||
items: [{ |
||||
el: { |
||||
type: "bi.layout", |
||||
cls: "loading-background" |
||||
}, |
||||
height: 30 |
||||
}], |
||||
element: BI.Maskers.make(this.getName(), this) |
||||
}); |
||||
} |
||||
BI.Maskers.show(self.getName()); |
||||
} else { |
||||
this._loading = BI.createWidget({ |
||||
type: "bi.layout", |
||||
cls: "loading-background", |
||||
height: 30 |
||||
}); |
||||
this._loading.element.css("zIndex", 1); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this._loading, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0 |
||||
}] |
||||
}) |
||||
} |
||||
}, |
||||
|
||||
loaded: function () { |
||||
var self = this, o = this.options; |
||||
BI.Maskers.remove(self.getName()); |
||||
this._loading && this._loading.destroy(); |
||||
this._loading && (this._loading = null); |
||||
o.onLoaded(); |
||||
self.fireEvent(BI.Pane.EVENT_LOADED); |
||||
}, |
||||
|
||||
check: function () { |
||||
this.setTipVisible(BI.isEmpty(this.options.items)); |
||||
}, |
||||
|
||||
setTipVisible: function (b) { |
||||
if (b === true) { |
||||
this._assertTip(); |
||||
this._tipText.setVisible(true); |
||||
} else { |
||||
this._tipText && this._tipText.setVisible(false); |
||||
} |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.options.items = items || []; |
||||
this.check(); |
||||
}, |
||||
|
||||
empty: function () { |
||||
|
||||
} |
||||
}); |
||||
BI.Pane.EVENT_LOADED = "EVENT_LOADED"; |
@ -0,0 +1,31 @@
|
||||
/** |
||||
* 超链接 |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.A |
||||
* @extends BI.Text |
||||
* @abstract |
||||
*/ |
||||
BI.A = BI.inherit(BI.Text, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.A.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-a display-block", |
||||
href: "", |
||||
target: "_blank", |
||||
el: null |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
var o = this.options; |
||||
this.options.element = $("<a href='" + o.href + "' target='" + o.target + "'>"); |
||||
BI.A.superclass._init.apply(this, arguments); |
||||
if (o.el) { |
||||
BI.createWidget(o.el, { |
||||
element: this.element |
||||
}); |
||||
} |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.a", BI.A); |
@ -0,0 +1,83 @@
|
||||
/** |
||||
* guy |
||||
* 加载条 |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.LoadingBar = BI.inherit(BI.Single, { |
||||
consts: { |
||||
loadedText: '加载更多', |
||||
endText: '无更多数据' |
||||
}, |
||||
_defaultConfig: function() { |
||||
var conf = BI.LoadingBar.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend( conf, { |
||||
baseCls : (conf.baseCls ||"")+' bi-loading-bar', |
||||
height: 30, |
||||
handler: BI.emptyFn |
||||
}) |
||||
}, |
||||
_init : function() { |
||||
BI.LoadingBar.superclass._init.apply(this, arguments); |
||||
var self = this; |
||||
this.loaded = BI.createWidget({ |
||||
type: "bi.text_button", |
||||
cls: "loading-text", |
||||
text: this.consts.loadedText, |
||||
width: 120, |
||||
handler: this.options.handler |
||||
}) |
||||
this.loaded.on(BI.Controller.EVENT_CHANGE, function(type){ |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}) |
||||
|
||||
this.loading = BI.createWidget({ |
||||
type: "bi.layout", |
||||
height:this.options.height, |
||||
cls: "loading-background cursor-default" |
||||
}) |
||||
var loaded = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
items: [this.loaded] |
||||
}) |
||||
var loading = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
items: [this.loading] |
||||
}) |
||||
this.cardLayout = BI.createWidget({ |
||||
type: "bi.card", |
||||
element: this.element, |
||||
items: [{ |
||||
el: loaded, |
||||
cardName: "loaded" |
||||
}, { |
||||
el: loading, |
||||
cardName: "loading" |
||||
}] |
||||
}) |
||||
this.invisible(); |
||||
}, |
||||
|
||||
_reset: function(){ |
||||
this.visible(); |
||||
this.loaded.setText(this.consts.loadedText); |
||||
this.loaded.enable(); |
||||
}, |
||||
|
||||
setLoaded: function(){ |
||||
this._reset(); |
||||
this.cardLayout.showCardByName("loaded"); |
||||
}, |
||||
|
||||
setEnd: function(){ |
||||
this.setLoaded(); |
||||
this.loaded.setText(this.consts.endText); |
||||
this.loaded.disable(); |
||||
}, |
||||
|
||||
setLoading: function(){ |
||||
this._reset(); |
||||
this.cardLayout.showCardByName("loading"); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.loading_bar", BI.LoadingBar); |
@ -0,0 +1,296 @@
|
||||
/** |
||||
* guy |
||||
* @class BI.BasicButton |
||||
* @extends BI.Single |
||||
* |
||||
* 一般的button父级 |
||||
*/ |
||||
BI.BasicButton = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.BasicButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-basic-button cursor-pointer", |
||||
value: "", |
||||
text: "", |
||||
stopEvent: false, |
||||
stopPropagation: false, |
||||
selected: false, |
||||
once: false, //点击一次选中有效,再点无效
|
||||
forceSelected: false, //点击即选中, 选中了就不会被取消
|
||||
forceNotSelected: false, //无论怎么点击都不会被选中
|
||||
disableSelected: false, //使能选中
|
||||
|
||||
shadow: false, |
||||
isShadowShowingOnSelected: false, //选中状态下是否显示阴影
|
||||
trigger: null, |
||||
handler: BI.emptyFn |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.BasicButton.superclass._init.apply(this, arguments); |
||||
var opts = this.options; |
||||
if (opts.selected === true) { |
||||
BI.nextTick(BI.bind(function () { |
||||
this.setSelected(opts.selected); |
||||
}, this)); |
||||
} |
||||
BI.nextTick(BI.bind(this.bindEvent, this)); |
||||
|
||||
if (opts.shadow) { |
||||
this._createShadow(); |
||||
} |
||||
}, |
||||
|
||||
_createShadow: function () { |
||||
var self = this, o = this.options; |
||||
|
||||
var assertMask = function () { |
||||
if (!self.$mask) { |
||||
self.$mask = BI.createWidget(BI.isObject(o.shadow) ? o.shadow : {}, { |
||||
type: "bi.layout", |
||||
cls: "bi-button-mask" |
||||
}); |
||||
self.$mask.invisible(); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: self.element, |
||||
items: [{ |
||||
el: self.$mask, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
} |
||||
}; |
||||
|
||||
this.element.mouseup(function () { |
||||
if (!self._hover && !o.isShadowShowingOnSelected) { |
||||
assertMask(); |
||||
self.$mask.invisible(); |
||||
} |
||||
}); |
||||
this.element.on("mouseenter." + this.getName(), function (e) { |
||||
if (self.element.__isMouseInBounds__(e)) { |
||||
if (self.isEnabled() && !self._hover && (o.isShadowShowingOnSelected || !self.isSelected())) { |
||||
assertMask(); |
||||
self.$mask.visible(); |
||||
} |
||||
} |
||||
}); |
||||
this.element.on("mousemove." + this.getName(), function (e) { |
||||
if (!self.element.__isMouseInBounds__(e)) { |
||||
if (self.isEnabled() && !self._hover) { |
||||
assertMask(); |
||||
self.$mask.invisible(); |
||||
} |
||||
} |
||||
}); |
||||
this.element.on("mouseleave." + this.getName(), function () { |
||||
if (self.isEnabled() && !self._hover) { |
||||
assertMask(); |
||||
self.$mask.invisible(); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
bindEvent: function () { |
||||
var self = this; |
||||
var o = this.options, hand = this.handle(); |
||||
if (!hand) { |
||||
return; |
||||
} |
||||
hand = hand.element; |
||||
switch (o.trigger) { |
||||
case "mouseup": |
||||
var mouseDown = false; |
||||
hand.mousedown(function () { |
||||
mouseDown = true; |
||||
ev(e); |
||||
}); |
||||
hand.mouseup(function (e) { |
||||
if (mouseDown === true) { |
||||
clk(e); |
||||
} |
||||
mouseDown = false; |
||||
ev(e); |
||||
}); |
||||
break; |
||||
case "mousedown": |
||||
var mouseDown = false; |
||||
var selected = false; |
||||
hand.mousedown(function (e) { |
||||
// if (e.button === 0) {
|
||||
if (mouseDown === true) { |
||||
return; |
||||
} |
||||
if (self.isSelected()) { |
||||
selected = true; |
||||
} else { |
||||
clk(e); |
||||
} |
||||
mouseDown = true; |
||||
ev(e); |
||||
// }
|
||||
}); |
||||
hand.mouseup(function (e) { |
||||
// if (e.button === 0) {
|
||||
if (mouseDown === true && selected === true) { |
||||
clk(e); |
||||
} |
||||
mouseDown = false; |
||||
selected = false; |
||||
// }
|
||||
}); |
||||
var checking = BI.debounce(function () { |
||||
if (!BI.DOM.isExist(self)) { |
||||
$(document).unbind("mouseup." + self.getName()); |
||||
} |
||||
}, 3000); |
||||
$(document).bind("mouseup." + this.getName(), function (e) { |
||||
// if (e.button === 0) {
|
||||
if (BI.DOM.isExist(self)) { |
||||
if (!hand.__isMouseInBounds__(e) && mouseDown === true && !selected) { |
||||
self.setSelected(!self.isSelected()); |
||||
self._trigger(); |
||||
} |
||||
mouseDown = false; |
||||
checking(); |
||||
} |
||||
// }
|
||||
}); |
||||
break; |
||||
case "dblclick": |
||||
hand.dblclick(clk); |
||||
break; |
||||
default: |
||||
hand.mousedown(function (e) { |
||||
ev(e); |
||||
}); |
||||
hand.mouseup(function (e) { |
||||
ev(e); |
||||
}); |
||||
hand.click(clk); |
||||
break; |
||||
} |
||||
//之后的300ms点击无效
|
||||
var onClick = BI.debounce(this.doClick, BI.EVENT_RESPONSE_TIME, true); |
||||
|
||||
function ev(e) { |
||||
if (o.stopEvent) { |
||||
e.stopEvent(); |
||||
} |
||||
if (o.stopPropagation) { |
||||
e.stopPropagation(); |
||||
} |
||||
} |
||||
|
||||
function clk(e) { |
||||
ev(e); |
||||
if (!self.isEnabled() || (self.isOnce() && self.isSelected())) { |
||||
return; |
||||
} |
||||
onClick.apply(self); |
||||
} |
||||
}, |
||||
|
||||
_trigger: function () { |
||||
var o = this.options; |
||||
if (this.isValid()) { |
||||
o.handler.call(this, this.getValue(), this); |
||||
var v = this.getValue(); |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, v, this); |
||||
this.fireEvent(BI.BasicButton.EVENT_CHANGE, v, this); |
||||
} |
||||
}, |
||||
|
||||
doClick: function () { |
||||
if (!this.isDisableSelected()) { |
||||
this.isForceSelected() ? this.setSelected(true) : |
||||
(this.isForceNotSelected() ? this.setSelected(false) : |
||||
this.setSelected(!this.isSelected())); |
||||
} |
||||
this._trigger(); |
||||
}, |
||||
|
||||
handle: function () { |
||||
return this; |
||||
}, |
||||
|
||||
hover: function () { |
||||
this._hover = true; |
||||
this.handle().element.addClass("hover"); |
||||
if (this.options.shadow) { |
||||
this.$mask && this.$mask.setVisible(true); |
||||
} |
||||
}, |
||||
|
||||
dishover: function () { |
||||
this._hover = false; |
||||
this.handle().element.removeClass("hover"); |
||||
if (this.options.shadow) { |
||||
this.$mask && this.$mask.setVisible(false); |
||||
} |
||||
}, |
||||
|
||||
setSelected: function (b) { |
||||
var o = this.options; |
||||
o.selected = b; |
||||
if (this.isSelected()) { |
||||
this.handle().element.addClass("active"); |
||||
} else { |
||||
this.handle().element.removeClass("active"); |
||||
} |
||||
if (o.shadow && !o.isShadowShowingOnSelected) { |
||||
this.$mask && this.$mask.setVisible(false); |
||||
} |
||||
}, |
||||
|
||||
isSelected: function () { |
||||
return this.options.selected; |
||||
}, |
||||
|
||||
isOnce: function () { |
||||
return this.options.once; |
||||
}, |
||||
|
||||
isForceSelected: function () { |
||||
return this.options.forceSelected; |
||||
}, |
||||
|
||||
isForceNotSelected: function () { |
||||
return this.options.forceNotSelected; |
||||
}, |
||||
|
||||
isDisableSelected: function () { |
||||
return this.options.disableSelected; |
||||
}, |
||||
|
||||
setText: function (text) { |
||||
this.options.text = text; |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.options.text; |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.BasicButton.superclass.setEnable.apply(this, arguments); |
||||
if (!b) { |
||||
if (this.options.shadow) { |
||||
this.$mask && this.$mask.setVisible(false); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
empty: function () { |
||||
$(document).unbind("mouseup." + this.getName()); |
||||
BI.BasicButton.superclass.empty.apply(this, arguments); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.BasicButton.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.BasicButton.EVENT_CHANGE = "BasicButton.EVENT_CHANGE"; |
@ -0,0 +1,56 @@
|
||||
/** |
||||
* 表示一个可以展开的节点, 不仅有选中状态而且有展开状态 |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.NodeButton |
||||
* @extends BI.BasicButton |
||||
* @abstract |
||||
*/ |
||||
BI.NodeButton = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.NodeButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend( conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-node", |
||||
open: false |
||||
}) |
||||
}, |
||||
|
||||
_init:function() { |
||||
BI.NodeButton.superclass._init.apply(this, arguments); |
||||
var self = this; |
||||
BI.nextTick(function(){ |
||||
self.setOpened(self.isOpened()); |
||||
}) |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.NodeButton.superclass.doClick.apply(this, arguments); |
||||
this.setOpened(!this.isOpened()); |
||||
}, |
||||
|
||||
isOnce: function(){ |
||||
return false; |
||||
}, |
||||
|
||||
isOpened: function(){ |
||||
return !!this.options.open; |
||||
}, |
||||
|
||||
setOpened: function(b){ |
||||
this.options.open = !!b; |
||||
}, |
||||
|
||||
triggerCollapse: function(){ |
||||
if(this.isOpened()) { |
||||
this.setOpened(false); |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
triggerExpand: function(){ |
||||
if(!this.isOpened()) { |
||||
this.setOpened(true); |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, this.getValue(), this); |
||||
} |
||||
} |
||||
}); |
@ -0,0 +1,52 @@
|
||||
/** |
||||
* @class BI.IconButton |
||||
* @extends BI.BasicButton |
||||
* 图标的button |
||||
*/ |
||||
BI.IconButton = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.IconButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
tagName: "a", |
||||
baseCls: (conf.baseCls || "") + " bi-icon-button horizon-center display-block", |
||||
iconWidth: null, |
||||
iconHeight: null |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.IconButton.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.element.css({ |
||||
textAlign: 'center' |
||||
}); |
||||
this.icon = BI.createWidget({ |
||||
type: 'bi.icon', |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
}); |
||||
if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) { |
||||
this.element.css("lineHeight", o.height + "px"); |
||||
BI.createWidget({ |
||||
type: "bi.default", |
||||
element: this.element, |
||||
items: [this.icon] |
||||
}) |
||||
} else { |
||||
BI.createWidget({ |
||||
element: this.element, |
||||
type: 'bi.center_adapt', |
||||
items: [this.icon] |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.IconButton.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.IconButton.EVENT_CHANGE, this); |
||||
} |
||||
} |
||||
}); |
||||
BI.IconButton.EVENT_CHANGE = "IconButton.EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_button", BI.IconButton); |
@ -0,0 +1,88 @@
|
||||
/** |
||||
* 图片的button |
||||
* |
||||
* Created by GUY on 2016/1/27. |
||||
* @class BI.ImageButton |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.ImageButton = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.ImageButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
tagName: "a", |
||||
baseCls: (conf.baseCls || "") + " bi-image-button display-block", |
||||
src: "", |
||||
iconWidth: "100%", |
||||
iconHeight: "100%" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ImageButton.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.image = BI.createWidget({ |
||||
type: "bi.img", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight, |
||||
src: o.src |
||||
}); |
||||
if (BI.isNumber(o.iconWidth) || BI.isNumber(o.iconHeight)) { |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
element: this.element, |
||||
items: [this.image] |
||||
}) |
||||
} else { |
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
element: this.element, |
||||
items: [this.image], |
||||
scrollable: false |
||||
}) |
||||
} |
||||
}, |
||||
|
||||
setWidth: function (w) { |
||||
BI.ImageButton.superclass.setWidth.apply(this, arguments); |
||||
this.options.width = w; |
||||
}, |
||||
|
||||
setHeight: function (h) { |
||||
BI.ImageButton.superclass.setHeight.apply(this, arguments); |
||||
this.options.height = h; |
||||
}, |
||||
|
||||
setImageWidth: function (w) { |
||||
this.image.setWidth(w); |
||||
}, |
||||
|
||||
setImageHeight: function (h) { |
||||
this.image.setHeight(h); |
||||
}, |
||||
|
||||
getImageWidth: function () { |
||||
return this.image.element.width(); |
||||
}, |
||||
|
||||
getImageHeight: function () { |
||||
return this.image.element.height(); |
||||
}, |
||||
|
||||
setSrc: function (src) { |
||||
this.options.src = src; |
||||
this.image.setSrc(src); |
||||
}, |
||||
|
||||
getSrc: function () { |
||||
return this.image.getSrc(); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.ImageButton.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.ImageButton.EVENT_CHANGE, this); |
||||
} |
||||
} |
||||
}); |
||||
BI.ImageButton.EVENT_CHANGE = "ImageButton.EVENT_CHANGE"; |
||||
$.shortcut("bi.image_button", BI.ImageButton); |
@ -0,0 +1,140 @@
|
||||
(function ($) { |
||||
|
||||
/** |
||||
* 文字类型的按钮 |
||||
* @class BI.Button |
||||
* @extends BI.BasicButton |
||||
* |
||||
* @cfg {JSON} options 配置属性 |
||||
* @cfg {'common'/'success'/'warning'/'ignore'} [options.level='common'] 按钮类型,用不同颜色强调不同的场景 |
||||
*/ |
||||
BI.Button = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
minWidth: 90 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.Button.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + ' bi-button', |
||||
shadow: true, |
||||
isShadowShowingOnSelected: true, |
||||
readonly: true, |
||||
iconClass: "", |
||||
level: 'common', |
||||
textAlign: "center", |
||||
whiteSpace: "nowrap", |
||||
forceCenter: false, |
||||
textWidth: null, |
||||
textHeight: null, |
||||
hgap: 10, |
||||
vgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
lgap: 0, |
||||
rgap: 0 |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Button.superclass._init.apply(this, arguments); |
||||
var o = this.options, self = this; |
||||
if (BI.isNumber(o.height)) { |
||||
this.element.css({height: o.height - 2, lineHeight: (o.height - 2) + 'px'}); |
||||
} |
||||
if (BI.isKey(o.iconClass)) { |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.icon", |
||||
width: 18 |
||||
}); |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
text: o.text, |
||||
value: o.value |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.horizontal_auto", |
||||
cls: "button-" + o.level + " " + o.iconClass, |
||||
element: this.element, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
items: [{ |
||||
type: "bi.horizontal", |
||||
items: [this.icon, this.text] |
||||
}] |
||||
}) |
||||
} else { |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "button-" + o.level, |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
forceCenter: o.forceCenter, |
||||
textWidth: o.textWidth, |
||||
textHeight: o.textHeight, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
element: this.element, |
||||
text: o.text, |
||||
value: o.value |
||||
}); |
||||
} |
||||
this.element.css({"min-width": this._const.minWidth - 2 + "px"}); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.Button.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.Button.EVENT_CHANGE, this); |
||||
} |
||||
}, |
||||
|
||||
setText: function (text) { |
||||
BI.Button.superclass.setText.apply(this, arguments); |
||||
this.text.setText(text); |
||||
}, |
||||
|
||||
setValue: function (text) { |
||||
BI.Button.superclass.setValue.apply(this, arguments); |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue(text); |
||||
} |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.Button.superclass.setEnable.apply(this, arguments); |
||||
this.text.setEnable(b); |
||||
this.icon && this.icon.setEnable(b); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
BI.Button.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
$.shortcut('bi.button', BI.Button); |
||||
BI.Button.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
})(jQuery); |
@ -0,0 +1,87 @@
|
||||
/** |
||||
* guy |
||||
* 可以点击的一行文字 |
||||
* @class BI.TextButton |
||||
* @extends BI.BasicButton |
||||
* 文字button |
||||
*/ |
||||
BI.TextButton = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.TextButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend( conf, { |
||||
tagName: "a", |
||||
baseCls: (conf.baseCls || "") + " bi-text-button display-block", |
||||
textAlign: "center", |
||||
whiteSpace: "nowrap", |
||||
forceCenter: false, |
||||
textWidth: null, |
||||
textHeight: null, |
||||
hgap: 0, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
text:"", |
||||
py: "" |
||||
}) |
||||
}, |
||||
|
||||
_init:function() { |
||||
BI.TextButton.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
textWidth: o.textWidth, |
||||
textHeight: o.textHeight, |
||||
forceCenter: o.forceCenter, |
||||
width: o.width, |
||||
height: o.height, |
||||
hgap: o.hgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
py: o.py |
||||
}); |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.TextButton.superclass.doClick.apply(this, arguments); |
||||
if(this.isValid()) { |
||||
this.fireEvent(BI.TextButton.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function(){ |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function(){ |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setText: function(text){ |
||||
BI.TextButton.superclass.setText.apply(this, arguments); |
||||
text = BI.isArray(text) ? text.join(",") : text; |
||||
this.text.setText(text); |
||||
}, |
||||
|
||||
setValue: function(text){ |
||||
BI.TextButton.superclass.setValue.apply(this, arguments); |
||||
if(!this.isReadOnly()) { |
||||
text = BI.isArray(text) ? text.join(",") : text; |
||||
this.text.setValue(text); |
||||
} |
||||
} |
||||
}); |
||||
BI.TextButton.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.text_button", BI.TextButton); |
@ -0,0 +1,137 @@
|
||||
/** |
||||
* guy |
||||
* 一个占位符和两个icon和一行数 组成的一行listitem |
||||
* |
||||
* Created by GUY on 2015/9/15. |
||||
* @class BI.BlankIconTextIconItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.BlankIconTextIconItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-blank-icon-text-icon-item", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
iconCls1: "close-ha-font", |
||||
iconCls2: "close-ha-font", |
||||
blankWidth: 0, |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.BlankIconTextIconItem.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
|
||||
var icon1 = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls1, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}) |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls2, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}, |
||||
top: 0, |
||||
bottom: 0, |
||||
right: 0 |
||||
}] |
||||
}) |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", { |
||||
type: "bi.layout", |
||||
width: o.blankWidth |
||||
}, icon1, this.text, { |
||||
type: "bi.layout", |
||||
width: c.commonWidth |
||||
}) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.BlankIconTextIconItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.BlankIconTextIconItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.BlankIconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.blank_icon_text_icon_item", BI.BlankIconTextIconItem); |
@ -0,0 +1,111 @@
|
||||
/** |
||||
* 带有一个占位 |
||||
* |
||||
* Created by GUY on 2015/9/11. |
||||
* @class BI.BlankIconTextItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.BlankIconTextItem = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.BlankIconTextItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-blank-icon-text-item", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
cls: "close-ha-font", |
||||
blankWidth: 0, |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.BlankIconTextItem.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
var blank = BI.createWidget({ |
||||
type: "bi.layout", |
||||
width: o.blankWidth |
||||
}) |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", blank, this.icon, this.text) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.BlankIconTextItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.BlankIconTextItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
} |
||||
}); |
||||
BI.BlankIconTextItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.blank_icon_text_item", BI.BlankIconTextItem); |
@ -0,0 +1,134 @@
|
||||
/** |
||||
* guy |
||||
* 两个icon和一行数 组成的一行listitem |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.IconTextIconItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.IconTextIconItem = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.IconTextIconItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-icon-text-icon-item", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
iconCls1: "close-ha-font", |
||||
iconCls2: "close-ha-font", |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.IconTextIconItem.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
|
||||
var icon1 = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls1, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}) |
||||
var blank = BI.createWidget({ |
||||
type: "bi.layout", |
||||
width: c.commonWidth |
||||
}) |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls2, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}, |
||||
top: 0, |
||||
bottom: 0, |
||||
right: 0 |
||||
}] |
||||
}) |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", icon1, this.text, blank) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.IconTextIconItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.IconTextIconItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.IconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_text_icon_item", BI.IconTextIconItem); |
@ -0,0 +1,106 @@
|
||||
/** |
||||
* guy |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.IconTextItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.IconTextItem = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.IconTextItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-icon-text-item", |
||||
direction: BI.Direction.Left, |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.IconTextItem.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}); |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.icon, this.text) |
||||
})))); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.IconTextItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.IconTextItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
} |
||||
}); |
||||
BI.IconTextItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_text_item", BI.IconTextItem); |
@ -0,0 +1,107 @@
|
||||
/** |
||||
* |
||||
* 图标的button |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.TextIconItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.TextIconItem = BI.inherit(BI.BasicButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.TextIconItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-text-icon-item", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
cls: "close-ha-font", |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.TextIconItem.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}); |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", this.text, this.icon) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.TextIconItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.TextIconItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
} |
||||
}); |
||||
BI.TextIconItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.text_icon_item", BI.TextIconItem); |
@ -0,0 +1,86 @@
|
||||
/** |
||||
* guy |
||||
* 一个button和一行数 组成的一行listitem |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.TextItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.TextItem = BI.inherit(BI.BasicButton, { |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.TextItem.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-text-item", |
||||
textAlign: "left", |
||||
whiteSpace: "nowrap", |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.TextItem.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
textHeight: o.whiteSpace == "nowrap" ? o.height : o.textHeight, |
||||
height: o.height, |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
py: o.py |
||||
}); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.TextItem.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.TextItem.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.TextItem.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.text_item", BI.TextItem); |
@ -0,0 +1,124 @@
|
||||
/** |
||||
* guy |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.IconTextIconNode |
||||
* @extends BI.NodeButton |
||||
*/ |
||||
BI.IconTextIconNode = BI.inherit(BI.NodeButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.IconTextIconNode.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-icon-text-icon-node", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
iconCls1: "close-ha-font", |
||||
iconCls2: "close-ha-font", |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.IconTextIconNode.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
|
||||
var icon1 = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls1, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}) |
||||
var blank = BI.createWidget({ |
||||
type: "bi.layout", |
||||
width: c.commonWidth |
||||
}) |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.center_adapt", |
||||
cls: o.iconCls2, |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}, |
||||
top: 0, |
||||
bottom: 0, |
||||
right: 0 |
||||
}] |
||||
}) |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", icon1, this.text, blank) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.IconTextIconNode.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.IconTextIconNode.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.IconTextIconNode.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_text_icon_node", BI.IconTextIconNode); |
@ -0,0 +1,97 @@
|
||||
/** |
||||
* guy |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.IconTextNode |
||||
* @extends BI.NodeButton |
||||
*/ |
||||
BI.IconTextNode = BI.inherit(BI.NodeButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.IconTextNode.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-icon-text-node", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
cls: "close-ha-font", |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.IconTextNode.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}) |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon, this.text) |
||||
})))); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.IconTextNode.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.IconTextNode.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
} |
||||
}); |
||||
BI.IconTextNode.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_text_node", BI.IconTextNode); |
@ -0,0 +1,96 @@
|
||||
/** |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.TextIconNode |
||||
* @extends BI.NodeButton |
||||
*/ |
||||
BI.TextIconNode = BI.inherit(BI.NodeButton, { |
||||
_const: { |
||||
commonWidth: 25 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.TextIconNode.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-text-icon-node", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
cls: "close-ha-font", |
||||
iconHeight: null, |
||||
iconWidth: null, |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.TextIconNode.superclass._init.apply(this, arguments); |
||||
var o = this.options, c = this._const; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
height: o.height |
||||
}) |
||||
this.icon = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
width: c.commonWidth, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.icon", |
||||
width: o.iconWidth, |
||||
height: o.iconHeight |
||||
} |
||||
}] |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", this.text, this.icon) |
||||
})))); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.TextIconNode.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.TextIconNode.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
} |
||||
}); |
||||
BI.TextIconNode.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.text_icon_node", BI.TextIconNode); |
@ -0,0 +1,77 @@
|
||||
/** |
||||
* guy |
||||
* |
||||
* Created by GUY on 2015/9/9. |
||||
* @class BI.TextNode |
||||
* @extends BI.NodeButton |
||||
*/ |
||||
BI.TextNode = BI.inherit(BI.NodeButton, { |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.TextNode.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-text-node", |
||||
textAlign: "left", |
||||
whiteSpace: "nowrap", |
||||
textHgap: 0, |
||||
textVgap: 0, |
||||
textLgap: 0, |
||||
textRgap: 0 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.TextNode.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
textHeight: o.whiteSpace == "nowrap" ? o.height : o.textHeight, |
||||
height: o.height, |
||||
hgap: o.textHgap, |
||||
vgap: o.textVgap, |
||||
lgap: o.textLgap, |
||||
rgap: o.textRgap, |
||||
text: o.text, |
||||
value: o.value, |
||||
keyword: o.keyword, |
||||
py: o.py |
||||
}); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.TextNode.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.TextNode.EVENT_CHANGE, this.getValue(), this); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setValue: function () { |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue.apply(this.text, arguments); |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.text.getValue(); |
||||
}, |
||||
|
||||
setText: function () { |
||||
this.text.setText.apply(this.text, arguments); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.text.getText(); |
||||
} |
||||
}); |
||||
BI.TextNode.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
$.shortcut("bi.text_node", BI.TextNode); |
@ -0,0 +1,146 @@
|
||||
/** |
||||
* |
||||
* Created by GUY on 2016/1/15. |
||||
* @class BI.CodeEditor |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.CodeEditor = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
return $.extend(BI.CodeEditor.superclass._defaultConfig.apply(), { |
||||
baseCls: 'bi-code-editor', |
||||
value: '', |
||||
watermark: "" |
||||
}); |
||||
}, |
||||
_init: function () { |
||||
BI.CodeEditor.superclass._init.apply(this, arguments); |
||||
var o = this.options, self = this; |
||||
this.editor = CodeMirror(this.element[0], { |
||||
textWrapping: true, |
||||
lineWrapping: true, |
||||
lineNumbers: false |
||||
}); |
||||
this.editor.on("change", function (cm, change) { |
||||
BI.nextTick(function () { |
||||
self.fireEvent(BI.CodeEditor.EVENT_CHANGE) |
||||
}); |
||||
}); |
||||
|
||||
this.editor.on("focus", function () { |
||||
watermark.setVisible(false); |
||||
self.fireEvent(BI.CodeEditor.EVENT_FOCUS); |
||||
}); |
||||
|
||||
this.editor.on("blur", function () { |
||||
watermark.setVisible(BI.isEmptyString(self.getValue())); |
||||
self.fireEvent(BI.CodeEditor.EVENT_BLUR); |
||||
}); |
||||
|
||||
// this.editor.on("blur", function () {
|
||||
// self.editor.execCommand("goLineEnd");
|
||||
// });
|
||||
|
||||
//水印
|
||||
var watermark = BI.createWidget({ |
||||
type: "bi.label", |
||||
text: o.watermark, |
||||
cls: "bi-water-mark", |
||||
whiteSpace: "nowrap", |
||||
textAlign: "left" |
||||
}); |
||||
watermark.element.bind( |
||||
"mousedown", function (e) { |
||||
self.insertString(""); |
||||
self.editor.focus(); |
||||
e.stopEvent(); |
||||
} |
||||
); |
||||
watermark.element.bind("click", function (e) { |
||||
self.editor.focus(); |
||||
e.stopEvent(); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: watermark, |
||||
top: 0, |
||||
left: 5 |
||||
}] |
||||
}); |
||||
|
||||
if (BI.isKey(o.value)) { |
||||
BI.nextTick(function () { |
||||
self.setValue(o.value); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.CodeEditor.superclass.setEnable.apply(this, arguments); |
||||
this.editor.setOption("readOnly", b === true ? false : "nocursor") |
||||
}, |
||||
|
||||
insertParam: function(param){ |
||||
var from = this.editor.getCursor(); |
||||
this.editor.replaceSelection(param); |
||||
var to = this.editor.getCursor(); |
||||
this.editor.markText(from, to, {className: 'param', atomic: true}); |
||||
this.editor.replaceSelection(" "); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
insertString: function(str){ |
||||
this.editor.replaceSelection(str); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.editor.getValue("\n", function (line) { |
||||
var rawText = line.text, value = line.text, num = 0; |
||||
value.text = rawText; |
||||
_.forEach(line.markedSpans, function (i, ms) { |
||||
switch (i.marker.className) { |
||||
case "param": |
||||
var fieldNameLength = i.to - i.from; |
||||
value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); |
||||
num += fieldNameLength + 3; |
||||
break; |
||||
} |
||||
}); |
||||
return value; |
||||
}); |
||||
}, |
||||
|
||||
_analyzeContent: function (v) { |
||||
var regx = /\$[\{][^\}]*[\}]|\w*\w|\$\{[^\$\(\)\+\-\*\/)\$,]*\w\}|\$\{[^\$\(\)\+\-\*\/]*\w\}|\$\{[^\$\(\)\+\-\*\/]*[\u4e00-\u9fa5]\}|\w|(.)|\n/g; |
||||
return v.match(regx); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
var self = this, result; |
||||
this.refresh(); |
||||
self.editor.setValue(""); |
||||
result = this._analyzeContent(v || ""); |
||||
BI.each(result, function (i, item) { |
||||
var fieldRegx = /\$[\{][^\}]*[\}]/; |
||||
var str = item.match(fieldRegx); |
||||
if (BI.isNotEmptyArray(str)) { |
||||
self.insertParam(str[0].substring(2, item.length - 1)); |
||||
} else { |
||||
self.insertString(item); |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
refresh: function(){ |
||||
var self = this; |
||||
BI.nextTick(function () { |
||||
self.editor.refresh(); |
||||
}); |
||||
} |
||||
}); |
||||
BI.CodeEditor.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.CodeEditor.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.CodeEditor.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
$.shortcut("bi.code_editor", BI.CodeEditor); |
@ -0,0 +1,330 @@
|
||||
/** |
||||
* Created by GUY on 2015/4/15. |
||||
* @class BI.Editor |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.Editor = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Editor.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: "bi-editor", |
||||
hgap: 4, |
||||
vgap: 2, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
tipType: "warning", |
||||
inputType: "text", |
||||
validationChecker: BI.emptyFn, |
||||
quitChecker: BI.emptyFn, |
||||
mouseOut: false, |
||||
allowBlank: false, |
||||
watermark: "", |
||||
errorText: "" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Editor.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.editor = this.addWidget(BI.createWidget({ |
||||
type: "bi.input", |
||||
element: "<input type='" + o.inputType + "'/>", |
||||
watermark: o.watermark, |
||||
validationChecker: o.validationChecker, |
||||
quitChecker: o.quitChecker, |
||||
mouseOut: o.mouseOut, |
||||
allowBlank: o.allowBlank |
||||
})); |
||||
this.editor.element.css({ |
||||
"width": "100%", |
||||
"height": "100%", |
||||
"border": "none", |
||||
"outline": "none", |
||||
"padding": "0", |
||||
"margin": "0" |
||||
}); |
||||
if (BI.isKey(this.options.watermark)) { |
||||
this.watermark = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "bi-water-mark", |
||||
text: this.options.watermark, |
||||
forceCenter: true, |
||||
whiteSpace: "nowrap", |
||||
textAlign: "left" |
||||
}); |
||||
this.watermark.element.bind({ |
||||
mousedown: function (e) { |
||||
if (self.isEnabled()) { |
||||
self.editor.isEditing() || self.editor.focus(); |
||||
} else { |
||||
self.editor.isEditing() && self.editor.blur(); |
||||
} |
||||
e.stopEvent(); |
||||
} |
||||
}); |
||||
this.watermark.element.bind("click", function (e) { |
||||
if (self.isEnabled()) { |
||||
self.editor.isEditing() || self.editor.focus(); |
||||
} else { |
||||
self.editor.isEditing() && self.editor.blur(); |
||||
} |
||||
e.stopEvent(); |
||||
}); |
||||
this.watermark.element.css({ |
||||
position: "absolute", |
||||
left: "3px", |
||||
right: "3px", |
||||
top: "0px", |
||||
bottom: "0px" |
||||
}); |
||||
} |
||||
var items = [{ |
||||
el: { |
||||
type: "bi.default", |
||||
items: this.watermark ? [this.editor, this.watermark] : [this.editor] |
||||
}, |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
}]; |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: items |
||||
}); |
||||
this.editor.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_FOCUS, function () { |
||||
self._checkError(); |
||||
self.element.addClass("bi-editor-focus"); |
||||
self.fireEvent(BI.Editor.EVENT_FOCUS, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_BLUR, function () { |
||||
self.setErrorVisible(false); |
||||
self.element.removeClass("bi-editor-focus"); |
||||
self.fireEvent(BI.Editor.EVENT_BLUR, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_CLICK, function () { |
||||
self.fireEvent(BI.Editor.EVENT_CLICK, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Editor.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_KEY_DOWN, function (v) { |
||||
self.fireEvent(BI.Editor.EVENT_KEY_DOWN, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_QUICK_DOWN, function (v) { |
||||
self.watermark && self.watermark.invisible(); |
||||
}); |
||||
|
||||
this.editor.on(BI.Input.EVENT_VALID, function () { |
||||
self._checkWaterMark(); |
||||
self.setErrorVisible(false); |
||||
self.fireEvent(BI.Editor.EVENT_VALID, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_ERROR, function () { |
||||
self._checkWaterMark(); |
||||
self.fireEvent(BI.Editor.EVENT_ERROR, arguments); |
||||
self.setErrorVisible(self.isEditing()); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_RESTRICT, function () { |
||||
self._checkWaterMark(); |
||||
var tip = self.setErrorVisible(true); |
||||
tip && tip.element.fadeOut(100, function () { |
||||
tip.element.fadeIn(100); |
||||
}); |
||||
self.fireEvent(BI.Editor.EVENT_RESTRICT, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_EMPTY, function () { |
||||
self._checkWaterMark(); |
||||
self.fireEvent(BI.Editor.EVENT_EMPTY, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_ENTER, function () { |
||||
self.fireEvent(BI.Editor.EVENT_ENTER, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_SPACE, function () { |
||||
self.fireEvent(BI.Editor.EVENT_SPACE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_BACKSPACE, function () { |
||||
self.fireEvent(BI.Editor.EVENT_BACKSPACE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_REMOVE, function () { |
||||
self.fireEvent(BI.Editor.EVENT_REMOVE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_START, function () { |
||||
self.fireEvent(BI.Editor.EVENT_START, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_PAUSE, function () { |
||||
self.fireEvent(BI.Editor.EVENT_PAUSE, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_STOP, function () { |
||||
self.fireEvent(BI.Editor.EVENT_STOP, arguments); |
||||
}); |
||||
this.editor.on(BI.Input.EVENT_CONFIRM, function () { |
||||
self.fireEvent(BI.Editor.EVENT_CONFIRM, arguments); |
||||
}); |
||||
this.element.click(function (e) { |
||||
e.stopPropagation(); |
||||
return false; |
||||
}); |
||||
if (BI.isKey(this.options.value) || BI.isEmptyString(this.options.value)) { |
||||
this.setValue(this.options.value); |
||||
} else { |
||||
this._checkWaterMark(); |
||||
} |
||||
}, |
||||
|
||||
_checkToolTip: function () { |
||||
var o = this.options; |
||||
var errorText = o.errorText; |
||||
if (BI.isFunction(errorText)) { |
||||
errorText = errorText(this.editor.getValue()); |
||||
} |
||||
if (BI.isKey(errorText)) { |
||||
if (!this.isEnabled() || this.isValid() || (BI.Bubbles.has(this.getName()) && BI.Bubbles.get(this.getName()).isVisible())) { |
||||
this.setTitle(""); |
||||
} else { |
||||
this.setTitle(errorText); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
_checkError: function () { |
||||
this.setErrorVisible(this.isEnabled() && !this.isValid()); |
||||
this._checkToolTip(); |
||||
}, |
||||
|
||||
_checkWaterMark: function () { |
||||
var o = this.options; |
||||
if (!this.disabledWarterMark && this.editor.getValue() === "" && BI.isKey(o.watermark)) { |
||||
this.watermark && this.watermark.visible(); |
||||
} else { |
||||
this.watermark && this.watermark.invisible(); |
||||
} |
||||
}, |
||||
|
||||
setErrorText: function (text) { |
||||
this.options.errorText = text; |
||||
}, |
||||
|
||||
getErrorText: function () { |
||||
return this.options.errorText; |
||||
}, |
||||
|
||||
setErrorVisible: function (b) { |
||||
var o = this.options; |
||||
var errorText = o.errorText; |
||||
if (BI.isFunction(errorText)) { |
||||
errorText = errorText(this.editor.getValue()); |
||||
} |
||||
if (!this.disabledError && BI.isKey(errorText)) { |
||||
BI.Bubbles[b ? "show" : "hide"](this.getName(), errorText, this); |
||||
this._checkToolTip(); |
||||
return BI.Bubbles.get(this.getName()); |
||||
} |
||||
}, |
||||
|
||||
disableError: function () { |
||||
this.disabledError = true; |
||||
this._checkError(); |
||||
}, |
||||
|
||||
enableError: function () { |
||||
this.disabledError = false; |
||||
this._checkError(); |
||||
}, |
||||
|
||||
disableWarterMark: function () { |
||||
this.disabledWarterMark = true; |
||||
this._checkWaterMark(); |
||||
}, |
||||
|
||||
enableWarterMark: function () { |
||||
this.disabledWarterMark = false; |
||||
this._checkWaterMark(); |
||||
}, |
||||
|
||||
focus: function () { |
||||
this.element.addClass("text-editor-focus"); |
||||
this.editor.focus(); |
||||
}, |
||||
|
||||
blur: function () { |
||||
this.element.removeClass("text-editor-focus"); |
||||
this.editor.blur(); |
||||
}, |
||||
|
||||
selectAll: function () { |
||||
this.editor.selectAll(); |
||||
}, |
||||
|
||||
onKeyDown: function (k) { |
||||
this.editor.onKeyDown(k); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
BI.Editor.superclass.setValue.apply(this, arguments); |
||||
this.editor.setValue(v); |
||||
this._checkError(); |
||||
this._checkWaterMark(); |
||||
}, |
||||
|
||||
getLastValidValue: function () { |
||||
return BI.trim(this.editor.getLastValidValue()); |
||||
}, |
||||
|
||||
resetLastValidValue: function () { |
||||
this.editor.resetLastValidValue(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
if (!this.isValid()) { |
||||
return BI.trim(this.editor.getLastValidValue()); |
||||
} |
||||
return BI.trim(this.editor.getValue()); |
||||
}, |
||||
|
||||
setValid: function (b) { |
||||
BI.Editor.superclass.setValid.apply(this, arguments); |
||||
this.editor.setValid(b); |
||||
}, |
||||
|
||||
isEditing: function () { |
||||
return this.editor.isEditing(); |
||||
}, |
||||
|
||||
isValid: function () { |
||||
return this.editor.isValid(); |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.Editor.superclass.setEnable.apply(this, arguments); |
||||
this.editor && this.editor.setEnable(b); |
||||
this.watermark && this.watermark.setEnable(b); |
||||
} |
||||
}); |
||||
BI.Editor.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.Editor.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.Editor.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.Editor.EVENT_CLICK = "EVENT_CLICK"; |
||||
BI.Editor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; |
||||
BI.Editor.EVENT_SPACE = "EVENT_SPACE"; |
||||
BI.Editor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; |
||||
|
||||
BI.Editor.EVENT_START = "EVENT_START"; |
||||
BI.Editor.EVENT_PAUSE = "EVENT_PAUSE"; |
||||
BI.Editor.EVENT_STOP = "EVENT_STOP"; |
||||
BI.Editor.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.Editor.EVENT_VALID = "EVENT_VALID"; |
||||
BI.Editor.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.Editor.EVENT_ENTER = "EVENT_ENTER"; |
||||
BI.Editor.EVENT_RESTRICT = "EVENT_RESTRICT"; |
||||
BI.Editor.EVENT_REMOVE = "EVENT_REMOVE"; |
||||
BI.Editor.EVENT_EMPTY = "EVENT_EMPTY"; |
||||
|
||||
$.shortcut("bi.editor", BI.Editor); |
@ -0,0 +1,94 @@
|
||||
/** |
||||
* 多文件 |
||||
* |
||||
* Created by GUY on 2016/4/13. |
||||
* @class BI.MultifileEditor |
||||
* @extends BI.Single |
||||
* @abstract |
||||
*/ |
||||
BI.MultifileEditor = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.MultifileEditor.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-multifile-editor", |
||||
multiple: false, |
||||
maxSize: 1024 * 1024, |
||||
accept: "", |
||||
url: "" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
var self = this, o = this.options; |
||||
BI.MultifileEditor.superclass._init.apply(this, arguments); |
||||
this.file = BI.createWidget({ |
||||
type: "bi.file", |
||||
cls: "multifile-editor", |
||||
width: "100%", |
||||
height: "100%", |
||||
name: o.name, |
||||
url: o.url, |
||||
multiple: o.multiple, |
||||
accept: o.accept, |
||||
maxSize: o.maxSize |
||||
}); |
||||
this.file.on(BI.File.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.MultifileEditor.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.file.on(BI.File.EVENT_UPLOADSTART, function () { |
||||
self.fireEvent(BI.MultifileEditor.EVENT_UPLOADSTART, arguments); |
||||
}); |
||||
this.file.on(BI.File.EVENT_ERROR, function () { |
||||
self.fireEvent(BI.MultifileEditor.EVENT_ERROR, arguments); |
||||
}); |
||||
this.file.on(BI.File.EVENT_PROGRESS, function () { |
||||
self.fireEvent(BI.MultifileEditor.EVENT_PROGRESS, arguments); |
||||
}); |
||||
this.file.on(BI.File.EVENT_UPLOADED, function () { |
||||
self.fireEvent(BI.MultifileEditor.EVENT_UPLOADED, arguments); |
||||
}); |
||||
|
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.adaptive", |
||||
scrollable: false, |
||||
items: [this.file] |
||||
}, |
||||
top: 0, |
||||
right: 0, |
||||
left: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
select: function () { |
||||
this.file.select(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.file.getValue(); |
||||
}, |
||||
|
||||
upload: function () { |
||||
this.file.upload(); |
||||
}, |
||||
|
||||
reset: function () { |
||||
this.file.reset(); |
||||
}, |
||||
|
||||
setEnable: function (enable) { |
||||
BI.MultiFile.superclass.setEnable.apply(this, arguments); |
||||
this.file.setEnable(enable); |
||||
} |
||||
}); |
||||
BI.MultifileEditor.EVENT_CHANGE = "MultifileEditor.EVENT_CHANGE"; |
||||
BI.MultifileEditor.EVENT_UPLOADSTART = "MultifileEditor.EVENT_UPLOADSTART"; |
||||
BI.MultifileEditor.EVENT_ERROR = "MultifileEditor.EVENT_ERROR"; |
||||
BI.MultifileEditor.EVENT_PROGRESS = "MultifileEditor.EVENT_PROGRESS"; |
||||
BI.MultifileEditor.EVENT_UPLOADED = "MultifileEditor.EVENT_UPLOADED"; |
||||
$.shortcut("bi.multifile_editor", BI.MultifileEditor); |
@ -0,0 +1,93 @@
|
||||
/** |
||||
* |
||||
* Created by GUY on 2016/1/18. |
||||
* @class BI.TextAreaEditor |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.TextAreaEditor = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
return $.extend(BI.TextAreaEditor.superclass._defaultConfig.apply(), { |
||||
baseCls: 'bi-textarea-editor', |
||||
value: '' |
||||
}); |
||||
}, |
||||
_init: function () { |
||||
BI.TextAreaEditor.superclass._init.apply(this, arguments); |
||||
var o = this.options, self = this; |
||||
this.content = BI.createWidget({ |
||||
type: "bi.layout", |
||||
tagName: "textarea", |
||||
width: "100%", |
||||
height: "100%", |
||||
cls: "textarea-editor-content display-block" |
||||
}); |
||||
this.content.element.css({"resize": "none"}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.adaptive", |
||||
items: [this.content] |
||||
}, |
||||
left: 0, |
||||
right: 3, |
||||
top: 0, |
||||
bottom: 5 |
||||
}] |
||||
}); |
||||
|
||||
this.content.element.focus(function () { |
||||
self.content.element.addClass("textarea-editor-focus"); |
||||
self.fireEvent(BI.TextAreaEditor.EVENT_FOCUS); |
||||
}); |
||||
this.content.element.blur(function () { |
||||
self.content.element.removeClass("textarea-editor-focus"); |
||||
self.fireEvent(BI.TextAreaEditor.EVENT_BLUR); |
||||
}); |
||||
if (BI.isKey(o.value)) { |
||||
self.setValue(o.value); |
||||
} |
||||
}, |
||||
|
||||
focus: function () { |
||||
this.content.element.addClass("textarea-editor-focus"); |
||||
this.content.element.focus(); |
||||
}, |
||||
|
||||
blur: function () { |
||||
this.content.element.removeClass("textarea-editor-focus"); |
||||
this.content.element.blur(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.content.element.val(); |
||||
}, |
||||
|
||||
setValue: function (value) { |
||||
this.content.element.val(value); |
||||
}, |
||||
|
||||
setStyle: function (style) { |
||||
this.style = style; |
||||
this.element.css(style); |
||||
this.content.element.css(style) |
||||
}, |
||||
|
||||
getStyle: function () { |
||||
return this.style; |
||||
}, |
||||
|
||||
setValid: function (b) { |
||||
BI.TextAreaEditor.superclass.setValid.apply(this, arguments); |
||||
this.content.setValid(b); |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.TextAreaEditor.superclass.setEnable.apply(this, arguments); |
||||
this.content.setEnable(b); |
||||
} |
||||
}); |
||||
BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.TextAreaEditor.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
$.shortcut("bi.textarea_editor", BI.TextAreaEditor); |
@ -0,0 +1,18 @@
|
||||
/** |
||||
* guy 图标 |
||||
* @class BI.Icon |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.Icon = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Icon.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
tagName: "i", |
||||
baseCls: (conf.baseCls || "") + " x-icon b-font horizon-center display-block" |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.Icon.superclass._init.apply(this, arguments); |
||||
} |
||||
}); |
||||
$.shortcut("bi.icon", BI.Icon); |
@ -0,0 +1,42 @@
|
||||
/** |
||||
* @class BI.Iframe |
||||
* @extends BI.Single |
||||
* @abstract |
||||
* Created by GameJian on 2016/3/2. |
||||
*/ |
||||
BI.Iframe = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Iframe.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-iframe", |
||||
src: "", |
||||
width: "100%", |
||||
height: "100%" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
var o = this.options; |
||||
this.options.element = $("<iframe frameborder='0' src='" + o.src + "'>"); |
||||
BI.Iframe.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
setSrc: function (src) { |
||||
this.options.src = src; |
||||
this.element.attr("src", src); |
||||
}, |
||||
|
||||
getSrc: function () { |
||||
return this.options.src; |
||||
}, |
||||
|
||||
getWidth: function () { |
||||
return this.options.width |
||||
}, |
||||
|
||||
getHeight: function () { |
||||
return this.options.height |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.iframe", BI.Iframe); |
@ -0,0 +1,36 @@
|
||||
/** |
||||
* ͼƬ |
||||
* |
||||
* Created by GUY on 2016/1/26. |
||||
* @class BI.Img |
||||
* @extends BI.Single |
||||
* @abstract |
||||
*/ |
||||
BI.Img = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Img.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-img", |
||||
src: "", |
||||
width: "100%", |
||||
height: "100%" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
var o = this.options; |
||||
this.options.element = $("<img src='" + o.src + "'>"); |
||||
BI.Img.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
setSrc: function (src) { |
||||
this.options.src = src; |
||||
this.element.attr("src", src); |
||||
}, |
||||
|
||||
getSrc: function () { |
||||
return this.options.src; |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.img", BI.Img); |
@ -0,0 +1,34 @@
|
||||
/** |
||||
* guy |
||||
* @extends BI.Single |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.Checkbox = BI.inherit(BI.IconButton, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.Checkbox.superclass._defaultConfig.apply(this,arguments); |
||||
return BI.extend(conf, { |
||||
tagName: "a", |
||||
baseCls: (conf.baseCls || "") + " bi-checkbox check-box-icon", |
||||
selected: false, |
||||
handler: BI.emptyFn, |
||||
width: 16, |
||||
height: 16, |
||||
iconWidth: 16, |
||||
iconHeight: 16 |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.Checkbox.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.Checkbox.superclass.doClick.apply(this, arguments); |
||||
if(this.isValid()){ |
||||
this.fireEvent(BI.Checkbox.EVENT_CHANGE); |
||||
} |
||||
} |
||||
}); |
||||
BI.Checkbox.EVENT_CHANGE = "Checkbox.EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.checkbox", BI.Checkbox); |
@ -0,0 +1,605 @@
|
||||
/** |
||||
* 文件 |
||||
* |
||||
* Created by GUY on 2016/1/27. |
||||
* @class BI.File |
||||
* @extends BI.Single |
||||
* @abstract |
||||
*/ |
||||
(function () { |
||||
|
||||
/** |
||||
* @description normalize input.files. create if not present, add item method if not present |
||||
* @param Object generated wrap object |
||||
* @return Object the wrap object itself |
||||
*/ |
||||
var F = (function (item) { |
||||
return function (input) { |
||||
var files = input.files || [input]; |
||||
if (!files.item) |
||||
files.item = item; |
||||
return files; |
||||
}; |
||||
})(function (i) { |
||||
return this[i]; |
||||
}); |
||||
|
||||
var event = { |
||||
|
||||
/** |
||||
* @description add an event via addEventListener or attachEvent |
||||
* @param DOMElement the element to add event |
||||
* @param String event name without "on" (e.g. "mouseover") |
||||
* @param Function the callback to associate as event |
||||
* @return Object noswfupload.event |
||||
*/ |
||||
add: document.addEventListener ? |
||||
function (node, name, callback) { |
||||
node.addEventListener(name, callback, false); |
||||
return this; |
||||
} : |
||||
function (node, name, callback) { |
||||
node.attachEvent("on" + name, callback); |
||||
return this; |
||||
}, |
||||
|
||||
/** |
||||
* @description remove an event via removeEventListener or detachEvent |
||||
* @param DOMElement the element to remove event |
||||
* @param String event name without "on" (e.g. "mouseover") |
||||
* @param Function the callback associated as event |
||||
* @return Object noswfupload.event |
||||
*/ |
||||
del: document.removeEventListener ? |
||||
function (node, name, callback) { |
||||
node.removeEventListener(name, callback, false); |
||||
return this; |
||||
} : |
||||
function (node, name, callback) { |
||||
node.detachEvent("on" + name, callback); |
||||
return this; |
||||
}, |
||||
|
||||
/** |
||||
* @description to block event propagation and prevent event default |
||||
* @param void generated event or undefined |
||||
* @return Boolean false |
||||
*/ |
||||
stop: function (e) { |
||||
if (!e) { |
||||
if (self.event) |
||||
event.returnValue = !(event.cancelBubble = true); |
||||
} else { |
||||
e.stopPropagation ? e.stopPropagation() : e.cancelBubble = true; |
||||
e.preventDefault ? e.preventDefault() : e.returnValue = false; |
||||
} |
||||
; |
||||
return false; |
||||
} |
||||
}; |
||||
|
||||
var sendFile = (function (toString) { |
||||
var multipart = function (boundary, name, file) { |
||||
return "--".concat( |
||||
boundary, CRLF, |
||||
'Content-Disposition: form-data; name="', name, '"; filename="', BI.cjkEncode(file.fileName), '"', CRLF, |
||||
"Content-Type: application/octet-stream", CRLF, |
||||
CRLF, |
||||
file.getAsBinary(), CRLF, |
||||
"--", boundary, "--", CRLF |
||||
); |
||||
}, |
||||
isFunction = function (Function) { |
||||
return toString.call(Function) === "[object Function]"; |
||||
}, |
||||
split = "onabort.onerror.onloadstart.onprogress".split("."), |
||||
length = split.length, |
||||
CRLF = "\r\n", |
||||
xhr = this.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"), |
||||
sendFile; |
||||
|
||||
// FireFox 3+, Safari 4 beta (Chrome 2 beta file is buggy and will not work)
|
||||
if (xhr.upload || xhr.sendAsBinary) |
||||
sendFile = function (handler, maxSize, width, height) { |
||||
if (-1 < maxSize && maxSize < handler.file.fileSize) { |
||||
if (isFunction(handler.onerror)) |
||||
handler.onerror(); |
||||
return; |
||||
} |
||||
for (var |
||||
xhr = new XMLHttpRequest, |
||||
upload = xhr.upload || { |
||||
addEventListener: function (event, callback) { |
||||
this["on" + event] = callback |
||||
} |
||||
}, |
||||
i = 0; |
||||
i < length; |
||||
i++ |
||||
) |
||||
upload.addEventListener( |
||||
split[i].substring(2), |
||||
(function (event) { |
||||
return function (rpe) { |
||||
if (isFunction(handler[event])) |
||||
handler[event](rpe, xhr); |
||||
}; |
||||
})(split[i]), |
||||
false |
||||
); |
||||
upload.addEventListener( |
||||
"load", |
||||
function (rpe) { |
||||
if (handler.onreadystatechange === false) { |
||||
if (isFunction(handler.onload)) |
||||
handler.onload(rpe, xhr); |
||||
} else { |
||||
setTimeout(function () { |
||||
if (xhr.readyState === 4) { |
||||
if (isFunction(handler.onload)) |
||||
handler.onload(rpe, xhr); |
||||
} else { |
||||
setTimeout(arguments.callee, 15); |
||||
} |
||||
}, 15); |
||||
} |
||||
}, |
||||
false |
||||
); |
||||
xhr.open("post", handler.url + '&filename=' + BI.cjkEncode(handler.file.fileName), true); |
||||
if (!xhr.upload) { |
||||
var rpe = {loaded: 0, total: handler.file.fileSize || handler.file.size, simulation: true}; |
||||
rpe.interval = setInterval(function () { |
||||
rpe.loaded += 1024 / 4; |
||||
if (rpe.total <= rpe.loaded) |
||||
rpe.loaded = rpe.total; |
||||
upload.onprogress(rpe); |
||||
}, 100); |
||||
xhr.onabort = function () { |
||||
upload.onabort({}); |
||||
}; |
||||
xhr.onerror = function () { |
||||
upload.onerror({}); |
||||
}; |
||||
xhr.onreadystatechange = function () { |
||||
switch (xhr.readyState) { |
||||
case 2: |
||||
case 3: |
||||
if (rpe.total <= rpe.loaded) |
||||
rpe.loaded = rpe.total; |
||||
upload.onprogress(rpe); |
||||
break; |
||||
case 4: |
||||
clearInterval(rpe.interval); |
||||
rpe.interval = 0; |
||||
rpe.loaded = rpe.total; |
||||
upload.onprogress(rpe); |
||||
if (199 < xhr.status && xhr.status < 400) { |
||||
upload["onload"]({}); |
||||
var attachO = BI.jsonDecode(xhr.responseText); |
||||
attachO.filename = BI.cjkDecode(handler.file.fileName); |
||||
if (handler.file.type.indexOf('image') != -1) { |
||||
attachO.attach_type = "image"; |
||||
} |
||||
handler.attach_array.push(attachO); |
||||
} else { |
||||
upload["onerror"]({}); |
||||
} |
||||
break; |
||||
} |
||||
}; |
||||
upload.onloadstart(rpe); |
||||
} else { |
||||
xhr.onreadystatechange = function () { |
||||
switch (xhr.readyState) { |
||||
case 4: |
||||
var attachO = BI.jsonDecode(xhr.responseText); |
||||
if (handler.file.type.indexOf('image') != -1) { |
||||
attachO.attach_type = "image"; |
||||
} |
||||
attachO.filename = BI.cjkDecode(handler.file.fileName); |
||||
if (handler.maxlength == 1) { |
||||
handler.attach_array[0] = attachO; |
||||
// handler.attach_array.push(attachO);
|
||||
} else { |
||||
handler.attach_array.push(attachO); |
||||
} |
||||
break; |
||||
} |
||||
} |
||||
} |
||||
var boundary = "AjaxUploadBoundary" + (new Date).getTime(); |
||||
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); |
||||
if (handler.file.getAsBinary) { |
||||
xhr[xhr.sendAsBinary ? "sendAsBinary" : "send"](multipart(boundary, handler.name, handler.file)); |
||||
} else { |
||||
xhr.setRequestHeader("Content-Type", "multipart/form-data"); |
||||
// xhr.setRequestHeader("X-Name", handler.name);
|
||||
// xhr.setRequestHeader("X-File-Name", handler.file.fileName);
|
||||
var form = new FormData(); |
||||
form.append("FileData", handler.file); |
||||
xhr.send(form); |
||||
} |
||||
return handler; |
||||
}; |
||||
// Internet Explorer, Opera, others
|
||||
else |
||||
sendFile = function (handler, maxSize, width, height) { |
||||
var url = handler.url.concat(-1 === handler.url.indexOf("?") ? "?" : "&", "AjaxUploadFrame=true"), |
||||
rpe = { |
||||
loaded: 1, total: 100, simulation: true, interval: setInterval(function () { |
||||
if (rpe.loaded < rpe.total) |
||||
++rpe.loaded; |
||||
if (isFunction(handler.onprogress)) |
||||
handler.onprogress(rpe, {}); |
||||
}, 100) |
||||
}, |
||||
onload = function () { |
||||
iframe.onreadystatechange = iframe.onload = iframe.onerror = null; |
||||
form.parentNode.removeChild(form); |
||||
form = null; |
||||
clearInterval(rpe.interval); |
||||
//rpe.loaded = rpe.total;
|
||||
try { |
||||
var responseText = (iframe.contentWindow.document || iframe.contentWindow.contentDocument).body.innerHTML; |
||||
var attachO = BI.jsonDecode(responseText); |
||||
if (handler.file.type.indexOf('image') != -1) { |
||||
attachO.attach_type = "image"; |
||||
} |
||||
|
||||
//attachO.fileSize = responseText.length;
|
||||
attachO.filename = BI.cjkDecode(handler.file.fileName); |
||||
if (handler.maxlength == 1) { |
||||
handler.attach_array[0] = attachO; |
||||
} else { |
||||
handler.attach_array.push(attachO); |
||||
} |
||||
} catch (e) { |
||||
if (isFunction(handler.onerror)) |
||||
handler.onerror(rpe, event || window.event); |
||||
} |
||||
if (isFunction(handler.onload)) |
||||
handler.onload(rpe, {responseText: responseText}); |
||||
}, |
||||
target = ["AjaxUpload", (new Date).getTime(), String(Math.random()).substring(2)].join("_"); |
||||
try { // IE < 8 does not accept enctype attribute ...
|
||||
var form = document.createElement('<form enctype="multipart/form-data"></form>'), |
||||
iframe = handler.iframe || (handler.iframe = document.createElement('<iframe id="' + target + '" name="' + target + '" src="' + url + '"></iframe>')); |
||||
} catch (e) { |
||||
var form = document.createElement('form'), |
||||
iframe = handler.iframe || (handler.iframe = document.createElement("iframe")); |
||||
form.setAttribute("enctype", "multipart/form-data"); |
||||
iframe.setAttribute("name", iframe.id = target); |
||||
iframe.setAttribute("src", url); |
||||
} |
||||
; |
||||
iframe.style.position = "absolute"; |
||||
iframe.style.left = iframe.style.top = "-10000px"; |
||||
iframe.onload = onload; |
||||
iframe.onerror = function (event) { |
||||
if (isFunction(handler.onerror)) |
||||
handler.onerror(rpe, event || window.event); |
||||
}; |
||||
iframe.onreadystatechange = function () { |
||||
if (/loaded|complete/i.test(iframe.readyState)) { |
||||
onload(); |
||||
|
||||
//wei : todo,将附件信息放到handler.attach
|
||||
} |
||||
else if (isFunction(handler.onloadprogress)) { |
||||
if (rpe.loaded < rpe.total) |
||||
++rpe.loaded; |
||||
handler.onloadprogress(rpe, { |
||||
readyState: { |
||||
loading: 2, |
||||
interactive: 3, |
||||
loaded: 4, |
||||
complete: 4 |
||||
}[iframe.readyState] || 1 |
||||
}); |
||||
} |
||||
}; |
||||
form.setAttribute("action", handler.url + '&width=' + width + '&height=' + height); |
||||
form.setAttribute("target", iframe.id); |
||||
form.setAttribute("method", "post"); |
||||
form.appendChild(handler.file); |
||||
form.style.display = "none"; |
||||
if (isFunction(handler.onloadstart)) |
||||
handler.onloadstart(rpe, {}); |
||||
with (document.body || document.documentElement) { |
||||
appendChild(iframe); |
||||
appendChild(form); |
||||
form.submit(); |
||||
} |
||||
; |
||||
return handler; |
||||
}; |
||||
xhr = null; |
||||
return sendFile; |
||||
})(Object.prototype.toString); |
||||
|
||||
var sendFiles = function (handler, maxSize, width, height) { |
||||
|
||||
var length = handler.files.length, |
||||
i = 0, |
||||
onload = handler.onload, |
||||
onloadstart = handler.onloadstart; |
||||
handler.current = 0; |
||||
handler.total = 0; |
||||
handler.sent = 0; |
||||
while (handler.current < length) { |
||||
handler.total += (handler.files[handler.current].fileSize || handler.files[handler.current].size); |
||||
handler.current++; |
||||
} |
||||
handler.current = 0; |
||||
if (length && handler.files[0].fileSize !== -1) { |
||||
handler.file = handler.files[handler.current]; |
||||
|
||||
sendFile(handler, maxSize, width, height).onload = function (rpe, xhr) { |
||||
handler.onloadstart = null; |
||||
handler.sent += (handler.files[handler.current].fileSize || handler.files[handler.current].size); |
||||
if (++handler.current < length) { |
||||
handler.file = handler.files[handler.current]; |
||||
sendFile(handler, maxSize, width, height).onload = arguments.callee; |
||||
} else if (onload) { |
||||
handler.onloadstart = onloadstart; |
||||
handler.onload = onload; |
||||
handler.onload(rpe, xhr); |
||||
} |
||||
}; |
||||
} else if (length) { |
||||
handler.total = length * 100; |
||||
handler.file = handler.files[handler.current]; |
||||
sendFile(handler, maxSize, width, height).onload = function (rpe, xhr) { |
||||
var callee = arguments.callee; |
||||
handler.onloadstart = null; |
||||
handler.sent += 100; |
||||
if (++handler.current < length) { |
||||
if (/\b(chrome|safari)\b/i.test(navigator.userAgent)) { |
||||
handler.iframe.parentNode.removeChild(handler.iframe); |
||||
handler.iframe = null; |
||||
} |
||||
; |
||||
setTimeout(function () { |
||||
handler.file = handler.files[handler.current]; |
||||
sendFile(handler, maxSize, width, height).onload = callee; |
||||
}, 15); |
||||
} else if (onload) { |
||||
setTimeout(function () { |
||||
handler.iframe.parentNode.removeChild(handler.iframe); |
||||
handler.iframe = null; |
||||
handler.onloadstart = onloadstart; |
||||
handler.onload = onload; |
||||
handler.onload(rpe, xhr); |
||||
}, 15); |
||||
} |
||||
}; |
||||
} |
||||
return handler; |
||||
}; |
||||
|
||||
BI.File = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.File.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-file display-block", |
||||
element: "<input type='file'>", |
||||
name: "", |
||||
url: "", |
||||
multiple: true, |
||||
accept: "", /**'*.jpg; *.zip'**/ |
||||
maxSize: 1024 * 1024 |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
var self = this, o = this.options; |
||||
BI.File.superclass._init.apply(this, arguments); |
||||
if (o.multiple === true) { |
||||
this.element.attr("multiple", "multiple"); |
||||
} |
||||
this.element.attr("name", o.name || this.getName()); |
||||
|
||||
BI.nextTick(function () { |
||||
// create the noswfupload.wrap Object
|
||||
// wrap.maxSize 文件大小限制
|
||||
// wrap.maxlength 文件个数限制
|
||||
var _wrap = self.wrap = self._wrap(self.element[0], o.maxSize); |
||||
// fileType could contain whatever text but filter checks *.{extension}
|
||||
// if present
|
||||
|
||||
// handlers
|
||||
|
||||
_wrap.onloadstart = function (rpe, xhr) { |
||||
//BI.Msg.toast("loadstart");
|
||||
self.fireEvent(BI.File.EVENT_UPLOADSTART); |
||||
}; |
||||
|
||||
_wrap.onprogress = function (rpe, xhr) { |
||||
//BI.Msg.toast("onprogress");
|
||||
// percent for each bar
|
||||
|
||||
// fileSize is -1 only if browser does not support file info access
|
||||
// this if splits recent browsers from others
|
||||
if (this.file.fileSize !== -1) { |
||||
// simulation property indicates when the progress event is fake
|
||||
if (rpe.simulation) { |
||||
|
||||
} else { |
||||
|
||||
} |
||||
} else { |
||||
// if fileSIze is -1 browser is using an iframe because it does
|
||||
// not support
|
||||
// files sent via Ajax (XMLHttpRequest)
|
||||
// We can still show some information
|
||||
} |
||||
self.fireEvent(BI.File.EVENT_PROGRESS, { |
||||
file: this.file, |
||||
total: rpe.total, |
||||
loaded: rpe.loaded, |
||||
simulation: rpe.simulation |
||||
}); |
||||
}; |
||||
|
||||
// generated if there is something wrong during upload
|
||||
_wrap.onerror = function () { |
||||
// just inform the user something was wrong
|
||||
self.fireEvent(BI.File.EVENT_ERROR); |
||||
}; |
||||
|
||||
// generated when every file has been sent (one or more, it does not
|
||||
// matter)
|
||||
_wrap.onload = function (rpe, xhr) { |
||||
var self_ = this; |
||||
// just show everything is fine ...
|
||||
// ... and after a second reset the component
|
||||
setTimeout(function () { |
||||
self_.clean(); // remove files from list
|
||||
self_.hide(); // hide progress bars and enable input file
|
||||
|
||||
//BI.Msg.toast("onload");
|
||||
self.fireEvent(BI.File.EVENT_UPLOADED); |
||||
// enable again the submit button/element
|
||||
}, 1000); |
||||
}; |
||||
_wrap.url = o.url ? o.url : BI.servletURL |
||||
+ '?op=fr_attach&cmd=ah_upload'; |
||||
_wrap.fileType = o.accept; //文件类型限制
|
||||
_wrap.attach_array = []; |
||||
_wrap.attach_names = []; |
||||
_wrap.attachNum = 0; |
||||
}); |
||||
}, |
||||
|
||||
_events: function (wrap) { |
||||
var self = this; |
||||
event.add(wrap.dom.input, "change", function () { |
||||
event.del(wrap.dom.input, "change", arguments.callee); |
||||
for (var input = wrap.dom.input.cloneNode(true), i = 0, files = F(wrap.dom.input); i < files.length; i++) { |
||||
var item = files.item(i); |
||||
var tempFile = item.value || item.name; |
||||
var value = item.fileName || (item.fileName = tempFile.split("\\").pop()), |
||||
ext = -1 !== value.indexOf(".") ? value.split(".").pop().toLowerCase() : "unknown", |
||||
size = item.fileSize || item.size; |
||||
if (wrap.fileType && -1 === wrap.fileType.indexOf("*." + ext)) { |
||||
//文件类型不支持
|
||||
BI.Msg.toast("文件类型不支持"); |
||||
self.fireEvent(BI.File.EVENT_ERROR, { |
||||
errorType: 0, |
||||
file: item |
||||
}); |
||||
} else if (wrap.maxSize !== -1 && size && wrap.maxSize < size) { |
||||
//文件大小不支持
|
||||
BI.Msg.toast("文件大小不支持"); |
||||
self.fireEvent(BI.File.EVENT_ERROR, { |
||||
errorType: 1, |
||||
file: item |
||||
}); |
||||
} else { |
||||
wrap.files.unshift(item); |
||||
//BI.Msg.toast(value);
|
||||
self.fireEvent(BI.File.EVENT_CHANGE, { |
||||
file: item |
||||
}); |
||||
} |
||||
} |
||||
input.value = ""; |
||||
wrap.dom.input.parentNode.replaceChild(input, wrap.dom.input); |
||||
wrap.dom.input = input; |
||||
event.add(wrap.dom.input, "change", arguments.callee); |
||||
}); |
||||
return wrap; |
||||
}, |
||||
|
||||
_wrap: function () { |
||||
var self = this, o = this.options; |
||||
// be sure input accept multiple files
|
||||
var input = this.element[0]; |
||||
this.element.attr("multiple", "multiple"); |
||||
input.value = ""; |
||||
|
||||
// wrap Object
|
||||
return this._events({ |
||||
|
||||
// DOM namespace
|
||||
dom: { |
||||
input: input, // input file
|
||||
disabled: false // internal use, checks input file state
|
||||
}, |
||||
name: input.name, // name to send for each file ($_FILES[{name}] in the server)
|
||||
// maxSize is the maximum amount of bytes for each file
|
||||
maxSize: o.maxSize ? o.maxSize >> 0 : -1, |
||||
files: [], // file list
|
||||
|
||||
// remove every file from the noswfupload component
|
||||
clean: function () { |
||||
this.files = []; |
||||
}, |
||||
|
||||
// upload one file a time (which make progress possible rather than all files in one shot)
|
||||
// the handler is an object injected into the wrap one, could be the wrap itself or
|
||||
// something like {onload:function(){alert("OK")},onerror:function(){alert("Error")}, etc ...}
|
||||
upload: function (handler) { |
||||
if (handler) { |
||||
for (var key in handler) |
||||
this[key] = handler[key]; |
||||
} |
||||
sendFiles(this, this.maxSize); |
||||
return this; |
||||
}, |
||||
|
||||
// hide progress bar (total + current) and enable files selection
|
||||
hide: function () { |
||||
if (this.dom.disabled) { |
||||
this.dom.disabled = false; |
||||
this.dom.input.removeAttribute("disabled"); |
||||
} |
||||
}, |
||||
|
||||
// show progress bar and disable file selection (used during upload)
|
||||
// total and current are pixels used to style bars
|
||||
// totalProp and currentProp are properties to change, "height" by default
|
||||
show: function (total, current, totalProp, currentProp) { |
||||
if (!this.dom.disabled) { |
||||
this.dom.disabled = true; |
||||
this.dom.input.setAttribute("disabled", "disabled"); |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
select: function () { |
||||
$(this.wrap.dom.input).click(); |
||||
}, |
||||
|
||||
upload: function (handler) { |
||||
this.wrap.upload(handler); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.wrap.attach_array; |
||||
}, |
||||
|
||||
reset: function () { |
||||
this.wrap.attach_array = []; |
||||
this.wrap.attach_names = []; |
||||
this.wrap.attachNum = 0; |
||||
}, |
||||
|
||||
setEnable: function (enable) { |
||||
BI.MultiFile.superclass.setEnable.apply(this, arguments); |
||||
if (enable === true) { |
||||
this.element.attr("disabled", "disabled"); |
||||
} else { |
||||
this.element.removeAttr("disabled"); |
||||
} |
||||
} |
||||
}); |
||||
BI.File.EVENT_CHANGE = "BI.File.EVENT_CHANGE"; |
||||
BI.File.EVENT_UPLOADSTART = "EVENT_UPLOADSTART"; |
||||
BI.File.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.File.EVENT_PROGRESS = "EVENT_PROGRESS"; |
||||
BI.File.EVENT_UPLOADED = "EVENT_UPLOADED"; |
||||
$.shortcut("bi.file", BI.File); |
||||
})(); |
@ -0,0 +1,274 @@
|
||||
/** |
||||
* guy |
||||
* @class BI.Input 一个button和一行数 组成的一行listitem |
||||
* @extends BI.Single |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.Input = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Input.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-input display-block", |
||||
element: "<input/>", |
||||
validationChecker: BI.emptyFn, |
||||
quitChecker: BI.emptyFn,//按确定键能否退出编辑
|
||||
mouseOut: false, |
||||
allowBlank: false |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Input.superclass._init.apply(this, arguments); |
||||
var self = this; |
||||
var _keydown = BI.debounce(function (keyCode) { |
||||
self.onKeyDown(keyCode); |
||||
self._keydown_ = false; |
||||
}, 300); |
||||
var _clk = BI.debounce(BI.bind(this._click, this), BI.EVENT_RESPONSE_TIME, true); |
||||
this._blurDebounce = BI.debounce(BI.bind(this._blur, this), BI.EVENT_RESPONSE_TIME, true); |
||||
this.element |
||||
.keydown(function (e) { |
||||
self.fireEvent(BI.Input.EVENT_QUICK_DOWN); |
||||
}) |
||||
.keyup(function (e) { |
||||
self._keydown_ = true; |
||||
_keydown(e.keyCode); |
||||
}) |
||||
.on("input propertychange", function (e) { |
||||
self._keydown_ = true; |
||||
_keydown(e.keyCode); |
||||
}) |
||||
.click(function (e) { |
||||
e.stopPropagation(); |
||||
_clk(); |
||||
}) |
||||
.mousedown(function (e) { |
||||
self.element.val(self.element.val()); |
||||
}) |
||||
.focusout(function (e) { |
||||
self._blurDebounce(); |
||||
}); |
||||
}, |
||||
|
||||
_focus: function () { |
||||
this.element.addClass("bi-input-focus"); |
||||
this._checkValidationOnValueChange(); |
||||
this._isEditing = true; |
||||
if (this.getValue() == "") { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_EMPTY); |
||||
} |
||||
this.fireEvent(BI.Input.EVENT_FOCUS); |
||||
}, |
||||
|
||||
_blur: function () { |
||||
var self = this; |
||||
if (self._keydown_ === true) { |
||||
BI.delay(blur, 300); |
||||
} else { |
||||
blur(); |
||||
} |
||||
function blur() { |
||||
if (!self.isValid() && self.options.quitChecker.apply(self, [BI.trim(self.getValue())]) !== false) { |
||||
self.element.val(self._lastValidValue ? self._lastValidValue : ""); |
||||
self._checkValidationOnValueChange(); |
||||
self._defaultState(); |
||||
} |
||||
self.element.removeClass("bi-input-focus"); |
||||
self._isEditing = false; |
||||
self._start = false; |
||||
if (self.isValid()) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CONFIRM, self.getValue(), self); |
||||
self.fireEvent(BI.Input.EVENT_CONFIRM); |
||||
} |
||||
self.fireEvent(BI.Input.EVENT_BLUR); |
||||
} |
||||
}, |
||||
|
||||
_click: function () { |
||||
if (this._isEditing !== true) { |
||||
this._focus(); |
||||
this.selectAll(); |
||||
this.fireEvent(BI.Input.EVENT_CLICK); |
||||
} |
||||
}, |
||||
|
||||
onClick: function () { |
||||
this._click(); |
||||
}, |
||||
|
||||
onKeyDown: function (keyCode) { |
||||
if (!this.isValid() || BI.trim(this._lastValidValue) !== BI.trim(this.getValue())) { |
||||
this._checkValidationOnValueChange(); |
||||
} |
||||
if (keyCode == BI.keyCode.ENTER) { |
||||
if (this.isValid() || this.options.quitChecker.apply(this, [BI.trim(this.getValue())]) !== false) { |
||||
this.blur(); |
||||
this.fireEvent(BI.Input.EVENT_ENTER); |
||||
} else { |
||||
this.fireEvent(BI.Input.EVENT_RESTRICT); |
||||
} |
||||
} |
||||
if (keyCode == BI.keyCode.SPACE) { |
||||
this.fireEvent(BI.Input.EVENT_SPACE); |
||||
} |
||||
if (keyCode == BI.keyCode.BACKSPACE && this._lastValue == "") { |
||||
this.fireEvent(BI.Input.EVENT_REMOVE); |
||||
} |
||||
if (keyCode == BI.keyCode.BACKSPACE || keyCode == BI.keyCode.DELETE) { |
||||
this.fireEvent(BI.Input.EVENT_BACKSPACE); |
||||
} |
||||
this.fireEvent(BI.Input.EVENT_KEY_DOWN); |
||||
|
||||
if (this.isValid() && BI.trim(this.getValue()) !== "") { |
||||
if (BI.trim(this.getValue()) !== this._lastValue && (!this._start || this._lastValue == null || this._lastValue === "") |
||||
|| (this._pause === true && !/(\s|\u00A0)$/.test(this.getValue()))) { |
||||
this._start = true; |
||||
this._pause = false; |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STARTEDIT, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_START); |
||||
} |
||||
} |
||||
|
||||
if (/(\s|\u00A0)$/.test(this.getValue())) { |
||||
this._pause = true; |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.PAUSE, "", this); |
||||
this.fireEvent(BI.Input.EVENT_PAUSE); |
||||
this._defaultState(); |
||||
} else if ((keyCode === BI.keyCode.BACKSPACE || keyCode === BI.keyCode.DELETE) && |
||||
BI.trim(this.getValue()) === "" && (this._lastValue !== null && BI.trim(this._lastValue) !== "")) { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_STOP); |
||||
this._valueChange(); |
||||
} else { |
||||
this._valueChange(); |
||||
} |
||||
}, |
||||
|
||||
//初始状态
|
||||
_defaultState: function () { |
||||
if (this.getValue() == "") { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_EMPTY); |
||||
} |
||||
this._lastValue = this.getValue(); |
||||
this._lastSubmitValue = null; |
||||
}, |
||||
|
||||
_valueChange: function () { |
||||
if (this.isValid() && BI.trim(this.getValue()) !== this._lastSubmitValue) { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_CHANGE); |
||||
this._lastSubmitValue = BI.trim(this.getValue()); |
||||
} |
||||
if (this.getValue() == "") { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EMPTY, this.getValue(), this); |
||||
this.fireEvent(BI.Input.EVENT_EMPTY); |
||||
} |
||||
this._lastValue = this.getValue(); |
||||
}, |
||||
|
||||
_checkValidationOnValueChange: function () { |
||||
var o = this.options; |
||||
var v = this.getValue(); |
||||
this.setValid( |
||||
(o.allowBlank === true && BI.trim(v) == "") || |
||||
(BI.isNotEmptyString(BI.trim(v)) |
||||
&& (v === this._lastValidValue || |
||||
o.validationChecker.apply(this, [BI.trim(v)]) !== false)) |
||||
); |
||||
}, |
||||
|
||||
focus: function () { |
||||
if (!this.element.is(":visible")) { |
||||
throw new Error("input输入框在不可见下不能focus"); |
||||
} |
||||
if (!this._isEditing === true) { |
||||
this.element.focus(); |
||||
this._focus(); |
||||
this.selectAll(); |
||||
} |
||||
}, |
||||
|
||||
blur: function () { |
||||
if (!this.element.is(":visible")) { |
||||
throw new Error("input输入框在不可见下不能blur"); |
||||
} |
||||
if (this._isEditing === true) { |
||||
this.element.blur(); |
||||
this._blurDebounce(); |
||||
} |
||||
}, |
||||
|
||||
selectAll: function () { |
||||
if (!this.element.is(":visible")) { |
||||
throw new Error("input输入框在不可见下不能select"); |
||||
} |
||||
this.element.select(); |
||||
this._isEditing = true; |
||||
}, |
||||
|
||||
setValue: function (textValue) { |
||||
this.element.val(textValue); |
||||
BI.nextTick(BI.bind(function () { |
||||
this._checkValidationOnValueChange(); |
||||
this._defaultState(); |
||||
if (this.isValid()) { |
||||
this._lastSubmitValue = this.getValue(); |
||||
} |
||||
}, this)); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.element.val() || ""; |
||||
}, |
||||
|
||||
isEditing: function () { |
||||
return this._isEditing; |
||||
}, |
||||
|
||||
getLastValidValue: function () { |
||||
return this._lastValidValue; |
||||
}, |
||||
|
||||
setValid: function () { |
||||
BI.Input.superclass.setValid.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this._lastValidValue = this.getValue(); |
||||
this.element.removeClass("bi-input-error"); |
||||
this.fireEvent(BI.Input.EVENT_VALID, BI.trim(this.getValue()), this); |
||||
} else { |
||||
if (this._lastValidValue === this.getValue()) { |
||||
this._lastValidValue = null; |
||||
} |
||||
this.element.addClass("bi-input-error"); |
||||
this.fireEvent(BI.Input.EVENT_ERROR, BI.trim(this.getValue()), this); |
||||
} |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.Input.superclass.setEnable.apply(this, [b]); |
||||
this.element[0].disabled = !b; |
||||
} |
||||
}); |
||||
BI.Input.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
BI.Input.EVENT_FOCUS = "EVENT_FOCUS"; |
||||
BI.Input.EVENT_CLICK = "EVENT_CLICK"; |
||||
BI.Input.EVENT_BLUR = "EVENT_BLUR"; |
||||
BI.Input.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; |
||||
BI.Input.EVENT_QUICK_DOWN = "EVENT_QUICK_DOWN"; |
||||
BI.Input.EVENT_SPACE = "EVENT_SPACE"; |
||||
BI.Input.EVENT_BACKSPACE = "EVENT_BACKSPACE"; |
||||
|
||||
BI.Input.EVENT_START = "EVENT_START"; |
||||
BI.Input.EVENT_PAUSE = "EVENT_PAUSE"; |
||||
BI.Input.EVENT_STOP = "EVENT_STOP"; |
||||
BI.Input.EVENT_CONFIRM = "EVENT_CONFIRM"; |
||||
BI.Input.EVENT_REMOVE = "EVENT_REMOVE"; |
||||
BI.Input.EVENT_EMPTY = "EVENT_EMPTY"; |
||||
BI.Input.EVENT_VALID = "EVENT_VALID"; |
||||
BI.Input.EVENT_ERROR = "EVENT_ERROR"; |
||||
BI.Input.EVENT_ENTER = "EVENT_ENTER"; |
||||
BI.Input.EVENT_RESTRICT = "EVENT_RESTRICT"; |
||||
$.shortcut("bi.input", BI.Input); |
@ -0,0 +1,34 @@
|
||||
/** |
||||
* guy |
||||
* @extends BI.Single |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.Radio = BI.inherit(BI.IconButton, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.Radio.superclass._defaultConfig.apply(this,arguments); |
||||
return BI.extend(conf, { |
||||
tagName: "a", |
||||
baseCls: (conf.baseCls || "") + " bi-radio radio-icon", |
||||
selected: false, |
||||
handler: BI.emptyFn, |
||||
width: 16, |
||||
height: 16, |
||||
iconWidth: 16, |
||||
iconHeight: 16 |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.Radio.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.Radio.superclass.doClick.apply(this, arguments); |
||||
if(this.isValid()){ |
||||
this.fireEvent(BI.Radio.EVENT_CHANGE); |
||||
} |
||||
} |
||||
}); |
||||
BI.Radio.EVENT_CHANGE = "Radio.EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.radio", BI.Radio); |
@ -0,0 +1,467 @@
|
||||
/** |
||||
* Created by GUY on 2015/6/26. |
||||
*/ |
||||
|
||||
BI.Label = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Label.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-label", |
||||
textAlign: "center", |
||||
whiteSpace: "nowrap", //normal or nowrap
|
||||
forceCenter: false, //是否无论如何都要居中, 不考虑超出边界的情况, 在未知宽度和高度时有效
|
||||
textWidth: null, |
||||
textHeight: null, |
||||
hgap: 0, |
||||
vgap: 0, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
text: "", |
||||
py: "", |
||||
keyword: "" |
||||
}) |
||||
}, |
||||
|
||||
_createJson: function () { |
||||
var o = this.options; |
||||
return { |
||||
type: "bi.text", |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
lineHeight: o.textHeight, |
||||
text: o.text, |
||||
value: o.value, |
||||
py: o.py, |
||||
keyword: o.keyword |
||||
}; |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Label.superclass._init.apply(this, arguments); |
||||
|
||||
if (this.options.textAlign === "center") { |
||||
this._createCenterEl(); |
||||
} else { |
||||
this._createNotCenterEl(); |
||||
} |
||||
}, |
||||
|
||||
_createCenterEl: function () { |
||||
var o = this.options; |
||||
var json = this._createJson(); |
||||
if (BI.isNumber(o.width) && o.width > 0) { |
||||
if (BI.isNumber(o.textWidth) && o.textWidth > 0) { |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
var gap = (o.width - o.textWidth) / 2; |
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
height: o.height, |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: gap + o.hgap + o.lgap, |
||||
right: gap + o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
} |
||||
] |
||||
}); |
||||
this.element.css({"line-height": o.height + "px"}); |
||||
return; |
||||
} |
||||
json.width = o.textWidth; |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
} |
||||
] |
||||
}); |
||||
return; |
||||
} |
||||
if (o.whiteSpace == "normal") { |
||||
this.text = BI.createWidget(json); |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
json.width = o.width - 2 * o.hgap; |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.textWidth) && o.textWidth > 0) { |
||||
json.width = o.textWidth; |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
} |
||||
] |
||||
}); |
||||
return; |
||||
} |
||||
if (o.whiteSpace == "normal") { |
||||
this.text = BI.createWidget(json); |
||||
this.text = BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
if (BI.isNumber(o.textHeight) && o.textHeight > 0) { |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
height: o.height, |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
BI.extend(json, { |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap |
||||
}); |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
this.text = BI.createWidget(BI.extend(json, { |
||||
element: this.element |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.layout", |
||||
element: this.text, |
||||
scrollable: true |
||||
}); |
||||
return; |
||||
} |
||||
BI.extend(json, { |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap |
||||
}); |
||||
if (o.forceCenter) { |
||||
this.text = BI.createWidget(json); |
||||
BI.createWidget({ |
||||
type: "bi.center_adapt", |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
this.text = BI.createWidget(BI.extend(json, { |
||||
element: this.element |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.layout", |
||||
element: this.text, |
||||
scrollable: true |
||||
}) |
||||
}, |
||||
|
||||
_createNotCenterEl: function () { |
||||
var o = this.options; |
||||
var json = this._createJson(); |
||||
if (BI.isNumber(o.width) && o.width > 0) { |
||||
if (BI.isNumber(o.textWidth) && o.textWidth > 0) { |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
height: o.height, |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
} |
||||
] |
||||
}); |
||||
this.element.css({"line-height": o.height + "px"}); |
||||
return; |
||||
} |
||||
json.width = o.textWidth; |
||||
BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
} |
||||
] |
||||
}); |
||||
return; |
||||
} |
||||
if (o.whiteSpace == "normal") { |
||||
this.text = BI.createWidget(json); |
||||
BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
json.width = o.width - 2 * o.hgap - o.lgap - o.rgap; |
||||
BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.textWidth) && o.textWidth > 0) { |
||||
json.width = o.textWidth; |
||||
BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [ |
||||
{ |
||||
el: (this.text = BI.createWidget(json)) |
||||
} |
||||
] |
||||
}); |
||||
return; |
||||
} |
||||
if (o.whiteSpace == "normal") { |
||||
this.text = BI.createWidget(json) |
||||
this.text = BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
scrollable: true, |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap, |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
if (BI.isNumber(o.height) && o.height > 0) { |
||||
if (BI.isNumber(o.textHeight) && o.textHeight > 0) { |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.adaptive", |
||||
height: o.height, |
||||
scrollable: true, |
||||
element: this.element, |
||||
items: [{ |
||||
el: (this.text = BI.createWidget(json)), |
||||
left: o.hgap + o.lgap, |
||||
right: o.hgap + o.rgap, |
||||
top: o.vgap + o.tgap, |
||||
bottom: o.vgap + o.bgap |
||||
}] |
||||
}); |
||||
return; |
||||
} |
||||
BI.extend(json, { |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap |
||||
}); |
||||
this.element.css({ |
||||
"line-height": o.height + "px" |
||||
}); |
||||
this.text = BI.createWidget(BI.extend(json, { |
||||
element: this.element |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.layout", |
||||
element: this.text, |
||||
scrollable: true |
||||
}); |
||||
return; |
||||
} |
||||
BI.extend(json, { |
||||
hgap: o.hgap, |
||||
vgap: o.vgap, |
||||
lgap: o.lgap, |
||||
rgap: o.rgap, |
||||
tgap: o.tgap, |
||||
bgap: o.bgap |
||||
}); |
||||
if (o.forceCenter) { |
||||
this.text = BI.createWidget(json); |
||||
BI.createWidget({ |
||||
type: "bi.vertical_adapt", |
||||
element: this.element, |
||||
items: [this.text] |
||||
}); |
||||
return; |
||||
} |
||||
this.text = BI.createWidget(BI.extend(json, { |
||||
element: this.element |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.layout", |
||||
element: this.text, |
||||
scrollable: true |
||||
}) |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.doHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.unHighLight.apply(this.text, arguments); |
||||
}, |
||||
|
||||
setText: function (v) { |
||||
this.options.text = v; |
||||
this.text.setText(v); |
||||
}, |
||||
|
||||
getText: function () { |
||||
return this.options.text; |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
BI.Label.superclass.setValue.apply(this, arguments); |
||||
if (!this.isReadOnly()) { |
||||
this.text.setValue(v); |
||||
} |
||||
}, |
||||
|
||||
populate: function () { |
||||
BI.Label.superclass.populate.apply(this, arguments); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.label", BI.Label); |
@ -0,0 +1,37 @@
|
||||
/** |
||||
* guy a元素 |
||||
* @class BI.Link |
||||
* @extends BI.Text |
||||
*/ |
||||
BI.Link = BI.inherit(BI.Label, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.Link.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-link", |
||||
href: "", |
||||
target: "_blank" |
||||
}) |
||||
}, |
||||
|
||||
_createJson: function(){ |
||||
var o = this.options; |
||||
return { |
||||
type:"bi.a", |
||||
textAlign: o.textAlign, |
||||
whiteSpace: o.whiteSpace, |
||||
lineHeight: o.textHeight, |
||||
text: o.text, |
||||
keyword: o.keyword, |
||||
value: o.value, |
||||
py: o.py, |
||||
href: o.href, |
||||
target: o.target |
||||
}; |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.Link.superclass._init.apply(this, arguments); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.link", BI.Link); |
@ -0,0 +1,158 @@
|
||||
/** |
||||
* guy |
||||
* 这仅仅只是一个超类, 所有简单控件的基类 |
||||
* 1、类的控制, |
||||
* 2、title的控制 |
||||
* 3、文字超过边界显示3个点 |
||||
* 4、cursor默认pointor |
||||
* @class BI.Single |
||||
* @extends BI.Widget |
||||
* @abstract |
||||
*/ |
||||
BI.Single = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Single.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-single", |
||||
readonly: false, |
||||
title: null, |
||||
warningTitle: null, |
||||
tipType: null, // success或warning
|
||||
value: null |
||||
}) |
||||
}, |
||||
|
||||
_showToolTip: function (e, opt) { |
||||
opt || (opt = {}); |
||||
var self = this; |
||||
var type = this.getTipType() || (this.isEnabled() ? "success" : "warning"); |
||||
var title = type === "success" ? this.getTitle() : (this.getWarningTitle() || this.getTitle()); |
||||
if (BI.isKey(title)) { |
||||
BI.Tooltips.show(e, this.getName(), title, type, this, opt); |
||||
} |
||||
}, |
||||
|
||||
_hideTooltip: function () { |
||||
var self = this; |
||||
var tooltip = BI.Tooltips.get(this.getName()); |
||||
if (BI.isNotNull(tooltip)) { |
||||
tooltip.element.fadeOut(200, function () { |
||||
BI.Tooltips.remove(self.getName()); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Single.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
if (BI.isKey(o.title) || BI.isKey(o.warningTitle) |
||||
|| BI.isFunction(o.title) || BI.isFunction(o.warningTitle)) { |
||||
this.enableHover(); |
||||
} |
||||
}, |
||||
|
||||
enableHover: function (opt) { |
||||
opt || (opt = {}); |
||||
var self = this; |
||||
if (!this._hoverBinded) { |
||||
this.element.on("mouseenter.title" + this.getName(), function (e) { |
||||
self._e = e; |
||||
if (self.getTipType() === "warning" || (BI.isKey(self.getWarningTitle()) && !self.isEnabled())) { |
||||
self.timeout = BI.delay(function () { |
||||
self._showToolTip(self._e || e, opt); |
||||
}, 200); |
||||
} else if (self.getTipType() === "success" || self.isEnabled()) { |
||||
self.timeout = BI.delay(function () { |
||||
self._showToolTip(self._e || e, opt); |
||||
}, 500); |
||||
} |
||||
}); |
||||
this.element.on("mousemove.title" + this.getName(), function (e) { |
||||
self._e = e; |
||||
if (!self.element.__isMouseInBounds__(e)) { |
||||
if (BI.isNotNull(self.timeout)) { |
||||
clearTimeout(self.timeout); |
||||
} |
||||
self._hideTooltip(); |
||||
} |
||||
}); |
||||
this.element.on("mouseleave.title" + this.getName(), function () { |
||||
self._e = null; |
||||
if (BI.isNotNull(self.timeout)) { |
||||
clearTimeout(self.timeout); |
||||
} |
||||
self._hideTooltip(); |
||||
}); |
||||
this._hoverBinded = true; |
||||
} |
||||
}, |
||||
|
||||
disabledHover: function () { |
||||
//取消hover事件
|
||||
if (BI.isNotNull(this.timeout)) { |
||||
clearTimeout(this.timeout); |
||||
} |
||||
this._hideTooltip(); |
||||
$(this.element).unbind("mouseenter.title" + this.getName()) |
||||
.unbind("mousemove.title" + this.getName()) |
||||
.unbind("mouseleave.title" + this.getName()); |
||||
this._hoverBinded = false; |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
this.items = items || []; |
||||
}, |
||||
|
||||
//opt: {container: '', belowMouse: false}
|
||||
setTitle: function (title, opt) { |
||||
this.options.title = title; |
||||
if (BI.isKey(title)) { |
||||
this.enableHover(opt); |
||||
} else { |
||||
this.disabledHover(); |
||||
} |
||||
}, |
||||
|
||||
setWarningTitle: function (title, opt) { |
||||
this.options.warningTitle = title; |
||||
if (BI.isKey(title)) { |
||||
this.enableHover(opt); |
||||
} else { |
||||
this.disabledHover(); |
||||
} |
||||
}, |
||||
|
||||
getTipType: function () { |
||||
return this.options.tipType; |
||||
}, |
||||
|
||||
isReadOnly: function () { |
||||
return !!this.options.readonly; |
||||
}, |
||||
|
||||
getTitle: function () { |
||||
var title = this.options.title; |
||||
if(BI.isFunction(title)) { |
||||
return title(); |
||||
} |
||||
return title; |
||||
}, |
||||
|
||||
getWarningTitle: function () { |
||||
var title = this.options.warningTitle; |
||||
if(BI.isFunction(title)) { |
||||
return title(); |
||||
} |
||||
return title; |
||||
}, |
||||
|
||||
setValue: function (val) { |
||||
if (!this.options.readonly) { |
||||
this.options.value = val; |
||||
} |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.options.value; |
||||
} |
||||
}); |
@ -0,0 +1,109 @@
|
||||
/** |
||||
* guy 表示一行数据,通过position来定位位置的数据 |
||||
* @class BI.Text |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.Text = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.Text.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-text", |
||||
textAlign: "left", |
||||
whiteSpace: "normal", |
||||
lineHeight: null, |
||||
hgap: 0, |
||||
vgap: 0, |
||||
lgap: 0, |
||||
rgap: 0, |
||||
tgap: 0, |
||||
bgap: 0, |
||||
text: "", |
||||
py: "" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Text.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.layout", |
||||
cls: "bi-text" |
||||
}); |
||||
this.text.element.appendTo(this.element); |
||||
if (BI.isKey(o.text)) { |
||||
this.text.element.text(o.text); |
||||
} else if (BI.isKey(o.value)) { |
||||
this.text.element.text(o.value); |
||||
} |
||||
if (o.hgap + o.lgap > 0) { |
||||
this.text.element.css({ |
||||
"margin-left": o.hgap + o.lgap + "px" |
||||
}) |
||||
} |
||||
if (o.hgap + o.rgap > 0) { |
||||
this.text.element.css({ |
||||
"margin-right": o.hgap + o.rgap + "px" |
||||
}) |
||||
} |
||||
if (o.vgap + o.tgap > 0) { |
||||
this.text.element.css({ |
||||
"margin-top": o.vgap + o.tgap + "px" |
||||
}) |
||||
} |
||||
if (o.vgap + o.bgap > 0) { |
||||
this.text.element.css({ |
||||
"margin-bottom": o.vgap + o.bgap + "px" |
||||
}) |
||||
} |
||||
if (BI.isNumber(o.height)) { |
||||
this.element.css({"lineHeight": o.height + "px"}); |
||||
} |
||||
if (BI.isNumber(o.lineHeight)) { |
||||
this.element.css({"lineHeight": o.lineHeight + "px"}); |
||||
} |
||||
this.text.element.css({ |
||||
"textAlign": o.textAlign, |
||||
"whiteSpace": o.whiteSpace |
||||
}); |
||||
this.element.css({ |
||||
"textAlign": o.textAlign, |
||||
"whiteSpace": o.whiteSpace |
||||
}); |
||||
if (BI.isKey(o.keyword)) { |
||||
this.text.element.__textKeywordMarked__(o.text, o.keyword, o.py); |
||||
} |
||||
}, |
||||
|
||||
doRedMark: function (keyword) { |
||||
var o = this.options; |
||||
this.text.element.__textKeywordMarked__(o.text || o.value, keyword, o.py); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
var o = this.options; |
||||
this.text.element.__textKeywordMarked__(o.text || o.value, "", o.py); |
||||
}, |
||||
|
||||
doHighLight: function () { |
||||
this.text.element.addClass("bi-high-light"); |
||||
}, |
||||
|
||||
unHighLight: function () { |
||||
this.text.element.removeClass("bi-high-light"); |
||||
}, |
||||
|
||||
setValue: function (text) { |
||||
BI.Text.superclass.setValue.apply(this, arguments); |
||||
if (!this.isReadOnly()) { |
||||
this.text.element.text(text); |
||||
} |
||||
}, |
||||
|
||||
setText: function (text) { |
||||
BI.Text.superclass.setText.apply(this, arguments); |
||||
this.options.text = text; |
||||
this.text.element.text(text); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.text", BI.Text); |
@ -0,0 +1,22 @@
|
||||
/** |
||||
* guy |
||||
* tip提示 |
||||
* zIndex在10亿级别 |
||||
* @class BI.Tip |
||||
* @extends BI.Single |
||||
* @abstract |
||||
*/ |
||||
BI.Tip = BI.inherit(BI.Single, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.Link.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-tip", |
||||
zIndex: BI.zIndex_tip |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.Tip.superclass._init.apply(this, arguments); |
||||
this.element.css({"zIndex": this.options.zIndex}); |
||||
} |
||||
}); |
@ -0,0 +1,27 @@
|
||||
/** |
||||
* 下拉 |
||||
* @class BI.Trigger |
||||
* @extends BI.Single |
||||
* @abstract |
||||
*/ |
||||
BI.Trigger = BI.inherit(BI.Single, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.Trigger.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-trigger cursor-pointer", |
||||
height: 30 |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.Trigger.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
setKey: function(){ |
||||
|
||||
}, |
||||
|
||||
getKey: function(){ |
||||
|
||||
} |
||||
}); |
@ -0,0 +1,106 @@
|
||||
/** |
||||
* svg绘图 |
||||
* |
||||
* Created by GUY on 2015/12/3. |
||||
* @class BI.Svg |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.Svg = BI.inherit(BI.Widget, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.Svg.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-svg" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.Svg.superclass._init.apply(this, arguments); |
||||
this.paper = Raphael(this.element[0]); |
||||
|
||||
$(this.paper.canvas).width("100%").height("100%").css({"left": "0", "top": "0"}).appendTo(this.element); |
||||
|
||||
this.top = this.paper.top; |
||||
this.bottom = this.paper.bottom; |
||||
this.customAttributes = this.paper.customAttributes; |
||||
this.ca = this.paper.ca; |
||||
this.raphael = this.paper.raphael; |
||||
}, |
||||
|
||||
add: function () { |
||||
return this.paper.add.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
path: function () { |
||||
return this.paper.path.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
image: function () { |
||||
return this.paper.image.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
rect: function () { |
||||
return this.paper.rect.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
circle: function () { |
||||
return this.paper.circle.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
ellipse: function () { |
||||
return this.paper.ellipse.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
text: function () { |
||||
return this.paper.text.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
print: function () { |
||||
return this.paper.print.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
|
||||
setStart: function () { |
||||
return this.paper.setStart.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
setFinish: function () { |
||||
return this.paper.setFinish.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
setSize: function () { |
||||
return this.paper.setSize.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
setViewBox: function () { |
||||
return this.paper.setViewBox.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
|
||||
getById: function () { |
||||
return this.paper.getById.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
getElementByPoint: function () { |
||||
return this.paper.getElementByPoint.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
getElementsByPoint: function () { |
||||
return this.paper.getElementsByPoint.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
getFont: function () { |
||||
return this.paper.getFont.apply(this.paper, arguments); |
||||
}, |
||||
|
||||
|
||||
set: function () { |
||||
return this.paper.set.apply(this.paper, arguments); |
||||
}, |
||||
remove: function () { |
||||
return this.paper.remove.apply(this.paper, arguments); |
||||
}, |
||||
clear: function () { |
||||
return this.paper.clear.apply(this.paper, arguments); |
||||
} |
||||
}); |
||||
$.shortcut("bi.svg", BI.Svg); |
@ -0,0 +1,33 @@
|
||||
/** |
||||
* |
||||
* 表格 |
||||
* |
||||
* Created by GUY on 2015/9/22. |
||||
* @class BI.TableCell |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.TableCell = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.TableCell.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-table-cell", |
||||
textAlign: "left", |
||||
text: "" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.TableCell.superclass._init.apply(this, arguments); |
||||
BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
whiteSpace: "nowrap", |
||||
textAlign: this.options.textAlign, |
||||
height: this.options.height, |
||||
text: this.options.text, |
||||
value: this.options.value, |
||||
lgap: 5 |
||||
}) |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.table_cell", BI.TableCell); |
@ -0,0 +1,57 @@
|
||||
/** |
||||
* |
||||
* 表格单元格 |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.CollectionTableCell |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.CollectionTableCell = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.CollectionTableCell.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-collection-table-cell", |
||||
width: 0, |
||||
height: 0, |
||||
_left: 0, |
||||
_top: 0, |
||||
cell: {} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.CollectionTableCell.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell = BI.createWidget(BI.extend({ |
||||
type: "bi.label" |
||||
}, o.cell, { |
||||
cls: (o.cell.cls || "") + "collection-table-cell-wrapper", |
||||
width: o.width - (o._left === 0 ? 1 : 0) - 1, |
||||
height: o.height - (o._top === 0 ? 1 : 0) - 1 |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.cell, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.CollectionTableCell.superclass.setWidth.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setWidth(o.width - (o._left === 0 ? 1 : 0) - 1); |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.CollectionTableCell.superclass.setHeight.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setHeight(o.height - (o._top === 0 ? 1 : 0) - 1); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.collection_table_cell", BI.CollectionTableCell); |
@ -0,0 +1,547 @@
|
||||
/** |
||||
* CollectionTable |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.CollectionTable |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.CollectionTable = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.CollectionTable.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-collection-table", |
||||
headerRowSize: 25, |
||||
rowSize: 25, |
||||
columnSize: [], |
||||
isNeedFreeze: false, |
||||
freezeCols: [], |
||||
isNeedMerge: false, |
||||
mergeCols: [], |
||||
mergeRule: BI.emptyFn, |
||||
header: [], |
||||
items: [], |
||||
regionColumnSize: [] |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.CollectionTable.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this._width = 0; |
||||
this._height = 0; |
||||
this._scrollBarSize = BI.DOM.getScrollWidth(); |
||||
this.topLeftCollection = BI.createWidget({ |
||||
type: "bi.collection_view", |
||||
cellSizeAndPositionGetter: function (index) { |
||||
return self.topLeftItems[index]; |
||||
} |
||||
}); |
||||
this.topLeftCollection.on(BI.Collection.EVENT_SCROLL, function (scroll) { |
||||
self.bottomLeftCollection.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.topRightCollection = BI.createWidget({ |
||||
type: "bi.collection_view", |
||||
cellSizeAndPositionGetter: function (index) { |
||||
return self.topRightItems[index]; |
||||
} |
||||
}); |
||||
this.topRightCollection.on(BI.Collection.EVENT_SCROLL, function (scroll) { |
||||
self.bottomRightCollection.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.bottomLeftCollection = BI.createWidget({ |
||||
type: "bi.collection_view", |
||||
cellSizeAndPositionGetter: function (index) { |
||||
return self.bottomLeftItems[index]; |
||||
} |
||||
}); |
||||
this.bottomLeftCollection.on(BI.Collection.EVENT_SCROLL, function (scroll) { |
||||
self.bottomRightCollection.setScrollTop(scroll.scrollTop); |
||||
self.topLeftCollection.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.bottomRightCollection = BI.createWidget({ |
||||
type: "bi.collection_view", |
||||
cellSizeAndPositionGetter: function (index) { |
||||
return self.bottomRightItems[index]; |
||||
} |
||||
}); |
||||
this.bottomRightCollection.on(BI.Collection.EVENT_SCROLL, function (scroll) { |
||||
self.bottomLeftCollection.setScrollTop(scroll.scrollTop); |
||||
self.topRightCollection.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.topLeft = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.topLeftCollection] |
||||
}); |
||||
this.topRight = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.topRightCollection] |
||||
}); |
||||
this.bottomLeft = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.bottomLeftCollection] |
||||
}); |
||||
this.bottomRight = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.bottomRightCollection] |
||||
}); |
||||
this.contextLayout = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.topLeft, |
||||
top: 0, |
||||
left: 0 |
||||
}, { |
||||
el: this.topRight, |
||||
top: 0 |
||||
}, { |
||||
el: this.bottomLeft, |
||||
left: 0 |
||||
}, { |
||||
el: this.bottomRight |
||||
}] |
||||
}); |
||||
|
||||
this.topScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_scrollbar", |
||||
width: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.topScrollbar.on(BI.GridTableScrollbar.EVENT_SCROLL, function (scrollTop) { |
||||
self.bottomLeftCollection.setScrollTop(scrollTop); |
||||
self.bottomRightCollection.setScrollTop(scrollTop); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.leftScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_horizontal_scrollbar", |
||||
height: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.leftScrollbar.on(BI.GridTableScrollbar.EVENT_SCROLL, function (scrollLeft) { |
||||
self.topLeftCollection.setScrollLeft(scrollLeft); |
||||
self.bottomLeftCollection.setScrollLeft(scrollLeft); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.rightScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_horizontal_scrollbar", |
||||
height: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.rightScrollbar.on(BI.GridTableScrollbar.EVENT_SCROLL, function (scrollLeft) { |
||||
self.topRightCollection.setScrollLeft(scrollLeft); |
||||
self.bottomRightCollection.setScrollLeft(scrollLeft); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.scrollBarLayout = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.topScrollbar, |
||||
right: 0, |
||||
top: 0 |
||||
}, { |
||||
el: this.leftScrollbar, |
||||
left: 0 |
||||
}, { |
||||
el: this.rightScrollbar, |
||||
}] |
||||
}); |
||||
this._width = o.width - BI.GridTableScrollbar.SIZE; |
||||
this._height = o.height - BI.GridTableScrollbar.SIZE; |
||||
if (o.items.length > 0 || o.header.length < 0) { |
||||
this._digest(); |
||||
this._populate(); |
||||
} |
||||
}, |
||||
|
||||
_getFreezeColLength: function () { |
||||
return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; |
||||
}, |
||||
|
||||
_populateScrollbar: function () { |
||||
var o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
this.topScrollbar.setContentSize(o.items.length * o.rowSize); |
||||
this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); |
||||
this.topScrollbar.setPosition(this.bottomRightCollection.getScrollTop()); |
||||
this.topScrollbar.populate(); |
||||
|
||||
this.leftScrollbar.setContentSize(totalLeftColumnSize); |
||||
this.leftScrollbar.setSize(regionSize); |
||||
this.leftScrollbar.setPosition(this.bottomLeftCollection.getScrollLeft()); |
||||
this.leftScrollbar.populate(); |
||||
|
||||
this.rightScrollbar.setContentSize(totalRightColumnSize); |
||||
this.rightScrollbar.setSize(this._width - regionSize); |
||||
this.rightScrollbar.setPosition(this.bottomRightCollection.getScrollLeft()); |
||||
this.rightScrollbar.populate(); |
||||
|
||||
var items = this.scrollBarLayout.attr("items"); |
||||
items[0].top = o.header.length * o.headerRowSize; |
||||
items[1].top = this._height; |
||||
items[2].top = this._height; |
||||
items[2].left = regionSize; |
||||
this.scrollBarLayout.attr("items", items); |
||||
this.scrollBarLayout.resize(); |
||||
}, |
||||
|
||||
_populateTable: function () { |
||||
var self = this, o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
|
||||
var tlw = regionSize; |
||||
var tlh = regionSize >= summaryColumnSizeArray[freezeColLength - 1] ? (o.header.length * o.headerRowSize) : (o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var trw = this._width - regionSize; |
||||
var trh = (this._width - regionSize >= totalColumnSize - (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (o.header.length * o.headerRowSize) : (o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var blw = (this._height - o.header.length * o.headerRowSize >= totalRowSize) ? regionSize : (regionSize + this._scrollBarSize); |
||||
var blh = (regionSize >= (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (this._height - o.header.length * o.headerRowSize) : (this._height - o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var brw = (this._height - o.header.length * o.headerRowSize >= totalRowSize) ? (this._width - regionSize) : (this._width - regionSize + this._scrollBarSize); |
||||
var brh = (this._width - regionSize >= totalColumnSize - (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (this._height - o.header.length * o.headerRowSize) : (this._height - o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
|
||||
var otlw = regionSize; |
||||
var otlh = o.header.length * o.headerRowSize; |
||||
var otrw = this._width - regionSize; |
||||
var otrh = o.header.length * o.headerRowSize; |
||||
var oblw = regionSize; |
||||
var oblh = this._height - o.header.length * o.headerRowSize; |
||||
var obrw = this._width - regionSize; |
||||
var obrh = this._height - o.header.length * o.headerRowSize; |
||||
|
||||
var digest = function (w, h, tw, th, el) { |
||||
if (w >= tw && h >= th) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "hidden", |
||||
overflowY: "hidden" |
||||
}) |
||||
} else if (w >= tw) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "hidden", |
||||
overflowY: "auto" |
||||
}) |
||||
} else if (h >= th) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "auto", |
||||
overflowY: "hidden" |
||||
}) |
||||
} else { |
||||
el.element.css({ |
||||
overflow: "auto", |
||||
overflowX: "auto", |
||||
overflowY: "auto" |
||||
}) |
||||
} |
||||
}; |
||||
|
||||
this.topLeft.setWidth(otlw); |
||||
this.topLeft.setHeight(otlh); |
||||
this.topRight.setWidth(otrw); |
||||
this.topRight.setHeight(otrh); |
||||
this.bottomLeft.setWidth(oblw); |
||||
this.bottomLeft.setHeight(oblh); |
||||
this.bottomRight.setWidth(obrw); |
||||
this.bottomRight.setHeight(obrh); |
||||
|
||||
this.topLeftCollection.setWidth(tlw); |
||||
this.topLeftCollection.setHeight(tlh); |
||||
this.topRightCollection.setWidth(trw); |
||||
this.topRightCollection.setHeight(trh); |
||||
this.bottomLeftCollection.setWidth(blw); |
||||
this.bottomLeftCollection.setHeight(blh); |
||||
this.bottomRightCollection.setWidth(brw); |
||||
this.bottomRightCollection.setHeight(brh); |
||||
|
||||
digest(tlw, tlh, totalLeftColumnSize, o.header.length * o.headerRowSize, this.topLeftCollection); |
||||
digest(trw, trh, totalRightColumnSize, o.header.length * o.headerRowSize, this.topRightCollection); |
||||
digest(blw, blh, totalLeftColumnSize, o.items.length * o.rowSize, this.bottomLeftCollection); |
||||
digest(brw, brh, totalRightColumnSize, o.items.length * o.rowSize, this.bottomRightCollection); |
||||
|
||||
var items = this.contextLayout.attr("items"); |
||||
items[1].left = regionSize; |
||||
items[2].top = o.header.length * o.headerRowSize; |
||||
items[3].left = regionSize; |
||||
items[3].top = o.header.length * o.headerRowSize; |
||||
this.contextLayout.attr("items", items); |
||||
this.contextLayout.resize(); |
||||
|
||||
var leftHeader = [], rightHeader = [], leftItems = [], rightItems = []; |
||||
var run = function (positions, items, rendered) { |
||||
BI.each(positions, function (i, item) { |
||||
var cell = { |
||||
type: "bi.collection_table_cell", |
||||
cell: items[item.row][item.col] |
||||
}; |
||||
rendered.push(cell); |
||||
}); |
||||
}; |
||||
run(this.topLeftItems, o.header, leftHeader); |
||||
run(this.topRightItems, o.header, rightHeader); |
||||
run(this.bottomLeftItems, o.items, leftItems); |
||||
run(this.bottomRightItems, o.items, rightItems); |
||||
|
||||
this.topLeftCollection.populate(leftHeader); |
||||
this.topRightCollection.populate(rightHeader); |
||||
this.bottomLeftCollection.populate(leftItems); |
||||
this.bottomRightCollection.populate(rightItems); |
||||
}, |
||||
|
||||
_digest: function () { |
||||
var o = this.options; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
this.topLeftItems = this._serialize(o.header, 0, freezeColLength, o.headerRowSize, o.columnSize, o.mergeCols); |
||||
this.topRightItems = this._serialize(o.header, freezeColLength, o.columnSize.length, o.headerRowSize, o.columnSize, true); |
||||
this.bottomLeftItems = this._serialize(o.items, 0, freezeColLength, o.rowSize, o.columnSize, o.mergeCols); |
||||
this.bottomRightItems = this._serialize(o.items, freezeColLength, o.columnSize.length, o.rowSize, o.columnSize, o.mergeCols); |
||||
}, |
||||
|
||||
_serialize: function (items, startCol, endCol, rowHeight, columnSize, mergeCols) { |
||||
var self = this, o = this.options; |
||||
var result = [], cache = {}, preCol = {}, preRow = {}, map = {}; |
||||
var summaryColumnSize = []; |
||||
for (var i = startCol; i < endCol; i++) { |
||||
if (i === startCol) { |
||||
summaryColumnSize[i] = columnSize[i]; |
||||
} else { |
||||
summaryColumnSize[i] = summaryColumnSize[i - 1] + columnSize[i]; |
||||
} |
||||
} |
||||
var mergeRow = function (i, j) { |
||||
preCol[j]._height += rowHeight; |
||||
preCol[j].__mergeRows.push(i); |
||||
}; |
||||
|
||||
var mergeCol = function (i, j) { |
||||
preRow[i]._width += columnSize[j]; |
||||
preRow[i].__mergeCols.push(j); |
||||
}; |
||||
|
||||
var createOneEl = function (r, c) { |
||||
var width = columnSize[c]; |
||||
var height = rowHeight; |
||||
map[r][c]._row = r; |
||||
map[r][c]._col = c; |
||||
map[r][c]._width = width; |
||||
map[r][c]._height = height; |
||||
preCol[c] = map[r][c]; |
||||
preCol[c].__mergeRows = [r]; |
||||
preRow[r] = map[r][c]; |
||||
preRow[r].__mergeCols = [c]; |
||||
|
||||
result.push({ |
||||
x: summaryColumnSize[c] - columnSize[c], |
||||
y: +r * rowHeight, |
||||
item: map[r][c] |
||||
}); |
||||
}; |
||||
|
||||
BI.each(items, function (i, cols) { |
||||
for (var j = startCol; j < endCol; j++) { |
||||
if (!cache[i]) { |
||||
cache[i] = {}; |
||||
} |
||||
if (!map[i]) { |
||||
map[i] = {}; |
||||
} |
||||
cache[i][j] = cols[j]; |
||||
map[i][j] = {}; |
||||
if (mergeCols === true || mergeCols.indexOf(j) > -1) { |
||||
if (i === 0 && j === startCol) { |
||||
createOneEl(0, startCol); |
||||
} else if (j === startCol && i > 0) { |
||||
var isNeedMergeRow = o.mergeRule(cache[i][j], cache[i - 1][j]); |
||||
if (isNeedMergeRow === true) { |
||||
mergeRow(i, j); |
||||
preRow[i] = preCol[j]; |
||||
} else { |
||||
createOneEl(i, j); |
||||
} |
||||
} else if (i === 0 && j > startCol) { |
||||
var isNeedMergeCol = o.mergeRule(cache[i][j], cache[i][j - 1]); |
||||
if (isNeedMergeCol === true) { |
||||
mergeCol(i, j); |
||||
preCol[j] = preRow[i]; |
||||
} else { |
||||
createOneEl(i, j); |
||||
} |
||||
} else { |
||||
var isNeedMergeRow = o.mergeRule(cache[i][j], cache[i - 1][j]); |
||||
var isNeedMergeCol = o.mergeRule(cache[i][j], cache[i][j - 1]); |
||||
if (isNeedMergeCol && isNeedMergeRow) { |
||||
continue; |
||||
//mergeRow(i, j);//优先合并列
|
||||
} |
||||
if (isNeedMergeCol) { |
||||
mergeCol(i, j); |
||||
} |
||||
if (isNeedMergeRow) { |
||||
mergeRow(i, j); |
||||
} |
||||
if (!isNeedMergeCol && !isNeedMergeRow) { |
||||
createOneEl(i, j); |
||||
} |
||||
} |
||||
} else { |
||||
createOneEl(i, j); |
||||
} |
||||
} |
||||
}); |
||||
return BI.map(result, function (i, item) { |
||||
return { |
||||
x: item.x, |
||||
y: item.y, |
||||
row: item.item._row, |
||||
col: item.item._col, |
||||
width: item.item._width, |
||||
height: item.item._height |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
_populate: function () { |
||||
if (this._width <= 0 || this._height <= 0) { |
||||
return; |
||||
} |
||||
if (this._isNeedDigest === true) { |
||||
this._digest(); |
||||
} |
||||
this._populateTable(); |
||||
this._populateScrollbar(); |
||||
}, |
||||
|
||||
getRegionSize: function () { |
||||
var o = this.options; |
||||
var regionSize = o.regionColumnSize[0] || 0; |
||||
if (o.isNeedFreeze === false || o.freezeCols.length === 0) { |
||||
return 0; |
||||
} |
||||
if (!regionSize) { |
||||
BI.each(o.freezeCols, function (i, col) { |
||||
regionSize += o.columnSize[col]; |
||||
}); |
||||
} |
||||
return regionSize; |
||||
}, |
||||
|
||||
setVerticalScroll: function (scrollTop) { |
||||
this.bottomLeftCollection.setScrollTop(scrollTop); |
||||
this.bottomRightCollection.setScrollTop(scrollTop); |
||||
}, |
||||
|
||||
setLeftHorizontalScroll: function (scrollLeft) { |
||||
this.topLeftCollection.setScrollLeft(scrollLeft); |
||||
this.bottomLeftCollection.setScrollLeft(scrollLeft); |
||||
}, |
||||
|
||||
setRightHorizontalScroll: function (scrollLeft) { |
||||
this.topRightCollection.setScrollLeft(scrollLeft); |
||||
this.bottomRightCollection.setScrollLeft(scrollLeft); |
||||
}, |
||||
|
||||
getVerticalScroll: function () { |
||||
return this.bottomRightCollection.getScrollTop(); |
||||
}, |
||||
|
||||
getLeftHorizontalScroll: function () { |
||||
return this.bottomLeftCollection.getScrollLeft(); |
||||
}, |
||||
|
||||
getRightHorizontalScroll: function () { |
||||
return this.bottomRightCollection.getScrollLeft(); |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.CollectionTable.superclass.setWidth.apply(this, arguments); |
||||
this._width = this.options.width - BI.GridTableScrollbar.SIZE; |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.CollectionTable.superclass.setHeight.apply(this, arguments); |
||||
this._height = this.options.height - BI.GridTableScrollbar.SIZE; |
||||
}, |
||||
|
||||
setColumnSize: function (columnSize) { |
||||
this._isNeedDigest = true; |
||||
this.options.columnSize = columnSize; |
||||
}, |
||||
|
||||
setRegionColumnSize: function (regionColumnSize) { |
||||
this._isNeedDigest = true; |
||||
this.options.regionColumnSize = regionColumnSize; |
||||
}, |
||||
|
||||
getColumnSize: function () { |
||||
return this.options.columnSize; |
||||
}, |
||||
|
||||
getRegionColumnSize: function () { |
||||
return this.options.regionColumnSize; |
||||
}, |
||||
|
||||
populate: function (items, header) { |
||||
if (items && items !== this.options.items) { |
||||
this._isNeedDigest = true; |
||||
this.options.items = items; |
||||
this._restore(); |
||||
} |
||||
if (header && header !== this.options.header) { |
||||
this._isNeedDigest = true; |
||||
this.options.header = header; |
||||
this._restore(); |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
_restore: function () { |
||||
this.topLeftCollection.restore(); |
||||
this.topRightCollection.restore(); |
||||
this.bottomLeftCollection.restore(); |
||||
this.bottomRightCollection.restore(); |
||||
}, |
||||
|
||||
restore: function () { |
||||
this._restore(); |
||||
} |
||||
}); |
||||
$.shortcut('bi.collection_table', BI.CollectionTable); |
@ -0,0 +1,140 @@
|
||||
/** |
||||
* QuickCollectionTable |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.QuickCollectionTable |
||||
* @extends BI.CollectionTable |
||||
*/ |
||||
BI.QuickCollectionTable = BI.inherit(BI.CollectionTable, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.QuickCollectionTable.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-quick-collection-table" |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.QuickCollectionTable.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.topLeftCollection.setOverflowX(false); |
||||
this.topLeftCollection.setOverflowY(false); |
||||
this.topRightCollection.setOverflowX(false); |
||||
this.topRightCollection.setOverflowY(false); |
||||
this.bottomLeftCollection.setOverflowX(false); |
||||
this.bottomLeftCollection.setOverflowY(false); |
||||
this.bottomRightCollection.setOverflowX(false); |
||||
this.bottomRightCollection.setOverflowY(false); |
||||
this._leftWheelHandler = new BI.WheelHandler( |
||||
BI.bind(this._onWheelY, this), |
||||
BI.bind(this._shouldHandleX, this), |
||||
BI.bind(this._shouldHandleY, this) |
||||
); |
||||
this._rightWheelHandler = new BI.WheelHandler( |
||||
BI.bind(this._onWheelY, this), |
||||
BI.bind(this._shouldHandleX, this), |
||||
BI.bind(this._shouldHandleY, this) |
||||
); |
||||
this.bottomLeftCollection.element.mousewheel(function (e) { |
||||
self._leftWheelHandler.onWheel(e.originalEvent); |
||||
}); |
||||
this.bottomRightCollection.element.mousewheel(function (e) { |
||||
self._rightWheelHandler.onWheel(e.originalEvent); |
||||
}); |
||||
}, |
||||
|
||||
_shouldHandleX: function (delta) { |
||||
return false; |
||||
}, |
||||
|
||||
_shouldHandleY: function (delta) { |
||||
if (delta > 0) { |
||||
return this.bottomRightCollection.getScrollTop() < this.bottomRightCollection.getMaxScrollTop(); |
||||
} else { |
||||
return this.bottomRightCollection.getScrollTop() > 0; |
||||
} |
||||
}, |
||||
|
||||
_onWheelY: function (deltaX, deltaY) { |
||||
var self = this; |
||||
var scrollTop = this.bottomRightCollection.getScrollTop(); |
||||
scrollTop += deltaY; |
||||
this.bottomLeftCollection.setScrollTop(scrollTop); |
||||
this.bottomRightCollection.setScrollTop(scrollTop); |
||||
self._populateScrollbar(); |
||||
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}, |
||||
|
||||
_populateTable: function () { |
||||
var self = this, o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
|
||||
var otlw = regionSize; |
||||
var otlh = o.header.length * o.headerRowSize; |
||||
var otrw = this._width - regionSize; |
||||
var otrh = o.header.length * o.headerRowSize; |
||||
var oblw = regionSize; |
||||
var oblh = this._height - o.header.length * o.headerRowSize; |
||||
var obrw = this._width - regionSize; |
||||
var obrh = this._height - o.header.length * o.headerRowSize; |
||||
|
||||
this.topLeft.setWidth(otlw); |
||||
this.topLeft.setHeight(otlh); |
||||
this.topRight.setWidth(otrw); |
||||
this.topRight.setHeight(otrh); |
||||
this.bottomLeft.setWidth(oblw); |
||||
this.bottomLeft.setHeight(oblh); |
||||
this.bottomRight.setWidth(obrw); |
||||
this.bottomRight.setHeight(obrh); |
||||
|
||||
this.topLeftCollection.setWidth(otlw); |
||||
this.topLeftCollection.setHeight(otlh); |
||||
this.topRightCollection.setWidth(otrw); |
||||
this.topRightCollection.setHeight(otrh); |
||||
this.bottomLeftCollection.setWidth(oblw); |
||||
this.bottomLeftCollection.setHeight(oblh); |
||||
this.bottomRightCollection.setWidth(obrw); |
||||
this.bottomRightCollection.setHeight(obrh); |
||||
|
||||
var items = this.contextLayout.attr("items"); |
||||
items[1].left = regionSize; |
||||
items[2].top = o.header.length * o.headerRowSize; |
||||
items[3].left = regionSize; |
||||
items[3].top = o.header.length * o.headerRowSize; |
||||
this.contextLayout.attr("items", items); |
||||
this.contextLayout.resize(); |
||||
|
||||
var leftHeader = [], rightHeader = [], leftItems = [], rightItems = []; |
||||
var run = function (positions, items, rendered) { |
||||
BI.each(positions, function (i, item) { |
||||
var cell = { |
||||
type: "bi.collection_table_cell", |
||||
cell: items[item.row][item.col] |
||||
}; |
||||
rendered.push(cell); |
||||
}); |
||||
}; |
||||
run(this.topLeftItems, o.header, leftHeader); |
||||
run(this.topRightItems, o.header, rightHeader); |
||||
run(this.bottomLeftItems, o.items, leftItems); |
||||
run(this.bottomRightItems, o.items, rightItems); |
||||
|
||||
this.topLeftCollection.populate(leftHeader); |
||||
this.topRightCollection.populate(rightHeader); |
||||
this.bottomLeftCollection.populate(leftItems); |
||||
this.bottomRightCollection.populate(rightItems); |
||||
} |
||||
}); |
||||
$.shortcut('bi.quick_collection_table', BI.QuickCollectionTable); |
@ -0,0 +1,59 @@
|
||||
/** |
||||
* |
||||
* 表格单元格 |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.GridTableCell |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.GridTableCell = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.GridTableCell.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-grid-table-cell", |
||||
width: 0, |
||||
height: 0, |
||||
_rowIndex: 0, |
||||
_columnIndex: 0, |
||||
_left: 0, |
||||
_top: 0, |
||||
cell: {} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.GridTableCell.superclass._init.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell = BI.createWidget(BI.extend({ |
||||
type: "bi.label" |
||||
}, o.cell, { |
||||
cls: (o.cell.cls || "") + "grid-table-cell-wrapper", |
||||
width: o.width - (o._columnIndex === 0 ? 1 : 0) - 1, |
||||
height: o.height - (o._rowIndex === 0 ? 1 : 0) - 1 |
||||
})); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.cell, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.GridTableCell.superclass.setWidth.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setWidth(o.width - (o._columnIndex === 0 ? 1 : 0) - 1); |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.GridTableCell.superclass.setHeight.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setHeight(o.height - (o._rowIndex === 0 ? 1 : 0) - 1); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.grid_table_cell", BI.GridTableCell); |
@ -0,0 +1,471 @@
|
||||
/** |
||||
* GridTable |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.GridTable |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.GridTable = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.GridTable.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-grid-table", |
||||
headerRowSize: 25, |
||||
rowSize: 25, |
||||
columnSize: [], |
||||
isNeedFreeze: false, |
||||
freezeCols: [], |
||||
header: [], |
||||
items: [], |
||||
regionColumnSize: [] |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.GridTable.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this._width = 0; |
||||
this._height = 0; |
||||
this._scrollBarSize = BI.DOM.getScrollWidth(); |
||||
var rowHeightGetter = function () { |
||||
return o.rowSize; |
||||
}; |
||||
var columnLeftWidthGetter = function (index) { |
||||
return o.columnSize[index]; |
||||
}; |
||||
var columnRightWidthGetter = function (index) { |
||||
return o.columnSize[index + self._getFreezeColLength()]; |
||||
}; |
||||
this.topLeftGrid = BI.createWidget({ |
||||
type: "bi.grid_view", |
||||
rowHeightGetter: rowHeightGetter, |
||||
columnWidthGetter: columnLeftWidthGetter, |
||||
}); |
||||
this.topLeftGrid.on(BI.Grid.EVENT_SCROLL, function (scroll) { |
||||
self.bottomLeftGrid.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.topRightGrid = BI.createWidget({ |
||||
type: "bi.grid_view", |
||||
rowHeightGetter: rowHeightGetter, |
||||
columnWidthGetter: columnRightWidthGetter, |
||||
}); |
||||
this.topRightGrid.on(BI.Grid.EVENT_SCROLL, function (scroll) { |
||||
self.bottomRightGrid.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.bottomLeftGrid = BI.createWidget({ |
||||
type: "bi.grid_view", |
||||
rowHeightGetter: rowHeightGetter, |
||||
columnWidthGetter: columnLeftWidthGetter, |
||||
}); |
||||
this.bottomLeftGrid.on(BI.Grid.EVENT_SCROLL, function (scroll) { |
||||
self.bottomRightGrid.setScrollTop(scroll.scrollTop); |
||||
self.topLeftGrid.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.bottomRightGrid = BI.createWidget({ |
||||
type: "bi.grid_view", |
||||
rowHeightGetter: rowHeightGetter, |
||||
columnWidthGetter: columnRightWidthGetter, |
||||
}); |
||||
this.bottomRightGrid.on(BI.Grid.EVENT_SCROLL, function (scroll) { |
||||
self.bottomLeftGrid.setScrollTop(scroll.scrollTop); |
||||
self.topRightGrid.setScrollLeft(scroll.scrollLeft); |
||||
self._populateScrollbar(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.topLeft = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.topLeftGrid] |
||||
}); |
||||
this.topRight = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.topRightGrid] |
||||
}); |
||||
this.bottomLeft = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.bottomLeftGrid] |
||||
}); |
||||
this.bottomRight = BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: false, |
||||
scrolly: false, |
||||
items: [this.bottomRightGrid] |
||||
}); |
||||
this.contextLayout = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.topLeft, |
||||
top: 0, |
||||
left: 0 |
||||
}, { |
||||
el: this.topRight, |
||||
top: 0 |
||||
}, { |
||||
el: this.bottomLeft, |
||||
left: 0 |
||||
}, { |
||||
el: this.bottomRight |
||||
}] |
||||
}); |
||||
|
||||
this.topScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_scrollbar", |
||||
width: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.topScrollbar.on(BI.GridTableScrollbar.EVENT_SCROLL, function (scrollTop) { |
||||
self.bottomLeftGrid.setScrollTop(scrollTop); |
||||
self.bottomRightGrid.setScrollTop(scrollTop); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.leftScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_horizontal_scrollbar", |
||||
height: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.leftScrollbar.on(BI.GridTableHorizontalScrollbar.EVENT_SCROLL, function (scrollLeft) { |
||||
self.topLeftGrid.setScrollLeft(scrollLeft); |
||||
self.bottomLeftGrid.setScrollLeft(scrollLeft); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.rightScrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_horizontal_scrollbar", |
||||
height: BI.GridTableScrollbar.SIZE |
||||
}); |
||||
this.rightScrollbar.on(BI.GridTableHorizontalScrollbar.EVENT_SCROLL, function (scrollLeft) { |
||||
self.topRightGrid.setScrollLeft(scrollLeft); |
||||
self.bottomRightGrid.setScrollLeft(scrollLeft); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
this.scrollBarLayout = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.topScrollbar, |
||||
right: 0, |
||||
top: 0 |
||||
}, { |
||||
el: this.leftScrollbar, |
||||
left: 0 |
||||
}, { |
||||
el: this.rightScrollbar, |
||||
}] |
||||
}); |
||||
this._width = o.width - BI.GridTableScrollbar.SIZE; |
||||
this._height = o.height - BI.GridTableScrollbar.SIZE; |
||||
this.header = this._getHeader(); |
||||
this.items = this._getItems(); |
||||
if (o.items.length > 0) { |
||||
this._populate(); |
||||
} |
||||
}, |
||||
|
||||
_getFreezeColLength: function () { |
||||
return this.options.isNeedFreeze ? this.options.freezeCols.length : 0; |
||||
}, |
||||
|
||||
_populateScrollbar: function () { |
||||
var o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
this.topScrollbar.setContentSize(o.items.length * o.rowSize); |
||||
this.topScrollbar.setSize(this._height - o.header.length * o.headerRowSize); |
||||
this.topScrollbar.setPosition(Math.min(this.bottomLeftGrid.getScrollTop(), this.bottomRightGrid.getScrollTop())); |
||||
this.topScrollbar.populate(); |
||||
|
||||
this.leftScrollbar.setContentSize(totalLeftColumnSize); |
||||
this.leftScrollbar.setSize(regionSize); |
||||
this.leftScrollbar.setPosition(this.bottomLeftGrid.getScrollLeft()); |
||||
this.leftScrollbar.populate(); |
||||
|
||||
this.rightScrollbar.setContentSize(totalRightColumnSize); |
||||
this.rightScrollbar.setSize(this._width - regionSize); |
||||
this.rightScrollbar.setPosition(this.bottomRightGrid.getScrollLeft()); |
||||
this.rightScrollbar.populate(); |
||||
|
||||
var items = this.scrollBarLayout.attr("items"); |
||||
items[0].top = o.header.length * o.headerRowSize; |
||||
items[1].top = this._height; |
||||
items[2].top = this._height; |
||||
items[2].left = regionSize; |
||||
this.scrollBarLayout.attr("items", items); |
||||
this.scrollBarLayout.resize(); |
||||
}, |
||||
|
||||
_getHeader: function () { |
||||
var o = this.options; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
var leftHeader = [], rightHeader = []; |
||||
BI.each(o.header, function (i, cols) { |
||||
leftHeader[i] = []; |
||||
rightHeader[i] = []; |
||||
BI.each(cols, function (j, col) { |
||||
var cell = { |
||||
type: "bi.grid_table_cell", |
||||
cell: col |
||||
}; |
||||
if (j < freezeColLength) { |
||||
leftHeader[i].push(cell); |
||||
} else { |
||||
rightHeader[i].push(cell); |
||||
} |
||||
}); |
||||
}); |
||||
return [leftHeader, rightHeader]; |
||||
}, |
||||
|
||||
_getItems: function () { |
||||
var o = this.options; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
var leftItems = [], rightItems = []; |
||||
BI.each(o.items, function (i, cols) { |
||||
leftItems[i] = []; |
||||
rightItems[i] = []; |
||||
BI.each(cols, function (j, col) { |
||||
var cell = { |
||||
type: "bi.grid_table_cell", |
||||
cell: col |
||||
}; |
||||
if (j < freezeColLength) { |
||||
leftItems[i].push(cell); |
||||
} else { |
||||
rightItems[i].push(cell); |
||||
} |
||||
}); |
||||
}); |
||||
return [leftItems, rightItems]; |
||||
}, |
||||
|
||||
_populateTable: function () { |
||||
var self = this, o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
|
||||
var tlw = regionSize; |
||||
var tlh = regionSize >= summaryColumnSizeArray[freezeColLength - 1] ? (o.header.length * o.headerRowSize) : (o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var trw = this._width - regionSize; |
||||
var trh = (this._width - regionSize >= totalColumnSize - (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (o.header.length * o.headerRowSize) : (o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var blw = (this._height - o.header.length * o.headerRowSize >= totalRowSize) ? regionSize : (regionSize + this._scrollBarSize); |
||||
var blh = (regionSize >= (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (this._height - o.header.length * o.headerRowSize) : (this._height - o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
var brw = (this._height - o.header.length * o.headerRowSize >= totalRowSize) ? (this._width - regionSize) : (this._width - regionSize + this._scrollBarSize); |
||||
var brh = (this._width - regionSize >= totalColumnSize - (summaryColumnSizeArray[freezeColLength - 1] || 0)) ? (this._height - o.header.length * o.headerRowSize) : (this._height - o.header.length * o.headerRowSize + this._scrollBarSize); |
||||
|
||||
var otlw = regionSize; |
||||
var otlh = o.header.length * o.headerRowSize; |
||||
var otrw = this._width - regionSize; |
||||
var otrh = o.header.length * o.headerRowSize; |
||||
var oblw = regionSize; |
||||
var oblh = this._height - o.header.length * o.headerRowSize; |
||||
var obrw = this._width - regionSize; |
||||
var obrh = this._height - o.header.length * o.headerRowSize; |
||||
|
||||
var digest = function (w, h, tw, th, el) { |
||||
if (w >= tw && h >= th) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "hidden", |
||||
overflowY: "hidden" |
||||
}) |
||||
} else if (w >= tw) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "hidden", |
||||
overflowY: "auto" |
||||
}) |
||||
} else if (h >= th) { |
||||
el.element.css({ |
||||
overflow: "hidden", |
||||
overflowX: "auto", |
||||
overflowY: "hidden" |
||||
}) |
||||
} else { |
||||
el.element.css({ |
||||
overflow: "auto", |
||||
overflowX: "auto", |
||||
overflowY: "auto" |
||||
}) |
||||
} |
||||
}; |
||||
|
||||
this.topLeft.setWidth(otlw); |
||||
this.topLeft.setHeight(otlh); |
||||
this.topRight.setWidth(otrw); |
||||
this.topRight.setHeight(otrh); |
||||
this.bottomLeft.setWidth(oblw); |
||||
this.bottomLeft.setHeight(oblh); |
||||
this.bottomRight.setWidth(obrw); |
||||
this.bottomRight.setHeight(obrh); |
||||
|
||||
this.topLeftGrid.setWidth(tlw); |
||||
this.topLeftGrid.setHeight(tlh); |
||||
this.topRightGrid.setWidth(trw); |
||||
this.topRightGrid.setHeight(trh); |
||||
this.bottomLeftGrid.setWidth(blw); |
||||
this.bottomLeftGrid.setHeight(blh); |
||||
this.bottomRightGrid.setWidth(brw); |
||||
this.bottomRightGrid.setHeight(brh); |
||||
|
||||
digest(tlw, tlh, totalLeftColumnSize, o.header.length * o.headerRowSize, this.topLeftGrid); |
||||
digest(trw, trh, totalRightColumnSize, o.header.length * o.headerRowSize, this.topRightGrid); |
||||
digest(blw, blh, totalLeftColumnSize, o.items.length * o.rowSize, this.bottomLeftGrid); |
||||
digest(brw, brh, totalRightColumnSize, o.items.length * o.rowSize, this.bottomRightGrid); |
||||
|
||||
this.topLeftGrid.setEstimatedColumnSize(freezeColLength > 0 ? totalLeftColumnSize / freezeColLength : 0); |
||||
this.topLeftGrid.setEstimatedRowSize(o.headerRowSize); |
||||
this.topRightGrid.setEstimatedColumnSize(totalRightColumnSize / (o.columnSize.length - freezeColLength)); |
||||
this.topRightGrid.setEstimatedRowSize(o.headerRowSize); |
||||
this.bottomLeftGrid.setEstimatedColumnSize(freezeColLength > 0 ? totalLeftColumnSize / freezeColLength : 0); |
||||
this.bottomLeftGrid.setEstimatedRowSize(o.rowSize); |
||||
this.bottomRightGrid.setEstimatedColumnSize(totalRightColumnSize / (o.columnSize.length - freezeColLength)); |
||||
this.bottomRightGrid.setEstimatedRowSize(o.rowSize); |
||||
|
||||
var items = this.contextLayout.attr("items"); |
||||
items[1].left = regionSize; |
||||
items[2].top = o.header.length * o.headerRowSize; |
||||
items[3].left = regionSize; |
||||
items[3].top = o.header.length * o.headerRowSize; |
||||
this.contextLayout.attr("items", items); |
||||
this.contextLayout.resize(); |
||||
|
||||
this.topLeftGrid.populate(this.header[0]); |
||||
this.topRightGrid.populate(this.header[1]); |
||||
this.bottomLeftGrid.populate(this.items[0]); |
||||
this.bottomRightGrid.populate(this.items[1]); |
||||
}, |
||||
|
||||
_populate: function () { |
||||
if (this._width <= 0 || this._height <= 0) { |
||||
return; |
||||
} |
||||
this._populateTable(); |
||||
this._populateScrollbar(); |
||||
}, |
||||
|
||||
getRegionSize: function () { |
||||
var o = this.options; |
||||
var regionSize = o.regionColumnSize[0] || 0; |
||||
if (o.isNeedFreeze === false || o.freezeCols.length === 0) { |
||||
return 0; |
||||
} |
||||
if (!regionSize) { |
||||
BI.each(o.freezeCols, function (i, col) { |
||||
regionSize += o.columnSize[col]; |
||||
}); |
||||
} |
||||
return regionSize; |
||||
}, |
||||
|
||||
setVerticalScroll: function (scrollTop) { |
||||
this.bottomLeftGrid.setScrollTop(scrollTop); |
||||
this.bottomRightGrid.setScrollTop(scrollTop); |
||||
}, |
||||
|
||||
setLeftHorizontalScroll: function (scrollLeft) { |
||||
this.topLeftGrid.setScrollLeft(scrollLeft); |
||||
this.bottomLeftGrid.setScrollLeft(scrollLeft); |
||||
}, |
||||
|
||||
setRightHorizontalScroll: function (scrollLeft) { |
||||
this.topRightGrid.setScrollLeft(scrollLeft); |
||||
this.bottomRightGrid.setScrollLeft(scrollLeft); |
||||
}, |
||||
|
||||
getVerticalScroll: function () { |
||||
return this.bottomRightGrid.getScrollTop(); |
||||
}, |
||||
|
||||
getLeftHorizontalScroll: function () { |
||||
return this.bottomLeftGrid.getScrollLeft(); |
||||
}, |
||||
|
||||
getRightHorizontalScroll: function () { |
||||
return this.bottomRightGrid.getScrollLeft(); |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.GridTable.superclass.setWidth.apply(this, arguments); |
||||
this._width = this.options.width - BI.GridTableScrollbar.SIZE; |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.GridTable.superclass.setHeight.apply(this, arguments); |
||||
this._height = this.options.height - BI.GridTableScrollbar.SIZE; |
||||
}, |
||||
|
||||
setColumnSize: function (columnSize) { |
||||
this.options.columnSize = columnSize; |
||||
}, |
||||
|
||||
setRegionColumnSize: function (regionColumnSize) { |
||||
this.options.regionColumnSize = regionColumnSize; |
||||
}, |
||||
|
||||
getColumnSize: function () { |
||||
return this.options.columnSize; |
||||
}, |
||||
|
||||
getRegionColumnSize: function () { |
||||
return this.options.regionColumnSize; |
||||
}, |
||||
|
||||
populate: function (items, header) { |
||||
if (items && this.options.items !== items) { |
||||
this.options.items = items; |
||||
this.items = this._getItems(); |
||||
this._restore(); |
||||
} |
||||
if (header && this.options.header !== header) { |
||||
this.options.header = header; |
||||
this.header = this._getHeader(); |
||||
this._restore(); |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
_restore: function () { |
||||
this.topLeftGrid.restore(); |
||||
this.topRightGrid.restore(); |
||||
this.bottomLeftGrid.restore(); |
||||
this.bottomRightGrid.restore(); |
||||
}, |
||||
|
||||
restore: function () { |
||||
this._restore(); |
||||
} |
||||
}); |
||||
$.shortcut('bi.grid_table', BI.GridTable); |
@ -0,0 +1,165 @@
|
||||
/** |
||||
* QuickGridTable |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.QuickGridTable |
||||
* @extends BI.GridTable |
||||
*/ |
||||
BI.QuickGridTable = BI.inherit(BI.GridTable, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.QuickGridTable.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-quick-grid-table" |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.QuickGridTable.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.topLeftGrid.setOverflowX(false); |
||||
this.topLeftGrid.setOverflowY(false); |
||||
this.topRightGrid.setOverflowX(false); |
||||
this.topRightGrid.setOverflowY(false); |
||||
this.bottomLeftGrid.setOverflowX(false); |
||||
this.bottomLeftGrid.setOverflowY(false); |
||||
this.bottomRightGrid.setOverflowX(false); |
||||
this.bottomRightGrid.setOverflowY(false); |
||||
this._leftWheelHandler = new BI.WheelHandler( |
||||
BI.bind(this._onWheelY, this), |
||||
BI.bind(this._shouldHandleX, this), |
||||
BI.bind(this._shouldHandleY, this) |
||||
); |
||||
this._rightWheelHandler = new BI.WheelHandler( |
||||
BI.bind(this._onWheelY, this), |
||||
BI.bind(this._shouldHandleX, this), |
||||
BI.bind(this._shouldHandleY, this) |
||||
); |
||||
this.bottomLeftGrid.element.mousewheel(function (e) { |
||||
self._leftWheelHandler.onWheel(e.originalEvent); |
||||
}); |
||||
this.bottomRightGrid.element.mousewheel(function (e) { |
||||
self._rightWheelHandler.onWheel(e.originalEvent); |
||||
}); |
||||
}, |
||||
|
||||
_shouldHandleX: function (delta) { |
||||
return false; |
||||
}, |
||||
|
||||
_shouldHandleY: function (delta) { |
||||
if (delta > 0) { |
||||
return this.bottomRightGrid.getScrollTop() < this.bottomRightGrid.getMaxScrollTop(); |
||||
} else { |
||||
return this.bottomRightGrid.getScrollTop() > 0; |
||||
} |
||||
}, |
||||
|
||||
_onWheelY: function (deltaX, deltaY) { |
||||
var self = this; |
||||
var scrollTop = this.bottomRightGrid.getScrollTop(); |
||||
scrollTop += deltaY; |
||||
this.bottomLeftGrid.setScrollTop(scrollTop); |
||||
this.bottomRightGrid.setScrollTop(scrollTop); |
||||
self._populateScrollbar(); |
||||
this.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}, |
||||
|
||||
_populateTable: function () { |
||||
var self = this, o = this.options; |
||||
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
BI.each(o.columnSize, function (i, size) { |
||||
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { |
||||
totalLeftColumnSize += size; |
||||
} else { |
||||
totalRightColumnSize += size; |
||||
} |
||||
totalColumnSize += size; |
||||
if (i === 0) { |
||||
summaryColumnSizeArray[i] = size; |
||||
} else { |
||||
summaryColumnSizeArray[i] = summaryColumnSizeArray[i - 1] + size; |
||||
} |
||||
}); |
||||
|
||||
var otlw = regionSize; |
||||
var otlh = o.header.length * o.headerRowSize; |
||||
var otrw = this._width - regionSize; |
||||
var otrh = o.header.length * o.headerRowSize; |
||||
var oblw = regionSize; |
||||
var oblh = this._height - o.header.length * o.headerRowSize; |
||||
var obrw = this._width - regionSize; |
||||
var obrh = this._height - o.header.length * o.headerRowSize; |
||||
|
||||
this.topLeft.setWidth(otlw); |
||||
this.topLeft.setHeight(otlh); |
||||
this.topRight.setWidth(otrw); |
||||
this.topRight.setHeight(otrh); |
||||
this.bottomLeft.setWidth(oblw); |
||||
this.bottomLeft.setHeight(oblh); |
||||
this.bottomRight.setWidth(obrw); |
||||
this.bottomRight.setHeight(obrh); |
||||
|
||||
this.topLeftGrid.setWidth(otlw); |
||||
this.topLeftGrid.setHeight(otlh); |
||||
this.topRightGrid.setWidth(otrw); |
||||
this.topRightGrid.setHeight(otrh); |
||||
this.bottomLeftGrid.setWidth(oblw); |
||||
this.bottomLeftGrid.setHeight(oblh); |
||||
this.bottomRightGrid.setWidth(obrw); |
||||
this.bottomRightGrid.setHeight(obrh); |
||||
|
||||
this.topLeftGrid.setEstimatedColumnSize(freezeColLength > 0 ? totalLeftColumnSize / freezeColLength : 0); |
||||
this.topLeftGrid.setEstimatedRowSize(o.headerRowSize); |
||||
this.topRightGrid.setEstimatedColumnSize(totalRightColumnSize / (o.columnSize.length - freezeColLength)); |
||||
this.topRightGrid.setEstimatedRowSize(o.headerRowSize); |
||||
this.bottomLeftGrid.setEstimatedColumnSize(freezeColLength > 0 ? totalLeftColumnSize / freezeColLength : 0); |
||||
this.bottomLeftGrid.setEstimatedRowSize(o.rowSize); |
||||
this.bottomRightGrid.setEstimatedColumnSize(totalRightColumnSize / (o.columnSize.length - freezeColLength)); |
||||
this.bottomRightGrid.setEstimatedRowSize(o.rowSize); |
||||
|
||||
var items = this.contextLayout.attr("items"); |
||||
items[1].left = regionSize; |
||||
items[2].top = o.header.length * o.headerRowSize; |
||||
items[3].left = regionSize; |
||||
items[3].top = o.header.length * o.headerRowSize; |
||||
this.contextLayout.attr("items", items); |
||||
this.contextLayout.resize(); |
||||
|
||||
var leftHeader = [], rightHeader = [], leftItems = [], rightItems = []; |
||||
BI.each(o.header, function (i, cols) { |
||||
leftHeader[i] = []; |
||||
rightHeader[i] = []; |
||||
BI.each(cols, function (j, col) { |
||||
var cell = { |
||||
type: "bi.grid_table_cell", |
||||
cell: col |
||||
}; |
||||
if (j < freezeColLength) { |
||||
leftHeader[i].push(cell); |
||||
} else { |
||||
rightHeader[i].push(cell); |
||||
} |
||||
}); |
||||
}); |
||||
BI.each(o.items, function (i, cols) { |
||||
leftItems[i] = []; |
||||
rightItems[i] = []; |
||||
BI.each(cols, function (j, col) { |
||||
var cell = { |
||||
type: "bi.grid_table_cell", |
||||
cell: col |
||||
}; |
||||
if (j < freezeColLength) { |
||||
leftItems[i].push(cell); |
||||
} else { |
||||
rightItems[i].push(cell); |
||||
} |
||||
}); |
||||
}); |
||||
this.topLeftGrid.populate(leftHeader); |
||||
this.topRightGrid.populate(rightHeader); |
||||
this.bottomLeftGrid.populate(leftItems); |
||||
this.bottomRightGrid.populate(rightItems); |
||||
} |
||||
}); |
||||
$.shortcut('bi.quick_grid_table', BI.QuickGridTable); |
@ -0,0 +1,407 @@
|
||||
/** |
||||
* |
||||
* 表格滚动条 |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.GridTableScrollbar |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.GridTableScrollbar = BI.inherit(BI.Widget, { |
||||
_const: { |
||||
FACE_MARGIN: 4, |
||||
FACE_MARGIN_2: 4 * 2, |
||||
FACE_SIZE_MIN: 30, |
||||
KEYBOARD_SCROLL_AMOUNT: 40 |
||||
}, |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.GridTableScrollbar.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "scrollbar-layout-main public-scrollbar-main", |
||||
attributes: { |
||||
tabIndex: 0 |
||||
}, |
||||
contentSize: 0, |
||||
defaultPosition: 0, |
||||
isOpaque: false, |
||||
orientation: "vertical", |
||||
position: 0, |
||||
size: 0 |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.GridTableScrollbar.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.focused = false; |
||||
this.isDragging = false; |
||||
this.face = BI.createWidget({ |
||||
type: "bi.layout", |
||||
cls: "scrollbar-layout-face public-scrollbar-face " |
||||
+ (this._isHorizontal() ? "scrollbar-layout-face-horizontal" : "scrollbar-layout-face-vertical") |
||||
}); |
||||
this.contextLayout = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.face, |
||||
left: 0, |
||||
top: 0 |
||||
}] |
||||
}); |
||||
var onWheel = o.orientation === 'horizontal' ? this._onWheelX : this._onWheelY; |
||||
this._wheelHandler = new BI.WheelHandler( |
||||
BI.bind(onWheel, this), |
||||
BI.bind(this._shouldHandleX, this), |
||||
BI.bind(this._shouldHandleY, this) |
||||
); |
||||
this._mouseMoveTracker = new BI.MouseMoveTracker( |
||||
BI.bind(this._onMouseMove, this), |
||||
BI.bind(this._onMouseMoveEnd, this), |
||||
document |
||||
); |
||||
this.element.on("mousedown", BI.bind(this._onMouseDown, this)); |
||||
this.element.on("mousewheel", function (e) { |
||||
self._wheelHandler.onWheel(e.originalEvent); |
||||
}); |
||||
this.element.on("keydown", BI.bind(this._onKeyDown, this)); |
||||
this.element.on("focus", function () { |
||||
self.focused = true; |
||||
self._populate(); |
||||
}); |
||||
this.element.on("blur", function () { |
||||
self.focused = false; |
||||
self._populate(); |
||||
}); |
||||
if (this._isHorizontal()) { |
||||
this.element.addClass("scrollbar-layout-main-horizontal"); |
||||
} else { |
||||
this.element.addClass("scrollbar-layout-main-vertical"); |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
_isHorizontal: function () { |
||||
return this.options.orientation === 'horizontal' |
||||
}, |
||||
|
||||
_getScale: function () { |
||||
var o = this.options; |
||||
var scale = o.size / o.contentSize; |
||||
var faceSize = o.size * scale; |
||||
|
||||
if (faceSize < this._const.FACE_SIZE_MIN) { |
||||
scale = (o.size - this._const.FACE_SIZE_MIN) / (o.contentSize - o.size); |
||||
} |
||||
return scale; |
||||
}, |
||||
|
||||
_getFaceSize: function () { |
||||
var o = this.options; |
||||
var scale = o.size / o.contentSize; |
||||
var faceSize = o.size * scale; |
||||
|
||||
if (faceSize < this._const.FACE_SIZE_MIN) { |
||||
faceSize = this._const.FACE_SIZE_MIN; |
||||
} |
||||
return faceSize; |
||||
}, |
||||
|
||||
_shouldHandleX: function (delta) { |
||||
return this.options.orientation === 'horizontal' ? |
||||
this._shouldHandleChange(delta) : |
||||
false; |
||||
}, |
||||
|
||||
_shouldHandleY: function (delta) { |
||||
return this.options.orientation !== 'horizontal' ? |
||||
this._shouldHandleChange(delta) : |
||||
false; |
||||
}, |
||||
|
||||
_shouldHandleChange: function (delta) { |
||||
return this.options.position + delta !== this.options.position; |
||||
}, |
||||
|
||||
_onWheelY: function (deltaX, deltaY) { |
||||
this._onWheel(deltaY); |
||||
}, |
||||
|
||||
_onWheelX: function (deltaX, deltaY) { |
||||
this._onWheel(deltaX); |
||||
}, |
||||
|
||||
_onWheel: function (delta) { |
||||
var maxPosition = this.options.contentSize - this.options.size; |
||||
this.options.position += delta; |
||||
if (this.options.position < 0) { |
||||
this.options.position = 0; |
||||
} else if (this.options.position > maxPosition) { |
||||
this.options.position = maxPosition; |
||||
} |
||||
this._populate(); |
||||
this.fireEvent(BI.GridTableScrollbar.EVENT_SCROLL, this.options.position); |
||||
}, |
||||
|
||||
_onMouseDown: function (e) { |
||||
if (e.target !== this.face.element[0]) { |
||||
var position = this._isHorizontal() ? e.offsetX : e.offsetY; |
||||
position /= this._getScale(); |
||||
this.options.position = BI.clamp(position - (this._getFaceSize() * 0.5 / this._getScale()), 0, this.options.contentSize - this.options.size); |
||||
this._populate(); |
||||
this.fireEvent(BI.GridTableScrollbar.EVENT_SCROLL, this.options.position); |
||||
} else { |
||||
this._mouseMoveTracker.captureMouseMoves(e); |
||||
} |
||||
this.element[0].focus(); |
||||
}, |
||||
|
||||
_onMouseMove: function (deltaX, deltaY) { |
||||
var delta = this._isHorizontal() ? deltaX : deltaY; |
||||
delta /= this._getScale(); |
||||
this.options.position = BI.clamp(this.options.position + delta, 0, this.options.contentSize - this.options.size); |
||||
this.isDragging = this._mouseMoveTracker.isDragging(); |
||||
this._populate(); |
||||
this.fireEvent(BI.GridTableScrollbar.EVENT_SCROLL, this.options.position); |
||||
}, |
||||
|
||||
_onMouseMoveEnd: function (event) { |
||||
this._mouseMoveTracker.releaseMouseMoves(); |
||||
if (this.isDragging === true) { |
||||
this.isDragging = false; |
||||
this._populate(); |
||||
} |
||||
}, |
||||
|
||||
_onKeyDown: function (event) { |
||||
var Keys = { |
||||
BACKSPACE: 8, |
||||
TAB: 9, |
||||
RETURN: 13, |
||||
ALT: 18, |
||||
ESC: 27, |
||||
SPACE: 32, |
||||
PAGE_UP: 33, |
||||
PAGE_DOWN: 34, |
||||
END: 35, |
||||
HOME: 36, |
||||
LEFT: 37, |
||||
UP: 38, |
||||
RIGHT: 39, |
||||
DOWN: 40, |
||||
DELETE: 46, |
||||
COMMA: 188, |
||||
PERIOD: 190, |
||||
A: 65, |
||||
Z: 90, |
||||
ZERO: 48, |
||||
NUMPAD_0: 96, |
||||
NUMPAD_9: 105 |
||||
}; |
||||
var keyCode = event.keyCode; |
||||
|
||||
if (keyCode === Keys.TAB) { |
||||
return; |
||||
} |
||||
|
||||
var distance = 40; |
||||
var direction = 0; |
||||
|
||||
if (this._isHorizontal()) { |
||||
switch (keyCode) { |
||||
case Keys.HOME: |
||||
direction = -1; |
||||
distance = this.options.contentSize; |
||||
break; |
||||
|
||||
case Keys.LEFT: |
||||
direction = -1; |
||||
break; |
||||
|
||||
case Keys.RIGHT: |
||||
direction = 1; |
||||
break; |
||||
|
||||
default: |
||||
return; |
||||
} |
||||
} |
||||
|
||||
if (!this._isHorizontal()) { |
||||
switch (keyCode) { |
||||
case Keys.SPACE: |
||||
if (event.shiftKey) { |
||||
direction = -1; |
||||
} else { |
||||
direction = 1; |
||||
} |
||||
break; |
||||
|
||||
case Keys.HOME: |
||||
direction = -1; |
||||
distance = this.options.contentSize; |
||||
break; |
||||
|
||||
case Keys.UP: |
||||
direction = -1; |
||||
break; |
||||
|
||||
case Keys.DOWN: |
||||
direction = 1; |
||||
break; |
||||
|
||||
case Keys.PAGE_UP: |
||||
direction = -1; |
||||
distance = this.options.size; |
||||
break; |
||||
|
||||
case Keys.PAGE_DOWN: |
||||
direction = 1; |
||||
distance = this.options.size; |
||||
break; |
||||
|
||||
default: |
||||
return; |
||||
} |
||||
} |
||||
|
||||
this.options.position = BI.clamp(this.options.position + (distance * direction), 0, this.options.contentSize - this.options.size); |
||||
event.preventDefault(); |
||||
this._populate(); |
||||
this.fireEvent(BI.GridTableScrollbar.EVENT_SCROLL, this.options.position); |
||||
}, |
||||
|
||||
_populate: function () { |
||||
var self = this, o = this.options; |
||||
if (o.size < 1 || o.contentSize <= o.size) { |
||||
this.setVisible(false); |
||||
return; |
||||
} |
||||
this.setVisible(true); |
||||
|
||||
var size = o.size; |
||||
var isHorizontal = this._isHorizontal(); |
||||
var isActive = this.focused || this.isDragging; |
||||
|
||||
var faceSize = this._getFaceSize(); |
||||
var isOpaque = o.isOpaque; |
||||
this.element[isOpaque === true ? "addClass" : "removeClass"]("public-scrollbar-main-opaque"); |
||||
this.element[isActive === true ? "addClass" : "removeClass"]("public-scrollbar-main-active"); |
||||
|
||||
this.face.element[isActive === true ? "addClass" : "removeClass"]("public-scrollbar-face-active"); |
||||
|
||||
var position = o.position * this._getScale() + this._const.FACE_MARGIN; |
||||
|
||||
var items = this.contextLayout.attr("items"); |
||||
if (isHorizontal) { |
||||
this.setWidth(size); |
||||
this.face.setWidth(faceSize - this._const.FACE_MARGIN_2); |
||||
items[0].left = position; |
||||
items[0].top = 0; |
||||
} else { |
||||
this.setHeight(size); |
||||
this.face.setHeight(faceSize - this._const.FACE_MARGIN_2); |
||||
items[0].left = 0; |
||||
items[0].top = position; |
||||
} |
||||
this.contextLayout.attr("items", items); |
||||
this.contextLayout.resize(); |
||||
}, |
||||
|
||||
setContentSize: function (contentSize) { |
||||
this.options.contentSize = contentSize; |
||||
}, |
||||
|
||||
setPosition: function (position) { |
||||
this.options.position = position; |
||||
}, |
||||
|
||||
setSize: function (size) { |
||||
this.options.size = size; |
||||
}, |
||||
|
||||
populate: function () { |
||||
this._populate(); |
||||
} |
||||
}); |
||||
BI.GridTableScrollbar.SIZE = 10; |
||||
BI.GridTableScrollbar.EVENT_SCROLL = "EVENT_SCROLL"; |
||||
$.shortcut("bi.grid_table_scrollbar", BI.GridTableScrollbar); |
||||
|
||||
|
||||
BI.GridTableHorizontalScrollbar = BI.inherit(BI.Widget, { |
||||
_const: { |
||||
FACE_MARGIN: 4, |
||||
FACE_MARGIN_2: 4 * 2, |
||||
FACE_SIZE_MIN: 30, |
||||
KEYBOARD_SCROLL_AMOUNT: 40 |
||||
}, |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.GridTableHorizontalScrollbar.superclass._defaultConfig.apply(this, arguments), { |
||||
attributes: { |
||||
tabIndex: 0 |
||||
}, |
||||
contentSize: 0, |
||||
position: 0, |
||||
size: 0 |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.GridTableHorizontalScrollbar.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.scrollbar = BI.createWidget({ |
||||
type: "bi.grid_table_scrollbar", |
||||
orientation: "horizontal", |
||||
isOpaque: true, |
||||
position: o.position, |
||||
contentSize: o.contentSize, |
||||
size: o.size |
||||
}); |
||||
this.scrollbar.on(BI.GridTableScrollbar.EVENT_SCROLL, function () { |
||||
self.fireEvent(BI.GridTableHorizontalScrollbar.EVENT_SCROLL, arguments); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
cls: "horizontal-scrollbar", |
||||
element: this.element, |
||||
width: o.size, |
||||
height: BI.GridTableScrollbar.SIZE, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.absolute", |
||||
scrollable: false, |
||||
height: BI.GridTableScrollbar.SIZE, |
||||
items: [{ |
||||
el: this.scrollbar, |
||||
left: 0, |
||||
top: 0 |
||||
}] |
||||
}, |
||||
top: 0, |
||||
left: 0, |
||||
right: 0 |
||||
}] |
||||
}); |
||||
}, |
||||
|
||||
setContentSize: function (contentSize) { |
||||
this.options.contentSize = contentSize; |
||||
this.scrollbar.setContentSize(contentSize); |
||||
}, |
||||
|
||||
setPosition: function (position) { |
||||
this.options.position = position; |
||||
this.scrollbar.setPosition(position); |
||||
}, |
||||
|
||||
setSize: function (size) { |
||||
this.setWidth(size); |
||||
this.options.size = size; |
||||
this.scrollbar.setSize(size); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.scrollbar.populate(); |
||||
} |
||||
}); |
||||
BI.GridTableHorizontalScrollbar.EVENT_SCROLL = "EVENT_SCROLL"; |
||||
$.shortcut("bi.grid_table_horizontal_scrollbar", BI.GridTableHorizontalScrollbar); |
@ -0,0 +1,30 @@
|
||||
/** |
||||
* |
||||
* 表格 |
||||
* |
||||
* Created by GUY on 2015/9/22. |
||||
* @class BI.TableHeaderCell |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.TableHeaderCell = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.TableHeaderCell.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-table-header-cell", |
||||
text: "" |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.TableHeaderCell.superclass._init.apply(this, arguments); |
||||
BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
textAlign: "center", |
||||
height: this.options.height, |
||||
text: this.options.text, |
||||
value: this.options.value |
||||
}) |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.table_header_cell", BI.TableHeaderCell); |
@ -0,0 +1,96 @@
|
||||
/** |
||||
* |
||||
* 表格单元格 |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.ResizableTableCell |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.ResizableTableCell = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ResizableTableCell.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-resizable-table-cell", |
||||
cell: {}, |
||||
start: BI.emptyFn, |
||||
resize: BI.emptyFn, |
||||
stop: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ResizableTableCell.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.cell = BI.createWidget(BI.extend({type: "bi.label"}, o.cell, {width: o.width, height: o.height})); |
||||
|
||||
var startDrag = false; |
||||
var size = 0, offset = 0, defaultSize = o.width; |
||||
var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX, deltaY) { |
||||
if (mouseMoveTracker.isDragging()) { |
||||
startDrag = true; |
||||
offset += deltaX; |
||||
size = BI.clamp(defaultSize + offset, 15, Number.MAX_VALUE); |
||||
self.handler.element.addClass("dragging"); |
||||
o.resize(size); |
||||
} |
||||
}, function () { |
||||
if (startDrag === true) { |
||||
size = BI.clamp(size, 15, Number.MAX_VALUE); |
||||
o.stop(size); |
||||
size = 0; |
||||
offset = 0; |
||||
defaultSize = o.width; |
||||
self.handler.element.removeClass("dragging"); |
||||
startDrag = false; |
||||
} |
||||
mouseMoveTracker.releaseMouseMoves(); |
||||
}, document); |
||||
this.handler = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
cls: "resizable-table-cell-resizer-container", |
||||
width: 6, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.layout", |
||||
cls: "resizable-table-cell-resizer-knob", |
||||
width: 4 |
||||
}, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
this.handler.element.on("mousedown", function (event) { |
||||
defaultSize = o.width; |
||||
mouseMoveTracker.captureMouseMoves(event); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.cell, |
||||
left: 0, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}, { |
||||
el: this.handler, |
||||
right: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}) |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.ResizableTableCell.superclass.setWidth.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setWidth(o.width); |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.ResizableTableCell.superclass.setHeight.apply(this, arguments); |
||||
var o = this.options; |
||||
this.cell.setHeight(o.height); |
||||
} |
||||
}); |
||||
$.shortcut("bi.resizable_table_cell", BI.ResizableTableCell); |
@ -0,0 +1,349 @@
|
||||
/** |
||||
* |
||||
* 可调整列宽的grid表格 |
||||
* |
||||
* Created by GUY on 2016/1/12. |
||||
* @class BI.ResizableTable |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.ResizableTable = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ResizableTable.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-resizable-table", |
||||
el: { |
||||
type: "bi.grid_table" |
||||
}, |
||||
isNeedFreeze: false, |
||||
isNeedResize: true, |
||||
isResizeAdapt: false, |
||||
headerRowSize: 25, |
||||
rowSize: 25, |
||||
isNeedMerge: true,//是否需要合并单元格
|
||||
mergeCols: [], |
||||
mergeRule: BI.emptyFn, |
||||
columnSize: [], |
||||
freezeCols: [], |
||||
header: [], |
||||
items: [], |
||||
regionColumnSize: [] |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ResizableTable.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.resizer = BI.createWidget({ |
||||
type: "bi.layout", |
||||
cls: "resizable-table-resizer", |
||||
invisible: true, |
||||
width: 2 |
||||
}); |
||||
this.regionResizerHandler = this._createResizerHandler(); |
||||
this.table = BI.createWidget(o.el, { |
||||
type: "bi.grid_table", |
||||
element: this.element, |
||||
width: o.width, |
||||
height: o.height, |
||||
headerRowSize: o.headerRowSize, |
||||
rowSize: o.rowSize, |
||||
columnSize: o.columnSize, |
||||
|
||||
isNeedFreeze: o.isNeedFreeze, |
||||
freezeCols: o.freezeCols, |
||||
isNeedMerge: o.isNeedMerge, |
||||
mergeCols: o.mergeCols, |
||||
mergeRule: BI.bind(this._mergeRule, this), |
||||
|
||||
header: this._formatHeader(o.header), |
||||
items: o.items, |
||||
regionColumnSize: o.regionColumnSize |
||||
}); |
||||
this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { |
||||
self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.absolute", |
||||
element: this.element, |
||||
items: [{ |
||||
el: this.regionResizerHandler, |
||||
left: 0, |
||||
top: 0, |
||||
bottom: 0 |
||||
}, { |
||||
el: this.resizer, |
||||
left: 0, |
||||
top: 0 |
||||
}] |
||||
}); |
||||
this._populate(); |
||||
}, |
||||
|
||||
_mergeRule: function (row1, row2) { |
||||
var o = this.options; |
||||
if (row1.type === "bi.resizable_table_cell") { |
||||
row1 = row1.cell; |
||||
} |
||||
if (row2.type === "bi.resizable_table_cell") { |
||||
row2 = row2.cell; |
||||
} |
||||
return o.mergeRule(row1, row2); |
||||
}, |
||||
|
||||
_createResizerHandler: function () { |
||||
var self = this, o = this.options; |
||||
var regionResizerHandler = BI.createWidget({ |
||||
type: "bi.absolute", |
||||
cls: "resizable-table-region-resizer", |
||||
invisible: true, |
||||
width: 6, |
||||
items: [{ |
||||
el: { |
||||
type: "bi.layout", |
||||
width: 2, |
||||
cls: "resizable-table-region-resizer-knob" |
||||
}, |
||||
left: 2, |
||||
top: 0, |
||||
bottom: 0 |
||||
}] |
||||
}); |
||||
var size = 0, offset = 0, defaultSize = 0, start = false; |
||||
var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX, deltaY) { |
||||
if (mouseMoveTracker.isDragging()) { |
||||
start = true; |
||||
offset += deltaX; |
||||
size = BI.clamp(defaultSize + offset, 15, o.width - 15); |
||||
|
||||
self.regionResizerHandler.element.addClass("dragging"); |
||||
self._setRegionResizerHandlerPosition(size - 3, 0); |
||||
} |
||||
|
||||
}, function () { |
||||
if (start === true) { |
||||
o.regionColumnSize[0] = BI.clamp(size, 15, o.width - 15); |
||||
self.table.setRegionColumnSize(o.regionColumnSize); |
||||
if (o.isResizeAdapt === true) { |
||||
var freezeColumnSize = self._getFreezeColumnSize(); |
||||
o.columnSize[self._getFreezeColLength() - 1] += o.regionColumnSize[0] - freezeColumnSize; |
||||
self.table.setColumnSize(o.columnSize); |
||||
} |
||||
self.table.populate(); |
||||
self._populate(); |
||||
self.regionResizerHandler.element.removeClass("dragging"); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE); |
||||
start = false; |
||||
} |
||||
mouseMoveTracker.releaseMouseMoves(); |
||||
}, document); |
||||
regionResizerHandler.element.on("mousedown", function (event) { |
||||
defaultSize = size = self._getRegionSize(); |
||||
offset = 0; |
||||
self._setResizerPosition(0, 0); |
||||
mouseMoveTracker.captureMouseMoves(event); |
||||
}); |
||||
return regionResizerHandler; |
||||
}, |
||||
|
||||
_setResizerPosition: function (left, top) { |
||||
this.resizer.element.css({ |
||||
left: left + "px", |
||||
top: top + "px" |
||||
}); |
||||
}, |
||||
|
||||
_setRegionResizerHandlerPosition: function (left, top) { |
||||
this.regionResizerHandler.element.css({ |
||||
left: left + "px", |
||||
top: top + "px" |
||||
}); |
||||
}, |
||||
|
||||
_getRegionSize: function () { |
||||
var o = this.options; |
||||
var regionSize = o.regionColumnSize[0] || 0; |
||||
if (o.isNeedFreeze === false || o.freezeCols.length === 0) { |
||||
return 0; |
||||
} |
||||
if (!regionSize) { |
||||
BI.each(o.freezeCols, function (i, col) { |
||||
regionSize += o.columnSize[col]; |
||||
}); |
||||
} |
||||
return regionSize; |
||||
}, |
||||
|
||||
_getRegionRowSize: function () { |
||||
var o = this.options; |
||||
return [o.header.length * o.headerRowSize, |
||||
Math.min(o.height - o.header.length * o.headerRowSize, o.items.length * o.rowSize)]; |
||||
}, |
||||
|
||||
_getFreezeColLength: function () { |
||||
return this.options.freezeCols.length; |
||||
}, |
||||
|
||||
_getFreezeColumnSize: function () { |
||||
var columnSize = this.options.columnSize; |
||||
var sum = 0; |
||||
for (var i = 0, len = this._getFreezeColLength(); i < len; i++) { |
||||
sum += columnSize[i]; |
||||
} |
||||
return sum; |
||||
}, |
||||
|
||||
_getResizerLeft: function (j) { |
||||
var left = 0; |
||||
var columnSize = this.options.columnSize; |
||||
var freezeColLength = this._getFreezeColLength(); |
||||
for (var i = (j >= freezeColLength ? freezeColLength : 0); i < j; i++) { |
||||
left += columnSize[i] || 0; |
||||
} |
||||
if (j >= freezeColLength) { |
||||
left += this.table.getRegionSize(); |
||||
left -= this.table.getRightHorizontalScroll(); |
||||
} else { |
||||
left -= this.table.getLeftHorizontalScroll(); |
||||
} |
||||
return left; |
||||
}, |
||||
|
||||
_formatHeader: function (header) { |
||||
var self = this, o = this.options; |
||||
var result = []; |
||||
var resize = function (j, size) { |
||||
self.resizer.setVisible(true); |
||||
var height = o.headerRowSize + self._getRegionRowSize()[1]; |
||||
self.resizer.setHeight(height); |
||||
|
||||
self._setResizerPosition(self._getResizerLeft(j) + size, (o.header.length - 1) * o.headerRowSize); |
||||
}; |
||||
var stop = function (j, size) { |
||||
self.resizer.setVisible(false); |
||||
o.columnSize[j] = size; |
||||
self.table.setColumnSize(o.columnSize); |
||||
self.table.populate(); |
||||
self._populate(); |
||||
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); |
||||
}; |
||||
BI.each(header, function (i, cols) { |
||||
if (i === header.length - 1) { |
||||
result[i] = []; |
||||
BI.each(cols, function (j, col) { |
||||
if (j === self._getFreezeColLength() - 1 || j === cols.length - 1) { |
||||
result[i][j] = col; |
||||
} else { |
||||
result[i][j] = { |
||||
type: "bi.resizable_table_cell", |
||||
cell: col, |
||||
resize: BI.bind(resize, null, j), |
||||
stop: BI.bind(stop, null, j) |
||||
}; |
||||
if (o.isNeedMerge) { |
||||
var r = i; |
||||
while (r > 0 && self._mergeRule(result[r][j], result[r - 1][j])) { |
||||
result[r - 1][j] = { |
||||
type: "bi.resizable_table_cell", |
||||
cell: result[r - 1][j], |
||||
resize: BI.bind(resize, null, j), |
||||
stop: BI.bind(stop, null, j) |
||||
}; |
||||
r--; |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} else { |
||||
result.push(cols); |
||||
} |
||||
}); |
||||
return result; |
||||
}, |
||||
|
||||
_populate: function () { |
||||
var o = this.options; |
||||
var regionSize = this._getRegionSize(); |
||||
if (regionSize > 0) { |
||||
this.regionResizerHandler.setVisible(true); |
||||
this._setRegionResizerHandlerPosition(regionSize - 3, 0); |
||||
} else { |
||||
this.regionResizerHandler.setVisible(false); |
||||
} |
||||
}, |
||||
|
||||
setWidth: function (width) { |
||||
BI.ResizableTable.superclass.setWidth.apply(this, arguments); |
||||
this.table.setWidth(width) |
||||
}, |
||||
|
||||
setHeight: function (height) { |
||||
BI.ResizableTable.superclass.setHeight.apply(this, arguments); |
||||
this.table.setHeight(height); |
||||
}, |
||||
|
||||
setVerticalScroll: function (scrollTop) { |
||||
this.table.setVerticalScroll(scrollTop); |
||||
}, |
||||
|
||||
setLeftHorizontalScroll: function (scrollLeft) { |
||||
this.table.setLeftHorizontalScroll(scrollLeft); |
||||
}, |
||||
|
||||
setRightHorizontalScroll: function (scrollLeft) { |
||||
this.table.setRightHorizontalScroll(scrollLeft); |
||||
}, |
||||
|
||||
setColumnSize: function (columnSize) { |
||||
this.options.columnSize = columnSize; |
||||
this.table.setColumnSize(columnSize); |
||||
}, |
||||
|
||||
getColumnSize: function () { |
||||
return this.table.getColumnSize(); |
||||
}, |
||||
|
||||
setRegionColumnSize: function (columnSize) { |
||||
this.options.regionColumnSize = columnSize; |
||||
this.table.setRegionColumnSize(columnSize); |
||||
}, |
||||
|
||||
getRegionColumnSize: function () { |
||||
return this.table.getRegionColumnSize(); |
||||
}, |
||||
|
||||
getVerticalScroll: function () { |
||||
return this.table.getVerticalScroll(); |
||||
}, |
||||
|
||||
getLeftHorizontalScroll: function () { |
||||
return this.table.getLeftHorizontalScroll(); |
||||
}, |
||||
|
||||
getRightHorizontalScroll: function () { |
||||
return this.table.getRightHorizontalScroll(); |
||||
}, |
||||
|
||||
attr: function () { |
||||
BI.ResizableTable.superclass.attr.apply(this, arguments); |
||||
this.table.attr.apply(this.table, arguments); |
||||
}, |
||||
|
||||
restore: function () { |
||||
this.table.restore(); |
||||
}, |
||||
|
||||
populate: function (items, header) { |
||||
if (items) { |
||||
this.options.items = items; |
||||
} |
||||
if (header) { |
||||
this.options.header = header; |
||||
if (this.options.isNeedResize) { |
||||
header = this._formatHeader(header); |
||||
} |
||||
} |
||||
this.table.populate(items, header); |
||||
this._populate(); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.resizable_table", BI.ResizableTable); |
@ -0,0 +1,500 @@
|
||||
/** |
||||
* guy |
||||
* 异步树 |
||||
* @class BI.TreeView |
||||
* @extends BI.Pane |
||||
*/ |
||||
BI.TreeView = BI.inherit(BI.Pane, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.TreeView.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-tree", |
||||
paras: {}, |
||||
itemsCreator: BI.emptyFn |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.TreeView.superclass._init.apply(this, arguments); |
||||
|
||||
this._stop = false; |
||||
this.container = BI.createWidget(); |
||||
|
||||
this._createTree(); |
||||
this.tip = BI.createWidget({ |
||||
type: "bi.loading_bar", |
||||
invisible: true, |
||||
handler: BI.bind(this._loadMore, this) |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.vertical", |
||||
scrollable: true, |
||||
scrolly: false, |
||||
element: this.element, |
||||
items: [this.container, this.tip] |
||||
}); |
||||
|
||||
}, |
||||
|
||||
_createTree: function () { |
||||
this.id = "bi-tree" + BI.UUID(); |
||||
if (this.nodes) { |
||||
this.nodes.destroy(); |
||||
} |
||||
if (this.tree) { |
||||
this.tree.destroy(); |
||||
} |
||||
this.tree = BI.createWidget({ |
||||
type: "bi.layout", |
||||
element: "<ul id='" + this.id + "' class='ztree'></ul>" |
||||
}); |
||||
BI.createWidget({ |
||||
type: "bi.default", |
||||
element: this.container, |
||||
items: [this.tree] |
||||
}); |
||||
}, |
||||
|
||||
//选择节点触发方法
|
||||
_selectTreeNode: function (treeId, treeNode) { |
||||
this.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, treeNode, this); |
||||
this.fireEvent(BI.TreeView.EVENT_CHANGE, treeNode, this); |
||||
}, |
||||
|
||||
//配置属性
|
||||
_configSetting: function () { |
||||
var paras = this.options.paras; |
||||
var self = this; |
||||
var setting = { |
||||
async: { |
||||
enable: true, |
||||
url: getUrl, |
||||
autoParam: ["id", "name"], |
||||
otherParam: BI.cjkEncodeDO(paras) |
||||
}, |
||||
check: { |
||||
enable: true |
||||
}, |
||||
data: { |
||||
key: { |
||||
title: "title", |
||||
name: "text" |
||||
}, |
||||
simpleData: { |
||||
enable: true |
||||
} |
||||
}, |
||||
view: { |
||||
showIcon: false, |
||||
expandSpeed: "", |
||||
nameIsHTML: true, |
||||
dblClickExpand: false |
||||
}, |
||||
callback: { |
||||
beforeExpand: beforeExpand, |
||||
onAsyncSuccess: onAsyncSuccess, |
||||
onAsyncError: onAsyncError, |
||||
beforeCheck: beforeCheck, |
||||
onCheck: onCheck, |
||||
onExpand: onExpand, |
||||
onCollapse: onCollapse, |
||||
onClick: onClick |
||||
} |
||||
}; |
||||
var className = "dark", perTime = 100; |
||||
|
||||
function onClick(event, treeId, treeNode) { |
||||
self.nodes.checkNode(treeNode, !treeNode.checked, true, true); |
||||
} |
||||
|
||||
function getUrl(treeId, treeNode) { |
||||
var parentNode = self._getParentValues(treeNode); |
||||
treeNode.times = treeNode.times || 1; |
||||
var param = "id=" + treeNode.id |
||||
+ "×=" + (treeNode.times++) |
||||
+ "&parent_values= " + window.encodeURIComponent(BI.jsonEncode(parentNode)) |
||||
+ "&check_state=" + window.encodeURIComponent(BI.jsonEncode(treeNode.getCheckStatus())); |
||||
|
||||
return BI.servletURL + '?op=' + self.options.op + '&cmd=' + self.options.cmd + "&" + param; |
||||
} |
||||
|
||||
function beforeExpand(treeId, treeNode) { |
||||
if (!treeNode.isAjaxing) { |
||||
if (!treeNode.children) { |
||||
treeNode.times = 1; |
||||
ajaxGetNodes(treeNode, "refresh"); |
||||
} |
||||
return true; |
||||
} else { |
||||
BI.Msg.toast("Please Wait。", "warning"); |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
function onAsyncSuccess(event, treeId, treeNode, msg) { |
||||
treeNode.halfCheck = false; |
||||
if (!msg || msg.length === 0 || /^<html>[\s,\S]*<\/html>$/gi.test(msg) || self._stop) { |
||||
return; |
||||
} |
||||
var zTree = self.nodes; |
||||
var totalCount = treeNode.count || 0; |
||||
|
||||
//尝试去获取下一组节点,若获取值为空数组,表示获取完成
|
||||
// TODO by GUY
|
||||
if (treeNode.children.length > totalCount) { |
||||
treeNode.count = treeNode.children.length; |
||||
BI.delay(function () { |
||||
ajaxGetNodes(treeNode); |
||||
}, perTime); |
||||
} else { |
||||
//treeNode.icon = "";
|
||||
zTree.updateNode(treeNode); |
||||
zTree.selectNode(treeNode.children[0]); |
||||
//className = (className === "dark" ? "":"dark");
|
||||
} |
||||
} |
||||
|
||||
function onAsyncError(event, treeId, treeNode, XMLHttpRequest, textStatus, errorThrown) { |
||||
var zTree = self.nodes; |
||||
BI.Msg.toast("Error!", "warning"); |
||||
//treeNode.icon = "";
|
||||
//zTree.updateNode(treeNode);
|
||||
} |
||||
|
||||
function ajaxGetNodes(treeNode, reloadType) { |
||||
var zTree = self.nodes; |
||||
if (reloadType == "refresh") { |
||||
//treeNode.icon = FR.servletURL +"?op=resource&resource=/com/fr/bi/web/css/base/third/ztree/img/loading.gif";
|
||||
zTree.updateNode(treeNode); |
||||
} |
||||
zTree.reAsyncChildNodes(treeNode, reloadType, true); |
||||
} |
||||
|
||||
function beforeCheck(treeId, treeNode) { |
||||
treeNode.halfCheck = false; |
||||
if (treeNode.checked === true) { |
||||
//将展开的节点halfCheck设为false,解决展开节点存在halfCheck=true的情况 guy
|
||||
//所有的半选状态都需要取消halfCheck=true的情况
|
||||
function track(children) { |
||||
BI.each(children, function (i, ch) { |
||||
if (ch.halfCheck === true) { |
||||
ch.halfCheck = false; |
||||
track(ch.children); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
track(treeNode.children); |
||||
var treeObj = self.nodes; |
||||
var nodes = treeObj.getSelectedNodes(); |
||||
$.each(nodes, function (index, node) { |
||||
node.halfCheck = false; |
||||
}) |
||||
} |
||||
} |
||||
|
||||
function onCheck(event, treeId, treeNode) { |
||||
self._selectTreeNode(treeId, treeNode); |
||||
} |
||||
|
||||
function onExpand(event, treeId, treeNode) { |
||||
treeNode.halfCheck = false; |
||||
} |
||||
|
||||
function onCollapse(event, treeId, treeNode) { |
||||
} |
||||
|
||||
return setting; |
||||
}, |
||||
|
||||
_getParentValues: function (treeNode) { |
||||
if (!treeNode.getParentNode()) { |
||||
return []; |
||||
} |
||||
var parentNode = treeNode.getParentNode(); |
||||
var result = this._getParentValues(parentNode); |
||||
result = result.concat([this._getNodeValue(parentNode)]); |
||||
return result; |
||||
}, |
||||
|
||||
_getNodeValue: function (node) { |
||||
//去除标红
|
||||
return node.value || node.text.replace(/<[^>]+>/g, ""); |
||||
}, |
||||
|
||||
//获取半选框值
|
||||
_getHalfSelectedValues: function (map, node) { |
||||
var self = this; |
||||
var checkState = node.getCheckStatus(); |
||||
//将未选的去掉
|
||||
if (checkState.checked === false && checkState.half === false) { |
||||
return; |
||||
} |
||||
//如果节点已展开,并且是半选
|
||||
if (BI.isNotEmptyArray(node.children) && checkState.half === true) { |
||||
var children = node.children; |
||||
BI.each(children, function (i, ch) { |
||||
self._getHalfSelectedValues(map, ch); |
||||
}); |
||||
return; |
||||
} |
||||
var parent = node.parentValues || self._getParentValues(node); |
||||
var path = parent.concat(this._getNodeValue(node)); |
||||
if (BI.isNotEmptyArray(node.children) || checkState.half === false) { |
||||
this._buildTree(map, path); |
||||
return; |
||||
} |
||||
var storeValues = BI.deepClone(this.options.paras.selected_values); |
||||
var treeNode = this._getTree(storeValues, path); |
||||
this._addTreeNode(map, parent, this._getNodeValue(node), treeNode); |
||||
}, |
||||
|
||||
_getTree: function (map, values) { |
||||
var cur = map; |
||||
BI.any(values, function (i, value) { |
||||
if (cur[value] == null) { |
||||
return true; |
||||
} |
||||
cur = cur[value]; |
||||
}); |
||||
return cur; |
||||
}, |
||||
|
||||
_addTreeNode: function (map, values, key, value) { |
||||
var cur = map; |
||||
BI.each(values, function (i, value) { |
||||
if (cur[value] == null) { |
||||
cur[value] = {}; |
||||
} |
||||
cur = cur[value]; |
||||
}); |
||||
cur[key] = value; |
||||
}, |
||||
|
||||
//构造树节点
|
||||
_buildTree: function (map, values) { |
||||
var cur = map; |
||||
BI.each(values, function (i, value) { |
||||
if (cur[value] == null) { |
||||
cur[value] = {}; |
||||
} |
||||
cur = cur[value]; |
||||
}) |
||||
}, |
||||
|
||||
//获取选中的值
|
||||
_getSelectedValues: function () { |
||||
var self = this; |
||||
var hashMap = {}; |
||||
var rootNoots = this.nodes.getNodes(); |
||||
track(rootNoots); |
||||
function track(nodes) { |
||||
BI.each(nodes, function (i, node) { |
||||
var checkState = node.getCheckStatus(); |
||||
if (checkState.checked === true || checkState.half === true) { |
||||
if (checkState.half === true) { |
||||
self._getHalfSelectedValues(hashMap, node); |
||||
} else { |
||||
var parentValues = node.parentValues || self._getParentValues(node); |
||||
var values = parentValues.concat([self._getNodeValue(node)]); |
||||
self._buildTree(hashMap, values); |
||||
} |
||||
} |
||||
}) |
||||
} |
||||
|
||||
return hashMap; |
||||
}, |
||||
|
||||
//处理节点
|
||||
_dealWidthNodes: function (nodes) { |
||||
var self = this, o = this.options; |
||||
//处理标红
|
||||
if (BI.isKey(o.paras.keyword)) { |
||||
var keyword = o.paras.keyword; |
||||
var ns = BI.Tree.transformToArrayFormat(nodes); |
||||
BI.each(ns, function (i, n) { |
||||
n.text = $("<div>").__textKeywordMarked__(n.text, keyword, n.py).html(); |
||||
}); |
||||
} |
||||
return nodes; |
||||
}, |
||||
|
||||
_loadMore: function () { |
||||
var self = this, o = this.options; |
||||
this.tip.setLoading(); |
||||
var op = BI.extend({}, o.paras, { |
||||
times: ++this.times |
||||
}); |
||||
o.itemsCreator(op, function (res) { |
||||
if (self._stop === true) { |
||||
return; |
||||
} |
||||
var hasNext = !!res.hasNext, nodes = res.items || []; |
||||
|
||||
if (!hasNext) { |
||||
self.tip.setEnd(); |
||||
} else { |
||||
self.tip.setLoaded(); |
||||
} |
||||
if (nodes.length > 0) { |
||||
self.nodes.addNodes(null, self._dealWidthNodes(nodes)); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
//生成树内部方法
|
||||
_initTree: function (setting) { |
||||
var self = this, o = this.options; |
||||
self.fireEvent(BI.Events.INIT); |
||||
this.times = 1; |
||||
var tree = this.tree; |
||||
tree.empty(); |
||||
this.loading(); |
||||
this.tip.setVisible(false); |
||||
var callback = function (nodes) { |
||||
if (self._stop === true) { |
||||
return; |
||||
} |
||||
self.nodes = $.fn.zTree.init(tree.element, setting, nodes); |
||||
}; |
||||
var op = BI.extend({}, o.paras, { |
||||
times: 1, |
||||
type: BICst.TREE.TREE_REQ_TYPE.INIT_DATA |
||||
}); |
||||
|
||||
o.itemsCreator(op, function (res) { |
||||
if (self._stop === true) { |
||||
return; |
||||
} |
||||
var hasNext = !!res.hasNext, nodes = res.items || []; |
||||
if (nodes.length > 0) { |
||||
callback(self._dealWidthNodes(nodes)); |
||||
} |
||||
self.setTipVisible(nodes.length <= 0); |
||||
self.loaded(); |
||||
if (!hasNext) { |
||||
self.tip.invisible(); |
||||
} else { |
||||
self.tip.setLoaded(); |
||||
} |
||||
op.times === 1 && self.fireEvent(BI.Events.AFTERINIT); |
||||
}); |
||||
}, |
||||
|
||||
//构造树结构,
|
||||
initTree: function (nodes, setting) { |
||||
var setting = setting || { |
||||
async: { |
||||
enable: false |
||||
}, |
||||
check: { |
||||
enable: false |
||||
}, |
||||
data: { |
||||
key: { |
||||
title: "title", |
||||
name: "text" |
||||
}, |
||||
simpleData: { |
||||
enable: true |
||||
} |
||||
}, |
||||
view: { |
||||
showIcon: false, |
||||
expandSpeed: "" |
||||
}, |
||||
callback: {} |
||||
}; |
||||
this.nodes = $.fn.zTree.init(this.tree.element, setting, nodes); |
||||
}, |
||||
|
||||
start: function () { |
||||
this._stop = false; |
||||
}, |
||||
|
||||
stop: function () { |
||||
this._stop = true; |
||||
}, |
||||
|
||||
//生成树方法
|
||||
stroke: function (config) { |
||||
delete this.options.keyword; |
||||
BI.extend(this.options.paras, config); |
||||
var setting = this._configSetting(); |
||||
this._createTree(); |
||||
this.start(); |
||||
this._initTree(setting); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.stroke.apply(this, arguments); |
||||
}, |
||||
|
||||
hasChecked: function () { |
||||
var treeObj = this.nodes; |
||||
return treeObj.getCheckedNodes(true).length > 0; |
||||
}, |
||||
|
||||
checkAll: function (checked) { |
||||
this.nodes && this.nodes.checkAllNodes(checked); |
||||
}, |
||||
|
||||
expandAll: function (flag) { |
||||
this.nodes && this.nodes.expandAll(flag); |
||||
}, |
||||
|
||||
setValue: function (value, param) { |
||||
this.options.paras.selected_values = value || {}; |
||||
this.selected_values = BI.deepClone(value) || {}; |
||||
this.checkAll(false); |
||||
this.updateValue(value, param); |
||||
this.refresh(); |
||||
}, |
||||
|
||||
updateValue: function (values, param) { |
||||
if (!this.nodes) { |
||||
return; |
||||
} |
||||
param || (param = "value"); |
||||
var treeObj = this.nodes; |
||||
BI.each(values, function (v, op) { |
||||
var nodes = treeObj.getNodesByParam(param, v, null); |
||||
BI.each(nodes, function (j, node) { |
||||
BI.extend(node, {checked: true}, op); |
||||
treeObj.updateNode(node); |
||||
}) |
||||
}); |
||||
}, |
||||
|
||||
refresh: function () { |
||||
this.nodes && this.nodes.refresh(); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
if (!this.nodes) { |
||||
return null; |
||||
} |
||||
return this._getSelectedValues(); |
||||
}, |
||||
|
||||
empty: function () { |
||||
BI.isNotNull(this.nodes) && this.nodes.destroy(); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
this.stop(); |
||||
this.nodes && this.nodes.destroy(); |
||||
BI.TreeView.superclass.destroy.apply(this, arguments); |
||||
} |
||||
}); |
||||
BI.extend(BI.TreeView, { |
||||
REQ_TYPE_INIT_DATA: 1, |
||||
REQ_TYPE_ADJUST_DATA: 2, |
||||
REQ_TYPE_CALCULATE_SELECT_DATA: 3, |
||||
REQ_TYPE_SELECTED_DATA: 4 |
||||
}); |
||||
|
||||
BI.TreeView.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
BI.TreeView.EVENT_INIT = BI.Events.INIT; |
||||
BI.TreeView.EVENT_AFTERINIT = BI.Events.AFTERINIT; |
||||
|
||||
$.shortcut("bi.tree", BI.TreeView); |
@ -0,0 +1,221 @@
|
||||
/** |
||||
* guy |
||||
* 同步树 |
||||
* @class BI.SyncTree |
||||
* @extends BI.TreeView |
||||
*/ |
||||
BI.SyncTree = BI.inherit(BI.TreeView, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SyncTree.superclass._defaultConfig.apply(this, arguments), {}) |
||||
}, |
||||
_init: function () { |
||||
BI.SyncTree.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
//配置属性
|
||||
_configSetting: function () { |
||||
var paras = this.options.paras; |
||||
var self = this; |
||||
var setting = { |
||||
async: { |
||||
enable: false, |
||||
otherParam: BI.cjkEncodeDO(paras) |
||||
}, |
||||
check: { |
||||
enable: true |
||||
}, |
||||
data: { |
||||
key: { |
||||
title: "title", |
||||
name: "text" |
||||
}, |
||||
simpleData: { |
||||
enable: true |
||||
} |
||||
}, |
||||
view: { |
||||
showIcon: false, |
||||
expandSpeed: "", |
||||
nameIsHTML: true, |
||||
dblClickExpand: false |
||||
}, |
||||
callback: { |
||||
beforeCheck: beforeCheck, |
||||
onCheck: onCheck, |
||||
beforeExpand: beforeExpand, |
||||
onExpand: onExpand, |
||||
onCollapse: onCollapse, |
||||
onClick: onClick |
||||
} |
||||
}; |
||||
|
||||
function onClick(event, treeId, treeNode) { |
||||
var zTree = $.fn.zTree.getZTreeObj(treeId); |
||||
zTree.checkNode(treeNode, !treeNode.checked, true, true); |
||||
} |
||||
|
||||
function beforeCheck(treeId, treeNode) { |
||||
treeNode.halfCheck = false; |
||||
if (treeNode.checked === true) { |
||||
//将展开的节点halfCheck设为false,解决展开节点存在halfCheck=true的情况 guy
|
||||
//所有的半选状态都需要取消halfCheck=true的情况
|
||||
function track(children) { |
||||
BI.each(children, function (i, ch) { |
||||
if (ch.halfCheck === true) { |
||||
ch.halfCheck = false; |
||||
track(ch.children); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
track(treeNode.children); |
||||
|
||||
var treeObj = $.fn.zTree.getZTreeObj(treeId); |
||||
var nodes = treeObj.getSelectedNodes(); |
||||
BI.each(nodes, function (index, node) { |
||||
node.halfCheck = false; |
||||
}) |
||||
} |
||||
} |
||||
|
||||
function beforeExpand(treeId, treeNode) { |
||||
self._expandNode(treeId, treeNode); |
||||
} |
||||
|
||||
function onCheck(event, treeId, treeNode) { |
||||
self._selectTreeNode(treeId, treeNode); |
||||
} |
||||
|
||||
function onExpand(event, treeId, treeNode) { |
||||
treeNode.halfCheck = false; |
||||
} |
||||
|
||||
function onCollapse(event, treeId, treeNode) { |
||||
treeNode.halfCheck = false; |
||||
} |
||||
|
||||
return setting; |
||||
}, |
||||
|
||||
_selectTreeNode: function (treeId, treeNode) { |
||||
var self = this, o = this.options; |
||||
var parent_values = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode)); |
||||
var name = this._getNodeValue(treeNode) |
||||
// var values = parent_values.concat([name]);
|
||||
if (treeNode.checked === true) { |
||||
} else { |
||||
var tNode = treeNode; |
||||
var pNode = this._getTree(this.selected_values, parent_values); |
||||
if (BI.isNotNull(pNode[name])) { |
||||
delete pNode[name]; |
||||
} |
||||
while (tNode != null && BI.isEmpty(pNode)) { |
||||
parent_values = parent_values.slice(0, parent_values.length - 1); |
||||
tNode = tNode.getParentNode(); |
||||
if (tNode != null) { |
||||
pNode = this._getTree(this.selected_values, parent_values); |
||||
name = this._getNodeValue(tNode); |
||||
delete pNode[name]; |
||||
} |
||||
} |
||||
} |
||||
BI.SyncTree.superclass._selectTreeNode.apply(self, arguments); |
||||
}, |
||||
|
||||
//展开节点
|
||||
_expandNode: function (treeId, treeNode) { |
||||
var self = this, o = this.options; |
||||
var parentValues = treeNode.parentValues || self._getParentValues(treeNode); |
||||
var op = BI.extend({}, o.paras, { |
||||
"id": treeNode.id, |
||||
"times": 1, |
||||
"parent_values": parentValues.concat(this._getNodeValue(treeNode)), |
||||
"check_state": treeNode.getCheckStatus() |
||||
}); |
||||
var complete = function (d) { |
||||
var nodes = d.items || []; |
||||
if (nodes.length > 0) { |
||||
callback(self._dealWidthNodes(nodes), !!d.hasNext); |
||||
} |
||||
}; |
||||
var times = 1; |
||||
|
||||
function callback(nodes, hasNext) { |
||||
self.nodes.addNodes(treeNode, nodes); |
||||
|
||||
if (hasNext === true) { |
||||
BI.delay(function () { |
||||
times++; |
||||
op.times = times; |
||||
o.itemsCreator(op, complete); |
||||
}, 100); |
||||
} |
||||
} |
||||
|
||||
if (!treeNode.children) { |
||||
o.itemsCreator(op, complete) |
||||
} |
||||
}, |
||||
|
||||
_joinTree: function (map, values, isLast) { |
||||
var cur = map; |
||||
BI.each(values, function (i, value) { |
||||
if (i > 0 && BI.isPlainObject(cur) && BI.isEmpty(cur)) { |
||||
return; |
||||
} |
||||
if (isLast === true && i === values.length - 1) { |
||||
cur[value] = {}; |
||||
return; |
||||
} |
||||
if (cur[value] == null) { |
||||
cur[value] = {}; |
||||
} |
||||
cur = cur[value]; |
||||
}) |
||||
}, |
||||
|
||||
_join: function (valueA, valueB) { |
||||
var self = this; |
||||
var hashMap = valueA || {}; |
||||
track([], valueB); |
||||
function track(parent, node) { |
||||
BI.each(node, function (n, item) { |
||||
var next = parent.concat([n]); |
||||
self._joinTree(hashMap, next, BI.isPlainObject(item) && BI.isEmpty(item)); |
||||
track(next, item); |
||||
}) |
||||
} |
||||
|
||||
return hashMap; |
||||
}, |
||||
|
||||
hasChecked: function () { |
||||
return !BI.isEmpty(this.selected_values) || BI.SyncTree.superclass.hasChecked.apply(this, arguments); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
if (!this.nodes) { |
||||
return {}; |
||||
} |
||||
var checkedValues = this._getSelectedValues(); |
||||
if (BI.isEmpty(checkedValues)) { |
||||
return this.selected_values; |
||||
} |
||||
if (BI.isEmpty(this.selected_values)) { |
||||
return checkedValues; |
||||
} |
||||
return this._join(checkedValues, this.selected_values); |
||||
}, |
||||
|
||||
//生成树方法
|
||||
stroke: function (config) { |
||||
delete this.options.keyword; |
||||
BI.extend(this.options.paras, config); |
||||
//取消选中时使用
|
||||
this.selected_values = BI.deepClone(this.options.paras.selected_values) || {}; |
||||
var setting = this._configSetting(); |
||||
this._initTree(setting); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.sync_tree", BI.SyncTree); |
@ -0,0 +1,175 @@
|
||||
/** |
||||
* guy |
||||
* 局部树,两个请求树, 第一个请求构造树,第二个请求获取节点 |
||||
* @class BI.PartTree |
||||
* @extends BI.SyncTree |
||||
*/ |
||||
BI.PartTree = BI.inherit(BI.SyncTree, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.PartTree.superclass._defaultConfig.apply(this, arguments), {}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.PartTree.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
_loadMore: function () { |
||||
var self = this, o = this.options; |
||||
var op = BI.extend({}, o.paras, { |
||||
type: BI.TreeView.REQ_TYPE_INIT_DATA, |
||||
times: ++this.times |
||||
}); |
||||
this.tip.setLoading(); |
||||
o.itemsCreator(op, function (d) { |
||||
var hasNext = !!d.hasNext, nodes = d.items || []; |
||||
o.paras.last_search_value = d.last_search_value; |
||||
if (self._stop === true) { |
||||
return; |
||||
} |
||||
if (!hasNext) { |
||||
self.tip.setEnd(); |
||||
} else { |
||||
self.tip.setLoaded(); |
||||
} |
||||
if (nodes.length > 0) { |
||||
self.nodes.addNodes(null, self._dealWidthNodes(nodes)); |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
_selectTreeNode: function (treeId, treeNode) { |
||||
var self = this, o = this.options; |
||||
var parent_values = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode)); |
||||
var name = this._getNodeValue(treeNode) |
||||
// var values = parent_values.concat([name]);
|
||||
if (treeNode.checked === true) { |
||||
BI.SyncTree.superclass._selectTreeNode.apply(self, arguments); |
||||
} else { |
||||
o.itemsCreator(BI.extend({}, o.paras, { |
||||
type: BI.TreeView.REQ_TYPE_CALCULATE_SELECT_DATA, |
||||
selected_values: this.selected_values, |
||||
not_selected_value: name, |
||||
parent_values: parent_values |
||||
}), function (new_values) { |
||||
if (BI.isEqual(self.selected_values, new_values)) { |
||||
var tNode = treeNode; |
||||
var pNode = self._getTree(new_values, parent_values); |
||||
if (pNode[name]) { |
||||
delete pNode[name]; |
||||
} |
||||
while (tNode != null && BI.isEmpty(pNode)) { |
||||
parent_values = parent_values.slice(0, parent_values.length - 1); |
||||
tNode = tNode.getParentNode(); |
||||
if (tNode != null) { |
||||
pNode = self._getTree(new_values, parent_values); |
||||
name = self._getNodeValue(tNode); |
||||
delete pNode[name]; |
||||
} |
||||
} |
||||
} |
||||
self.selected_values = new_values; |
||||
BI.SyncTree.superclass._selectTreeNode.apply(self, arguments); |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_getSelectedValues: function () { |
||||
var self = this; |
||||
var hashMap = {}; |
||||
var rootNoots = this.nodes.getNodes(); |
||||
track(rootNoots); |
||||
function track(nodes) { |
||||
BI.each(nodes, function (i, node) { |
||||
var checkState = node.getCheckStatus(); |
||||
if (checkState.checked === false) { |
||||
return true; |
||||
} |
||||
var parentValues = node.parentValues || self._getParentValues(node); |
||||
//把文字中的html去掉,其实就是把文字颜色去掉
|
||||
var values = parentValues.concat([self._getNodeValue(node)]); |
||||
self._buildTree(hashMap, values); |
||||
// if(checkState.checked === true && checkState.half === false && nodes[i].flag === true){
|
||||
// continue;
|
||||
// }
|
||||
if (BI.isNotEmptyArray(node.children)) { |
||||
track(node.children); |
||||
return true; |
||||
} |
||||
if (checkState.half === true) { |
||||
self._getHalfSelectedValues(hashMap, node); |
||||
} |
||||
}) |
||||
} |
||||
|
||||
return hashMap; |
||||
}, |
||||
|
||||
_initTree: function (setting, keyword) { |
||||
var self = this, o = this.options; |
||||
this.times = 1; |
||||
var tree = this.tree; |
||||
tree.empty(); |
||||
self.tip.setVisible(false); |
||||
this.loading(); |
||||
var op = BI.extend({}, o.paras, { |
||||
type: BI.TreeView.REQ_TYPE_INIT_DATA, |
||||
times: this.times |
||||
}); |
||||
var complete = function (d) { |
||||
if (self._stop === true || keyword != o.paras.keyword) { |
||||
return; |
||||
} |
||||
var hasNext = !!d.hasNext, nodes = d.items || []; |
||||
o.paras.last_search_value = d.last_search_value; |
||||
if (nodes.length > 0) { |
||||
callback(self._dealWidthNodes(nodes)); |
||||
} |
||||
self.setTipVisible(nodes.length <= 0); |
||||
self.loaded(); |
||||
if (!hasNext) { |
||||
self.tip.invisible(); |
||||
} else { |
||||
self.tip.setLoaded(); |
||||
} |
||||
self.fireEvent(BI.Events.AFTERINIT); |
||||
}; |
||||
|
||||
function callback(nodes) { |
||||
if (self._stop === true) { |
||||
return; |
||||
} |
||||
self.nodes = $.fn.zTree.init(tree.element, setting, nodes); |
||||
} |
||||
|
||||
BI.delay(function () { |
||||
o.itemsCreator(op, complete); |
||||
}, 100); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var o = this.options; |
||||
var result = BI.PartTree.superclass.getValue.apply(this, arguments); |
||||
o.itemsCreator({ |
||||
type: BI.TreeView.REQ_TYPE_ADJUST_DATA, |
||||
selected_values: result |
||||
}, function (res) { |
||||
result = res; |
||||
}); |
||||
return result; |
||||
}, |
||||
|
||||
//生成树方法
|
||||
stroke: function (config) { |
||||
var o = this.options; |
||||
delete o.paras.keyword; |
||||
BI.extend(o.paras, config); |
||||
delete o.paras.last_search_value; |
||||
//取消选中时使用
|
||||
this.selected_values = BI.deepClone(o.paras.selected_values) || {}; |
||||
//delete this.options.paras.selected_values;
|
||||
var setting = this._configSetting(); |
||||
this._initTree(setting, o.paras.keyword); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.part_tree", BI.PartTree); |
@ -0,0 +1,155 @@
|
||||
/** |
||||
* |
||||
* 自定义树 |
||||
* |
||||
* Created by GUY on 2015/9/7. |
||||
* @class BI.CustomTree |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.CustomTree = BI.inherit(BI.Widget, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.CustomTree.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-custom-tree", |
||||
expander: { |
||||
el: {}, |
||||
popup: { |
||||
type: "bi.custom_tree" |
||||
} |
||||
}, |
||||
|
||||
items: [], |
||||
itemsCreator: BI.emptyFn, |
||||
|
||||
el: { |
||||
type: "bi.button_tree", |
||||
chooseType: 0, |
||||
layouts: [{ |
||||
type: "bi.vertical" |
||||
}] |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.CustomTree.superclass._init.apply(this, arguments); |
||||
this.initTree(this.options.items); |
||||
}, |
||||
|
||||
setEnable: function (v) { |
||||
BI.CustomTree.superclass.setEnable.apply(this, arguments); |
||||
this.tree.setEnable(v) |
||||
}, |
||||
|
||||
_formatItems: function (nodes) { |
||||
var self = this, o = this.options; |
||||
nodes = BI.Tree.transformToTreeFormat(nodes); |
||||
|
||||
var items = []; |
||||
BI.each(nodes, function (i, node) { |
||||
if (BI.isNotEmptyArray(node.children) || node.isParent === true) { |
||||
var item = BI.extend({ |
||||
type: "bi.expander", |
||||
el: {}, |
||||
popup: {type: "bi.custom_tree"} |
||||
}, BI.deepClone(o.expander), { |
||||
id: node.id, |
||||
pId: node.pId, |
||||
value: node.value |
||||
}); |
||||
var el = BI.stripEL(node); |
||||
if (!BI.isWidget(el)) { |
||||
el = BI.clone(el); |
||||
delete el.children; |
||||
BI.extend(item.el, el); |
||||
} else { |
||||
item.el = el; |
||||
} |
||||
item.popup.expander = BI.deepClone(o.expander); |
||||
item.items = item.popup.items = node.children; |
||||
item.itemsCreator = item.popup.itemsCreator = function (op) { |
||||
if (BI.isNotNull(op.node)) {//从子节点传过来的itemsCreator直接向上传递
|
||||
return o.itemsCreator.apply(self, arguments); |
||||
} |
||||
var args = Array.prototype.slice.call(arguments, 0); |
||||
args[0].node = node; |
||||
return o.itemsCreator.apply(self, args); |
||||
}; |
||||
BI.isNull(item.popup.el) && (item.popup.el = BI.deepClone(o.el)); |
||||
items.push(item); |
||||
} else { |
||||
items.push(node); |
||||
} |
||||
}); |
||||
return items; |
||||
}, |
||||
|
||||
//构造树结构,
|
||||
initTree: function (nodes) { |
||||
var self = this, o = this.options; |
||||
this.tree = BI.createWidget(o.el, { |
||||
element: this.element, |
||||
items: this._formatItems(nodes), |
||||
itemsCreator: function (op, callback) { |
||||
o.itemsCreator.apply(this, [op, function (items) { |
||||
var args = Array.prototype.slice.call(arguments, 0); |
||||
args[0] = self._formatItems(items); |
||||
callback.apply(null, args); |
||||
}]); |
||||
} |
||||
}); |
||||
this.tree.on(BI.Controller.EVENT_CHANGE, function (type, val, obj) { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
if (type === BI.Events.CLICK) { |
||||
self.fireEvent(BI.CustomTree.EVENT_CHANGE, val, obj); |
||||
} |
||||
}) |
||||
}, |
||||
|
||||
//生成树方法
|
||||
stroke: function (nodes) { |
||||
this.populate.apply(this, arguments); |
||||
}, |
||||
|
||||
populate: function (nodes) { |
||||
var args = Array.prototype.slice.call(arguments, 0); |
||||
if (arguments.length > 0) { |
||||
args[0] = this._formatItems(nodes); |
||||
} |
||||
this.tree.populate.apply(this.tree, args); |
||||
}, |
||||
|
||||
doBehavior: function () { |
||||
this.tree.doBehavior.apply(this.tree, arguments); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.tree && this.tree.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.tree ? this.tree.getValue() : []; |
||||
}, |
||||
|
||||
getAllButtons: function () { |
||||
return this.tree ? this.tree.getAllButtons() : []; |
||||
}, |
||||
|
||||
getAllLeaves: function () { |
||||
return this.tree ? this.tree.getAllLeaves() : []; |
||||
}, |
||||
|
||||
getNodeById: function (id) { |
||||
return this.tree && this.tree.getNodeById(id); |
||||
}, |
||||
|
||||
getNodeByValue: function (id) { |
||||
return this.tree && this.tree.getNodeByValue(id); |
||||
}, |
||||
|
||||
empty: function () { |
||||
this.tree.empty(); |
||||
} |
||||
}); |
||||
BI.CustomTree.EVENT_CHANGE = "EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.custom_tree", BI.CustomTree); |
@ -0,0 +1,88 @@
|
||||
/** |
||||
* 可以改变图标的button |
||||
* |
||||
* Created by GUY on 2016/2/2. |
||||
* |
||||
* @class BI.IconChangeButton |
||||
* @extends BI.Single |
||||
*/ |
||||
BI.IconChangeButton = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
var conf = BI.IconChangeButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: "bi-icon-change-button", |
||||
iconClass: "", |
||||
iconWidth: null, |
||||
iconHeight: null, |
||||
|
||||
stopEvent: false, |
||||
stopPropagation: false, |
||||
selected: false, |
||||
once: false, //点击一次选中有效,再点无效
|
||||
forceSelected: false, //点击即选中, 选中了就不会被取消
|
||||
forceNotSelected: false, //无论怎么点击都不会被选中
|
||||
disableSelected: false, //使能选中
|
||||
|
||||
shadow: false, |
||||
isShadowShowingOnSelected: false, //选中状态下是否显示阴影
|
||||
trigger: null, |
||||
handler: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.IconChangeButton.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.button = BI.createWidget({ |
||||
type: "bi.icon_button", |
||||
element: this.element, |
||||
cls: o.iconClass, |
||||
height: o.height, |
||||
iconWidth: o.iconWidth, |
||||
iconHeight: o.iconHeight, |
||||
|
||||
stopEvent: o.stopEvent, |
||||
stopPropagation: o.stopPropagation, |
||||
selected: o.selected, |
||||
once: o.once, |
||||
forceSelected: o.forceSelected, |
||||
forceNotSelected: o.forceNotSelected, |
||||
disableSelected: o.disableSelected, |
||||
|
||||
shadow: o.shadow, |
||||
isShadowShowingOnSelected: o.isShadowShowingOnSelected, |
||||
trigger: o.trigger, |
||||
handler: o.handler |
||||
}); |
||||
|
||||
this.button.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.button.on(BI.IconButton.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.IconChangeButton.EVENT_CHANGE, arguments); |
||||
}); |
||||
}, |
||||
|
||||
isSelected: function () { |
||||
return this.button.isSelected(); |
||||
}, |
||||
|
||||
setSelected: function (b) { |
||||
this.button.setSelected(b); |
||||
}, |
||||
|
||||
setIcon: function (cls) { |
||||
var o = this.options; |
||||
if (o.iconClass !== cls) { |
||||
this.element.removeClass(o.iconClass).addClass(cls); |
||||
o.iconClass = cls; |
||||
} |
||||
}, |
||||
|
||||
setEnable: function (b) { |
||||
BI.IconChangeButton.superclass.setEnable.apply(this, arguments); |
||||
this.button.setEnable(b); |
||||
} |
||||
}); |
||||
BI.IconChangeButton.EVENT_CHANGE = "IconChangeButton.EVENT_CHANGE"; |
||||
$.shortcut("bi.icon_change_button", BI.IconChangeButton); |
@ -0,0 +1,32 @@
|
||||
/** |
||||
* guy |
||||
* @extends BI.Single |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.HalfIconButton = BI.inherit(BI.IconButton, { |
||||
_defaultConfig: function() { |
||||
var conf = BI.HalfIconButton.superclass._defaultConfig.apply(this,arguments); |
||||
return BI.extend(conf, { |
||||
extraCls: "bi-half-icon-button check-half-select-icon", |
||||
height: 16, |
||||
width: 16, |
||||
iconWidth: 16, |
||||
iconHeight: 16, |
||||
selected: false |
||||
}) |
||||
}, |
||||
|
||||
_init : function() { |
||||
BI.HalfIconButton.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.HalfIconButton.superclass.doClick.apply(this, arguments); |
||||
if(this.isValid()){ |
||||
this.fireEvent(BI.HalfIconButton.EVENT_CHANGE); |
||||
} |
||||
} |
||||
}); |
||||
BI.HalfIconButton.EVENT_CHANGE = "HalfIconButton.EVENT_CHANGE"; |
||||
|
||||
$.shortcut("bi.half_icon_button", BI.HalfIconButton); |
@ -0,0 +1,30 @@
|
||||
/** |
||||
* 统一的trigger图标按钮 |
||||
* |
||||
* Created by GUY on 2015/9/16. |
||||
* @class BI.TriggerIconButton |
||||
* @extends BI.IconButton |
||||
*/ |
||||
BI.TriggerIconButton = BI.inherit(BI.IconButton, { |
||||
|
||||
_defaultConfig: function () { |
||||
var conf = BI.TriggerIconButton.superclass._defaultConfig.apply(this, arguments); |
||||
return BI.extend(conf, { |
||||
baseCls: (conf.baseCls || "") + " bi-trigger-icon-button", |
||||
extraCls: "pull-down-font" |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.TriggerIconButton.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.TriggerIconButton.superclass.doClick.apply(this, arguments); |
||||
if (this.isValid()) { |
||||
this.fireEvent(BI.TriggerIconButton.EVENT_CHANGE, this); |
||||
} |
||||
} |
||||
}); |
||||
BI.TriggerIconButton.EVENT_CHANGE = "TriggerIconButton.EVENT_CHANGE"; |
||||
$.shortcut("bi.trigger_icon_button", BI.TriggerIconButton); |
@ -0,0 +1,72 @@
|
||||
/** |
||||
* guy |
||||
* 复选框item |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.MultiSelectItem = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function() { |
||||
return BI.extend(BI.MultiSelectItem.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-multi-select-item", |
||||
height: 25, |
||||
logic: { |
||||
dynamic: false |
||||
} |
||||
}) |
||||
}, |
||||
_init : function() { |
||||
BI.MultiSelectItem.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.checkbox = BI.createWidget({ |
||||
type: "bi.checkbox" |
||||
}); |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
whiteSpace: "nowrap", |
||||
textHeight: o.height, |
||||
height: o.height, |
||||
hgap: o.hgap, |
||||
rgap: o.rgap, |
||||
text: o.text, |
||||
keyword: o.keyword, |
||||
value: o.value, |
||||
py: o.py |
||||
}); |
||||
this.checkbox.on(BI.Controller.EVENT_CHANGE, function(type){ |
||||
if(type === BI.Events.CLICK) { |
||||
self.setSelected(self.isSelected()); |
||||
} |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", { |
||||
type: "bi.center_adapt", |
||||
items: [this.checkbox], |
||||
width: 36 |
||||
} ,this.text) |
||||
})))); |
||||
}, |
||||
|
||||
doRedMark: function(){ |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function(){ |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doClick: function(){ |
||||
BI.MultiSelectItem.superclass.doClick.apply(this, arguments); |
||||
this.checkbox.setSelected(this.isSelected()); |
||||
}, |
||||
|
||||
setSelected: function(v){ |
||||
BI.MultiSelectItem.superclass.setSelected.apply(this, arguments); |
||||
this.checkbox.setSelected(v); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.multi_select_item", BI.MultiSelectItem); |
@ -0,0 +1,59 @@
|
||||
/** |
||||
* Created by GUY on 2016/2/2. |
||||
* |
||||
* @class BI.SingleSelectIconTextItem |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.SingleSelectIconTextItem = BI.inherit(BI.Single, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectIconTextItem.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-single-select-icon-text-item bi-list-item-active", |
||||
iconClass: "", |
||||
hgap: 10, |
||||
height: 25 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.SingleSelectIconTextItem.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.icon_text_item", |
||||
element: this.element, |
||||
cls: o.iconClass, |
||||
once: o.once, |
||||
selected: o.selected, |
||||
height: o.height, |
||||
iconHeight: o.iconHeight, |
||||
iconWidth: o.iconWidth, |
||||
text: o.text, |
||||
keyword: o.keyword, |
||||
value: o.value, |
||||
py: o.py |
||||
}); |
||||
this.text.on(BI.Controller.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
}, |
||||
|
||||
isSelected: function () { |
||||
return this.text.isSelected(); |
||||
}, |
||||
|
||||
setSelected: function (b) { |
||||
this.text.setSelected(b); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.SingleSelectIconTextItem.superclass.doClick.apply(this, arguments); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.single_select_icon_text_item", BI.SingleSelectIconTextItem); |
@ -0,0 +1,49 @@
|
||||
/** |
||||
* guy |
||||
* 复选框item |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.SingleSelectItem = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectItem.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-single-select-item bi-list-item-active", |
||||
hgap: 10, |
||||
height: 25 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.SingleSelectItem.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
element: this.element, |
||||
textAlign: "left", |
||||
whiteSpace: "nowrap", |
||||
textHeight: o.height, |
||||
height: o.height, |
||||
hgap: o.hgap, |
||||
text: o.text, |
||||
keyword: o.keyword, |
||||
value: o.value, |
||||
py: o.py |
||||
}); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.SingleSelectItem.superclass.doClick.apply(this, arguments); |
||||
}, |
||||
|
||||
setSelected: function (v) { |
||||
BI.SingleSelectItem.superclass.setSelected.apply(this, arguments); |
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.single_select_item", BI.SingleSelectItem); |
@ -0,0 +1,74 @@
|
||||
/** |
||||
* guy |
||||
* 单选框item |
||||
* @type {*|void|Object} |
||||
*/ |
||||
BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.SingleSelectRadioItem.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-single-select-radio-item bi-list-item-active", |
||||
logic: { |
||||
dynamic: false |
||||
}, |
||||
hgap: 10, |
||||
height: 25 |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.SingleSelectRadioItem.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.radio = BI.createWidget({ |
||||
type: "bi.radio" |
||||
}); |
||||
this.radio.on(BI.Controller.EVENT_CHANGE, function (type) { |
||||
if (type === BI.Events.CLICK) { |
||||
self.setSelected(!self.isSelected()); |
||||
} |
||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
||||
}); |
||||
this.text = BI.createWidget({ |
||||
type: "bi.label", |
||||
cls: "list-item-text", |
||||
textAlign: "left", |
||||
whiteSpace: "nowrap", |
||||
textHeight: o.height, |
||||
height: o.height, |
||||
hgap: o.hgap, |
||||
text: o.text, |
||||
keyword: o.keyword, |
||||
value: o.value, |
||||
py: o.py |
||||
}); |
||||
|
||||
BI.createWidget(BI.extend({ |
||||
element: this.element |
||||
}, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { |
||||
items: BI.LogicFactory.createLogicItemsByDirection("left", { |
||||
type: "bi.center_adapt", |
||||
items: [this.radio], |
||||
width: 36 |
||||
}, this.text) |
||||
})))); |
||||
}, |
||||
|
||||
doRedMark: function () { |
||||
this.text.doRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
unRedMark: function () { |
||||
this.text.unRedMark.apply(this.text, arguments); |
||||
}, |
||||
|
||||
doClick: function () { |
||||
BI.SingleSelectRadioItem.superclass.doClick.apply(this, arguments); |
||||
this.radio.setSelected(this.isSelected()); |
||||
}, |
||||
|
||||
setSelected: function (v) { |
||||
BI.SingleSelectRadioItem.superclass.setSelected.apply(this, arguments); |
||||
this.radio.setSelected(v); |
||||
|
||||
} |
||||
}); |
||||
|
||||
$.shortcut("bi.single_select_radio_item", BI.SingleSelectRadioItem); |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue