Commit ac913656 by Huang Linyu

add KitJS for datapicker that can use key shift for multi-select

parent 78234e75
Showing with 5043 additions and 17 deletions
<#assign pageJsContent> <#assign pageJsContent>
<!-- <script src="${staticServer}/js/app/weekday_checkbox.js"></script> --> <!-- <script src="${staticServer}/js/app/weekday_checkbox.js"></script> -->
<link rel="stylesheet" href="${staticServer}/js/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css">
<script src="${staticServer}/js/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="${staticServer}/js/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script> <script src="http://www.google-analytics.com/ga.js"></script>
<script src="${staticServer}/KitJS/js/kit.js"></script>
<!--widget-->
<script src="${staticServer}/KitJS/js/array.js"></script>
<script src="${staticServer}/KitJS/js/date.js"></script>
<script src="${staticServer}/KitJS/js/dom.js"></script>
<script src="${staticServer}/KitJS/js/selector.js"></script>
<script src="${staticServer}/KitJS/js/widget/DatePicker/datepicker.js"></script>
<link rel="stylesheet" href="${staticServer}/KitJS/css/widget/DatePicker/datepicker.css" />
<script> <script>
$('.datepicker').datepicker({ //日期连续选择
language: 'zh-CN', $kit.$(function() {
multidate: true, $kit.ev({
daysOfWeekHighlighted:'06', el : '#theDate',
todayHighlight:true, ev : 'focus',
weekStart:0 fn : function(e) {
var d;
d = e.target[$kit.ui.DatePicker.defaultConfig.kitWidgetName];
if(d) {
d.show();
} else {
var params = {
dateFormat : 'yyyy-mm-dd', //接受和输出的日期格式
language : 'cn',//本地化语言
show : false, //默认是否显示
canMultipleChoose : true, //能否多选
dateStringSeparator : ',', //多选时候输出分隔符
shiftSelectOutType : 'full', //多选时候输出类型,full为将选中的日期全部输出,short为输出选中日期的开头和结尾
shiftSelectOutTypeShortSeparator : '~'//当输出类型为short时,比如选中了3月1日到3月10日,则输出"3月1日~3月10日",简短输出,只有开头+分隔符+结尾
};
d = new $kit.ui.DatePicker(params).init();
d.adhere($kit.el('#theDate'));
d.show();
}
}
});
$kit.ev({
el : document,
ev : 'click',
fn : function(e) {
var input = $kit.el('#theDate');
d = input[$kit.ui.DatePicker.defaultConfig.kitWidgetName];
if(d && !$kit.contains(d.picker, e.target) && input != e.target) {
d.hide();
}
}
});
}); });
</script> </script>
</#assign> </#assign>
<@com.layout title="库存设置" module="product" current="resource_create" pageJs=pageJsContent> <@com.layout title="库存设置" module="product" current="resource_create" pageJs=pageJsContent>
......
<#assign pageJsContent> <#assign pageJsContent>
<!--<script src="${staticServer}/js/app/weekday_checkbox.js"></script> --> <!--<script src="${staticServer}/js/app/weekday_checkbox.js"></script> -->
<!--
<link rel="stylesheet" href="${staticServer}/js/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css"> <link rel="stylesheet" href="${staticServer}/js/bootstrap-datepicker/dist/css/bootstrap-datepicker3.min.css">
<script src="${staticServer}/js/bootstrap-datepicker/js/bootstrap-datepicker.js"></script> <script src="${staticServer}/js/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="${staticServer}/js/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script> <script src="${staticServer}/js/bootstrap-datepicker/js/locales/bootstrap-datepicker.zh-CN.js"></script>
<link rel="stylesheet" href="${staticServer}/KitJS/css/widget/DatePicker/datepicker.css" />
-->
<script src="http://www.google-analytics.com/ga.js"></script>
<script src="${staticServer}/KitJS/js/kit.js"></script>
<!--widget-->
<script src="${staticServer}/KitJS/js/array.js"></script>
<script src="${staticServer}/KitJS/js/date.js"></script>
<script src="${staticServer}/KitJS/js/dom.js"></script>
<script src="${staticServer}/KitJS/js/selector.js"></script>
<script src="${staticServer}/KitJS/js/widget/DatePicker/datepicker.js"></script>
<link rel="stylesheet" href="${staticServer}/KitJS/css/widget/DatePicker/datepicker.css" />
<script>
//日期连续选择
$kit.$(function() {
$kit.ev({
el : '#theDate',
ev : 'focus',
fn : function(e) {
var d;
d = e.target[$kit.ui.DatePicker.defaultConfig.kitWidgetName];
if(d) {
d.show();
} else {
var params = {
dateFormat : 'yyyy-mm-dd', //接受和输出的日期格式
language : 'cn',//本地化语言
show : false, //默认是否显示
canMultipleChoose : true, //能否多选
dateStringSeparator : ',', //多选时候输出分隔符
shiftSelectOutType : 'full', //多选时候输出类型,full为将选中的日期全部输出,short为输出选中日期的开头和结尾
shiftSelectOutTypeShortSeparator : '~'//当输出类型为short时,比如选中了3月1日到3月10日,则输出"3月1日~3月10日",简短输出,只有开头+分隔符+结尾
};
d = new $kit.ui.DatePicker(params).init();
d.adhere($kit.el('#theDate'));
d.show();
}
}
});
$kit.ev({
el : document,
ev : 'click',
fn : function(e) {
var input = $kit.el('#theDate');
d = input[$kit.ui.DatePicker.defaultConfig.kitWidgetName];
if(d && !$kit.contains(d.picker, e.target) && input != e.target) {
d.hide();
}
}
});
});
</script>
<script> <script>
$(function () { $(function () {
...@@ -30,13 +86,8 @@ $(function () { ...@@ -30,13 +86,8 @@ $(function () {
}); });
$('.datepicker').datepicker({
language: 'zh-CN',
multidate: true,
daysOfWeekHighlighted:'06',
todayHighlight:true,
weekStart:0
});
</script> </script>
</#assign> </#assign>
......
.kitjs-form-button {
width: auto;
height: auto;
-webkit-appearance: none;
border: 1px solid #ddd;
outline: none;
color: #111;
text-shadow: 0 1px 1px #fff;
cursor: pointer;
border: 1px solid #ccc;
padding: 0.5em 1em;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);/*去除android高亮框*/
background-color: #eee;
border-radius: 1em;/*圆角*/
-webkit-transition: all 300ms ease-in 0;/*渐变动画 */
background-image: -webkit-gradient(linear, left top, left 25, from(#fdfdfd), to(#eee));
background-image: -moz-linear-gradient(top, #fdfdfd 0, #eee 50%);
box-shadow: 0 1px 4px rgba(0,0,0,.3)
text-shadow: 0 1px 0 white;
}
.kitjs-form-button:hover {
border: 1px solid #808080;
}
.kitjs-form-button:active {
border: 1px solid #808080;
background-color: #fdfdfd;
background-image: -webkit-gradient(linear, left top, left 25, from(#eee), to(#fdfdfd));
background-image: -moz-linear-gradient(top, #eee 0, #fdfdfd 50%);
}
.kitjs-form-button.selected {
border: 1px solid #144F71;
background-color: #2567AB;
color: #fff;
background-image: -webkit-gradient(linear, left top, left 25, from(#5F9CC5), to(#396B9E));
background-image: -moz-linear-gradient(top, #5F9CC5 0, #396B9E 50%);
text-shadow: 0 -1px 1px #145072;
}
\ No newline at end of file
.kitjs-form-checkbox {
cursor: pointer;
-webkit-appearance: none;
position: relative;
outline: none;
vertical-align: middle;
line-height: 1em;
height: 1em;
width: 1em;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
margin: 0;
border: 1px solid #ccc;
background: none;
-webkit-transition: box-shadow 300ms ease-in 0;
}
.kitjs-form-checkbox:hover, .kitjs-form-checkbox:active {
border-color: #aaa;
box-shadow: 0 0 10px #aaa;
}
.kitjs-form-checkbox:checked {
background-color: #aaa;
border-color: #aaa;
box-shadow: inset 0px 0px 0px 2px white;
}
.kitjs-form-combox-wrapper {
position: relative;
display: inline-block;
*display: inline;
*zoom: 1;
}
.kitjs-form-combox-wrapper.suggesting .kitjs-form-combobox-input {
background: url("/KitJs/KitJs/src/img/loading.gif") right no-repeat;
}
\ No newline at end of file
.kitjs-form-fieldset {
border: 1px solid #ccc;
border-radius: 0.5em;
background: none;
-webkit-transition: box-shadow 300ms ease-in 0;
}
.kitjs-form-fieldset:active,
.kitjs-form-fieldset:hover,
.kitjs-form-fieldset:focus {
border-color: #aaa;
box-shadow: 0 0 10px #aaa;
}
.kitjs-form-fieldset legend {
color: #ccc;
background-color: #fff;
-webkit-transition: all 300ms ease-in 0;
}
.kitjs-form-fieldset:active legend,
.kitjs-form-fieldset:hover legend,
.kitjs-form-fieldset:focus legend {
color: #000;
}
\ No newline at end of file
@import url(button.css);
@import url(textbox.css);
@import url(checkbox.css);
@import url(radio.css);
@import url(select.css);
@import url(textarea.css);
@import url(fieldset.css);
@import url(combobox.css);
@import url(suggestselect.css);
@import url(list.css);
\ No newline at end of file
.kitjs-form-list {
z-index: 99999;
background-color: #fff;
list-style: none;
display: block;
position: absolute;
top: 100%;
width: 100%;
_width: 250px;
left: 0px;
border: 1px solid #ccc;
line-height: 30px;
font-size: 14px;
box-shadow: 0 0 10px rgba(0,0,0,0.2);
padding: 2px;
max-height: 200px;
_height: expression(eval(this.offsetHeight>200?200:this.offsetHeight));
*display: inline;
*zoom: 1;
overflow: auto;
cursor: pointer;
}
.kitjs-form-list .kitjs-form-listItem {
padding: 0 5px;
*zoom: 1;
_width: 222px;
}
.kitjs-form-list .kitjs-form-listItem-odd {
background-color: #f8f8f8;
}
.kitjs-form-list .kitjs-form-listItem-even {
background-color: #fff;
}
.kitjs-form-list .selected {
background-color: #576b9c;
color: #fff;
font-weight: bold;
}
.kitjs-form-list .selected b {
color: orange;
}
.kitjs-form-list-loading {
height: 30px;
line-height: 30px;
color: #000;
text-align: center;
}
.kitjs-form-list-loading i {
display: inline-block;
background: url("/KitJs/KitJs/src/img/loading.gif");
width: 15px;
height: 15px;
}
.kitjs-form-list-error {
color: red;
text-align: center;
height: 30px;
line-height: 30px;
}
.kitjs-form-listItem {
vertical-align: baseline;
}
.kitjs-form-listItem b {
vertical-align: baseline;
color: red;
}
.kitjs-form-radio {
cursor: pointer;
-webkit-appearance: none;
position: relative;
outline: none;
vertical-align: middle;
line-height: 1em;
height: 1em;
width: 1em;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
margin: 0;
border-radius: 1em;
border: 1px solid #ccc;
background: none;
-webkit-transition: box-shadow 300ms ease-in 0;
}
.kitjs-form-radio:hover, .kitjs-form-radio:active {
border-color: #aaa;
box-shadow: 0 0 10px #aaa;
}
.kitjs-form-radio:checked {
background-color: #aaa;
border-color: #aaa;
box-shadow: inset 0px 0px 0px 2px white;
}
/*
* select外围wrap
*/
.kitjs-form-select {
padding: 0;
margin: 0;
cursor: pointer;
position: relative;
vertical-align: middle;
border-radius: .3em;
-webkit-transition: box-shadow 300ms ease-in 0;/*渐变动画 */
background-image: -webkit-gradient(linear, left top, left 25, from(#fff), color-stop(10%, #eee), to(#fff));/*渐变背景*/
}
.kitjs-form-select select {
padding: 0;
margin: 0;
outline: none;
cursor: pointer;
font-size: 16px;
border: 1px solid #ddd;
border-radius: .3em;/*圆角*/
position: relative;
background: none;
padding-right: 1.5em;/*给右边按钮留出距离*/
line-height: 1em;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);/*去掉android高亮框*/
outline: none;
z-index: 1;
vertical-align: baseline;
-webkit-transition: all 300ms ease-in 0;
}
.kitjs-form-select select:hover, .kitjs-form-select select:active, .kitjs-form-select select:focus {
color: #000;
outline: none;
border-color: #aaa;
box-shadow: 0 0 10px #aaa;
}
/**
* select箭头
*/
.kitjs-form-select:after {
z-index: 0;
content: ' ';
display: block;
position: absolute;
width: 0px;
height: 0px;
right: 0.3em;
top: 0.4em;
border-width: 8px;
border-style: dashed;
border-color: transparent;
border-top-style: solid;
border-top-color: #ccc;
-webkit-transform: scaleX(0.8);
}
/**
* select箭头在鼠标hover时高亮
*/
.kitjs-form-select:hover:after, .kitjs-form-select:active:after {
border-top-color: #000;
}
\ No newline at end of file
.kitjs-form-suggestselect-wrapper {
position: relative;
display: inline-block;
*display: inline;
*zoom: 1;
}
.kitjs-form-suggestselect-wrapper.suggesting .kitjs-form-suggestselect-input {
background: url("/KitJs/KitJs/src/img/loading.gif") right no-repeat;
}
\ No newline at end of file
.kitjs-form-textarea {
width: auto;
height: auto;
-webkit-appearance: none;
border: 1px solid #ddd;
outline: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);/*去除android高亮框*/
border-radius: .3em;/*圆角*/
-webkit-transition: box-shadow 300ms ease-in 0;/*渐变动画 */
background-image: -webkit-gradient(linear, left top, left 25, from(#fff), color-stop(3%, #eee), to(#fff));/*渐变背景*/
}
.kitjs-form-textarea:focus {
color: #000;
outline: none;
border-color: #aaa;/*获得焦点边框颜色*/
box-shadow: 0 0 10px #aaa;/*获得焦点光晕*/
}
\ No newline at end of file
.kitjs-form-textbox {
width: auto;
height: auto;
-webkit-appearance: none;
border: 1px solid #ddd;
outline: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);/*去除android高亮框*/
border-radius: .3em;/*圆角*/
-webkit-transition: box-shadow 300ms ease-in 0;/*渐变动画 */
background-image: -webkit-gradient(linear, left top, left 25, from(#fff), color-stop(3%, #eee), to(#fff));/*渐变背景*/
}
.kitjs-form-textbox:focus {
color: #000;
outline: none;
border-color: #aaa;/*获得焦点边框颜色*/
box-shadow: 0 0 10px #aaa;/*获得焦点光晕*/
}
\ No newline at end of file
.kitjs_audio audio {
position: absolute;
left: -1px;
}
.kitjs_audio {
width: 980px;
height: 40px;
display: block;
background: url(audio-controls.png) no-repeat 0 -118px;
font-family: monospace;
font-size: 12px;
box-shadow: 1px 1px 15px rgba(0, 0, 0, 0.8);
-webkit-transition: all 500ms ease-out 0ms;
-moz-transition: all 500ms ease-out 0ms;
transition: all 500ms ease-out 0ms;
}
.kitjs_audio .play-pause {
width: 30px;
height: 30px;
margin: 5px 16px 0 20px;
float: left;
overflow: hidden;
}
.kitjs_audio p {
display: none;
width: 30px;
height: 30px;
margin: 0px;
cursor: pointer;
}
.kitjs_audio .play {
display: block;
}
.kitjs_audio .scrubber {
position: relative;
float: left;
width: 866px;
height: 17px;
margin-top: 12px;
cursor: pointer;
background: url(audio-controls.png) no-repeat 0 -226px;
}
.kitjs_audio .progress {
position: absolute;
top: 0px;
left: 0px;
height: 17px;
z-index: 1;
}
.kitjs_audio .progress i.time-icon {
display: block;
cursor: pointer;
width: 17px;
height: 17px;
position: absolute;
right: -9px;
top: 0px;
overflow: hidden;
background: url(audio-controls.png) no-repeat -107px -3px;
}
.kitjs_audio .loaded {
position: absolute;
top: 0px;
left: 0px;
height: 17px;
width: 0px;
background: url(audio-controls.png) no-repeat 0 -186px;
}
.kitjs_audio .time {
position: absolute;
right: -60px;
text-align: center;
top: -54px;
width: 120px;
color: #fff;
line-height: 33px;
height: 50px;
background: url(audio-controls.png) no-repeat -226px 0;
opacity: 0;
display: none;
-webkit-transition: all 500ms ease-out 0ms;
-moz-transition: all 500ms ease-out 0ms;
transition: all 500ms ease-out 0ms;
}
.kitjs_audio .time em {
padding: 0px 2px 0px 0px;
color: #f9f9f9;
font-style: normal;
}
.kitjs_audio .time strong {
padding: 0px 0px 0px 2px;
font-weight: normal;
color: #fff;
}
.kitjs_audio .error-message {
float: left;
display: none;
margin: 0px 10px;
height: 36px;
width: 400px;
overflow: hidden;
line-height: 36px;
white-space: nowrap;
color: #fff;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-icab-text-overflow: ellipsis;
-khtml-text-overflow: ellipsis;
-moz-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
}
.kitjs_audio .error-message a {
color: #eee;
text-decoration: none;
padding-bottom: 1px;
border-bottom: 1px solid #999;
white-space: wrap;
}
.kitjs_audio .play {
background: url(audio-controls.png) -43px 5px no-repeat;
}
.kitjs_audio .play:hover {
background-position: -43px -28px;
}
.kitjs_audio .play:active {
background-position: -43px -65px;
}
.kitjs_audio .loading {
display: block;
}
.kitjs_audio .error {
}
.kitjs_audio .pause {
background: url(audio-controls.png) 6px 5px no-repeat;
}
.kitjs_audio .pause:hover {
background-position: 6px -28px;
}
.kitjs_audio .pause:active {
background-position: 6px -65px;
}
.kitjs_audio.playing .pause {
display: block;
}
.kitjs_audio.loading .play, .loading .pause, .loading .error {
display: none;
}
.kitjs_audio.loading .loading {
display: block;
background: url(loading.gif) no-repeat 7px 7px;
}
.kitjs_audio.error .time, .error .play, .error .pause, .error .scrubber, .error .loading {
display: none;
}
.kitjs_audio.error .error {
display: block;
}
.kitjs_audio.error .play-pause p {
cursor: auto;
}
.kitjs_audio.error .error-message {
display: block;
}
.kitjs_audio.playing {
opacity: 0.5;
filter: alpha(opacity=50);
}
.kitjs_audio.playing:hover {
opacity: 1;
filter: alpha(opacity=100);
}
.kitjs_audio .time-hover {
opacity: 1;
display: block;
}
.kitjs_audio.playing .time {
opacity: 1;
display: block;
}
.kitjs_audio.playing .play, .playing .loading, .playing .error {
display: none;
}
\ No newline at end of file
.datepicker {
padding: 4px;
display: inline-block;
*display: inline;
*zoom: 1;
padding: 1px;
margin-top: 1px;
color: #333;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 13px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
/*.dow {
border-top: 1px solid #ddd !important;
}*/
}
.datepicker:before {
content: '';
display: inline-block;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #ccc;
border-bottom-color: rgba(0, 0, 0, 0.2);
position: absolute;
top: -7px;
left: 6px;
}
.datepicker:after {
content: '';
display: inline-block;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid #ffffff;
position: absolute;
top: -6px;
left: 7px;
}
.datepicker > div {
display: none;
}
.datepicker.days div.datepicker-days {
display: block;
}
.datepicker.months div.datepicker-months {
display: block;
}
.datepicker.years div.datepicker-years {
display: block;
}
.datepicker table {
margin: 0;
}
.datepicker td,
.datepicker th {
text-align: center;
width: 20px;
height: 20px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.datepicker td.day:hover {
background: #eeeeee;
cursor: pointer;
}
.datepicker td.old,
.datepicker td.new {
color: #999999;
}
.datepicker td.disabled,
.datepicker td.disabled:hover {
background: none;
color: #ddd;
cursor: default;
}
.datepicker td.active,
.datepicker td.active:hover,
.datepicker td.active.disabled,
.datepicker td.active.disabled:hover {
background-color: #006dcc;
background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
background-image: -o-linear-gradient(top, #0088cc, #0044cc);
background-image: linear-gradient(top, #0088cc, #0044cc);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
border-color: #0044cc #0044cc #002a80;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:dximagetransform.microsoft.gradient(enabled=false);
color: #fff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.datepicker td.active:hover,
.datepicker td.active:hover:hover,
.datepicker td.active.disabled:hover,
.datepicker td.active.disabled:hover:hover,
.datepicker td.active:active,
.datepicker td.active:hover:active,
.datepicker td.active.disabled:active,
.datepicker td.active.disabled:hover:active,
.datepicker td.active.active,
.datepicker td.active:hover.active,
.datepicker td.active.disabled.active,
.datepicker td.active.disabled:hover.active,
.datepicker td.active.disabled,
.datepicker td.active:hover.disabled,
.datepicker td.active.disabled.disabled,
.datepicker td.active.disabled:hover.disabled,
.datepicker td.active[disabled],
.datepicker td.active:hover[disabled],
.datepicker td.active.disabled[disabled],
.datepicker td.active.disabled:hover[disabled] {
background-color: #0044cc;
}
.datepicker td.active:active,
.datepicker td.active:hover:active,
.datepicker td.active.disabled:active,
.datepicker td.active.disabled:hover:active,
.datepicker td.active.active,
.datepicker td.active:hover.active,
.datepicker td.active.disabled.active,
.datepicker td.active.disabled:hover.active {
background-color: #003399 \9;
}
.datepicker td span {
display: block;
width: 25%;
height: 54px;
line-height: 54px;
float: left;
cursor: pointer;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
.datepicker td span:hover {
background: #eeeeee;
}
.datepicker td span.disabled,
.datepicker td span.disabled:hover {
background: none;
color: #999999;
cursor: default;
}
.datepicker td span.active,
.datepicker td span.active:hover,
.datepicker td span.active.disabled,
.datepicker td span.active.disabled:hover {
background-color: #006dcc;
background-image: -moz-linear-gradient(top, #0088cc, #0044cc);
background-image: -ms-linear-gradient(top, #0088cc, #0044cc);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#0088cc), to(#0044cc));
background-image: -webkit-linear-gradient(top, #0088cc, #0044cc);
background-image: -o-linear-gradient(top, #0088cc, #0044cc);
background-image: linear-gradient(top, #0088cc, #0044cc);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0088cc', endColorstr='#0044cc', GradientType=0);
border-color: #0044cc #0044cc #002a80;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
filter: progid:dximagetransform.microsoft.gradient(enabled=false);
color: #fff;
text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.datepicker td span.active:hover,
.datepicker td span.active:hover:hover,
.datepicker td span.active.disabled:hover,
.datepicker td span.active.disabled:hover:hover,
.datepicker td span.active:active,
.datepicker td span.active:hover:active,
.datepicker td span.active.disabled:active,
.datepicker td span.active.disabled:hover:active,
.datepicker td span.active.active,
.datepicker td span.active:hover.active,
.datepicker td span.active.disabled.active,
.datepicker td span.active.disabled:hover.active,
.datepicker td span.active.disabled,
.datepicker td span.active:hover.disabled,
.datepicker td span.active.disabled.disabled,
.datepicker td span.active.disabled:hover.disabled,
.datepicker td span.active[disabled],
.datepicker td span.active:hover[disabled],
.datepicker td span.active.disabled[disabled],
.datepicker td span.active.disabled:hover[disabled] {
background-color: #0044cc;
}
.datepicker td span.active:active,
.datepicker td span.active:hover:active,
.datepicker td span.active.disabled:active,
.datepicker td span.active.disabled:hover:active,
.datepicker td span.active.active,
.datepicker td span.active:hover.active,
.datepicker td span.active.disabled.active,
.datepicker td span.active.disabled:hover.active {
background-color: #003399 \9;
}
.datepicker td span.old {
color: #999999;
}
.datepicker th.switch {
width: 145px;
}
.datepicker thead tr:first-child th {
cursor: pointer;
}
.datepicker thead tr:first-child th:hover {
background: #eeeeee;
}
.datepicker thead tr:first-child th:active {
background: #e3e3e3;
}
.input-append.date .add-on i,
.input-prepend.date .add-on i {
display: block;
cursor: pointer;
width: 16px;
height: 16px;
}
.dropdown-menu {
position: relative;
z-index: 1000;
padding: 4px 0;
margin: 0;
list-style: none;
background-color: white;
border-color: #CCC;
border-color: rgba(0, 0, 0, 0.2);
border-style: solid;
border-width: 1px;
border-radius: 4px;
-webkit-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-moz-box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.2);
-webkit-background-clip: padding-box;
-moz-background-clip: padding;
background-clip: padding-box;
}
.datepicker-months tbody td {
position: relative;
*zoom: 1;
}
.dropdown-menu::before {
content: '';
display: inline-block;
border-left: 7px solid transparent;
border-right: 7px solid transparent;
border-bottom: 7px solid #CCC;
border-bottom-color: rgba(0, 0, 0, 0.2);
position: absolute;
top: -7px;
left: 6px;
}
.dropdown-menu::after {
content: '';
display: inline-block;
border-left: 6px solid transparent;
border-right: 6px solid transparent;
border-bottom: 6px solid white;
position: absolute;
top: -6px;
left: 7px;
}
i.icon-arrow-left,
i.icon-arrow-right {
font-weight: bold;
font-family: Black;
font-style: normal;
cursor: pointer;
}
.datepicker-days table {
display: inline-block;
*display: inline;
*zoom: 1;
}
.kitjs-dialog {
display: inline-block;
*zoom: 1;
*width: 300px;
border-radius: 10px;
padding: 10px;
background-color: rgba(200,200,200,0.5);
position: absolute;
top: 40px;
left: 40px;
z-index: 999999;
min-width: 300px;
box-shadow: 0 0 5px rgba(200,200,200,0.5);
}
.kitjs-dialog-title {
*width: 300px;
padding: 5px;
cursor: move;
height: 25px;
border: 1px solid #ccc;
border: 1px solid rgba(200,200,200,0.5);
border-bottom: 0;
background-color: #C9D6ED;
background: -webkit-gradient(linear, 0 0, 0 bottom, from(#DEE5F1), to(#C9D6ED));
}
.kitjs-dialog-panel {
*width: 300px;
padding: 5px;
border: 1px solid #ccc;
border: 1px solid rgba(200,200,200,0.5);
border-top: 0;
min-height: 50px;
background-color: #fff;
}
a.kitjs-dialog-close-btn {
position: absolute;
right: 17px;
top: 16px;
z-index: 9999;
height: 20px;
width: 20px;
border: 2px solid #fff;
cursor: pointer;
border-radius: 20px;
font-size: 10px;
text-align: center;
vertical-align: baseline;
line-height: 20px;
text-indent: -1px;
background-color: #ccc;
color: #fff;
font-family: black;
text-decoration: none;
font-weight: bold;
font-style: normal;
opacity: 0.5;
overflow: hidden;
-webkit-transition: all 300ms ease-in 0ms;
}
a.kitjs-dialog-close-btn:hover {
opacity: 1;
background-color: #000;
}
.kitjs-dialog-confirm-text {
padding: 10px;
font-weight: bold;
}
.kitjs-dialog-confirm-buttons {
text-align: right;
}
.kitjs-dialog-confirm-buttons a {
background-color: whiteSmoke;
border: 1px solid #DEDEDE;
border-top: 1px solid #EEE;
border-left: 1px solid #EEE;
cursor: pointer;
font-size: 100%;
line-height: 130%;
color: #ccc;
font-weight: bold;
cursor: pointer;
padding: 0 10px;
margin-left: 10px;
opacity: 0.7;
-webkit-transition: all 300ms ease-out 0ms;
-moz-transition: all 300ms ease-out 0ms;
transition: all 300ms ease-out 0ms;
display: inline-block;
*display: inline;
*zoom: 1;
}
.kitjs-dialog-confirm-buttons a.confirm-yes {
background: url(../../../img/tick.png) no-repeat 10px 2px;
background-color: whiteSmoke;
padding: 0px 10px 0 30px;
cursor: pointer;
color: #529214;
}
.kitjs-dialog-confirm-buttons a.confirm-yes:hover {
background-color: #E6EFC2;
border: 1px solid #C6D880;
color: #529214;
}
.kitjs-dialog-confirm-buttons a.confirm-yes:active {
background-color: #529214;
border-color: #529214;
color: #fff;
}
.kitjs-dialog-confirm-buttons a.confirm-no {
background: url(../../../img/cross.png) no-repeat 10px 2px;
background-color: whiteSmoke;
padding: 0px 10px 0 30px;
cursor: pointer;
color: #D12F19;
}
.kitjs-dialog-confirm-buttons a.confirm-no:hover {
background-color: #FBE3E4;
border: 1px solid #FBC2C4;
color: #D12F19;
}
.kitjs-dialog-confirm-buttons a.confirm-no:active {
background-color: #D12F19;
border: 1px solid #D12F19;
color: white;
}
.kitjs-dialog-confirm-buttons a.confirm-cancel:hover {
background-color: #DFF4FF;
border: 1px solid #C2E1EF;
color: #369;
}
.kitjs-dialog-confirm-buttons a.confirm-cancel:active {
background-color: #6299C5;
border: 1px solid #6299C5;
color: white;
}
.kitjs-gallery-wrapper .kitjs-gallery-item-list {
margin: 0 auto;
width: 310px;
*width: 9999px;
width: 9999px\0;
height: 173px;
display: block;
position: static;
*position: absolute;
position: absolute\0;
-webkit-transform-style: preserve-3d;
-moz-transform-style: preserve-3d;
-o-transform-style: preserve-3d;
-ms-transform-style: preserve-3d;
transform-style: preserve-3d;
-webkit-perspective: 1000px;
-moz-perspective: 1000px;
-o-perspective: 1000px;
-ms-perspective: 1000px;
perspective: 1000px;
}
.kitjs-gallery {
text-align: center;
overflow: visible;
*overflow: hidden;
overflow: hidden\0;
}
.kitjs-gallery-wrapper li {
float: none;
display: block;
position: absolute;
*position: static;
position: static\0;
*float: left;
float: left\0;
top: 0;
left: 0;
-webkit-transition: all 500ms ease-out 0ms;
-moz-transition: all 500ms ease-out 0ms;
transition: all 500ms ease-out 0ms;
opacity: 0;
}
li.kitjs-gallery-item-selected {
-webkit-transform: translateX(0px) translateZ(0px) rotateY(0deg);
-moz-transform: translateX(0px) translateZ(0px) rotateY(0deg);
transform: translateX(0px) translateZ(0px) rotateY(0deg);
opacity: 1;
}
li.kitjs-gallery-item-previous {
-webkit-transform: translateX(-350px) translateZ(-200px) rotateY(45deg);
-moz-transform: translateX(-350px) translateZ(-200px) rotateY(45deg);
transform: translateX(-350px) translateZ(-200px) rotateY(45deg);
opacity: 0.75;
}
li.kitjs-gallery-item-next {
-webkit-transform: translateX(350px) translateZ(-200px) rotateY(-45deg);
-moz-transform: translateX(350px) translateZ(-200px) rotateY(-45deg);
transform: translateX(350px) translateZ(-200px) rotateY(-45deg);
opacity: 0.75;
}
.kitjs-gallery-control-panel {
margin-top: 20px;
}
.kitjs-gallery-wrapper li {
box-shadow: 0px 10px 20px rgba(0,0,0,0.3);
-moz-box-shadow: none;
}
\ No newline at end of file
.kitjs-gallery-wrapper ul,
.kitjs-gallery-wrapper li {
list-style: none;
margin: 0;
padding: 0;
}
.kitjs-gallery-wrapper {
}
.kitjs-gallery-item-list {
width: 9999px;
position: absolute;
top: 0;
left: 0;
height: 173px;
}
.kitjs-gallery {
position: relative;
width: 936px;
height: 174px;
overflow: hidden;
}
.kitjs-gallery-wrapper li {
float: left;
font-size: 0;
padding: 4px;
border: 2px solid transparent;
opacity: 1;
-webkit-transition: all 500ms ease-out 0ms;
-moz-transition: all 500ms ease-out 0ms;
transition: all 500ms ease-out 0ms;
}
.kitjs-gallery-wrapper li img {
border: 0;
width: 300px;
margin: 0;
}
li.kitjs-gallery-item-selected {
border-color: #000;
}
li.kitjs-gallery-item-previous {
}
li.kitjs-gallery-item-next {
}
.kitjs-gallery-control-panel {
text-align: center;
}
.kitjs-gallery-btn-prev,
.kitjs-gallery-btn-next {
width: auto;
height: auto;
-webkit-appearance: none;
border: 1px solid #ddd;
outline: none;
color: #111;
text-shadow: 0 1px 1px #fff;
cursor: pointer;
border: 1px solid #ccc;
padding: 0.5em 1em;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);/*去除android高亮框*/
background-color: #eee;
border-radius: 1em;/*圆角*/
-webkit-transition: all 300ms ease-in 0;/*渐变动画 */
background-image: -webkit-gradient(linear, left top, left 25, from(#fdfdfd), to(#eee));
background-image: -moz-linear-gradient(top,#fdfdfd 0,#eee 50%);
box-shadow: 0 1px 4px rgba(0,0,0,.3)
text-shadow: 0 1px 0 white;
}
.kitjs-gallery-btn-prev:hover,
.kitjs-gallery-btn-next:hover {
border: 1px solid #808080;
}
.kitjs-gallery-btn-prev:active,
.kitjs-gallery-btn-next:active {
border: 1px solid #808080;
background-color: #fdfdfd;
background-image: -webkit-gradient(linear, left top, left 25, from(#eee), to(#fdfdfd));
background-image: -moz-linear-gradient(top,#eee 0,#fdfdfd 50%);
}
.kitjs-gallery-btn-disabled {
color: #ccc;
cursor: pointer;
-webkit-transition: none;
}
.kitjs-gallery-btn-disabled:hover,
.kitjs-gallery-btn-disabled:active {
border: 1px solid #ddd;
background-color: #eee;
background-image: -webkit-gradient(linear, left top, left 25, from(#fdfdfd), to(#eee));
background-image: -moz-linear-gradient(top,#fdfdfd 0,#eee 50%);
}
.kitLightBox-showImageContainer {
border: 10px solid #fff;
border-radius: 5px;
background-color: #fff;
margin: 0;
padding: 0;
position: relative;
padding: 10px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
border: 0;
*border: 1px solid #000;
border: 1px solid #000\0/;
}
.kitLightBox-showImage-imageBox {
margin: 0;
padding: 0;
position: relative;
overflow: hidden;
}
.kitLightBox-showImage-imageBox image {
border: 0;
postion: absolute;
top: 0;
left: 0;
}
.kitLightBox-completeShow {
}
.kitLightBox-closeButton {
display: none;
width: 30px;
height: 30px;
background: url(/KitJs/KitJs/src/img/close.png) no-repeat 0 0;
position: absolute;
right: -20px;
top: -20px;
cursor: pointer;
}
.kitLightBox-completeShow .kitLightBox-closeButton {
display: block;
}
.tag-wrapper {
display: block;
width: 500px;
}
.tag-input {
border: 0;
height: 18px;
display: inline-block;
*display: inline;
*zoom: 1;
margin: 5px 0 5px 0;
border-bottom: 1px solid #ccc;
outline: 0;
font-size: 14px;
line-height: 18px;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
.tag-wrapper .tag {
position: relative;
display: inline-block;
*display: inline;
*zoom: 1;
margin: 5px 16px 5px 0;
height: 18px;
border: 1px solid #939cc3;
border-radius: 1em;
font-family: Arail;
line-height: 16px;
font-size: 14px;
padding: 0 1em;
padding-right: 2em;
color: #6a7299;
background-image: -webkit-gradient(linear, 0 0,0 100%, from(#dbe6fa), to(#bbcff4));
background-image: -moz-linear-gradient(top, #dbe6fa 0, #bbcff4 100%);
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dbe6fa' ,endColorstr='#bbcff4');
-webkit-transition: all 300ms ease-out 0ms;
-moz-transition: all 300ms ease-out 0ms;
transition: all 300ms ease-out 0ms;
}
/*
.tag-wrapper .tag:hover {
color: #fff;
border-color: #4273cf;
background-image: -webkit-gradient(linear, 0 0,0 100%, from(#4c8aff), to(#3164fd));
background-image: -moz-linear-gradient(top, #4c8aff 0, #3164fd 100%)!important;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#4c8aff' ,endColodstr='#3164fd');
}
*/
.tag-wrapper .close-btn {
height: 12px;
width: 12px;
display: block;
position: absolute;
top: 3px;
right: 9px;
text-align: center;
line-height: 9px;
font-style: normal;
font-family: Arail;
text-decoration: none;
background-color: #ccc;
color: #fff;
border-radius: 12px;
cursor: pointer;
font-size: 12px;
}
.tag-wrapper .close-btn:hover {
background-color: red;
}
.taginput-wrapper {
position: relative;
}
#kitjs-float-tips {
width: 300px;
padding: 12px 0;
background: #2C6FCE;
color: white;
position: fixed;
top: 50%;
left: 50%;
margin-left: -150px;
margin-top: -20px;
z-index: 99999;
text-align: center;
vertical-align: middle;
box-shadow: 0 0 10px #2c6fce;
}
#kitjs-float-tips s {
display: inline-block;
width: 16px;
height: 16px;
vertical-align: middle;
top: 12px;
left: 12px;
margin-right: 10px;
background: url(http://xueduany.github.com/Ciku/img/media/loading.gif) no-repeat;
}
\ No newline at end of file
/**
* 保留插入顺序的HashMap
* @class LinkedHashMap
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/LinkedHashMap.js">Source code</a>
*/
var LinkedHashMap = function() {
this.array = [];
this.map = {};
}
LinkedHashMap.prototype = {
constructor : LinkedHashMap,
/**
* 判断是否存在
* @param {Object}
* @param {Object}
* @return {Boolean}
*/
hs : function(key, value) {
var key = key || null, value = value || null, me = this;
if(key == null) {
if(value != null) {
for(var p in me.map) {
if(me.map[p] == value) {
return true;
}
}
}
} else {
if( key in me.map) {
return true;
}
}
return false;
},
/**
* 添加
* @param {Object}
* @param {Object}
*/
ad : function(key, value) {
var value = value || null;
var key = key || null;
var me = this;
if(key == null) {
return;
}
if( key in me.map) {
me.map[key] = value;
} else {
me.array.push(key);
me.map[key] = value;
}
},
/**
* 删除
* @param {Object}
*/
rm : function(key) {
var key = key || null;
var me = this;
if( key in me.map) {
delete me.map[key];
for(var i = 0; i < me.array.length; i++) {
if(me.array[i] == key) {
me.array.splice(i, 1);
break;
}
}
}
},
/**
* 从第一个删到找到的key
* @param {Object}
*/
rmTill : function(key) {
var me = this, delIndex = -1;
for(var i = 0; i < me.array.length; i++) {
if(me.array[i] == key) {
delIndex = i;
break;
}
}
if(delIndex > -1) {
for(var i = 0; i <= delIndex; i++) {
delete me.map[me.array[i]];
}
me.array.splice(0, delIndex + 1);
}
},
/**
* 从找到的key开始,删除到结尾
* @param {Object}
*/
rmFrom : function(key) {
var me = this;
for(var i = 0; i < me.array.length; i++) {
if(me.array[i] == key) {
delIndex = i;
break;
}
}
if(delIndex > -1) {
for(var i = delIndex; i < me.array.length; i++) {
delete me.map[me.array[i]];
}
me.array.splice(delIndex, me.array.length - delIndex);
}
},
/**
* 长度
* @return {Number}
*/
size : function() {
return this.array.length;
},
/**
* 遍历
* @param {Function}
* @param {Object}
*/
each : function(fn, scope) {
var me = this;
var scope = scope || window;
var fn = fn || null;
if(fn == null || typeof (fn) != "function") {
return;
}
for(var i = 0; i < me.array.length; i++) {
var key = me.array[i];
var value = me.map[key];
var re = fn.call(scope, key, value, i, me.array, me.map);
if(re == false) {
break;
}
}
},
/**
* get
* @param {Object}
* @return {Object}
*/
get : function(key) {
return this.map[key];
},
/**
* 排序
* @param {Function}
* @return {Object}
*/
sort : function(compare) {
var me = this;
me.array.sort(compare);
}
};
/**
* @class $kit.SortMap
* @extends LinkedHashMap
*/
$kit.SortMap = $kit.LinkedHashMap = LinkedHashMap;
/**
* 树状字典,加速下拉菜单读取速度
* @class TreeDict
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/TreeDict.js">Source code</a>
* @modify
* 2012/04/09
* 清明休假想到的,如果遇到“北京”和“北京市”,这两个作为key存入字典,时,按照现在的逻辑,北京市会把北京盖掉,
* 现在改为对于同前缀的key,加入结束标记作为区分,这样时间存在字典里面的是"北京endSing"和北京市endSign,这样就可以区分开了
*/
var TreeDict = function(config) {
var me = this;
me.config = $kit.join(arguments.callee.defaultConfig, config);
me.size = 0;
me.deep = me.config.deep;
me.data = {};
}
/**
* @member
* @enum
*/
TreeDict.defaultConfig = {
deep : 10, //嵌套深度,此参数影响词典内存对象大小,也影响search索引性能
data : undefined,
endSign : '$end$'//避免"北京"作为key被"北京市"覆盖掉,现引用结束标记概念,以区别ab和abc这样的字符
}
TreeDict.prototype = {
constructor : TreeDict,
/**
* 判断是否存在
* @param {String}
* @return {Boolean}
*/
hs : function(key) {
var key = key || null, me = this;
if(key == null) {
var beginIndex = 0, recurDeep = 0, //
lookfor = me.data, index, lastLookfor, find;
while(beginIndex < key.length) {
if(recurDeep < me.deep - 1) {
index = key.substring(beginIndex, beginIndex + 1);
find = lookfor[index];
} else {
index = key.substring(beginIndex);
find = lookfor[index];
}
if($kit.isEmpty(find)) {
return false;
} else {
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
return true;
}
}
lookfor = find;
beginIndex++;
recurDeep++;
}
return false;
}
},
/**
* 添加
* @param {String}
* @param {String}
*/
ad : function(key, value) {
var value = value || null;
var key = key || null;
var me = this;
if(key == null || value == null) {
return;
}
var beginIndex = 0, recurDeep = 0, //
lookfor = me.data, index, lastLookfor, find;
while(beginIndex < key.length) {
if(recurDeep < me.deep - 1) {
index = key.substring(beginIndex, beginIndex + 1);
find = lookfor[index];
} else {
index = key.substring(beginIndex);
find = lookfor[index];
}
if($kit.isEmpty(find)) {//如果找不到key了
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
lookfor[index] = {};
lookfor[index][me.config.endSign] = value;
find = lookfor[index];
} else {
find = lookfor[index] = {};
}
} else {
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
find[me.config.endSign] = value;
}
}
lookfor = find;
beginIndex++;
recurDeep++;
}
},
/**
* 删除
* @param {String}
*/
rm : function(key) {
var key = key || null;
var me = this;
if(key == null) {
return;
}
var beginIndex = 0, recurDeep = 0, //
lookfor = me.data, index, lastLookfor, find;
while(beginIndex < key.length) {
if(recurDeep < me.deep - 1) {
index = key.substring(beginIndex, beginIndex + 1);
find = lookfor[index];
} else {
index = key.substring(beginIndex);
find = lookfor[index];
}
if($kit.isEmpty(find)) {
return false;
} else {
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
delete lookfor[index][me.config.endSign];
//有没别的索引,没有就斩草除根!!!
var deleteIndex = false;
for(var p in lookfor[index]) {
deleteIndex = true;
break;
}
if(deleteIndex) {
delete lookfor[index];
}
}
}
lookfor = find;
beginIndex++;
recurDeep++;
}
},
/**
* 存放数据总数
* @return {Number}
*/
size : function() {
this.size = this.count(0, this.data);
return this.size;
},
count : function(size, o) {
var me = this;
size = size || 0;
for(var p in o) {
if(o[p][me.config.endSign]) {
size++;
} else {
size += this.count(size, o[p]);
}
}
return size;
},
/**
* 从字典中取出符合key的value值
* @param {String}
* @return {String}
*/
get : function(key) {
var value = value || null;
var key = key || null;
var me = this;
if(key == null) {
return;
}
var beginIndex = 0, recurDeep = 0, //
lookfor = me.data, index, lastLookfor, find;
while(beginIndex < key.length) {
if(recurDeep < me.deep - 1) {
index = key.substring(beginIndex, beginIndex + 1);
find = lookfor[index];
} else {
index = key.substring(beginIndex);
find = lookfor[index];
}
if($kit.isEmpty(find)) {//如果找不到key了
return null;
} else {
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
return find[me.config.endSign];
}
}
lookfor = find;
beginIndex++;
recurDeep++;
}
return null;
},
/**
* 按首字符匹配原则查询,返回
* [{key: 'key', value: 'value'}, {key: 'key', value: 'value'}]格式数组
* @param {String}
* @return {Array}
*/
search : function(key) {
var value = value || null;
var key = key || null;
var me = this;
if(key == null || key == '') {
var re = [];
me.travel(me.data, re);
return re;
}
var beginIndex = 0, recurDeep = 0, //
lookfor = me.data, index, lastLookfor, find;
var keyArray = [];
while(beginIndex < key.length) {
if(recurDeep < me.deep - 1) {
index = key.substring(beginIndex, beginIndex + 1);
find = lookfor[index];
} else {
index = key.substring(beginIndex);
find = lookfor[index];
}
if($kit.isEmpty(find)) {//如果找不到key了
return null;
} else {
keyArray.push(index);
if(beginIndex == key.length - 1 || recurDeep == me.deep - 1) {
break;
}
}
lookfor = find;
beginIndex++;
recurDeep++;
}
var re = [];
var beginData;
beginData = me.data[keyArray[0]];
for(var i = 1; i < keyArray.length; i++) {
beginData = beginData[keyArray[i]];
}
me.travel(beginData, re, keyArray.join(''));
return re;
},
/**
* @private
*/
travel : function(tree, array, key, currentKey) {
var me = this;
if(tree == null) {
return;
}
key = key || '';
array = array || [];
if(tree[me.config.endSign]) {
array.push({
key : key,
value : tree[me.config.endSign]
});
}
for(var k in tree) {
if(k != me.config.endSign) {
me.travel(tree[k], array, key + k, k);
}
}
}
};
/**
* @class $kit.TreeDict
* @extends TreeDict
*/
$kit.TreeDict = TreeDict;
/**
* 数组扩展
* @class $Kit.Array
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/array.js">Source code</a>
*/
$Kit.Array = function(config) {
//
}
$Kit.Array.prototype =
/**
* lends $Kit.Array.prototype
*/
{
/**
* 从小到大排序
* @param {Number}
* @param {Number}
* @return {Array}
* @private
*/
SORT_ASC : function(left, right) {
return left - right;
},
/**
* 从大到小排序
* @param {Number}
* @param {Number}
* @return {Array}
* @private
*/
SORT_DESC : function(left, right) {
return right - left;
},
/**
* 判断是否存在
* @param {Array}
* @param {Object}
* @param {Object} config
* @param {Boolean} config.ignoreCase 判断是否相等时候,是否忽略大小写
* @return {Boolean}
*/
hs : function(ary, check, setting) {
var me = this;
if(!$kit.isAry(ary)) {
return;
}
var defaultSetting = {
ignoreCase : false
}
var setting = $kit.merge(defaultSetting, setting);
for(var i = 0; i < ary.length; i++) {
var o = ary[i];
if(o == check//
|| (setting.ignoreCase && o.toString().toLowerCase() == check.toString().toLowerCase())) {
return true;
}
}
return false;
},
/**
* 向数组中添加元素
* @param {Array}
* @param {Object|Array}
* @param {Object} config
* @param {Boolean} config.ifExisted 为true时候,则进行存在判断,存在则不加,为false,直接第一个数组冗余相加
* @param {Boolean} config.ignoreCase 判断是否相等时候,是否忽略大小写
*/
ad : function(ary, add, setting) {
var me = this;
if(!$kit.isAry(ary)) {
return;
}
var defaultSetting = {
ifExisted : false,
ignoreCase : false
}
var setting = $kit.merge(defaultSetting, setting);
if($kit.isAry(add)) {
for(var i = 0; i < add.length; i++) {
me.ad(ary, add[i], setting);
}
} else {
if(setting.ifExisted && ary.length > 0) {
for(var i = 0; i < ary.length; i++) {
var o = ary[i];
if(o == add//
|| (setting.ignoreCase && o.toString().toLowerCase() == add.toString().toLowerCase())) {
break;
} else if(i == ary.length - 1) {
ary.push(add);
}
}
} else {
ary.push(add);
}
}
},
/**
* 数组删除元素
* @param {Array}
* @param {Object|Array}
* @param {Object} config
* @param {Boolean} config.ignoreCase 判断是否相等时候,是否忽略大小写
* @param {Boolean} config.isGlobal 是否全局检查,不仅仅删除第一个发现的
*/
rm : function(ary, del, setting) {
var me = this;
if(!$kit.isAry(ary)) {
return;
}
var defaultSetting = {
ignoreCase : false,
isGlobal : true
}
var setting = $kit.merge(defaultSetting, setting);
if($kit.isAry(del)) {
for(var i = 0; i < del.length; i++) {
me.rm(ary, del[i], setting);
}
} else {
for(var i = 0; i < ary.length; i++) {
var o = ary[i];
if(o == del//
|| (setting.ignoreCase && o.toString().toLowerCase() == del.toString().toLowerCase())) {
ary.splice(i, 1);
if(setting.isGlobal) {
continue;
} else {
break;
}
}
}
}
},
/**
* 排序
* @param {Array}
* @param {String} param 排序类型,目前支持ASC从小到大,DESC从大到小两种类型
* @rettun {Array} 返回被排序的数组
*/
sort : function(ary, param) {
var me = this;
if($kit.isEmpty(ary) || $kit.isEmpty(param)) {
return;
}
if($kit.isFn(param)) {
return ary.sort(param);
} else {
switch (param) {
case "ASC" :
return ary.sort(me.SORT_ASC);
case "DESC" :
return ary.sort(me.SORT_DESC);
}
}
},
/**
* 通过比较方法取得值
* @param {Array}
* @param {Function} validateFn 遍历数组,执行该方法,等方法返回true时候,获得数组中对应值。方法传入三个参数,当前元素,当前元素索引,数组
* @param {Object} [scope] 执行方法时候的this指针
* @return {Object}
*/
get : function(ary, validateFn, scope) {
var scope = scope || window;
for(var i = 0; i < ary.length; i++) {
if(validateFn.call(scope, ary[i], i, ary) == true) {
return ary[i];
}
}
},
/**
* 遍历数组,获得数组中元素以xxx文字开头的
* @param {Array}
* @param {String}
* @return {Object}
*/
getTextBeginWith : function(ary, beginWithText) {
var me = this;
return me.get(ary, function(o) {
if(o.indexOf(beginWithText) == 0) {
return true;
}
});
},
/**
* 把字符串按照分隔符转换成数组
* @param {String}
* @param {String} [separate] 默认值为','
* @return {Array}
*/
parse : function(str, separate) {
var separate = ',' || separate;
return (str && str.split(separate)) || [str]
},
/**
* 过滤满足条件的数组元素
* @param {Array}
* @param {Function} 方法传入三个参数,当前元素,当前元素索引,数组
* @return {Array}
*/
filter : function(ary, compare) {
var re = [];
$kit.each(ary, function(o, i, ary) {
if(compare(o, i, ary)) {
re.push(o);
}
});
return re;
},
/**
* 返回指定元素在数组的第几个,从0开始
* @param {Array}
* @param {Object}
* @return {Number}
*/
indexOf : function(ary, obj) {
var index = -1;
if(obj != null) {
$kit.each(ary, function(o, idx) {
if(obj == o) {
index = idx;
return false;
}
});
}
return index;
},
/**
* 克隆一个新的数组
* @param {Array}
* @param {Array}
*/
clone : function(ary) {
var re = [];
$kit.each(ary, function(o) {
re.push(o);
});
return re;
},
/**
* 删除数组中空的元素
* @param {Array}
* @return {Array}
*/
delEmpty : function(ary) {
for(var i = 0; i < ary.length; ) {
if(ary[i] == '' || ary[i] == null) {
ary.splice(i, 1);
} else {
i++;
}
}
return ary;
},
/**
* 删除重复元素,不保证顺序
* @param {Array}
* @return {Array}
*/
rmRepeat : function(ary) {
var tmp = {}, re = [];
$kit.each(ary, function(o) {
tmp[o] = 1;
});
for(var o in tmp) {
re.push(o);
}
return re;
}
};
/**
* $Kit.Array实例,直接通过这个实例访问$Kit.Array所有方法
* @global
* @type $Kit.Array
* @name $kit.array
* @alias $kit.ary
*/
$kit.ary = $kit.array = new $Kit.Array();
/**
* Cookie扩展
* @class $Kit.Cookie
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/cookie.js">Source code</a>
*/
$Kit.Cookie = function(config) {
//
}
$kit.merge($Kit.Cookie.prototype,
/**
* @lends $Kit.Cookie.prototype
*/
{
/**
* 获取cookie值
* @param {String}
* @return {Object|Null}
*/
get : function(key) {
// Still not sure that "[a-zA-Z0-9.()=|%/_]+($|;)" match *all* allowed characters in cookies
tmp = document.cookie.match((new RegExp(key + '=[a-zA-Z0-9.()=|%/_]+($|;)', 'g')));
if(!tmp || !tmp[0]) {
return null;
} else {
return unescape(tmp[0].substring(key.length + 1, tmp[0].length).replace(';', '')) || null;
}
},
/**
* 塞cookie,塞多了你不怕肚子疼?
* @param {String} 存cookie里面的key
* @param {String} 保存值
* @param {Number} ttl 存活时间(hours)
* @param {String} [path] 影响的路径Path in which the cookie is effective, default is "/" (optional)
* @param {String} [domain] Domain where the cookie is effective, default is window.location.host (optional)
* @param {String} [secure] Use SSL or not, default false (optional)
*/
set : function(key, value, ttl, path, domain, secure) {
cookie = [key + '=' + escape(value), 'path=' + ((!path || path == '') ? '/' : path), 'domain=' + ((!domain || domain == '') ? window.location.host : domain)];
if(ttl) {
cookie.push(Cookie.hoursToExpireDate(ttl));
}
if(secure) {
cookie.push('secure');
}
return document.cookie = cookie.join('; ');
},
/**
* 删除
* @param {String} key The token that will be used to retrieve the cookie
* @param {String} path Path used to create the cookie (optional)
* @param {String} domain Domain used to create the cookie, default is null (optional)
*/
rm : function(key, path, domain) {
path = (!path || typeof path != 'string') ? '' : path;
domain = (!domain || typeof domain != 'string') ? '' : domain;
if(Cookie.get(key)) {
Cookie.set(key, '', 'Thu, 01-Jan-70 00:00:01 GMT', path, domain);
}
},
/**
* Return GTM date string of "now" + time to live
* @param {Number} ttl Time To Live (hours)
* @return {String}
*/
hoursToExpireDate : function(ttl) {
if(parseInt(ttl) == 'NaN') {
return '';
} else {
now = new Date();
now.setTime(now.getTime() + (parseInt(ttl) * 60 * 60 * 1000));
return now.toGMTString();
}
},
/**
* Return true if cookie functionnalities are available
* @return {Boolean}
*/
test : function() {
Cookie.set('b49f729efde9b2578ea9f00563d06e57', 'true');
if(Cookie.get('b49f729efde9b2578ea9f00563d06e57') == 'true') {
Cookie.unset('b49f729efde9b2578ea9f00563d06e57');
return true;
}
return false;
},
/**
* If Firebug JavaScript console is present, it will dump cookie string to console.
*/
dump : function() {
if( typeof console != 'undefined') {
console.log(document.cookie.split(';'));
}
}
});
/**
* $Kit.Cookie实例,直接通过这个实例访问$Kit.Cookie所有方法
* @global
* @type $Kit.Cookie
*/
$kit.cookie = new $Kit.Cookie();
/**
* ajax
* @class $Kit.IO
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/ajax.js">Source code</a>
*/
$Kit.IO = function() {
//
}
$kit.merge($Kit.IO.prototype,
/**
* @lends $Kit.IO.prototype
*/
{
/**
* ajax
* @param {Object} config
* @param {String} config.url
* @param {Object} [config.params] {key:value}格式
* @param {Stirng} [config.method] get或者post或者delete或者...,默认get
* @param {Boolean} [config.async] 是否异步,默认true,异步
* @param {Object} [config.head] requestHead {key:value}格式
* @param {Obejct} [config.body] {key:value}格式
* @param {Function} [config.onProgress] 处理中回调,bigpipe
* @param {Function} [config.onSuccess] 成功回调
* @param {Function} [config.onError] 错误回调
* @param {Function} [config.onOvertime] 超时回调
* @param {Number} [config.overtime] 默认3000,单位毫秒
* @param {Function} [config.readyStateChangeFn] ready状态回调
*/
ajax : function(config) {
var me = this;
var xmlhttp = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
var defaultConfig = {
url : undefined,
params : undefined,
method : 'GET',
async : true,
head : undefined,
body : null,
onProgress : undefined,
onSuccess : undefined,
onError : undefined,
onOvertime : undefined,
overtime : 3000,
readyStateChangeFn : function() {
if(xmlhttp.readyState == 3) {
clearTimeout(xmlhttp.timeoutOvertime);
config.onProgress && config.onProgress(xmlhttp, xmlhttp.responseText, xmlhttp);
//
if($kit.isFn(config.onError)) {
xmlhttp.timeoutOvertime = setTimeout(function() {
config.onError.call(xmlhttp, xmlhttp.responseText, xmlhttp);
}, config.overtime);
}
} else if(xmlhttp.readyState == 4) {
clearTimeout(xmlhttp.timeoutOvertime);
if(xmlhttp.status == '200') {
config.onSuccess && config.onSuccess.call(xmlhttp, xmlhttp.responseText, xmlhttp);
} else if(/^\d{3}$/.test(xmlhttp.status)) {
if(/^[45]\d{2}$/.test(xmlhttp.status)) {
config.onError && config.onError.call(xmlhttp, xmlhttp.responseText, xmlhttp);
}
}
//
var methodName = 'onHTTP' + xmlhttp.status;
config[methodName] && config[methodName].call(xmlhttp, xmlhttp.responseText, xmlhttp);
}
}
}
$kit.mergeIf(config, defaultConfig);
//
if(config.head) {
for(var k in config.head) {
var v = config.head[k];
xmlhttp.setRequestHeader(k, v);
}
}
var url = config.url;
if(!$kit.isEmpty(config.params)) {
if(config.url.indexOf('?') == config.url.length - 1) {
url += $kit.concat(config.params, '&', '=');
} else {
url += '?' + $kit.concat(config.params);
}
}
var body = $kit.concat(config.body, '&', '=');
//
xmlhttp.open(config.method, url, config.async);
xmlhttp.onreadystatechange = config.readyStateChangeFn;
xmlhttp.send(config.body);
//
if($kit.isFn(config.onOvertime)) {
xmlhttp.timeoutOvertime = setTimeout(function() {
config.onOvertime.call(xmlhttp, xmlhttp);
}, config.overtime);
}
},
/**
* get
* @param {Object} config
* @param {String} config.url
* @param {Object} [config.params] {key:value}格式
* @param {Boolean} [config.async] 是否异步,默认true,异步
* @param {Function} [config.onSuccess] 成功回调
*/
get : function(config) {
var me = this;
var defaultConfig = {
method : 'GET',
async : true,
body : undefined,
onSuccess : function(res, xmlhttp) {
try {
res = eval(res);
} catch(e) {
}
config.onSuccess.call(xmlhttp, res, xmlhttp);
}
}
return me.ajax($kit.join(config, defaultConfig));
},
/**
* 同步get
* @param {Object} config
* @param {String} config.url
* @param {Object} [config.params] {key:value}格式
* @param {Function} [config.onSuccess] 成功回调
*/
syncGet : function(config) {
var me = this;
var defaultConfig = {
method : 'GET',
async : false,
body : undefined,
onSuccess : function(res, xmlhttp) {
try {
res = eval(res);
} catch(e) {
}
config.onSuccess.call(xmlhttp, res, xmlhttp);
}
}
return me.ajax($kit.join(config, defaultConfig));
},
/**
* post
* @param {Object} config
* @param {String} config.url
* @param {Obejct} [config.body] {key:value}格式
* @param {Boolean} [config.async] 是否异步,默认true,异步
* @param {Function} [config.onSuccess] 成功回调
*/
post : function(config) {
var me = this;
var defaultConfig = {
method : 'POST',
async : true,
onSuccess : function(res, xmlhttp) {
try {
res = eval(res);
} catch(e) {
}
config.onSuccess.call(xmlhttp, res, xmlhttp);
}
}
return me.ajax($kit.join(config, defaultConfig));
},
/**
* 同步post
* @param {Object} config
* @param {String} config.url
* @param {Obejct} [config.body] {key:value}格式
* @param {Function} [config.onSuccess] 成功回调
*/
syncPost : function(config) {
var me = this;
var defaultConfig = {
method : 'POST',
async : false,
onSuccess : function(res, xmlhttp) {
try {
res = eval(res);
} catch(e) {
}
config.onSuccess.call(xmlhttp, res, xmlhttp);
}
}
return me.ajax($kit.join(config, defaultConfig));
},
/**
* jsonp
* @param {Object} config
* @param {Object} config.url
* @param {Object} config.params
* @param {Object} config.onSuccess
*/
jsonp : function(config) {
if(config.url) {
var url = config.url;
if(config.params) {
if(config.url.indexOf('?') == config.url.length - 1) {
url += $kit.concat(config.params, '&', '=');
} else {
url += '?' + $kit.concat(config.params);
}
}
var script = document.createElement('script');
if(config.onSuccess) {
if(script.readyState) {//ie
script.onreadystatechange = function() {
if(script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
config.onSuccess && config.onSuccess();
}
}
} else {
script.onload = function() {
config.onSuccess && config.onSuccess();
}
}
}
script.src = url;
document.body.appendChild(script);
}
}
});
/**
* $Kit.IO的实例,直接通过这个实例访问$Kit.IO所有方法
* @global
* @name $kit.io
* @type $Kit.IO
*/
$kit.io = new $Kit.IO();
/* @ignore
Referrence:
See http://www.JSON.org/js.html
Example:
text = $kit.json.stringify(['e', {pluribus: 'unum'}]);
// text is '["e",{"pluribus":"unum"}]'
text = $kit.json.stringify(['e', {pluribus: 'unum'}], null, '\t');
// text is '[\n\t"e",\n\t{\n\t\t"pluribus": "unum"\n\t}\n]'
text = $kit.json.stringify([new Date()], function (key, value) {
return this[key] instanceof Date ?
'Date(' + this[key] + ')' : value;
});
// text is '["Date(---current time---)"]'
$kit.json.parse(text, reviver)
This method parses a JSON text to produce an object or array.
It can throw a SyntaxError exception.
The optional reviver parameter is a function that can filter and
transform the results. It receives each of the keys and values,
and its return value is used instead of the original value.
If it returns what it received, then the structure is not modified.
If it returns undefined then the member is deleted.
Example:
// Parse the text. Values that look like ISO date strings will
// be converted to Date objects.
myData = $kit.json.parse(text, function (key, value) {
var a;
if (typeof value === 'string') {
a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
if (a) {
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+a[5], +a[6]));
}
}
return value;
});
myData = $kit.json.parse('["Date(09/09/2001)"]', function (key, value) {
var d;
if (typeof value === 'string' &&
value.slice(0, 5) === 'Date(' &&
value.slice(-1) === ')') {
d = new Date(value.slice(5, -1));
if (d) {
return d;
}
}
return value;
});
**/
// Create a JSON object only if one does not already exist. We create the
// methods in a closure to avoid creating global variables.
/**
* JSON扩展
* @class $Kit.JSON
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/json.js">Source code</a>
*/
$Kit.JSON = function() {
function f(n) {
// Format integers to have at least two digits.
return n < 10 ? '0' + n : n;
}
if( typeof Date.prototype.toJSON !== 'function') {
Date.prototype.toJSON = function(key) {
return isFinite(this.valueOf()) ? this.getUTCFullYear() + '-' + f(this.getUTCMonth() + 1) + '-' + f(this.getUTCDate()) + 'T' + f(this.getUTCHours()) + ':' + f(this.getUTCMinutes()) + ':' + f(this.getUTCSeconds()) + 'Z' : null;
};
String.prototype.toJSON = Number.prototype.toJSON = Boolean.prototype.toJSON = function(key) {
return this.valueOf();
};
}
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, escapable = /[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g, gap, indent, meta = {// table of character
// substitutions
'\b' : '\\b',
'\t' : '\\t',
'\n' : '\\n',
'\f' : '\\f',
'\r' : '\\r',
'"' : '\\"',
'\\' : '\\\\'
}, rep;
function quote(string) {
// If the string contains no control characters, no quote characters, and no
// backslash characters, then we can safely slap some quotes around it.
// Otherwise we must also replace the offending characters with safe escape
// sequences.
escapable.lastIndex = 0;
return escapable.test(string) ? '"' + string.replace(escapable, function(a) {
var c = meta[a];
return typeof c === 'string' ? c : '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
}) + '"' : '"' + string + '"';
}
function str(key, holder) {
// Produce a string from holder[key].
var i, // The loop counter.
k, // The member key.
v, // The member value.
length, mind = gap, partial, value = holder[key];
// If the value has a toJSON method, call it to obtain a replacement value.
if(value && typeof value === 'object' && typeof value.toJSON === 'function') {
value = value.toJSON(key);
}
// If we were called with a replacer function, then call the replacer to
// obtain a replacement value.
if( typeof rep === 'function') {
value = rep.call(holder, key, value);
}
// What happens next depends on the value's type.
switch (typeof value) {
case 'string':
return quote(value);
case 'number':
// JSON numbers must be finite. Encode non-finite numbers as null.
return isFinite(value) ? String(value) : 'null';
case 'boolean':
case 'null':
// If the value is a boolean or null, convert it to a string. Note:
// typeof null does not produce 'null'. The case is included here in
// the remote chance that this gets fixed someday.
return String(value);
// If the type is 'object', we might be dealing with an object or an array or
// null.
case 'object':
// Due to a specification blunder in ECMAScript, typeof null is 'object',
// so watch out for that case.
if(!value) {
return 'null';
}
// Make an array to hold the partial results of stringifying this object value.
gap += indent;
partial = [];
// Is the value an array?
if(Object.prototype.toString.apply(value) === '[object Array]') {
// The value is an array. Stringify every element. Use null as a placeholder
// for non-JSON values.
length = value.length;
for( i = 0; i < length; i += 1) {
partial[i] = str(i, value) || 'null';
}
// Join all of the elements together, separated with commas, and wrap them in
// brackets.
v = partial.length === 0 ? '[]' : gap ? '[\n' + gap + partial.join(',\n' + gap) + '\n' + mind + ']' : '[' + partial.join(',') + ']';
gap = mind;
return v;
}
// If the replacer is an array, use it to select the members to be stringified.
if(rep && typeof rep === 'object') {
length = rep.length;
for( i = 0; i < length; i += 1) {
if( typeof rep[i] === 'string') {
k = rep[i];
v = str(k, value);
if(v) {
partial.push(quote(k) + ( gap ? ': ' : ':') + v);
}
}
}
} else {
// Otherwise, iterate through all of the keys in the object.
for(k in value) {
if(Object.prototype.hasOwnProperty.call(value, k)) {
v = str(k, value);
if(v) {
partial.push(quote(k) + ( gap ? ': ' : ':') + v);
}
}
}
}
// Join all of the member texts together, separated with commas,
// and wrap them in braces.
v = partial.length === 0 ? '{}' : gap ? '{\n' + gap + partial.join(',\n' + gap) + '\n' + mind + '}' : '{' + partial.join(',') + '}';
gap = mind;
return v;
}
}
this.stringify = function(value, replacer, space) {
// The stringify method takes a value and an optional replacer, and an optional
// space parameter, and returns a JSON text. The replacer can be a function
// that can replace values, or an array of strings that will select the keys.
// A default replacer method can be provided. Use of the space parameter can
// produce text that is more easily readable.
var i;
gap = '';
indent = '';
// If the space parameter is a number, make an indent string containing that
// many spaces.
if( typeof space === 'number') {
for( i = 0; i < space; i += 1) {
indent += ' ';
}
// If the space parameter is a string, it will be used as the indent string.
} else if( typeof space === 'string') {
indent = space;
}
// If there is a replacer, it must be a function or an array.
// Otherwise, throw an error.
rep = replacer;
if(replacer && typeof replacer !== 'function' && ( typeof replacer !== 'object' || typeof replacer.length !== 'number')) {
throw new Error('JSON.stringify');
}
// Make a fake root object containing our value under the key of ''.
// Return the result of stringifying the value.
return str('', {
'' : value
});
}
this.parse = function(text) {
try {
//eval('var reJSONObject=' + text);
//return reJSONObject;
return new Function('var reJSONObject=' + text + ';return reJSONObject;')();
} catch(e) {
throw new SyntaxError('JSON.parse');
}
}
}
$kit.merge($Kit.JSON.prototype,
/**
* @lends $Kit.JSON.prototype
*/
{
/**
* 把json序列化成为json String
* @function
* @param {Object} json
* @return {String} string
*/
stringify : this.stringify,
/**
* 解析json string成为json object
* @function
* @param {String} jsonString
* @return {Object} json
*/
parse : this.parse
});
/**
* $Kit.JSON的实例,直接通过这个实例访问$Kit.JSON所有方法
* @global
* @type $Kit.JSON
*/
$kit.json = new $Kit.JSON();
/**
* 本地存储
* @class $Kit.LocalStorage
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/localStorage.js">Source code</a>
*/
$Kit.LocalStorage = function() {
//
if(!window.localStorage) {
document.documentElement.style.behavior = 'url(#default#userData)';
}
}
$kit.merge($Kit.LocalStorage.prototype,
/**
* @lends $Kit.LocalStorage.prototype
*/
{
/**
* 保存
* @param {Object}
* @param {Object}
* @param {Obejct}
*/
set : function(key, val, context) {
if(window.localStorage) {
return window.localStorage.setItem(key, val, context);
} else {
try {
document.documentElement.setAttribute(key, value);
return document.documentElement.save(context || 'default');
} catch (e) {
}
}
},
/**
* 读取
* @param {Object}
* @param {Object}
*/
get : function(key, context) {
if(window.localStorage) {
return window.localStorage.getItem(key, context);
} else {
try {
document.documentElement.load(context || 'default');
return document.documentElement.getAttribute(key) || '';
} catch (e) {
}
}
},
/**
* 删除
* @param {Object}
* @param {Object}
*/
rm : function(key, context) {
if(window.localStorage) {
return window.localStorage.removeItem(key, context);
} else {
try {
context = context || 'default';
document.documentElement.load(context);
document.documentElement.removeAttribute(key);
return document.documentElement.save(context);
} catch (e) {
}
}
},
/**
* 清空
*/
clear : function() {
if(window.localStorage) {
return window.localStorage.clear();
} else {
try {
document.documentElement.expires = -1;
} catch (e) {
}
}
}
});
/**
* $Kit.LocalStorage的实例,直接通过这个实例访问$Kit.LocalStorage所有方法
* @global
* @type $Kit.LocalStorage
*/
$kit.localStorage = new $Kit.LocalStorage();
/**
* 数组扩展
* @class $Kit.Math
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/math.js">Source code</a>
*/
$Kit.Math = function() {
//
}
$kit.merge($Kit.Math.prototype,
/**
* @lends $Kit.Math.prototype
*/
{
/**
* 前面补0
* @param {Number|String}
* @param {Number}
* @return {String}
*/
padZero : function(num, length) {
var re = num.toString();
do {
var l1 = re.indexOf(".") > -1 ? re.indexOf(".") : re.length;
if(l1 < length) {
re = "0" + re;
}
} while (l1 < length);
return re;
},
/**
* 返回min与max之间的随机数,没有max,则返回0~min之间
* @param {Number}
* @param {Number} [max]
* @return {Number}
*/
rand : function(min, max) {
max = max || min || 100;
min = min || 0;
var rnd = Math.round(Math.random() * max);
if(min != 0 && max != min) {
if(min > max) {
max = min;
}
if(min < 0) {
rnd = this.positiveOrNegative() * rnd;
}
while(rnd < min) {
rnd = this.positiveOrNegative() * Math.round(Math.random() * max)
}
}
return rnd;
},
/**
* 随机返回0或者1
* @return {Number}
*/
oneOrZero : function() {
return Math.round(Math.random());
},
/**
* 随机返回正或者负,return -1 || +1
* @return {Number}
*/
positiveOrNegative : function() {
var flag = this.oneOrZero();
if(flag) {
return 1;
}
return -1;
},
/**
* 取多少位的随机数,返回string
* @param {Number}
* @return {String}
*/
randUnit : function(length) {
length = length || 3;
return this.padZero(Math.round(Math.random() * Math.pow(10, length)), length);
},
/**
* 取多少位的随机数,开头非0,返回数字
* @param {Number}
* @return {String}
*/
randUnitNotZeroBefore : function(length) {
length = length || 3;
var re = Math.round(Math.random() * Math.pow(10, length));
while(re < Math.pow(10, length - 1)) {
re = Math.round(Math.random() * Math.pow(10, length));
}
return re;
},
/**
* 进制转换
* @param {Number|String}
* @param {Number|String}
* @param {Number|String}
* @return {String}
*/
convert : function(str, oldHex, newHex) {
var num = new String(str);
num = parseInt(num, parseInt(oldHex));
return num.toString(parseInt(newHex));
},
/**
* 给数字添加逗号分割
* @param {Number}
* @param {String} [sign] 分隔符号,默认是,
* @param {Number} [n] 默认以千位分割,默人是3,10的3次方
* @return {String}
*/
splitNumberWithComma : function(num, sign, n) {
if(sign == null && n == null) {
sign = ',';
n = 3;
} else {
if(n == null) {
if( typeof sign != 'number') {
//
n = 3;
} else {
sign = ',';
n = parseInt(sign);
}
}
}
var s = num.toString().split('');
var a = [], b = [];
for(var i = 0; i < s.length; i++) {
if((s.length - i - 1) % n > 0) {
b.push(s[i]);
} else {
b.push(s[i]);
a.push(b.join(''));
b = [];
}
}
return a.join(sign);
}
});
/**
* $Kit.Math的实例,直接通过这个实例访问$Kit.Math所有方法
* @global
* @type $Kit.Math
*/
$kit.math = new $Kit.Math();
/**
* 多线程
* @class $Kit.Multithread
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/multithread.js">Source code</a>
* @example <a href="http://xueduany.github.com/KitJs/KitJs/demo/MultiThread/demo.html">KitJs多线程demo演示</a>
*/
$Kit.Multithread = function(url) {
this.threadPool = {};
this.currentThreadId = 0;
this.iterateDefaultTimeOut = 300;
}
$kit.merge($Kit.Multithread.prototype,
/**
* @lends $Kit.Multithread.prototype
*/
{
/**
* 创建一个新线程
* @param {Function}
* @return {Number} 返回线程id
*/
newThread : function(fn) {
if($kit.isFn(fn)) {
var threadId = $kit.only();
this.threadPool[threadId] = this.threadPool[threadId] || {};
this.threadPool[threadId].fn = fn;
this.threadPool[threadId]['executeStack'] = [];
//this.threadPool[threadId].fn = fn.toString().trim().replace(/function\s*\([\w\d,\s]*\)\s*\{/, '');
//this.threadPool[threadId].fn = this.threadPool[threadId].fn.substring(0, this.threadPool[threadId].fn.length - 1);
//this.threadPool[threadId].fn = 'this.currentThreadId = "' + threadId + '";' + this.threadPool[threadId].fn
//this.threadPool[threadId].fn = this.parse(this.threadPool[threadId].fn);
return threadId;
}
},
/**
* 根据线程id运行线程
* @param {Number}
*/
run : function(threadId) {
if(this.threadPool[threadId]) {
this.currentThreadId = threadId;
//(function() {
//eval(this.threadPool[threadId].fn);
this.threadPool[threadId].fn();
//}).call(this);
}
},
parse : function(fnString) {
//
},
/**
* 延时线程执行
* @param {Function}
* @param {Number}
*/
sleep : function(fn, timeOut) {
if(this.threadPool[this.currentThreadId] == null) {
return;
}
timeOut = timeOut || 0;
this.threadPool[this.currentThreadId ]['executeStack'] = this.threadPool[this.currentThreadId ]['executeStack'] || [];
var self = this;
var currentThreadId = this.currentThreadId;
var timeOutId = setTimeout(function() {
(function() {
this.currentThreadId = currentThreadId;
this.threadPool[this.currentThreadId]['executeStack'].pop();
fn();
}).call(self);
}, timeOut);
this.threadPool[this.currentThreadId ]['executeStack'].push(timeOutId);
},
/**
* 杀死线程
* @param {Number}
* @return {Boolean}
*/
killThread : function(threadId) {
if(this.threadPool[threadId]) {
do {
var id = 0;
if(this.threadPool[threadId]['executeStack']) {
id = this.threadPool[threadId]['executeStack'].pop();
try {
clearTimeout(id);
clearInterval(id);
} catch(e) {
}
}
} while(id>0)
delete this.threadPool[threadId];
return true;
}
return false;
},
/**
* 循环,替代标准的while,for等
* @param {Function|Boolean|String}
* @param {Function}
*/
iterate : function(condition, fn) {
var timeout = this.iterateDefaultTimeOut;
var self = this;
var currentThreadId = this.currentThreadId;
var intervalId;
function f1() {
var flag = false;
if($kit.isFn(condition)) {
flag = condition();
} else if($kit.isStr(condition)) {
flag = eval(condition);
} else {
flag = condition;
}
//
if(flag) {
fn();
(function() {
clearInterval(intervalId);
intervalId = setInterval(function() {
(function() {
if(this.threadPool[currentThreadId] != null) {
this.currentThreadId = currentThreadId;
var executeStack = this.threadPool[currentThreadId]['executeStack'];
//this.threadPool[this.currentThreadId ]['executeStack'].push(f);
if(executeStack.length <= 1) {
clearInterval(intervalId);
executeStack.pop();
f1.call(self)
}
} else {
clearInterval(intervalId);
}
}).call(self);
}, timeout);
if(this.threadPool[this.currentThreadId] && this.threadPool[this.currentThreadId]['executeStack']) {
this.threadPool[this.currentThreadId ]['executeStack'].push(intervalId);
}
}).call(self);
} else {
clearInterval(intervalId);
}
}
f1.call(this);
}
});
/**
* $Kit.Multithread的实例,直接通过这个实例访问$Kit.Multithread所有方法
* @global
* @alias $kit.multithread
* @type $Kit.Multithread
*/
$kit.multithread = new $Kit.Multithread();
/**
* 文本扩展
* @class $Kit.String
* @requires kit.js
* @requires math.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/string.js">Source code</a>
*/
$Kit.String = function() {
this.ScriptFragment = '<script[^>]*>([\\S\\s]*?)<\/script>';
this.specialChar = {
'\b' : '\\b',
'\t' : '\\t',
'\n' : '\\n',
'\f' : '\\f',
'\r' : '\\r',
'\\' : '\\\\'
}
}
$kit.merge($Kit.String.prototype,
/**
* @lends $Kit.String.prototype
*/
{
/**
* 断句
* @param {String}
* @return {String}
*/
breakSentence : function(str) {
return str.replace(/([,\.\?!;:][\s"'’”)])(\n?)/g, '$1\n');
},
/**
* HTML字符串转移,如&转移为&amp;保证可以在页面显示html代码,而不是实际内容
* @param {String}
* @return {String}
*/
HTMLEncode : function(str) {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/ /g, '&nbsp;').replace(/\'/g, '&#39;').replace(/\"/g, '&quot;');
},
/**
* 解码转义过的html
* @param {String}
* @return {String}
*/
HTMLDecode : function(str) {
return str.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&nbsp;/g, ' ').replace(/&#39;'/g, '\'').replace(/&quot/g, '"');
},
/**
* gb2312转换unicode进制
* @param {String}
* @return {String}
*/
ChineseToUnicode : function(str) {
return escape(str).replace(/%u/g, '\\u').replace(/%([0-9a-f]{2})/ig, '\\u00$1');
},
/**
* unicode进制转换gb2312
* @param {String}
* @return {String}
*/
UnicodeToChinese : function(str) {
return unescape(str.replace(/\\u00/g, '%').replace(/\\u/g, '%u'));
},
/**
* &#xxx;转义中文
* @param {String}
* @return {String}
*/
HTMLEntityToChinese : function(str) {
var regExp = /&#([0-9]+);/ig;
while(str.match(regExp) && str.match(regExp).length) {
var find = str.match(regExp)[0];
str = str.replace(find, String.fromCharCode(find.substring(2, find.length - 1)));
}
return str;
},
/**
* 中文转html实体
* @param {String}
* @return {String}
*/
ChineseToHTMLEntity : function(str) {
var re = [];
for(var i = 0; i < str.length; i++) {
var charCode = str.charCodeAt(i);
re.push('&#' + charCode + ';');
}
return re.join('');
},
/**
* html实体字符&#xxx;转换unicode
* @param {String}
* @return {String}
*/
HTMLEntityToUnicode : function(str) {
var regExp = /&#([0-9]+);/ig;
while(str.match(regExp) && str.match(regExp).length) {
var find = str.match(regExp)[0];
var code = find.substring(2, find.length - 1);
str = str.replace(find, '\\u' + $kit.math.padZero($kit.math.convert(code, 10, 16), 4));
}
return str;
},
/**
* unicode转html实体
* @param {String}
* @return {String}
*/
UnicodeToHTMLEntity : function(str) {
var regExp = /\\u([0-9a-f]+)/ig;
while(str.match(regExp) && str.match(regExp).length) {
var find = str.match(regExp)[0];
var code = find.substring(2);
str = str.replace(find, '&#' + $kit.math.convert(code, 16, 10) + ';');
}
return str;
},
/**
* convert方法 统一接口
* @param {String}
* @param {String}
* @param {String}
* @return {String}
*/
convert : function(str, oldEncoding, newEncoding) {
switch (oldEncoding.toLowerCase()) {
case 'unicode':
case 'utf':
switch (newEncoding.toLowerCase()) {
case 'gbk':
case 'gb2312':
case 'gb':
case 'chinese':
return this.UnicodeToChinese(str);
break;
case 'htmlentity':
case 'entity':
return this.UnicodeToHTMLEntity(str);
break;
}
break;
case 'gbk':
case 'gb2312':
case 'gb':
case 'chinese':
switch (newEncoding.toLowerCase()) {
case 'unicode':
case 'utf':
return this.ChineseToUnicode(str);
break;
case 'htmlentity':
case 'entity':
return this.ChineseToHTMLEntity(str);
break;
}
break;
case 'htmlentity':
case 'entity':
switch (newEncoding.toLowerCase()) {
case 'gbk':
case 'gb2312':
case 'gb':
case 'chinese':
return this.HTMLEntityToChinese(str);
break;
case 'unicode':
case 'utf':
return this.HTMLEntityToUnicode(str);
break;
}
break;
}
},
/**
* 首尾去空格
* @param {String}
* @return {String}
*/
strip : function(str) {
return str.replace(/^\s+/, '').replace(/\s+$/, '');
},
/**
* 左去空
* @param {String}
* @return {String}
*/
ltrim : function(str) {
return str.replace(/^\s+/, '');
},
/**
* 右去空
* @param {String}
* @return {String}
*/
rtrim : function(str) {
return str.replace(/\s+$/, '');
},
/**
* 去掉所有的tag标记
* @param {String}
* @param {String}
*/
stripTags : function(str) {
return str.replace(/<\w+(\s+("[^"]*"|'[^']*'|[^>])+)?>|<\/\w+>/gi, '');
},
/**
* 去除脚本代码
* @param {String}
* @return {String}
*/
stripScripts : function(str) {
return this.replace(new RegExp(this.ScriptFragment, 'img'), '');
},
/**
* 找出脚本代码,将结果放在一个数组中
* @param {String}
* @return {Array}
*/
extractScripts : function(str) {
var matchAll = new RegExp(this.ScriptFragment, 'img'), matchOne = new RegExp(this.ScriptFragment, 'im'), re = [];
$kit.each((str.match(matchAll) || []), function(scriptTag) {
re.push((scriptTag.match(matchOne) || ['', ''])[1]);
});
return re;
},
/**
* Check if the string contains a substring.
* @param {String}
* @return {Boolean}
*/
include : function(str, pattern) {
return str.indexOf(pattern) > -1;
},
/**
* Checks if the string starts with substring.
* @param {String}
* @return {Boolean}
* @example
* 'Prototype JavaScript'.startsWith('Pro');//-> true
*/
startsWith : function(str, pattern) {
return str.lastIndexOf(pattern, 0) === 0;
},
/**
* Checks if the string ends with substring.
* @param {String}
* @return {Boolean}
* @example
* 'slaughter'.endsWith('laughter')// -> true
*/
endsWith : function(str, pattern) {
var d = str.length - pattern.length;
return d >= 0 && str.indexOf(pattern, d) === d;
},
/**
* Converts a string separated by dashes into a camelCase equivalent. For instance, 'foo-bar' would be converted to 'fooBar'.
* @param {String}
* @return {String}
* @example
* 'background-color'.camelize();// -> 'backgroundColor'
* '-moz-binding'.camelize();// -> 'MozBinding'
*/
camelize : function(str) {
return str.replace(/-+(.)?/g, function(match, chr) {
return chr ? chr.toUpperCase() : '';
});
},
/**
* Capitalizes the first letter of a string and downcases all the others.
* @param {String}
* @return {String}
* @example
* 'hello'.capitalize();// -> 'Hello'
* 'HELLO WORLD!'.capitalize();// -> 'Hello world!'
*/
capitalize : function(str) {
return str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
},
/**
* Converts a camelized string into a series of words separated by an underscore ("_").
* @param {String}
* @return {String}
*/
underscore : function(str) {
return str.replace(/::/g, '/').replace(/([A-Z]+)([A-Z][a-z])/g, '$1_$2').replace(/([a-z\d])([A-Z])/g, '$1_$2').replace(/-/g, '_').toLowerCase();
},
/**
* Replaces every instance of the underscore character ("_") by a dash ("-").
* @param {String}
* @return {String}
* @example
* 'border_bottom_width'.dasherize();// -> 'border-bottom-width'
* Note:
* Used in conjunction with String#underscore, String#dasherize converts a DOM style into its CSS equivalent.
* 'borderBottomWidth'.underscore().dasherize();// -> 'border-bottom-width'
*/
dasherize : function(str) {
return str.replace(/_/g, '-');
},
/**
* Check if the string is 'blank', meaning either empty or containing only whitespace.
* @param {String}
* @return {Boolean}
* @example
* ''.blank();//-> true
* ' '.blank();//-> true
* ' a '.blank();//-> false
*/
blank : function(str) {
return /^\s*$/.test(str);
},
/**
* Checks if the string is empty.
* @param {String}
* @return {Boolean}
* @example
* ''.empty();//-> true
* ' '.empty();//-> false
*/
empty : function(str) {
return str == '';
},
/**
* Returns a debug-oriented version of the string (i.e. wrapped in single or double quotes, with backslashes and quotes escaped).
* @param {String}
* @return {Boolean}
* @example
* 'I\'m so happy.'.inspect();
* // -> '\'I\\\'m so happy.\'' (displayed as 'I\'m so happy.' in an alert dialog or the console)
* 'I\'m so happy.'.inspect(true);
* // -> '"I'm so happy."' (displayed as "I'm so happy." in an alert dialog or the console)
*/
inspect : function(str, useDoubleQuotes) {
var escapedString = str.replace(/[\x00-\x1f\\]/g, function(character) {
if( character in this.specialChar) {
return this.specialChar[character];
}
var c = character.charCodeAt();
return '\\u00' + $kit.math.padZero(c.toString(16), 2);
});
if(useDoubleQuotes)
return '"' + escapedString.replace(/"/g, '\\"') + '"';
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
},
/**
* 在字符串中指定位置插入字符串
* @param {String}
* @param {Number}
* @param {String}
* @return {String}
*/
insert : function(str, pos, insertString) {
var a = str.split('');
a.splice(pos, 0, insertString);
return a.join('');
}
});
/**
* $Kit.String的实例,直接通过这个实例访问$Kit.String所有方法
* @global
* @alias $kit.str
* @type $Kit.String
*/
$kit.str = $kit.string = new $Kit.String();
/**
* url扩展
* @class $Kit.Url
* @requires kit.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/url.js">Source code</a>
*/
$Kit.Url = function(url) {
this._fields = {
'Username' : 4,
'Password' : 5,
'Port' : 7,
'Protocol' : 2,
'Host' : 6,
'Pathname' : 8,
'URL' : 0,
'Querystring' : 9,
'Fragment' : 10
};
this._values = {};
this._regex = null;
this._regex = /^((\w+):\/\/)?((\w+):?(\w+)?@)?([^\/\?:]+):?(\d+)?(\/?[^\?#]+)?\??([^#]+)?#?(\w*)/;
for(var f in this._fields) {
this['get' + f] = this._makeGetter(f);
if( typeof url != 'undefined') {
this.parse(url);
}
}
}
$kit.merge($Kit.Url.prototype,
/**
* @lends $Kit.Url.prototype
*/
{
/**
* 通过解析url,返回包含用户名,密码,端口,协议,路径名,请求参数的map对象
* @param {String}
* @return {Map}
*/
parse : function(url) {
for(var f in this._fields) {
this._values[f] = '';
}
var r = this._regex.exec(url);
if(!r)
throw "URLParser::_parse -> Invalid URL"
for(var f in this._fields)
if( typeof r[this._fields[f]] != 'undefined') {
this._values[f] = r[this._fields[f]];
}
if(this._values['Querystring'].length) {
var queryString = this._values['Querystring'];
var params = {};
var a = queryString.split('&');
for(var i = 0; i < a.length; i++) {
var o = a[i];
var a1 = o.split('=');
var k = a1[0];
var v = decodeURI(a1[1]);
if( k in params) {
if($kit.isAry(params[k])) {
//
} else {
var old = params[k];
params[k] = [];
params[k].push(old);
}
params[k].push(v);
} else {
params[k] = v;
}
}
this._values.Params = params;
}
return this._values;
},
_makeGetter : function(field) {
return function() {
return this._values[field];
}
},
getParam : function(key) {
if(this._values.Params) {
return this._values.Params[key]
}
return null;
}
});
/**
* $Kit.Url的实例,直接通过这个实例访问$Kit.Url所有方法
* @global
* @alias $kit.url
* @type $Kit.Url
*/
$kit.url = new $Kit.Url(location.href);
package
{
import flash.display.Sprite;
import flash.external.ExternalInterface;
import flash.net.URLRequest;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.events.Event;
import flash.errors.IOError;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.system.Security;
public class audiojs extends Sprite
{
private var _channel:SoundChannel;
private var sound:Sound;
private var duration:Number;
private var playerInstance:String;
private var pausePoint:Number = 0;
private var playing:Boolean = false;
private var volume:Number = 1;
private var timer:Timer = new Timer(250, 0);
private function get channel():SoundChannel
{
return this._channel;
}
private function set channel(channel:SoundChannel):void
{
this._channel = channel;
this._channel.addEventListener(Event.SOUND_COMPLETE, this.soundEnded);
}
public function audiojs():void
{
Security.allowDomain("*");
this.playerInstance = root.loaderInfo.parameters.playerInstance + '.';
ExternalInterface.addCallback('init', init);
ExternalInterface.addCallback('load', load);
ExternalInterface.addCallback('playPause', playPause);
ExternalInterface.addCallback('pplay', play);
ExternalInterface.addCallback('ppause', pause);
ExternalInterface.addCallback('skipTo', skipTo);
ExternalInterface.addCallback('skipTimeTo', skipTimeTo);
ExternalInterface.addCallback('setVolume', setVolume);
ExternalInterface.call(this.playerInstance + 'initialized');
}
private function updatePlayhead(e:TimerEvent = null):void
{
var targetPosition:Number = e ? this.channel.position : this.pausePoint;
var playProgress:Number = targetPosition / this.duration;
if (playProgress > 1)
playProgress = 1;
if (playProgress > 0)
{
ExternalInterface.call(this.playerInstance + 'updatePlayhead', playProgress);
}
}
private function loadProgress(e:ProgressEvent):void
{
this.duration = (e.bytesTotal / (e.bytesLoaded / this.sound.length))
var loadPercent:Number = e.bytesLoaded / e.bytesTotal;
if (loadPercent > 1)
loadPercent = 1;
if (loadPercent > 0)
{
ExternalInterface.call(this.playerInstance + 'loadProgress', loadPercent, (this.duration / 1000));
}
}
private function init(mp3:String):void
{
this.load(mp3);
}
private function load(mp3:String):void
{
if (this.channel)
{
this.channel.stop();
}
if (this.sound)
{
this.sound.removeEventListener(ProgressEvent.PROGRESS, this.loadProgress);
}
this.channel = new SoundChannel();
this.sound = new Sound(new URLRequest(mp3));
this.pausePoint = 0;
this.sound.addEventListener(IOErrorEvent.IO_ERROR, this.loadError);
this.sound.addEventListener(ProgressEvent.PROGRESS, this.loadProgress);
this.timer.addEventListener(TimerEvent.TIMER, this.updatePlayhead);
this.timer.start();
}
private function loadError(e:IOErrorEvent):void
{
ExternalInterface.call(this.playerInstance + 'loadError');
}
private function play():void
{
this.channel = this.sound.play(this.pausePoint);
this.setVolume(this.volume);
this.playing = true;
this.timer.start();
}
private function pause():void
{
this.pausePoint = this.channel.position;
this.channel.stop();
this.playing = false;
this.timer.stop();
}
private function playPause():void
{
if (this.playing)
{
this.pause();
}
else
{
this.play();
}
}
private function skipTo(percent:Number):void
{
this.channel.stop();
this.pausePoint = this.duration * percent;
if (this.playing)
{
this.channel = this.sound.play(this.pausePoint);
this.setVolume(this.volume);
}
else
{
this.updatePlayhead();
}
}
private function skipTimeTo(time:Number):void
{
this.channel.stop();
this.pausePoint = time * 1000;
if (this.playing)
{
this.channel = this.sound.play(this.pausePoint);
this.setVolume(this.volume);
}
else
{
this.updatePlayhead();
}
}
private function setVolume(vol:Number):void
{
this.volume = vol;
var transform:SoundTransform = this.channel.soundTransform;
if (vol < 0)
vol = 0;
if (vol > 1)
vol = 1;
transform.volume = vol;
channel.soundTransform = transform;
}
private function soundEnded(e:Event):void
{
ExternalInterface.call(this.playerInstance + 'trackEnded');
}
}
}
\ No newline at end of file
$kit.$(function() {
$kit.widgetInstance = {};
var defaultConfig = $kit.ui.CodeExample.defaultConfig;
$kit.each($kit.el8cls(defaultConfig.codeExampleCls), function(currentOne, idx, array) {
$kit.widgetInstance[defaultConfig.kitWidgetName] = $kit.widgetInstance[defaultConfig.kitWidgetName] || [];
var config = {
where : currentOne,
opener : $kit.attr(currentOne, 'opener')
};
if($kit.isEmpty($kit.el8tag('textarea', currentOne))) {
config.script = currentOne.innerText;
} else {
config.scriptContainer = $kit.el8tag('textarea', currentOne);
}
$kit.widgetInstance[defaultConfig.codeExampleCls].push(new $kit.ui.CodeExample(config));
});
});
/**
* 用window.open测试script效果
* @class $kit.ui.CodeExample
* @requires kit.js
* @requires ieFix.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/CodeExample/codeExample.js">Source code</a>
* @example <a href="http://xueduany.github.com/KitJs/KitJs/demo/CodeExample/demo.html">Demo</a>
*/
$kit.ui.CodeExample = function(config) {
var me = this;
me.config = $kit.join(me.constructor.defaultConfig, config);
me.init();
};
$kit.merge($kit.ui.CodeExample,
/**
* @lends $kit.ui.CodeExample
*/
{
/**
* 默认配置
* @enum
*/
defaultConfig : {
kitWidgetName : "kitCodeExample",
codeExampleCls : 'kitjs_codeExample',
/**
* 打开window执行script之后干嘛
* @type {Function}
*/
then : undefined,
/**
* 点击跑script那个按钮插哪儿,默认插到document.body屁股上
* @type {Element}
*/
where : undefined,
/**
* window.opener
* @type {URL}
*/
opener : 'about:blank',
/**
* 插的位置,默认last
* @type {String}
*/
pos : 'last',
/**
* 点击跑脚本的HTML
* @type {HTML}
*/
what : '<button class="codeExampleViewBtn">Run Test</button>'
}
});
$kit.merge($kit.ui.CodeExample.prototype,
/**
* @lends $kit.ui.CodeExample.prototype
*/
{
/**
* 初始化
*/
init : function() {
var me = this;
if(!$kit.isEmpty(me.config.where)) {
$kit.insEl({
where : me.config.where,
pos : me.config.pos,
what : me.config.what
});
var btn = $kit.el('.codeExampleViewBtn', me.config.where)[0];
$kit.ev({
el : btn,
ev : 'click',
fn : function(e, cfg) {
var me = this;
me.runTest();
},
scope : me
});
}
},
/**
* 跑测试
*/
runTest : function() {
var me = this;
var opener = window.open(me.config.opener);
if(me.config.opener.toString().toLowerCase() == 'about:blank') {
$kit.dom.injectJs({
where : opener.document.body,
text : me.config.script || me.config.scriptContainer ? $kit.val(me.config.scriptContainer) : '',
then : me.config.then
});
} else if('onload' in opener) {
$kit.ev({
el : opener,
ev : 'load',
fn : function() {
$kit.dom.injectJs({
where : opener.document.body,
text : me.config.script || me.config.scriptContainer ? $kit.val(me.config.scriptContainer) : '',
then : me.config.then
});
}
});
}
}
});
/**
* 对话框组件
* @class $kit.ui.Dialog
* @require kit.js
* @require dom.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Dialog/dialog.js">Source code</a>
*/
$kit.ui.Dialog = function(config) {
var me = this;
me.config = $kit.join(me.constructor.defaultConfig, config);
}
$kit.merge($kit.ui.Dialog,
/**
* @lends $kit.ui.Dialog
*/
{
/**
* @enum
*/
defaultConfig : {
html : [//
'<div class="${dialogCls}">', //
'<div class="${dialogTitleCls}"></div>', //
'<div class="${dialogPanelCls}">', //
'</div>', //
'<a class="${closeBtnCls}">╳</a>', //
'</div>'//
].join(''),
dialogCls : 'kitjs-dialog',
dialogTitleCls : 'kitjs-dialog-title',
dialogPanelCls : 'kitjs-dialog-panel',
closeBtnCls : 'kitjs-dialog-close-btn',
//
useMask : false,
draggable : true,
title : 'Dialog'
}
});
$kit.merge($kit.ui.Dialog.prototype,
/**
* @lends $kit.ui.Dialog.prototype
*/
{
/**
* 初始化
*/
init : function() {
var me = this;
me.wrapper = $kit.newHTML($kit.tpl(me.config.html,me.config)).childNodes[0];
document.body.appendChild(me.wrapper);
me.title = $kit.el8cls(me.config.dialogTitleCls, me.wrapper);
me.panel = $kit.el8cls(me.config.dialogPanelCls, me.wrapper);
me.closeBtn = $kit.el8cls(me.config.closeBtnCls, me.wrapper);
$kit.ev({
el : me.closeBtn,
ev : 'click',
fn : me.hide,
scope : me
});
if(me.title && me.config.title) {
me.title.innerHTML = me.config.title;
}
if(me.config.useMask) {
me.mask = new $kit.ui.Mask();
}
if(me.config.draggable) {
$kit.event.draggable(me.title);
}
return me;
},
/**
* 居中
*/
center : function() {
var me = this;
var pos = $kit.dom.clientOffsetCenter(me.wrapper);
$kit.css(me.wrapper, {
top : pos.top + 'px',
left : pos.left + 'px'
});
},
/**
* 显示
*/
show : function() {
var me = this;
if(me.config.useMask && me.mask) {
me.mask.show();
}
me.wrapper.style.display = '';
},
/**
* 隐藏
*/
hide : function() {
var me = this;
if(me.config.useMask && me.mask) {
me.mask.hide();
}
me.wrapper.style.display = 'none';
},
/**
* 销毁
*/
destroy : function() {
$kit.rmEl(this.wrapper);
}
});
/**
* 悬停tips
* @class $kit.ui.Dialog.HoverTips
* @extends $kit.ui.Dialog
* @require kit.js
* @require dom.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Dialog/hoverTips.js">Source code</a>
*/
$kit.ui.Dialog.HoverTips = function(config) {
var me = this;
$kit.inherit({
child : $kit.ui.Dialog.HoverTips,
father : $kit.ui.Dialog
});
me.config = $kit.join(me.constructor.defaultConfig, config);
}
$kit.merge($kit.ui.Dialog.HoverTips, {
defaultConfig : $kit.mergeIf(
/**
* @member defaultConfig
* @memberOf $kit.ui.Dialog.HoverTips
* @enum
*/
{
html : [//
'<div class="${dialogCls}">', //
'<div class="${dialogTitleCls}"></div>', //
'<div class="${dialogPanelCls}">', //
'<div class="${confirmTextCls}">${confirmText}</div>', //
'<div class="${confirmButtonsCls}">', //
'<a class="${yesCls}">${yesText}</a>', //
'<a class="${noCls}">${noText}</a>', //
'<a class="${cancelCls}">${cancelText}</a>', //
'</div>', //
'</div>', //
'<a class="${closeBtnCls}">╳</a>', //
'</div>'//
].join(''),
yesText : '是',
noText : '否',
cancelText : '取消',
confirmTextCls : 'kitjs-dialog-confirm-text',
confirmButtonsCls : 'kitjs-dialog-confirm-buttons',
yesCls : 'confirm-yes',
noCls : 'confirm-no',
cancelCls : 'confirm-cancel',
confirmText : '请确认你的请求?',
//
// yes的跳转方法
yesThen : null,
// no的跳转方法
noThen : null,
// 取消的跳转方法
cancelThen : null,
showEffect : {
fx : $kit.anim.fx('swing'),
duration : 500,
from : {
opacity : 0
},
to : {
opacity : 1
}
},
hideEffect : {
fx : $kit.anim.fx('swing'),
duration : 500,
to : {
opacity : 0
},
from : {
opacity : 1
}
}
}, $kit.ui.Dialog.defaultConfig)
});
$kit.merge($kit.ui.Dialog.HoverTips.prototype,
/**
* @lends $kit.ui.Dialog.HoverTips.prototype
*/
{
/**
* 初始化
*/
init : function() {
var me = this;
me.wrapper = $kit.newHTML($kit.tpl(me.config.html,me.config)).childNodes[0];
document.body.appendChild(me.wrapper);
me.wrapper.style.display = 'none';
me.title = $kit.el8cls(me.config.dialogTitleCls, me.wrapper);
me.panel = $kit.el8cls(me.config.dialogPanelCls, me.wrapper);
me.closeBtn = $kit.el8cls(me.config.closeBtnCls, me.wrapper);
me.yesBtn = $kit.el8cls(me.config.yesCls, me.wrapper);
me.noBtn = $kit.el8cls(me.config.noCls, me.wrapper);
me.cancelBtn = $kit.el8cls(me.config.cancelCls, me.wrapper);
$kit.ev({
el : me.closeBtn,
ev : 'click',
fn : me.hide,
scope : me
});
$kit.ev({
el : me.yesBtn,
ev : 'click',
fn : function(e) {
me.config.yesThen && me.config.yesThen();
me.hide();
},
scope : me
});
$kit.ev({
el : me.noBtn,
ev : 'click',
fn : function(e) {
me.config.noThen && me.config.noThen();
me.hide();
},
scope : me
});
$kit.ev({
el : me.cancelBtn,
ev : 'click',
fn : function(e) {
me.config.cancelThen && me.config.cancelThen();
me.hide();
},
scope : me
});
if(me.title && me.config.title) {
me.title.innerHTML = me.config.title;
}
if(me.config.useMask) {
me.mask = new $kit.ui.Mask();
}
if(me.config.draggable) {
$kit.event.draggable(me.title);
}
me.show();
return me;
},
/**
* 显示
*/
show : function() {
var me = this;
if(me.config.useMask && me.mask) {
me.mask.show();
}
me.wrapper.style.display = '';
$kit.css(me.wrapper, 'opacity', 0);
me.center();
$kit.anim.motion($kit.merge({
el : me.wrapper
}, me.config.showEffect));
},
/**
* 隐藏
*/
hide : function() {
var me = this;
if(me.config.useMask && me.mask) {
me.mask.hide();
}
me.wrapper.style.display = 'none';
}
});
/**
* 对话框组件,yes Or no Or cancel
* @class $kit.ui.Dialog.YesOrNo
* @extends $kit.ui.Dialog
* @require kit.js
* @require dom.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Dialog/yesOrNo.js">Source code</a>
*/
$kit.ui.Dialog.YesOrNo = function(config) {
var me = this;
$kit.inherit({
child : $kit.ui.Dialog.YesOrNo,
father : $kit.ui.Dialog
});
me.config = $kit.join(me.constructor.defaultConfig, config);
}
$kit.merge($kit.ui.Dialog.YesOrNo, {
defaultConfig : $kit.mergeIf(
/**
* @member defaultConfig
* @memberOf $kit.ui.Dialog.YesOrNo
* @enum
*/
{
html : [//
'<div class="${dialogCls}">', //
'<div class="${dialogTitleCls}"></div>', //
'<div class="${dialogPanelCls}">', //
'<div class="${confirmTextCls}">${confirmText}</div>', //
'<div class="${confirmButtonsCls}">', //
'<a class="${yesCls}">${yesText}</a>', //
'<a class="${noCls}">${noText}</a>', //
'<a class="${cancelCls}">${cancelText}</a>', //
'</div>', //
'</div>', //
'<a class="${closeBtnCls}">╳</a>', //
'</div>'//
].join(''),
yesText : '是',
noText : '否',
cancelText : '取消',
confirmTextCls : 'kitjs-dialog-confirm-text',
confirmButtonsCls : 'kitjs-dialog-confirm-buttons',
yesCls : 'confirm-yes',
noCls : 'confirm-no',
cancelCls : 'confirm-cancel',
confirmText : '请确认你的请求?',
//
// yes的跳转方法
yesThen : null,
// no的跳转方法
noThen : null,
// 取消的跳转方法
cancelThen : null
}, $kit.ui.Dialog.defaultConfig)
});
$kit.merge($kit.ui.Dialog.YesOrNo.prototype,
/**
* @lends $kit.ui.Dialog.YesOrNo.prototype
*/
{
/**
* 初始化
*/
init : function() {
var me = this;
me.wrapper = $kit.newHTML($kit.tpl(me.config.html,me.config)).childNodes[0];
document.body.appendChild(me.wrapper);
me.title = $kit.el8cls(me.config.dialogTitleCls, me.wrapper);
me.panel = $kit.el8cls(me.config.dialogPanelCls, me.wrapper);
me.closeBtn = $kit.el8cls(me.config.closeBtnCls, me.wrapper);
me.yesBtn = $kit.el8cls(me.config.yesCls, me.wrapper);
me.noBtn = $kit.el8cls(me.config.noCls, me.wrapper);
me.cancelBtn = $kit.el8cls(me.config.cancelCls, me.wrapper);
$kit.ev({
el : me.closeBtn,
ev : 'click',
fn : me.hide,
scope : me
});
$kit.ev({
el : me.yesBtn,
ev : 'click',
fn : function(e) {
me.config.yesThen && me.config.yesThen();
me.hide();
},
scope : me
});
$kit.ev({
el : me.noBtn,
ev : 'click',
fn : function(e) {
me.config.noThen && me.config.noThen();
me.hide();
},
scope : me
});
$kit.ev({
el : me.cancelBtn,
ev : 'click',
fn : function(e) {
me.config.cancelThen && me.config.cancelThen();
me.hide();
},
scope : me
});
if(me.title && me.config.title) {
me.title.innerHTML = me.config.title;
}
if(me.config.useMask) {
me.mask = new $kit.ui.Mask();
}
if(me.config.draggable) {
$kit.event.draggable(me.title);
}
return me;
},
/**
* 点击yes执行方法
* @param {Function}
*/
setYesThen : function(fn) {
this.config.yesThen = fn;
},
/**
* 点击no执行方法
* @param {Function}
*/
setNoThen : function(fn) {
this.config.noThen = fn;
},
/**
* 点击cancel执行方法
* @param {Function}
*/
setCancelThen : function(fn) {
this.config.cancelThen = fn;
}
});
/**
* 基本编辑器
* @class $kit.ui.Editor
* @requires kit.js
* @requires ieFix.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Editor/editor.js">Source code</a>
*/
$kit.ui.Editor = function(config) {
var me = this;
me.config = $kit.join(me.constructor.defaultConfig, config);
}
$kit.merge($kit.ui.Editor,
/**
* @lends $kit.ui.Editor
*/
{
/**
* @enum
*/
defaultConfig : {
kitWidgetName : "kitEditor",
el : undefined
}
});
$kit.merge($kit.ui.Editor.prototype,
/**
* @lends $kit.ui.Editor.prototype
*/
{
/**
* 注册自定义事件
* @param {Object} config
* @param {String} config.ev
* @param {Function} config.fn
*/
ev : function() {
if(arguments.length == 1) {
var evCfg = arguments[0];
var scope = evCfg.scope || this;
if($kit.isFn(evCfg.fn) && $kit.isStr(evCfg.ev)) {
var evCfg = {
ev : evCfg.ev,
fn : evCfg.fn,
scope : this
};
this.event = this.event || {};
this.event[evCfg.ev] = this.event[evCfg.ev] || [];
this.event[evCfg.ev].push(evCfg);
}
}
},
/**
* 触发自定义事件
* @param {Object} config
* @param {String} config.ev
*/
newEv : function() {
if(arguments.length == 1 && !$kit.isEmpty(this.event)) {
var evAry, evCfg, _evCfg = {};
if($kit.isStr(arguments[0])) {
var ev = arguments[0];
evAry = this.event[ev];
} else if($kit.isObj(arguments[0])) {
_evCfg = arguments[0];
evAry = this.event[_evCfg.ev];
}
if(!$kit.isEmpty(evAry)) {
for(var i = 0; evAry != null && i < evAry.length; i++) {
evCfg = $kit.merge(evAry[i], _evCfg);
var e = {
target : this,
type : evCfg.ev
}
evCfg.fn.call(evCfg.scope, e, evCfg);
}
}
}
}
});
/**
* 简单编辑器
* @class $kit.ui.Editor.SimpleEditor
* @extends $kit.ui.Editor
* @requires kit.js
* @requires ieFix.js
* @requires dom.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Editor/simpleeditor.js">Source code</a>
* @example
* <a href="http://xueduany.github.com/KitJs/KitJs/demo/SimpleEditor/demo.html">Demo</a><br/>
* <img src="http://xueduany.github.com/KitJs/KitJs/demo/SimpleEditor/demo.png">
*/
$kit.ui.Editor.SimpleEditor = function(config) {
var me = this;
$kit.inherit({
child : $kit.ui.Editor.SimpleEditor,
father : $kit.ui.Editor
});
me.config = $kit.join(me.constructor.defaultConfig, config);
}
$kit.merge($kit.ui.Editor.SimpleEditor,
/**
* @lends $kit.ui.Editor.SimpleEditor
*/
{
/**
* @enum
*/
defaultConfig : {
kitWidgetName : "kitSimpleEditor",
el : undefined,
template : {
editorHTML : [//
'<div class="${editorCommandCls}">', //
'<button class="${editorCommandPrefixCls}bold">加粗</button>', //
'<button class="${editorCommandPrefixCls}highlight">高亮</button>', //
'<button class="${editorCommandPrefixCls}italic ">斜体</button>', //
'</div>', //
'<div class="${editorContentCls}">', //
'<iframe class="${editorIframeCls}"></iframe>', //
'</div>' //
].join(''),
editorCommandCls : 'kitjs-editor-command',
editorWrapperCls : 'kitjs-editor-wrapper',
editorCommandPrefixCls : 'editor-command-',
editorContentCls : 'kitjs-editor-content',
editorSourceCls : 'kitjs-editor-source',
editorIframeCls : 'kitjs-editor-iframe'
}
}
});
$kit.merge($kit.ui.Editor.SimpleEditor.prototype,
/**
* @lends $kit.ui.Editor.SimpleEditor.prototype
*/
{
/**
* 初始化
*/
build : function() {
var me = this;
var editorHTML = $kit.tpl(me.config.template.editorHTML, me.config.template);
var wrapper = document.createElement('div');
wrapper.className = me.config.template.editorWrapperCls;
me.wrapper = wrapper;
$kit.rpEl(me.config.el, wrapper);
wrapper.innerHTML = editorHTML;
me._intervalIframeReadyCount = 0;
me._intervalIframeReady = setInterval(function() {
me._intervalIframeReadyCount++;
var editorIframe = $kit.el8cls(me.config.template.editorIframeCls, wrapper);
me.editorIframe = editorIframe;
if(me._intervalIframeReadyCount > 10000) {
clearInterval(me._intervalIframeReady);
}
if(!$kit.isEmpty(me.editorIframe.contentWindow)) {
clearInterval(me._intervalIframeReady);
me.doc = editorIframe.contentWindow.document;
me.doc.designMode = 'on';
me.doc.contentEditable = true;
me.doc.compatMode = 'CSS1Compat';
$kit.css(me.doc.body, {
margin : 0,
padding : 0,
width : editorIframe.offsetWidth - 20 - $kit.css(editorIframe, 'border-width'),
'overflowX' : 'hidden',
'overflowY' : 'auto',
'word-wrap' : 'break-word',
'word-break' : 'break-all'
})
}
}, 300);
me.editorCommand = $kit.el8cls(me.config.template.editorCommandCls, wrapper);
$kit.ev({
el : me.editorCommand,
ev : 'click',
fn : function(e) {
var el = e.target;
if(el.tagName && el.tagName.toLowerCase() == 'button') {
var command = $kit.dom.getClassNameByPrefix(el, me.config.template.editorCommandPrefixCls).substring(me.config.template.editorCommandPrefixCls.length);
me.excuteCommand(command);
}
},
scope : me
})
},
/**
* 执行命令
* @param {String}
*/
excuteCommand : function(command) {
var me = this;
if(command == 'bold') {
me.doc.execCommand('bold', false, null);
} else if(command == 'highlight') {
me.doc.execCommand('backcolor', false, 'orange');
me.doc.execCommand('forecolor', false, 'white');
} else if(command == 'italic') {
me.doc.execCommand('italic', false, null);
}
}
});
$kit.$(function() {
$kit.widgetInstance = {};
var defaultConfig = $kit.ui.Form.TextArea.defaultConfig;
$kit.each($kit.els8cls(defaultConfig.textAreaCls), function(currentOne, idx, array) {
$kit.widgetInstance[defaultConfig.kitWidgetName] = $kit.widgetInstance[defaultConfig.kitWidgetName] || [];
$kit.widgetInstance[defaultConfig.kitWidgetName].push(new $kit.ui.Form.TextArea({
el : currentOne,
minRows : 1 || $kit.attr(currentOne, 'minrows'),
autoFixHeight : true || $kit.attr(currentOne, 'autofixheight')
}));
});
});
/**
* combobox
* @class $kit.ui.Form.ComboBox
* @extends $kit.ui.Form
* @requires kit.js
* @requires ieFix.js
* @see <a href="https://github.com/xueduany/KitJs/blob/master/KitJs/src/js/widget/Form/combobox.js">Source code</a>
* @example
* <a href="http://xueduany.github.com/KitJs/KitJs/demo/Combobox/combobox.html">Demo</a><br/>
* <img src="http://xueduany.github.com/KitJs/KitJs/demo/Combobox/demo.png">
*/
$kit.ui.Form.ComboBox = function(config) {
$kit.inherit({
child : $kit.ui.Form.ComboBox,
father : $kit.ui.Form
});
var me = this;
me.config = $kit.join(me.constructor.defaultConfig, config);
me.init();
}
$kit.merge($kit.ui.Form.ComboBox,
/**
* @lends $kit.ui.Form.ComboBox
*/
{
/**
* @enum
*/
defaultConfig : {
el : undefined,
kitWidgetName : 'kitFormComboBox',
transformCls : 'kitjs-form-combobox',
inputCls : 'kitjs-form-combobox-input',
wrapperCls : 'kitjs-form-combox-wrapper',
/**
* 延时
* @type {Number}
*/
suggestDelay : 500
}
});
$kit.merge($kit.ui.Form.ComboBox.prototype,
/**
* @lends $kit.ui.Form.ComboBox.prototype
*/
{
/**
* 初始化
*/
init : function() {
var me = this;
//me.transform();
},
/**
* 变形为comboBox
*/
transform : function() {
var me = this;
this.wrapper = document.createElement('div');
$kit.adCls(this.wrapper, this.config.wrapperCls);
this.inputEl = document.createElement('input');
this.inputEl.className = me.config.inputCls;
this.inputEl.type = 'text';
//formEl
this.formEl = document.createElement('input');
this.formEl.type = 'hidden';
if(me.config.el.name) {
this.formEl.name = me.config.el.name;
}
//
this.wrapper.appendChild(me.inputEl);
this.wrapper.appendChild(me.formEl);
$kit.rpEl(this.config.el, this.wrapper);
//
this.fillData();
this.list = new $kit.ui.Form.List({
where : me.wrapper,
list : me.config.data.search(''),
triggleEl : me.inputEl,
formEl : me.formEl,
setValue : function(key, value) {
me.setValue(key, value, me.list.selectedLi);
me.newEv({
ev : 'change'
});
}
});
$kit.ev({
el : me.inputEl,
ev : 'input change',
fn : function(e) {
var me = this;
me._inputChange();
},
scope : me
});
$kit.ev({
el : me.inputEl,
ev : 'propertychange',
fn : function(e) {
var me = this;
if(e.propertyName.toLowerCase() == 'value') {
me._inputChange();
}
},
scope : me
});
$kit.ev({
el : me.inputEl,
ev : 'focus',
fn : function(e) {
var me = this;
me.hasFocus = true;
},
scope : me
});
$kit.ev({
el : me.inputEl,
ev : 'blur',
fn : function(e) {
var me = this;
me.hasFocus = false;
me._blur && me._blur();
me._inputChange();
},
scope : me
});
//
},
_inputChange : function() {
var me = this;
clearTimeout(me._timeout_suggest);
me._timeout_suggest = setTimeout(function() {
me.suggest();
me._setFormValue();
me.newEv({
ev : 'change'
});
}, me.config.suggestDelay);
},
/**
* 给隐藏表单元素赋值
* @private
*/
_setFormValue : function() {
var me = this;
if(me.list.listItemCount == 1 && me.inputEl.value == $kit.attr($kit.el8cls(me.list.config.listItemCls, me.list.listEl), 'key')) {
me.formEl.value = $kit.attr($kit.el8cls(me.list.config.listItemCls, me.list.listEl), 'value');
} else {
me.formEl.value = me.inputEl.value;
}
},
/**
* 填充数据
*/
fillData : function() {
if($kit.isEmpty(this.config.data)) {
this.config.data = new $kit.TreeDict();
if(this.config.el.tagName && this.config.el.tagName.toLowerCase() == 'select') {
var select = this.config.el;
for(var i = 0; i < select.options.length; i++) {
var option = select.options[i];
this.config.data.ad(option.text, option.value);
}
}
}
},
/**
* 智能提示
*/
suggest : function() {
var me = this;
$kit.adCls(me.wrapper, 'suggesting');
setTimeout(function() {
me.list.buildList(me.config.data.search(me.inputEl.value));
if(me.hasFocus && me.list._flag_listEl_mousedown_ev != true) {
if(me.list.listItemCount == 1) {
var li = $kit.el8cls(me.list.config.listItemCls, me.list.listEl);
if(me.inputEl.value == $kit.attr(li, 'key')) {
me.list.selectedLi = li;
$kit.adCls(me.list.selectedLi, me.list.config.selectedCls);
}
}
me.list.show();
}
if(me.list._flag_listEl_mousedown_ev == true) {
me.list._flag_listEl_mousedown_ev = false;
}
setTimeout(function() {
$kit.rmCls(me.wrapper, 'suggesting')
}, 200);
}, 0);
},
/**
* js赋值API
*/
setValue : function(key, value, selectedLi) {
var me = this;
if(key == null) {
return;
}
me.inputEl.value = key;
value = value || null;
if(value == null) {
value = this.data.get(key);
}
me.formEl.value = value;
selectedLi = selectedLi || null;
if(selectedLi == null) {
var a = [];
if(me.list.listEl.getElementsByClassName) {
a = $kit.els8cls(me.list.config.listItemCls);
} else {
a = me.list.listEl.childNodes;
}
for(var i = 0; i < a.length; i++) {
if($kit.hsCls(a[i], me.list.listItemCls)) {
if($kit.attr(a[i], 'key') == key) {
selectedLi = a[i];
}
}
}
}
me.list.selectedLi = selectedLi;
},
_blur : function() {
//
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment