lib.js 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  1. ;(function($){//延时hover插件
  2. $.fn.hoverDelay = function(options){
  3. var defaults = {
  4. hoverDuring: 200,
  5. outDuring: 200,
  6. hoverEvent: function(){
  7. $.noop();
  8. },
  9. outEvent: function(){
  10. $.noop();
  11. }
  12. };
  13. var sets = $.extend(defaults,options || {});
  14. var hoverTimer, outTimer;
  15. return $(this).each(function(){
  16. $(this).hover(function(){
  17. clearTimeout(outTimer);
  18. hoverTimer = setTimeout(sets.hoverEvent, sets.hoverDuring);
  19. },function(){
  20. clearTimeout(hoverTimer);
  21. outTimer = setTimeout(sets.outEvent, sets.outDuring);
  22. });
  23. });
  24. }
  25. })(jQuery);
  26. $.fn.placeholder = function(){
  27. var i = document.createElement('input'),placeholdersupport ='placeholder' in i;
  28. if(!placeholdersupport){
  29. var inputs = $(this);
  30. inputs.each(function(){
  31. var input = $(this),
  32. text = input.attr('placeholder'),
  33. pdl = 0,height = input.outerHeight(),
  34. width = input.outerWidth(),
  35. placeholder = $('<span class="phTips">'+text+'</span>');
  36. try{
  37. pdl = input.css('padding-left').match(/\d*/i)[0] * 1;
  38. }catch(e){
  39. pdl = 5;
  40. }
  41. placeholder.css({
  42. 'margin-left': -(width-pdl),
  43. 'height':height,
  44. 'line-height':height+"px",
  45. 'position':'absolute',
  46. 'color': "#cecfc9",
  47. 'font-size' : "12px"
  48. });
  49. placeholder.click(function(){
  50. input.focus();
  51. });
  52. if(input.val() != ""){
  53. placeholder.css({display:'none'});
  54. }else{
  55. placeholder.css({display:'inline'});
  56. }
  57. placeholder.insertAfter(input);
  58. input.keydown(function(e){
  59. placeholder.css({display:'none'});
  60. });
  61. input.blur(function(e){
  62. if(input.val() != ""){
  63. placeholder.css({display:'none'});
  64. }else{
  65. placeholder.css({display:'inline'});
  66. }
  67. });
  68. input.keyup(function(e){
  69. if($(this).val() != ""){
  70. placeholder.css({display:'none'});
  71. }else{
  72. placeholder.css({display:'inline'});
  73. }
  74. });
  75. });
  76. }
  77. return this;
  78. };
  79. //以上placeholder兼容性插件
  80. ;(function ($) {
  81. $.fn.extend({
  82. titletip:function(){
  83. $(this).each(function(){
  84. var tip,c=$(this),content=$(this).attr("title");
  85. $(this).removeAttr("title");
  86. $(this).hoverDelay({
  87. hoverEvent: function(){
  88. var l=c.offset().left,t=c.offset().top,w=c.width(),h=c.height();
  89. tip=$("<div class='title-tip'><b class='ui-arrow ui-arrowup'><em>◆</em><span>◆</span></b>"+content+"</div>").css({"left":l+w/2-47,"top":t+h+12}).appendTo("body");
  90. },
  91. outEvent: function(){
  92. tip!=null?tip.remove():"";
  93. }
  94. });
  95. });
  96. }
  97. });
  98. })(jQuery);
  99. //以上title tip 插件
  100. var ll={};
  101. var ajaxSubmit=false;//防止重复提交
  102. ll.common={
  103. //js 精确计算浮点数
  104. accMul:function(arg1,arg2){
  105. var m=0,s1=arg1.toString(),s2=arg2.toString();
  106. try{m+=s1.split(".")[1].length;}catch(e){}
  107. try{m+=s2.split(".")[1].length;}catch(e){}
  108. return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
  109. },
  110. accDiv:function(arg1,arg2){
  111. var t1=0,t2=0,r1,r2;
  112. try{t1=arg1.toString().split(".")[1].length;}catch(e){}
  113. try{t2=arg2.toString().split(".")[1].length;}catch(e){}
  114. with(Math){
  115. r1=Number(arg1.toString().replace(".",""));
  116. r2=Number(arg2.toString().replace(".",""));
  117. return (r1/r2)*pow(10,t2-t1);
  118. }
  119. },
  120. accAdd:function(arg1,arg2){
  121. var r1,r2,m;
  122. try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
  123. try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
  124. m=Math.pow(10,Math.max(r1,r2))
  125. return (arg1*m+arg2*m)/m
  126. },
  127. accSub:function(arg1,arg2){
  128. var r1,r2,m,n;
  129. try{r1=arg1.toString().split(".")[1].length}catch(e){r1=0}
  130. try{r2=arg2.toString().split(".")[1].length}catch(e){r2=0}
  131. m=Math.pow(10,Math.max(r1,r2));
  132. //last modify by deeka
  133. //动态控制精度长度
  134. n=(r1>=r2)?r1:r2;
  135. return ((arg1*m-arg2*m)/m).toFixed(n);
  136. },
  137. slideToggle:function(o,d,t,c){//点击显隐 o,触发对象,d,显隐对象,t:替换文本,c:触发后回调函数
  138. o.click(function(){
  139. d.toggle();
  140. t==null?"":o.text()==t[0]?o.text(t[1]):o.text(t[0]);
  141. c==null?"":c();
  142. });
  143. },
  144. tab:function(h,b,index,callback){//tab切换 h,点击对象 b,切换对象 index:默认选中索引 callback:回调函数
  145. if (typeof(index) !== "number") {
  146. index = 0;
  147. }
  148. h.eq(index).addClass("active");
  149. b.eq(index).addClass("active");
  150. h.click(function(){
  151. if($(this).hasClass("active")) return false;
  152. var index=h.parent().find(h).index(this);
  153. h.parent().find(h).removeClass("active");
  154. $(this).addClass("active");
  155. b.removeClass("active");
  156. b.eq(index).addClass("active");
  157. callback==null?"":callback();
  158. });
  159. },
  160. radioChoose:function(o,r,c){//单选框选中 o:点击对象 r:单选框 c: callback
  161. var n=r.attr("name");
  162. o.click(function(){
  163. r.prop("checked",true).focusout();//针对表单验证加入focusout();
  164. c==null?"":c();
  165. });
  166. r.click(function(){o.click();});
  167. },
  168. picCenter:function(box){
  169. box.each(function(){
  170. var _this=$(this);
  171. var bw=$(this).width();
  172. var bh=$(this).height();
  173. var src=$(this).find("img").attr("src");
  174. var img=new Image();
  175. img.onload=function(){
  176. if(img.width/bw>img.height/bh){
  177. _this.find("img").css({height:bh,width:(img.width*bh/img.height),marginLeft:-((img.width*bh/img.height)-bw)/2});
  178. }else{
  179. _this.find("img").css({width:bw,height:(img.height*bw/img.width),marginTop:-((img.height*bw/img.width)-bh)/2});
  180. }
  181. };
  182. img.src=src;
  183. });
  184. },
  185. checkChoose:function(o,r,c,d){//复选选中 o:点击对象 r:复选框 c: 选中回调函数 d:取消选中回调函数
  186. o.click(function(){
  187. if(r.is(":checked")){
  188. r.prop("checked",false).focusout();//针对表单验证加入focusout();
  189. d==null?"":d(o);
  190. }else{
  191. r.prop("checked",true).focusout();//针对表单验证加入focusout();
  192. c==null?"":c(o);
  193. }
  194. });
  195. r.click(function(){o.click();});
  196. },
  197. loadPage:function(uri,params,place,loadtext,callback){//ajax参数,显示位置,加载中文本,回调函数。
  198. //判断url是否自带参数 2014-06-19 16:08 @author xuwei
  199. var random=uri.indexOf("?")>-1?"&m="+Math.random():"?m="+Math.random();
  200. $.ajax({
  201. url: uri+random,
  202. data: params || {},
  203. dataType: 'html',
  204. type: "get",
  205. beforeSend:function(){
  206. place==null?"":place.html(loadtext||"加载中");
  207. },
  208. success: function(data) {
  209. //解决页面过期ajax返回过期页面而非html代码段导致排版错乱问题 2014-06-19 16:18 xuwei
  210. if(data.indexOf("<html>")>-1){
  211. location.href=uri; //暂时注释
  212. return false;
  213. };
  214. place==null?"":place.html(data);
  215. /*cb_data=data;//全局赋值ajax内容方便调用*/
  216. callback==null?"":callback(data);
  217. },
  218. error: function() {
  219. place==null?"":place.html("加载出了点问题");
  220. }
  221. });
  222. },
  223. emailDirect:function(email){//常用邮箱匹配
  224. var email=email || "null@null.com";
  225. var hash = {
  226. 'qq.com': 'http://mail.qq.com',
  227. 'gmail.com': 'http://mail.google.com',
  228. 'sina.com': 'http://mail.sina.com.cn',
  229. '163.com': 'http://mail.163.com',
  230. '126.com': 'http://mail.126.com',
  231. 'yeah.net': 'http://www.yeah.net/',
  232. 'sohu.com': 'http://mail.sohu.com/',
  233. 'tom.com': 'http://mail.tom.com/',
  234. 'sogou.com': 'http://mail.sogou.com/',
  235. '139.com': 'http://mail.10086.cn/',
  236. 'hotmail.com': 'http://www.hotmail.com',
  237. 'live.com': 'http://login.live.com/',
  238. 'live.cn': 'http://login.live.cn/',
  239. 'live.com.cn': 'http://login.live.com.cn',
  240. '189.com': 'http://webmail16.189.cn/webmail/',
  241. 'yahoo.com.cn': 'http://mail.cn.yahoo.com/',
  242. 'yahoo.cn': 'http://mail.cn.yahoo.com/',
  243. 'eyou.com': 'http://www.eyou.com/',
  244. '21cn.com': 'http://mail.21cn.com/',
  245. '188.com': 'http://www.188.com/',
  246. 'foxmail.com': 'http://www.foxmail.com',
  247. 'outlook.com': 'http://www.outlook.com'
  248. }
  249. var _mail = email.split('@')[1].toLocaleLowerCase(); //获取邮箱域
  250. for (var j in hash){
  251. if(j == _mail){
  252. return hash[_mail];
  253. }
  254. }
  255. return false;
  256. },
  257. ajaxForm:function(json){//url 参数 回调函数
  258. ajaxSubmit=json.load?false:ajaxSubmit;
  259. if(ajaxSubmit){return;}//防止重复提交表单;
  260. var random=json.url.indexOf("?")>-1?"&m="+Math.random():"?m="+Math.random();
  261. var option = {
  262. type: json.type || 'POST',
  263. url: json.url+random || "",
  264. data: json.data || {},
  265. dataType: json.dataType || "json",
  266. beforeSend:json.beforeSend || function(){
  267. ajaxSubmit=true;
  268. if(json.obj!=null)json.obj.prepend("<i class='loading-ico'></i>").addClass("disabled");
  269. },
  270. success:function(data){
  271. ajaxSubmit=false;
  272. if(json.obj!=null){json.obj.removeClass("disabled");json.obj.find(".loading-ico").remove()};
  273. if(data.errorCode=="relogin"){
  274. window.location.reload();
  275. return;
  276. }
  277. json.success(data);
  278. },
  279. error:json.error || function(){
  280. ajaxSubmit=false;
  281. if(json.obj!=null){json.obj.removeClass("disabled");json.obj.find(".loading-ico").remove()};
  282. ll.common.tips("error","网络错误,请稍后再试!",2000);
  283. }
  284. };
  285. !!json.timeout && (option.timeout = json.timeout);
  286. $.ajax(option);
  287. },
  288. tips:function(type,text,timer){//type:normal|error|success|info|load
  289. var type=type || "normal";
  290. var text=text || "提示";
  291. var timer=timer || 3000;
  292. var m=parseInt(Math.random()*1000000);
  293. var typetext={'wait':'<i class="wait"></i>','success':'<i class="success"></i>','error':'<i class="error"></i>','info':'<i class="info"></i>'}[type] || "";
  294. $(".tips-dialog").animate({marginTop:"-=5",opacity:"-=.2"},200);
  295. var $tip=$("<div>").addClass("tips-dialog").attr("id","tips"+m).html(typetext+text).appendTo("body");
  296. var oh=$tip.outerHeight(true),ow=$tip.outerWidth(true), s = ll.common.screen();
  297. var c = {top:(s.h-oh)/2,left:(s.w -ow)/2 + s.left};
  298. $tip.is(":visible")?$tip.animate(c,100):$tip.css(c);
  299. $tip.fadeIn(200);
  300. setTimeout(function(){
  301. $("#tips"+m).fadeOut(200,function(){
  302. $("#tips"+m).remove();
  303. });
  304. },timer);
  305. },
  306. loading:{
  307. show:function(){
  308. ll.lock.show();
  309. $("#loading-tip").size()?$("#loading-tip").show():$("<div id='loading-tip' class='loading-tip loading2'></div>").appendTo("body");
  310. },
  311. hide:function(){
  312. ll.lock.hide();
  313. $("#loading-tip").hide();
  314. }
  315. },
  316. MformBeauty:function(obj){//表单美化
  317. if(obj!=null && obj.is("select")){
  318. setTimeout(function(){
  319. obj.each(function(){
  320. $(this).siblings("span").text($(this).find("option:selected").text());
  321. $(this).prop("disabled")?$(this).parent("div").addClass("disabled"):$(this).parent("div").removeClass("disabled");
  322. });
  323. },10);
  324. return;
  325. }
  326. $(".x-select").each(function(){
  327. var _c=$(this);
  328. //if(_c.is(":hidden") || !_c.is("select")) return;//如果是隐藏的跳过
  329. _c.wrap('<div class="'+_c.attr("class")+'"></div>').before('<span>'+_c.find("option:selected").text()+'</span>');
  330. _c.removeAttr("class");
  331. if(_c.prop("disabled")){_c.parent("div").addClass("disabled");}
  332. _c.on("change",function(){
  333. _c.siblings("span").text(_c.find("option:selected").text());
  334. }).on("focus",function(){
  335. _c.parent().addClass("focus");
  336. }).on("blur",function(){
  337. _c.parent().removeClass("focus");
  338. });
  339. });
  340. $(".x-file").each(function(){
  341. var _c=$(this);
  342. //if(_c.is(":hidden") || !_c.is("input")) return;//如果是隐藏的跳过
  343. _c.wrap('<div class="'+_c.attr("class")+'"></div>').before('<span class="x-file-icon"></span><span class="x-file-text"></span><span class="x-file-btn">浏览...</span>');
  344. _c.removeAttr("class");
  345. _c.siblings(".x-file-text").text(_c.val());
  346. _c.on("change",function(){
  347. var _t=$(this).val(),_z="file";
  348. _c.siblings("i").remove();
  349. _c.siblings(".x-file-text").text("");
  350. if(_t==""){
  351. return;
  352. }
  353. var t1 = _t.lastIndexOf("\\");
  354. var t2 = _t.lastIndexOf(".");
  355. if( t1 < t2 && t1 < _t.length){
  356. _z =_t.substring(t2+1);
  357. _t =_t.substring(t1 + 1);
  358. }
  359. $("<i></i>").insertAfter(_c).addClass("i-"+_z);
  360. _c.siblings(".x-file-text").text(_t);
  361. }).on("focus",function(){
  362. _c.parent().addClass("focus");
  363. }).on("blur",function(){
  364. _c.parent().removeClass("focus");
  365. });
  366. });
  367. if(/msie 8\.0/i.test(navigator.userAgent.toLowerCase())) return;//如果是IE8 不修改单选复选框
  368. $(".x-radio").each(function(){
  369. var _c=$(this);
  370. //if(_c.is(":hidden") || !_c.is("input")) return;//如果是隐藏的跳过
  371. _c.wrap('<div class="'+_c.attr("class")+'"></div>').after("<b></b>");
  372. _c.removeAttr("class");
  373. _c.parent().on("click",function(){
  374. _c.prop("checked",true);
  375. _c.siblings("b").addClass("checked");
  376. _c.focus();
  377. });
  378. _c.on("focus",function(){
  379. _c.parent().addClass("focus");
  380. }).on("blur",function(){
  381. _c.parent().removeClass("focus");
  382. });
  383. });
  384. $(".x-checkbox").each(function(){
  385. var _c=$(this);
  386. //if(_c.is(":hidden") || !_c.is("input")) return;//如果是隐藏的跳过
  387. _c.wrap('<div class="'+_c.attr("class")+'"></div>').after("<b></b>");
  388. _c.removeAttr("class");
  389. _c.parent().on("click",function(){
  390. if(_c.prop("checked")){
  391. _c.prop("checked",false);
  392. }else{
  393. _c.prop("checked",true);
  394. }
  395. _c.focus();
  396. });
  397. _c.on("focus",function(){
  398. _c.parent().addClass("focus");
  399. }).on("blur",function(){
  400. _c.parent().removeClass("focus");
  401. });
  402. });
  403. },
  404. parseQuery: function (query) {//地址栏参数解析
  405. var parames = {};
  406. if ( ! query ) {return parames;}// return empty object
  407. var Pairs = query.split(/[;&]/);
  408. for ( var i = 0; i < Pairs.length; i++ ) {
  409. var KeyVal = Pairs[i].split('=');
  410. if ( ! KeyVal || KeyVal.length != 2 ) {continue;}
  411. var key = unescape( KeyVal[0] );
  412. var val = unescape( KeyVal[1] );
  413. val = val.replace(/\+/g, ' ');
  414. parames[key] = val;
  415. }
  416. return parames;
  417. },
  418. screen : function(){
  419. var s={
  420. w:$(window).width(),
  421. h:$(window).height(),
  422. left:document.documentElement.scrollLeft || document.body.scrollLeft,
  423. top:document.documentElement.scrollTop || document.body.scrollTop,
  424. sw:document.documentElement.scrollWidth || document.body.scrollWidth,
  425. sh:document.documentElement.scrollHeight || document.body.scrollHeight
  426. };
  427. return s;
  428. },
  429. center:function(o,b){//居中
  430. var oh=o.outerHeight(true),ow=o.outerWidth(true), s = ll.common.screen();
  431. if(oh>s.h){
  432. var c = {top:s.top+50,left:(s.w -ow)/2 + s.left,marginBottom:50};
  433. }else{
  434. var c = {top:(s.h-oh)/2+s.top,left:(s.w -ow)/2 + s.left};
  435. };
  436. o.is(":visible") && !b ?o.animate(c,100): o.css(c);
  437. return c;
  438. },
  439. messageCode:function(o,sec){//点击倒计时,用于验证码再次发送等 o:点击对象 sec:秒数 (默认60)
  440. if(o.hasClass("disabled")) return;
  441. var sec=sec || 60;
  442. var dt=o.text();
  443. if (o.attr("disabled")){return false;}
  444. o.text(sec+"秒后重发").addClass("disabled");
  445. var timer = setInterval(function(){
  446. sec=sec-1;
  447. if(sec>0){
  448. o.text(sec+"秒后重发").addClass("disabled");
  449. }else{
  450. clearInterval(timer);
  451. o.text(dt).removeClass("disabled");
  452. }
  453. },1000);
  454. },
  455. getCurrentDate : function(){//获取今天日期
  456. var objDate=new Date();
  457. var year = objDate.getYear();
  458. if(year < 1900){year = year + 1900;}
  459. var month = objDate.getMonth() + 1;
  460. var day = objDate.getDate();
  461. month = month>=10?month:'0'+month;day = day>=10?day:'0'+day;
  462. var date = year + "-" + month + "-" + day;return date;
  463. },
  464. getYesterDate : function(){//获取昨天日期
  465. var objDate=new Date();
  466. var year = objDate.getYear();
  467. if(year < 1900){year = year + 1900;}
  468. var month = objDate.getMonth() + 1;
  469. var day = objDate.getDate() -1;month = month>=10?month:'0'+month;
  470. day = day>=10?day:'0'+day;var date = year + "-" + month + "-" + day;
  471. return date;
  472. },
  473. datepicker:function(option){//日历控件激活
  474. var base=Context.base;
  475. $.getScript(base+"/js/datepicker.js").done(function( script, textStatus ) {
  476. $(".date-picker").datepicker(option);
  477. }).fail(function( jqxhr, settings, exception ) {
  478. alert("加载日历控件失败");
  479. });
  480. },
  481. city:function(province,city,callback){//省市联动
  482. var base=Context.base;
  483. var _province=$("#"+province);
  484. var _provinceValue=_province.data("value")!=null?_province.data("value"):"";
  485. var _city=$("#"+city);
  486. var _cityValue=_city.data("value")!=null?_city.data("value"):"";
  487. $.getScript(base+"/js/city.js").done(function( script, textStatus ) {
  488. //初始化省市
  489. _province.empty();
  490. _city.empty();
  491. var provinceJson='<option value="">请选择省份</option>';
  492. var cityJson='<option value="">请选择城市</option>';
  493. for (var i=0;i<cityJsonData.length;i++){
  494. provinceJson+='<option data-index="'+i+'" value="'+cityJsonData[i].province+'">'+cityJsonData[i].province+'</option>';
  495. }
  496. _province.html(provinceJson);
  497. _city.html(cityJson);
  498. ll.common.MformBeauty(_province);
  499. ll.common.MformBeauty(_city);
  500. _province.on("change",function(){
  501. var ind=$(this).find("option:selected").data("index");
  502. if(ind==null){
  503. cityJson='<option value="">请选择城市</option>';
  504. }else{
  505. cityJson="";
  506. for (var i=0;i<cityJsonData[ind].cities.length;i++){
  507. cityJson+='<option data-code="'+cityJsonData[ind].cities[i].cityId+'" value="'+cityJsonData[ind].cities[i].cityName+'">'+cityJsonData[ind].cities[i].cityName+'</option>';
  508. }
  509. }
  510. _city.html(cityJson);
  511. ll.common.MformBeauty(_city);
  512. });
  513. if(_provinceValue!=null){
  514. _province.find("option[value='"+_provinceValue+"']").prop("selected",true);
  515. ll.common.MformBeauty(_province);
  516. _province.change();
  517. _city.find("option[value='"+_cityValue+"']").prop("selected",true);
  518. ll.common.MformBeauty(_city);
  519. }
  520. }).fail(function( jqxhr, settings, exception ) {
  521. alert("加载省市联动控件失败");
  522. });
  523. },
  524. date:function(year,month,day,date){//身份证日期联动 date 格式 2015-06-30
  525. var _year=$("#"+year),_month=$("#"+month),_day=$("#"+day);
  526. _year.empty();
  527. _month.empty();
  528. _day.empty();
  529. var YearJson='',MonthJson='',DayJson='';
  530. var nowYear=parseInt(date.split("-")[0]),nowMonth=parseInt(date.split("-")[1]),nowDay=parseInt(date.split("-")[2]);
  531. for (var i=0;i<=20;i++){YearJson+='<option value="'+(nowYear+i)+'">'+(nowYear+i)+'年</option>';}
  532. for (var i=0;i<12;i++){
  533. var m=(i+1)>=10?(i+1):"0"+(i+1);
  534. MonthJson+=nowMonth==(i+1)?'<option selected="selected" value="'+m+'">'+(i+1)+'月</option>':'<option value="'+m+'">'+(i+1)+'月</option>';}
  535. for (var i=0;i<31;i++){
  536. var m=(i+1)>=10?(i+1):"0"+(i+1);
  537. DayJson+=nowDay==(i+1)?'<option selected="selected" value="'+m+'">'+(i+1)+'日</option>':'<option value="'+m+'">'+(i+1)+'日</option>';}
  538. _year.html(YearJson);
  539. _month.html(MonthJson);
  540. _day.html(DayJson);
  541. },
  542. checkIdcard:function(idcard){ ///////身份证号码验证
  543. var returnData={status:true};
  544. var idcard,Y,JYM;
  545. var S,M;
  546. var idcard_array = new Array();
  547. idcard_array = idcard.split("");
  548. //地区检验
  549. if(ll.common.IdCardGetArea(idcard)==false){
  550. returnData={status:false,msg:"请输入正确的身份证号码"};
  551. return returnData;
  552. };
  553. //身份号码位数及格式检验
  554. switch(idcard.length){
  555. case 15:
  556. if ( (parseInt(idcard.substr(6,2))+1900) % 4 == 0 || ((parseInt(idcard.substr(6,2))+1900) % 100 == 0 && (parseInt(idcard.substr(6,2))+1900) % 4 == 0 )){
  557. ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}$/;//测试出生日期的合法性
  558. } else {
  559. ereg=/^[1-9][0-9]{5}[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}$/;//测试出生日期的合法性
  560. }
  561. if(ereg.test(idcard)){
  562. returnData={status:true};
  563. return returnData;
  564. }else{
  565. returnData={status:false,msg:"请输入正确的身份证号码"};
  566. return returnData;
  567. };
  568. break;
  569. case 18:
  570. //18位身份号码检测
  571. //出生日期的合法性检查
  572. if ( parseInt(idcard.substr(6,4)) % 4 == 0 || (parseInt(idcard.substr(6,4)) % 100 == 0 && parseInt(idcard.substr(6,4))%4 == 0 )){
  573. ereg=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}[0-9Xx]$/;//闰年出生日期的合法性正则表达式
  574. } else {
  575. ereg=/^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|3[0-1])|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|1[0-9]|2[0-8]))[0-9]{3}[0-9Xx]$/;//平年出生日期的合法性正则表达式
  576. }
  577. if(ereg.test(idcard)){//测试出生日期的合法性
  578. //计算校验位
  579. S = (parseInt(idcard_array[0]) + parseInt(idcard_array[10])) * 7
  580. + (parseInt(idcard_array[1]) + parseInt(idcard_array[11])) * 9
  581. + (parseInt(idcard_array[2]) +parseInt(idcard_array[12])) * 10
  582. + (parseInt(idcard_array[3]) + parseInt(idcard_array[13])) * 5
  583. + (parseInt(idcard_array[4]) + parseInt(idcard_array[14])) * 8
  584. + (parseInt(idcard_array[5]) + parseInt(idcard_array[15])) * 4
  585. + (parseInt(idcard_array[6]) + parseInt(idcard_array[16])) * 2
  586. + parseInt(idcard_array[7]) * 1
  587. + parseInt(idcard_array[8]) * 6
  588. + parseInt(idcard_array[9]) * 3 ;
  589. Y = S % 11;
  590. M = "F";
  591. JYM = "10X98765432";
  592. M = JYM.substr(Y,1);//判断校验位
  593. if(M == idcard_array[17]){
  594. returnData={status:true};
  595. return returnData;
  596. }else{
  597. returnData={status:false,msg:"请输入正确的身份证号码"};
  598. return returnData;
  599. };//检测ID的校验位
  600. }else{
  601. returnData={status:false,msg:"请输入正确的身份证号码"};
  602. return returnData;
  603. }
  604. break;
  605. default:
  606. returnData={status:false,msg:"请输入正确的身份证号码"};
  607. return returnData;
  608. break;
  609. }
  610. return true;
  611. },
  612. IdCardGetArea:function(idcard){ ///////身份证号码地区验证
  613. var area={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国外" };
  614. var idcard,Y,JYM;
  615. var S,M;
  616. var idcard_array = new Array();
  617. idcard_array = idcard.split("");
  618. //地区检验
  619. if(area[parseInt(idcard.substr(0,2))]==null)
  620. return false;
  621. else
  622. return area[parseInt(idcard.substr(0,2))];
  623. },
  624. isArray:function(o){
  625. return Object.prototype.toString.call(o)=='[object Array]';
  626. }
  627. };
  628. //表单验证区块 @author xuwei 2015-06-15
  629. ll.validate={
  630. reg : {
  631. userName:/^([a-z|A-Z]+|[ \u4e00-\u9fa5]+|[0-9]+|[_|_]+)+$/,//用户名
  632. unCN:/^([a-z|A-Z]+|[0-9]+|[_|_]+)+$/,//英文数字特殊字符
  633. passWord:/^[\@A-Za-z0-9~!@#$%^&*()_+`\-={}:";'<>?,.\/\\]{6,32}$/,//密码
  634. passWordGruop:/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{0,10000}$/,//加强密码验证 必须包含特殊符号字母数字
  635. passWordStrong:/^(?=.*[a-zA-Z])(?=.*\d)(?=.*[~!@#$%^&*()_+`\-={}:";'<>?,.\/]).{6,32}$/,//加强密码验证 必须包含特殊符号字母数字
  636. CN:/^[\u4e00-\u9fa5]+$/,//中文
  637. realName:/^[\u2E80-\uFE4F](?:(•|·|\.|)[\u2E80-\uFE4F])+$/,// 支持中文姓名
  638. unNull:/^\S+$/, //非空
  639. Mobile:/^1[0-9]{10}$/, //手机
  640. bankCard:/^\d{15,19}$/, //银行卡
  641. bankCardCompany:/^\d{8,28}$/, //企业银行卡
  642. Number :/^[0-9]+$/,
  643. enNumber :/^[A-Za-z0-9]+$/, //英文数字
  644. Date:/^\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}$/,
  645. idCard:/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/, //身份证号码
  646. Email:/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/,//电子邮箱
  647. isFloat:/^\-?(-?\d*)\.?\d{1,2}$/, //正负保留两位小数
  648. isFloatPlus:/^(-?\d*)\.?\d{1,2}$/, //保留两位小数
  649. isFloatPlusThree:/^(-?\d*)\.?\d{1,3}$/, //保留三位小数
  650. Price:/^(([1-9]\d{0,9})|0)(\.\d{1,2})?$/, // 1.非负整数输入,如0、100等 2.两位小数的非负浮点数输入
  651. PriceThree:/^(([1-9]\d{0,9})|0)(\.\d{1,3})?$/, // 1.非负整数输入,如0、100等 2.三位小数的非负浮点数输入
  652. verCode:/^\d{6}$/, //验证码
  653. Float:/^[0-9]{1,}([.]{1}[0-9]{1,4}){0,1}$/,
  654. login:/^(([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)|1[0-9]{10})$/
  655. },
  656. mark:"validate",
  657. check:{},//验证列表容器
  658. results:{},
  659. showtip:function(type,msg,obj){ //传参 消息类型(exp,error,success),消息文本,验证对象或者显示位置
  660. if(obj.is("select,textarea,input") || obj.find("select,textarea,input").size()){
  661. if(obj.last().next(".x-tip").size()) obj.last().next(".x-tip").remove();
  662. $("<div>").addClass("x-tip").html("<span class='"+type+"'>"+msg+"</span>").insertAfter(obj.last());
  663. }else{
  664. obj.addClass("x-tip").html("<span class='"+type+"'>"+msg+"</span>");
  665. }
  666. },
  667. hidetip:function(obj){
  668. if(obj.is("select,textarea,input") || obj.find("select,textarea,input").size()){
  669. obj.last().next(".x-tip").remove();
  670. }else{
  671. obj.removeClass(".x-tip").html("");
  672. }
  673. },
  674. init:function(mark,list){//给list中的控件激活验证
  675. var parames = $.extend({
  676. type : null,//默认非空
  677. reg : null,
  678. empty : null,
  679. error : null,
  680. hold : false,
  681. success : null,
  682. byte : null,
  683. price : null,
  684. place : null,
  685. ext : null, //附加外部验证
  686. file : [], //文件类型允许上传的文件类型
  687. ajax : null//异步判断 null 或者 异步参数 ajax 参数 {url:url,data:data,}
  688. },list.parames);
  689. var _self = this;
  690. var _mark=mark;
  691. var _input=list.obj.is("div")?list.obj.children("input,textarea,select") : list.obj;//为了兼容文本框美化后class转移到包含的div
  692. /*var _tip=parames.place==null?list.obj:parames.place;//容器 *///不兼容文本框美化
  693. var _tip=parames.place==null?list.obj.closest("[class^='x-']").size()?list.obj.closest("[class^='x-']"):list.obj:parames.place;//容器(兼容文本框美化)
  694. var _type=_input.is("select")?"select":_input.is("textarea")?"text":_input.attr("type");
  695. var _ident=parseInt(Math.random()*1000000000000);//标识
  696. if(typeof(_self.results[_mark])=="undefined") _self.results[_mark]={};
  697. _self.results[_mark][_ident]=false;
  698. if(_input.is(":hidden") || !_input.size() || !_input.is(":disabled")){_self.results[_mark][_ident]=true;}
  699. var value=null;
  700. switch(_type){
  701. case "checkbox":
  702. case "radio":
  703. if(parames.error==null){
  704. _self.results[_mark][_ident]=true;
  705. return;
  706. }
  707. _input.off("blur.validate").on("blur.validate",function(){
  708. if(_input.is(":hidden")){
  709. _self.results[_mark][_ident]=true;
  710. return false;
  711. }
  712. value=_input.filter(":checked").val();
  713. value=typeof(value)=="undefined"?"":value;
  714. if(value==""){
  715. _self.results[_mark][_ident]=false;
  716. _self.showtip("error",parames.error,_tip);
  717. return false;
  718. }else{
  719. _self.results[_mark][_ident]=true;
  720. _self.hidetip(_tip);
  721. }
  722. });
  723. break;
  724. case "select":
  725. if(parames.error==null){
  726. _self.results[_mark][_ident]=true;
  727. return;
  728. }
  729. _input.off("blur.validate").on("blur.validate",function(){
  730. if(_input.is(":hidden")){
  731. _self.results[_mark][_ident]=true;
  732. return false;
  733. }
  734. value=_input.val();
  735. value=typeof(value)=="undefined"?"":value;
  736. if(value==""){
  737. _self.results[_mark][_ident]=false;
  738. _self.showtip("error",parames.error,_tip);
  739. return false;
  740. }else{
  741. _self.results[_mark][_ident]=true;
  742. _self.hidetip(_tip);
  743. }
  744. });
  745. break;
  746. case "file":
  747. _input.off("change.validate blur.validate").on("change.validate blur.validate",function(){
  748. if(_input.is(":hidden")){
  749. _self.results[_mark][_ident]=true;
  750. return false;
  751. }
  752. value=_input.val();
  753. value=typeof(value)=="undefined"?"":value;
  754. if(value.length==0 && parames.empty!=null){
  755. _self.results[_mark][_ident]=false;
  756. _self.showtip("error",parames.empty,_tip);
  757. return false;
  758. }
  759. if(parames.error==null){
  760. _self.results[_mark][_ident]=true;
  761. return;
  762. }
  763. var t2 = value.lastIndexOf(".");
  764. _z =value.substring(t2+1);
  765. for(var i=0; i<parames.file.length; i++){
  766. if(parames.file[i].toUpperCase()==_z.toUpperCase()){
  767. _self.results[_mark][_ident]=true;
  768. _self.hidetip(_tip);
  769. return;
  770. };
  771. }
  772. _self.results[_mark][_ident]=false;
  773. _self.showtip("error",parames.error,_tip);
  774. return false;
  775. });
  776. break;
  777. default:
  778. _input.off("focus.validate blur.validate").on("focus.validate",function(){
  779. parames.tips!=null?( parames.tips!="" && _self.showtip("exp",parames.tips,_tip) ):_self.hidetip(_tip);
  780. }).on("blur.validate",function(){
  781. if(_input.is(":hidden")){
  782. _self.results[_mark][_ident]=true;
  783. return false;
  784. }
  785. //屏蔽非密码输入框前后空格
  786. _input.not(":password").val(_input.val().replace(/(^\s*)|(\s*$)/g, ""));
  787. value=_input.val();
  788. value=typeof(value)=="undefined"?"":value;
  789. //非空判断
  790. if(parames.empty!=null){
  791. if(value.length==0){
  792. _self.results[_mark][_ident]=false;
  793. _self.showtip("error",parames.empty,_tip);
  794. return false;
  795. }
  796. };
  797. //字符长度验证
  798. if(parames.byte!=null){
  799. var min=parames.byte[0] || 0;
  800. var max=parames.byte[1] || 1000;
  801. var err=parames.byte[2] || parames.error;
  802. if(value.replace(/[^\x00-\xff]/g,"***").length < min || value.replace(/[^\x00-\xff]/g, "***").length > max){
  803. _self.results[_mark][_ident]=false;
  804. _self.showtip("error",err,_tip);
  805. return false;
  806. };
  807. };
  808. //外部函数判断
  809. if(parames.ext!=null){
  810. var ext=parames.ext(_input);
  811. //example return {status:true|false,msg:"验证通过|不通过"}
  812. if(!ext.status){
  813. _self.results[_mark][_ident]=false;
  814. _self.showtip("error",ext.msg,_tip);
  815. return false;
  816. }
  817. };
  818. //type 正则验证
  819. if(parames.type!=null){
  820. var reg=_self.reg[parames.type];
  821. if (reg==null) return;
  822. if(!reg.test(value)){
  823. _self.results[_mark][_ident]=false;
  824. _self.showtip("error",parames.error,_tip);
  825. return false;
  826. }
  827. if(parames.type=="idCard"){//身份证验证
  828. if(!ll.common.checkIdcard(value.replace(/\s+/g,"").replace("x","X")).status){
  829. _self.results[_mark][_ident]=false;
  830. _self.showtip("error",ll.common.checkIdcard(value.replace(/\s+/g,"")).msg,_tip);
  831. return false;
  832. }
  833. }
  834. };
  835. //自定义正则验证
  836. if(parames.reg!=null){
  837. var reg= parames.reg;
  838. if(!reg.test(value)){
  839. _self.results[_mark][_ident]=false;
  840. _self.showtip("error",parames.error,_tip);
  841. return false;
  842. }
  843. };
  844. //金额判断
  845. if(parames.price!=null){
  846. var min=parames.price[0]*100 || 0;
  847. var max=parames.price[1]*100 || 9999999999999999999999999;
  848. var err=parames.price[2] || parames.error;
  849. if(parseInt(value.replace(/[^0-9.]+/,''))*100< min || (value.replace(/[^0-9.]+/,''))*100 > max){
  850. _self.results[_mark][_ident]=false;
  851. _self.showtip("error",err,_tip);
  852. return false;
  853. };
  854. };
  855. //异步验证
  856. if(parames.ajax!=null){
  857. var ajaxStatus=true;
  858. var url=parames.ajax.url||"";
  859. var data=parames.ajax.data|| {};
  860. var zb="";
  861. for(var key in data){
  862. var value = data[key];
  863. zb+=(zb==""?"":"&")+key+"="+value.val();
  864. }
  865. $.ajax({
  866. url: url+"?m=" + Math.random(),
  867. async: false,
  868. dataType: 'json',
  869. type:"POST",
  870. data:zb,
  871. beforeSend:function(){
  872. !parames.hold && _self.showtip("waiting","",_tip);
  873. },
  874. success: function(data) {
  875. var err=data.retmsg || "验证不通过!";
  876. if(data.retcode=="0000"){
  877. !parames.hold && _self.hidetip(_tip);
  878. }else{
  879. ajaxStatus=false;
  880. _self.results[_mark][_ident]=false;
  881. _self.showtip("error",err,_tip);
  882. return false;
  883. }
  884. //返回0000 通过
  885. },
  886. error: function(XMLHttpRequest, textStatus, errorThrown) {
  887. ajaxStatus=false;
  888. _self.results[_mark][_ident]=false;
  889. _self.showtip("error","服务器错误!",_tip);
  890. return false;
  891. }
  892. });
  893. if(!ajaxStatus) return false;//ajax不通过
  894. };
  895. parames.success!=null?_self.showtip("success",parames.success,_tip):(!parames.hold && _self.hidetip(_tip));
  896. _self.results[_mark][_ident]=true;
  897. });
  898. break;
  899. }
  900. },
  901. add:function(option){//添加验证对象数组
  902. var _option=typeof (option) == "undefined"?{}:option;
  903. var _self=this;
  904. var _mark=_option.mark || _self.mark;
  905. for(var i=0;i<_option.list.length;i++){
  906. _self.check[_mark].push(_option.list[i]);
  907. }
  908. _self.results[_mark]={};//清空数组
  909. for(var i=0;i<_self.check[_mark].length;i++){
  910. _self.init(_mark,_self.check[_mark][i]);
  911. }
  912. },
  913. update:function(option){//更新验证对象数组
  914. var _option=typeof (option) == "undefined"?{}:option;
  915. var _self=this;
  916. var _mark=_option.mark || _self.mark;
  917. _self.check[_mark]=_option.list;
  918. _self.results[_mark]={};//清空数组
  919. for(var i=0;i<_self.check[_mark].length;i++){
  920. _self.init(_mark,_self.check[_mark][i]);
  921. }
  922. },
  923. destroy:function(option){
  924. var _option=typeof (option) == "undefined"?{}:option;
  925. var _self=this;
  926. var _mark=_option.mark || _self.mark;
  927. delete _self.check[_mark];
  928. },
  929. submit:function(option){//接受参数json
  930. var _option=typeof (option) == "undefined"?{}:option;
  931. var _self=this;
  932. var _mark=_option.mark || this.mark;
  933. _self.check[_mark]=_option.list;
  934. for(var i=0;i<_self.check[_mark].length;i++){
  935. _self.init(_mark,_self.check[_mark][i]);
  936. }
  937. var sEvent=_option.obj.is("form")?"submit":"click";
  938. _option.obj.on(sEvent,function(e){
  939. var status=true;
  940. for(var i=0;i<_self.check[_mark].length;i++){
  941. var _input=_self.check[_mark][i].obj.is("div")?_self.check[_mark][i].obj.children("input,textarea,select"):_self.check[_mark][i].obj;//为了兼容文本框美化后class转移到包含的div
  942. _input.blur();
  943. }
  944. for (var j in _self.results[_mark]){
  945. if(_self.results[_mark][j]==false){status=false;}
  946. };
  947. if (status && typeof (_option.callback) == "function") {
  948. _option.callback();
  949. } else if (!status){
  950. return false;
  951. }
  952. });
  953. }
  954. };
  955. /* 对话框 */
  956. /*自定义提示信息box
  957. *@param type 提示框类型alert|confirm
  958. *@param head 提示框是否显示
  959. *@param title 提示框标题
  960. *@param clazz 父元素增加样式类
  961. *@param content 提示内容
  962. *@param width 提示框宽度
  963. *@param move 是否可以拖动true|false
  964. *@param lock 是否锁屏true|false
  965. *@param scroll 内容超出滚动
  966. *@param before 加载之前事件回调
  967. *@param load 加载中事件回调
  968. *@param enterFunc 回车事件回调
  969. *@param destroyFunc 销毁事件回调
  970. *@param buttons array[
  971. *@value 按钮文字
  972. *@handle 当点击处理function]
  973. */
  974. ll.dialog={
  975. boxs : {},
  976. create : function(op){
  977. op = $.extend({
  978. type : 'box',
  979. head : 'show',
  980. buttons : []
  981. },op);
  982. if(this.boxs[op.type])return this.boxs[op.type];
  983. var config=this.boxs[op.type]={};
  984. var t1 = $('<label></label>');
  985. var t2 = $('<span></span>');
  986. var t=$('<div class="ll-dialog-hd"></div>').append(t1).append(t2);
  987. if(op.head=="hide") {
  988. t.hide();
  989. }
  990. var c = $('<div class="ll-dialog-bd"></div>');
  991. var o = $('<div class="ll-dialog '+op.clazz+'"></div>').append(t).append(c);
  992. if(op.buttons.length>0){
  993. var b = $('<div class="ll-dialog-bt"></div>');
  994. var buttons = [];
  995. $(op.buttons).each(function(i,v){
  996. buttons[i] = $('<input type="button" class="button" value="'+v+'">');
  997. b.append(buttons[i]);
  998. b.append(' ');
  999. });
  1000. o.append(b);
  1001. this.boxs[op.type]['buttons'] = buttons;
  1002. }
  1003. o.css("display","none").appendTo(document.body).focus();
  1004. this.boxs[op.type].obj = $(o);
  1005. this.boxs[op.type].title = t1;
  1006. this.boxs[op.type].content = c;
  1007. this.boxs[op.type].close = t2;
  1008. this.boxs[op.type].option = op;
  1009. return this.boxs[op.type];
  1010. },
  1011. simple : function(op){
  1012. var self = this;
  1013. op = $.extend({
  1014. type : 'BOX',
  1015. head : 'show',
  1016. title : '提示',
  1017. clazz : '',
  1018. content : '',
  1019. width : 400,
  1020. move : false,
  1021. lock : false,
  1022. scroll : true,
  1023. before : $.noop,
  1024. load : $.noop,
  1025. enterFunc : function(){ll.dialog.close(op.type); },
  1026. escFunc : function(){ll.dialog.close(op.type);},
  1027. destroyFunc:function(){}
  1028. },op);
  1029. //call before function
  1030. op.before();
  1031. //create base box HTML
  1032. var buttons = [],butFunc = [];
  1033. $(op.buttons).each(function(i,n){
  1034. buttons.push(n.value);
  1035. butFunc.push(n.handle||$.noop);
  1036. });
  1037. var cloneOp = {};
  1038. $.extend(true,cloneOp, op);
  1039. cloneOp.buttons = buttons;
  1040. var o = this.create(cloneOp);
  1041. o.lock = op.lock;
  1042. //update Info
  1043. o.title.html(op.title);
  1044. if(typeof(op.content)=='object'||op.content.indexOf('#')==0)
  1045. {
  1046. op.content=$(op.content);
  1047. o.restore=op.content.clone(true);
  1048. o.content.html(op.content.html());
  1049. op.content.remove();
  1050. }
  1051. else
  1052. o.content.html(op.content);
  1053. o.obj.css('width',op.width);
  1054. if(op.height){
  1055. var mh = op.height - 40;
  1056. if(!op.scroll){
  1057. o.content.css({
  1058. height : mh,
  1059. overflow : 'hidden'
  1060. });
  1061. }else{
  1062. o.content.css({
  1063. height : mh,
  1064. maxHeight : mh+1,
  1065. overflow : 'auto'
  1066. });
  1067. }
  1068. }
  1069. //bind Event
  1070. o.close.unbind('click');
  1071. o.close.bind({
  1072. click : function(){
  1073. ll.dialog.close(op.type);
  1074. }
  1075. });
  1076. $(o.buttons).each(function(i,n){
  1077. n.unbind('click');
  1078. n.click(function(){butFunc[i](o);});
  1079. });
  1080. if(o.buttons&&o.buttons.length>0){
  1081. $(document.body).unbind('keydown');
  1082. $(document.body).bind('keydown',function(event){
  1083. if(event.keyCode==27){op.escFunc();ll.dialog.close(op.type);}
  1084. if(event.keyCode==13){op.enterFunc();ll.dialog.close(op.type);}
  1085. });
  1086. }
  1087. //align center
  1088. ll.common.center(o.obj);
  1089. if(op.move){if(!ll.draggable)return alert('ll.draggable 插件未加载');ll.draggable(o.obj.find('.ll-dialog-hd'),o.obj);}
  1090. if(op.lock){if(!ll.lock)return alert('ll.lock 插件未加载');ll.lock.show();}
  1091. o.obj.show();
  1092. o.obj.focus();
  1093. //call loaded function
  1094. op.load(o);
  1095. },
  1096. close : function(op){
  1097. var c = 0,op=typeof(op)=='string' ? this.boxs[op] : op;
  1098. for(var k in this.boxs){
  1099. if(this.boxs[k].lock){
  1100. if(this.boxs[k].obj.is(":visible"))
  1101. c++;
  1102. }
  1103. }
  1104. if(op){op.obj.hide();}
  1105. if(c<=1){ll.lock.hide();}
  1106. if(op.restore){op.restore.appendTo(document.body);}
  1107. if (op && op.option) {
  1108. op.option.destroyFunc();
  1109. }
  1110. },
  1111. alert : function(op){
  1112. if(op.buttons){
  1113. $(op.buttons).each(function(i,v){
  1114. if(!v.handle){
  1115. v.handle=function(o){ll.dialog.close(o);}
  1116. }
  1117. });
  1118. }
  1119. if(typeof(op)=='string'){
  1120. this.simple({
  1121. type : 'alert',
  1122. head : 'show',
  1123. title : '提示',
  1124. content : '<div>'+op+'</div>',
  1125. lock : true,
  1126. move : false,
  1127. enterFunc : op.ok,
  1128. escFunc : op.ok,
  1129. destroyFunc:op.destroyFunc,
  1130. buttons : op.buttons || [{
  1131. value : '确定',
  1132. handle : function(o){
  1133. ll.dialog.close(o);
  1134. }
  1135. }]
  1136. });
  1137. }else{
  1138. this.simple({
  1139. type : 'alert',
  1140. head : op.head,
  1141. title : op.title || '提示',
  1142. content : op.content,
  1143. clazz : op.clazz,
  1144. width : op.width,
  1145. lock : op.lock||true,
  1146. move : op.move|| false,
  1147. load : op.load,
  1148. enterFunc : op.ok,
  1149. escFunc : op.ok,
  1150. destroyFunc:op.destroyFunc,
  1151. buttons : op.buttons || [{
  1152. value : '确定',
  1153. handle : function(o){
  1154. op.ok&&op.ok(o);
  1155. ll.dialog.close(o);
  1156. }
  1157. }]
  1158. });
  1159. }
  1160. },
  1161. confirm : function(op){
  1162. if(op.buttons){
  1163. $(op.buttons).each(function(i,v){
  1164. if(!v.handle){
  1165. v.handle=function(o){ll.dialog.close(o);}
  1166. }
  1167. });
  1168. }
  1169. this.simple({
  1170. type : 'confirm',
  1171. head : op.head,
  1172. title : op.title || '提示',
  1173. content : op.content,
  1174. width : op.width,
  1175. lock : op.lock||true,
  1176. move : op.move|| false,
  1177. load : op.load,
  1178. enterFunc : op.ok,
  1179. escFunc : op.cancel,
  1180. destroyFunc:op.destroyFunc,
  1181. buttons : op.buttons || [{
  1182. value : '确定',
  1183. handle : function(o){
  1184. op.ok&&op.ok(o);
  1185. ll.dialog.close(o);
  1186. }
  1187. },{
  1188. value : '取消',
  1189. handle : function(o){
  1190. op.cancel&&op.cancel(o);
  1191. ll.dialog.close(o);
  1192. }
  1193. }]
  1194. });
  1195. }
  1196. };
  1197. /* 拖动 */
  1198. ll.draggable=function(obj,dragObj,box){
  1199. dragObj = dragObj || obj;
  1200. var obj = $(obj);
  1201. var dragObj = $(dragObj);
  1202. if(!dragObj)return;
  1203. obj.css('cursor','move');
  1204. var pos,h=this,o=$(document);
  1205. var oh = dragObj.outerHeight();
  1206. var ow = dragObj.outerWidth();
  1207. obj.mousedown(function(event){
  1208. if(h.setCapture)h.setCapture();
  1209. pos = {
  1210. top : dragObj.position().top,
  1211. left : dragObj.position().left
  1212. };
  1213. pos = {
  1214. top : event.clientY - pos.top,
  1215. left : event.clientX - pos.left
  1216. };
  1217. o.mousemove(function(event){
  1218. try{
  1219. if (window.getSelection) {
  1220. window.getSelection().removeAllRanges();
  1221. } else {
  1222. document.selection.empty();
  1223. }
  1224. }catch(e){}
  1225. if(box==null){
  1226. var s = ll.common.screen();
  1227. var maxTop = s.sh;
  1228. var maxLeft = s.sw;
  1229. var top = Math.max(event.clientY-pos.top,0);
  1230. var left = Math.max(event.clientX-pos.left,0);
  1231. }else{
  1232. var s = box;
  1233. maxTop = s.height();
  1234. maxLeft = s.width();
  1235. top = Math.max(event.clientY-pos.top,0);
  1236. left = Math.max(event.clientX-pos.left,0);
  1237. }
  1238. dragObj.css({top:Math.min(top,maxTop-oh),left:Math.min(left,maxLeft-ow)});
  1239. });
  1240. o.mouseup(function(event){
  1241. if(h.releaseCapture)h.releaseCapture();
  1242. o.unbind('mousemove');
  1243. o.unbind('mouseup');
  1244. });
  1245. });
  1246. };
  1247. /* 锁屏 */
  1248. ll.lock={
  1249. source : null,
  1250. initialize : function(op){
  1251. var s = ll.common.screen();
  1252. op = op || {w : s.sw,h : s.sh,t : 0,l : 0};
  1253. if(!this.o){
  1254. this.o = $(document.createElement("div"));
  1255. this.o.attr('id','ll-mask');
  1256. this.o.css({
  1257. 'background' : '#000',
  1258. 'top' : 0,
  1259. 'left' : 0,
  1260. 'bottom' : 0,
  1261. 'right' : 0,
  1262. 'position' : 'fixed',
  1263. 'zIndex' : 2000,
  1264. 'opacity' : 0.5,
  1265. 'filter' : 'Alpha(opacity=50)',
  1266. 'display' : 'none'
  1267. });
  1268. this.o.appendTo(document.body);
  1269. //$(window).resize(function(){if(this.o.isVisible()) {this.show(this.source);}}.bind(this));
  1270. }else{
  1271. this.o.css({
  1272. width : op.w,
  1273. height : op.h,
  1274. top : op.t,
  1275. left : op.l
  1276. });
  1277. }
  1278. },
  1279. show : function(obj){
  1280. this.source=obj;
  1281. var op = !obj ? null : {
  1282. w : $(obj).outerWidth(),
  1283. h : $(obj).outerHeight(),
  1284. t : $(obj).position().top,
  1285. l : $(obj).position().left
  1286. };
  1287. this.initialize(op);
  1288. this.o.show();
  1289. },
  1290. hide : function(){
  1291. if(this.o)this.o.hide();
  1292. }
  1293. };
  1294. /* 浏览器检测 */
  1295. ll.browser= {
  1296. ua: function () {
  1297. var u = navigator.userAgent;
  1298. return { //移动终端浏览器版本信息
  1299. trident: u.indexOf('Trident') > -1, //IE内核
  1300. presto: u.indexOf('Presto') > -1, //opera内核
  1301. webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
  1302. gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
  1303. mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
  1304. iOS: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
  1305. android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
  1306. iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
  1307. iPad: u.indexOf('iPad') > -1, //是否iPad
  1308. webApp: u.indexOf('Safari') == -1, //是否web应该程序,没有头部与底部
  1309. weChat: u.indexOf('MicroMessenger') > -1,
  1310. UC: u.indexOf('UCBrowser') > -1,
  1311. u3: u.indexOf('U3') > -1,
  1312. chrome: u.indexOf('Chrome') > -1,
  1313. windowsPhone: u.indexOf("Windows Phone") > -1,
  1314. samsung: u.indexOf("Samsung") > -1,
  1315. QQ: u.indexOf("QQBrowser") > -1,
  1316. llfx: u.indexOf("CBExchange") > -1,
  1317. };
  1318. }()
  1319. };
  1320. $(function(){
  1321. "use strict";
  1322. //IE8以下浏览器的升级提示
  1323. if (window.navigator.appName == "Microsoft Internet Explorer") {
  1324. if (!document.documentMode || document.documentMode < 8) {
  1325. $("body").prepend('<div class="FUCKIE"><div class="bd"><a href="javascript:;" class="closeFUCKIE">&times;</a>您目前使用的是较低版本IE内核的浏览器,为了最佳的性能体验,建议您&nbsp;<a target="_blank" href="http://browsehappy.com">升级浏览器</a>&nbsp;或使用chrome浏览器。</div></div>');
  1326. $(".closeFUCKIE").click(function(){
  1327. $(".FUCKIE").remove();
  1328. });
  1329. }
  1330. }
  1331. //$('[placeholder]').placeholder({isUseSpan:true});
  1332. $(".titletip").titletip();
  1333. //模拟下拉框
  1334. ll.common.MformBeauty();
  1335. //对话框
  1336. $("body").on("click",".llDialog",function(event){
  1337. event.preventDefault();
  1338. var url=$(this).attr("href");
  1339. var queryString = url.replace(/^[^\?]+\??/,'');
  1340. var parames = ll.common.parseQuery( queryString );
  1341. var d_wid=parames['width']==null?'auto':(parames['width']*1) + 30;
  1342. var d_hei=parames['height']==null?'auto':(parames['height']*1) + 40;
  1343. var d_title=$(this).attr("title");
  1344. ll.lock.show();
  1345. $("#loading-tip").size()?$("#loading-tip").show():$("<div id='loading-tip' class='loading-tip loading2'></div>").appendTo("body");
  1346. ll.common.loadPage(url,{},null,null,function(data){
  1347. $("#loading-tip").remove();
  1348. ll.dialog.simple({
  1349. type : 'llDialog',
  1350. lock : true,
  1351. move : true,
  1352. title : d_title,
  1353. content : data,
  1354. width : $(data).width(),
  1355. load : function(){
  1356. }
  1357. });
  1358. });
  1359. });
  1360. var resizeTimer = null;
  1361. $(window).resize(function(){
  1362. if(resizeTimer){clearTimeout(resizeTimer)};
  1363. resizeTimer = setTimeout(function(){$(".ll-dialog").size?ll.common.center($(".ll-dialog")):"";}, 400);
  1364. });
  1365. $("body").on("keydown",function(event){
  1366. if (event.keyCode==13 && $(".action-bar").find("a:first").size()){
  1367. $(".action-bar").find("a:first").click();
  1368. }
  1369. });
  1370. });
  1371. //验证码
  1372. //@param IDs array 默认“vali”
  1373. function refresh(IDs){
  1374. var imgUrl = Context.base + "/captcha.htm?t="+new Date().getTime();
  1375. if(IDs && IDs.length){
  1376. $(IDs).each(function(i,id){
  1377. document.getElementById(id).src=imgUrl;
  1378. });
  1379. }
  1380. else {
  1381. document.getElementById("vali").src=imgUrl;
  1382. }
  1383. //验证码结果
  1384. $(".codeResult").hide();
  1385. }
  1386. //email autocomplate
  1387. function EmailAutoComplete(a){this.config={targetCls:".inputElem",parentCls:".parentCls",hiddenCls:".hiddenCls",searchForm:".jqtransformdone",hoverBg:"hoverBg",inputValColor:"black",mailArr:"@qq.com @163.com @126.com @189.com @sina.com @hotmail.com @gmail.com @sohu.com".split(" "),isSelectHide:!0,callback:null};this.cache={onlyFlag:!0,currentIndex:-1,oldIndex:-1};this.init(a)}EmailAutoComplete.prototype={constructor:EmailAutoComplete,init:function(a){this.config=$.extend(this.config,a||{});var d=this,c=d.config,b=d.cache;$(c.targetCls).each(function(a,f){$(f).keyup(function(a){var e=a.target,h=$.trim($(this).val()),m=a.keyCode,n=$(this).outerHeight(),p=$(this).outerWidth(),q=parseInt($(this).css("margin-top")),g=$(this).closest(c.parentCls);$(g).css({position:"relative"});""==h?($(f).attr({"data-html":""}),$(c.hiddenCls,g).val(""),b.currentIndex=-1,b.oldIndex=-1,$(".auto-tip",g)&&!$(".auto-tip",g).is(":hidden")&&$(".auto-tip",g).hide(),d._removeBg(g)):($(f).attr({"data-html":h}),$(c.hiddenCls,g).val(h),$(".auto-tip",g)&&$(".auto-tip",g).is(":hidden")&&$(".auto-tip",g).show(),d._renderHTML({keycode:m,e:a,target:e,targetVal:h,height:n,width:p,marginTop:q,parentNode:g}))})});$(c.searchForm).each(function(a,b){$(b).keydown(function(a){if(13==a.keyCode)return!1})});$(document).click(function(a){a.stopPropagation();a=a.target;var b=c.targetCls.replace(/^\./,"");$(a).hasClass(b)||$(".auto-tip")&&$(".auto-tip").each(function(a,b){!$(b).is(":hidden")&&$(b).hide()})})},_renderHTML:function(a){var d=this.config,c=this.cache,b,e=this._keyCode(a.keycode);$(".auto-tip",a.parentNode).is(":hidden")&&$(".auto-tip",a.parentNode).show();if(-1<e)this._keyUpAndDown(a.targetVal,a.e,a.parentNode);else{b=/@/.test(a.targetVal)?a.targetVal.replace(/@.*/,""):a.targetVal;if(c.onlyFlag){$(a.parentNode).append('\x3cinput type\x3d"hidden" class\x3d"hiddenCls"/\x3e');for(var e='\x3cul class\x3d"auto-tip"\x3e',f=0;f<d.mailArr.length;f++)e+='\x3cli class\x3d"p-index'+f+'"\x3e\x3cspan class\x3d"output-num"\x3e\x3c/span\x3e\x3cem class\x3d"em" data-html\x3d"'+d.mailArr[f]+'"\x3e'+d.mailArr[f]+"\x3c/em\x3e\x3c/li\x3e";e+="\x3c/ul\x3e";c.onlyFlag=!1;$(a.parentNode).append(e);$(".auto-tip",a.parentNode).css({position:"absolute",top:a.height+a.marginTop,width:a.width-2+"px",left:0,border:"1px solid #ccc","z-index":1E4})}$(".auto-tip li",a.parentNode).each(function(a,c){$(".output-num",c).html(b);!$(".output-num",c).hasClass(d.inputValColor)&&$(".output-num",c).addClass(d.inputValColor);var e=$.trim($(".em",c).attr("data-html"));$(c).attr({"data-html":b+""+e})});this._accurateMate({target:a.target,parentNode:a.parentNode});this._itemHover(a.parentNode);this._executeClick(a.parentNode)}},_accurateMate:function(a){var d=this.config,c=this.cache,b=$.trim($(a.target,a.parentNode).attr("data-html")),e=[];if(/@/.test(b)){var f=b.replace(/@.*/,""),l=b.replace(/.*@/,"");$.map(d.mailArr,function(a){(new RegExp(l)).test(a)&&e.push(a)});if(0<e.length){$(".auto-tip",a.parentNode).html("");$(".auto-tip",a.parentNode)&&$(".auto-tip",a.parentNode).is(":hidden")&&$(".auto-tip",a.parentNode).show();for(var b="",k=0,h=e.length;k<h;k++)b+='\x3cli class\x3d"p-index'+k+'"\x3e\x3cspan class\x3d"output-num"\x3e\x3c/span\x3e\x3cem class\x3d"em" data-html\x3d"'+e[k]+'"\x3e'+e[k]+"\x3c/em\x3e\x3c/li\x3e";$(".auto-tip",a.parentNode).html(b);$(".auto-tip li",a.parentNode).each(function(a,b){$(".output-num",b).html(f);!$(".output-num",b).hasClass(d.inputValColor)&&$(".output-num",b).addClass(d.inputValColor);var c=$.trim($(".em",b).attr("data-html"));$(b).attr("data-html","");$(b).attr({"data-html":f+""+c})});c.currentIndex=-1;c.oldIndex=-1;$(".auto-tip .output-num",a.parentNode).html(f);this._itemHover(a.parentNode);this._executeClick(a.parentNode)}else $(".auto-tip",a.parentNode)&&!$(".auto-tip",a.parentNode).is(":hidden")&&$(".auto-tip",a.parentNode).hide(),$(".auto-tip",a.parentNode).html("")}},_itemHover:function(a){var d=this.config;$(".auto-tip li",a).hover(function(a,b){!$(this).hasClass(d.hoverBg)&&$(this).addClass(d.hoverBg)},function(){$(this).hasClass(d.hoverBg)&&$(this).removeClass(d.hoverBg)})},_removeBg:function(a){var d=this.config;$(".auto-tip li",a).each(function(a,b){$(b).hasClass(d.hoverBg)&&$(b).removeClass(d.hoverBg)})},_keyUpAndDown:function(a,d,c){var b=this.cache;a=this.config;if($(".auto-tip li",c)&&0<$(".auto-tip li").length){var e=$(".auto-tip li",c).length;d=d.keyCode;b.oldIndex=b.currentIndex;38==d?(-1==b.currentIndex?b.currentIndex=e-1:(--b.currentIndex,0>b.currentIndex&&(b.currentIndex=e-1)),-1!==b.currentIndex&&(!$(".auto-tip .p-index"+b.currentIndex,c).hasClass(a.hoverBg)&&$(".auto-tip .p-index"+b.currentIndex,c).addClass(a.hoverBg).siblings().removeClass(a.hoverBg),b=$(".auto-tip .p-index"+b.currentIndex,c).attr("data-html"),$(a.targetCls,c).val(b),$(a.hiddenCls,c).val(b))):40==d?(b.currentIndex==e-1?b.currentIndex=0:(b.currentIndex++,b.currentIndex>e-1&&(b.currentIndex=0)),-1!==b.currentIndex&&(!$(".auto-tip .p-index"+b.currentIndex,c).hasClass(a.hoverBg)&&$(".auto-tip .p-index"+b.currentIndex,c).addClass(a.hoverBg).siblings().removeClass(a.hoverBg),b=$(".auto-tip .p-index"+b.currentIndex,c).attr("data-html"),$(a.targetCls,c).val(b),$(a.hiddenCls,c).val(b))):13==d&&(d=$(".auto-tip .p-index"+b.oldIndex,c).attr("data-html"),$(a.targetCls,c).val(d),$(a.hiddenCls,c).val(d),a.isSelectHide&&!$(".auto-tip",c).is(":hidden")&&$(".auto-tip",c).hide(),a.callback&&$.isFunction(a.callback)&&a.callback(),b.currentIndex=-1,b.oldIndex=-1)}},_keyCode:function(a){for(var d="17 18 38 40 37 39 33 34 35 46 36 13 45 44 145 19 20 9".split(" "),c=0,b=d.length;c<b;c++)if(a==d[c])return c;return-1},_executeClick:function(a){var d=this.config;$(".auto-tip li",a).unbind("mousedown");$(".auto-tip li",a).bind("mousedown",function(c){c=$(this).attr("data-html");$(d.targetCls,a).val(c);d.isSelectHide&&!$(".auto-tip",a).is(":hidden")&&$(".auto-tip",a).hide();$(d.hiddenCls,a).val(c);d.callback&&$.isFunction(d.callback)&&d.callback()})}};