/*
|
* 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('<i class="fa fa-dot-circle-o"></i>');
|
} else {
|
$(e).after('<i class="fa fa-circle"></i>');
|
}
|
|
$(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('<i class="fa fa-check-square"></i>');
|
} else {
|
$(e).after('<i class="fa fa-square"></i>');
|
}
|
|
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('<span class="file-uploader-row"><input class="text text-uploader text-' + $(e).attr('name') + '" type="text" readonly><button class="btn btn-uploader btn-' + $(e).attr('name') + '"><i class="fa fa-upload"></i>选择文件</button></span>');
|
|
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('<div class="select-container select-container-primary"></div>');
|
} else if ($(e).hasClass('select-info')) {
|
$(e).wrap('<div class="select-container select-container-info"></div>');
|
} else if ($(e).hasClass('select-danger')) {
|
$(e).wrap('<div class="select-container select-container-danger"></div>');
|
} else if ($(e).hasClass('select-success')) {
|
$(e).wrap('<div class="select-container select-container-success"></div>');
|
} else if ($(e).hasClass('select-warning')) {
|
$(e).wrap('<div class="select-container select-container-warning"></div>');
|
} else {
|
$(e).wrap('<div class="select-container"></div>');
|
}
|
|
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('<div class="alert-msg"><div class="shade"></div><div class="popmsg' + msg.style + '"><span class="popmsg-title"><i class="fa fa-info-circle"></i>' + msg.title + '</span><span class="popmsg-content">' + msg.text + '</span><span class="popmsg-close"><button class="btn btn-close-alert' + msg.btnCloseStyle + '">关闭</button></span></div></div>');
|
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('<div class="confirm-msg"><div class="shade"></div><div class="popmsg' + msg.style + '"><span class="popmsg-title"><i class="fa fa-info-circle"></i>' + msg.title + '</span><span class="popmsg-content">' + msg.text + '</span><span class="popmsg-close"><button class="btn mr5 btn-close-yes' + msg.btnCloseStyle + '">Yes</button><button class="btn btn-close-no' + msg.btnCloseStyle + '">No</button></span></div></div>');
|
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('<div class="cbdialog-container"><div class="shade"></div><div class="cbdialog' + dialog.dialogStyle + '"><span class="cbdialog-title"><i class="fa fa-th-large"></i>' + dialog.dialogTitleText + '<button class="btn btn-close-cbdialog' + dialog.btnCloseStyle + '" title="关闭窗口"><i class="fa fa-remove"></i></button><button class="btn btn-maximum-cbdialog' + dialog.btnCloseStyle + '" title="最大化窗口"><i class="fa fa-folder"></i></button></span><span class="cbdialog-content"><iframe id="dialog-iframe" src="' + dialog.dialogURL + '" width="100%" frameborder="0"></span></div></div>');
|
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('<i class="fa fa-folder-open"></i>').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('<i class="fa fa-folder"></i>').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('<i class="glyphicon glyphicon-calendar"></i>'); });
|
|
/* 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()); });
|