Jquery UI Rotatable w/4 Corner Handles
How to get four corner rotate handles when using jQuery UI Rotatable plugin from https://github.com/godswearhats/jquery-ui-rotatable. Answer to this question: http://stackoverflow.com/questions/38460183/how-to-get-four-corners-rotate-handle-for-a-rotatable-div
by Twisty
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-beta1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
<script src="//cdn.jsdelivr.net/jquery.ui.rotatable/1.0.1/jquery.ui.rotatable.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.css">
<div class="box-wrapper">
<div class="box">
</div>
</div>
CSS
.box {
border: 2px solid black;
width: 100px;
height: 100px;
background-color: green;
margin: 27px;
position: relative;
}
.ui-rotatable-handle {
background: url("https://cdn.jsdelivr.net/jquery.ui.rotatable/1.0.1/rotate.png");
background-repeat: no-repeat;
background-size: 100% 100%;
height: 25px;
width: 25px;
position: absolute;
}
.ui-rotatable-handle-sw {
bottom: -27px;
left: -27px;
}
.ui-rotatable-handle-nw {
top: -27px;
left: -27px;
}
.ui-rotatable-handle-se {
bottom: -27px;
right: -27px;
}
.ui-rotatable-handle-ne {
top: -27px;
right: -27px;
}
JavaScript
$(function() {
// Prepare extra handles
var nw = $("<div>", {
class: "ui-rotatable-handle"
});
var ne = nw.clone();
var se = nw.clone();
/*
You can also combine this plugin with the jQuery UI built-in resizable() and draggable(), although the latter works best when applied to a container with the rotatable inside it. See the Demo page for some examples.
*/
// Assign Draggable
$('.box-wrapper').draggable({
cancel: ".ui-rotatable-handle"
});
// Assign Rotatable
$('.box').resizable().rotatable();
// Assign coordinate classes to handles
$('.box div.ui-rotatable-handle').addClass("ui-rotatable-handle-sw");
nw.addClass("ui-rotatable-handle-nw");
ne.addClass("ui-rotatable-handle-ne");
se.addClass("ui-rotatable-handle-se");
// Assign handles to box
$(".box").append(nw, ne, se);
// Assigning bindings for rotation event
$(".box div[class*='ui-rotatable-handle-']").bind("mousedown", function(e) {
$('.box').rotatable("instance").startRotate(e);
});
});