Cut any elements from web page
$ git clone git@github.com:likerRr/cutterjs.git
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="cutter.min.js">
You only need to initialize plugin with jQuery element, that wraps area where you want to cut:
$('body').cutter('init');
Now move cursor to any element and press Ctrl+x
or Delete
key
By default, init method have some default options:
display: none
You can override almost all actions used in plugin just in init
method with second parameter
All callback methods accept one parameter - element in action
Handle, when mouse moves over element in target area:
$('body').cutter('init', {
mouseOver: function(el) {
el.data('border', el.css('border'));
el.css('border', 'dotted gray 1px');
},
});
Now hovered elements will have dotted gray border
Please, note, you need to store default data with
data
method to be able to restore previous element state
Handle, when mouse moves out from element in target area:
$('body').cutter('init', {
mouseOut: function(el) {
el.css('border', el.data('border'));
},
});
Now we can restore default value of
border
property
You can use that option to set up, how elements will be removed
$('body').cutter('init', {
onCut: function(el) {
el.data('opacity', el.css('opacity'));
el.css('opacity', '0.3');
},
});
Note! You need to store default element state to be able to restore it
You may need to do list with deleted elements to be able to restore them, so that method will help you
var deletedElements = [];
...
$('body').cutter('init', {
afterCut: function(el) {deletedElements .push(el);},
});
Function will handle when you call restore
method
$('body').cutter('init', {
onRestore: function(el) {
el.css('opacity', el.data('opacity'));
}
});
I think that "cut mode" will not be active all the time, so we need to be able to stop it
var bodyArea = $('body').cutter('init');
...
bodyArea.cutter('stop');
After calling this method all actions will be suspended
To restore "cut mode" call start
method
var bodyArea = $('body').cutter('init');
...
bodyArea.cutter('stop');
...
bodyArea.cutter('start');
You can also get all deleted items for current area, just use deleted
method
var bodyArea = $('body').cutter('init');
...
var deletedItems = bodyArea.cutter('deleted');
Finally you need to be able to restore deleted elements. Method restore
will help you. It accepts one optional parameter - deleted jQuery element or empty to restore all elements
var $lastDeleted;
...
var bodyArea = $('body').cutter('init', {
afterCut: function(el) {$lastDeleted = el;},
});
// restore one
bodyArea.cutter('restore', $lastDeleted);
// restore all
bodyArea.cutter('restore');
Just press Start to cut!
button at navigation bar and enjoy!
Project under MIT licence, feel free to use and edit