draw.js 3.3 KB

1
  1. $(function(){var timeId=null,enabled=false,selectElement=null,currentElement=null;var elt=$("<div style='background-color:#fff;display:none;margin-bottom:8px;' id='zwfpos'></div>");$.fn.bindDraw=function(opt){$(this).mousedown(function(e){if($("#kskm_titleinput").attr("disabled")){return}var obj=$(this).parents(opt.drawSelect).first()[0];currentElement=obj;currentElement.selector=opt.drawSelect;if($("#pup_upbox").is(":visible")){return}enabled=true;$(obj).after(elt);elt.show().css({height:$(obj).height(),width:$(obj).width()});$(obj).css({position:"absolute",opacity:.5,width:$(obj).width(),zIndex:99,marginLeft:0,left:$(obj).offset().left,top:$(obj).offset().top}).attr("initLeft",$(obj).offset().left);var element=$(e.srcElement||e.target);element.parent().parent().addClass("input_blue");var p=$(obj).offset();obj.pos={left:e.clientX-p.left,top:e.clientY-p.top+$(window).scrollTop()};$(obj).find("[contenteditable]").blur();$("body").append(obj);if(e.cancelBubble){e.cancelBubble=true}else{e.stopPropagation()}return false}).parent().parent().mouseup(function(e){if(!enabled){return}enabled=false;if($("#zwfpos").is(":visible")){elt.after(currentElement);$("body").append(elt.hide());$(currentElement).css({position:"",opacity:"",marginLeft:"",width:"",top:"",left:""});currentElement.style.zoom="";if(window.IS_MOVE){window.moveData&&window.moveData(currentElement);window.IS_MOVE=false}}$(".input_blue").removeClass("input_blue").find("input").css("-webkit-user-select","")})};$(document).mousemove(function(e){if(enabled){var winTop=$(window).scrollTop();$(currentElement).css({left:e.clientX-currentElement.pos.left,top:e.clientY-currentElement.pos.top+winTop});var top=e.clientY-currentElement.pos.top+winTop;elt.siblings(currentElement.selector).each(function(i,n){var meTop=$(this).offset().top;if(meTop>top+20&&i==0){$(this).before(elt);window.IS_MOVE=true;return false}if(top<meTop&&top>meTop-$(this).height()/2){$(this).after(elt);window.IS_MOVE=true;return false}});return false}})});function animate(slt,attr,start,end,speed,callback,isOpacity){var bro=$.browser;if(bro.mozilla){attr="-moz-"+attr}else if(bro.safari){attr="-webkit-"+attr}else if(bro.msie&&navigator.appVersion.indexOf("MSIE 9.0")>=0){attr="-ms-"+attr}else{if(typeof callback=="function"){callback()}return}var time=15;speed=speed+speed%time;var startNum=parseFloat(start.substring(start.indexOf("(")+1,start.indexOf(")")));var endNum=parseFloat(end.substring(end.indexOf("(")+1,end.indexOf(")")));var step=(endNum-startNum)/speed*time;var i=0;var deg="";var tmpArrs=start.replace(/\([\d\.]+\)/,"(-)").split("-");if(start.indexOf("deg")>0){deg="deg";tmpArrs=start.replace(/\([\d\.]+deg\)/,"(-)").split("-")}var p={start:start,startNum:startNum,endNum:endNum,step:step,i:i,time:time,attr:attr,speed:speed,clearId:null,tmpArrs:tmpArrs,startNum2:startNum};if(!isOpacity){if(p.endNum>=p.startNum){slt.css("opacity","0").fadeTo(speed,1)}else{slt.fadeTo(speed,0)}}var loop=function(p){if(p.i*p.time>p.speed){if(typeof callback=="function"){callback()}return}else{var nowPosition=p.startNum2+p.step;p.startNum2=nowPosition;if(p.endNum>=p.startNum){if(nowPosition>p.endNum){nowPosition=p.endNum}}else{if(nowPosition<p.endNum){nowPosition=p.endNum}}nowPosition+=deg;var value=p.tmpArrs[0]+nowPosition+p.tmpArrs[1];slt.css(p.attr,value);p.clearId=setTimeout(function(){loop(p)},p.time)}p.i++};clearTimeout(p.clearId);loop(p)}