⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 editorcontent.js

📁 现在的这个版本除了对代码进了相当多的优化以外
💻 JS
📖 第 1 页 / 共 2 页
字号:
            if(content.width != null && content.height != null) {
                content.width = 0;
                content.height = 0;
            }
            //alert(content.width+":"+content.height);
        }
        resizeHandle = firedobj.id;
        
        /*if(status!=null) {
            status.innerHTML  = " obj:"+firedobj.id;
        }*/

        x=ns6? e.clientX: event.clientX
        y=ns6? e.clientY: event.clientY

        oa_w = parseInt(ant.style.width);
        oa_h = parseInt(ant.style.height);
        oa_x = parseInt(ant.style.left);
        oa_y = parseInt(ant.style.top);

        dragapproved=true
        document.onmousemove=moveHandle;
        return false;
    }
    else
    if((firedobj.className == "selection" || firedobj.className=="selectionWhite")&& mode == "crop") {
        
        x=ns6? e.clientX: event.clientX
        y=ns6? e.clientY: event.clientY
        
        oa_x = parseInt(ant.style.left);
        oa_y = parseInt(ant.style.top);

        dragapproved=true
        document.onmousemove=moveContent;
        return false;
    }
    else
    if (firedobj.className=="crop" && mode == "crop")
    {
        if(content != null) {
            if(content.width != null && content.height != null) {
                content.width = 0;
                content.height = 0;
            }
            //alert(content.width+":"+content.height);
        }

        if (status == null)
            status = MM_findObj("status");

        if (ant == null)
            ant = MM_findObj("ant");

        if (canvas == null)
            canvas = MM_findObj("imgCanvas");
        if(content == null) {
            content = MM_findObj("cropContent");
        }

        if (pic_width == null || pic_height == null)
        {
            image = MM_findObj("theImage");
            pic_width = image.width;
            pic_height = image.height;
        }

        ant.style.visibility = "visible";

        obj = firedobj;
        dragapproved=true
        z=firedobj
        temp1=parseInt(z.style.left+0)
        temp2=parseInt(z.style.top+0)
        x=ns6? e.clientX: event.clientX
        y=ns6? e.clientY: event.clientY
        document.onmousemove=move
        return false
    }
        else if(firedobj.className=="crop" && mode == "measure") {

            if (ant == null)
                ant = MM_findObj("ant");

            if (canvas == null)
                canvas = MM_findObj("imgCanvas");

            x=ns6? e.clientX: event.clientX
            y=ns6? e.clientY: event.clientY

                //jg_doc.draw
            dragapproved=true
            document.onmousemove=measure

            return false
        }
}

function measure(e) 
{
    if (dragapproved)
    {
        mx2 = ns6? e.clientX : event.clientX;
        my2 = ns6? e.clientY : event.clientY;
        
        jg_doc.clear();
        jg_doc.setStroke(Stroke.DOTTED); 
        jg_doc.drawLine(x,y,mx2,my2);
        jg_doc.paint();
        showStatus();
        return false;
    }
}

function setMarker(nx,ny,nw,nh) 
{
    if (ant == null)
        ant = MM_findObj("ant");

    if (canvas == null)
        canvas = MM_findObj("imgCanvas");
    if(content == null) {
        content = MM_findObj("cropContent");
    }

    if (pic_width == null || pic_height == null)
    {
        image = MM_findObj("theImage");
        pic_width = image.width;
        pic_height = image.height;
    }

    ant.style.visibility = "visible";

    nx = pic_x + nx;
    ny = pic_y + ny;

    if (nw >= 0)
    {
        ant.style.left = nx;
        ant.style.width = nw;
    }
    else
    {
        ant.style.left = nx+nw;
        ant.style.width = -1*nw;
    }

    if (nh >= 0)
    {
        ant.style.top = ny;
        ant.style.height = nh;
    }
    else
    {
        ant.style.top = ny+nh;
        ant.style.height = -1*nh
    }

    
}

function max(x,y) 
{
    if(y > x)
        return x;
    else 
        return y;
}

function drawBoundHandle() 
{
    if(ant == null || ant.style == null) 
        return false;

    var ah = parseInt(ant.style.height);
    var aw = parseInt(ant.style.width);
    var ax = parseInt(ant.style.left);
    var ay = parseInt(ant.style.top);

    jg_doc.drawHandle(ax-15,ay-15,30,30,"nw-resize"); //upper left
    jg_doc.drawHandle(ax-15,ay+ah-15,30,30,"sw-resize"); //lower left
    jg_doc.drawHandle(ax+aw-15,ay-15,30,30,"ne-resize"); //upper right
    jg_doc.drawHandle(ax+aw-15,ay+ah-15,30,30,"se-resize"); //lower right

    jg_doc.drawHandle(ax+max(15,aw/10),ay-8,aw-2*max(15,aw/10),8,"n-resize"); //top middle
    jg_doc.drawHandle(ax+max(15,aw/10),ay+ah,aw-2*max(15,aw/10),8,"s-resize"); //bottom middle
    jg_doc.drawHandle(ax-8, ay+max(15,ah/10),8,ah-2*max(15,ah/10),"w-resize"); //left middle
    jg_doc.drawHandle(ax+aw, ay+max(15,ah/10),8,ah-2*max(15,ah/10),"e-resize"); //right middle



    jg_doc.drawHandleBox(ax-4,ay-4,8,8,"nw-resize"); //upper left
    jg_doc.drawHandleBox(ax-4,ay+ah-4,8,8,"sw-resize"); //lower left
    jg_doc.drawHandleBox(ax+aw-4,ay-4,8,8,"ne-resize"); //upper right
    jg_doc.drawHandleBox(ax+aw-4,ay+ah-4,8,8,"se-resize"); //lower right

    jg_doc.drawHandleBox(ax+aw/2-4,ay-4,8,8,"n-resize"); //top middle
    jg_doc.drawHandleBox(ax+aw/2-4,ay+ah-4,8,8,"s-resize"); //bottom middle
    jg_doc.drawHandleBox(ax-4, ay+ah/2-4,8,8,"w-resize"); //left middle
    jg_doc.drawHandleBox(ax+aw-4, ay+ah/2-4,8,8,"e-resize"); //right middle

    //jg_doc.paint();
}

function showStatus() 
{
    if(ant == null || ant.style == null) {
        return false;
    }

    if(mode == "measure") {
        //alert(pic_x);
        mx1 = x - pic_x;
        my1 = y - pic_y;

        mw = mx2 - x;
        mh = my2 - y;

        md = parseInt(Math.sqrt(mw*mw + mh*mh)*100)/100;

        ma = (Math.atan(-1*mh/mw)/Math.PI)*180;
        if(mw < 0 && mh < 0)
            ma = ma+180;

        if (mw <0 && mh >0)
            ma = ma - 180;

        ma = parseInt(ma*100)/100;

        if (m_sx != null && !isNaN(mx1))
            m_sx.value = mx1+"px";
        if (m_sy != null && !isNaN(my1))
            m_sy.value = my1+"px";
        if(m_w != null && !isNaN(mw))
            m_w.value = mw + "px";
        if(m_h != null && !isNaN(mh))
            m_h.value = mh + "px";

        if(m_d != null && !isNaN(md))
            m_d.value = md + "px";
        if(m_a != null && !isNaN(ma))
            m_a.value = ma + "";

        if(r_ra != null &&!isNaN(ma))
            r_ra.value = ma;            

        //alert("mx1:"+mx1+" my1"+my1);
        return false;
    }

    var ah = parseInt(ant.style.height);
    var aw = parseInt(ant.style.width);
    var ax = parseInt(ant.style.left);
    var ay = parseInt(ant.style.top);

    var cx = ax-pic_x<0?0:ax-pic_x;
    var cy = ay-pic_y<0?0:ay-pic_y;
    cx = cx>pic_width?pic_width:cx;
    cy = cy>pic_height?pic_height:cy;
    
    var cw = ax-pic_x>0?aw:aw-(pic_x-ax);
    var ch = ay-pic_y>0?ah:ah-(pic_y-ay);

    ch = ay+ah<pic_y+pic_height?ch:ch-(ay+ah-pic_y-pic_height);
    cw = ax+aw<pic_x+pic_width?cw:cw-(ax+aw-pic_x-pic_width);

    ch = ch<0?0:ch; cw = cw<0?0:cw;
    
    if (ant.style.visibility == "hidden")
    {
        cx = ""; cy = ""; cw=""; ch="";
    }

    if(mode == 'crop') {
        if(t_cx != null)
            t_cx.value = cx;
        if (t_cy != null)   
            t_cy.value = cy;
        if(t_cw != null)
            t_cw.value = cw;
        if (t_ch != null)   
            t_ch.value = ch;
    }
    else if(mode == 'scale') {

        var sw = aw, sh = ah;

        if (s_sw.value.indexOf('%')>0 && s_sh.value.indexOf('%')>0)
        {   
            sw = cw/pic_width;
            sh = ch/pic_height;
        }
        if (s_sw != null)
            s_sw.value = sw;
        if (s_sh != null)
            s_sh.value = sh;
    }

}

function dragStopped()
{
    dragapproved=false;

    if(ant == null || ant.style == null) {
        return false;
    }

    if(mode == "measure") {
        jg_doc.drawLine(x-4,y,x+4,y);
        jg_doc.drawLine(x,y-4,x,y+4);
        jg_doc.drawLine(mx2-4,my2,mx2+4,my2);
        jg_doc.drawLine(mx2,my2-4,mx2,my2+4);

        jg_doc.paint();
        showStatus();
        return false;
    }
        var ah = parseInt(ant.style.height);
        var aw = parseInt(ant.style.width);
        var ax = parseInt(ant.style.left);
        var ay = parseInt(ant.style.top);
        jg_doc.clear();
        
        if(content != null) {
            if(content.width != null && content.height != null) {
                content.width = aw-1;
                content.height = ah-1;
            }
            //alert(content.width+":"+content.height);
        }
        if(mode == "crop") {
            //alert(pic_y);
            jg_doc.fillRectPattern(pic_x,pic_y,pic_width,ay-pic_y,pattern);
            
            var h1 = ah;
            var y1 = ay;
            if (ah+ay >= pic_height+pic_y)
                h1 = pic_height+pic_y-ay;
            else if (ay <= pic_y)
            {
                h1 = ay+ah-pic_y;
                y1 = pic_y;
            }
            jg_doc.fillRectPattern(pic_x,y1,ax-pic_x,h1,pattern);
            jg_doc.fillRectPattern(ax+aw,y1,pic_x+pic_width-ax-aw,h1,pattern);
            jg_doc.fillRectPattern(pic_x,ay+ah,pic_width,pic_height+pic_y-ay-ah,pattern);
        }
        else if(mode == "scale") {
            //alert("Resizing: iw:"+image.width+" nw:"+aw);
            document.theImage.height = ah;
            document.theImage.width = aw;
            document.theImage.style.height = ah+" px";
            document.theImage.style.width = aw+" px";

            P7_Snap('theImage','ant',0,0);

            //alert("After Resizing: iw:"+image.width+" nw:"+aw);
        }

        drawBoundHandle();
        jg_doc.paint();
    
        showStatus();
    return false;
}

document.onmousedown=drags
document.onmouseup=dragStopped;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -