diff --git a/question/type/ddimageortext/edit_ddimagetoimage_form.php b/question/type/ddimageortext/edit_ddimagetoimage_form.php
index 4a44913ca3d..d5cf5f70fa9 100644
--- a/question/type/ddimageortext/edit_ddimagetoimage_form.php
+++ b/question/type/ddimageortext/edit_ddimagetoimage_form.php
@@ -261,12 +261,12 @@ class qtype_ddimagetoimage_edit_form extends question_edit_form {
'requires' => array('node', 'dd', 'dd-drop', 'dd-constrain', 'form_filepicker')
);
$maxsizes =new stdClass();
- $maxsizes->bg_image = new stdClass();
- $maxsizes->bg_image->width = QTYPE_DDIMAGETOIMAGE_BGIMAGE_MAXWIDTH;
- $maxsizes->bg_image->height = QTYPE_DDIMAGETOIMAGE_BGIMAGE_MAXHEIGHT;
- $maxsizes->drag_image = new stdClass();
- $maxsizes->drag_image->width = QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXWIDTH;
- $maxsizes->drag_image->height = QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXHEIGHT;
+ $maxsizes->bgimage = new stdClass();
+ $maxsizes->bgimage->width = QTYPE_DDIMAGETOIMAGE_BGIMAGE_MAXWIDTH;
+ $maxsizes->bgimage->height = QTYPE_DDIMAGETOIMAGE_BGIMAGE_MAXHEIGHT;
+ $maxsizes->dragimage = new stdClass();
+ $maxsizes->dragimage->width = QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXWIDTH;
+ $maxsizes->dragimage->height = QTYPE_DDIMAGETOIMAGE_DRAGIMAGE_MAXHEIGHT;
$PAGE->requires->js_init_call('M.qtype_ddimagetoimage.init_form', array($maxsizes),
true, $jsmodule);
diff --git a/question/type/ddimageortext/module.js b/question/type/ddimageortext/module.js
index ac74e83219b..a3378a8f390 100644
--- a/question/type/ddimageortext/module.js
+++ b/question/type/ddimageortext/module.js
@@ -9,13 +9,13 @@ M.qtype_ddimagetoimage={
this.doc = this.doc_structure(Y, Y.one(topnodestr), this, null);
this.init_drops(drops);
var i = 0;
- this.doc.drag_item_homes().each(function(dragitemhome){
+ this.doc.drag_image_homes().each(function(dragimagehome){
var dragimageno =
- +this.doc.get_classname_numeric_suffix(dragitemhome, 'dragimagehomes');
- var choice = +this.doc.get_classname_numeric_suffix(dragitemhome, 'choice');
- var group = +this.doc.get_classname_numeric_suffix(dragitemhome, 'group')
+ +this.doc.get_classname_numeric_suffix(dragimagehome, 'dragimagehomes');
+ var choice = +this.doc.get_classname_numeric_suffix(dragimagehome, 'choice');
+ var group = +this.doc.get_classname_numeric_suffix(dragimagehome, 'group')
var groupsize = this.doc.drop_zone_group(group).size();
- var dragnode = this.doc.clone_new_drag_item(i, dragimageno);
+ var dragnode = this.doc.clone_new_drag_image(i, dragimageno);
i++;
if (!readonly) {
this.doc.draggable_for_question(dragnode, group, choice);
@@ -23,7 +23,7 @@ M.qtype_ddimagetoimage={
if (dragnode.hasClass('infinite')) {
var dragstocreate = groupsize - 1;
while (dragstocreate > 0) {
- dragnode = this.doc.clone_new_drag_item(i, dragimageno);
+ dragnode = this.doc.clone_new_drag_image(i, dragimageno);
i++;
if (!readonly) {
this.doc.draggable_for_question(dragnode, group, choice);
@@ -34,7 +34,7 @@ M.qtype_ddimagetoimage={
//put these here for easy refernece later
}, this);
this.doc.bg_img().on('load', this.delayed_redraw, this);
- this.doc.drag_item_homes().on('load', this.delayed_redraw, this);
+ this.doc.drag_image_homes().on('load', this.delayed_redraw, this);
Y.on('windowresize', this.redraw, this);
},
delayed_redraw : function (e) {
@@ -42,10 +42,10 @@ M.qtype_ddimagetoimage={
this.Y.later(2000, this, this.redraw);
},
redraw : function(e) {
- this.doc.drag_items().removeClass('placed');
- this.doc.drag_items().each (function (dragitem) {
- if (dragitem.dd !== undefined) {
- dragitem.dd.detachAll('drag:start');
+ this.doc.drag_images().removeClass('placed');
+ this.doc.drag_images().each (function (dragimage) {
+ if (dragimage.dd !== undefined) {
+ dragimage.dd.detachAll('drag:start');
}
}, this);
this.doc.drop_zones().each(function(dropzone) {
@@ -56,13 +56,13 @@ M.qtype_ddimagetoimage={
var choice = input.get('value');
if (choice !== "") {
var group = dropzone.getData('group');
- var dragitem = this.doc.top_node()
+ var dragimage = this.doc.top_node()
.one('div.dragitemgroup'+group+' img.choice'+choice+'.drag:not(.placed)');
- if (dragitem !== null) {
- dragitem.setXY(dropzone.getXY());
- dragitem.addClass('placed');
- if (dragitem.dd !== undefined) {
- dragitem.dd.once('drag:start', function (e, input) {
+ if (dragimage !== null) {
+ dragimage.setXY(dropzone.getXY());
+ dragimage.addClass('placed');
+ if (dragimage.dd !== undefined) {
+ dragimage.dd.once('drag:start', function (e, input) {
input.set('value', '');
e.target.get('node').removeClass('placed');
},this, input);
@@ -70,10 +70,10 @@ M.qtype_ddimagetoimage={
}
}
}, this);
- this.doc.drag_items().each(function(dragitem) {
- if (!dragitem.hasClass('placed')) {
- var dragitemhome = this.doc.get_drag_image_home(dragitem.getData('dragimageno'));
- dragitem.setXY(dragitemhome.getXY());
+ this.doc.drag_images().each(function(dragimage) {
+ if (!dragimage.hasClass('placed')) {
+ var dragimagehome = this.doc.drag_image_home(dragimage.getData('dragimageno'));
+ dragimage.setXY(dragimagehome.getXY());
}
}, this);
this.update_padding_sizes_all();
@@ -114,14 +114,14 @@ M.qtype_ddimagetoimage={
* Object to encapsulate operations on dd area.
*/
doc_structure : function (Y, topnode, mainobj, maxsizes) {
- var dragitemsarea = topnode.one('div.dragitems');
+ var dragimagesarea = topnode.one('div.dragitems');
var dropbgarea = topnode.one('div.droparea');
return {
top_node : function() {
return topnode;
},
- drag_items : function() {
- return dragitemsarea.all('img.drag');
+ drag_images : function() {
+ return dragimagesarea.all('img.drag');
},
drop_zones : function() {
return topnode.all('div.dropzones div.dropzone');
@@ -129,14 +129,14 @@ M.qtype_ddimagetoimage={
drop_zone_group : function(groupno) {
return topnode.all('div.dropzones div.group' + groupno);
},
- drag_items_cloned_from : function(dragimageno) {
- return dragitemsarea.all('img.dragimages'+dragimageno);
+ drag_images_cloned_from : function(dragimageno) {
+ return dragimagesarea.all('img.dragimages'+dragimageno);
},
- drag_item : function(draginstanceno) {
- return dragitemsarea.one('img.draginstance' + draginstanceno);
+ drag_image : function(draginstanceno) {
+ return dragimagesarea.one('img.draginstance' + draginstanceno);
},
- drag_item_homes : function() {
- return dragitemsarea.all('img.draghome');
+ drag_image_homes : function() {
+ return dragimagesarea.all('img.draghome');
},
bg_img : function() {
return topnode.one('img.dropbackground');
@@ -145,39 +145,28 @@ M.qtype_ddimagetoimage={
dropbgarea.setContent('');
this.bg_img().on('load', this.on_image_load, this, 'bg_image');
},
- add_or_update_drag_item_home : function (dragimageno, url, alt, group) {
- var oldhome = dragitemsarea.one('img.dragimagehomes'+dragimageno);
+ add_or_update_drag_image_home : function (dragimageno, url, alt, group) {
+ var oldhome = this.drag_image_home(dragimageno);
var classes = 'draghome dragimagehomes'+dragimageno+' group'+group;
var imghtml = '
';
if (oldhome === null) {
if (url) {
- dragitemsarea.append(imghtml);
+ dragimagesarea.append(imghtml);
}
} else {
if (url) {
- dragitemsarea.insert(imghtml, oldhome);
+ dragimagesarea.insert(imghtml, oldhome);
}
oldhome.remove(true);
}
- var newlycreated = dragitemsarea.one('img.dragimagehomes'+dragimageno);
+ var newlycreated = dragimagesarea.one('img.dragimagehomes'+dragimageno);
if (newlycreated !== null) {
newlycreated.setData('groupno', group);
newlycreated.setData('dragimageno', dragimageno);
- newlycreated.on('load', this.on_image_load, this, 'drag_image');
}
},
- on_image_load : function (e, imagetype) {
- if (maxsizes !== null) {
- var maxsize = maxsizes[imagetype];
- var reduceby = Math.max(e.target.get('width') / maxsize.width,
- e.target.get('height') / maxsize.height);
- if (reduceby > 1) {
- e.target.set('width', Math.floor(e.target.get('width') / reduceby));
- }
- }
- },
- get_drag_image_home : function (dragimageno) {
- return dragitemsarea.one('img.dragimagehomes' + dragimageno);
+ drag_image_home : function (dragimageno) {
+ return dragimagesarea.one('img.dragimagehomes' + dragimageno);
},
get_classname_numeric_suffix : function(node, prefix) {
var classes = node.getAttribute('class');
@@ -194,8 +183,8 @@ M.qtype_ddimagetoimage={
}
throw 'Prefix "'+prefix+'" not found in class names.';
},
- clone_new_drag_item : function (draginstanceno, dragimageno) {
- var draghome = this.get_drag_image_home(dragimageno);
+ clone_new_drag_image : function (draginstanceno, dragimageno) {
+ var draghome = this.drag_image_home(dragimageno);
if (draghome === null) {
return null;
}
@@ -281,6 +270,7 @@ M.qtype_ddimagetoimage={
//---------- stuff below this line only used in question editing form ---------------
fp : null,
+ maxsizes : null,
/**
* Entry point when called from question editing form
*/
@@ -291,64 +281,139 @@ M.qtype_ddimagetoimage={
topnode.append('