123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527 |
- var Namespace = new Object();
- Namespace.register = function(path) {
- var arr = path.split(".");
- var ns = "";
- for ( var i = 0; i < arr.length; i++) {
- if (i > 0)
- ns += ".";
- ns += arr[i];
- eval("if(typeof(" + ns + ") == 'undefined') " + ns + " = new Object();");
- }
- };
- jQuery.extend({
- /**
- * 根据名称全选或反选复选框。
- *
- * @param name
- * @param checked
- */
- checkAll : function(name, checked) {
- $("input[name='" + name + "']").attr("checked", checked);
- },
- /**
- * 根据复选框的名称获取选中值,使用逗号分隔。
- *
- * @param name
- * @returns {String}
- */
- getChkValue : function(name) {
- var str = "";
- $('input[type="checkbox"][name=' + name + ']').each(function() {
- if ($(this).attr('checked')) {
- str += $(this).val() + ",";
- }
- });
- if (str != "")
- str = str.substring(0, str.length - 1);
- return str;
- },
- /**
- * 根据名称获取下拉框的列表的值,使用逗号分隔。
- *
- * @param name
- * @returns {String}
- */
- getSelectValue : function(name) {
- var str = "";
- $('select[name=' + name + '] option').each(function() {
- str += $(this).val() + ",";
- });
- if (str != "")
- str = str.substring(0, str.length - 1);
- return str;
- },
- copyToClipboard : function(txt) {
- if (window.clipboardData) {
- window.clipboardData.clearData();
- window.clipboardData.setData("Text", txt);
- return true;
- } else if (navigator.userAgent.indexOf("Opera") != -1) {
- window.location = txt;
- return false;
- } else if (window.netscape) {
- try {
- netscape.security.PrivilegeManager
- .enablePrivilege("UniversalXPConnect");
- } catch (e) {
- alert($lang.tip.msg,$lang_js.util.copyToClipboard.netscape);
- return false;
- }
- var clip = Components.classes['@mozilla.org/widget/clipboard;1']
- .createInstance(Components.interfaces.nsIClipboard);
- if (!clip)
- return false;
- var trans = Components.classes['@mozilla.org/widget/transferable;1']
- .createInstance(Components.interfaces.nsITransferable);
- if (!trans)
- return false;
- trans.addDataFlavor('text/unicode');
- var str = Components.classes["@mozilla.org/supports-string;1"]
- .createInstance(Components.interfaces.nsISupportsString);
- var copytext = txt;
- str.data = copytext;
- trans.setTransferData("text/unicode", str,
- copytext.length * 2);
- var clipid = Components.interfaces.nsIClipboard;
- if (!clip)
- return false;
- clip.setData(trans, null, clipid.kGlobalClipboard);
- return true;
- } else {
- alert($lang.tip.msg,$lang_js.util.copyToClipboard.notCopy);
- return false;
- }
- },
- /**
- * 拷贝指定文本框的值。
- *
- * @param objId
- */
- copy : function(objId) {
- var str = $("#" + objId).val();
- var rtn = jQuery.copyToClipboard(str);
- if (rtn) {
- alert($lang_js.util.copy.success);
- }
- },
- /**
- * 判断是否是IE浏览器
- *
- * @returns {Boolean}
- */
- isIE : function() {
- if (!!window.ActiveXObject || "ActiveXObject" in window){
- return true;
- }
- else{
- return false;
- }
-
- },
- /**
- * 判断是否是IE6浏览器
- *
- * @returns {Boolean}
- */
- isIE6 : function() {
- if(($.browser.msie && $.browser.version =='6.0') &&!$.support.style)
- return true;
- return false;
- },
- /**
- * 序列化xmldom节点为一个xml。 用法: var sb=new StringBuffer(); var
- * str=jQuery.getChildXml(node,sb);
- *
- * @param node
- * xmldom节点。
- * @param sb
- * @returns
- */
- getChildXml : function(node, sb) {
- var nodes = node.childNodes;
- var len = nodes.length;
- for ( var i = 0; i < len; i++) {
- var childNode = nodes[i];
- if (childNode.nodeType != 1)
- continue;
- var childNodeName = childNode.nodeName;
- sb.append("<" + childNodeName + " ");
- var attrs = childNode.attributes;
- for ( var k = 0; k < attrs.length; k++) {
- var attr = attrs[k];
- sb.append(" " + attr.name + "=\"" + attr.value + "\" ");
- }
- sb.append(">");
- $.getChildXml(childNode, sb);
- sb.append("</" + childNodeName + ">");
- }
- },
- /**
- * 根据xmlnode序列化xml
- *
- * @param node
- * xmldom节点。
- * @returns
- */
- getChildXmlByNode : function(node) {
- var sb = new StringBuffer();
- jQuery.getChildXml(node, sb);
- return sb.toString();
- },
- /**
- * 根据xml节点,返回该节点的xml属性。 返回值通过参数ary获取。 用法: var node; var ary=new
- * Array(); $.getAttrXml(node,ary);
- *
- * @param node
- * @param ary
- */
- getAttrXml : function(node, ary) {
- var nodes = node.childNodes;
- var len = nodes.length;
- for ( var i = 0; i < len; i++) {
- var childNode = nodes[i];
- if (childNode.nodeType != 1)
- continue;
- var attrs = childNode.attributes;
- var obj = new Object();
- for ( var k = 0; k < attrs.length; k++) {
- var attr = attrs[k];
- obj[attr.name] = attr.value;
- }
- ary.push(obj);
- $.getAttrXml(childNode, ary);
- }
- },
- /**
- * <img src="img/logo.png" onload="$.fixPNG(this);"/>
- * 解决图片在ie中背景透明的问题。
- *
- * @param imgObj
- */
- fixPNG : function(imgObj) {
- var arVersion = navigator.appVersion.split("MSIE");
- var version = parseFloat(arVersion[1]);
- if ((version >= 5.5) && (version < 7)
- && (document.body.filters)) {
- var imgID = (imgObj.id) ? "id='" + imgObj.id + "' " : "";
- var imgClass = (imgObj.className) ? "class='"
- + imgObj.className + "' " : "";
- var imgTitle = (imgObj.title) ? "title='" + imgObj.title
- + "' " : "title='" + imgObj.alt + "' ";
- var imgStyle = "display:inline-block;"
- + imgObj.style.cssText;
- var strNewHTML = "<span "
- + imgID
- + imgClass
- + imgTitle
- + " style=\""
- + "width:"
- + imgObj.width
- + "px; height:"
- + imgObj.height
- + "px;"
- + imgStyle
- + ";"
- + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
- + "(src=\'" + imgObj.src
- + "\', sizingMethod='scale');\"></span>";
- imgObj.outerHTML = strNewHTML;
- }
- },
- /**
- * 获取当前路径中指定键的参数值。
- *
- * @param key
- * @returns
- */
- getParameter : function(key) {
- var parameters = unescape(window.location.search.substr(1))
- .split("&");
- for ( var i = 0; i < parameters.length; i++) {
- var paramCell = parameters[i].split("=");
- if (paramCell.length == 2
- && paramCell[0].toUpperCase() == key.toUpperCase()) {
- return paramCell[1];
- }
- }
- return new String();
- },
- /**
- * 根据年份和月份获取某个月的天数。
- *
- * @param year
- * @param month
- * @returns
- */
- getMonthDays : function(year, month) {
- if (month < 0 || month > 11) {
- return 30;
- }
- var arrMon = new Array(12);
- arrMon[0] = 31;
- if (year % 4 == 0) {
- arrMon[1] = 29;
- } else {
- arrMon[1] = 28;
- }
- arrMon[2] = 31;
- arrMon[3] = 30;
- arrMon[4] = 31;
- arrMon[5] = 30;
- arrMon[6] = 31;
- arrMon[7] = 31;
- arrMon[8] = 30;
- arrMon[9] = 31;
- arrMon[10] = 30;
- arrMon[11] = 31;
- return arrMon[month];
- },
- /**
- * 计算日期为当年的第几周
- *
- * @param year
- * @param month
- * @param day
- * @returns
- */
- weekOfYear : function(year, month, day) {
- // year 年
- // month 月
- // day 日
- // 每周从周日开始
- var date1 = new Date(year, 0, 1);
- var date2 = new Date(year, month - 1, day, 1);
- var dayMS = 24 * 60 * 60 * 1000;
- var firstDay = (7 - date1.getDay()) * dayMS;
- var weekMS = 7 * dayMS;
- date1 = date1.getTime();
- date2 = date2.getTime();
- return Math.ceil((date2 - date1 - firstDay) / weekMS) + 1;
- },
- /**
- * 添加书签
- *
- * @param title
- * @param url
- * @returns {Boolean}
- */
- addBookmark : function(title, url) {
- if (window.sidebar) {
- window.sidebar.addPanel(title, url, "");
- } else if (document.all) {
- window.external.AddFavorite(url, title);
- } else if (window.opera && window.print) {
- return true;
- }
- },
- /**
- * 设置cookie
- *
- * @param name
- * @param value
- */
- setCookie : function(name, value) {
- var expdate = new Date();
- var argv = arguments;
- var argc = arguments.length;
- var expires = (argc > 2) ? argv[2] : null;
- var path = (argc > 3) ? argv[3] : null;
- var domain = (argc > 4) ? argv[4] : null;
- var secure = (argc > 5) ? argv[5] : false;
- if (expires != null)
- expdate.setTime(expdate.getTime() + (expires * 1000));
- document.cookie = name
- + "="
- + escape(value)
- + ((expires == null) ? "" : ("; expires=" + expdate
- .toGMTString()))
- + ((path == null) ? "" : ("; path=" + path))
- + ((domain == null) ? "" : ("; domain=" + domain))
- + ((secure == true) ? "; secure" : "");
- },
- /**
- * 删除cookie
- *
- * @param name
- */
- delCookie : function(name) {
- var exp = new Date();
- exp.setTime(exp.getTime() - 1);
- var cval = $.getCookie(name);
- document.cookie = name + "=" + cval + "; expires="
- + exp.toGMTString();
- },
- /**
- * 读取cookie
- *
- * @param name
- * @returns
- */
- getCookie : function(name) {
- var arg = name + "=";
- var alen = arg.length;
- var clen = document.cookie.length;
- var i = 0;
- while (i < clen) {
- var j = i + alen;
- if (document.cookie.substring(i, j) == arg)
- return $.getCookieVal(j);
- i = document.cookie.indexOf(" ", i) + 1;
- if (i == 0)
- break;
- }
- return null;
- },
- getCookieVal : function(offset)
- {
- var endstr = document.cookie.indexOf(";", offset);
- if (endstr == -1)
- endstr = document.cookie.length;
- return unescape(document.cookie.substring(offset, endstr));
- },
- /**
- * 通过js设置表单的值。
- *
- * @param data
- */
- setFormByJson : function(data) {
- var json = data;
- if (typeof (data) == "string") {
- json = jQuery.parseJSON(data);
- }
- for ( var p in json) {
- var value = json[p];
- var frmElments = $("input[name='" + p+ "'],textarea[name='" + p + "']");
- if (frmElments[0]) {
- frmElments.val(value);
- }
- }
- },
- /**
- * 当鼠标移过表格行时,高亮表格行数据
- */
- highlightTableRows : function() {
- $("tr.odd,tr.even").hover(function() {
- $(this).addClass("over");
- }, function() {
- $(this).removeClass("over");
- });
- },
- /**
- * 选中行或反选
- **/
- selectTr:function(){
- $("tr.odd,tr.even").each(function(){
- $(this).bind("mousedown",function(event){
- if(event.target.tagName=="TD")
- var strFilter='input:checkbox[class="pk"],input:radio[class="pk"]';
- var obj=$(this).find(strFilter);
- if(obj.length==1){
- var state=obj.attr("checked");
- obj.attr("checked",!state);
- var isHashCheck = $("chkall");
- if(isHashCheck){
- obj.trigger("change");
- }
- }
- }
- );
- });
- },
- /**
- * 在数组中指定的位置插入数据。
- * @param aryData
- * @param data
- * @param index
- */
- insert : function(aryData,data,index){
- if(isNaN(index) || index<0 || index>aryData.length) {
- aryData.push(data);
- }else{
- var temp = aryData.slice(index);
- aryData[index]=data;
- for (var i=0; i<temp.length; i++){
- aryData[index+1+i]=temp[i];
- }
- }
- },
-
- getFirstLower:function(v){
- var value="";
- if(v.indexOf('_')!=-1){
- var ary=v.split('_');
- for(var i=0;i<ary.length;i++){
- var tmp=ary[i];
- if(i==0){
- value+=tmp.toLowerCase();
- }else{
- value+=tmp.substring(0,1).toUpperCase()+tmp.substring(1,tmp.length+1).toLowerCase();
- }
- }
- }else{
- value=v.toLowerCase();
- }
- return value;
- },
-
- getFirstUpper:function(v){
- var value="";
- if(v.indexOf('_')!=-1){
- var ary=v.split('_');
- for(var i=0;i<ary.length;i++){
- var tmp=ary[i];
- value+=tmp.substring(0,1).toUpperCase()+tmp.substring(1,tmp.length+1).toLowerCase();
- }
- }else{
- value=v.substring(0,1).toUpperCase()+v.substring(1,v.length+1).toLowerCase();
- }
- return value;
- },
- /**
- *
- * @param url
- * @returns
- */
- openFullWindow:function(url){
- var h=screen.availHeight-35;
- var w=screen.availWidth-5;
- var vars="top=0,left=0,height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizable=1,scrollbars=1";
-
- var win=window.open(url,"",vars,true);
- return win;
- },
- /**
- *
- * @param url
- * @returns
- */
- openMidWindow:function(url){
- var h=350;
- var w=560;
- var t=(screen.availHeight-h)/2;
- var l=(screen.availWidth-w)/2;
- var vars="top="+t+",left="+l+",height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,resizable=1,scrollbars=1";
-
- var win=window.open(url,"",vars,true);
- return win;
- },
- /**
- * 刷新父窗口并关闭当前窗口。
- */
- closeWindow:function(){
- if(window.opener){
- try{
- window.opener.location.href=window.opener.location.href.getNewUrl();
- }
- catch(e){}
- }
- window.close();
- },
- /**
- * 如果传入的值是null、undefined或空字符串,则返回true。(可选的)
- * @param {Mixed} value 要验证的值。
- * @param {Boolean} allowBlank (可选的) 如果该值为true,则空字符串不会当作空而返回true。
- * @return {Boolean}
- */
- isEmpty : function(v, allowBlank){
- return v === null || v === undefined || (!allowBlank ? v === '' : false);
- },
- /**
- * 将数字转换成人名币大写。
- * @param currencyDigits
- * @returns
- */
- convertCurrency:function(currencyDigits) {
-
- var MAXIMUM_NUMBER = 99999999999.99;
- var CN_ZERO = "零";
- var CN_ONE = "壹";
- var CN_TWO = "贰";
- var CN_THREE = "叁";
- var CN_FOUR = "肆";
- var CN_FIVE = "伍";
- var CN_SIX = "陆";
- var CN_SEVEN = "柒";
- var CN_EIGHT = "捌";
- var CN_NINE = "玖";
- var CN_TEN = "拾";
- var CN_HUNDRED = "佰";
- var CN_THOUSAND = "仟";
- var CN_TEN_THOUSAND = "万";
- var CN_HUNDRED_MILLION = "亿";
- var CN_SYMBOL = "";
- var CN_DOLLAR = "元";
- var CN_TEN_CENT = "角";
- var CN_CENT = "分";
- var CN_INTEGER = "整";
- var integral;
- var decimal;
- var outputCharacters;
- var parts;
- var digits, radices, bigRadices, decimals;
- var zeroCount;
- var i, p, d;
- var quotient, modulus;
- currencyDigits = currencyDigits.toString();
- if (currencyDigits == "") {
- return "";
- }
- if (currencyDigits.match(/[^,.\d]/) != null) {
- return "";
- }
- if ((currencyDigits).match(/^((\d{1,3}(,\d{3})*(.((\d{3},)*\d{1,3}))?)|(\d+(.\d+)?))$/) == null) {
- return "";
- }
- currencyDigits = currencyDigits.replace(/,/g, "");
- currencyDigits = currencyDigits.replace(/^0+/, "");
-
- if (Number(currencyDigits) > MAXIMUM_NUMBER) {
- return "";
- }
- parts = currencyDigits.split(".");
- if (parts.length > 1) {
- integral = parts[0];
- decimal = parts[1];
-
- decimal = decimal.substr(0, 2);
- }
- else {
- integral = parts[0];
- decimal = "";
- }
-
- digits = new Array(CN_ZERO, CN_ONE, CN_TWO, CN_THREE, CN_FOUR, CN_FIVE, CN_SIX, CN_SEVEN, CN_EIGHT, CN_NINE);
- radices = new Array("", CN_TEN, CN_HUNDRED, CN_THOUSAND);
- bigRadices = new Array("", CN_TEN_THOUSAND, CN_HUNDRED_MILLION);
- decimals = new Array(CN_TEN_CENT, CN_CENT);
-
- outputCharacters = "";
-
- if (Number(integral) > 0) {
- zeroCount = 0;
- for (i = 0; i < integral.length; i++) {
- p = integral.length - i - 1;
- d = integral.substr(i, 1);
- quotient = p / 4;
- modulus = p % 4;
- if (d == "0") {
- zeroCount++;
- }
- else {
- if (zeroCount > 0) {
- outputCharacters += digits[0];
- }
- zeroCount = 0;
- outputCharacters += digits[Number(d)] + radices[modulus];
- }
- if (modulus == 0 && zeroCount < 4) {
- outputCharacters += bigRadices[quotient];
- }
- }
- outputCharacters += CN_DOLLAR;
- }
-
- if (decimal != "") {
- for (i = 0; i < decimal.length; i++) {
- d = decimal.substr(i, 1);
- if (d != "0") {
- outputCharacters += digits[Number(d)] + decimals[i];
- }
- }
- }
-
- if (outputCharacters == "") {
- outputCharacters = CN_ZERO + CN_DOLLAR;
- }
- if (decimal == "") {
- outputCharacters += CN_INTEGER;
- }
- outputCharacters = CN_SYMBOL + outputCharacters;
- return outputCharacters;
- },
- /**
- * 转换节点的tagName
- * 示例 var me=$(this); me=$.tagName(me,"span");
- * @param self {object} 要转换的单个节点
- * @param tag {string} 转换为tag类型节点
- * @return {object} 转换后的节点对象
- */
- tagName:function(self,tag){
- var attrs=self.attributes,
- newTag=document.createElement(tag);
- for(var i=0,c;c=attrs[i++];){
- if(!c.value||c.value=='null')continue;
- $(newTag).attr(c.name,c.value);
- }
- $(self).before($(newTag));
- $(self).remove();
- return $(newTag);
- },
- /**
- * 在文本框指定的地方插入文本
- * @param txtarea 文本框对象
- * @param tag 文本
- */
- insertText : function(txtarea, tag) {
- // IE
- if (document.selection) {
- var theSelection = document.selection.createRange().text;
- if (!theSelection) {
- theSelection = tag;
- }
- txtarea.focus();
- if (theSelection.charAt(theSelection.length - 1) == " ") {
- theSelection = theSelection.substring(0,
- theSelection.length - 1);
- document.selection.createRange().text = theSelection
- + " ";
- } else {
- document.selection.createRange().text = theSelection;
- }
- // Mozilla
- } else if (txtarea.selectionStart || txtarea.selectionStart == '0') {
- var startPos = txtarea.selectionStart;
- var endPos = txtarea.selectionEnd;
- var myText = (txtarea.value).substring(startPos, endPos);
- if (!myText) {
- myText = tag;
- }
- if (myText.charAt(myText.length - 1) == " ") {
- subst = myText.substring(0, (myText.length - 1)) + " ";
- } else {
- subst = myText;
- }
- txtarea.value = txtarea.value.substring(0, startPos)+ subst+ txtarea.value.substring(endPos,txtarea.value.length);
- txtarea.focus();
- var cPos = startPos + (myText.length);
- txtarea.selectionStart = cPos;
- txtarea.selectionEnd = cPos;
- // All others
- } else {
- txtarea.value += tag;
- txtarea.focus();
- }
- if (txtarea.createTextRange)
- txtarea.caretPos = document.selection.createRange().duplicate();
- },
- confirm:function(selector,message,callback){
- $(selector).click(function(){
- if($(this).hasClass('disabled')) return false;
-
- var ele=this;
- $.ligerDialog.confirm(message,$lang.tip.msg,function(rtn) {
- if(rtn){
- if($.browser.msie){
- $.gotoDialogPage(ele.href);
- }
- else{
- location.href=ele.href;
- }
- }
- });
- return false;
- });
- },
- /**
- * Dialog窗口跳转
- * @param {} url 地址
- */
- gotoDialogPage: function (url) {
- if($.browser.msie){
- var a = document.createElement("a");
- a.href=url;
- document.body.appendChild(a);
- a.click();
- }
- else{
- location.href=url;
- }
- },
- /**
- * 克隆对象。
- */
- cloneObject:function(obj){
- var o = obj.constructor === Array ? [] : {};
- for(var i in obj){
- if(obj.hasOwnProperty(i)){
- o[i] = typeof obj[i] === "object" ? cloneObject(obj[i]) : obj[i];
- }
- }
- return o;
- },
- /**
- * 清除表单
- */
- clearQueryForm:function(){
- $("input[name^='Q_'],select[name^='Q_']").each(function(){
- $(this).val('');
- });
- },
- getFileExtName:function(fileName){
- var pos=fileName.lastIndexOf(".");
- if(pos==-1) return "";
- return fileName.substring(pos +1);
- },
- //转成千分位。
- comdify:function(v){
- if(v&&v!=''){
- n=v+"";
- var re=/\d{1,3}(?=(\d{3})+$)/g;
- var n1=n.trim().replace(/^(\d+)((\.\d+)?)$/,function(s,s1,s2){
- return s1.replace(re,"$&,")+s2;
- });
- return n1;
- }
- return v;
- },
- toNumber:function(v){
- if(v&&v!=''){
- if(v.indexOf(',')==-1)
- return v;
- var ary=v.split(',');
- var val=ary.join("");
- return val;
- }
- return 0;
- },
- /**
- * 上下移动
- *
- * @param {}
- * obj 上移的对象
- * @param {}
- * isUp 是否上移
- */
- moveTr : function(obj, isUp) {
- var thisTr = $(obj).parents("tr");
- if (isUp) {
- var prevTr = $(thisTr).prev();
- if (prevTr) {
- thisTr.insertBefore(prevTr);
- }
- } else {
- var nextTr = $(thisTr).next();
- if (nextTr) {
- thisTr.insertAfter(nextTr);
- }
- }
- },
- getCurrentDate:function(){
-
- var myDate=new Date();
- var month=myDate.getMonth()+1;
- month=(month<10)?"0" + month:month;
- return myDate.getFullYear() +"-" + month + "-"+ myDate.getDate();
- },
- getPageSize:function() {
- var winW, winH;
- if(window.innerHeight) {// all except IE
- winW = window.innerWidth;
- winH = window.innerHeight;
- } else if (document.documentElement && document.documentElement.clientHeight) {// IE 6 Strict Mode
- winW = document.documentElement.clientWidth;
- winH = document.documentElement.clientHeight;
- } else if (document.body) { // other
- winW = document.body.clientWidth;
- winH = document.body.clientHeight;
- } // for small pages with total size less then the viewport
- return {width:winW, height:winH};
- } ,
- isArray : function(v){
- return Object.prototype.toString.call(v) === '[object Array]';
- }
-
- });
- /**
- * 功能:给url添加一个当前时间日期数值,使页面不会被缓存。
- */
- String.prototype.getNewUrl = function() {
- // 如果url中没有参数。
- var time = new Date().getTime();
- var url = this;
- //去除‘#’后边的字符
- if (url.indexOf("#") != -1) {
- var index=url.lastIndexOf("#",url.length-1);
- url=url.substring(0, index);
- }
-
- while(url.endWith("#")){
- url=url.substring(0, url.length-1);
- }
- url=url.replace(/(\?|&)rand=\d*/g, "");
- if (url.indexOf("?") == -1) {
- url += "?rand=" + time;
- } else {
- url += "&rand=" + time;
- }
- return url;
- };
- /**
- * 功能:给url添加jsessionId 防止session丢失。
- * @returns {String}
- */
- String.prototype.getSessionUrl=function(){
- //jsessionid
- var url = this;
- if(url.indexOf(";jsessionid=")!=-1){
- return url;
- }
- if(url.indexOf("?")==-1){
- url+=";jsessionid=" +__jsessionid;
- }
- else{
- var aryUrl=url.split("?");
- url=aryUrl[0] +";jsessionid=" +__jsessionId +"?" + aryUrl[1];
- }
- return url;
- };
- /**
- * 判断字符串是否为空。
- *
- * @returns {Boolean}
- */
- String.prototype.isEmpty = function() {
- var rtn = (this == null || this == undefined || this.trim() == '');
- return rtn;
- };
- /**
- * 功能:移除首尾空格
- */
- String.prototype.trim = function() {
- return this.replace(/(^\s*)|(\s*$)/g, "");
- };
- /**
- * 功能:移除左边空格
- */
- String.prototype.lTrim = function() {
- return this.replace(/(^\s*)/g, "");
- };
- /**
- * 功能:移除右边空格
- */
- String.prototype.rTrim = function() {
- return this.replace(/(\s*$)/g, "");
- };
- /**
- * 判断结束是否相等
- *
- * @param str
- * @param isCasesensitive
- * @returns {Boolean}
- */
- String.prototype.endWith = function(str, isCasesensitive) {
- if (str == null || str == "" || this.length == 0
- || str.length > this.length)
- return false;
- var tmp = this.substring(this.length - str.length);
- if (isCasesensitive == undefined || isCasesensitive) {
- return tmp == str;
- } else {
- return tmp.toLowerCase() == str.toLowerCase();
- }
- };
- /**
- * 判断开始是否相等
- *
- * @param str
- * @param isCasesensitive
- * @returns {Boolean}
- */
- String.prototype.startWith = function(str, isCasesensitive) {
- if (str == null || str == "" || this.length == 0
- || str.length > this.length)
- return false;
- var tmp = this.substr(0, str.length);
- if (isCasesensitive == undefined || isCasesensitive) {
- return tmp == str;
- } else {
- return tmp.toLowerCase() == str.toLowerCase();
- }
- };
- /**
- * 在字符串左边补齐指定数量的字符
- *
- * @param c
- * 指定的字符
- * @param count
- * 补齐的次数 使用方法: var str="999"; str=str.leftPad("0",3); str将输出 "000999"
- * @returns
- */
- String.prototype.leftPad = function(c, count) {
- if (!isNaN(count)) {
- var a = "";
- for ( var i = this.length; i < count; i++) {
- a = a.concat(c);
- }
- a = a.concat(this);
- return a;
- }
- return null;
- };
- /**
- * 在字符串右边补齐指定数量的字符
- *
- * @param c
- * 指定的字符
- * @param count
- * 补齐的次数 使用方法: var str="999"; str=str.rightPad("0",3); str将输出
- * "999000"
- * @returns
- */
- String.prototype.rightPad = function(c, count) {
- if (!isNaN(count)) {
- var a = this;
- for ( var i = this.length; i < count; i++) {
- a = a.concat(c);
- }
- return a;
- }
- return null;
- };
- /**
- * 对html字符进行编码 用法: str=str.htmlEncode();
- *
- * @returns
- */
- String.prototype.htmlEncode = function() {
- return this.replace(/&/g, "&").replace(/</g, "<").replace(/>/g,
- ">").replace(/\"/g, """).replace(/\'/g, "'");
- };
- /**
- * 对html字符串解码 用法: str=str.htmlDecode();
- *
- * @returns
- */
- String.prototype.htmlDecode = function() {
- return this.replace(/\&\;/g, '\&').replace(/\>\;/g, '\>').replace(
- /\<\;/g, '\<').replace(/\"\;/g, '\'').replace(/\&\#39\;/g,
- '\'');
- };
- /**
- * 对json中的特殊字符进行转义
- */
- String.prototype.jsonEscape = function(){
- return this.replace(/\"/g, """).replace(/\n/g,"&nuot;");
- };
- /**
- * 对json中的特殊字符进行转义
- */
- String.prototype.jsonUnescape = function(){
- return this.replace(/"/g, "\"").replace(/&nuot;/g,"\n");
- };
- /**
- * 字符串替换
- *
- * @param s1
- * 需要替换的字符
- * @param s2
- * 替换的字符。
- * @returns
- */
- String.prototype.replaceAll = function(s1, s2) {
- return this.replace(new RegExp(s1, "gm"), s2);
- };
- /**
- * 获取url参数
- *
- * @returns {object}
- */
- String.prototype.getArgs = function() {
- var args = {};
- if(this.indexOf("?")>-1){
- var argStr = this.split("?")[1],
- argAry = argStr.split("&");
-
- for(var i=0,c;c=argAry[i++];){
- var pos = c.indexOf("=");
- if(pos==-1)continue;
- var argName = c.substring(0,pos),
- argVal = c.substring(pos+1);
- argVal = decodeURIComponent(argVal);
- args[argName] = argVal;
- }
- }
- return args;
- };
- /**
- * var str=String.format("姓名:{0},性别:{1}","ray","男");
- * alert(str);
- * @returns
- */
- String.format=function(){
- var template=arguments[0];
- var args=arguments;
- var str=template.replace(/\{(\d+)\}/g,function(m,i){
- var k=parseInt(i)+1;
- return args[k];
- });
- return str;
- };
- /**
- * 字符串操作 使用方法: var sb=new StringBuffer(); sb.append("aa"); sb.append("aa"); var
- * str=sb.toString();
- *
- * @returns {StringBuffer}
- */
- function StringBuffer() {
- this.content = new Array;
- }
- StringBuffer.prototype.append = function(str) {
- this.content.push(str);
- };
- StringBuffer.prototype.toString = function() {
- return this.content.join("");
- };
- /**
- * 日期格式化
- * 格式 YYYY/yyyy/YY/yy 表示年份
- * MM/M 月份
- * W/w 星期
- * dd/DD/d/D 日期
- * hh/HH/h/H 时间
- * mm/m 分钟
- * ss/SS/s/S 秒
- */
- Date.prototype.Format = function(formatStr)
- {
- var str = formatStr;
- if(formatStr==undefined || formatStr==null){
- str="yyyy-MM-dd";
- }
-
- var Week = ['日','一','二','三','四','五','六'];
-
- str=str.replace(/yyyy|YYYY/,this.getFullYear());
- str=str.replace(/yy|YY/,(this.getYear() % 100)>9?(this.getYear() % 100).toString():'0' + (this.getYear() % 100));
-
- str=str.replace(/MM/,(this.getMonth()+1)>9?(this.getMonth()+1).toString():'0' + (this.getMonth()+1));
- str=str.replace(/M/g,(this.getMonth()+1));
-
- str=str.replace(/w|W/g,Week[this.getDay()]);
-
- str=str.replace(/dd|DD/,this.getDate()>9?this.getDate().toString():'0' + this.getDate());
- str=str.replace(/d|D/g,this.getDate());
-
- str=str.replace(/hh|HH/,this.getHours()>9?this.getHours().toString():'0' + this.getHours());
- str=str.replace(/h|H/g,this.getHours());
- str=str.replace(/mm/,this.getMinutes()>9?this.getMinutes().toString():'0' + this.getMinutes());
- str=str.replace(/m/g,this.getMinutes());
-
- str=str.replace(/ss|SS/,this.getSeconds()>9?this.getSeconds().toString():'0' + this.getSeconds());
- str=str.replace(/s|S/g,this.getSeconds());
-
- return str;
- };
- /**
- * 求两个时间的天数差 日期格式为 yyyy-MM-dd 或 YYYY-MM-dd HH:mm:ss
- */
- function daysBetween(DateOne,DateTwo)
- {
- var date1 = new Date(DateOne).getTime();
- var date2 = new Date(DateTwo).getTime();;
- if(date1>date2){
- return false;
- }else{
- return true;
- }
- };
- /**
- * 加载多个Script
- * @param resources script file array :['file1.js','file2.js']
- * @param callback function
- * @returns void
- */
- jQuery.getMutilScript = function( resources, callback ) {
- var getScript = function(url,callback){
- $.ajax({
- url: url,
- dataType: "script",
- success: callback,
- async:false
- }).done(function(){
- callback && callback();
- });
- };
- var // reference declaration & localization
- length = resources.length,
- handler = function() { counter++; },
- deferreds = [],
- counter = 0,
- idx = 0;
- for ( ; idx < length; idx++ ) {
- deferreds.push(
- getScript( resources[ idx ], handler )
- );
- }
- jQuery.when(deferreds ).done(function(){
- callback && callback();
- });
- };
- $(function(){
- if($.browser){
- if($.browser.version=='6.0'){
- $("a.tipinfo").each(function(){
- $(this).mouseover(function(){
- $("span",$(this)).show();
- });
- $(this).mouseleave(function(){
- $("span",$(this)).hide();
- });
- });
- }
- }
- });
- jQuery.getWindowRect = function() {
- var myWidth = 0, myHeight = 0;
- if( typeof( window.innerWidth ) == 'number' ) {
- //Non-IE
- myWidth = window.innerWidth;
- myHeight = window.innerHeight;
- } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
- //IE 6+ in 'standards compliant mode'
- myWidth = document.documentElement.clientWidth;
- myHeight = document.documentElement.clientHeight;
- } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
- //IE 4 compatible
- myWidth = document.body.clientWidth;
- myHeight = document.body.clientHeight;
- }
- return {
- height:myHeight,
- width:myWidth
- };
- }
- //禁用刷新。通过传入浏览器类型 来指定禁用某个浏览器的刷新
- function forbidF5(exp) {
- var currentExplorer = window.navigator.userAgent;
- //ie "MSIE" ,, firefox "Firefox" ,,Chrome "Chrome",,Opera "Opera",,Safari "Safari"
- if (currentExplorer.indexOf(exp) >= 0) {
- document.onkeydown = function(e) {
- var ev = window.event || e;
- var code = ev.keyCode || ev.which;
- if (code == 116) {
- ev.keyCode ? ev.keyCode = 0 : ev.which = 0;
- cancelBubble = true;
- return false;
- }
- }
- }
- }
- Date.prototype.format = function(format)
- {
- var o = {
- "M+" : this.getMonth()+1, //month
- "d+" : this.getDate(),//day
- "h+" : this.getHours(), //hour
- "m+" : this.getMinutes(), //minute
- "s+" : this.getSeconds(), //second
- "q+" : Math.floor((this.getMonth()+3)/3), //quarter
- "S" : this.getMilliseconds() //millisecond
- }
-
- if(/(y+)/.test(format))
- format = format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
- for(var k in o)
- if(new RegExp("("+ k +")").test(format))
- format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
- return format;
- }
- /**
- * 调整点击资源菜单时 tab导航栏向上浮动的问题;
- */
- function justifyMargin(height,level,time){
- if(window.navigator.userAgent.indexOf("Chrome")>=0){
- window.setTimeout(function(){
- var tabLinks = "";
- if(level==3){
- tabLinks = $("#framecenter > div.l-tab-links",parent.parent.document);
- if($(".l-layout-left",parent.document)[0] && $("iframe",parent.document).length !=1) return;
- }else{
- tabLinks = $("#framecenter > div.l-tab-links",parent.document)
- }
- tabLinks.css("margin-top",parseInt(tabLinks.css("margin-top"))+ height +"px");
- },time||0)
- }
- }
- /**
- * 修复所有树状结构右键菜单超出屏幕的问题
- * @param e 传入点击事件event
- */
- function justifyRightClickPosition(e){
- var offsetHeight=parseInt($(".l-menu").eq(0).height());
- var ePageY=parseInt(e.pageY);
- var bodyOffsetHeight=parseInt(document.body.offsetHeight);
- var h=$(window).height() ;
- if(offsetHeight+ePageY>=bodyOffsetHeight-10){
- e.pageY=ePageY-offsetHeight;
- }
- }
- /**
- * 修复list页面滚动条的bug ,用法 在对应的页面 的body上面加上 onload事件 如 : <body style="overflow: hidden;" onload="changeHeight()">
- */
- function changeScrollHeight(noNeedFoldHeight,time){
- window.setTimeout(function(){
- $.setCookie("noNeedFoldHeight", noNeedFoldHeight||"");
- if(noNeedFoldHeight) return;
- $("body").css("overflow-y","hidden");
- var currentTable=$(".table-grid.table-list");
- if(! currentTable) return;
- var tableBody=currentTable.parent(),foldHeight=0;
- if(!parent.document.querySelectorAll("#logoImg")[0])foldHeight = $("#searchForm").height();
- var moreHeight = $('.panel-search').attr("moreHeight")||0;
- tableBody.height($(window).height()-tableBody[0].offsetTop-$(".index_menu",$(parent.document)).height()/2-foldHeight-moreHeight);
- tableBody.css("overflow-y","scroll");
- tableBody.css("border","1px solid #A0BDBB");
- currentTable.css("margin-top","0px");
- },time||10)
- }
- /**
- * 获取元素当前页angular的scope by liyj
- * @param obj
- * @returns
- */
- function getScope(obj){
- obj=(obj&&$(obj))||$("[ng-controller]");
- obj=(obj[0]?obj:$("body"));
- return obj.scope();
- }
- /**
- * 将字符串转为json对象。
- * @param jsonStr
- * @param type 可不填写
- * @returns
- */
- function parseToJson(jsonStr,type){
- type=type||1;
- if(jsonStr === "") return;
- try{
- switch(type){
- case 1:
- return eval("("+jsonStr+")");
- break;
- case 2:
- return $.parseJSON(jsonStr);
- break;
- case 3:
- return angular.fromJson(jsonStr);
- break;
- case 4:
- JSON.parse(jsonStr);
- break;
- default:
- console.error("解析json对象错误");
- break;
- }
-
- }catch(e){
- return parseToJson(jsonStr,type+1);
- }
- }
- //在鼠标停留的地方插入text
- function insertText(obj,str) {
- if (document.selection) {
- var sel = document.selection.createRange();
- sel.text = str;
- } else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
- var startPos = obj.selectionStart,
- endPos = obj.selectionEnd,
- cursorPos = startPos,
- tmpStr = obj.value;
- obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
- cursorPos += str.length;
- obj.selectionStart = obj.selectionEnd = cursorPos;
- } else {
- obj.value += str;
- }
- }
- /**
- * 通过scope中取得ng-model对应的属性值
- * @param obj 控件对象
- * @param exp 表示ngModel (可选) 列如 editingField.option.numberFormat.isShowComdify
- * @param scope (可选)
- * @returns
- */
- function getValByScope(obj,exp,scope){
- if(obj) obj=angular.element(obj);
- if(!scope&&!obj) return;
- scope=scope||obj.scope();
- var ngModel=exp||(obj&&(obj.attr("ht-model-true")||obj.attr("ng-model")));
- if(!ngModel) {
- if(obj&&(obj.attr("type")=="checkbox"||obj.attr("type")=="radio")){
- if(obj.is(":checked")) return obj.val();
- else return "";
- }else return obj.val();
- }
- //判断是否是获取复选框的值
- if(ngModel.indexOf("__tempCheckBoxVal")!=-1){
- ngModel=obj.attr("ht-checkbox");
- }
- try{
- if(scope){
- var str="scope."+ngModel;
- return eval("("+str+")");
- }else{
- return obj.val();
- }
- }catch(e){
- return "";
- }
- }
- function delSubRow(){
- $("input:checked").closest("[var='templTr']").remove();
- }
- function checkTr(el){
- var ck = $("input[type='checkbox']",$(el));
- ck.attr("checked",!ck.attr("checked"));
- }
- /**
- * 给控件的scope赋值
- * @param obj 控件对象 (当传入exp时,obj可以传入空值)
- * @param val 值
- * @param time 延迟时间(可选)
- * @param exp 表示ngModel (可选) 列如 editingField.option.numberFormat.isShowComdify
- */
- function setValToScope(obj,val,time,exp,scope){
- __setValTimes = 0;
- if(time){ // 加上时间延迟 是为了处理在easyUI界面没有加载成功的情况下 数据赋值失败的问题
- window.setTimeout(fun,time);
- }else{
- fun();
- }
- function fun(){
- if(obj&&!scope){
- obj=angular.element(obj);
- scope=obj.scope();
- }
- if(!scope) return;
- ngModel=exp||(obj&&(obj.attr("ht-model-true")||obj.attr("ng-model")));
- if(!ngModel) return;
- var exps=ngModel.split("."),tempModel=ngModel;
-
- if(ngModel.indexOf("data")==0&&ngModel.indexOf(".sub_")>0){
- var sub_model = $.extend([],exps);
- sub_model.splice(exps.length-1,1);
- var subModelVals = getValByScope(null,sub_model.join("."),scope),tempScope = "";
- if(!subModelVals){
- subModelVals = getValByScope(null,sub_model.join("."),scope.$parent);
- tempScope = scope.$parent;
- }else{
- tempScope = scope;
- }
- if(subModelVals){
- if(subModelVals instanceof Array){
- for(var i =0;i<subModelVals.length;i++){
- subModelVals[i][targetParam] = val;
- }
- setValToScope(null,subModelVals,null,sub_model.join("."),tempScope);
- return ;
- }
- }
- }
- setVal();
- __setValTimes = 0;
- function setVal(){
- try{
- eval("("+"scope."+ngModel+"=val"+")");
- obj&&obj.attr("ng-model")&&obj.val(val);
- if(!scope.$$phase){
- scope.$digest();
- }
- }catch(e){
- if(__setValTimes>20) return ;
- setTempVal();
- __setValTimes++;
- tempModel=ngModel;
- exps=ngModel.split(".");
- setVal();
- }
- }
- function setTempVal(){// a.b.c
- try{
- eval("("+"scope."+tempModel+"={}"+")");
- }catch(e){
- tempModel=exps.remove(exps[exps.length-1]).join(".");
- setTempVal();
- }
- }
- }
- }
- /**
- * 序列化查询参数
- * @param {} form
- * @return {}
- */
- function serializeObject(form){
- var o = {};
- var a = $(form).serializeArray();
- $.each(a, function() {
- if (o[this.name]) {
- if (!o[this.name].push) {
- o[this.name] = [o[this.name]];
- }
- o[this.name].push(this.value || '');
- } else {
- o[this.name] = this.value || '';
- }
- });
- return o;
- }
- function renderDtype(type){
- <!--DTYPE(下发状态):0下发,1上报,2省来文,3市来文,4市上报,5县区上报,6乡镇上报-->
- var typeArray=new Array("下发公文","上报公文","省来文","市来文","市上报文件","县区上报文件","乡镇上报文件");
- return typeArray[type];
- }
|