Вход Регистрация
Файл: concrete5.7.5.6/concrete/js/image-editor/controls/position.js
Строк: 582
<?php
var me = $(this), ratio_hratio_v;

im.bind('changeActiveElement', function () {
    if (
im.strictSize) {
        
im.activeElement.setDraggable(true);
    }
    
im.activeElement.setPosition({x0y0});
    
im.adjustSavers();
    
ratio im.activeElement.getWidth() / im.activeElement.getHeight();
    
height_input.val(im.activeElement.getHeight());
    
width_input.val(im.activeElement.getWidth());
    
resetScale();
});

function 
FitImage(imme) {

    function 
resetThumbnail() {
        if (
im.settings.saveWidth && !im.settings.saveHeight) {
            $(
width_input).val(im.settings.saveWidth).keyup();
        } else if (
im.settings.saveWidth && im.settings.saveHeight) {
            if (
ratio || ratio === 1) {
                if (
im.settings.saveWidth im.settings.saveHeight) {
                    $(
width_input).val(im.settings.saveWidth).keyup();
                } else {
                    $(
height_input).val(im.settings.saveHeight).keyup();
                }
            } else if (
ratio 1) {
                if (
im.settings.saveWidth im.settings.saveHeight) {
                    $(
height_input).val(im.settings.saveHeight).keyup();
                } else {
                    $(
width_input).val(im.settings.saveWidth).keyup();
                }
            }
        }
    }

    function 
centerImage() {
        
im.activeElement.setPosition(00);
        
im.activeElement.parent.draw();
    }

    if (
im.settings.saveWidth || im.settings.saveHeight) {
        $(
'button.reset'me).on('click', function() {
            
resetThumbnail();
            
centerImage();
        });
    } else {
        $(
'button.reset'me).hide();
    }

}

new 
FitImage(imme);

function 
Rotation(imme) {
    var 
my this,
        
RotationFlipModeVertical 0,
        
RotationFlipModeHorizontal 1;

    function 
flip(rotationFlipMode) {
        var 
scale im.activeElement.getScale(),
            
scaleCopy = {xscale.xyscale.y};
        switch (
rotationFlipMode) {
            case 
RotationFlipModeHorizontal:
                
scaleCopy.*= -1;

                var 
degChange im.activeElement.getRotation(),
                    
= -scaleCopy.im.activeElement.getWidth();
                
im.activeElement.parent.move(Math.cos(degChange), Math.sin(degChange));
                break;
            case 
RotationFlipModeVertical:
                
scaleCopy.*= -1;

                
im.activeElement.rotateDeg(90);
                var 
degChange im.activeElement.getRotation(),
                    
= -scaleCopy.im.activeElement.getHeight();
                
im.activeElement.rotateDeg(-90);
                
im.activeElement.parent.move(Math.cos(degChange), Math.sin(degChange));

                break;
        }
        
im.activeElement.setScale(scaleCopy);
        
im.fire('activeElementShouldAdjustLayer');
        
im.activeElement.parent.draw();
        
im.fire('rotationChanged');
        
setTimeout(function () {
            
im.activeElement.parent.draw();
        }, 
0);
    }

    $(
'button.hflip'me).click(function () {
        
flip(RotationFlipModeHorizontal);
    });
    $(
'button.vflip'me).click(function () {
        
flip(RotationFlipModeVertical);
    });
    $(
'button.rot'me).click(function () {
        var 
deg im.activeElement.getRotationDeg();
        
deg = (Math.round((deg 90) / 90) * 90) % 360;
        
im.activeElement.setRotationDeg(deg);
        
im.activeElement.setPosition({x0y0});
        
im.adjustSavers();

        
im.fire('activeElementShouldAdjustLayer');

        
im.fire('rotationChanged');
        
setTimeout(function () {
            
im.activeElement.parent.draw();
        }, 
0);
    });
    
this.box = $('div.angle > input'me).val(0);
}

new 
Rotation(imme);

var 
crop_area = $('div.crop-area'me);
var 
locked true,
    
lock = $('button.lock'me).click(function () {
        var 
method;
        if (
locked) {
            
method = $.fn.removeClass;
        } else {
            
method = $.fn.addClass;
            
ratio im.activeElement.getWidth() / im.activeElement.getHeight();
        }
        
locked = !locked;
        
method.call(lock'active');
    });

var 
height_input = $('input[name="height"]'me).keyup(_.debounce(function (e) {
    if (
e.which === 9) {
        return;
    }
    var 
height parseInt($(this).val()), width im.activeElement.getWidth();

    if (
locked) {
        
width Math.floor(height ratio);
    }

    
im.activeElement.setWidth(width);
    
im.activeElement.setHeight(height);

    
im.fire('sizeChanged', { widthwidthheightheight });

}, 
250));

var 
width_input = $('input[name="width"]'me).keyup(_.debounce(function (e) {
    if (
e.which === 9) {
        return;
    }
    var 
width parseInt($(this).val()), height im.activeElement.getHeight();

    if (
locked) {
        
height Math.floor(width * (ratio));
    }

    
im.activeElement.setWidth(width);
    
im.activeElement.setHeight(height);

    
im.fire('sizeChanged', { widthwidthheightheight });

}, 
250));

var 
crop_button = $('button.begincrop'me).click(function() {
    if (
im.crop) return;
    
im.crop = new Crop;
    
crop_button.attr('disabled'1);
});

im.bind('sizeChanged', function (eventdata) {
    
im.activeElement.parent.draw();
    
im.adjustSavers();

    
width_input.val(data.width);
    
height_input.val(data.height);

    if (!
data.scale) {
        
resetScale();
    }
});

var 
percent = $('span.scale-percent');
var 
scale = $('div.scale-slider');
var 
scale_width 0scale_height 0fired_from_scale false;

var 
resetScale = function() {
    
scale_width im.activeElement.getWidth();
    
scale_height im.activeElement.getHeight();
    
scale.slider('value'100);
    
percent.text('100%');
};

var 
resetDebounced _.debounce(function() {
    
resetScale();
}, 
2000);

scale.slider({
    
value100,
    
min10,
    
max500,
    
step5,
    
slide: function(eventdata) {
        
new_width Math.floor(scale_width * (data.value 100));
        
new_height Math.floor(scale_height * (data.value 100));
        
im.activeElement.setWidth(new_width);
        
im.activeElement.setHeight(new_height);
        
im.adjustSavers();

        
percent.text(data.value '%');
        
resetDebounced();

        
im.fire('sizeChanged', {
            
widthnew_width,
            
heightnew_height,
            
scaletrue
        
});
    }
});

function 
Crop() {
    var 
crop this;

    
im.bind('ImageEditorWillSave', function() {
        
crop.layer.hide();
    });

    
this.active true;
    
crop_area.slideDown();
    
this.layer = new Kinetic.Layer({
        
fill'red',
        
positionim.activeElement.parent.getPosition(),
        
draggablefalse,
        
listeningtrue
    
});

    
im.bind('sizeChanged', function() {
        var 
old_position _.clone(crop.layer.getPosition());
        
crop.layer.setPosition(im.activeElement.parent.getPosition());
        
crop.dragLayer.setPosition(im.activeElement.parent.getPosition());
        var 
new_position _.clone(crop.layer.getPosition());

        
crop.offset.-= (new_position.old_position.x);
        
crop.offset.-= (new_position.old_position.y);

        
crop.layer.draw();
    });

    var 
start_positionstart_offset;

    
this.cover = new Kinetic.Shape({
        
fill'black',
        
opacity.4,
        
widthim.stage.getWidth() * 2,
        
heightim.stage.getHeight() * 2,
        
listeningfalse,
        
draggablefalse,
        
drawFunc: function (context) {
            var 
dimensions im.stage.getTotalDimensions(),
                
dimensions.min.crop.layer.getPosition().- (im.scale im.stage.getPosition().x),
                
dimensions.min.crop.layer.getPosition().- (im.scale im.stage.getPosition().y),
                
offset Math.max(dimensions.visibleWidthdimensions.visibleHeight) * 2,
                
small_rect = {
                    
position: {
                        
xcrop.offset.x,
                        
ycrop.offset.y
                    
},
                    
size: {
                        
width:  crop.width,
                        
heightcrop.height
                    
}
                },
                
large_rect = {
                    
position: {
                        
xoffset,
                        
yoffset
                    
},
                    
size: {
                        
width:  offset 2,
                        
heightoffset 2
                    
}
                };

            
context.beginPath();

            
context.moveTo(small_rect.position.xsmall_rect.position.y);
            
context.lineTo(small_rect.position.xsmall_rect.position.small_rect.size.height);
            
context.lineTo(small_rect.position.small_rect.size.widthsmall_rect.position.small_rect.size.height);
            
context.lineTo(small_rect.position.small_rect.size.widthsmall_rect.position.y);
            
context.lineTo(large_rect.position.large_rect.size.widthsmall_rect.position.y);
            
context.lineTo(large_rect.position.large_rect.size.widthlarge_rect.position.large_rect.size.height);
            
context.lineTo(large_rect.position.xlarge_rect.position.large_rect.size.height);
            
context.lineTo(large_rect.position.xlarge_rect.position.y);
            
context.lineTo(large_rect.position.large_rect.size.widthlarge_rect.position.y);
            
context.lineTo(large_rect.position.large_rect.size.widthsmall_rect.position.y);

            
context.closePath();

            
context.fillStrokeShape(this);
        }
    });


    
this.dragLayer = new Kinetic.Layer({
        
positioncrop.layer.getPosition()
    });

    
this.dragRect = new Kinetic.Rect({
        
draggabletrue,
        
listeningtrue,
        
drawFunc: function (context) {
            var 
dimensions im.stage.getTotalDimensions();
            
context.beginPath();
            
context.rect(crop.offset.crop.widthcrop.offset.y, -crop.widthcrop.height);

            
context.closePath();
            
context.fillStrokeShape(this);
        }
    })
        .
on('dragstart', function () {
            
start_position _.clone(this.getPosition());
            
start_offset _.clone(crop.offset);
        })
        .
on('dragmove', function () {
            var 
change = {
                
xthis.getPosition().start_position.x,
                
ythis.getPosition().start_position.y
            
};
            
crop.offset.start_offset.change.x;
            
crop.offset.start_offset.change.y;

            
crop.positionDraggers(this);
            
crop.draggers.top.left.parent.draw();
        })
        .
on('dragend', function () {
            var 
me this;
            
_.defer(function () {
                
crop.layer.moveToTop();
                
im.stage.draw();
                
me.setPosition(00);
                
me.parent.draw();
            });
        });

    
this.dragLayer.add(this.dragRect);

    return 
this.init();
}

Crop.prototype = {

    
init: function () {
        
this.locked true;

        
this.initializeDraggers();

        var 
dragger this.draggerslayer this.layercrop this;
        
layer.add(this.cover);
        
layer.add(dragger.top.left);
        
layer.add(dragger.top.right);
        
layer.add(dragger.bottom.left);
        
layer.add(dragger.bottom.right);

        
layer.setRotation(im.activeElement.getRotation());
        
layer.setScale(im.activeElement.getScale());
        
this.dragLayer.setRotation(im.activeElement.getRotation());
        
this.dragLayer.setScale(im.activeElement.getScale());

        
this.width im.activeElement.getWidth();
        
this.height im.activeElement.getHeight();
        
this.offset = {
            
x0,
            
y0
        
};

        
im.stage.add(this.dragLayer);
        
im.stage.add(layer);
        
layer.moveToTop();
        
im.stage.draw();

        
im.bind('scaleChange', function (event) {
            if (!
crop.active) return;
            
dragger.top.left.setScale(im.scale);
            
dragger.top.right.setScale(im.scale);
            
dragger.bottom.left.setScale(im.scale);
            
dragger.bottom.right.setScale(im.scale);
            
crop.dragRect.parent.draw();
        });

        var 
start_position;
        
im.bind('rotationChanged', function() {
            
_.defer(function(){
                
layer.setRotation(im.activeElement.getRotation());
                
layer.setScale(im.activeElement.getScale());
                
crop.dragLayer.setRotation(im.activeElement.getRotation());
                
crop.dragLayer.setScale(im.activeElement.getScale());
                
im.stage.draw();
            });
        });

        
im.bind('sizeChanged', function (eventdata) {
            if (!
crop.active) return;
            
crop.positionDraggers();
            
crop.dragRect.parent.draw();
        });

        var 
ratio im.activeElement.getWidth() / im.activeElement.getHeight();

        var 
lock_button = $('button.croplock').click(function () {
            if (!
crop.active) return;

            var 
method;
            if (
crop.locked) {
                
method = $.fn.removeClass;
            } else {
                
method = $.fn.addClass;
                
ratio crop.width crop.height;
            }
            
crop.locked = !crop.locked;
            
method.call(lock_button'active');
        }).
addClass('active');
        
im.bind('changeActiveElement', function () {
            if (
crop !== im.cropConcrete.event.unbind(eventim.stage.getContainer());

            
ratio crop.width crop.height;
            
im.stage.draw();
        });

        var 
do_crop = $('button.docrop'me).click(function() {
            if (!
crop.active) return;
            
crop.finalize();
        });
        var 
cancel_crop = $('button.cancel'me).click(function() {
            
crop.destroy();
            
im.adjustSavers();
        });


        var 
height_input = $('input[name="cropheight"]'me).keyup(_.debounce(function () {
            var 
height parseInt($(this).val()), width crop.width;

            if (!
height || isNaN(height)) {
                
height im.activeElement.getHeight();
            }

            if (
crop.locked) {
                
width Math.floor(height ratio);
            }

            
crop.width width;
            
crop.height height;

            
im.fire('cropSizeChanged', { widthwidthheightheight });

        }, 
250)).val(crop.height);

        var 
width_input = $('input[name="cropwidth"]'me).keyup(_.debounce(function () {
            var 
width parseInt($(this).val()), height crop.height;

            if (!
width || isNaN(width)) {
                
width im.activeElement.getHeight();
            }

            if (
crop.locked) {
                
height Math.floor(width * (ratio));
            }

            
crop.width Math.abs(width);
            
crop.height Math.abs(height);

            
im.fire('cropSizeChanged', { widthwidthheightheight });

        }, 
250)).val(crop.width);

        
im.bind('cropSizeChanged', function (eventdata) {
            
crop.width Math.floor(data.width);
            
crop.height Math.floor(data.height);
            
width_input.val(crop.width);
            
height_input.val(crop.height);
            
_.defer(function () {
                
crop.positionDraggers();
                
layer.draw();
            });
        });

        
this.positionDraggers();
    },

    
initializeDraggers: function () {
        var 
crop thisstart_positionstart_offsetstart_widthstart_height,
            
dragger = new Kinetic.Rect({
                
width10,
                
height10,
                
offset: {
                    
x5,
                    
y5
                
},
                
scaleim.scale,
                
stroke'black',
                
fill'white',
                
draggabletrue,
                
listeningtrue
            
}).on('dragstart',function () {
                
start_position _.clone(this.getPosition());
                
start_offset _.clone(crop.offset);
                
start_width crop.width;
                
start_height crop.height;
            }).
on('dragend',function () {
                
crop.positionDraggers();

                
im.stage.draw();
            }).
on('dragmove', function () {
                
im.fire('cropSizeChanged', {
                    
widthcrop.width,
                    
heightcrop.height
                
});
            });

        var 
drawFunc dragger.getDrawFunc();
        
dragger.setDrawFunc(function () {
            
crop.positionDraggers();
            
drawFunc.apply(thisarguments);
        });

        
this.draggers = {
            
top: {
                
leftdragger,
                
rightdragger.clone()
            },
            
bottom: {
                
leftdragger.clone(),
                
rightdragger.clone()
            }
        };

        function 
getOffset() {
            return {
                
xthis.getPosition().start_position.x,
                
ythis.getPosition().start_position.y
            
};
        }

        
this.draggers.top.left.on('dragmove', function () {
            var 
offset getOffset.call(this);

            if (
crop.locked) {
                
offset.offset.* (start_height start_width);
            }

            
crop.width start_width offset.x;
            
crop.height start_height offset.y;
            
crop.offset.start_offset.offset.y;
            
crop.offset.start_offset.offset.x;

            
crop.positionDraggers(this);
        });

        
this.draggers.top.right.on('dragmove', function () {
            var 
offset getOffset.call(this);

            if (
crop.locked) {
                
offset.= -offset.* (start_height start_width);
            }

            
crop.width start_width offset.x;
            
crop.height start_height offset.y;
            
crop.offset.start_offset.offset.y;

            
crop.positionDraggers(this);
        });

        
this.draggers.bottom.left.on('dragmove', function () {
            var 
offset getOffset.call(this);

            if (
crop.locked) {
                
offset.= -offset.* (start_height start_width);
            }
            
crop.width start_width offset.x;
            
crop.height start_height offset.y;
            
crop.offset.start_offset.offset.x;

            
crop.positionDraggers(this);
        });

        
this.draggers.bottom.right.on('dragmove', function () {
            var 
offset getOffset.call(this);

            if (
crop.locked) {
                
offset.offset.* (start_height start_width);
            }
            
crop.width start_width offset.x;
            
crop.height start_height offset.y;

            
crop.positionDraggers(this);
        });
    },

    
positionDraggers: function (omit_dragger) {
        var 
top_left this.draggers.top.lefttop_right this.draggers.top.right,
            
bottom_left this.draggers.bottom.leftbottom_right this.draggers.bottom.right,
            
offset;

        if (
this.height || this.width 0) {
            
this.height Math.max(this.height0);
            
this.width Math.max(this.width0);
            
omit_dragger null;
        }
        
offset = {
            
width: (-this.width im.scale) + 5,
            
height: (-this.height im.scale) + 5
        
};

        if (
top_left !== omit_dragger) {
            
top_left.setPosition({
                
xthis.offset.x,
                
ythis.offset.y
            
});
        }
        if (
top_right !== omit_dragger) {
            
top_right.setPosition({
                
xthis.offset.x,
                
ythis.offset.y
            
}).setOffset({
                
xoffset.width,
                
y5
            
});
        }
        if (
bottom_left !== omit_dragger) {
            
bottom_left.setPosition({
                
xthis.offset.x,
                
ythis.offset.y
            
}).setOffset({
                
x5,
                
yoffset.height
            
});
        }
        if (
bottom_right !== omit_dragger) {
            
bottom_right.setPosition({
                
xthis.offset.x,
                
ythis.offset.y
            
}).setOffset({
                
xoffset.width,
                
yoffset.height
            
});
        }
    },

    
destroy: function () {
        var 
me this;
        
this.active false;
        
this.layer.removeChildren();
        
this.layer.remove();
        
this.dragLayer.removeChildren();
        
this.dragLayer.remove();
        
im.crop null;
        
crop_button.enable();
        
crop_area.slideUp();

        
_(this).chain().functions().each(function(val) {
            
me[val] = function(){};
        });
    },

    
finalize: function() {
        var 
crop this,
            
elem im.activeElement,
            
old_filter elem.getFilter(),
            
old_rotation elem.getRotationDeg(),
            
old_scale elem.getScale(),
            
old_layer_position elem.parent.getPosition(),
            
old_stage_position im.stage.getPosition();

        
im.stage.setScale(1);
        
im.stage.setPosition(00);
        
elem.parent.setPosition(00);
        
elem.setRotationDeg(0);
        
elem.setScale(11);
        
elem.clearFilter();

        
elem.toImage({
            
x0,
            
y0,
            
widthelem.getWidth(),
            
heightelem.getHeight(),
            
callback: function(image) {
                
im.activeElement.setImage(image);
                
im.activeElement.setFilter(old_filter);
                
im.activeElement.setRotationDeg(old_rotation);
                
im.activeElement.setScale(old_scale);
                
elem.setCrop({
                    
xcrop.offset.x,
                    
ycrop.offset.y,
                    
widthcrop.width,
                    
heightcrop.height
                
});
                
im.stage.setScale(im.scale);

                
elem.setWidth(crop.width);
                
elem.setHeight(crop.height);

                
elem.parent.draw();
                
im.adjustSavers();
                
crop.destroy();
                
im.stage.draw();

                
elem.getLayer().setPosition(old_layer_position);
                
im.stage.setPosition(old_stage_position);

                
im.fire('activeElementSizeChange');
                
im.fire('sizeChanged', {
                    
widthcrop.width,
                    
heightcrop.height
                
});
            }
        });

    }

};
?>
Онлайн: 0
Реклама