From 682bf667eabad4d030ca4403b8a0d4153aa78b97 Mon Sep 17 00:00:00 2001 From: Tim Hunt Date: Fri, 13 Feb 2015 18:59:00 +0000 Subject: [PATCH] MDL-47494 ddimageortext: Update dd qtype tests to use js_pending not fixed waits #14895 --- question/type/ddimageortext/tests/behat/preview.feature | 2 -- .../moodle-qtype_ddimageortext-dd-debug.js | 6 +++++- .../moodle-qtype_ddimageortext-dd-min.js | 4 ++-- .../moodle-qtype_ddimageortext-dd.js | 6 +++++- .../moodle-qtype_ddimageortext-form-debug.js | 3 +++ .../moodle-qtype_ddimageortext-form-min.js | 4 ++-- .../moodle-qtype_ddimageortext-form.js | 3 +++ .../ddimageortext/yui/src/ddimageortext/js/ddimageortext.js | 6 +++++- question/type/ddimageortext/yui/src/form/js/form.js | 3 +++ 9 files changed, 28 insertions(+), 9 deletions(-) diff --git a/question/type/ddimageortext/tests/behat/preview.feature b/question/type/ddimageortext/tests/behat/preview.feature index 7fde499e362..5fd5954229f 100644 --- a/question/type/ddimageortext/tests/behat/preview.feature +++ b/question/type/ddimageortext/tests/behat/preview.feature @@ -28,7 +28,6 @@ Feature: Preview a drag-drop onto image question Scenario: Preview a question using the mouse. When I click on "Preview" "link" in the "Drag onto image" "table_row" And I switch to "questionpreview" window - And I wait "2" seconds # Odd, but the
s go to nothing, not a space. And I drag "mountainbelt" to place "1" in the drag and drop onto image question And I drag "continentalshelf" to place "2" in the drag and drop onto image question @@ -46,7 +45,6 @@ Feature: Preview a drag-drop onto image question Scenario: Preview a question using the keyboard. When I click on "Preview" "link" in the "Drag onto image" "table_row" And I switch to "questionpreview" window - And I wait "1" seconds And I type " " on place "1" in the drag and drop onto image question And I type " " on place "2" in the drag and drop onto image question And I type " " on place "3" in the drag and drop onto image question diff --git a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-debug.js b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-debug.js index 10bacdda793..60417571ffa 100644 --- a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-debug.js +++ b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-debug.js @@ -250,14 +250,17 @@ var DDIMAGEORTEXT_QUESTION = function() { * This is the code for question rendering. */ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { + pendingid: '', initializer : function() { + this.pendingid = 'qtype_ddimageortext-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.doc = this.doc_structure(this); this.poll_for_image_load(null, false, 0, this.create_all_drag_and_drops); this.doc.bg_img().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); this.doc.drag_item_homes().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); - Y.later(500, this, this.reposition_drags_for_question, [], true); + Y.later(500, this, this.reposition_drags_for_question, [pendingid], true); }, create_all_drag_and_drops : function () { this.init_drops(); @@ -293,6 +296,7 @@ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { v.on('dragchange', this.drop_zone_key_press, this); }, this); } + M.util.js_complete(this.pendingid); }, drop_zone_key_press : function (e) { switch (e.direction) { diff --git a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-min.js b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-min.js index a7f8f78af6e..92f8b43654c 100644 --- a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-min.js +++ b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-qtype_ddimageortext-dd",function(e,t){var n="ddimageortext_dd",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{doc:null,polltimer:null,afterimageloaddone:!1,poll_for_image_load:function(t,n,r,i){if(this.afterimageloaddone)return;var s=this.doc.bg_img().get("complete");n&&(s=s&&this.doc.bg_img().hasClass("constrained"));var o=!this.doc.drag_item_homes().some(function(e){if(e.get("tagName")!=="IMG")return!1;var t=e.get("complete");return n&&(t=t&&e.hasClass("constrained")),!t});if(s&&o)this.polltimer!==null&&(this.polltimer.cancel(),this.polltimer=null),this.doc.drag_item_homes().detach("load",this.poll_for_image_load),this.doc.bg_img().detach("load",this.poll_for_image_load),r!==0?e.later(r,this,i):i.call(this),this.afterimageloaddone=!0;else if(this.polltimer===null){var u=[null,n,r,i];this.polltimer=e.later(1e3,this,this.poll_for_image_load,u,!0)}},doc_structure:function(t){var n=e.one(this.get("topnode")),r=n.one("div.dragitems"),i=n.one("div.droparea");return{top_node:function(){return n},drag_items:function(){return r.all(".drag")},drop_zones:function(){return n.all("div.dropzones div.dropzone")},drop_zone_group:function(e){return n.all("div.dropzones div.group"+e)},drag_items_cloned_from:function(e){return r.all(".dragitems"+e)},drag_item:function(e){return r.one(".draginstance"+e)},drag_items_in_group:function(e){return r.all(".drag.group"+e)},drag_item_homes:function(){return r.all(".draghome")},bg_img:function(){return n.one(".dropbackground")},load_bg_img:function(e){i.setContent(''),this.bg_img().on("load",this.on_image_load,this,"bg_image")},add_or_update_drag_item_home:function(e,t,n,i){var s=this.drag_item_home(e),o="draghome dragitemhomes"+e+" group"+i,u=''+n+'',a='
'+n+"
";s===null?t?r.append(u):n!==""&&r.append(a):(t?r.insert(u,s):n!==""&&r.insert(a,s),s.remove(!0));var f=r.one(".dragitemhomes"+e);f!==null&&(f.setData("groupno",i),f.setData("dragitemno",e))},drag_item_home:function(e){return r.one(".dragitemhomes"+e)},get_classname_numeric_suffix:function(e,t){var n=e.getAttribute("class");if(n!==""){var r=n.split(" ");for(var i=0;i0)o=this.doc.clone_new_drag_item(e,n),e++,this.get("readonly")||this.doc.draggable_for_question(o,i,r),u--}},this),this.reposition_drags_for_question(),this.get("readonly")||(this.doc.drop_zones().set("tabIndex",0),this.doc.drop_zones().each(function(e){e.on("dragchange",this.drop_zone_key_press,this)},this))},drop_zone_key_press:function(e){switch(e.direction){case"next":this.place_next_drag_in(e.target);break;case"previous":this.place_previous_drag_in(e.target);break;case"remove":this.remove_drag_from_drop(e.target)}e.preventDefault(),this.reposition_drags_for_question()},place_next_drag_in:function(e){this.search_for_unplaced_drop_choice(e,1)},place_previous_drag_in:function(e){this.search_for_unplaced_drop_choice(e,-1)},search_for_unplaced_drop_choice -:function(e,t){var n,r=this.current_drag_in_drop(e);if(""===r)if(t===1)n=1;else{n=1;var i=e.getData("group");this.doc.drag_items_in_group(i).each(function(e){n=Math.max(n,e.getData("choice"))},this)}else n=+r+t;var s;do{if(this.get_choices_for_drop(n,e).size()===0){this.remove_drag_from_drop(e);return}s=this.get_unplaced_choice_for_drop(n,e),n+=t}while(s===null);this.place_drag_in_drop(s,e)},current_drag_in_drop:function(t){var n=t.getData("inputid"),r=e.one("input#"+n);return r.get("value")},remove_drag_from_drop:function(e){this.place_drag_in_drop(null,e)},place_drag_in_drop:function(t,n){var r=n.getData("inputid"),i=e.one("input#"+r);t!==null?i.set("value",t.getData("choice")):i.set("value","")},reposition_drags_for_question:function(){this.doc.drag_items().removeClass("placed"),this.doc.drag_items().each(function(e){e.dd!==undefined&&e.dd.detachAll("drag:start")},this),this.doc.drop_zones().each(function(e){var t=e.getData("xy");e.setXY(this.convert_to_window_xy(t));var n="input#"+e.getData("inputid"),r=this.doc.top_node().one(n),i=r.get("value");if(i!==""){var s=this.get_unplaced_choice_for_drop(i,e);s!==null&&(s.setXY(e.getXY()),s.addClass("placed"),s.dd!==undefined&&s.dd.once("drag:start",function(e,t){t.set("value",""),e.target.get("node").removeClass("placed")},this,r))}},this),this.doc.drag_items().each(function(e){if(!e.hasClass("placed")&&!e.hasClass("yui3-dd-dragging")){var t=this.doc.drag_item_home(e.getData("dragitemno"));e.setXY(t.getXY())}},this)},get_choices_for_drop:function(e,t){var n=t.getData("group");return this.doc.top_node().all("div.dragitemgroup"+n+" .choice"+e+".drag")},get_unplaced_choice_for_drop:function(e,t){var n=this.get_choices_for_drop(e,t),r=null;return n.some(function(e){return!e.hasClass("placed")&&!e.hasClass("yui3-dd-dragging")?(r=e,!0):!1}),r},init_drops:function(){var t=this.doc.top_node().one("div.dropzones"),n={};for(var r=1;r<=8;r++){var i=e.Node.create('
');t.append(i),n[r]=i}var s=function(e){var t=e.drag.get("node"),n=e.drop.get("node");Number(n.getData("group"))===t.getData("group")&&this.place_drag_in_drop(t,n)};for(var o in this.get("drops")){var u=this.get("drops")[o],a="dropzone group"+u.group+" place"+o,f=u.text.replace('"','"'),l='
 
',c=e.Node.create(l);n[u.group].append(c),c.setStyles({opacity:.5}),c.setData("xy",u.xy),c.setData("place",o),c.setData("inputid",u.fieldname.replace(":","_")),c.setData("group",u.group);var h=new e.DD.Drop({node:c,groups:[u.group]});h.on("drop:hit",s,this)}}},{NAME:i,ATTRS:{}}),e.Event.define("dragchange",{_event:e.UA.webkit||e.UA.ie?"keydown":"keypress",_keys:{32:"next",37:"previous",38:"previous",39:"next",40:"next",27:"remove"},_keyHandler:function(e,t){this._keys[e.keyCode]&&(e.direction=this._keys[e.keyCode],t.fire(e))},on:function(e,t,n){t._detacher=e.on(this._event,this._keyHandler,this,n)}}),M.qtype_ddimageortext.init_question=function(e){return new s(e)}},"@VERSION@",{requires:["node","dd","dd-drop","dd-constrain"]}); +YUI.add("moodle-qtype_ddimageortext-dd",function(e,t){var n="ddimageortext_dd",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,e.Base,{doc:null,polltimer:null,afterimageloaddone:!1,poll_for_image_load:function(t,n,r,i){if(this.afterimageloaddone)return;var s=this.doc.bg_img().get("complete");n&&(s=s&&this.doc.bg_img().hasClass("constrained"));var o=!this.doc.drag_item_homes().some(function(e){if(e.get("tagName")!=="IMG")return!1;var t=e.get("complete");return n&&(t=t&&e.hasClass("constrained")),!t});if(s&&o)this.polltimer!==null&&(this.polltimer.cancel(),this.polltimer=null),this.doc.drag_item_homes().detach("load",this.poll_for_image_load),this.doc.bg_img().detach("load",this.poll_for_image_load),r!==0?e.later(r,this,i):i.call(this),this.afterimageloaddone=!0;else if(this.polltimer===null){var u=[null,n,r,i];this.polltimer=e.later(1e3,this,this.poll_for_image_load,u,!0)}},doc_structure:function(t){var n=e.one(this.get("topnode")),r=n.one("div.dragitems"),i=n.one("div.droparea");return{top_node:function(){return n},drag_items:function(){return r.all(".drag")},drop_zones:function(){return n.all("div.dropzones div.dropzone")},drop_zone_group:function(e){return n.all("div.dropzones div.group"+e)},drag_items_cloned_from:function(e){return r.all(".dragitems"+e)},drag_item:function(e){return r.one(".draginstance"+e)},drag_items_in_group:function(e){return r.all(".drag.group"+e)},drag_item_homes:function(){return r.all(".draghome")},bg_img:function(){return n.one(".dropbackground")},load_bg_img:function(e){i.setContent(''),this.bg_img().on("load",this.on_image_load,this,"bg_image")},add_or_update_drag_item_home:function(e,t,n,i){var s=this.drag_item_home(e),o="draghome dragitemhomes"+e+" group"+i,u=''+n+'',a='
'+n+"
";s===null?t?r.append(u):n!==""&&r.append(a):(t?r.insert(u,s):n!==""&&r.insert(a,s),s.remove(!0));var f=r.one(".dragitemhomes"+e);f!==null&&(f.setData("groupno",i),f.setData("dragitemno",e))},drag_item_home:function(e){return r.one(".dragitemhomes"+e)},get_classname_numeric_suffix:function(e,t){var n=e.getAttribute("class");if(n!==""){var r=n.split(" ");for(var i=0;i0)o=this.doc.clone_new_drag_item(e,n),e++,this.get("readonly")||this.doc.draggable_for_question(o,i,r),u--}},this),this.reposition_drags_for_question(),this.get("readonly")||(this.doc.drop_zones().set("tabIndex",0),this.doc.drop_zones().each(function(e){e.on("dragchange",this.drop_zone_key_press,this)},this)),M.util.js_complete(this.pendingid)},drop_zone_key_press:function(e){switch(e.direction){case"next":this.place_next_drag_in(e.target);break;case"previous":this.place_previous_drag_in(e.target);break;case"remove":this.remove_drag_from_drop(e.target)}e.preventDefault(),this.reposition_drags_for_question()}, +place_next_drag_in:function(e){this.search_for_unplaced_drop_choice(e,1)},place_previous_drag_in:function(e){this.search_for_unplaced_drop_choice(e,-1)},search_for_unplaced_drop_choice:function(e,t){var n,r=this.current_drag_in_drop(e);if(""===r)if(t===1)n=1;else{n=1;var i=e.getData("group");this.doc.drag_items_in_group(i).each(function(e){n=Math.max(n,e.getData("choice"))},this)}else n=+r+t;var s;do{if(this.get_choices_for_drop(n,e).size()===0){this.remove_drag_from_drop(e);return}s=this.get_unplaced_choice_for_drop(n,e),n+=t}while(s===null);this.place_drag_in_drop(s,e)},current_drag_in_drop:function(t){var n=t.getData("inputid"),r=e.one("input#"+n);return r.get("value")},remove_drag_from_drop:function(e){this.place_drag_in_drop(null,e)},place_drag_in_drop:function(t,n){var r=n.getData("inputid"),i=e.one("input#"+r);t!==null?i.set("value",t.getData("choice")):i.set("value","")},reposition_drags_for_question:function(){this.doc.drag_items().removeClass("placed"),this.doc.drag_items().each(function(e){e.dd!==undefined&&e.dd.detachAll("drag:start")},this),this.doc.drop_zones().each(function(e){var t=e.getData("xy");e.setXY(this.convert_to_window_xy(t));var n="input#"+e.getData("inputid"),r=this.doc.top_node().one(n),i=r.get("value");if(i!==""){var s=this.get_unplaced_choice_for_drop(i,e);s!==null&&(s.setXY(e.getXY()),s.addClass("placed"),s.dd!==undefined&&s.dd.once("drag:start",function(e,t){t.set("value",""),e.target.get("node").removeClass("placed")},this,r))}},this),this.doc.drag_items().each(function(e){if(!e.hasClass("placed")&&!e.hasClass("yui3-dd-dragging")){var t=this.doc.drag_item_home(e.getData("dragitemno"));e.setXY(t.getXY())}},this)},get_choices_for_drop:function(e,t){var n=t.getData("group");return this.doc.top_node().all("div.dragitemgroup"+n+" .choice"+e+".drag")},get_unplaced_choice_for_drop:function(e,t){var n=this.get_choices_for_drop(e,t),r=null;return n.some(function(e){return!e.hasClass("placed")&&!e.hasClass("yui3-dd-dragging")?(r=e,!0):!1}),r},init_drops:function(){var t=this.doc.top_node().one("div.dropzones"),n={};for(var r=1;r<=8;r++){var i=e.Node.create('
');t.append(i),n[r]=i}var s=function(e){var t=e.drag.get("node"),n=e.drop.get("node");Number(n.getData("group"))===t.getData("group")&&this.place_drag_in_drop(t,n)};for(var o in this.get("drops")){var u=this.get("drops")[o],a="dropzone group"+u.group+" place"+o,f=u.text.replace('"','"'),l='
 
',c=e.Node.create(l);n[u.group].append(c),c.setStyles({opacity:.5}),c.setData("xy",u.xy),c.setData("place",o),c.setData("inputid",u.fieldname.replace(":","_")),c.setData("group",u.group);var h=new e.DD.Drop({node:c,groups:[u.group]});h.on("drop:hit",s,this)}}},{NAME:i,ATTRS:{}}),e.Event.define("dragchange",{_event:e.UA.webkit||e.UA.ie?"keydown":"keypress",_keys:{32:"next",37:"previous",38:"previous",39:"next",40:"next",27:"remove"},_keyHandler:function(e,t){this._keys[e.keyCode]&&(e.direction=this._keys[e.keyCode],t.fire(e))},on:function(e,t,n){t._detacher=e.on(this._event,this._keyHandler,this,n)}}),M.qtype_ddimageortext.init_question=function(e){return new s(e)}},"@VERSION@",{requires:["node","dd","dd-drop","dd-constrain"]}); diff --git a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd.js b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd.js index 10bacdda793..60417571ffa 100644 --- a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd.js +++ b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-dd/moodle-qtype_ddimageortext-dd.js @@ -250,14 +250,17 @@ var DDIMAGEORTEXT_QUESTION = function() { * This is the code for question rendering. */ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { + pendingid: '', initializer : function() { + this.pendingid = 'qtype_ddimageortext-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.doc = this.doc_structure(this); this.poll_for_image_load(null, false, 0, this.create_all_drag_and_drops); this.doc.bg_img().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); this.doc.drag_item_homes().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); - Y.later(500, this, this.reposition_drags_for_question, [], true); + Y.later(500, this, this.reposition_drags_for_question, [pendingid], true); }, create_all_drag_and_drops : function () { this.init_drops(); @@ -293,6 +296,7 @@ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { v.on('dragchange', this.drop_zone_key_press, this); }, this); } + M.util.js_complete(this.pendingid); }, drop_zone_key_press : function (e) { switch (e.direction) { diff --git a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-debug.js b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-debug.js index ec97e7b75aa..e8722250900 100644 --- a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-debug.js +++ b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-debug.js @@ -24,9 +24,12 @@ var DDIMAGEORTEXT_FORM = function() { }; Y.extend(DDIMAGEORTEXT_FORM, M.qtype_ddimageortext.dd_base_class, { + pendingid: '', fp : null, initializer : function() { + this.pendingid = 'qtype_ddimageortext-form-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.fp = this.file_pickers(); var tn = Y.one(this.get('topnode')); tn.one('div.fcontainer').append('
' + diff --git a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-min.js b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-min.js index eba956ab617..c5fdf05f1d8 100644 --- a/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-min.js +++ b/question/type/ddimageortext/yui/build/moodle-qtype_ddimageortext-form/moodle-qtype_ddimageortext-form-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-qtype_ddimageortext-form",function(e,t){var n="moodle-qtype_ddimageortext-form",r=function(){r.superclass.constructor.apply(this,arguments)};e.extend(r,M.qtype_ddimageortext.dd_base_class,{fp:null,initializer:function(){this.fp=this.file_pickers();var t=e.one(this.get("topnode"));t.one("div.fcontainer").append('
'),this.doc=this.doc_structure(this),this.draw_dd_area()},draw_dd_area:function(){var t=this.fp.file("bgimage").href;this.stop_selector_events(),this.set_options_for_drag_item_selectors();if(t!==null){this.doc.load_bg_img(t),this.load_drag_homes();var n=new e.DD.Drop({node:this.doc.bg_img()});n.on("drop:hit",function(e){e.drag.get("node").setData("gooddrop",!0)}),this.afterimageloaddone=!1,this.doc.bg_img().on("load",this.constrain_image_size,this,"bgimage"),this.doc.drag_item_homes().on("load",this.constrain_image_size,this,"dragimage"),this.doc.bg_img().after("load",this.poll_for_image_load,this,!0,0,this.after_all_images_loaded),this.doc.drag_item_homes().after("load",this.poll_for_image_load,this,!0,0,this.after_all_images_loaded)}else this.setup_form_events();this.update_visibility_of_file_pickers()},after_all_images_loaded:function(){this.update_padding_sizes_all(),this.update_drag_instances(),this.reposition_drags_for_form(),this.set_options_for_drag_item_selectors(),this.setup_form_events(),e.later(500,this,this.reposition_drags_for_form,[],!0)},constrain_image_size:function(e,t){var n=this.get("maxsizes")[t],r=Math.max(e.target.get("width")/n.width,e.target.get("height")/n.height);r>1&&e.target.set("width",Math.floor(e.target.get("width")/r)),e.target.addClass("constrained"),e.target.detach("load",this.constrain_image_size)},load_drag_homes:function(){for(var e=0;e'+t[u]+"";s.append(a);var f=s.one('option[value="'+u+'"]');if(u===+o)f.set("selected",!0);else if(u!==0){var l=e.one("#id_drags_"+(u-1)+"_infinite");l&&!l.get("checked")&&e.all("fieldset#id_dropzoneheader select").some(function(e){return Number(e.get("value"))===u?(f.set("disabled",!0),!0):!1},this)}}}},stop_selector_events:function(){e.all("fieldset#id_dropzoneheader select").detachAll()},setup_form_events:function(){e.all("fieldset#id_dropzoneheader input").on("blur",function(e){var t=e.target.getAttribute("name"),n=this.form.from_name_with_index(t).indexes[0],r=[this.form.get_form_value("drops",[n,"xleft"]),this.form.get_form_value("drops",[n,"ytop"])],i=this.constrain_xy(n,r);this.form.set_form_value("drops",[n,"xleft"],i[0]),this.form.set_form_value("drops",[n,"ytop"],i[1])},this),e.all("fieldset#id_dropzoneheader select").on("change",function(e){var t=e.target.getAttribute("name"),n=this.form.from_name_with_index(t).indexes[0],r=this.doc.drag_item(n);r!==null&&r.remove(!0),this.draw_dd_area()},this);for(var t=0;t
'),this.doc=this.doc_structure(this),this.draw_dd_area()},draw_dd_area:function(){var t=this.fp.file("bgimage").href;this.stop_selector_events(),this.set_options_for_drag_item_selectors();if(t!==null){this.doc.load_bg_img(t),this.load_drag_homes();var n=new e.DD.Drop({node:this.doc.bg_img()});n.on("drop:hit",function(e){e.drag.get("node").setData("gooddrop",!0)}),this.afterimageloaddone=!1,this.doc.bg_img().on("load",this.constrain_image_size,this,"bgimage"),this.doc.drag_item_homes().on("load",this.constrain_image_size,this,"dragimage"),this.doc.bg_img().after("load",this.poll_for_image_load,this,!0,0,this.after_all_images_loaded),this.doc.drag_item_homes().after("load",this.poll_for_image_load,this,!0,0,this.after_all_images_loaded)}else this.setup_form_events();this.update_visibility_of_file_pickers()},after_all_images_loaded:function(){this.update_padding_sizes_all(),this.update_drag_instances(),this.reposition_drags_for_form(),this.set_options_for_drag_item_selectors(),this.setup_form_events(),e.later(500,this,this.reposition_drags_for_form,[],!0)},constrain_image_size:function(e,t){var n=this.get("maxsizes")[t],r=Math.max(e.target.get("width")/n.width,e.target.get("height")/n.height);r>1&&e.target.set("width",Math.floor(e.target.get("width")/r)),e.target.addClass("constrained"),e.target.detach("load",this.constrain_image_size)},load_drag_homes:function(){for(var e=0;e'+t[u]+"";s.append(a);var f=s.one('option[value="'+u+'"]');if(u===+o)f.set("selected",!0);else if(u!==0){var l=e.one("#id_drags_"+(u-1)+"_infinite");l&&!l.get("checked")&&e.all("fieldset#id_dropzoneheader select").some(function(e){return Number(e.get("value"))===u?(f.set("disabled",!0),!0):!1},this)}}}},stop_selector_events:function(){e.all("fieldset#id_dropzoneheader select").detachAll()},setup_form_events:function(){e.all("fieldset#id_dropzoneheader input").on("blur",function(e){var t=e.target.getAttribute("name"),n=this.form.from_name_with_index(t).indexes[0],r=[this.form.get_form_value("drops",[n,"xleft"]),this.form.get_form_value("drops",[n,"ytop"])],i=this.constrain_xy(n,r);this.form.set_form_value("drops",[n,"xleft"],i[0]),this.form.set_form_value("drops",[n,"ytop"],i[1])},this),e.all("fieldset#id_dropzoneheader select").on("change",function(e){var t=e.target.getAttribute("name"),n=this.form.from_name_with_index(t).indexes[0],r=this.doc.drag_item(n);r!==null&&r.remove(!0),this.draw_dd_area()},this);for(var t=0;t
' + diff --git a/question/type/ddimageortext/yui/src/ddimageortext/js/ddimageortext.js b/question/type/ddimageortext/yui/src/ddimageortext/js/ddimageortext.js index d22e07c7e41..f5b312c8df7 100644 --- a/question/type/ddimageortext/yui/src/ddimageortext/js/ddimageortext.js +++ b/question/type/ddimageortext/yui/src/ddimageortext/js/ddimageortext.js @@ -248,14 +248,17 @@ var DDIMAGEORTEXT_QUESTION = function() { * This is the code for question rendering. */ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { + pendingid: '', initializer : function() { + this.pendingid = 'qtype_ddimageortext-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.doc = this.doc_structure(this); this.poll_for_image_load(null, false, 0, this.create_all_drag_and_drops); this.doc.bg_img().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); this.doc.drag_item_homes().after('load', this.poll_for_image_load, this, false, 0, this.create_all_drag_and_drops); - Y.later(500, this, this.reposition_drags_for_question, [], true); + Y.later(500, this, this.reposition_drags_for_question, [pendingid], true); }, create_all_drag_and_drops : function () { this.init_drops(); @@ -291,6 +294,7 @@ Y.extend(DDIMAGEORTEXT_QUESTION, M.qtype_ddimageortext.dd_base_class, { v.on('dragchange', this.drop_zone_key_press, this); }, this); } + M.util.js_complete(this.pendingid); }, drop_zone_key_press : function (e) { switch (e.direction) { diff --git a/question/type/ddimageortext/yui/src/form/js/form.js b/question/type/ddimageortext/yui/src/form/js/form.js index bbd94130264..a786dca647f 100644 --- a/question/type/ddimageortext/yui/src/form/js/form.js +++ b/question/type/ddimageortext/yui/src/form/js/form.js @@ -22,9 +22,12 @@ var DDIMAGEORTEXT_FORM = function() { }; Y.extend(DDIMAGEORTEXT_FORM, M.qtype_ddimageortext.dd_base_class, { + pendingid: '', fp : null, initializer : function() { + this.pendingid = 'qtype_ddimageortext-form-' + Math.random().toString(36).slice(2); // Random string. + M.util.js_pending(this.pendingid); this.fp = this.file_pickers(); var tn = Y.one(this.get('topnode')); tn.one('div.fcontainer').append('
' +