|
$(document).ready(function () { |
|
|
|
function clickable(){ |
|
$("span").on("click", function(){ |
|
var obj = $("body").find(".selected"); |
|
|
|
if($(this) != obj){ |
|
if(!$(this).hasClass('tri-contain')){ |
|
|
|
} |
|
$(obj).removeClass("selected"); |
|
$(this).addClass("selected"); |
|
} |
|
}); |
|
|
|
} |
|
|
|
function newObj(){ |
|
$("body").append("<span data-rot='0' class='tri-contain'><div class='tri' style=' border-bottom-color: "+ $("#colorpicker").val() +"'></div></span>"); |
|
$(".tri-contain").draggable().resizable(); |
|
var labelcount = parseInt($("#count-tri").text(), 10); |
|
$("#count-tri").text(labelcount + 1); |
|
if((labelcount+1)!=1){ |
|
$("#count-tri-text").text(" triangles"); |
|
} |
|
else{ |
|
$("#count-tri-text").text(" triangle"); |
|
} |
|
|
|
$(".tri-contain").on("resize", function(){ |
|
var height = $(this).height(); |
|
var width = $(this).width(); |
|
|
|
$(this).find(".tri").css({"border-bottom-width": height, "border-left-width": width/2, "border-right-width": width/2}); |
|
$(this).find(".triRight").css({"border-bottom-width": height, "border-left-width": width/2, "border-right-width": width/2}); |
|
$(this).find(".triDown").css({"border-top-width": height, "border-left-width": width/2, "border-right-width": width/2}); |
|
$(this).find(".triLeft").css({"border-bottom-width": height, "border-left-width": width/2, "border-right-width": width/2}); |
|
}); |
|
clickable(); |
|
} |
|
|
|
function newSqr (){ |
|
$("body").append("<span class='grab' style='background-color: "+ $("#colorpicker").val() +"' data-rot='0'></span>"); |
|
$(".grab").draggable(); |
|
$(".grab").resizable(); |
|
var labelcount = parseInt($("#count-block").text(), 10); |
|
$("#count-block").text(labelcount + 1); |
|
if((labelcount+1)!=1){ |
|
$("#count-block-text").text(" blocks"); |
|
} |
|
else{ |
|
$("#count-block-text").text(" block"); |
|
} |
|
clickable(); |
|
} |
|
|
|
function newCir (){ |
|
$("body").append("<span class='circle' style='background-color: "+ $("#colorpicker").val() +"' data-rot='0'></span>"); |
|
$(".circle").draggable(); |
|
$(".circle").resizable(); |
|
var labelcount = parseInt($("#count-circle").text(), 10); |
|
$("#count-circle").text(labelcount + 1); |
|
if((labelcount+1)!=1){ |
|
$("#count-circle-text").text(" circles"); |
|
} |
|
else { |
|
$("#count-circle-text").text(" circle"); |
|
} |
|
clickable(); |
|
} |
|
|
|
function deleteObj(){ |
|
var delobj = $("body").find(".selected"); |
|
// $("body").find(".selected").remove(); |
|
var count = 0; |
|
if(delobj.hasClass('tri-contain')){ |
|
count = parseInt($('#count-tri').text(), 10); |
|
count--; |
|
$("#count-tri").text(count); |
|
if(count!=1){ |
|
$("#count-tri-text").text(" triangles"); |
|
} |
|
else { |
|
$("#count-tri-text").text(" triangle"); |
|
} |
|
} |
|
else if(delobj.hasClass('circle')){ |
|
count = parseInt($('#count-circle').text(), 10); |
|
count--; |
|
$("#count-circle").text(count); |
|
if(count!=1){ |
|
$("#count-circle-text").text(" circles"); |
|
} |
|
else { |
|
$("#count-circle-text").text(" circle"); |
|
} |
|
} |
|
else if(delobj.hasClass('grab')){ |
|
count = parseInt($('#count-block').text(), 10); |
|
count--; |
|
$("#count-block").text(count); |
|
if(count!=1){ |
|
$("#count-block-text").text(" blocks"); |
|
} |
|
else { |
|
$("#count-block-text").text(" block"); |
|
} |
|
} |
|
|
|
delobj.remove(); |
|
} |
|
|
|
function rotater(){ |
|
var rotation = $(".selected").data('rot') + 45; |
|
$(".selected").css({"transform": "rotate("+rotation+"deg)"}).data('rot', rotation); |
|
} |
|
|
|
/* Initialize draggable and droppable elements*/ |
|
$("body").droppable(); |
|
$(".grab").draggable().resizable(); |
|
$(".tri-contain").draggable().resizable(); |
|
$(".circle").draggable().resizable(); |
|
|
|
|
|
/* Call to functions */ |
|
$("#block").on("click", function(){ |
|
newSqr(); |
|
}); |
|
|
|
$("#triangle").on("click", function(){ |
|
newObj(); |
|
}); |
|
|
|
$("#circle").on("click", function(){ |
|
newCir(); |
|
}); |
|
|
|
$("#delete").on("click", function(){ |
|
deleteObj(); |
|
}); |
|
|
|
$("#rotater").on("click", function(){ |
|
rotater(); |
|
}); |
|
|
|
clickable(); |
|
|
|
|
|
}); |