');
202 | $('#tm-tip-content').css("textAlign",opts.contentAlign).html(content);//设置内容
203 | if(opts.width!=0){$(".tm-window-tip").css({width:opts.width});}/*设置高度如果高度设置为0:则为自动高度*/
204 | if(opts.height!=0){$(".tm-window-tip").css({height:opts.height});}/*设置高度如果高度设置为0:则为自动高度*/
205 | var _selfWidth = $(".tm-window-tip").width();//tip框的宽度
206 | var _selfHeight = $(".tm-window-tip").height();//tip框的高度
207 | var height = $this.height();/*元素自身高度*/
208 | var width = $this.width();/*元素自身宽度*/
209 | var offsetLeft = $this.offset().left;/*元素的相对左边距*/
210 | var offsetTop = $this.offset().top;/*元素的相对顶部距离*/
211 | var bodyWidth = $("body").innerWidth();
212 | var bodyHeight = $("body").innerHeight();
213 | var fixWidth = offsetLeft+_selfWidth+width;
214 | var fixHeight = offsetTop+_selfHeight+height;
215 | var left = 0;
216 | var top = 0;
217 | var arrowLeft = 0;
218 | var arrowTop = 0;
219 |
220 | /*如果offsetLeft=0的情况下*/
221 | if(offsetLeft==0 || offsetLeft<_selfWidth){
222 | if(opts.arrow=='rightTop')opts.arrow = "leftTop";
223 | if(opts.arrow=='rightMiddle')opts.arrow = "leftMiddle";
224 | if(opts.arrow=='rightBottom')opts.arrow = "leftBottom";
225 | if(opts.arrow=='topRight')opts.arrow = "topLeft";
226 | if(opts.arrow=='topMiddle')opts.arrow = "topLeft";
227 | if(opts.arrow=='bottomMiddle')opts.arrow = "bottomLeft";
228 | if(opts.arrow=='bottomRight')opts.arrow = "bottomLeft";
229 | }
230 |
231 | if(offsetTop==0 || offsetTop < _selfHeight){
232 | opts.arrow = "topMiddle";
233 | }
234 |
235 | if(fixWidth > bodyWidth ){
236 | if(opts.arrow=='topLeft')opts.arrow = "topRight";
237 | if(opts.arrow=='topMiddle')opts.arrow = "topRight";
238 | if(opts.arrow=='bottomMiddle')opts.arrow = "bottomRight";
239 | if(opts.arrow=='bottomLeft')opts.arrow = "bottomRight";
240 | if(opts.arrow=='leftTop')opts.arrow = "rightTop";
241 | if(opts.arrow=='leftMiddle')opts.arrow = "rightMiddle";
242 | if(opts.arrow=='leftBottom')opts.arrow = "rightBottom";
243 | }
244 |
245 | if(fixHeight > bodyHeight){
246 | opts.arrow = "bottomMiddle";
247 | }
248 |
249 |
250 | if(opts.arrow=='topMiddle'){
251 | left = offsetLeft - _selfWidth/2+width/2 ;
252 | top = offsetTop+height+10;
253 | arrowLeft = offsetLeft+width/2-5 ;
254 | arrowTop = offsetTop +height-2;
255 | }
256 |
257 | if(opts.arrow=='topLeft'){
258 | left = offsetLeft + width/2;
259 | top = offsetTop+height+14;
260 | arrowLeft = offsetLeft+(width/2)+7;
261 | arrowTop = offsetTop +height+4;
262 | }
263 |
264 | if(opts.arrow=='topRight'){
265 | left = offsetLeft - _selfWidth+width/2;
266 | top = offsetTop+height+10;
267 | arrowLeft = offsetLeft+width/2-16;
268 | arrowTop = offsetTop +height ;
269 | }
270 |
271 | if(opts.arrow=='bottomLeft'){
272 | top = offsetTop-_selfHeight-13 ;
273 | left = offsetLeft +width/2;
274 | arrowLeft = offsetLeft+width/2+12 ;
275 | arrowTop = offsetTop-10;
276 | }
277 |
278 | if(opts.arrow=='bottomMiddle'){
279 | top = offsetTop-_selfHeight-16 ;
280 | left = offsetLeft - _selfWidth/2 +width/2 ;
281 | arrowLeft = offsetLeft+width/2-4 ;
282 | arrowTop = offsetTop-10;
283 | }
284 |
285 | if(opts.arrow=='bottomRight'){
286 | top = offsetTop-_selfHeight-13 ;
287 | left = offsetLeft -_selfWidth+width/2;
288 | arrowLeft = offsetLeft+width/2-18;
289 | arrowTop = offsetTop-10;
290 | }
291 |
292 | if(opts.arrow=='leftTop'){
293 | left = offsetLeft +width+14;
294 | top = offsetTop;
295 | arrowLeft = offsetLeft+width+2;
296 | arrowTop = offsetTop+12;
297 | }
298 | if(opts.arrow=='leftMiddle'){
299 | left = offsetLeft +width+12;
300 | top = offsetTop - _selfHeight/2+2;
301 | arrowLeft = offsetLeft+width-2;
302 | arrowTop = offsetTop;
303 | }
304 | if(opts.arrow=='leftBottom'){
305 | left = offsetLeft +width+12;
306 | top = offsetTop-_selfHeight+12;
307 | arrowLeft = offsetLeft+width;
308 | arrowTop = offsetTop-1;
309 | }
310 |
311 | if(opts.arrow=='rightTop'){
312 | left = offsetLeft -_selfWidth-16;
313 | top = offsetTop;
314 | arrowLeft = offsetLeft-12;
315 | arrowTop = offsetTop+14;
316 | }
317 | if(opts.arrow=='rightMiddle'){
318 | left = offsetLeft -_selfWidth-16;
319 | top = offsetTop - _selfHeight/2+2;
320 | arrowLeft = offsetLeft-12;
321 | arrowTop = offsetTop;
322 | }
323 | if(opts.arrow=='rightBottom'){
324 | left = offsetLeft -_selfWidth-16;
325 | top = offsetTop - _selfHeight;
326 | arrowLeft = offsetLeft-12;
327 | arrowTop = offsetTop-16;
328 | }
329 | if(!opts.hideArrow){
330 | $(".tooltip-nightly-arrow").addClass("tooltip-nightly-"+opts.arrow);
331 | }
332 | if(isEmpty(opts.arrow))opts.arrow = "bottomMiddle";
333 | var st = 2;
334 | opts.border = "2px solid #333";
335 | opts.background = opts.background||"#333";
336 | $(".tooltip-nightly-arrow").addClass("tooltip-nightly-"+opts.arrow+"-black");
337 | $(".tooltip-nightly-arrow").css({left:(arrowLeft+opts.offLeft),top:(arrowTop+opts.offTop)});
338 | $(".tm-window-tip").css({left:left+"px",top:(top+st),opacity:1,border:opts.border,background:opts.background,color:opts.fontColor});
339 | $('.tm-tips').click(function(){
340 | $(this).remove();
341 | });
342 | }
343 | };
344 |
345 | $.fn.tmTip.parseOptions = function($target) {
346 | return {
347 | width : $target.attr("width"),
348 | height : $target.attr("height"),
349 | tip : $target.attr("tip"),
350 | title:$target.attr("title"),
351 | event:$target.attr("event"),
352 | arrow:$target.attr("arrow"),
353 | offLeft:$target.attr("offLeft"),
354 | offTop:$target.attr("offTop"),
355 | background:$target.attr("background"),
356 | border:$target.attr("border"),
357 | color:$target.attr("color"),
358 | proxy:$target.attr("proxy")
359 | };
360 | };
361 | $.fn.tmTip.defaults ={
362 | width : 0,//宽度
363 | height : 0,//高度如果为0则为自动高度
364 | title:"",//如果tip为空用title
365 | event:"hover",//触发的事件类型
366 | arrow:"bottomMiddle",
367 | hideArrow:false,//是否隐藏方向箭头
368 | background:"",//设置背景
369 | border:"",
370 | proxy:"",
371 | tip : "",//内容
372 | contentAlign:"left",
373 | offLeft:0,//左部偏移
374 | offTop:0,//顶部移动
375 | color:"black"
376 | };
377 |
378 |
379 |
380 | /********************tab***************************/
381 | $.fn.tzTab = function(options){
382 | var opts = $.extend({},$.fn.tzTab.methods,$.fn.tzTab.defaults,options);
383 | this.each(function(){
384 | var optss = $.extend({},opts,$.fn.tzTab.parseOptions($(this)));
385 | opts.init($(this),optss);
386 | });
387 | };
388 |
389 | $.fn.tzTab.methods = {
390 | init : function($tab,opts){
391 | $tab.addClass("tzui-tabs");
392 | var $ul = $("
");
393 | var liHtml = "";
394 | var contentHtml = "";
395 | var jdata = opts.tabDatas;
396 | var length = jdata.length;
397 | var className = "tzui-state-default";
398 |
399 | if(opts.index==0 || opts.index>length)opts.index=0;//边界判断
400 | for(var i=0;i
"+jdata[i].title+"";
407 | contentHtml+=""+jdata[i].content+"
";
408 | className = "";
409 | }
410 | $ul.html(liHtml);
411 | $tab.append($ul);
412 | //面板内容
413 | $tab.append(contentHtml);
414 | if(opts.width)$tab.width(opts.width);
415 | if(opts.height)$tab.height(opts.height);
416 | if(opts.background){
417 | $tab.css("border","2px solid "+opts.background);
418 | $ul.css({"background":opts.background});
419 | $ul.find("li>a").filter(function(){
420 | if(!$(this).parent().hasClass("tzui-state-active")){
421 | $(this).css({"background":opts.background,"color":"#fff"});
422 | }
423 | });
424 | }
425 |
426 | if(opts.linear && opts.border){
427 | $tab.css("border","2px solid "+opts.border);
428 | $ul.css({"background":"linear-gradient("+opts.linear+")"});
429 | $ul.find("li>a").filter(function(){
430 | if(!$(this).parent().hasClass("tzui-state-active")){
431 | $(this).css({"background":"linear-gradient("+opts.linear+")","color":"#fff"});
432 | }
433 | });
434 | }
435 |
436 | $tab.find(".tzui-tabs-nav > li").on(opts.event,function(){
437 | var markFlag = $(this).hasClass("tzui-tabs-active");
438 | if(markFlag)return;
439 | var tab = $(this).attr("tab");
440 | $(this).addClass("tzui-tabs-active tzui-state-active").siblings().removeClass("tzui-tabs-active tzui-state-active");
441 | $tab.find(".tzui-tabs-panel").hide();
442 | var $content = $tab.find("#"+tab);
443 | $content.show();
444 | $(this).find("a").removeAttr("style");
445 | if(opts.linear && opts.border){
446 | $(this).siblings().find("a").css({"background":"linear-gradient("+opts.linear+")","color":"#fff"});
447 | }else{
448 | $(this).siblings().find("a").css({"background":opts.background,"color":"#fff"});
449 | }
450 | if(opts.callback)opts.callback($(this),$content);
451 | //当前元素解绑事件
452 | });
453 |
454 |
455 | }
456 | };
457 |
458 | $.fn.tzTab.parseOptions = function($target){
459 | var datas = $target.find(".data").text();
460 | var json = {
461 | width:$target.data("width"),//选项卡的宽度
462 | height:$target.data("height"),//选项卡的高度
463 | event:$target.data("event"),//选项卡的事件类型
464 | background:$target.data("background"),
465 | linear:$target.data("linear"),
466 | border:$target.data("border"),
467 | index:$target.data("index")//默认选择哪一个
468 | };
469 | if(datas)json["tabDatas"]=eval("("+datas+")");
470 | return json;
471 | };
472 |
473 | $.fn.tzTab.defaults = {
474 | width:600,//选项卡的宽度
475 | height:300,//选项卡的高度
476 | event:"click",//选项卡的事件类型
477 | background:"#4684b2",
478 | linear:"",
479 | border:"",
480 | index:2,//默认选择哪一个
481 | callback:function($current,$content){
482 |
483 | },
484 | tabDatas:[
485 | {title:"选项卡1",content:"士大夫收到111","url":"user.action"},
486 | {title:"选项卡2",content:"士大夫收到22222","url":"delete.action"},
487 | {title:"选项卡3",content:"选项卡3333"}
488 | ]
489 | };
490 |
491 |
492 | /**********************drag***********************/
493 | $.fn.tzDrag = function(options){
494 | var opts = $.extend({},$.fn.tzDrag.methods,$.fn.tzDrag.defaults,options);
495 | this.each(function(){
496 | var optss = $.extend({},opts,$.fn.tzDrag.parseOptions($(this)));
497 | opts.init($(this),optss);
498 | });
499 | };
500 |
501 | $.fn.tzDrag.methods = {
502 | init:function($dialog,opts){//层拖动
503 | var thisObj = this;
504 | var mark = false;
505 | // $dialog.css("position","absolute");
506 | var $dialogClone = null;
507 | $dialog.on("mousedown",opts.handler,function(e){
508 | //镜像
509 | tzUtil.forbiddenSelect();
510 | if(opts.ghost)$dialogClone= thisObj.ghsot($dialog,opts);
511 | var $this = $(this).parent();
512 |
513 | if(!opts.handler){
514 | $this=$(this);
515 | }
516 |
517 | var x = e.clientX;
518 | var y = e.clientY;
519 | var left = $this.offset().left;
520 | var top = $this.offset().top;
521 | var w = $this.width();
522 | var h = $this.height();
523 | var offsetHeight = $this.parent().height() - h-2;
524 | //var offsetHeight = $(document).height() - h-2;
525 | var offsetWidth= $this.parent(). width() - w-2;
526 | var stop= $(window).scrollTop();
527 | var jsonData = {};
528 | jsonData.width=w;
529 | jsonData.height=h;
530 | mark = true;
531 | $(document).on("mousemove",function(e){
532 | if(mark){
533 | var nx = e.clientX;
534 | var ny = e.clientY;
535 | var nl = nx + left - x;
536 | var nt = ny + top - y - stop;
537 | if(nl<=0)nl=1;
538 | if(nt<=0)nt=1;
539 | if(nl>=offsetWidth)nl = offsetWidth;
540 | if(nt>=offsetHeight)nt = offsetHeight;
541 | jsonData.left = nl;
542 | jsonData.top = nt;
543 | if(opts.ghost){
544 | $dialogClone.css({left:nl,top:nt});
545 | }else{
546 | $this.css({left:nl,top:nt});
547 | }
548 | if(opts.move)opts.move(jsonData,$this);
549 | }
550 |
551 | }).on("mouseup",function(){
552 | if(opts.ghost){
553 | $dialogClone.remove();
554 | $this.css({left:jsonData.left,top:jsonData.top});
555 | }
556 | tzUtil.autoSelect();
557 | if(opts.up)opts.up($this);
558 | mark = false;
559 | });
560 | });
561 | },
562 | ghsot:function($dialog,opts){
563 | var $dialogClone = $dialog.clone();
564 | $dialogClone.css({"background":"#f9f9f9","opacity":0.5,"border":"1px dotted #ccc"}).find(".tzui-empty").empty();
565 | $("body").append($dialogClone);
566 | return $dialogClone;
567 | }
568 |
569 |
570 | };
571 |
572 | $.fn.tzDrag.parseOptions = function($dialog){
573 | return {
574 | handler:$dialog.data("handler"),
575 | ghost:$dialog.data("ghost")
576 | };
577 | };
578 |
579 | $.fn.tzDrag.defaults = {
580 | handler:"",//拖动代理
581 | ghost:true,//是否产生镜像
582 | move:function(opts){
583 | },
584 | up:function(opts){
585 | }
586 |
587 | };
588 |
589 |
590 | var imgboxTimer = null;
591 |
592 | /*图集插件*/
593 | $.fn.tzImgbox = function(options){
594 | return this.each(function(){
595 | var opts = null;
596 | var cache = $(this).data("tzImgbox");
597 | if(cache){
598 | opts = $.extend(cache.options,options);
599 | cache.options = opts;
600 | }else{
601 | var opts = $.extend({},$.fn.tzImgbox.defaults,$.fn.tzImgbox.parseOptions($(this)),options);
602 | $(this).data("tzImgbox",{options:opts});
603 | initImgbox($(this));
604 | }
605 | var src = $(this).attr("src");
606 | if(isEmpty(src))src = $(this).attr("_src");
607 | if(opts.suffix)src = src.replace(opts.suffix,"");
608 | opts.imgArrs.push(src);
609 | });
610 | };
611 |
612 | function initImgbox($this){
613 | var opts = $this.data("tzImgbox").options;
614 | $this.on(opts.eventType,function(e){
615 | stopBubble(e);
616 | var title = $(this).attr("title");
617 | if(isEmpty(title))title="";
618 | $("body").append(''+
619 | '
'+
620 | '
'+
621 | '
'+
622 | '
'+
623 | '
'+
624 | '
'+
625 | '
'+
626 | '
'+
627 | '
'+
628 | '
'+
629 | '
!['+title+']()
'+
630 | '
'+
631 | '
' +
632 | '
'+
633 | '
'+
634 | '
'+
635 | '
'+
636 | '
');
637 | $("#tm-box-imgs").css({height:0,width:0});
638 | var src = $(this).attr("src");
639 | if(isEmpty(src))src = $(this).attr("_src");
640 | if(isNotEmpty(opts.suffix))src=src.replace(opts.suffix,"");
641 | tzImgboxLoading(src,opts);
642 | $("#tm-box-wrap").width(opts.width);
643 | $("#tm-box-content").width(opts.width-20).height(opts.height);
644 | var vheight = $(window).height();
645 | if(document.body.scrollHeight>$(window).height()){
646 | vheight = document.body.scrollHeight;
647 | }
648 | $(".tm-ui-overdisplay").height(vheight);
649 | //if(opts.drag)$.fn.Tmui.methods._moveAll($("#tm-box-wrap"),".tm-box-bg");
650 | //if(opts.drag)$("#tm-box-wrap").tmDrag({handle:$(".tm-box-bg")});
651 | $(".tm-ui-overdisplay").click(function(){
652 | $("#tm-box-loading").remove();
653 | $(".tm-ui-overdisplay").fadeOut("fast",function(){
654 | $(this).remove();
655 | });
656 | $("#tm-box-wrap").remove();
657 | clearInterval(imgboxTimer);
658 | });
659 |
660 | $.fn.tzImgbox.methods.resizeImgbox($this);
661 | if(isNotEmpty(opts.top)){
662 | $("#tm-box-wrap").css("top",opts.top);
663 | }
664 |
665 | /*翻页控制*/
666 | var index = $.tmArray.indexOf(opts.imgArrs,$(this).attr("src"));
667 | var imgArr = opts.imgArrs;
668 | $("#tm-box-left").click(function(){
669 | clearInterval(imgboxTimer);
670 | if(index==0)index = imgArr.length;
671 | index--;
672 | tzImgboxLoading(imgArr[index],opts);
673 | });
674 |
675 | $("#tm-box-right").click(function(){
676 | clearInterval(imgboxTimer);
677 | index++;
678 | if(index== imgArr.length)index = 0;
679 | tzImgboxLoading(imgArr[index],opts);
680 | });
681 |
682 | $("#tm-auto-play").click(function(){
683 | var text = $(this).text();
684 | if(text=='自动播放')$(this).text("暂停播放");
685 | if(text=='暂停播放'){
686 | clearInterval(imgboxTimer);
687 | $(this).text("自动播放");
688 | return;
689 | }
690 | /*定时轮播*/
691 | imgboxTimer = setInterval(function(){
692 | index++;
693 | if(index == imgArr.length)index = 0;
694 | tzImgboxLoading(imgArr[index],opts);
695 | },opts.time*1000);
696 | });
697 | /*翻页控制*/
698 | });
699 | };
700 |
701 | function tzImgboxLoading(src,opts){
702 | var img = new Image();
703 | img.src = src;
704 | if(img.complete){
705 | tzImgboxLoadingProxy(img,opts);
706 | }else{
707 | img.onreadystatechange = function () {
708 | }
709 | img.onload = function () {
710 | tzImgboxLoadingProxy(img,opts);
711 | }
712 | img.onerror = function () {
713 | tmLoading("图片加载失败或没有找到...",1);
714 | }
715 | }
716 | };
717 |
718 | function tzImgboxLoadingProxy(img,opts){
719 | $("#tm-box-loading").remove();
720 | var top = (getClientHeight() - opts.height) / 2
721 | $("#tm-box-wrap").append('');
722 | var title = $("img[src='"+img.src+"']").attr("title")
723 | if(isEmpty(title)){
724 | title = $("*[_src='"+img.src+"']").attr("title");
725 | }
726 | $("#tm-box-loading").fadeIn(200,function(){
727 | $(this).hide();
728 | $("#tm-box-imgs").attr("src",img.src);
729 | $("#tm-box-tit").html(title);
730 | var width = img.width;
731 | var height = img.height;
732 | var bodyWidth = opts.width;
733 | var bodyHeight = opts.height;
734 | var box = $.fn.tzImgbox.methods.resizeImg(img,opts.bitWidth,opts.bitHeight);
735 | $("#tm-box-imgs").width(box.width).height(box.height);
736 | var width = $("#tm-box-imgs").width();
737 | var height = $("#tm-box-imgs").height();
738 | var left = (bodyWidth - width)/2-10;
739 | var top = (bodyHeight - height)/2 ;
740 | $("#tm-box-imgs").css({left:left,top:top});
741 | });
742 | }
743 |
744 | $.fn.tzImgbox.parseOptions = function($target) {
745 | return {
746 |
747 | }
748 | };
749 |
750 | $.fn.tzImgbox.methods = {
751 | loadImg : function(src,$img){
752 | var o= new Image();
753 | o.src = src;
754 | if(o.complete){
755 | $("#tm-box-loading").remove();
756 | $img.attr("src",src);
757 | $img.show();
758 | }else{
759 | o.onload = function(){
760 | $("#tm-box-loading").remove();
761 | $img.attr("src",src);
762 | $img.show();
763 | };
764 | o.onerror = function(){
765 | tmLoading("图片加载失败或者图片没有找到",1);
766 | };
767 | }
768 | },
769 |
770 | resizeImg:function (img,iwidth,iheight){
771 | var image= img;
772 | var boxWH = {};
773 | if(image.width>0 && image.height>0){
774 | boxWH.width=image.width;
775 | boxWH.height=image.height;
776 | if(boxWH.width>iwidth){
777 | boxWH.height = (boxWH.height*iwidth)/boxWH.width;
778 | boxWH.width = iwidth;
779 |
780 | }
781 | if(boxWH.height>iheight){
782 | boxWH.width = (boxWH.width*iheight)/boxWH.height;;
783 | boxWH.height = iheight;
784 | }
785 | }
786 | return boxWH;
787 | } ,
788 |
789 | resizeImgbox:function($this){
790 | var bodyWidth = getClientWidth();
791 | //var bodyHeight = getClientHeight();
792 | var bodyHeight = $(window).height();
793 | var offset =$this.offset();
794 | var width = $("#tm-box-wrap").width();
795 | var height = $("#tm-box-wrap").height();
796 | var left = (bodyWidth - width)/2-15;
797 | var top = (bodyHeight - height)/2 - 30;
798 | $("#tm-box-wrap").css({left:left,top:top});
799 | $("#tm-box-wrap").find("#tm-box-close").click(function(){
800 | $(".tm-ui-overdisplay").fadeOut("fast",function(){
801 | $(this).remove();
802 | });
803 | $("#tm-box-wrap").remove();
804 | clearInterval(imgboxTimer);
805 | });
806 | }
807 | }
808 |
809 | $.fn.tzImgbox.defaults ={
810 | imgArrs:[],
811 | drag:true,
812 | width:960,
813 | height:420,
814 | bitWidth : 960,
815 | bitHeight: 550,
816 | eventType:"dblclick",
817 | suffix:"",//在实际开发的过程中,可能需要展示的是小图,而预览的时候看到的是大图片,比如:/images/aaa_small.jpg如果你填写了:"_small"--那么最终呈现的是/images/aaa.jpg
818 | time:2
819 | }
820 | /***********tzImgbox end**********/
821 |
822 | })(jQuery);
823 |
824 |
825 |
826 |
827 | //jquery插件的定义方式
828 | var tzLoading = function(message,options){
829 | var opts = $.extend({},options);
830 | this.init(message,opts.timeout,opts);
831 | };
832 |
833 | tzLoading.prototype = {
834 | init : function(message,timeout,opts){
835 | var $loading = this.template(message,opts);
836 | if($loading){
837 | //定位
838 | tzUtil._position($loading).resize($loading);
839 | //事件绑定
840 | this.events($loading);
841 | //时间关闭
842 | this.timeout($loading,timeout);
843 | }
844 | },
845 |
846 | template:function(content,opts){
847 | var $loading = $("#tzloading");
848 | if(content=="remove"){
849 | tzUtil.animates($loading,"slideUp");
850 | return;
851 | }
852 | if($loading.length==0){
853 | if(content=="remove"){
854 | tzUtil.animates($loading,"slideUp");
855 | return;
856 | }
857 | $loading = $("");
858 | var $loadingGif = $("");
859 | var $loadingContent = $("");
860 | $loadingContent.html(content);
861 | $loading.append($loadingGif).append($loadingContent);
862 | $("body").append($loading);
863 | if(opts.overlay){
864 | $("body").append("");
865 | $loading.next().click(function(){
866 | $(this).remove();
867 | $loading.trigger("click");
868 | });
869 | }
870 | }else{
871 | $loading.find(".tzui-loading-cnt").html(content);
872 | }
873 |
874 | if(opts.height)$loading.height(opts.height);
875 | return $loading;
876 | },
877 |
878 | events :function($loading){
879 | $loading.click(function(){
880 | tzUtil.animates($(this),"slideUp");
881 | });
882 | },
883 |
884 | timeout:function($loading,timeout){
885 | var timr = null;
886 | if(isNotEmpty(timeout+"") && timeout >0){
887 | clearTimeout(timr);
888 | timr = setTimeout(function(){
889 | //事件的触发
890 | $loading.trigger("click");
891 | },timeout*500);
892 | }
893 | }
894 | };
895 |
896 | var loading = function(message,timeout,overlay){
897 | new tzLoading(message,{"timeout":timeout,overlay:overlay});
898 | };
899 |
900 | /*******************dialog**********************************/
901 | //dialog的弹出层
902 | $.tzConfirm = function(options){
903 | var opts = $.extend({},$.tzDialog.methods,$.tzDialog.defaults,options);
904 | opts.icon = "warn";
905 | opts.init(opts);
906 | };
907 |
908 | $.tzPrompt = function(options){
909 | var opts = $.extend({},$.tzDialog.methods,$.tzDialog.defaults,options);
910 | var $dialog = opts.init(opts);
911 | var mw= opts.width - 68;
912 | $dialog.find(".tzdialog_message").html(" "+opts.content+":
" +
913 | "
");
914 | //这个确定按钮事件
915 | $dialog.find(".tzdialog_ok").off("click").on("click",function(){
916 | var $input = $dialog.find(".tzdialog_message").find("input");
917 | var value = $input.val().trim();
918 | if(value==""){
919 | loading("请输入内容!",2);
920 | $input.focus();
921 | return;
922 | }
923 | if(opts.validator($input)){
924 | if(opts.callback)opts.callback(value);//回调方法
925 | $dialog.next().remove();
926 | tzUtil.animates($dialog,opts.animate);
927 | }
928 | });
929 | };
930 |
931 | $.tzAlert = function(options){
932 | var opts = $.extend({},$.tzDialog.methods,$.tzDialog.defaults,options);
933 | opts.icon = "tip";
934 | opts.init(opts);
935 | //var $dialog = opts.init(opts);
936 | // $dialog.find(".tzdialog_cancel").remove();
937 | };
938 |
939 | $.tzDialog = {};
940 |
941 | $.tzDialog.methods = {
942 | //初始化
943 | init:function(opts){
944 | var $dialog = this.template(opts);
945 | //弹出层事件初始化
946 | this.events($dialog,opts);
947 | this.params($dialog,opts);
948 | var btns = opts.buttons;
949 | for(var key in btns){
950 | $dialog.append(""+key+" ");
951 | }
952 | $dialog.find("a.btns").click(function(){
953 | var text = $(this).text();
954 | btns[text].call($dialog);
955 | });
956 |
957 | return $dialog;
958 | },
959 | params:function($dialog,opts){
960 | if(opts.width)$dialog.width(opts.width);
961 | if(opts.height){
962 | if(opts.height<=160)opts.height=160;
963 | $dialog.height(opts.height);
964 | }
965 | $dialog.find(".tzdialog_message").css({"textAlign":"center","lineHeight":opts.height-145+"px"}).height(opts.height-145);
966 | //弹出层居中
967 | tzUtil._position($dialog);
968 | //拖动事件的绑定
969 | if(opts.drag)$dialog.tzDrag({handler:".tzdialog_title","ghost":opts.ghost});
970 | },
971 |
972 | //弹出层的模板
973 | template : function(opts){
974 | var $dialog = $(""+
975 | "
"+opts.title+"
" +
976 | "
x"+
977 | "
"+
986 | "
");
987 | $("body").append($dialog).append("");
988 | return $dialog;
989 | },
990 | events:function($dialog,opts){
991 | //这个确定按钮事件
992 | $dialog.find(".tzdialog_ok").on("click",function(){
993 | if(opts.callback)opts.callback(true);//回调方法
994 | $dialog.next().remove();
995 | tzUtil.animates($dialog,opts.animate);
996 | });
997 |
998 | //关闭按钮事件
999 | $dialog.find(".tzdialog_cancel,.delete").on("click",function(){
1000 | if(opts.callback)opts.callback(false);//回调方法
1001 | $dialog.next().remove();
1002 | tzUtil.animates($dialog,opts.animate);
1003 | });
1004 |
1005 | //响应事件
1006 | var timer = null;
1007 | $(window).resize(function(){
1008 | clearTimeout(timer);
1009 | timer = setTimeout(function(){tzUtil._position($dialog);},30);
1010 | });
1011 | }
1012 | };
1013 |
1014 | //弹出层的默认参数
1015 | $.tzDialog.defaults = {
1016 | width:272,
1017 | handle:".tzdiaog_title",
1018 | height:166,
1019 | title:"标题",
1020 | icon:"success",
1021 | drag:true,
1022 | ghost:true,
1023 | value:"",
1024 | animate:"top",
1025 | cancelText:"取消",
1026 | sureText:"确定",
1027 | validator:function($input){
1028 | return true;
1029 | },
1030 | callback:function(ok){
1031 | },
1032 | content:"请输入内容..."
1033 | };
1034 |
1035 | var ajaxTimeout = null;
1036 | $.tzAjax = {
1037 | request : function(options,dataJson){
1038 | var opts = $.extend({},{limit:true,before:function(){
1039 | },error:function(){
1040 |
1041 | },callback:function(data){
1042 |
1043 | }},options);
1044 | var _url = opts.url;
1045 | if(isEmpty(_url)){
1046 | _url = basePath+"/"+opts.model+"/"+opts.method;
1047 | }
1048 | if(isNotEmpty(opts.params)){
1049 | _url+="&"+opts.params;
1050 | }
1051 |
1052 | if(opts.limit){
1053 | clearTimeout(ajaxTimeout);
1054 | ajaxTimeout = setTimeout(function(){
1055 | $.tzAjax.ajaxMain(opts,_url,dataJson);
1056 | },200);
1057 | }else{
1058 | $.tzAjax.ajaxMain(opts,_url,dataJson);
1059 | }
1060 | },
1061 | ajaxMain:function(opts,_url,dataJson){
1062 | $.ajax({
1063 | type:"post",
1064 | data : dataJson,
1065 | url : _url,
1066 | beforeSend:function(){opts.before();},
1067 | error:function(){loading("抱歉!因为操作不能够及时响应,请稍后在试...",1);opts.error();clearTimeout(ajaxTimeout);},
1068 | success:function(data){
1069 | if(data.result=="logout"){
1070 | loading("session超时,请登录...");
1071 | }else{
1072 | if(opts.callback)opts.callback(data);
1073 | }
1074 | clearTimeout(ajaxTimeout);
1075 | }
1076 | });
1077 | }
1078 | };
--------------------------------------------------------------------------------