diff --git a/amd/build/canvas.min.js b/amd/build/canvas.min.js index c386bb5..0b9b343 100644 --- a/amd/build/canvas.min.js +++ b/amd/build/canvas.min.js @@ -1,2 +1,13 @@ -function _typeof(a){"@babel/helpers - typeof";if("function"==typeof Symbol&&"symbol"==typeof Symbol.iterator){_typeof=function(a){return typeof a}}else{_typeof=function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a}}return _typeof(a)}define ("mod_gcanvas/canvas",["jquery","core/notification"],function(a,b){'use strict';var c={id:0,debugjs:!1,hasHorizontalRuler:!0,background:""},d=function(a){var b,d;for(b in c){if(c.hasOwnProperty(b)&&a.hasOwnProperty(b)){d=_typeof(c[b]);if("boolean"===d){c[b]=!!a[b]}else if("number"===d){c[b]=+a[b]}else if("string"===d){c[b]=a[b]+""}}}},f={},g=0,h=!0,i=function(a){if(a){for(var b in console){if("function"==typeof console[b]){f[b]=console[b].bind(window.console)}}}else{for(var c in console){if("function"==typeof console[c]){f[c]=function(){}}}}},j=null,k={canvasWidth:800,canvasHeight:500,defaultShaperect:{width:70,height:70,left:200,top:50,angle:0,fill:"#ffb628"},defaultShapecircle:{radius:40,left:200,top:50,fill:"#b3cc2b"},defaultShapetriangle:{top:50,left:200,width:70,height:70,fill:"#0081b4"},defaultShapetextbox:{top:50,left:200,fill:"#0081b4"},loadHistory:function loadHistory(){a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"load_history",data:{id:c.id}},dataType:"json",success:function success(b){f.log(b);if(b.success){a("#history").html(b.html)}},error:function error(a){f.error(a.responseText);b.addNotification({message:a.responseText,type:"error"})}})},saveCanvasAjax:function saveCanvasAjax(){if(!fabric.Canvas.supports("toDataURL")){b.addNotification({message:"This browser doesn't provide means to serialize canvas to an image",type:"error"})}else{a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"save_canvas",data:{id:c.id,status:"final",canvas_data:j.toDataURL({multiplier:1,format:"png"}),json_data:JSON.stringify(j)}},dataType:"json",success:function success(a){f.log(a);if(a.success){b.addNotification({message:M.util.get_string("javascript:updated","mod_gcanvas"),type:"success"});k.loadHistory()}else{b.addNotification({message:a.error,type:"error"})}},error:function error(a){f.error(a.responseText);b.addNotification({message:a.responseText,type:"error"})}})}},deleteSelectedCanvasItems:function deleteSelectedCanvasItems(){try{var a=j.getActiveObjects();if(0>=a.length){f.log("Selection empty");return}for(var b in a){if(a.hasOwnProperty(b)){var c=a[b];if(c.id!==void 0&&"ruler"===c.id){f.log("Ruler: Not removable!");continue}j.remove(c)}}j.discardActiveObject().renderAll()}catch(a){f.error("Nothing selected",a)}},loadDynamicToolbarMappingShapes:function loadDynamicToolbarMappingShapes(){a("#toolbar .icon[data-element-type]").on("click",function(){var b,c=a(this).data("element-type");try{j.discardActiveObject()}catch(a){}var d="defaultShape"+c.toLowerCase();f.log("Search for shape: "+d);if(k.hasOwnProperty(d)){f.log("Shape found");if("Textbox"===c){b=new fabric[c]("DEMO",k[d])}else{b=new fabric[c](k[d])}j.add(b);j.setActiveObject(b)}else{f.error("Shape not found!")}j.renderAll()})},loadColorPicker:function loadColorPicker(){a("#colorpicker").spectrum({showPalette:!0,palette:[],showSelectionPalette:!0,selectionPalette:["red","green","blue","orange"],flat:!1,change:function change(a){f.log("change color");k.setColor(a)}}).on("dragstart.spectrum , dragstop.spectrum",function(a,b){f.log("change color - dragstop - dragstart");k.setColor(b)})},loadEmojiCsv:function loadEmojiCsv(a){f.log("loadEmojiCsv : ",a);fabric.Image.fromURL(a.replace(".png",".svg"),function(a){a.set({height:500,width:500,left:150,top:100,angle:0,centerTransform:!0}).scale(.4).setCoords();j.add(a);j.setActiveObject(a)})},deleteAttempt:function deleteAttempt(d){f.log("Delete",d);b.confirm(M.util.get_string("javascript:confirm_title","mod_gcanvas"),M.util.get_string("javascript:confirm_desc","mod_gcanvas"),M.util.get_string("javascript:yes","mod_gcanvas"),M.util.get_string("javascript:no","mod_gcanvas"),function(){a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"delete_attempt",data:{id:c.id,attempt_id:d.data("id")}},dataType:"json",success:function success(a){f.log(a);if(a.success){k.loadHistory()}else{b.addNotification({message:a.error,type:"error"})}},error:function error(a){f.error(a.responseText);b.addNotification({message:a.responseText,type:"error"})}})})},restoreAttempt:function restoreAttempt(b){f.log("Restore",b);a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"get_attempt",data:{id:c.id,attempt_id:b.data("id")}},dataType:"json",success:function success(a){f.log(a);if(a.success){h=!1;j.loadFromJSON(a.record.json_data,j.renderAll.bind(j));setTimeout(function(){h=!0},1e3)}}})},showFileuploader:function showFileuploader(b){a("#canvas-filepicker-form-"+b).toggle()},setBackgroundImage:function setBackgroundImage(){if(""!==c.background){fabric.Image.fromURL(c.background,function(a){j.setBackgroundImage(a,j.renderAll.bind(j),{scaleX:j.width/a.width,scaleY:j.height/a.height})})}},addUserImage:function addUserImage(){var b={id:c.id},d=a("#canvas-filepicker-form-student_image form").serializeArray();a.each(d,function(a,c){b[c.name]=c.value});a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"upload_images",data:b},dataType:"json",success:function success(b){f.log(b);if(b.success){k.addImageFromUrl(b.image)}a("#canvas-filepicker-form-student_image").hide()}})},addImageFromUrl:function addImageFromUrl(a){fabric.Image.fromURL(a,function(a){a.set({left:150,top:100,angle:0,centerTransform:!0}).setCoords();var b=j.getWidth()/3;if(a.width>b){a.scaleToWidth(b)}j.add(a);j.setActiveObject(a)})},selectToolbarImage:function selectToolbarImage(){var b=a("#image-picker");if(b.is(":visible")){b.hide();return}b.show();a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"get_toolbar_images",data:{id:c.id}},dataType:"json",success:function success(c){f.log(c);if(c.success){var d="";b.html(d)}}})},undo:function undo(){if(0===g){return}try{var a=localStorage.getItem("buffer_"+g);j.loadFromJSON(a,j.renderAll.bind(j));localStorage.removeItem("buffer_"+g);g--}catch(a){f.log(a)}},loadToolbar:function loadToolbar(){this.setBackgroundImage();this.loadDynamicToolbarMappingShapes();this.loadColorPicker();a("#clear").on("click",function(){j.clear();if(c.hasHorizontalRuler){k.addHorizontalRuler()}k.setBackgroundImage()});a("#arrow i").on("click",function(){k.loadArrowToCanvas()});a("#trash i").on("click",function(){k.deleteSelectedCanvasItems()});a("#smiley i").on("click",function(){k.loadEmojiPicker()});a("#undo").on("click",function(){h=!1;k.undo();setTimeout(function(){h=!0},500)});a("#add-image i").on("click",function(){k.showFileuploader("student_image")});a("#select-a-image i").on("click",function(){k.selectToolbarImage()});a("#image-picker ").on("click","img",function(){k.addImageFromUrl(a(this).attr("src"));a("#image-picker").hide()});a("#save-canvas").on("click",function(){k.saveCanvasAjax()});a("#show-help").on("click",function(){a("#dialog-help").show()});a("#dialog-help").on("click",function(){a("#dialog-help").hide()});a("#history").on("click",".delete",function(b){b.preventDefault();k.deleteAttempt(a(this))}).on("click",".restore",function(b){b.preventDefault();k.restoreAttempt(a(this))});a("#emoji-picker").on("click","img",function(){k.loadEmojiCsv(a(this).attr("src"));a("#emoji-picker").hide()});a("#change_background").on("click",function(){k.showFileuploader("background")});a("#add_toolbar_images").on("click",function(){k.showFileuploader("toolbar_shape")});a("#canvas-filepicker-form-student_image").on("click","#id_submitbutton",function(a){a.preventDefault();k.addUserImage()});a(".dialog").on("click",".btn-secondary",function(b){b.preventDefault();f.log("Cancel");a(".dialog").hide()})},loadEmojiPicker:function loadEmojiPicker(){var b=a("#emoji-picker");if(""!==b.html()){f.log("Toggle emoji");b.toggle();return}a.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"emoji",data:{id:c.id}},dataType:"json",success:function success(a){f.log(a);if(a.success){b.html(a.html).show()}}})},loadArrowToCanvas:function loadArrowToCanvas(){fabric.loadSVGFromURL("pix/arrow.svg",function(a,b){var c=fabric.util.groupSVGElements(a,b);j.add(c.scale(.1)).centerObject(c).renderAll();c.setCoords();j.setActiveObject(c)})},setColor:function setColor(a){var b=a.toHexString(),c=j.getActiveObjects();if(c){for(var d in c){if(c.hasOwnProperty(d)){var e=c[d];if(e.hasOwnProperty("id")&&"ruler"===e.id){continue}e.set("fill",b)}}j.renderAll()}else{f.log("No active items")}},preventMovingOutOfCanvas:function preventMovingOutOfCanvas(){j.on("object:moving",function(a){var b=a.target;if(b.currentHeight>b.canvas.height||b.currentWidth>b.canvas.width){return}b.setCoords();if(0>b.getBoundingRect().top||0>b.getBoundingRect().left){b.top=Math.max(b.top,b.top-b.getBoundingRect().top);b.left=Math.max(b.left,b.left-b.getBoundingRect().left)}if(b.getBoundingRect().top+b.getBoundingRect().height>b.canvas.height||b.getBoundingRect().left+b.getBoundingRect().width>b.canvas.width){b.top=Math.min(b.top,b.canvas.height-b.getBoundingRect().height+b.top-b.getBoundingRect().top);b.left=Math.min(b.left,b.canvas.width-b.getBoundingRect().width+b.left-b.getBoundingRect().left)}})},keyboardActions:function keyboardActions(){a(document).keydown(function(a){f.log("keypress",a.which);switch(a.which){case 46:k.deleteSelectedCanvasItems();break;}})},init:function init(){this.__canvas=j=new fabric.Canvas("sketch");a("body").on("contextmenu","canvas , img",function(){return!1});j.setHeight(this.canvasHeight);j.setWidth(this.canvasWidth-70);j.on({"selection:created":this.onchange,"selection:updated":this.onchange,"object:added":this.addToCache,"object:removed":this.addToCache,"object:modified":this.addToCache});localStorage.clear();this.preventMovingOutOfCanvas();this.loadToolbar();if(c.hasHorizontalRuler){this.addHorizontalRuler()}this.loadHistory();this.keyboardActions()},addToCache:function addToCache(){f.log("history");k.addCanvasToCacheBuffer()},addCanvasToCacheBuffer:function addCanvasToCacheBuffer(){if(!h){return}clearTimeout(0);setTimeout(function(){try{g++;localStorage.setItem("buffer_"+g,JSON.stringify(j))}catch(a){f.log(a)}},500)},addHorizontalRuler:function addHorizontalRuler(){var b=new fabric.Rect({width:this.canvasWidth,height:2,id:"ruler",left:0,top:410,angle:0,fill:"#8b58a1"});b.flipY=!1;b.lockMovementX=!0;b.lockScalingX=!0;b.lockScalingY=!0;b.lockUniScaling=!0;b.lockRotation=!0;j.add(b);j.renderAll();a(document).keydown(function(a){switch(a.which){case 38:b.top=b.top-10;j.renderAll();break;case 40:b.top=b.top+10;j.renderAll();break;default:return;}a.preventDefault()})},onchange:function onchange(b){if(b.target.hasOwnProperty("id")&&"ruler"===b.target.id){return}a("#colorpicker").spectrum("set",b.target.fill)}};return{initialise:function initialise(b){a.getScript(M.cfg.wwwroot+"/mod/gcanvas/javascript/spectrum.js").done(function(){d(b);i(c.debugjs);a.noConflict();a(document).ready(function(){f.log("Canvas Module v1.2");k.init()})}).fail(function(a,b,c){f.log(a);f.log(b);f.log(c)})}}}); -//# sourceMappingURL=canvas.min.js.map +/** + * JS Canvas + * + * Tested in Moodle 3.9 + * + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * + * @copyright 2018 MFreak.nl + * @author Luuk Verhoeven + **/ +define("mod_gcanvas/canvas",["jquery","core/notification"],(function($,notification){var opts={id:0,debugjs:!1,hasHorizontalRuler:!0,background:""},debug={},bufferStep=0,bufferActive=!0,canvas=null,canvasModule={canvasWidth:800,canvasHeight:500,defaultShaperect:{width:70,height:70,left:200,top:50,angle:0,fill:"#ffb628"},defaultShapecircle:{radius:40,left:200,top:50,fill:"#b3cc2b"},defaultShapetriangle:{top:50,left:200,width:70,height:70,fill:"#0081b4"},defaultShapetextbox:{top:50,left:200,fill:"#0081b4"},loadHistory:function(){$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"load_history",data:{id:opts.id}},dataType:"json",success:function(response){debug.log(response),response.success&&$("#history").html(response.html)},error:function(response){debug.error(response.responseText),notification.addNotification({message:response.responseText,type:"error"})}})},saveCanvasAjax:function(){fabric.Canvas.supports("toDataURL")?$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"save_canvas",data:{id:opts.id,status:"final",canvas_data:canvas.toDataURL({multiplier:1,format:"png"}),json_data:JSON.stringify(canvas)}},dataType:"json",success:function(response){debug.log(response),response.success?(notification.addNotification({message:M.util.get_string("javascript:updated","mod_gcanvas"),type:"success"}),canvasModule.loadHistory()):notification.addNotification({message:response.error,type:"error"})},error:function(response){debug.error(response.responseText),notification.addNotification({message:response.responseText,type:"error"})}}):notification.addNotification({message:"This browser doesn't provide means to serialize canvas to an image",type:"error"})},deleteSelectedCanvasItems:function(){try{var activeobjects=canvas.getActiveObjects();if(activeobjects.length<=0)return void debug.log("Selection empty");for(var i in activeobjects)if(activeobjects.hasOwnProperty(i)){var element=activeobjects[i];if(void 0!==element.id&&"ruler"===element.id){debug.log("Ruler: Not removable!");continue}canvas.remove(element)}canvas.discardActiveObject().renderAll()}catch(e){debug.error("Nothing selected",e)}},loadDynamicToolbarMappingShapes:function(){$("#toolbar .icon[data-element-type]").on("click",(function(){var el,elementtype=$(this).data("element-type");try{canvas.discardActiveObject()}catch(e){}var shape="defaultShape"+elementtype.toLowerCase();debug.log("Search for shape: "+shape),canvasModule.hasOwnProperty(shape)?(debug.log("Shape found"),el="Textbox"===elementtype?new fabric[elementtype]("DEMO",canvasModule[shape]):new fabric[elementtype](canvasModule[shape]),canvas.add(el),canvas.setActiveObject(el)):debug.error("Shape not found!"),canvas.renderAll()}))},loadColorPicker:function(){$("#colorpicker").spectrum({showPalette:!0,palette:[],showSelectionPalette:!0,selectionPalette:["red","green","blue","orange"],flat:!1,change:function(color){debug.log("change color"),canvasModule.setColor(color)}}).on("dragstart.spectrum , dragstop.spectrum",(function(e,color){debug.log("change color - dragstop - dragstart"),canvasModule.setColor(color)}))},loadEmojiCsv:function(src){debug.log("loadEmojiCsv : ",src),fabric.Image.fromURL(src.replace(".png",".svg"),(function(object){object.set({height:500,width:500,left:150,top:100,angle:0,centerTransform:!0}).scale(.4).setCoords(),canvas.add(object),canvas.setActiveObject(object)}))},deleteAttempt:function($el){debug.log("Delete",$el),notification.confirm(M.util.get_string("javascript:confirm_title","mod_gcanvas"),M.util.get_string("javascript:confirm_desc","mod_gcanvas"),M.util.get_string("javascript:yes","mod_gcanvas"),M.util.get_string("javascript:no","mod_gcanvas"),(function(){$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"delete_attempt",data:{id:opts.id,attempt_id:$el.data("id")}},dataType:"json",success:function(response){debug.log(response),response.success?canvasModule.loadHistory():notification.addNotification({message:response.error,type:"error"})},error:function(response){debug.error(response.responseText),notification.addNotification({message:response.responseText,type:"error"})}})}))},restoreAttempt:function($el){debug.log("Restore",$el),$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"get_attempt",data:{id:opts.id,attempt_id:$el.data("id")}},dataType:"json",success:function(response){debug.log(response),response.success&&(bufferActive=!1,canvas.loadFromJSON(response.record.json_data,canvas.renderAll.bind(canvas)),setTimeout((function(){bufferActive=!0}),1e3))}})},showFileuploader:function(filearea){$("#canvas-filepicker-form-"+filearea).toggle()},setBackgroundImage:function(){""!==opts.background&&"false"!==opts.background&&fabric.Image.fromURL(opts.background,(function(img){canvas.setBackgroundImage(img,canvas.renderAll.bind(canvas),{scaleX:canvas.width/img.width,scaleY:canvas.height/img.height})}))},addUserImage:function(){var formdata={id:opts.id},inputs=$("#canvas-filepicker-form-student_image form").serializeArray();$.each(inputs,(function(i,input){formdata[input.name]=input.value})),$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"upload_images",data:formdata},dataType:"json",success:function(response){debug.log(response),response.success&&canvasModule.addImageFromUrl(response.image),$("#canvas-filepicker-form-student_image").hide()}})},addImageFromUrl:function(path){fabric.Image.fromURL(path,(function(object){object.set({left:150,top:100,angle:0,centerTransform:!0}).setCoords();var maxwidth=canvas.getWidth()/3;object.width>maxwidth&&object.scaleToWidth(maxwidth),canvas.add(object),canvas.setActiveObject(object)}))},selectToolbarImage:function(){var dialog=$("#image-picker");dialog.is(":visible")?dialog.hide():(dialog.show(),$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"get_toolbar_images",data:{id:opts.id}},dataType:"json",success:function(response){if(debug.log(response),response.success){var html='",dialog.html(html)}}}))},undo:function(){if(0!==bufferStep)try{var data=localStorage.getItem("buffer_"+bufferStep);canvas.loadFromJSON(data,canvas.renderAll.bind(canvas)),localStorage.removeItem("buffer_"+bufferStep),bufferStep--}catch(e){debug.log(e)}},loadToolbar:function(){this.setBackgroundImage(),this.loadDynamicToolbarMappingShapes(),this.loadColorPicker(),$("#clear").on("click",(function(){canvas.clear(),opts.hasHorizontalRuler&&canvasModule.addHorizontalRuler(),canvasModule.setBackgroundImage()})),$("#arrow i").on("click",(function(){canvasModule.loadArrowToCanvas()})),$("#trash i").on("click",(function(){canvasModule.deleteSelectedCanvasItems()})),$("#smiley i").on("click",(function(){canvasModule.loadEmojiPicker()})),$("#undo").on("click",(function(){bufferActive=!1,canvasModule.undo(),setTimeout((function(){bufferActive=!0}),500)})),$("#add-image i").on("click",(function(){canvasModule.showFileuploader("student_image")})),$("#select-a-image i").on("click",(function(){canvasModule.selectToolbarImage()})),$("#image-picker ").on("click","img",(function(){canvasModule.addImageFromUrl($(this).attr("src")),$("#image-picker").hide()})),$("#save-canvas").on("click",(function(){canvasModule.saveCanvasAjax()})),$("#show-help").on("click",(function(){$("#dialog-help").show()})),$("#dialog-help").on("click",(function(){$("#dialog-help").hide()})),$("#history").on("click",".delete",(function(e){e.preventDefault(),canvasModule.deleteAttempt($(this))})).on("click",".restore",(function(e){e.preventDefault(),canvasModule.restoreAttempt($(this))})),$("#emoji-picker").on("click","img",(function(){canvasModule.loadEmojiCsv($(this).attr("src")),$("#emoji-picker").hide()})),$("#change_background").on("click",(function(){canvasModule.showFileuploader("background")})),$("#add_toolbar_images").on("click",(function(){canvasModule.showFileuploader("toolbar_shape")})),$("#canvas-filepicker-form-student_image").on("click","#id_submitbutton",(function(e){e.preventDefault(),canvasModule.addUserImage()})),$(".dialog").on("click",".btn-secondary",(function(e){e.preventDefault(),debug.log("Cancel"),$(".dialog").hide()}))},loadEmojiPicker:function(){var $picker=$("#emoji-picker");if(""!==$picker.html())return debug.log("Toggle emoji"),void $picker.toggle();$.ajax({type:"POST",url:M.cfg.wwwroot+"/mod/gcanvas/ajax.php",data:{sesskey:M.cfg.sesskey,action:"emoji",data:{id:opts.id}},dataType:"json",success:function(response){debug.log(response),response.success&&$picker.html(response.html).show()}})},loadArrowToCanvas:function(){fabric.loadSVGFromURL("pix/arrow.svg",(function(objects,options){var obj=fabric.util.groupSVGElements(objects,options);canvas.add(obj.scale(.1)).centerObject(obj).renderAll(),obj.setCoords(),canvas.setActiveObject(obj)}))},setColor:function(color){var colorhex=color.toHexString(),activeobjects=canvas.getActiveObjects();if(activeobjects){for(var i in activeobjects)if(activeobjects.hasOwnProperty(i)){var element=activeobjects[i];if(element.hasOwnProperty("id")&&"ruler"===element.id)continue;element.set("fill",colorhex)}canvas.renderAll()}else debug.log("No active items")},preventMovingOutOfCanvas:function(){canvas.on("object:moving",(function(e){var obj=e.target;obj.currentHeight>obj.canvas.height||obj.currentWidth>obj.canvas.width||(obj.setCoords(),(obj.getBoundingRect().top<0||obj.getBoundingRect().left<0)&&(obj.top=Math.max(obj.top,obj.top-obj.getBoundingRect().top),obj.left=Math.max(obj.left,obj.left-obj.getBoundingRect().left)),(obj.getBoundingRect().top+obj.getBoundingRect().height>obj.canvas.height||obj.getBoundingRect().left+obj.getBoundingRect().width>obj.canvas.width)&&(obj.top=Math.min(obj.top,obj.canvas.height-obj.getBoundingRect().height+obj.top-obj.getBoundingRect().top),obj.left=Math.min(obj.left,obj.canvas.width-obj.getBoundingRect().width+obj.left-obj.getBoundingRect().left)))}))},keyboardActions:function(){$(document).keydown((function(e){if(debug.log("keypress",e.which),46===e.which)canvasModule.deleteSelectedCanvasItems()}))},init:function(){this.__canvas=canvas=new fabric.Canvas("sketch"),$("body").on("contextmenu","canvas , img",(function(){return!1})),canvas.setHeight(this.canvasHeight),canvas.setWidth(this.canvasWidth-70),canvas.on({"selection:created":this.onchange,"selection:updated":this.onchange,"object:added":this.addToCache,"object:removed":this.addToCache,"object:modified":this.addToCache}),localStorage.clear(),this.preventMovingOutOfCanvas(),this.loadToolbar(),opts.hasHorizontalRuler&&this.addHorizontalRuler(),this.loadHistory(),this.keyboardActions()},addToCache:function(){debug.log("history"),canvasModule.addCanvasToCacheBuffer()},addCanvasToCacheBuffer:function(){bufferActive&&(clearTimeout(0),setTimeout((function(){try{bufferStep++,localStorage.setItem("buffer_"+bufferStep,JSON.stringify(canvas))}catch(e){debug.log(e)}}),500))},addHorizontalRuler:function(){var ruler=new fabric.Rect({width:this.canvasWidth,height:2,id:"ruler",left:0,top:410,angle:0,fill:"#8b58a1"});ruler.flipY=!1,ruler.lockMovementX=!0,ruler.lockScalingX=!0,ruler.lockScalingY=!0,ruler.lockUniScaling=!0,ruler.lockRotation=!0,canvas.add(ruler),canvas.renderAll(),$(document).keydown((function(e){switch(e.which){case 38:ruler.top=ruler.top-10,canvas.renderAll();break;case 40:ruler.top=ruler.top+10,canvas.renderAll();break;default:return}e.preventDefault()}))},onchange:function(options){options.target.hasOwnProperty("id")&&"ruler"===options.target.id||$("#colorpicker").spectrum("set",options.target.fill)}};return{initialise:function(args){$.getScript(M.cfg.wwwroot+"/mod/gcanvas/javascript/spectrum.js").done((function(){!function(options){var key,vartype;for(key in opts)opts.hasOwnProperty(key)&&options.hasOwnProperty(key)&&("boolean"==(vartype=typeof opts[key])?opts[key]=Boolean(options[key]):"number"===vartype?opts[key]=Number(options[key]):"string"===vartype&&(opts[key]=String(options[key])))}(args),function(isenabled){if(isenabled)for(var m in console)"function"==typeof console[m]&&(debug[m]=console[m].bind(window.console));else for(var i in console)"function"==typeof console[i]&&(debug[i]=function(){})}(opts.debugjs),$.noConflict(),$(document).ready((function(){debug.log("Canvas Module v1.2"),canvasModule.init()}))})).fail((function(jqxhr,settings,exception){debug.log(jqxhr),debug.log(settings),debug.log(exception)}))}}})); + +//# sourceMappingURL=canvas.min.js.map \ No newline at end of file diff --git a/amd/build/canvas.min.js.map b/amd/build/canvas.min.js.map index c6567f2..803ebcd 100644 --- a/amd/build/canvas.min.js.map +++ b/amd/build/canvas.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/canvas.js"],"names":["define","$","notification","opts","id","debugjs","hasHorizontalRuler","background","setOptions","options","key","vartype","hasOwnProperty","debug","bufferStep","bufferActive","setDebug","isenabled","m","console","bind","window","i","canvas","canvasModule","canvasWidth","canvasHeight","defaultShaperect","width","height","left","top","angle","fill","defaultShapecircle","radius","defaultShapetriangle","defaultShapetextbox","loadHistory","ajax","type","url","M","cfg","wwwroot","data","sesskey","action","dataType","success","response","log","html","error","responseText","addNotification","message","saveCanvasAjax","fabric","Canvas","supports","toDataURL","multiplier","format","JSON","stringify","util","get_string","deleteSelectedCanvasItems","activeobjects","getActiveObjects","length","element","remove","discardActiveObject","renderAll","e","loadDynamicToolbarMappingShapes","on","el","elementtype","shape","toLowerCase","add","setActiveObject","loadColorPicker","spectrum","showPalette","palette","showSelectionPalette","selectionPalette","flat","change","color","setColor","loadEmojiCsv","src","Image","fromURL","replace","object","set","centerTransform","scale","setCoords","deleteAttempt","$el","confirm","restoreAttempt","loadFromJSON","record","json_data","setTimeout","showFileuploader","filearea","toggle","setBackgroundImage","img","scaleX","scaleY","addUserImage","formdata","inputs","serializeArray","each","input","name","value","addImageFromUrl","image","hide","path","maxwidth","getWidth","scaleToWidth","selectToolbarImage","dialog","is","show","images","undo","localStorage","getItem","removeItem","loadToolbar","clear","addHorizontalRuler","loadArrowToCanvas","loadEmojiPicker","attr","preventDefault","$picker","loadSVGFromURL","objects","obj","groupSVGElements","centerObject","colorhex","toHexString","preventMovingOutOfCanvas","target","currentHeight","currentWidth","getBoundingRect","Math","max","min","keyboardActions","document","keydown","which","init","__canvas","setHeight","setWidth","onchange","addToCache","addCanvasToCacheBuffer","clearTimeout","setItem","ruler","Rect","flipY","lockMovementX","lockScalingX","lockScalingY","lockUniScaling","lockRotation","initialise","args","getScript","done","noConflict","ready","fail","jqxhr","settings","exception"],"mappings":"mSA4BAA,OAAM,sBAAC,CAAC,QAAD,CAAW,mBAAX,CAAD,CAAkC,SAASC,CAAT,CAAYC,CAAZ,CAA0B,CAC9D,aAD8D,GAO1DC,CAAAA,CAAI,CAAG,CACPC,EAAE,CAAE,CADG,CAEPC,OAAO,GAFA,CAGPC,kBAAkB,GAHX,CAIPC,UAAU,CAAE,EAJL,CAPmD,CAkB1DC,CAAU,CAAG,SAASC,CAAT,CAAkB,CAE/B,GAAIC,CAAAA,CAAJ,CAASC,CAAT,CACA,IAAKD,CAAL,GAAYP,CAAAA,CAAZ,CAAkB,CACd,GAAIA,CAAI,CAACS,cAAL,CAAoBF,CAApB,GAA4BD,CAAO,CAACG,cAAR,CAAuBF,CAAvB,CAAhC,CAA6D,CAGzDC,CAAO,SAAUR,CAAI,CAACO,CAAD,CAAd,CAAP,CACA,GAAgB,SAAZ,GAAAC,CAAJ,CAA2B,CACvBR,CAAI,CAACO,CAAD,CAAJ,GAAoBD,CAAO,CAACC,CAAD,CAC9B,CAFD,IAEO,IAAgB,QAAZ,GAAAC,CAAJ,CAA0B,CAC7BR,CAAI,CAACO,CAAD,CAAJ,EAAmBD,CAAO,CAACC,CAAD,CAC7B,CAFM,IAEA,IAAgB,QAAZ,GAAAC,CAAJ,CAA0B,CAC7BR,CAAI,CAACO,CAAD,CAAJ,CAAmBD,CAAO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0E,cAAF,EACH,CAlBD,CAmBH,CAr0Bc,CA20BfyB,QAAQ,CAAE,kBAAStK,CAAT,CAAkB,CACxB,GAAIA,CAAO,CAACuJ,MAAR,CAAepJ,cAAf,CAA8B,IAA9B,GAA6D,OAAtB,GAAAH,CAAO,CAACuJ,MAAR,CAAe5J,EAA1D,CAA0E,CACtE,MACH,CAEDH,CAAC,CAAC,cAAD,CAAD,CAAkBqF,QAAlB,CAA2B,KAA3B,CAAkC7E,CAAO,CAACuJ,MAAR,CAAe/H,IAAjD,CACH,CAj1Bc,CA/F2C,CAm7B9D,MAAO,CAMH2J,UAAU,CAAE,oBAASC,CAAT,CAAe,CAGvB5L,CAAC,CAAC6L,SAAF,CAAYpJ,CAAC,CAACC,GAAF,CAAMC,OAAN,CAAgB,qCAA5B,EAAmEmJ,IAAnE,CAAwE,UAAW,CAG/EvL,CAAU,CAACqL,CAAD,CAAV,CAGA7K,CAAQ,CAACb,CAAI,CAACE,OAAN,CAAR,CAEAJ,CAAC,CAAC+L,UAAF,GACA/L,CAAC,CAACuK,QAAD,CAAD,CAAYyB,KAAZ,CAAkB,UAAW,CACzBpL,CAAK,CAACsC,GAAN,CAAU,oBAAV,EACA3B,CAAY,CAACmJ,IAAb,EACH,CAHD,CAIH,CAbD,EAaGuB,IAbH,CAaQ,SAASC,CAAT,CAAgBC,CAAhB,CAA0BC,CAA1B,CAAqC,CAEzCxL,CAAK,CAACsC,GAAN,CAAUgJ,CAAV,EACAtL,CAAK,CAACsC,GAAN,CAAUiJ,CAAV,EACAvL,CAAK,CAACsC,GAAN,CAAUkJ,CAAV,CACH,CAlBD,CAmBH,CA5BE,CA8BV,CAj9BK,CAAN","sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * JS Canvas\n *\n * Tested in Moodle 3.9\n *\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n * @package local_commander\n * @copyright 2018 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* global fabric */\n/* eslint no-unused-expressions: \"off\", no-console:off, no-invalid-this:\"off\",no-script-url:\"off\", block-scoped-var: \"off\" */\ndefine(['jquery', 'core/notification'], function($, notification) {\n 'use strict';\n\n /**\n * Possible options\n * @type {{id: number, debugjs: boolean, hasHorizontalRuler: boolean, background: string}}\n */\n var opts = {\n id: 0,\n debugjs: false,\n hasHorizontalRuler: true,\n background: '',\n };\n\n /**\n * Set options base on listed options\n * @param {object} options\n */\n var setOptions = function(options) {\n \"use strict\";\n var key, vartype;\n for (key in opts) {\n if (opts.hasOwnProperty(key) && options.hasOwnProperty(key)) {\n\n // Casting to prevent errors.\n vartype = typeof opts[key];\n if (vartype === \"boolean\") {\n opts[key] = Boolean(options[key]);\n } else if (vartype === 'number') {\n opts[key] = Number(options[key]);\n } else if (vartype === 'string') {\n opts[key] = String(options[key]);\n }\n // Skip all other types.\n }\n }\n };\n\n /**\n * Console log debug wrapper.\n */\n var debug = {};\n\n /**\n * Local history/cache buffer\n * @type {number}\n */\n var bufferStep = 0;\n\n /**\n *\n * @type {number}\n */\n var bufferTimer = 0;\n\n /**\n * Should we store changes to localstorage\n * @type {boolean}\n */\n var bufferActive = true;\n\n /**\n * Set debug mode\n * Should only be enabled if site is in debug mode.\n * @param {boolean} isenabled\n */\n var setDebug = function(isenabled) {\n\n if (isenabled) {\n for (var m in console) {\n if (typeof console[m] == 'function') {\n debug[m] = console[m].bind(window.console);\n }\n }\n } else {\n // Fake wrapper.\n for (var i in console) {\n if (typeof console[i] == 'function') {\n debug[i] = function() {\n // Don't do anything.\n };\n }\n }\n }\n };\n\n /**\n * Canvas holder.\n * @type fabric.Canvas\n */\n var canvas = null;\n\n /**\n * Module canvas wrapper.\n */\n var canvasModule = {\n\n /**\n * @type int\n */\n canvasWidth: 800,\n\n /**\n * @type int\n */\n canvasHeight: 500,\n\n /**\n * Default rectangle.\n */\n defaultShaperect: {\n width: 70,\n height: 70,\n left: 200,\n top: 50,\n angle: 0,\n fill: '#ffb628'\n },\n\n /**\n * Default circle.\n */\n defaultShapecircle: {\n radius: 40,\n left: 200,\n top: 50,\n fill: '#b3cc2b'\n },\n\n /**\n * Default triangle.\n */\n defaultShapetriangle: {\n top: 50,\n left: 200,\n width: 70,\n height: 70,\n fill: '#0081b4'\n },\n\n /**\n * Default text.\n */\n defaultShapetextbox: {\n top: 50,\n left: 200,\n fill: '#0081b4'\n },\n\n /**\n * Load user there history.\n */\n loadHistory: function() {\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'load_history',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n if (response.success) {\n $('#history').html(response.html);\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n },\n\n /**\n * Save the current canvas.\n */\n saveCanvasAjax: function() {\n // Canvas to image.\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL\n if (!fabric.Canvas.supports('toDataURL')) {\n\n notification.addNotification({\n message: 'This browser doesn\\'t provide means to serialize canvas to an image',\n type: \"error\"\n });\n\n } else {\n\n // Send data to AJAX.\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'save_canvas',\n data: {\n 'id': opts.id,\n 'status': 'final',\n 'canvas_data': canvas.toDataURL({\n multiplier: 1,\n format: 'png'\n }),\n 'json_data': JSON.stringify(canvas)\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n notification.addNotification({\n message: M.util.get_string('javascript:updated', 'mod_gcanvas'),\n type: \"success\",\n });\n\n // Load attempts.\n canvasModule.loadHistory();\n\n } else {\n notification.addNotification({\n message: response.error,\n type: \"error\"\n });\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n }\n },\n\n /**\n * Trash selected canvas items.\n */\n deleteSelectedCanvasItems: function() {\n try {\n var activeobjects = canvas.getActiveObjects();\n if (activeobjects.length <= 0) {\n debug.log('Selection empty');\n return;\n }\n\n for (var i in activeobjects) {\n if (activeobjects.hasOwnProperty(i)) {\n var element = activeobjects[i];\n\n if (element.id !== undefined && element.id === 'ruler') {\n debug.log('Ruler: Not removable!');\n continue;\n }\n\n canvas.remove(element);\n }\n }\n\n canvas.discardActiveObject().renderAll();\n\n } catch (e) {\n debug.error('Nothing selected', e);\n }\n },\n\n /**\n * Dynamic method for selecting a shape.\n */\n loadDynamicToolbarMappingShapes: function() {\n\n $('#toolbar .icon[data-element-type]').on('click', function() {\n var el;\n var elementtype = $(this).data('element-type');\n\n try {\n canvas.discardActiveObject();\n } catch (e) {\n // If nothing is added to the canvas this gives a error.\n }\n\n var shape = \"defaultShape\" + elementtype.toLowerCase();\n debug.log(\"Search for shape: \" + shape);\n\n if (canvasModule.hasOwnProperty(shape)) {\n debug.log(\"Shape found\");\n\n if (elementtype === 'Textbox') {\n el = new fabric[elementtype]('DEMO', canvasModule[shape]);\n } else {\n el = new fabric[elementtype](canvasModule[shape]);\n }\n\n canvas.add(el);\n canvas.setActiveObject(el);\n } else {\n debug.error('Shape not found!');\n }\n\n canvas.renderAll();\n });\n },\n\n /**\n * Colorpicker used for changing the color of a shape.\n */\n loadColorPicker: function() {\n $(\"#colorpicker\").spectrum({\n showPalette: true,\n palette: [],\n showSelectionPalette: true,\n selectionPalette: [\"red\", \"green\", \"blue\", \"orange\"],\n flat: false,\n change: function(color) {\n debug.log('change color');\n canvasModule.setColor(color);\n }\n }).on(\"dragstart.spectrum , dragstop.spectrum\", function(e, color) {\n debug.log('change color - dragstop - dragstart');\n canvasModule.setColor(color);\n }\n );\n },\n\n /**\n * Using svg making sure it looks nice.\n *\n * @param {string} src\n */\n loadEmojiCsv: function(src) {\n debug.log('loadEmojiCsv : ', src);\n // Issue when using loadsvgfromurl.\n fabric.Image.fromURL(src.replace('.png', '.svg'), function(object) {\n // Logic below needed to work with the svg files.\n object.set({\n height: 500,\n width: 500,\n left: 150,\n top: 100,\n angle: 0,\n centerTransform: true\n }).scale(0.4).setCoords();\n canvas.add(object);\n canvas.setActiveObject(object);\n });\n },\n\n /**\n * Delete a attempt/sketch\n * TODO we could better use amd Ajax helper Moodle and external webservice, for now this is okay.\n *\n * @param {jQuery} $el\n */\n deleteAttempt: function($el) {\n debug.log('Delete', $el);\n notification.confirm(\n M.util.get_string('javascript:confirm_title', 'mod_gcanvas'),\n M.util.get_string('javascript:confirm_desc', 'mod_gcanvas'),\n M.util.get_string('javascript:yes', 'mod_gcanvas'),\n M.util.get_string('javascript:no', 'mod_gcanvas'), function() {\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'delete_attempt',\n data: {\n 'id': opts.id,\n 'attempt_id': $el.data('id'),\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n // Load attempts.\n canvasModule.loadHistory();\n\n } else {\n notification.addNotification({\n message: response.error,\n type: \"error\"\n });\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n });\n },\n\n /**\n * Restore a attempt/sketch\n *\n * @param {jQuery} $el\n */\n restoreAttempt: function($el) {\n debug.log('Restore', $el);\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'get_attempt',\n data: {\n 'id': opts.id,\n 'attempt_id': $el.data('id'),\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n bufferActive = false;\n\n canvas.loadFromJSON(response.record.json_data, canvas.renderAll.bind(canvas));\n\n setTimeout(function() {\n bufferActive = true;\n }, 1000);\n }\n }\n });\n },\n\n /**\n * Show the fileuploader.\n *\n * @param {string} filearea\n */\n showFileuploader: function(filearea) {\n $('#canvas-filepicker-form-' + filearea).toggle();\n },\n\n /**\n * Set background of the canvas.\n */\n setBackgroundImage: function() {\n\n if (opts.background !== '') {\n fabric.Image.fromURL(opts.background, function(img) {\n // Add background image.\n canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {\n scaleX: canvas.width / img.width,\n scaleY: canvas.height / img.height\n });\n });\n }\n },\n\n /**\n * Add user image.\n */\n addUserImage: function() {\n var formdata = {'id': opts.id},\n inputs = $('#canvas-filepicker-form-student_image form').serializeArray();\n\n $.each(inputs, function(i, input) {\n formdata[input.name] = input.value;\n });\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'upload_images',\n data: formdata\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n canvasModule.addImageFromUrl(response.image);\n }\n $('#canvas-filepicker-form-student_image').hide();\n }\n });\n },\n\n /**\n * Add image from url\n * TODO SVG support.\n * @param {string} path\n */\n addImageFromUrl: function(path) {\n\n fabric.Image.fromURL(path, function(object) {\n object.set({\n left: 150,\n top: 100,\n angle: 0,\n centerTransform: true\n }).setCoords();\n\n // Prevent to large objects.\n var maxwidth = canvas.getWidth() / 3;\n\n if (object.width > maxwidth) {\n object.scaleToWidth(maxwidth);\n }\n\n canvas.add(object);\n canvas.setActiveObject(object);\n });\n },\n\n /**\n * Select toolbar images.\n */\n selectToolbarImage: function() {\n var dialog = $('#image-picker');\n if (dialog.is(':visible')) {\n dialog.hide();\n return;\n }\n dialog.show();\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'get_toolbar_images',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n var html = '';\n\n dialog.html(html);\n }\n }\n });\n },\n\n /**\n * Undo 1 canvas step.\n */\n undo: function() {\n\n if (bufferStep === 0) {\n return;\n }\n try {\n var data = localStorage.getItem('buffer_' + bufferStep);\n canvas.loadFromJSON(data, canvas.renderAll.bind(canvas));\n\n localStorage.removeItem('buffer_' + bufferStep);\n\n bufferStep--;\n } catch (e) {\n debug.log(e);\n }\n },\n\n /**\n * Toolbar actions.\n */\n loadToolbar: function() {\n\n this.setBackgroundImage();\n\n // Most shapes will be placed on canvas by this function.\n this.loadDynamicToolbarMappingShapes();\n\n // Color picker.\n this.loadColorPicker();\n\n // Clear canvas items.\n $('#clear').on('click', function() {\n canvas.clear();\n\n if (opts.hasHorizontalRuler) {\n canvasModule.addHorizontalRuler();\n }\n\n canvasModule.setBackgroundImage();\n });\n\n // Arrow.\n $('#arrow i').on('click', function() {\n canvasModule.loadArrowToCanvas();\n });\n\n // Remove selected items.\n $('#trash i').on('click', function() {\n canvasModule.deleteSelectedCanvasItems();\n });\n\n // Load emoji picker.\n $('#smiley i').on('click', function() {\n canvasModule.loadEmojiPicker();\n });\n\n $('#undo').on('click', function() {\n bufferActive = false;\n canvasModule.undo();\n\n setTimeout(function() {\n bufferActive = true;\n }, 500);\n });\n\n // Add own image to the canvas.\n $('#add-image i').on('click', function() {\n canvasModule.showFileuploader('student_image');\n });\n\n // Student selecting a image, added to the toolbar by teachers.\n $('#select-a-image i').on('click', function() {\n canvasModule.selectToolbarImage();\n });\n\n $('#image-picker ').on('click', 'img', function() {\n canvasModule.addImageFromUrl($(this).attr('src'));\n $('#image-picker').hide();\n });\n\n $('#save-canvas').on('click', function() {\n canvasModule.saveCanvasAjax();\n });\n\n $('#show-help').on('click', function() {\n $('#dialog-help').show();\n });\n\n $('#dialog-help').on('click', function() {\n $('#dialog-help').hide();\n });\n\n $('#history').on('click', '.delete', function(e) {\n e.preventDefault();\n canvasModule.deleteAttempt($(this));\n\n }).on('click', '.restore', function(e) {\n\n e.preventDefault();\n canvasModule.restoreAttempt($(this));\n\n });\n\n // Dialog to selected a emoji.\n $('#emoji-picker').on('click', 'img', function() {\n canvasModule.loadEmojiCsv($(this).attr('src'));\n $('#emoji-picker').hide();\n });\n\n // Teacher background.\n $('#change_background').on('click', function() {\n canvasModule.showFileuploader('background');\n });\n\n // Teacher image.\n $('#add_toolbar_images').on('click', function() {\n canvasModule.showFileuploader('toolbar_shape');\n });\n\n $('#canvas-filepicker-form-student_image').on('click', '#id_submitbutton', function(e) {\n e.preventDefault();\n\n // Form should be posted to AJAX call so we can get the image.\n canvasModule.addUserImage();\n });\n\n // Hide pressing on cancel.\n $('.dialog').on('click', '.btn-secondary', function(e) {\n e.preventDefault();\n debug.log('Cancel');\n $('.dialog').hide();\n });\n },\n\n /**\n * Emoji dialog\n */\n loadEmojiPicker: function() {\n var $picker = $('#emoji-picker');\n if ($picker.html() !== '') {\n debug.log('Toggle emoji');\n $picker.toggle();\n return;\n }\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'emoji',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n $picker.html(response.html).show();\n }\n }\n });\n },\n\n /**\n * Load the arrow icon to the canvas.\n */\n loadArrowToCanvas: function() {\n fabric.loadSVGFromURL('pix/arrow.svg', function(objects, options) {\n var obj = fabric.util.groupSVGElements(objects, options);\n canvas.add(obj.scale(0.1)).centerObject(obj).renderAll();\n obj.setCoords();\n canvas.setActiveObject(obj);\n });\n },\n\n /**\n * Set active element colors.\n * @param {object} color\n */\n setColor: function(color) {\n\n var colorhex = color.toHexString(); // #ff0000\n var activeobjects = canvas.getActiveObjects();\n if (activeobjects) {\n\n for (var i in activeobjects) {\n if (activeobjects.hasOwnProperty(i)) {\n var element = activeobjects[i];\n\n if (element.hasOwnProperty('id') && element.id === 'ruler') {\n continue;\n }\n\n element.set(\"fill\", colorhex);\n }\n }\n\n canvas.renderAll();\n } else {\n debug.log('No active items');\n }\n },\n\n /**\n * Don't allow going out of canvas.\n */\n preventMovingOutOfCanvas: function() {\n canvas.on('object:moving', function(e) {\n var obj = e.target;\n // If object is too big ignore.\n if (obj.currentHeight > obj.canvas.height || obj.currentWidth > obj.canvas.width) {\n return;\n }\n obj.setCoords();\n\n if (obj.getBoundingRect().top < 0 || obj.getBoundingRect().left < 0) {\n obj.top = Math.max(obj.top, obj.top - obj.getBoundingRect().top);\n obj.left = Math.max(obj.left, obj.left - obj.getBoundingRect().left);\n }\n\n if (obj.getBoundingRect().top + obj.getBoundingRect().height > obj.canvas.height ||\n obj.getBoundingRect().left + obj.getBoundingRect().width > obj.canvas.width) {\n obj.top = Math.min(obj.top, obj.canvas.height - obj.getBoundingRect().height + obj.top -\n obj.getBoundingRect().top);\n obj.left = Math.min(obj.left, obj.canvas.width - obj.getBoundingRect().width + obj.left -\n obj.getBoundingRect().left);\n }\n });\n },\n\n /**\n * Trigger for extra keyboard commands.\n */\n keyboardActions: function() {\n $(document).keydown(function(e) {\n debug.log('keypress', e.which);\n switch (e.which) {\n case 46:\n canvasModule.deleteSelectedCanvasItems();\n break;\n }\n });\n },\n\n /**\n * Start this module.\n */\n init: function() {\n\n // Load canvas.\n this.__canvas = canvas = new fabric.Canvas('sketch');\n\n // Prevent right click.\n $('body').on('contextmenu', 'canvas , img', function() {\n return false;\n });\n\n // Dimensions.\n canvas.setHeight(this.canvasHeight);\n canvas.setWidth(this.canvasWidth - 70);\n\n // Catch some actions.\n canvas.on({\n 'selection:created': this.onchange,\n 'selection:updated': this.onchange,\n\n // 'object:moving' : this.add_to_history,\n 'object:added': this.addToCache,\n 'object:removed': this.addToCache,\n 'object:modified': this.addToCache,\n });\n\n // Make sure we start with a empty storage.\n localStorage.clear();\n\n this.preventMovingOutOfCanvas();\n\n this.loadToolbar();\n\n if (opts.hasHorizontalRuler) {\n this.addHorizontalRuler();\n }\n\n this.loadHistory();\n\n this.keyboardActions();\n },\n\n /**\n * Keep a history/cache buffer.\n */\n addToCache: function() {\n debug.log('history');\n canvasModule.addCanvasToCacheBuffer();\n },\n\n /**\n * Add canvas to local storage.\n */\n addCanvasToCacheBuffer: function() {\n // When undo there lot of modified events we doesnt want to trigger if thats the case.\n if (!bufferActive) {\n return;\n }\n\n clearTimeout(bufferTimer);\n setTimeout(function() {\n try {\n bufferStep++;\n localStorage.setItem('buffer_' + bufferStep, JSON.stringify(canvas));\n } catch (e) {\n debug.log(e);\n }\n }, 500);\n },\n\n /**\n * Horizontal ruler.\n */\n addHorizontalRuler: function() {\n var ruler = new fabric.Rect({\n width: this.canvasWidth,\n height: 2,\n id: 'ruler',\n left: 0,\n top: 410,\n angle: 0,\n fill: '#8b58a1'\n });\n\n ruler.flipY = false;\n ruler.lockMovementX = true;\n ruler.lockScalingX = true;\n ruler.lockScalingY = true;\n ruler.lockUniScaling = true;\n ruler.lockRotation = true;\n\n canvas.add(ruler);\n canvas.renderAll();\n\n // Keyboard arrows move ruler.\n $(document).keydown(function(e) {\n switch (e.which) {\n\n case 38: // Up arrow.\n ruler.top = ruler.top - 10;\n canvas.renderAll();\n break;\n\n case 40: // Down arrow.\n ruler.top = ruler.top + 10;\n canvas.renderAll();\n\n break;\n\n default:\n return; // Exit this handler for other keys.\n }\n e.preventDefault(); // Prevent the default action (scroll / move caret).\n });\n },\n\n /**\n * Trigger on canvas element actions.\n * @param {object} options\n */\n onchange: function(options) {\n if (options.target.hasOwnProperty('id') && options.target.id === 'ruler') {\n return;\n }\n\n $(\"#colorpicker\").spectrum(\"set\", options.target.fill);\n }\n };\n\n return {\n\n /**\n * Init\n * @param {object} args\n */\n initialise: function(args) {\n\n // Load spectrum javascript form here.\n $.getScript(M.cfg.wwwroot + \"/mod/gcanvas/javascript/spectrum.js\").done(function() {\n\n // Load the args passed from PHP.\n setOptions(args);\n\n // Set internal debug console.\n setDebug(opts.debugjs);\n\n $.noConflict();\n $(document).ready(function() {\n debug.log('Canvas Module v1.2');\n canvasModule.init();\n });\n }).fail(function(jqxhr, settings, exception) {\n // Display loading issue in console.\n debug.log(jqxhr);\n debug.log(settings);\n debug.log(exception);\n });\n }\n };\n});"],"file":"canvas.min.js"} \ No newline at end of file +{"version":3,"file":"canvas.min.js","sources":["../src/canvas.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see .\n\n/**\n * JS Canvas\n *\n * Tested in Moodle 3.9\n *\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n *\n * @copyright 2018 MFreak.nl\n * @author Luuk Verhoeven\n **/\n/* global fabric */\n/* eslint no-unused-expressions: \"off\", no-console:off, no-invalid-this:\"off\",no-script-url:\"off\", block-scoped-var: \"off\" */\ndefine(['jquery', 'core/notification'], function($, notification) {\n 'use strict';\n\n /**\n * Possible options\n * @type {{id: number, debugjs: boolean, hasHorizontalRuler: boolean, background: string}}\n */\n var opts = {\n id: 0,\n debugjs: false,\n hasHorizontalRuler: true,\n background: '',\n };\n\n /**\n * Set options base on listed options\n * @param {object} options\n */\n var setOptions = function(options) {\n \"use strict\";\n var key, vartype;\n for (key in opts) {\n if (opts.hasOwnProperty(key) && options.hasOwnProperty(key)) {\n\n // Casting to prevent errors.\n vartype = typeof opts[key];\n if (vartype === \"boolean\") {\n opts[key] = Boolean(options[key]);\n } else if (vartype === 'number') {\n opts[key] = Number(options[key]);\n } else if (vartype === 'string') {\n opts[key] = String(options[key]);\n }\n // Skip all other types.\n }\n }\n };\n\n /**\n * Console log debug wrapper.\n */\n var debug = {};\n\n /**\n * Local history/cache buffer\n * @type {number}\n */\n var bufferStep = 0;\n\n /**\n *\n * @type {number}\n */\n var bufferTimer = 0;\n\n /**\n * Should we store changes to localstorage\n * @type {boolean}\n */\n var bufferActive = true;\n\n /**\n * Set debug mode\n * Should only be enabled if site is in debug mode.\n * @param {boolean} isenabled\n */\n var setDebug = function(isenabled) {\n\n if (isenabled) {\n for (var m in console) {\n if (typeof console[m] == 'function') {\n debug[m] = console[m].bind(window.console);\n }\n }\n } else {\n // Fake wrapper.\n for (var i in console) {\n if (typeof console[i] == 'function') {\n debug[i] = function() {\n // Don't do anything.\n };\n }\n }\n }\n };\n\n /**\n * Canvas holder.\n * @type fabric.Canvas\n */\n var canvas = null;\n\n /**\n * Module canvas wrapper.\n */\n var canvasModule = {\n\n /**\n * @type int\n */\n canvasWidth: 800,\n\n /**\n * @type int\n */\n canvasHeight: 500,\n\n /**\n * Default rectangle.\n */\n defaultShaperect: {\n width: 70,\n height: 70,\n left: 200,\n top: 50,\n angle: 0,\n fill: '#ffb628'\n },\n\n /**\n * Default circle.\n */\n defaultShapecircle: {\n radius: 40,\n left: 200,\n top: 50,\n fill: '#b3cc2b'\n },\n\n /**\n * Default triangle.\n */\n defaultShapetriangle: {\n top: 50,\n left: 200,\n width: 70,\n height: 70,\n fill: '#0081b4'\n },\n\n /**\n * Default text.\n */\n defaultShapetextbox: {\n top: 50,\n left: 200,\n fill: '#0081b4'\n },\n\n /**\n * Load user there history.\n */\n loadHistory: function() {\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'load_history',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n if (response.success) {\n $('#history').html(response.html);\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n },\n\n /**\n * Save the current canvas.\n */\n saveCanvasAjax: function() {\n // Canvas to image.\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL\n if (!fabric.Canvas.supports('toDataURL')) {\n\n notification.addNotification({\n message: 'This browser doesn\\'t provide means to serialize canvas to an image',\n type: \"error\"\n });\n\n } else {\n\n // Send data to AJAX.\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'save_canvas',\n data: {\n 'id': opts.id,\n 'status': 'final',\n 'canvas_data': canvas.toDataURL({\n multiplier: 1,\n format: 'png'\n }),\n 'json_data': JSON.stringify(canvas)\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n notification.addNotification({\n message: M.util.get_string('javascript:updated', 'mod_gcanvas'),\n type: \"success\",\n });\n\n // Load attempts.\n canvasModule.loadHistory();\n\n } else {\n notification.addNotification({\n message: response.error,\n type: \"error\"\n });\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n }\n },\n\n /**\n * Trash selected canvas items.\n */\n deleteSelectedCanvasItems: function() {\n try {\n var activeobjects = canvas.getActiveObjects();\n if (activeobjects.length <= 0) {\n debug.log('Selection empty');\n return;\n }\n\n for (var i in activeobjects) {\n if (activeobjects.hasOwnProperty(i)) {\n var element = activeobjects[i];\n\n if (element.id !== undefined && element.id === 'ruler') {\n debug.log('Ruler: Not removable!');\n continue;\n }\n\n canvas.remove(element);\n }\n }\n\n canvas.discardActiveObject().renderAll();\n\n } catch (e) {\n debug.error('Nothing selected', e);\n }\n },\n\n /**\n * Dynamic method for selecting a shape.\n */\n loadDynamicToolbarMappingShapes: function() {\n\n $('#toolbar .icon[data-element-type]').on('click', function() {\n var el;\n var elementtype = $(this).data('element-type');\n\n try {\n canvas.discardActiveObject();\n } catch (e) {\n // If nothing is added to the canvas this gives a error.\n }\n\n var shape = \"defaultShape\" + elementtype.toLowerCase();\n debug.log(\"Search for shape: \" + shape);\n\n if (canvasModule.hasOwnProperty(shape)) {\n debug.log(\"Shape found\");\n\n if (elementtype === 'Textbox') {\n el = new fabric[elementtype]('DEMO', canvasModule[shape]);\n } else {\n el = new fabric[elementtype](canvasModule[shape]);\n }\n\n canvas.add(el);\n canvas.setActiveObject(el);\n } else {\n debug.error('Shape not found!');\n }\n\n canvas.renderAll();\n });\n },\n\n /**\n * Colorpicker used for changing the color of a shape.\n */\n loadColorPicker: function() {\n $(\"#colorpicker\").spectrum({\n showPalette: true,\n palette: [],\n showSelectionPalette: true,\n selectionPalette: [\"red\", \"green\", \"blue\", \"orange\"],\n flat: false,\n change: function(color) {\n debug.log('change color');\n canvasModule.setColor(color);\n }\n }).on(\"dragstart.spectrum , dragstop.spectrum\", function(e, color) {\n debug.log('change color - dragstop - dragstart');\n canvasModule.setColor(color);\n }\n );\n },\n\n /**\n * Using svg making sure it looks nice.\n *\n * @param {string} src\n */\n loadEmojiCsv: function(src) {\n debug.log('loadEmojiCsv : ', src);\n // Issue when using loadsvgfromurl.\n fabric.Image.fromURL(src.replace('.png', '.svg'), function(object) {\n // Logic below needed to work with the svg files.\n object.set({\n height: 500,\n width: 500,\n left: 150,\n top: 100,\n angle: 0,\n centerTransform: true\n }).scale(0.4).setCoords();\n canvas.add(object);\n canvas.setActiveObject(object);\n });\n },\n\n /**\n * Delete a attempt/sketch\n * TODO we could better use amd Ajax helper Moodle and external webservice, for now this is okay.\n *\n * @param {jQuery} $el\n */\n deleteAttempt: function($el) {\n debug.log('Delete', $el);\n notification.confirm(\n M.util.get_string('javascript:confirm_title', 'mod_gcanvas'),\n M.util.get_string('javascript:confirm_desc', 'mod_gcanvas'),\n M.util.get_string('javascript:yes', 'mod_gcanvas'),\n M.util.get_string('javascript:no', 'mod_gcanvas'), function() {\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'delete_attempt',\n data: {\n 'id': opts.id,\n 'attempt_id': $el.data('id'),\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n // Load attempts.\n canvasModule.loadHistory();\n\n } else {\n notification.addNotification({\n message: response.error,\n type: \"error\"\n });\n }\n },\n error: function(response) {\n debug.error(response.responseText);\n // Show a error messages.\n notification.addNotification({\n message: response.responseText,\n type: \"error\"\n });\n }\n });\n });\n },\n\n /**\n * Restore a attempt/sketch\n *\n * @param {jQuery} $el\n */\n restoreAttempt: function($el) {\n debug.log('Restore', $el);\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'get_attempt',\n data: {\n 'id': opts.id,\n 'attempt_id': $el.data('id'),\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n bufferActive = false;\n\n canvas.loadFromJSON(response.record.json_data, canvas.renderAll.bind(canvas));\n\n setTimeout(function() {\n bufferActive = true;\n }, 1000);\n }\n }\n });\n },\n\n /**\n * Show the fileuploader.\n *\n * @param {string} filearea\n */\n showFileuploader: function(filearea) {\n $('#canvas-filepicker-form-' + filearea).toggle();\n },\n\n /**\n * Set background of the canvas.\n */\n setBackgroundImage: function() {\n\n if (opts.background !== '' && opts.background !== 'false') {\n fabric.Image.fromURL(opts.background, function(img) {\n // Add background image.\n canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {\n scaleX: canvas.width / img.width,\n scaleY: canvas.height / img.height\n });\n });\n }\n },\n\n /**\n * Add user image.\n */\n addUserImage: function() {\n var formdata = {'id': opts.id},\n inputs = $('#canvas-filepicker-form-student_image form').serializeArray();\n\n $.each(inputs, function(i, input) {\n formdata[input.name] = input.value;\n });\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'upload_images',\n data: formdata\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n canvasModule.addImageFromUrl(response.image);\n }\n $('#canvas-filepicker-form-student_image').hide();\n }\n });\n },\n\n /**\n * Add image from url\n * TODO SVG support.\n * @param {string} path\n */\n addImageFromUrl: function(path) {\n\n fabric.Image.fromURL(path, function(object) {\n object.set({\n left: 150,\n top: 100,\n angle: 0,\n centerTransform: true\n }).setCoords();\n\n // Prevent to large objects.\n var maxwidth = canvas.getWidth() / 3;\n\n if (object.width > maxwidth) {\n object.scaleToWidth(maxwidth);\n }\n\n canvas.add(object);\n canvas.setActiveObject(object);\n });\n },\n\n /**\n * Select toolbar images.\n */\n selectToolbarImage: function() {\n var dialog = $('#image-picker');\n if (dialog.is(':visible')) {\n dialog.hide();\n return;\n }\n dialog.show();\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'get_toolbar_images',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n var html = '';\n\n dialog.html(html);\n }\n }\n });\n },\n\n /**\n * Undo 1 canvas step.\n */\n undo: function() {\n\n if (bufferStep === 0) {\n return;\n }\n try {\n var data = localStorage.getItem('buffer_' + bufferStep);\n canvas.loadFromJSON(data, canvas.renderAll.bind(canvas));\n\n localStorage.removeItem('buffer_' + bufferStep);\n\n bufferStep--;\n } catch (e) {\n debug.log(e);\n }\n },\n\n /**\n * Toolbar actions.\n */\n loadToolbar: function() {\n\n this.setBackgroundImage();\n\n // Most shapes will be placed on canvas by this function.\n this.loadDynamicToolbarMappingShapes();\n\n // Color picker.\n this.loadColorPicker();\n\n // Clear canvas items.\n $('#clear').on('click', function() {\n canvas.clear();\n\n if (opts.hasHorizontalRuler) {\n canvasModule.addHorizontalRuler();\n }\n\n canvasModule.setBackgroundImage();\n });\n\n // Arrow.\n $('#arrow i').on('click', function() {\n canvasModule.loadArrowToCanvas();\n });\n\n // Remove selected items.\n $('#trash i').on('click', function() {\n canvasModule.deleteSelectedCanvasItems();\n });\n\n // Load emoji picker.\n $('#smiley i').on('click', function() {\n canvasModule.loadEmojiPicker();\n });\n\n $('#undo').on('click', function() {\n bufferActive = false;\n canvasModule.undo();\n\n setTimeout(function() {\n bufferActive = true;\n }, 500);\n });\n\n // Add own image to the canvas.\n $('#add-image i').on('click', function() {\n canvasModule.showFileuploader('student_image');\n });\n\n // Student selecting a image, added to the toolbar by teachers.\n $('#select-a-image i').on('click', function() {\n canvasModule.selectToolbarImage();\n });\n\n $('#image-picker ').on('click', 'img', function() {\n canvasModule.addImageFromUrl($(this).attr('src'));\n $('#image-picker').hide();\n });\n\n $('#save-canvas').on('click', function() {\n canvasModule.saveCanvasAjax();\n });\n\n $('#show-help').on('click', function() {\n $('#dialog-help').show();\n });\n\n $('#dialog-help').on('click', function() {\n $('#dialog-help').hide();\n });\n\n $('#history').on('click', '.delete', function(e) {\n e.preventDefault();\n canvasModule.deleteAttempt($(this));\n\n }).on('click', '.restore', function(e) {\n\n e.preventDefault();\n canvasModule.restoreAttempt($(this));\n\n });\n\n // Dialog to selected a emoji.\n $('#emoji-picker').on('click', 'img', function() {\n canvasModule.loadEmojiCsv($(this).attr('src'));\n $('#emoji-picker').hide();\n });\n\n // Teacher background.\n $('#change_background').on('click', function() {\n canvasModule.showFileuploader('background');\n });\n\n // Teacher image.\n $('#add_toolbar_images').on('click', function() {\n canvasModule.showFileuploader('toolbar_shape');\n });\n\n $('#canvas-filepicker-form-student_image').on('click', '#id_submitbutton', function(e) {\n e.preventDefault();\n\n // Form should be posted to AJAX call so we can get the image.\n canvasModule.addUserImage();\n });\n\n // Hide pressing on cancel.\n $('.dialog').on('click', '.btn-secondary', function(e) {\n e.preventDefault();\n debug.log('Cancel');\n $('.dialog').hide();\n });\n },\n\n /**\n * Emoji dialog\n */\n loadEmojiPicker: function() {\n var $picker = $('#emoji-picker');\n if ($picker.html() !== '') {\n debug.log('Toggle emoji');\n $picker.toggle();\n return;\n }\n\n $.ajax({\n type: 'POST',\n url: M.cfg.wwwroot + '/mod/gcanvas/ajax.php',\n data: {\n sesskey: M.cfg.sesskey,\n action: 'emoji',\n data: {\n 'id': opts.id,\n }\n },\n dataType: \"json\",\n success: function(response) {\n debug.log(response);\n\n if (response.success) {\n $picker.html(response.html).show();\n }\n }\n });\n },\n\n /**\n * Load the arrow icon to the canvas.\n */\n loadArrowToCanvas: function() {\n fabric.loadSVGFromURL('pix/arrow.svg', function(objects, options) {\n var obj = fabric.util.groupSVGElements(objects, options);\n canvas.add(obj.scale(0.1)).centerObject(obj).renderAll();\n obj.setCoords();\n canvas.setActiveObject(obj);\n });\n },\n\n /**\n * Set active element colors.\n * @param {object} color\n */\n setColor: function(color) {\n\n var colorhex = color.toHexString(); // #ff0000\n var activeobjects = canvas.getActiveObjects();\n if (activeobjects) {\n\n for (var i in activeobjects) {\n if (activeobjects.hasOwnProperty(i)) {\n var element = activeobjects[i];\n\n if (element.hasOwnProperty('id') && element.id === 'ruler') {\n continue;\n }\n\n element.set(\"fill\", colorhex);\n }\n }\n\n canvas.renderAll();\n } else {\n debug.log('No active items');\n }\n },\n\n /**\n * Don't allow going out of canvas.\n */\n preventMovingOutOfCanvas: function() {\n canvas.on('object:moving', function(e) {\n var obj = e.target;\n // If object is too big ignore.\n if (obj.currentHeight > obj.canvas.height || obj.currentWidth > obj.canvas.width) {\n return;\n }\n obj.setCoords();\n\n if (obj.getBoundingRect().top < 0 || obj.getBoundingRect().left < 0) {\n obj.top = Math.max(obj.top, obj.top - obj.getBoundingRect().top);\n obj.left = Math.max(obj.left, obj.left - obj.getBoundingRect().left);\n }\n\n if (obj.getBoundingRect().top + obj.getBoundingRect().height > obj.canvas.height ||\n obj.getBoundingRect().left + obj.getBoundingRect().width > obj.canvas.width) {\n obj.top = Math.min(obj.top, obj.canvas.height - obj.getBoundingRect().height + obj.top -\n obj.getBoundingRect().top);\n obj.left = Math.min(obj.left, obj.canvas.width - obj.getBoundingRect().width + obj.left -\n obj.getBoundingRect().left);\n }\n });\n },\n\n /**\n * Trigger for extra keyboard commands.\n */\n keyboardActions: function() {\n $(document).keydown(function(e) {\n debug.log('keypress', e.which);\n switch (e.which) {\n case 46:\n canvasModule.deleteSelectedCanvasItems();\n break;\n }\n });\n },\n\n /**\n * Start this module.\n */\n init: function() {\n\n // Load canvas.\n this.__canvas = canvas = new fabric.Canvas('sketch');\n\n // Prevent right click.\n $('body').on('contextmenu', 'canvas , img', function() {\n return false;\n });\n\n // Dimensions.\n canvas.setHeight(this.canvasHeight);\n canvas.setWidth(this.canvasWidth - 70);\n\n // Catch some actions.\n canvas.on({\n 'selection:created': this.onchange,\n 'selection:updated': this.onchange,\n\n // 'object:moving' : this.add_to_history,\n 'object:added': this.addToCache,\n 'object:removed': this.addToCache,\n 'object:modified': this.addToCache,\n });\n\n // Make sure we start with a empty storage.\n localStorage.clear();\n\n this.preventMovingOutOfCanvas();\n\n this.loadToolbar();\n\n if (opts.hasHorizontalRuler) {\n this.addHorizontalRuler();\n }\n\n this.loadHistory();\n\n this.keyboardActions();\n },\n\n /**\n * Keep a history/cache buffer.\n */\n addToCache: function() {\n debug.log('history');\n canvasModule.addCanvasToCacheBuffer();\n },\n\n /**\n * Add canvas to local storage.\n */\n addCanvasToCacheBuffer: function() {\n // When undo there lot of modified events we doesnt want to trigger if thats the case.\n if (!bufferActive) {\n return;\n }\n\n clearTimeout(bufferTimer);\n setTimeout(function() {\n try {\n bufferStep++;\n localStorage.setItem('buffer_' + bufferStep, JSON.stringify(canvas));\n } catch (e) {\n debug.log(e);\n }\n }, 500);\n },\n\n /**\n * Horizontal ruler.\n */\n addHorizontalRuler: function() {\n var ruler = new fabric.Rect({\n width: this.canvasWidth,\n height: 2,\n id: 'ruler',\n left: 0,\n top: 410,\n angle: 0,\n fill: '#8b58a1'\n });\n\n ruler.flipY = false;\n ruler.lockMovementX = true;\n ruler.lockScalingX = true;\n ruler.lockScalingY = true;\n ruler.lockUniScaling = true;\n ruler.lockRotation = true;\n\n canvas.add(ruler);\n canvas.renderAll();\n\n // Keyboard arrows move ruler.\n $(document).keydown(function(e) {\n switch (e.which) {\n\n case 38: // Up arrow.\n ruler.top = ruler.top - 10;\n canvas.renderAll();\n break;\n\n case 40: // Down arrow.\n ruler.top = ruler.top + 10;\n canvas.renderAll();\n\n break;\n\n default:\n return; // Exit this handler for other keys.\n }\n e.preventDefault(); // Prevent the default action (scroll / move caret).\n });\n },\n\n /**\n * Trigger on canvas element actions.\n * @param {object} options\n */\n onchange: function(options) {\n if (options.target.hasOwnProperty('id') && options.target.id === 'ruler') {\n return;\n }\n\n $(\"#colorpicker\").spectrum(\"set\", options.target.fill);\n }\n };\n\n return {\n\n /**\n * Init\n * @param {object} args\n */\n initialise: function(args) {\n\n // Load spectrum javascript form here.\n $.getScript(M.cfg.wwwroot + \"/mod/gcanvas/javascript/spectrum.js\").done(function() {\n\n // Load the args passed from PHP.\n setOptions(args);\n\n // Set internal debug console.\n setDebug(opts.debugjs);\n\n $.noConflict();\n $(document).ready(function() {\n debug.log('Canvas Module v1.2');\n canvasModule.init();\n });\n }).fail(function(jqxhr, settings, exception) {\n // Display loading issue in console.\n debug.log(jqxhr);\n debug.log(settings);\n debug.log(exception);\n });\n }\n };\n});\n"],"names":["define","$","notification","opts","id","debugjs","hasHorizontalRuler","background","debug","bufferStep","bufferActive","canvas","canvasModule","canvasWidth","canvasHeight","defaultShaperect","width","height","left","top","angle","fill","defaultShapecircle","radius","defaultShapetriangle","defaultShapetextbox","loadHistory","ajax","type","url","M","cfg","wwwroot","data","sesskey","action","dataType","success","response","log","html","error","responseText","addNotification","message","saveCanvasAjax","fabric","Canvas","supports","toDataURL","multiplier","format","JSON","stringify","util","get_string","deleteSelectedCanvasItems","activeobjects","getActiveObjects","length","i","hasOwnProperty","element","undefined","remove","discardActiveObject","renderAll","e","loadDynamicToolbarMappingShapes","on","el","elementtype","this","shape","toLowerCase","add","setActiveObject","loadColorPicker","spectrum","showPalette","palette","showSelectionPalette","selectionPalette","flat","change","color","setColor","loadEmojiCsv","src","Image","fromURL","replace","object","set","centerTransform","scale","setCoords","deleteAttempt","$el","confirm","restoreAttempt","loadFromJSON","record","json_data","bind","setTimeout","showFileuploader","filearea","toggle","setBackgroundImage","img","scaleX","scaleY","addUserImage","formdata","inputs","serializeArray","each","input","name","value","addImageFromUrl","image","hide","path","maxwidth","getWidth","scaleToWidth","selectToolbarImage","dialog","is","show","images","undo","localStorage","getItem","removeItem","loadToolbar","clear","addHorizontalRuler","loadArrowToCanvas","loadEmojiPicker","attr","preventDefault","$picker","loadSVGFromURL","objects","options","obj","groupSVGElements","centerObject","colorhex","toHexString","preventMovingOutOfCanvas","target","currentHeight","currentWidth","getBoundingRect","Math","max","min","keyboardActions","document","keydown","which","init","__canvas","setHeight","setWidth","onchange","addToCache","addCanvasToCacheBuffer","clearTimeout","setItem","ruler","Rect","flipY","lockMovementX","lockScalingX","lockScalingY","lockUniScaling","lockRotation","initialise","args","getScript","done","key","vartype","Boolean","Number","String","setOptions","isenabled","m","console","window","setDebug","noConflict","ready","fail","jqxhr","settings","exception"],"mappings":";;;;;;;;;;AA2BAA,4BAAO,CAAC,SAAU,sBAAsB,SAASC,EAAGC,kBAO5CC,KAAO,CACPC,GAAI,EACJC,SAAS,EACTC,oBAAoB,EACpBC,WAAY,IA8BZC,MAAQ,GAMRC,WAAa,EAYbC,cAAe,EA+BfC,OAAS,KAKTC,aAAe,CAKfC,YAAa,IAKbC,aAAc,IAKdC,iBAAkB,CACdC,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