Skip to content

Commit

Permalink
Fix #7 solve loading spectrum M.cfg.wwwroot
Browse files Browse the repository at this point in the history
Also optimize some code styling
  • Loading branch information
luukverhoeven committed May 13, 2019
1 parent 29f687c commit 7e80562
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion amd/build/canvas.min.js

Large diffs are not rendered by default.

49 changes: 26 additions & 23 deletions amd/src/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
* @author Luuk Verhoeven
**/
/* global fabric */
/* eslint no-unused-expressions: "off", no-console:off, no-invalid-this:"off",no-script-url:"off" */

/* eslint no-unused-expressions: "off", no-console:off, no-invalid-this:"off",no-script-url:"off", block-scoped-var: "off" */
define(['jquery', 'core/notification'], function($, notification) {
'use strict';

Expand Down Expand Up @@ -106,6 +105,7 @@ define(['jquery', 'core/notification'], function($, notification) {
for (var m in console) {
if (typeof console[m] == 'function') {
debug[m] = function() {
// Don't do anything.
};
}
}
Expand Down Expand Up @@ -136,7 +136,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Default rectangle.
*/
default_shape_rect: {
defaultShaperect: {
width: 70,
height: 70,
left: 200,
Expand All @@ -148,7 +148,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Default circle.
*/
default_shape_circle: {
defaultShapecircle: {
radius: 40,
left: 200,
top: 50,
Expand All @@ -158,7 +158,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Default triangle.
*/
default_shape_triangle: {
defaultShapetriangle: {
top: 50,
left: 200,
width: 70,
Expand All @@ -169,7 +169,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Default text.
*/
default_shape_textbox: {
defaultShapetextbox: {
top: 50,
left: 200,
fill: '#0081b4'
Expand Down Expand Up @@ -317,7 +317,7 @@ define(['jquery', 'core/notification'], function($, notification) {
// If nothing is added to the canvas this gives a error.
}

var shape = "default_shape_" + elementtype.toLowerCase();
var shape = "defaultShape" + elementtype.toLowerCase();
debug.log("Search for shape: " + shape);

if (canvasModule.hasOwnProperty(shape)) {
Expand Down Expand Up @@ -363,7 +363,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Using svg making sure it looks nice.
*
* @param src
* @param {string} src
*/
loadEmojiCsv: function(src) {
debug.log('loadEmojiCsv : ', src);
Expand All @@ -385,12 +385,11 @@ define(['jquery', 'core/notification'], function($, notification) {

/**
* Delete a attempt/sketch
* TODO we could better use amd Ajax helper Moodle and external webservice, for now this is okay.
*
* @param {jQuery} $el
*/
deleteAttempt: function($el) {
//TODO we could better use amd Ajax helper Moodle and external webservice, for now this is okay.

debug.log('Delete', $el);
notification.confirm(
M.util.get_string('javascript:confirm_title', 'mod_gcanvas'),
Expand Down Expand Up @@ -474,7 +473,7 @@ define(['jquery', 'core/notification'], function($, notification) {
/**
* Show the fileuploader.
*
* @param filearea
* @param {string} filearea
*/
showFileuploader: function(filearea) {
$('#canvas-filepicker-form-' + filearea).toggle();
Expand All @@ -487,7 +486,7 @@ define(['jquery', 'core/notification'], function($, notification) {

if (opts.background !== '') {
fabric.Image.fromURL(opts.background, function(img) {
// add background image
// Add background image.
canvas.setBackgroundImage(img, canvas.renderAll.bind(canvas), {
scaleX: canvas.width / img.width,
scaleY: canvas.height / img.height
Expand All @@ -497,11 +496,10 @@ define(['jquery', 'core/notification'], function($, notification) {
},

/**
* addUserImage
* Add user image.
*/
addUserImage: function() {
var formdata = {'id': opts.id,};
var inputs = $('#canvas-filepicker-form-student_image form').serializeArray();
var formdata = {'id': opts.id}, inputs = $('#canvas-filepicker-form-student_image form').serializeArray();

$.each(inputs, function(i, input) {
formdata[input.name] = input.value;
Expand All @@ -528,12 +526,12 @@ define(['jquery', 'core/notification'], function($, notification) {
},

/**
* addImageFromUrl
* Add image from url
* TODO SVG support.
* @param {string} path
*/
addImageFromUrl: function(path) {

// TODO SVG support.
fabric.Image.fromURL(path, function(object) {
object.set({
left: 150,
Expand All @@ -555,7 +553,7 @@ define(['jquery', 'core/notification'], function($, notification) {
},

/**
* selectToolbarImage
* Select toolbar images.
*/
selectToolbarImage: function() {
var dialog = $('#image-picker');
Expand Down Expand Up @@ -594,7 +592,7 @@ define(['jquery', 'core/notification'], function($, notification) {
},

/**
* Undo 1 canvas step
* Undo 1 canvas step.
*/
undo: function() {

Expand Down Expand Up @@ -966,7 +964,7 @@ define(['jquery', 'core/notification'], function($, notification) {

/**
* Trigger on canvas element actions.
* @param options
* @param {object} options
*/
onchange: function(options) {
if (options.target.hasOwnProperty('id') && options.target.id === 'ruler') {
Expand All @@ -981,12 +979,12 @@ define(['jquery', 'core/notification'], function($, notification) {

/**
* Init
* @param args
* @param {object} args
*/
initialise: function(args) {

// Load spectrum javascript form here.
$.getScript("/mod/gcanvas/javascript/spectrum.js").done(function() {
$.getScript(M.cfg.wwwroot + "/mod/gcanvas/javascript/spectrum.js").done(function() {

// Load the args passed from PHP.
setOptions(args);
Expand All @@ -996,9 +994,14 @@ define(['jquery', 'core/notification'], function($, notification) {

$.noConflict();
$(document).ready(function() {
debug.log('Canvas Module v1.1');
debug.log('Canvas Module v1.2');
canvasModule.init();
});
}).fail(function(jqxhr, settings, exception) {
// Display loading issue in console.
debug.log(jqxhr);
debug.log(settings);
debug.log(exception);
});
}
};
Expand Down
1 change: 1 addition & 0 deletions lang/en/gcanvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
$string['btn:intro'] = 'Edit help text';
$string['btn:submit'] = 'Submit';
$string['btn:undo'] = 'Undo';
$string['btn:colorpicker'] = 'Colorpicker';

// Javascript.
$string['javascript:confirm_title'] = 'Confirm deletion of your sketch';
Expand Down
1 change: 1 addition & 0 deletions lang/nl/gcanvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
$string['btn:intro'] = 'Pas help tekst aan';
$string['btn:submit'] = 'Bewaren';
$string['btn:undo'] = 'Ongedaan maken';
$string['btn:colorpicker'] = 'Kleur selecteren';

// Javascript.
$string['javascript:confirm_title'] = 'Bevestig dat je deze tekening wil verwijderen.';
Expand Down
2 changes: 1 addition & 1 deletion templates/canvas.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<div class="item icon" id="trash" title="{{# str}} btn:trash, mod_gcanvas {{/ str}}">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</div>
<div class="item icon" title="{{# str}} btn:trash, mod_gcanvas {{/ str}}">
<div class="item icon" title="{{# str}} btn:colorpicker, mod_gcanvas {{/ str}}">
<input id="colorpicker" type="hidden"/>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'mod_gcanvas';
$plugin->release = '1.0.5';
$plugin->version = 2019050705;
$plugin->release = '1.0.6';
$plugin->version = 2019051300;
$plugin->requires = 2018051700;
$plugin->maturity = MATURITY_ALPHA;

0 comments on commit 7e80562

Please sign in to comment.