✏️ 正在编辑: global.js
路径:
/srv/systems_dir/koruspay/public/scripts/global.js
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
// =================================================================== // Author: Matt Kruse <matt@mattkruse.com> // WWW: http://www.mattkruse.com/ // // NOTICE: You may use this code for any purpose, commercial or // private, without any further permission from the author. You may // remove this notice from your final code if you wish, however it is // appreciated by the author if at least my web site address is kept. // // You may *NOT* re-distribute this code in any way except through its // use. That means, you can include it in your product, or your web // site, or any other form where the code is actually being used. You // may not put the plain javascript up on your site for download or // include it in your javascript libraries for download. // If you wish to share this code with others, please just point them // to the URL instead. // Please DO NOT link directly to my .js files from your site. Copy // the files to your server and use them there. Thank you. // =================================================================== // HISTORY // ------------------------------------------------------------------ // February 29, 2004: Fixed bug caused by LAST update, when control // checkbox is the first on checked. I hate when that happens. // January 28, 2004: Fixed bug that occurred when checkbox was CHECKED // by default. // December 16, 2002: Created /* Original coding done by David Rogers - http://www.MrDaveR.com/ DESCRIPTION: This library lets you quickly and easily make multiple checkboxes behave as a group by limiting the total number of boxes that can be checked and/or have a master control checkbox. COMPATABILITY: Should work on all Javascript-compliant browsers. USAGE: // Create a new CheckBoxGroup object var myOptions = new CheckBoxGroup(); // Tell the object which checkboxes exist in your group. You may make multiple // calls to this function, and/or pass multiple arguments. You may specify // field names exactly, or use a wildcard at the beginning or end of the // name. myOptions.addToGroup("cb1","cb2","optionset*"); myOptions.addToGroup("*checkbox"); // Optionally set a "control" box which will effect all other boxes. myOptions.setControlBox("masterCheckboxName"); // Specify how your control box will interact with the group. Options are // either "some" or "all" ("all" is default). // all: Checking the box will select all the other boxes. Unchecking it will // uncheck all the group checkboxes. Selecting all the checkboxes in // the group will automatically check the control box. // some: Checking any checkbox in the group will check the control box. The // control box may not be unchecked if any option in the group is // still checked. If no boxes in the group are checked, you may still // check the control box. myOptions.setMasterBehavior("some"); // Optionally set the maximum number of boxes in the group which are allowed // to be checked. You may pass a second argument which is an alert message to // be displayed to the user if they exceed this limit. myOptions.setMaxAllowed(3); myOptions.setMaxAllowed(3,"You may only select 3 choices!"); // IMPORTANT: After defining the group and behavior, you must insert an action // into EVERY checkbox's onClick event-handler. Just specify the name of the // group object that the checkbox belongs to, and pass it 'this' as the argument. <INPUT TYPE="checkbox" NAME="cb1" onClick="myOptions.check(this)"> // That's it! Your checkboxes will now behave as a group! */ function CheckBoxGroup() { this.controlBox=null; this.controlBoxChecked=null; this.maxAllowed=null; this.maxAllowedMessage=null; this.masterBehavior=null; this.formRef=null; this.checkboxWildcardNames=new Array(); this.checkboxNames=new Array(); this.totalBoxes=0; this.totalSelected=0; // Public methods this.setControlBox=CBG_setControlBox; this.setMaxAllowed=CBG_setMaxAllowed; this.setMasterBehavior=CBG_setMasterBehavior; // all, some this.addToGroup=CBG_addToGroup; // Private methods this.expandWildcards=CBG_expandWildcards; this.addWildcardCheckboxes=CBG_addWildcardCheckboxes; this.addArrayCheckboxes=CBG_addArrayCheckboxes; this.addSingleCheckbox=CBG_addSingleCheckbox; this.check=CBG_check; } // Set the master control checkbox name function CBG_setControlBox(name) { this.controlBox=name; } // Set the maximum number of checked boxes in the set, and optionally // the message to popup when the max is reached. function CBG_setMaxAllowed(num,msg) { this.maxAllowed=num; if (msg!=null&&msg!="") { this.maxAllowedMessage=msg; } } // Set the behavior for the checkbox group master checkbox // All: all boxes must be checked for the master to be checked // Some: one or more of the boxes can be checked for the master to be checked function CBG_setMasterBehavior(b) { this.masterBehavior = b.toLowerCase(); } // Add checkbox wildcards to the checkboxes array function CBG_addToGroup() { if (arguments.length>0) { for (var i=0;i<arguments.length;i++) { this.checkboxWildcardNames[this.checkboxWildcardNames.length]=arguments[i]; } } } // Expand the wildcard checkbox names given in the addToGroup method function CBG_expandWildcards() { if (this.formRef==null) { alert("ERROR: No form element has been passed. Cannot extract form name!"); return false; } for (var i=0; i<this.checkboxWildcardNames.length;i++) { var n = this.checkboxWildcardNames[i]; var el = this.formRef[n]; if (n.indexOf("*")!=-1) { this.addWildcardCheckboxes(n); } else if(CBG_nameIsArray(el)) { this.addArrayCheckboxes(n); } else { this.addSingleCheckbox(el); } } } // Add checkboxes to the group which match a pattern function CBG_addWildcardCheckboxes(name) { var i=name.indexOf("*"); if ((i==0) || (i==name.length-1)) { searchString= (i)?name.substring(0,name.length-1):name.substring(1,name.length); for (var j=0;j<this.formRef.length;j++) { currentElement = this.formRef.elements[j]; currentElementName=currentElement.name; var partialName = (i)?currentElementName.substring(0,searchString.length) : currentElementName.substring(currentElementName.length-searchString.length,currentElementName.length); if (partialName==searchString) { if(CBG_nameIsArray(currentElement)) this.addArrayCheckboxes(currentElement); else this.addSingleCheckbox(currentElement); } } } } // Add checkboxes to the group which all have the same name function CBG_addArrayCheckboxes(name) { if((CBG_nameIsArray(this.formRef[name])) && (this.formRef[name].length>0)) { for (var i=0; i<this.formRef[name].length; i++) { this.addSingleCheckbox(this.formRef[name][i]); } } } function CBG_addSingleCheckbox(obj) { if (obj != this.formRef[this.controlBox]) { this.checkboxNames[this.checkboxNames.length]=obj; this.totalBoxes++; if (obj.checked) { this.totalSelected++; } } } // Runs whenever a checkbox in the group is clicked function CBG_check(obj) { var checked=obj.checked; if (this.formRef==null) { this.formRef=obj.form; this.expandWildcards(); if (this.controlBox==null || obj.name!=this.controlBox) { this.totalSelected += (checked)?-1:1; } } if (this.controlBox!=null&&obj.name==this.controlBox) { if (this.masterBehavior=="all") { for (i=0;i<this.checkboxNames.length;i++) { this.checkboxNames[i].checked=checked; } this.totalSelected=(checked)?this.checkboxNames.length:0; } else { if (!checked) { obj.checked = (this.totalSelected>0)?true:false; obj.blur(); } } } else { if (this.masterBehavior=="all") { if (!checked) { this.formRef[this.controlBox].checked=false; this.totalSelected--; } else { this.totalSelected++; } if (this.controlBox!=null) { this.formRef[this.controlBox].checked=(this.totalSelected==this.totalBoxes)?true:false; } } else { if (!obj.checked) { this.totalSelected--; } else { this.totalSelected++; } if (this.controlBox!=null) { this.formRef[this.controlBox].checked=(this.totalSelected>0)?true:false; } if (this.maxAllowed!=null) { if (this.totalSelected>this.maxAllowed) { obj.checked=false; this.totalSelected--; if (this.maxAllowedMessage!=null) { alert(this.maxAllowedMessage); } return false; } } } } } function CBG_nameIsArray(obj) { return ((typeof obj.type!="string")&&(obj.length>0)&&(obj[0]!=null)&&(obj[0].type=="checkbox")); } //Abrir caixa de dialogo modal function openDialog(obj, url){ $("#" + obj).load(url).dialog({ height: 600, width: 980, modal:true, close: function(event,ui){ $(obj).dialog('destroy'); } }); } function openDialogObj(obj, width, height){ $("#" + obj).dialog({ height: height, width: width, modal:true, close: function(event,ui){ $(obj).dialog('destroy'); } }); $('#btn_save').click(function(){ $('#f_extrato').submit(); }); } /** * Mascaras */ function mascara(o,f){ v_obj=o v_fun=f setTimeout("execmascara()",1) } function execmascara(){ v_obj.value=v_fun(v_obj.value) } function leech(v){ v=v.replace(/o/gi,"0") v=v.replace(/i/gi,"1") v=v.replace(/z/gi,"2") v=v.replace(/e/gi,"3") v=v.replace(/a/gi,"4") v=v.replace(/s/gi,"5") v=v.replace(/t/gi,"7") return v } function soNumeros(v){ return v.replace(/\D/g,"") } function telefone(v){ v=v.replace(/\D/g,"") //Remove tudo o que não é dígito v=v.replace(/^(\d\d)(\d)/g,"($1) $2") //Coloca parênteses em volta dos dois primeiros dígitos if( v.length == 13 ){ v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca hífen entre o quarto e o quinto dígitos }else{ v=v.replace(/(\d{5})(\d)/,"$1-$2") } return v } function fcpf(v){ v=v.replace(/\D/g,"") //Remove tudo o que não é dígito v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos v=v.replace(/(\d{3})(\d)/,"$1.$2") //Coloca um ponto entre o terceiro e o quarto dígitos //de novo (para o segundo bloco de números) v=v.replace(/(\d{3})(\d{1,2})$/,"$1-$2") //Coloca um hífen entre o terceiro e o quarto dígitos return v } function data(v){ v=v.replace(/\D/g,"") v=v.replace(/(\d{2})(\d)/,"$1/$2") v=v.replace(/(\d{2})(\d)/,"$1/$2") return v } function mesAno(v) { v=v.replace(/\D/g,"") v=v.replace(/(\d{2})(\d)/,"$1/$2") return v } function fcep(v){ v=v.replace(/\D/g,"") //Remove tudo o que não é dígito v=v.replace(/^(\d{5})(\d)/,"$1-$2") //Esse é tão fácil que não merece explicações return v } function fcnpj(v){ v=v.replace(/\D/g,"") //Remove tudo o que não é dígito v=v.replace(/^(\d{2})(\d)/,"$1.$2") //Coloca ponto entre o segundo e o terceiro dígitos v=v.replace(/^(\d{2})\.(\d{3})(\d)/,"$1.$2.$3") //Coloca ponto entre o quinto e o sexto dígitos v=v.replace(/\.(\d{3})(\d)/,".$1/$2") //Coloca uma barra entre o oitavo e o nono dígitos v=v.replace(/(\d{4})(\d)/,"$1-$2") //Coloca um hífen depois do bloco de quatro dígitos return v } function romanos(v){ v=v.toUpperCase() //Maiúsculas v=v.replace(/[^IVXLCDM]/g,"") //Remove tudo o que não for I, V, X, L, C, D ou M //Essa é complicada! Copiei daqui: http://www.diveintopython.org/refactoring/refactoring.html while(v.replace(/^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$/,"")!="") v=v.replace(/.$/,"") return v } function site(v){ v=v.replace(/^http:\/\/?/,"") dominio=v caminho="" if(v.indexOf("/")>-1) dominio=v.split("/")[0] caminho=v.replace(/[^\/]*/,"") dominio=dominio.replace(/[^\w\.\+-:@]/g,"") caminho=caminho.replace(/[^\w\d\+-@:\?&=%\(\)\.]/g,"") caminho=caminho.replace(/([\?&])=/,"$1") if(caminho!="")dominio=dominio.replace(/\.+$/,"") v="http://"+dominio+caminho return v } function hora(v){ v=v.replace(/\D/g,"") //Remove tudo o que não é dígito v=v.replace(/(\d{2})(\d)/,"$1:$2") //Coloca um ponto entre o segundo e o terceiro dígitos return v } function maiusculo(v){ v.value = v.value.toUpperCase(); } function mvalor(v){ v=v.replace(/\D/g,"");//Remove tudo o que não é dígito v=v.replace(/(\d)(\d{8})$/,"$1.$2");//coloca o ponto dos milhões v=v.replace(/(\d)(\d{5})$/,"$1.$2");//coloca o ponto dos milhares v=v.replace(/(\d)(\d{2})$/,"$1,$2");//coloca a virgula antes dos 2 últimos dígitos return v; } function aniversario(v){ v=v.replace(/\D/g,"") v=v.replace(/(\d{2})(\d)/,"$1/$2") return v } /*Fim das mascaras*/ function relogio(){ momentoAtual = new Date() hora = momentoAtual.getHours() minuto = momentoAtual.getMinutes() segundo = momentoAtual.getSeconds() horaImprimivel = hora + " : " + minuto + " : " + segundo document.getElementById("relogio").value = horaImprimivel setTimeout("relogio()",1000) } function openWin(url, width, height, scrollbar){ //pega a resolu��o do visitante w = screen.width; h = screen.height; //divide a resolu��o por 2, obtendo o centro do monitor meio_w = w/2; meio_h = h/2; //diminui o valor da metade da resolu��o pelo tamanho da janela, fazendo com q ela fique centralizada altura2 = height/2; largura2 = width/2; meio1 = meio_h-altura2; meio2 = meio_w-largura2; window.open (url, "","menubar=1,resizable=0,location=0,status=1,scrollbars="+scrollbar+", width="+width+",height="+height+", top="+meio1+", left="+meio2); } function confirmaLink(url){ if(confirm('Tem certeza que deseja executar essa operação?', url)){ window.location = url; } return false; } function validarForm(form){ var f = form; var cont = 0; for (i=0;i<f.elements.length;i++){ if(f.elements[i].className == "require" && f.elements[i].value == ""){ alert('Atenção! Preencha todos os campos corretamente.'); f.elements[i].focus(); f.elements[i].style.borderColor = "#DF1B1B"; return false; break; } else{ f.elements[i].style.borderColor = ""; } } return true; } function validarChecks(form){ var cont = 0; for (i=0;i<form.elements.length;i++){ if(form.elements[i].type == "checkbox" && form.elements[i].checked == true){ cont++; } } if(cont <= 0){ alert("Marque pelo menos um ítem."); return false; } } function number_format( number, decimals, dec_point, thousands_sep ) { var n = number, prec = decimals; n = !isFinite(+n) ? 0 : +n; prec = !isFinite(+prec) ? 0 : Math.abs(prec); var sep = (typeof thousands_sep == "undefined") ? ',' : thousands_sep; var dec = (typeof dec_point == "undefined") ? '.' : dec_point; var s = (prec > 0) ? n.toFixed(prec) : Math.round(n).toFixed(prec); //fix for IE parseFloat(0.55).toFixed(0) = 0; var abs = Math.abs(n).toFixed(prec); var _, i; if (abs >= 1000) { _ = abs.split(/\D/); i = _[0].length % 3 || 3; _[0] = s.slice(0,i + (n < 0)) + _[0].slice(i).replace(/(\d{3})/g, sep+'$1'); s = _.join(dec); } else { s = s.replace('.', dec); } return s; } //setar cor de linha function selecionarLinha(obj){ // $(document).ready(function(){ //percorre os inputs para identificar se já estão selecionados e muda a cor da linha // var ipts = $(".linha_nao_paga").find("input"); // jQuery.each(ipts, function(){ // if (this.checked == true) { // id = $(this).attr('rel'); // $("#tr_"+id).css('background-color', 'green'); // // } else { // id = $(this).attr('rel'); // $("#tr_"+id).css('background-color', '#F2F2F2'); // } // }); // $(obj).click(function() { if (obj.checked == true) { id = $(obj).attr('rel'); $("#tr_"+id).addClass('linha_selecionada'); console.log('linha selecionada'); } else { id = $(obj).attr('rel'); $("#tr_"+id).removeClass('linha_selecionada'); console.log('linha não selecionada'); } // }); // $('#control').click(function() { // if (this.checked == true) { // id = $(this).attr('rel'); // $(".linha_nao_paga").css('background-color', 'green'); // // } else { // id = $(this).attr('rel'); // $(".linha_nao_paga").css('background-color', '#F2F2F2'); // } // }); // }); } $(document).ready(function(){ $('table.selecionar tbody tr') .filter(':has(:checkbox:checked)') .addClass('selected') .end() .click(function(event) { if (event.target.type !== 'checkbox') { $(':checkbox', this).trigger('click'); } }) .find(':checkbox') .click(function(event) { $(this).parents('tr:first').toggleClass('linha_selecionada'); }); // $('form :text, textarea').keyup(function() { // this.style = "text-transform: uppercase"; // var upper = this.value.toUpperCase(); // if (this.value != upper){ // this.value = upper; // } // }); }); function fPassaAlfaNumerico(oEvent, strTipo) { if ( ( (oEvent.keyCode >= 32 ) && (oEvent.keyCode <= 47 ) ) || ( (oEvent.keyCode >= 58 ) && (oEvent.keyCode <= 64 ) ) || ( (oEvent.keyCode >= 91 ) && (oEvent.keyCode <= 96 ) ) || ( (oEvent.keyCode >= 123) )) { oEvent.returnValue = 0; } //-- Letras if( (strTipo == "a") || (strTipo == "A") ) { if ( (oEvent.keyCode >= 48 ) && (oEvent.keyCode <= 57 ) ) { oEvent.returnValue = 0; } } //-- Numeros if( (strTipo == "n") || (strTipo == "N") ) { if ( ( (oEvent.keyCode >= 65 ) && (oEvent.keyCode <= 90 ) ) || ( (oEvent.keyCode >= 97 ) && (oEvent.keyCode <= 122) ) || ( (oEvent.keyCode == 32 ) ) ) { oEvent.returnValue = 0; } } } var myOptions = new CheckBoxGroup(); myOptions.setControlBox("control"); myOptions.addToGroup("checks[]"); myOptions.setMasterBehavior("all"); $(document).ready(function() { $('tr.selecionar') .filter(':has(:checkbox:checked)') .addClass('selected') .end() .click(function(event) { $(this).toggleClass('selected'); if (event.target.type !== 'checkbox') { $(':checkbox', this).attr('checked', function() { return !this.checked; }); } }); }); Number.prototype.formatMoney = function(c, d, t){ var n = this, c = isNaN(c = Math.abs(c)) ? 2 : c, d = d == undefined ? "." : d, t = t == undefined ? "," : t, s = n < 0 ? "-" : "", i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); }; function hideShowTableColumn(element){ var $table = $("#sortedTable"); cols = $(element).val(); colspan = $table.find('thead tr:eq(0) td:eq(0)').attr('colspan'); if (colspan > 0) { $table.find('thead tr:eq(1) *:nth-child('+ cols +')').toggle(); } else { $table.find('thead tr:eq(0) *:nth-child('+ cols +')').toggle(); } $table.find('tbody tr *:nth-child('+ cols +')').toggle(); $table.find('tfoot tr *:nth-child('+ cols +')').toggle(); $table.find("tfoot td").attr('colspan', cols.length); } function resetElements(form) { var frm_elements = form.elements; for (i = 0; i < frm_elements.length; i++) { field_type = frm_elements[i].type.toLowerCase(); switch (field_type) { case "text": case "date": case "password": case "textarea": case "hidden": form.elements[i].value = ""; break; case "radio": case "checkbox": if (frm_elements[i].checked) { frm_elements[i].checked = false; } break; case "select-one": case "select-multi": frm_elements[i].selectedIndex = -1; break; default: break; } } } function selectAll(textareaFieldId) { var textVal = document.getElementById(textareaFieldId); textVal.focus(); // Focus on textarea textVal.select();// Select all text document.execCommand("Copy"); alert('Dados copiados. Use ctrl + V para fazer a colagem no local desejado!'); }
💾 保存文件
← 返回文件管理器