/*
* CBUI 1.0
* Last update @ 2016-08-17 15:35
* By Poly Tam
* (C) Shenzhen CBSCS CO., Ltd.
*/
/* ===== Menu ===== */
/* Function List */
/* Input Radio */
/* Input Checkbox */
/* File Uploader */
/* Select */
/* Table */
/* Alert Pop Message */
/* Pop Message */
/* CBUI Dialog */
/* Date Picker */
/* Progress Bar */
/* Customized */
/* Function List */
//Write Content
function Write(c) { return document.write(c); }
//screenLeft与screenX兼容
function leftX() { return (typeof (screenLeft) == 'number') ? screenLeft : screenX; }
//screenTop与screenY兼容
function topY() { return (typeof (screenTop) == 'number') ? screenTop : screenY; }
//Auto Position
function autoPosition(ele) {
function init() {
$('#' + ele).css({
'top': ((function () {
if (typeof window.innerHeight != 'undefined') {
return window.innerHeight;
} else {
return document.documentElement.clientHeight - 26;
}
})() - $('#' + ele).height()) / 2 + 'px', 'left': ((function () {
if (typeof window.innerWidth != 'undefined') {
return window.innerWidth;
} else {
return document.documentElement.clientWidth;
}
})() - $('#' + ele).width()) / 2 + 'px'
});
}
init();
$(window).resize(function () {
init();
});
}
//IFrame AutoSize
function autoFrameSize(ele, siblingsSize) {
function init() {
$('#' + ele).css('height', (function () {
if (typeof window.innerHeight != 'undefined') {
return window.innerHeight - siblingsSize;
} else {
return document.documentElement.clientHeight - siblingsSize;
}
})() + 'px');
}
init();
$(window).resize(function () {
init();
});
}
/* Input Radio */
$('.radio').each(function (i, e) {
if ($(e).attr('checked')) {
$(e).after('');
} else {
$(e).after('');
}
$(e).next('i').click(function () {
if ($(e).attr('disabled') || $(e).attr('checked')) { return; }
$(e).attr('checked', 'checked').next('i').attr('class', 'fa fa-dot-circle-o').siblings('i').attr('class', 'fa fa-circle').siblings($(e)).removeAttr('checked');
});
});
/* Input Checkbox */
$('.checkbox').each(function (i, e) {
if ($(e).attr('checked')) {
$(e).after('');
} else {
$(e).after('');
}
var toggleCheck = 1;
$(e).next('i').click(function () {
if ($(e).attr('disabled')) { return; }
if (toggleCheck == 1) {
$(e).attr('checked', 'checked').next('i').attr('class', 'fa fa-check-square');
toggleCheck = 0;
} else {
$(e).removeAttr('checked').next('i').attr('class', 'fa fa-square');
toggleCheck = 1;
}
});
});
/* File Uploader */
$('.file-uploader').each(function (i, e) {
$(e).after('');
if ($(e).attr('disabled')) {
$('.text-' + $(e).attr('name')).eq(i).attr('disabled', 'disabled');
$('.btn-' + $(e).attr('name')).eq(i).attr('disabled', 'disabled').css('background', '#ccc');
}
$('.btn.btn-uploader').eq(i).click(function () { $(e).trigger('click'); });
$(e).change(function () {
$('.text.text-uploader').eq(i).val($(e).val().substr($(e).val().lastIndexOf('\\') + 1));
});
});
/* Select */
$('.select').each(function (i, e) {
if (BrowserDetect.browser == 'Internet Explorer') {
$(e).removeClass('select');
} else {
if ($(e).hasClass('select-primary')) {
$(e).wrap('
');
} else if ($(e).hasClass('select-info')) {
$(e).wrap('');
} else if ($(e).hasClass('select-danger')) {
$(e).wrap('');
} else if ($(e).hasClass('select-success')) {
$(e).wrap('');
} else if ($(e).hasClass('select-warning')) {
$(e).wrap('');
} else {
$(e).wrap('');
}
if ($(e).attr('disabled')) $(e).parent('.select-container').toggleClass('select-container-disabled');
if ($(e).hasClass('select-block')) {
$(e).parent('.select-container').addClass('select-container-block');
} else if ($(e).hasClass('select-block-half')) {
$(e).parent('.select-container').addClass('select-container-block-half');
} else if ($(e).hasClass('select-xs')) {
$(e).parent('.select-container').addClass('select-container-xs');
} else if ($(e).hasClass('select-sm')) {
$(e).parent('.select-container').addClass('select-container-sm');
} else if ($(e).hasClass('select-lg')) {
$(e).parent('.select-container').addClass('select-container-xl');
} else if ($(e).hasClass('select-xl')) {
$(e).parent('.select-container').addClass('select-container-lg');
} else {
$(e).parent('.select-container').addClass('');
}
}
});
/* Table */
//$('.dataTable').each(function(i,e) { $('tr:even').css('background', '#eee'); });
/* Alert Pop Message */
function alertMsg(params) {
var msg = null;
msg = {
text: params.text ? params.text : '这家伙很懒,提示的什么内容也不写。',
title: params.title ? params.title : '提示信息',
style: params.style ? ' popmsg-' + params.style : '',
btnCloseStyle: params.style ? ' btn-' + params.style : '',
autoClose: params.autoClose == true ? true : false,
draggable: params.drag == true ? true : false,
init: function () {
$(document.body).append('' + msg.title + '' + msg.text + '
');
document.onmousewheel = function () { return false; }
msg.resizeDialog();
$(window).resize(function () { msg.resizeDialog(); });
msg.dragDialog();
msg.closeDialog();
},
resizeDialog: function () {
$('.popmsg').css({ top: ($(window).height() - $('.popmsg').height()) / 2 + 'px', left: ($(window).width() - $('.popmsg').width()) / 2 + 'px' });
},
closeDialog: function () {
if (msg.autoClose) {
setTimeout(function () {
$('.alert-msg').remove();
}, 3000);
} else {
$('.btn.btn-close-alert').click(function () {
$('.alert-msg').remove();
});
}
document.onmousewheel = function () { return true; }
},
dragDialog: function () {
if (msg.draggable) { $('.popmsg').draggable({ cursor: "move" }); }
}
}
return msg;
}
/* Confirm Pop Message */
function confirmMsg(params) {
var msg = null;
msg = {
text: params.text ? params.text : '您确定要这样操作吗?',
title: params.title ? params.title : '提示信息',
style: params.style ? ' popmsg-' + params.style : '',
btnCloseStyle: params.style ? ' btn-' + params.style : '',
autoClose: params.autoClose == true ? true : false,
draggable: params.drag == true ? true : false,
init: function () {
$(document.body).append('' + msg.title + '' + msg.text + '
');
document.onmousewheel = function () { return false; }
msg.resizeDialog();
$(window).resize(function () { msg.resizeDialog(); });
msg.dragDialog();
msg.callDialog();
},
resizeDialog: function () {
$('.popmsg').css({ top: ($(window).height() - $('.popmsg').height()) / 2 + 'px', left: ($(window).width() - $('.popmsg').width()) / 2 + 'px' });
},
closeDialog: function () {
$('.confirm-msg').remove();
document.onmousewheel = function () { return true; }
},
dragDialog: function () {
if (msg.draggable) { $('.popmsg').draggable({ cursor: "move" }); }
},
callDialog: function () {
$('.btn.btn-close-yes').click(function () {
msg.closeDialog();
if (typeof params.callback == 'function') { params.callback(); }
});
$('.btn.btn-close-no').click(function () {
msg.closeDialog();
});
}
}
return msg;
}
/* CBUI Dialog */
function cbDialog(params) {
var dialog = null;
dialog = {
dialogWidth: params.width ? params.width : 600,
dialogHeight: params.height ? params.height : 320,
dialogURL: params.url ? params.url : 'http://m.baidu.com',
dialogStyle: params.style ? ' cbdialog-' + params.style : '',
dialogTitleText: params.title ? params.title : '弹出窗口',
btnCloseStyle: params.style ? ' btn-' + params.style : '',
draggable: params.drag == false ? false : true,
toggleResizeWindow: 1,
init: function () {
$(document.body).append('' + dialog.dialogTitleText + '
');
document.onmousewheel = function () { return false; }
dialog.dragDialog();
dialog.resizeDialogWindow();
$(window).resize(function () { dialog.resizeDialogWindow(); });
$('.btn.btn-close-cbdialog').click(function () { dialog.closeDialog(); });
$('.btn.btn-maximum-cbdialog').click(function () { dialog.maxDialogWindow(); });
$('.cbdialog-title').dblclick(function () { dialog.maxDialogWindow(); });
},
resizeDialogWindow: function () {
$('.cbdialog').css({ width: dialog.dialogWidth + 'px', height: dialog.dialogHeight + 'px', top: ($(window).height() - dialog.dialogHeight) / 2 + 'px', left: ($(window).width() - dialog.dialogWidth) / 2 + 'px' });
$('#dialog-iframe').height(dialog.dialogHeight - 43);
},
maxDialogWindow: function () {
if (dialog.toggleResizeWindow == 1) {
$('.cbdialog').css({ width: $(window).width() + 'px', height: $(window).height() + 'px', top: 0, left: 0 });
$('#dialog-iframe').height($(window).height() - 43);
$('.btn.btn-maximum-cbdialog').html('').attr('title', '还原窗口');
dialog.toggleResizeWindow = 0;
} else {
$('.cbdialog').css({ width: dialog.dialogWidth + 'px', height: dialog.dialogHeight + 'px', top: ($(window).height() - dialog.dialogHeight) / 2 + 'px', left: ($(window).width() - dialog.dialogWidth) / 2 + 'px' });
$('#dialog-iframe').height(dialog.dialogHeight - 43);
$('.btn.btn-maximum-cbdialog').html('').attr('title', '最大化窗口');
dialog.toggleResizeWindow = 1;
}
},
closeDialog: function () {
$('.cbdialog-container').remove();
location.reload();
document.onmousewheel = function () { return true; }
},
dragDialog: function () {
if (dialog.draggable) { $('.cbdialog').draggable({ cursor: "move" }); }
}
}
return dialog;
}
/* Date Picker */
$('.text.text-date').each(function (i, e) { $(e).after(''); });
/* Progress Bar */
function progressBar(barId, barNum, totalNum) {
var bar = null;
bar = {
init: function () {
if (barNum > totalNum) {
alertMsg({ style: 'danger', text: '进度条参数错误!' }).init();
return;
}
var tempNum = 0;
var si = setInterval(function () {
tempNum += 1;
$('#' + barId + ' .progress-bar').css('width', Math.floor(tempNum / totalNum * 100) + '%');
if (tempNum == barNum) clearInterval(si);
}, 100);
}
}
return bar;
}
/* Customized */
//Anchor Auto Title
$('a').each(function () { $(this).attr('title', $(this).text()); });