Skip to content

Commit

Permalink
MDL-47494 ddimageortext: NOBUG fixing code that constrains xy coords …
Browse files Browse the repository at this point in the history
…to within the background image.

And also fixed links to css to standardize character metrics.
  • Loading branch information
jamiepratt committed Sep 13, 2011
1 parent 9593b72 commit 06f0077
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion question/type/ddimageortext/edit_ddimageortext_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,8 @@ public function data_preprocessing($question) {
$PAGE->requires->yui_module('moodle-qtype_ddimageortext-form',
'M.qtype_ddimageortext.init_form',
array($params));
$PAGE->requires->css('/lib/yui/3.4.0/build/cssfonts/fonts-context-min.css');
$PAGE->requires->css('/lib/yui/3.4.0/build/cssfonts-context/fonts-context-min.css');
$PAGE->requires->css('/lib/yui/3.4.0/build/cssreset-context/cssreset-context-min.css');

return $question;
}
Expand Down
4 changes: 3 additions & 1 deletion question/type/ddimageortext/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@
class qtype_ddimageortext_renderer extends qtype_with_combined_feedback_renderer {

public function head_code(question_attempt $qa) {
$this->page->requires->css('/lib/yui/3.4.0/build/csscssfonts/fonts-context-min.css');
$this->page->requires->css('/lib/yui/3.4.0/build/cssfonts-context/fonts-context-min.css');
$this->page->requires->css(
'/lib/yui/3.4.0/build/cssreset-context/cssreset-context-min.css');
return parent::head_code($qa);
}
public function clear_wrong(question_attempt $qa) {
Expand Down
7 changes: 4 additions & 3 deletions question/type/ddimageortext/yui/dd/dd.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ YUI.add('moodle-qtype_ddimageortext-dd', function(Y) {
var oldhome = this.drag_item_home(dragitemno);
var classes = 'draghome dragitemhomes'+dragitemno+' group'+group;
var imghtml = '<img class="'+classes+'" src="'+url+'" alt="'+alt+'" />';
var divhtml = '<div class="yui3-cssfonts '+classes+'">'+alt+'</div>';
var divhtml = '<div class="yui3-cssfonts yui3-cssreset '
+classes+'">'+alt+'</div>';
if (oldhome === null) {
if (url) {
dragitemsarea.append(imghtml);
Expand Down Expand Up @@ -211,8 +212,8 @@ YUI.add('moodle-qtype_ddimageortext-dd', function(Y) {
}
},
convert_to_window_xy : function (bgimgxy) {
return [+bgimgxy[0] + this.doc.bg_img().getX(),
+bgimgxy[1] + this.doc.bg_img().getY()];
return [+bgimgxy[0] + this.doc.bg_img().getX() + 1,
+bgimgxy[1] + this.doc.bg_img().getY() + 1];
}
}, {
NAME : DDIMAGEORTEXTDDNAME,
Expand Down
14 changes: 9 additions & 5 deletions question/type/ddimageortext/yui/form/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ YUI.add('moodle-qtype_ddimageortext-form', function(Y) {
Y.all('fieldset#dropzoneheader input').on('blur', function (e){
var name = e.target.getAttribute('name');
var draginstanceno = this.form.from_name_with_index(name).indexes[0];
var fromform = [this.form.get_form_value('drops', [draginstanceno, 'xleft']),
this.form.get_form_value('drops', [draginstanceno, 'ytop'])];
var constrainedxy = this.constrain_xy(draginstanceno, fromform);
this.form.set_form_value('drops', [draginstanceno, 'xleft'], constrainedxy[0]);
this.form.set_form_value('drops', [draginstanceno, 'ytop'], constrainedxy[1]);
}, this);

//change in selected item
Expand All @@ -177,10 +182,10 @@ YUI.add('moodle-qtype_ddimageortext-form', function(Y) {
this.draw_dd_area();
}, this);
Y.all('fieldset#draggableitemheader_'+i+' input[type="text"]')
.on('blur', function (e){
this.doc.drag_items().remove(true);
.on('blur', function (e, draginstanceno){
this.doc.drag_item(draginstanceno).remove(true);
this.draw_dd_area();
}, this);
}, this, i);
//change to infinite checkbox
Y.all('fieldset#draggableitemheader_'+i+' input[type="checkbox"]')
.on('change', this.set_options_for_drag_item_selectors, this);
Expand Down Expand Up @@ -223,8 +228,7 @@ YUI.add('moodle-qtype_ddimageortext-form', function(Y) {
var dragitemno = drag.getData('dragitemno');
drag.setXY(this.doc.drag_item_home(dragitemno).getXY());
} else {
var constrainedxy = this.constrain_xy(draginstanceno, fromform);
drag.setXY(this.convert_to_window_xy(constrainedxy));
drag.setXY(this.convert_to_window_xy(fromform));
}
}
},
Expand Down

0 comments on commit 06f0077

Please sign in to comment.