-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.rbcode.min.js
More file actions
3 lines (2 loc) · 5.77 KB
/
jquery.rbcode.min.js
File metadata and controls
3 lines (2 loc) · 5.77 KB
1
2
/* rbCode v1.1.0 - Jquery plugin - Quang K. Cao runbusi.com MIT license*/
(function(a){a.fn.rbCode=function(d){var f={is_number:true,is_zebra:true,zebra_bg:"#CCC",zebra_cross_bg:"#FFF",modal_bg:"#000",bg:"#CCC",text_color:"#000",list_color:"#333",z_index:999,opacity:0.75,a_number:["Hide Number","Show Number","text"],a_zebra:["Hide Zebra","Show Zebra","text"],a_popout:["PopOut","Close","text"]};var o="</span></li><li><span>";var p="";var k="";var b;var c,j;var w=a(document);var e=a(window);var s;var m,t;if(a("#popout_modal").length==0){s=document.createElement("div");s.id="popout_modal";document.body.appendChild(s)}var r=a("#popout_modal");r.css({top:"0",left:"0",width:"100%",height:"100%",background:f.modal_bg,position:"fixed","z-index":f.z_index-1,opacity:f.opacity,display:"none"});return this.each(function(){if(d){a.extend(f,d)}a(this).css({background:f.bg,color:f.text_color,padding:"5px","-webkit-border-radius":"5px","-moz-border-radius":"5px","border-radius":"5px"});m=f.is_zebra;t=f.is_number;p='<a class="toggleZebra" title="" href="">';switch(f.a_zebra[2]){case"text":p+=f.a_zebra[(f.is_zebra)?0:1];break;case"image":p+='<img alt="" src="'+f.a_zebra[(f.is_zebra)?0:1]+'"/>';break;default:p+=f.a_zebra[(f.is_zebra)?0:1]}p+="</a> ";p+='<a class="toggleNumber" title="" href="">';switch(f.a_number[2]){case"text":p+=f.a_number[(f.is_number)?0:1];break;case"image":p+='<img alt="" src="'+f.a_number[(f.is_number)?0:1]+'"/>';break;default:p+=f.a_number[(f.is_number)?0:1];break}p+="</a> ";p+='<a class="togglePopout" title="" href="">';switch(f.a_popout[2]){case"text":p+=f.a_popout[0];break;case"image":p+='<img alt="" src="'+f.a_popout[0]+'"/>';break;default:p+=f.a_popout[0];break}p+="</a> ";k='<div class="toolbar" style="text-align:right;">'+p+"</a> </div>";zebra=a(".toggleZebra",a(this));number=a(".toggleNumber",a(this));popout=a(".togglePopout",a(this));p=a(this).html();p=p.replace(/\t/g," ");if(p.substr(0,3)=="<p>"){p=p.substr(3,p.length)}p=p.replace(/<p>/g,"\n");p=p.replace(/<\/p>/g,"");p=p.replace(/\n/g,"<br/>");if(p.substr(p.length-5,5)=="<br/>"){p=p.substr(0,p.length-5)}p=p.replace(/<BR>/g,"<br/>");p=p.replace(/<BR\/>/g,"<br/>");p=p.replace(/<br>/g,o);p=p.replace(/<br\/>/g,o);s=document.createElement("div");s.className="precode";s.innerHTML="<ol><li><span>"+p+"</span></li></ol>";a(this).html(s);c=a(".precode",a(this));j=a(".precode ol",a(this));c.css("overflow","auto");j.css({"list-style":(f.is_number)?"decimal inside":"none",color:f.list_color,margin:0,padding:0});if(f.is_zebra){u(j,c);var x=0;a("ol li",a(this)).each(function(){if(x%2==1){a(this).css("background",f.zebra_bg)}else{a(this).css("background",f.zebra_cross_bg)}x++})}a("ol li span",a(this)).css("color",f.text_color);a("ol li span",a(this)).each(function(){if(a(this).html()==""){a(this).html(" ")}});a(this).prepend(k);a(this).on("mouseenter",g);a(this).on("mouseleave",v);a(this).on("keyup",function(y){if(y.keyCode==27){h()}});e.on("resize",function(){u(j,c);i()})});function g(x){a(this).on("click",".toggleZebra",q);a(this).on("click",".toggleNumber",n);a(this).on("click",".togglePopout",l)}function v(x){a(this).off("click",".toggleZebra",q);a(this).off("click",".toggleNumber",n);a(this).off("click",".togglePopout",l)}function q(z){c=a(".precode",a(this).parent().parent());j=a(".precode ol",a(this).parent().parent());var y=0;var x=a("ol li",a(this).parent().parent());if(m!=f.is_zebra){x.each(function(){if(y%2==1){a(this).css("background",f.zebra_bg)}else{a(this).css("background",f.zebra_cross_bg)}y++})}else{x.each(function(){a(this).css("background","none")})}m=!m;switch(f.a_zebra[2]){case"text":a(this).html(f.a_zebra[(m)?0:1]);break;case"image":a("img",a(this)).attr("src",f.a_zebra[(m)?0:1]);break;default:a(this).html(f.a_zebra[(m)?0:1])}return false}function n(x){j=a(".precode ol",a(this).parent().parent());if(t!=f.is_number){j.css("list-style","decimal inside")}else{j.css("list-style","none")}t=!t;switch(f.a_number[2]){case"text":a(this).html(f.a_number[(t)?0:1]);break;case"image":a("img",a(this)).attr("src",f.a_number[(t)?0:1]);break;default:a(this).html(f.a_number[(t)?0:1])}return false}function l(A){r.css({background:f.modal_bg,"z-index":f.z_index-1,opacity:f.opacity});var B=a(this).parent().parent();c=a(".precode",B);j=a(".precode ol",B);u(j,c);var z=a(".toolbar",B);if(B.css("z-index")!=999){b=B.css("z-index")}if(B.hasClass("popout")){h()}else{r.show();B.addClass("popout");B.css({top:0,left:0,position:"fixed"});var x=B.height();var y=B.width();c.css({width:(y>=e.width())?(e.width()-z.height()):(y+2*z.height())+"px",height:(x>=e.height())?(e.height()-2*z.height()):x+"px"});u(j,c);B.css({top:(x<=e.height())?((e.height()-x)/2-z.height()):0+"px",left:(y<=e.width())?((e.width()-y)/2-z.height()):0+"px",width:(y>e.width())?e.width():(y+2*z.height())+"px",height:(x>e.height())?e.height():(x+z.height())+"px","z-index":f.z_index});switch(f.a_popout[2]){case"text":a(this).html(f.a_popout[1]);break;case"image":a("img",a(this)).attr("src",f.a_popout[1]);break;default:a(this).html(f.a_popout[1])}}return false}function u(x,y){x.css("position","fixed");var z=x.width();x.css("position","relative");x.css("position","static");x.width((z>=y.width())?z:"auto")}function i(){var x=(e.height()-a(".popout").height())/2;var y=(e.width()-a(".popout").width())/2;a(".popout").css({top:x+"px",left:y+"px"})}function h(){if(a(".popout").length){var x=a(".popout");c=a(".precode",x);j=a(".precode ol",x);u(j,c);if(x.css("z-index")!=999){b=x.css("z-index")}r.hide();x.css({top:"auto",left:"auto",width:"auto",height:"auto",position:"relative","z-index":b});x.css("position","static");c.css({width:"auto",height:"auto"});u(j,c);switch(f.a_popout[2]){case"text":a(".togglePopout",x).html(f.a_popout[0]);break;case"image":a("img",a(".togglePopout",x)).attr("src",f.a_popout[0]);break;default:a(".togglePopout",x).html(f.a_popout[0])}x.removeClass("popout")}}}})(jQuery);