javaeye3/public/javascripts/support.js

87 lines
2.7 KiB
JavaScript

function checkForm(boxes, msg) {
var i = 0;
boxes.each(function(e){ i += e.checked; });
if(i < 1) {
var message = '请选择条目';
alert(message);return false;
}else{
return confirm(msg);
}
}
function checkAll(boxes, is_checked) {
if(is_checked){
boxes.each(function(e){
e.checked = true;
});
} else {
boxes.each(function(e){
e.checked = false;
});
}
}
function colSort(th, order){
order = typeof order !== "undefined" ? order : 0;
var tb = th.parentNode.parentNode.parentNode.tBodies[0];
var arr = [];
for(var i=0; i<tb.rows.length; i++) {
var cell = tb.rows[i].cells[th.cellIndex];
do {
cell = cell.firstChild;
}
while(cell != null && cell.nodeType != 3)
var txt = "";
for(var n = cell; n !== null; n.nextSibling) {
if(n.nodeType === 3) {
txt = document.all ? n.nodeValue : n.nodeValue.replace(/^\\n*|^\s*|\s*$|\\n*$/g, "");
break;
}
}
arr.push([txt, tb.rows[i].rowIndex]);
}
arr.sort(function(a, b) { return a[0].localeCompare(b[0]); });
var ntab = tb.parentNode.cloneNode(true);
while(tb.rows.length > 0) tb.deleteRow(0);
if(order) {
for(var i=(arr.length-1); i>=0; i--) tb.appendChild(ntab.rows[arr[i][1]].cloneNode(true));
} else {
for(var i=0; i<arr.length; i++) tb.appendChild(ntab.rows[arr[i][1]].cloneNode(true));
}
for(var i=0; i<tb.rows.length; i++) {
var new_class = (i % 2)==1 ? 'backgray' : '';
var old_class = tb.rows[i].className.replace('backgray', '').replace(/(^\s*)|(\s*$)/g, '');
tb.rows[i].className = old_class + (old_class.length>1 ? ' ' : '') + new_class;
}
th.onclick = function() { colSort(this, !order) };
}
function count_limit_input(element, total) {
var content = element.value;
var chinese_charsets = content.match(/[\u0391-\uFFE5]/g)
var no_chinese_charsets = content.match(/[^\u0391-\uFFE5]/g)
var count = 0;
if (chinese_charsets) { count += chinese_charsets.size(); }
if (no_chinese_charsets) { count += no_chinese_charsets.size() / 2; }
var over = parseInt(total - count);
var notice = element.next('.count_notice');
if (notice) {
notice.update('剩余' + over + '字');
} else {
element.insert({after: '<span class="count_notice">剩余' + over + '字</span>'});
};
if (over < 0) {
element.next('.count_notice').addClassName('overflow');
$('submit_button').disable();
} else {
element.next('.count_notice').removeClassName('overflow');
$('submit_button').enable();
}
}
function limit_input(element, total) {
count_limit_input(element, total);
element.observe('input', function(event) {
count_limit_input(element, total);
});
};