From da1a0b10521498761db0f1220863decb34213144 Mon Sep 17 00:00:00 2001 From: marcusgreen Date: Sat, 29 Aug 2020 15:50:45 +0100 Subject: [PATCH] eslint fixes --- amd/build/dragdrop.min.js.map | 2 +- amd/build/questionedit.min.js | 2 +- amd/build/questionedit.min.js.map | 2 +- amd/src/dragdrop.js | 16 +++++++++++----- amd/src/questionedit.js | 9 ++++----- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/amd/build/dragdrop.min.js.map b/amd/build/dragdrop.min.js.map index 0725ba9d..d599f271 100644 --- a/amd/build/dragdrop.min.js.map +++ b/amd/build/dragdrop.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["../src/dragdrop.js"],"names":["define","$","init","singleuse","on","dragShow","val","that","draggables","targetVal","i","length","sourceVal","textContent","removeClass","draggable","revert","helper","cursor","scroll","droppable","hoverClass","drop","event","ui","hasClass","value","text","css","addClass","dblclick"],"mappings":"AAuBAA,OAAM,0BAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,8CAAvB,CAAD,CAAyE,SAAUC,CAAV,CAAa,CAC1F,MAAO,CACLC,IAAI,CAAE,cAAUC,CAAV,CAAqB,CACzBF,CAAC,CAAC,aAAD,CAAD,CAAiBG,EAAjB,CAAoB,UAApB,CAAgC,UAAY,CAC1C,GAAID,CAAJ,CAAe,CACbE,CAAQ,CAAC,IAAD,CAAR,CACAJ,CAAC,CAAC,IAAD,CAAD,CAAQK,GAAR,CAAY,EAAZ,CACD,CACF,CALD,EAOA,QAASD,CAAAA,CAAT,CAAkBE,CAAlB,CAAwB,IAClBC,CAAAA,CAAU,CAAGP,CAAC,CAAC,YAAD,CADI,CAElBQ,CAAS,CAAGR,CAAC,CAACM,CAAD,CAAD,CAAQD,GAAR,EAFM,CAGlBI,CAHkB,CAItB,IAAKA,CAAC,CAAG,CAAT,CAAYA,CAAC,CAAGF,CAAU,CAACG,MAA3B,CAAmCD,CAAC,EAApC,CAAwC,CACtC,GAAIE,CAAAA,CAAS,CAAGJ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CAAC,IAAD,CAAD,CAAQ2B,GAAR,CAAY,kBAAZ,CAAgC,OAAhC,CACF,CAJA,CAKD,CAnDI,CAqDR,CAtDK,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 * JavaScript code for the gapfill question type.\n *\n * @package qtype\n * @subpackage gapfill\n * @copyright 2020 Marcus Green\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], function ($) {\n return {\n init: function (singleuse) {\n $(\".droptarget\").on('dblclick', function () {\n if (singleuse) {\n dragShow(this);\n $(this).val(\"\");\n }\n });\n\n function dragShow(that) {\n var draggables = $(\".draggable\");\n var targetVal = $(that).val();\n var i;\n for (i = 0; i < draggables.length; i++) {\n var sourceVal = draggables[i].textContent;\n if (sourceVal == targetVal) {\n $(draggables[i]).removeClass(\"hide\");\n }\n }\n }\n\n $(\".droptarget\").on('keydown drop', function () {\n dragShow(this);\n });\n\n $(\".draggable\").draggable({\n revert: false,\n helper: 'clone',\n cursor: 'pointer',\n scroll: 'false',\n });\n\n $(\".droptarget\").droppable({\n hoverClass: 'active',\n drop: function (event, ui) {\n if ($(ui.draggable).hasClass('readonly')) {\n return;\n }\n this.value = $(ui.draggable).text();\n $(this).css(\"background-color\", \"white\");\n $(this).addClass(\"dropped\");\n if (singleuse) {\n $(ui.draggable).addClass(\"hide\");\n }\n }\n });\n $(\".droptarget\").dblclick(function() {\n $(this).val(\"\");\n $(this).removeClass(\"dropped\");\n $(this).css(\"background-color\", \"white\");\n });\n }\n };\n});"],"file":"dragdrop.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/dragdrop.js"],"names":["define","$","init","singleuse","on","dragShow","val","that","draggables","targetVal","i","length","sourceVal","textContent","removeClass","draggable","revert","helper","cursor","scroll","droppable","hoverClass","drop","event","ui","hasClass","value","text","css","addClass","dblclick"],"mappings":"AAuBAA,OAAM,0BAAC,CAAC,QAAD,CAAW,UAAX,CAAuB,8CAAvB,CAAD,CAAyE,SAASC,CAAT,CAAY,CACzF,MAAO,CACLC,IAAI,CAAE,cAASC,CAAT,CAAoB,CACxBF,CAAC,CAAC,aAAD,CAAD,CAAiBG,EAAjB,CAAoB,UAApB,CAAgC,UAAW,CACzC,GAAID,CAAJ,CAAe,CACbE,CAAQ,CAAC,IAAD,CAAR,CACAJ,CAAC,CAAC,IAAD,CAAD,CAAQK,GAAR,CAAY,EAAZ,CACD,CACF,CALD,EAaA,QAASD,CAAAA,CAAT,CAAkBE,CAAlB,CAAwB,IAClBC,CAAAA,CAAU,CAAGP,CAAC,CAAC,YAAD,CADI,CAElBQ,CAAS,CAAGR,CAAC,CAACM,CAAD,CAAD,CAAQD,GAAR,EAFM,CAGlBI,CAHkB,CAItB,IAAKA,CAAC,CAAG,CAAT,CAAYA,CAAC,CAAGF,CAAU,CAACG,MAA3B,CAAmCD,CAAC,EAApC,CAAwC,CACtC,GAAIE,CAAAA,CAAS,CAAGJ,CAAU,CAACE,CAAD,CAAV,CAAcG,WAA9B,CACA,GAAID,CAAS,EAAIH,CAAjB,CAA4B,CAC1BR,CAAC,CAACO,CAAU,CAACE,CAAD,CAAX,CAAD,CAAiBI,WAAjB,CAA6B,MAA7B,CACD,CACF,CACF,CAEDb,CAAC,CAAC,aAAD,CAAD,CAAiBG,EAAjB,CAAoB,cAApB,CAAoC,UAAW,CAC7CC,CAAQ,CAAC,IAAD,CACT,CAFD,EAIAJ,CAAC,CAAC,YAAD,CAAD,CAAgBc,SAAhB,CAA0B,CACxBC,MAAM,GADkB,CAExBC,MAAM,CAAE,OAFgB,CAGxBC,MAAM,CAAE,SAHgB,CAIxBC,MAAM,CAAE,OAJgB,CAA1B,EAOAlB,CAAC,CAAC,aAAD,CAAD,CAAiBmB,SAAjB,CAA2B,CACzBC,UAAU,CAAE,QADa,CAEzBC,IAAI,CAAE,cAASC,CAAT,CAAgBC,CAAhB,CAAoB,CACxB,GAAIvB,CAAC,CAACuB,CAAE,CAACT,SAAJ,CAAD,CAAgBU,QAAhB,CAAyB,UAAzB,CAAJ,CAA0C,CACxC,MACD,CACD,KAAKC,KAAL,CAAazB,CAAC,CAACuB,CAAE,CAACT,SAAJ,CAAD,CAAgBY,IAAhB,EAAb,CACA1B,CAAC,CAAC,IAAD,CAAD,CAAQ2B,GAAR,CAAY,kBAAZ,CAAgC,OAAhC,EACA3B,CAAC,CAAC,IAAD,CAAD,CAAQ4B,QAAR,CAAiB,SAAjB,EACA,GAAI1B,CAAJ,CAAe,CACbF,CAAC,CAACuB,CAAE,CAACT,SAAJ,CAAD,CAAgBc,QAAhB,CAAyB,MAAzB,CACD,CACF,CAZwB,CAA3B,EAcA5B,CAAC,CAAC,aAAD,CAAD,CAAiB6B,QAAjB,CAA0B,UAAW,CACnC7B,CAAC,CAAC,IAAD,CAAD,CAAQK,GAAR,CAAY,EAAZ,EACAL,CAAC,CAAC,IAAD,CAAD,CAAQa,WAAR,CAAoB,SAApB,EACAb,CAAC,CAAC,IAAD,CAAD,CAAQ2B,GAAR,CAAY,kBAAZ,CAAgC,OAAhC,CACF,CAJA,CAKD,CAzDI,CA2DR,CA5DK,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 * JavaScript code for the gapfill question type.\n *\n * @package qtype\n * @subpackage gapfill\n * @copyright 2020 Marcus Green\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\ndefine(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], function($) {\n return {\n init: function(singleuse) {\n $(\".droptarget\").on('dblclick', function() {\n if (singleuse) {\n dragShow(this);\n $(this).val(\"\");\n }\n });\n\n /**\n * Reveal draggables that are not\n * the the current one\n *\n * @param {*} that\n */\n function dragShow(that) {\n var draggables = $(\".draggable\");\n var targetVal = $(that).val();\n var i;\n for (i = 0; i < draggables.length; i++) {\n var sourceVal = draggables[i].textContent;\n if (sourceVal == targetVal) {\n $(draggables[i]).removeClass(\"hide\");\n }\n }\n }\n\n $(\".droptarget\").on('keydown drop', function() {\n dragShow(this);\n });\n\n $(\".draggable\").draggable({\n revert: false,\n helper: 'clone',\n cursor: 'pointer',\n scroll: 'false',\n });\n\n $(\".droptarget\").droppable({\n hoverClass: 'active',\n drop: function(event, ui) {\n if ($(ui.draggable).hasClass('readonly')) {\n return;\n }\n this.value = $(ui.draggable).text();\n $(this).css(\"background-color\", \"white\");\n $(this).addClass(\"dropped\");\n if (singleuse) {\n $(ui.draggable).addClass(\"hide\");\n }\n }\n });\n $(\".droptarget\").dblclick(function() {\n $(this).val(\"\");\n $(this).removeClass(\"dropped\");\n $(this).css(\"background-color\", \"white\");\n });\n }\n };\n});"],"file":"dragdrop.min.js"} \ No newline at end of file diff --git a/amd/build/questionedit.min.js b/amd/build/questionedit.min.js index 07188a0f..d6dbee07 100644 --- a/amd/build/questionedit.min.js +++ b/amd/build/questionedit.min.js @@ -1,2 +1,2 @@ -define ("qtype_gapfill/questionedit",["jquery","qtype_gapfill/Item"],function(a,b){return{init:function init(){a("#id_answerdisplay").change(function(){debugger;var b=a(this).val();if("gapfill"==b){a("#id_fixedgapsize").prop("disabled",!1);a("#id_optionsaftertext").prop("disabled",!0).prop("checked",!1);a("#id_singleuse").prop("disabled",!0).prop("checked",!1)}if("dragdrop"==b){a("#id_optionsaftertext").prop("disabled",!1);a("#id_singleuse").prop("disabled",!1);a("#id_fixedgapsize").prop("disabled",!1)}if("dropdown"==b){a("#id_fixedgapsize").prop("disabled",!0).prop("checked",!1);a("#id_optionsaftertext").prop("disabled",!0).prop("checked",!1);a("#id_singleuse").prop("disabled",!0).prop("checked",!1)}});a("#id_itemsettings_button").on("click",function(){var b=a(".editor_atto").length;if(1>b){a("#id_error_itemsettings_button").css({display:"inline",color:"red"});a("#id_error_itemsettings_button")[0].innerHTML=M.util.get_string("itemsettingserror","qtype_gapfill");return}a("#questiontext .atto_html_button").attr("disabled","true");if(a("#id_questiontexteditable").get(0).isContentEditable){a("#id_questiontexteditable").attr("contenteditable","false");a("#fitem_id_questiontext").find("button").attr("disabled","true");var c=a("#id_questiontexteditable").css("height"),f=a("#id_questiontexteditable").css("width");a("#id_questiontexteditable").css("display","none");a("#id_itemsettings_canvas").css(d(a("#id_questiontexteditable")));var g=a("#id_questiontexteditable").closest(".editor_atto_content_wrap");a("#id_itemsettings_canvas").appendTo(g).css("position","relative");a("#id_itemsettings_canvas").css({display:"block",background:"lightgrey"});a("#id_itemsettings_canvas").html(a("#id_questiontexteditable").prop("innerHTML"));a("#id_itemsettings_canvas").css({height:c,width:f});a("#id_itemsettings_canvas").css({height:"100%",width:"100%"});a("#id_itemsettings_button").html(M.util.get_string("editquestiontext","qtype_gapfill"));a("#id_itemsettings_canvas").height(a("#id_questiontexteditable").height());e(a("#id_itemsettings_canvas")[0])}else{a("#id_questiontexteditable").css({display:"block",backgroundColor:"white"});a("#id_questiontexteditable").attr("contenteditable","true");a("#id_itemsettings_canvas").css("display","none");a("#fitem_id_questiontext").find("button").removeAttr("disabled");a("#id_settings_popup").css("display","none");a("#id_itemsettings_button").html(M.util.get_string("additemsettings","qtype_gapfill"));a("[class^=atto_]").removeAttr("disabled")}});a("#id_itemsettings_canvas").on("click",function(c){if(!a("#id_questiontexteditable").get(0).isContentEditable&&c.target.id.match(/^id[0-9]+_/)){var d=a("#id_delimitchars").val(),e=new b(c.target.innerHTML,d),f=e.getItemSettings(c.target);if(null===f||0===f.length){a("#id_correcteditable").html("");a("#id_incorrecteditable").html("")}else{a("#id_correcteditable").html(f.correctfeedback);a("#id_incorrecteditable").html(f.incorrectfeedback)}a("label[for*='id_correct']").text(M.util.get_string("correct","qtype_gapfill"));a("label[for*='id_incorrect']").text(M.util.get_string("incorrect","qtype_gapfill"));a("#id_itemsettings_popup .atto_image_button").attr("disabled","true");a("#id_itemsettings_popup .atto_media_button").attr("disabled","true");a("#id_itemsettings_popup .atto_managefiles_button").attr("disabled","true");var g=M.util.get_string("additemsettings","qtype_gapfill");g+=": "+a("
").html(e.stripdelim()).text();require(["jquery","jqueryui"],function(a){a("#id_itemsettings_popup").dialog({position:{my:"right",at:"right",of:"#id_itemsettings_canvas"},height:500,width:"70%",modal:!1,title:g,buttons:[{text:"OK",click:function click(){var b=e.updateJson(c);a("[class^=atto_]").removeAttr("disabled");a("[name='itemsettings']").val(b);a(".ui-dialog-content").dialog("close");a("#id_questiontexteditable").attr("contenteditable","true");a("#id_itemsettings_button").click()}}]})})}});function c(a){for(var b=[],c=0,d=a.length;cb){a("#id_error_itemsettings_button").css({display:"inline",color:"red"});a("#id_error_itemsettings_button")[0].innerHTML=M.util.get_string("itemsettingserror","qtype_gapfill");return}a("#questiontext .atto_html_button").attr("disabled","true");if(a("#id_questiontexteditable").get(0).isContentEditable){a("#id_questiontexteditable").attr("contenteditable","false");a("#fitem_id_questiontext").find("button").attr("disabled","true");var c=a("#id_questiontexteditable").css("height"),f=a("#id_questiontexteditable").css("width");a("#id_questiontexteditable").css("display","none");a("#id_itemsettings_canvas").css(d(a("#id_questiontexteditable")));var g=a("#id_questiontexteditable").closest(".editor_atto_content_wrap");a("#id_itemsettings_canvas").appendTo(g).css("position","relative");a("#id_itemsettings_canvas").css({display:"block",background:"lightgrey"});a("#id_itemsettings_canvas").html(a("#id_questiontexteditable").prop("innerHTML"));a("#id_itemsettings_canvas").css({height:c,width:f});a("#id_itemsettings_canvas").css({height:"100%",width:"100%"});a("#id_itemsettings_button").html(M.util.get_string("editquestiontext","qtype_gapfill"));a("#id_itemsettings_canvas").height(a("#id_questiontexteditable").height());e(a("#id_itemsettings_canvas")[0])}else{a("#id_questiontexteditable").css({display:"block",backgroundColor:"white"});a("#id_questiontexteditable").attr("contenteditable","true");a("#id_itemsettings_canvas").css("display","none");a("#fitem_id_questiontext").find("button").removeAttr("disabled");a("#id_settings_popup").css("display","none");a("#id_itemsettings_button").html(M.util.get_string("additemsettings","qtype_gapfill"));a("[class^=atto_]").removeAttr("disabled")}});a("#id_itemsettings_canvas").on("click",function(c){if(!a("#id_questiontexteditable").get(0).isContentEditable&&c.target.id.match(/^id[0-9]+_/)){var d=a("#id_delimitchars").val(),e=new b(c.target.innerHTML,d),f=e.getItemSettings(c.target);if(null===f||0===f.length){a("#id_correcteditable").html("");a("#id_incorrecteditable").html("")}else{a("#id_correcteditable").html(f.correctfeedback);a("#id_incorrecteditable").html(f.incorrectfeedback)}a("label[for*='id_correct']").text(M.util.get_string("correct","qtype_gapfill"));a("label[for*='id_incorrect']").text(M.util.get_string("incorrect","qtype_gapfill"));a("#id_itemsettings_popup .atto_image_button").attr("disabled","true");a("#id_itemsettings_popup .atto_media_button").attr("disabled","true");a("#id_itemsettings_popup .atto_managefiles_button").attr("disabled","true");var g=M.util.get_string("additemsettings","qtype_gapfill");g+=": "+a("
").html(e.stripdelim()).text();require(["jquery","jqueryui"],function(a){a("#id_itemsettings_popup").dialog({position:{my:"right",at:"right",of:"#id_itemsettings_canvas"},height:500,width:"70%",modal:!1,title:g,buttons:[{text:"OK",click:function click(){var b=e.updateJson(c);a("[class^=atto_]").removeAttr("disabled");a("[name='itemsettings']").val(b);a(".ui-dialog-content").dialog("close");a("#id_questiontexteditable").attr("contenteditable","true");a("#id_itemsettings_button").click()}}]})})}});function c(a){for(var b=[],c=0,d=a.length;c.\n\n/**\n * JavaScript code for the gapfill question type.\n *\n * @package qtype_gapfill\n * @copyright 2017 Marcus Green\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\n/* The data is stored in a hidden field */\ndefine(['jquery', 'qtype_gapfill/Item'], function($, Item) {\n return {\n init: function() {\n $('#id_answerdisplay').change(function(evt) {\n debugger;\n var selected = $(this).val();\n if(selected == 'gapfill'){\n $('#id_fixedgapsize').prop('disabled',false);\n $(\"#id_optionsaftertext\").prop('disabled',true).prop('checked',false);\n $('#id_singleuse').prop('disabled',true).prop('checked', false);\n }\n if(selected == 'dragdrop'){\n $('#id_optionsaftertext').prop('disabled',false);\n $('#id_singleuse').prop('disabled',false);\n $('#id_fixedgapsize').prop('disabled',false);\n }\n if(selected == 'dropdown'){\n $('#id_fixedgapsize').prop('disabled',true).prop('checked',false);\n $('#id_optionsaftertext').prop('disabled',true).prop('checked',false);\n $('#id_singleuse').prop('disabled',true).prop('checked',false);\n }\n\n\n\n\n });\n /* A click on the itemsettings button */\n $('#id_itemsettings_button').on('click', function() {\n var attoIsLive = $('.editor_atto').length;\n /* Show error if Atto is not loaded. It might be because the page has not finished loading\n * or because plain text elements are being used or (perhaps less likely as time goes on)\n * the HTMLarea editor is being used. It might be possible to work with those other editors\n * but limiting to Atto keeps things straightforward and maintainable.\n */\n if (attoIsLive < 1) {\n $('#id_error_itemsettings_button').css({\n display: 'inline',\n color: 'red',\n });\n $('#id_error_itemsettings_button')[0].innerHTML = M.util.get_string(\n 'itemsettingserror',\n 'qtype_gapfill'\n );\n return;\n }\n $('#questiontext .atto_html_button').attr('disabled', 'true');\n if ($('#id_questiontexteditable').get(0).isContentEditable) {\n $('#id_questiontexteditable').attr('contenteditable', 'false');\n $('#fitem_id_questiontext')\n .find('button')\n .attr('disabled', 'true');\n var settingformheight = $('#id_questiontexteditable').css('height');\n var settingformwidth = $('#id_questiontexteditable').css('width');\n $('#id_questiontexteditable').css('display', 'none');\n /* Copy the styles from attos editable area so the canvas looks the same (except gray) */\n $('#id_itemsettings_canvas').css(\n copyStyles($('#id_questiontexteditable'))\n );\n var ed = $('#id_questiontexteditable').closest(\n '.editor_atto_content_wrap'\n );\n $('#id_itemsettings_canvas')\n .appendTo(ed)\n .css('position', 'relative');\n $('#id_itemsettings_canvas').css({\n display: 'block',\n background: 'lightgrey',\n });\n\n /* Copy the real html to the feedback editing html */\n $('#id_itemsettings_canvas').html(\n $('#id_questiontexteditable').prop('innerHTML')\n );\n $('#id_itemsettings_canvas').css({\n height: settingformheight,\n width: settingformwidth,\n });\n $('#id_itemsettings_canvas').css({height: '100%', width: '100%'});\n $('#id_itemsettings_button').html(\n M.util.get_string('editquestiontext', 'qtype_gapfill')\n );\n /* Setting the height by hand gets around a quirk of MSIE */\n $('#id_itemsettings_canvas').height(\n $('#id_questiontexteditable').height()\n );\n /* Disable the buttons on questiontext but not on the feedback form */\n /* wrapContent should be the last on this block as it sometimes falls over with an error */\n wrapContent($('#id_itemsettings_canvas')[0]);\n } else {\n $('#id_questiontexteditable').css({\n display: 'block',\n backgroundColor: 'white',\n });\n $('#id_questiontexteditable').attr('contenteditable', 'true');\n $('#id_itemsettings_canvas').css('display', 'none');\n $('#fitem_id_questiontext')\n .find('button')\n .removeAttr('disabled');\n $('#id_settings_popup').css('display', 'none');\n $('#id_itemsettings_button').html(\n M.util.get_string('additemsettings', 'qtype_gapfill')\n );\n $('[class^=atto_]').removeAttr('disabled');\n }\n });\n\n /* A click on the text */\n $('#id_itemsettings_canvas').on('click', function(e) {\n /*\n * Questiontext needs to be edditable and the target must start\n * with id followed by one or more digits and an underscore\n * */\n if (\n !$('#id_questiontexteditable').get(0).isContentEditable &&\n e.target.id.match(/^id[0-9]+_/)\n ) {\n var delimitchars = $('#id_delimitchars').val();\n var item = new Item(e.target.innerHTML, delimitchars);\n\n // Var item = new Item(e.target.innerHTML, delimitchars);\n var itemsettings = item.getItemSettings(e.target);\n if (itemsettings === null || itemsettings.length === 0) {\n $('#id_correcteditable').html('');\n $('#id_incorrecteditable').html('');\n } else {\n $('#id_correcteditable').html(itemsettings.correctfeedback);\n $('#id_incorrecteditable').html(itemsettings.incorrectfeedback);\n }\n $(\"label[for*='id_correct']\").text(\n M.util.get_string('correct', 'qtype_gapfill')\n );\n $(\"label[for*='id_incorrect']\").text(\n M.util.get_string('incorrect', 'qtype_gapfill')\n );\n $('#id_itemsettings_popup .atto_image_button').attr(\n 'disabled',\n 'true'\n );\n $('#id_itemsettings_popup .atto_media_button').attr(\n 'disabled',\n 'true'\n );\n $('#id_itemsettings_popup .atto_managefiles_button').attr(\n 'disabled',\n 'true'\n );\n var title = M.util.get_string('additemsettings', 'qtype_gapfill');\n /* The html jquery call will turn any encoded entities such as > to html, i.e. > */\n title +=\n ': ' +\n $('
')\n .html(item.stripdelim())\n .text();\n require(['jquery', 'jqueryui'], function($) {\n $('#id_itemsettings_popup').dialog({\n position: {\n my: 'right',\n at: 'right',\n of: '#id_itemsettings_canvas',\n },\n height: 500,\n width: '70%',\n modal: false,\n title: title,\n buttons: [\n {\n text: 'OK',\n click: function() {\n var JSONstr = item.updateJson(e);\n $('[class^=atto_]').removeAttr('disabled');\n $(\"[name='itemsettings']\").val(JSONstr);\n $('.ui-dialog-content').dialog('close');\n /* Set editable to true as it is checked at the start of click */\n $('#id_questiontexteditable').attr(\n 'contenteditable',\n 'true'\n );\n $('#id_itemsettings_button').click();\n },\n },\n ],\n });\n });\n }\n });\n\n /**\n * Convert an object to an array\n * @param {object} obj\n * @return {array}\n */\n function toArray(obj) {\n var arr = [];\n for (var i = 0, iLen = obj.length; i < iLen; i++) {\n arr.push(obj[i]);\n }\n return arr;\n }\n\n // Wrap the words of an element and child elements in a span.\n // Recurs over child elements, add an ID and class to the wrapping span.\n // Does not affect elements with no content, or those to be excluded.\n var wrapContent = (function() {\n return function(el) {\n var count = 0;\n var gaps = [];\n // If element provided, start there, otherwise use the body.\n el = el && el.parentNode ? el : document.body;\n // Get all child nodes as a static array.\n var node,\n nodes = toArray(el.childNodes);\n if (el.id === 'id_questiontextfeedback' && count > 0) {\n count = 0;\n }\n var frag, text;\n var delimitchars = $('#id_delimitchars').val();\n var l = delimitchars.substring(0, 1);\n var r = delimitchars.substring(1, 2);\n var regex = new RegExp('(\\\\' + l + '.*?\\\\' + r + ')', 'g');\n var sp,\n span = document.createElement('span');\n // Tag names of elements to skip, there are more to add.\n var skip = {\n script: '',\n button: '',\n input: '',\n select: '',\n textarea: '',\n option: '',\n };\n // For each child node...\n for (var i = 0, iLen = nodes.length; i < iLen; i++) {\n node = nodes[i];\n // If it's an element, call wrapContent.\n if (node.nodeType === 1 && !(node.tagName.toLowerCase() in skip)) {\n wrapContent(node);\n // If it's a text node, wrap words.\n } else if (node.nodeType === 3) {\n var textsplit = new RegExp('(\\\\' + l + '.*?\\\\' + r + ')', 'g');\n text = node.data.split(textsplit);\n if (text) {\n // Create a fragment, handy suckers these.\n frag = document.createDocumentFragment();\n for (var j = 0, jLen = text.length; j < jLen; j++) {\n // If not whitespace, wrap it and append to the fragment.\n doGap(text, span, j);\n }\n }\n // Replace the original node with the fragment.\n node.parentNode.replaceChild(frag, node);\n }\n }\n /**\n * Process each gap\n *\n * @param {*} text\n * @param {*} span\n * @param {*} j\n */\n function doGap(text, span, j) {\n gaps = [];\n if (regex.test(text[j])) {\n sp = span.cloneNode(false);\n count++;\n sp.className = 'item';\n var item = new Item(text[j], $('#id_delimitchars').val());\n if (item.gaptext > '') {\n var instance = 0;\n for (var k = 0; k < gaps.length; ++k) {\n if (gaps[k] === item.text) {\n instance++;\n }\n }\n item.id = 'id' + count + '_' + instance;\n sp.id = item.id;\n var is = item.getItemSettings(item);\n if (item.striptags(is.correctfeedback) > '') {\n sp.className = 'hascorrect';\n }\n if (item.striptags(is.incorrectfeedback) > '') {\n sp.className = sp.className + ' ' + 'hasnocorrect';\n }\n gaps.push(item.gaptext);\n }\n sp.appendChild(document.createTextNode(text[j]));\n frag.appendChild(sp);\n // Otherwise, just append it to the fragment.\n } else {\n frag.appendChild(document.createTextNode(text[j]));\n }\n }\n };\n })();\n /**\n *\n * @param {array} source\n * @return {array} product\n */\n function copyStyles(source) {\n // The map to return with requested styles and values as KVP.\n var product = {};\n // The style object from the DOM element we need to iterate through.\n var style;\n // Recycle the name of the style attribute.\n var name;\n // Prevent from empty selector.\n if (source.length) {\n // Otherwise, we need to get everything.\n var dom = source.get(0);\n if (window.getComputedStyle) {\n // Convenience methods to turn css case ('background-image') to camel ('backgroundImage').\n var pattern = /-([a-z])/g;\n var uc = function(a, b) {\n return b.toUpperCase();\n };\n var camelize = function(string) {\n return string.replace(pattern, uc);\n };\n // Make sure we're getting a good reference.\n if ((style = window.getComputedStyle(dom, null))) {\n var camel, value;\n for (var i = 0, l = style.length; i < l; i++) {\n name = style[i];\n camel = camelize(name);\n value = style.getPropertyValue(name);\n product[camel] = value;\n }\n } else if ((style = dom.currentStyle)) {\n for (name in style) {\n product[name] = style[name];\n }\n } else if ((style = dom.style)) {\n for (name in style) {\n if (typeof style[name] != 'function') {\n product[name] = style[name];\n }\n }\n }\n return product;\n }\n }\n return false;\n }\n },\n };\n});\n"],"file":"questionedit.min.js"} \ No newline at end of file +{"version":3,"sources":["../src/questionedit.js"],"names":["define","$","Item","init","change","selected","val","prop","on","attoIsLive","length","css","display","color","innerHTML","M","util","get_string","attr","get","isContentEditable","find","settingformheight","settingformwidth","copyStyles","ed","closest","appendTo","background","html","height","width","wrapContent","backgroundColor","removeAttr","e","target","id","match","delimitchars","item","itemsettings","getItemSettings","correctfeedback","incorrectfeedback","text","title","stripdelim","require","dialog","position","my","at","of","modal","buttons","click","JSONstr","updateJson","toArray","obj","arr","i","iLen","push","el","count","gaps","parentNode","document","body","node","nodes","childNodes","frag","l","substring","r","regex","RegExp","sp","span","createElement","skip","script","button","input","select","textarea","option","nodeType","tagName","toLowerCase","textsplit","data","split","createDocumentFragment","j","jLen","doGap","replaceChild","test","cloneNode","className","gaptext","instance","k","is","striptags","appendChild","createTextNode","source","product","style","name","dom","window","getComputedStyle","uc","a","b","toUpperCase","camelize","string","replace","camel","value","getPropertyValue","currentStyle"],"mappings":"AAyBAA,OAAM,8BAAC,CAAC,QAAD,CAAW,oBAAX,CAAD,CAAmC,SAASC,CAAT,CAAYC,CAAZ,CAAkB,CACzD,MAAO,CACLC,IAAI,CAAE,eAAW,CACfF,CAAC,CAAC,mBAAD,CAAD,CAAuBG,MAAvB,CAA8B,UAAW,CACvC,GAAIC,CAAAA,CAAQ,CAAGJ,CAAC,CAAC,IAAD,CAAD,CAAQK,GAAR,EAAf,CACA,GAAgB,SAAZ,EAAAD,CAAJ,CAA2B,CACzBJ,CAAC,CAAC,kBAAD,CAAD,CAAsBM,IAAtB,CAA2B,UAA3B,KACAN,CAAC,CAAC,sBAAD,CAAD,CAA0BM,IAA1B,CAA+B,UAA/B,KAAgDA,IAAhD,CAAqD,SAArD,KACAN,CAAC,CAAC,eAAD,CAAD,CAAmBM,IAAnB,CAAwB,UAAxB,KAAyCA,IAAzC,CAA8C,SAA9C,IACD,CACD,GAAgB,UAAZ,EAAAF,CAAJ,CAA4B,CAC1BJ,CAAC,CAAC,sBAAD,CAAD,CAA0BM,IAA1B,CAA+B,UAA/B,KACAN,CAAC,CAAC,eAAD,CAAD,CAAmBM,IAAnB,CAAwB,UAAxB,KACAN,CAAC,CAAC,kBAAD,CAAD,CAAsBM,IAAtB,CAA2B,UAA3B,IACD,CACD,GAAgB,UAAZ,EAAAF,CAAJ,CAA4B,CAC1BJ,CAAC,CAAC,kBAAD,CAAD,CAAsBM,IAAtB,CAA2B,UAA3B,KAA4CA,IAA5C,CAAiD,SAAjD,KACAN,CAAC,CAAC,sBAAD,CAAD,CAA0BM,IAA1B,CAA+B,UAA/B,KAAgDA,IAAhD,CAAqD,SAArD,KACAN,CAAC,CAAC,eAAD,CAAD,CAAmBM,IAAnB,CAAwB,UAAxB,KAAyCA,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B,CAAkCoD,CAAC,CAAGa,CAAtC,CAAyCb,CAAC,EAA1C,CAA8C,CAC5CoD,CAAI,CAAGD,CAAK,CAACnD,CAAD,CAAZ,CACA+D,CAAK,CAAGH,CAAQ,CAACR,CAAD,CAAhB,CACAY,CAAK,CAAGb,CAAK,CAACc,gBAAN,CAAuBb,CAAvB,CAAR,CACAF,CAAO,CAACa,CAAD,CAAP,CAAiBC,CAClB,CACF,CARD,IAQO,IAAKb,CAAK,CAAGE,CAAG,CAACa,YAAjB,CAAgC,CACrC,IAAKd,CAAL,GAAaD,CAAAA,CAAb,CAAoB,CAClBD,CAAO,CAACE,CAAD,CAAP,CAAgBD,CAAK,CAACC,CAAD,CACtB,CACF,CAJM,IAIA,IAAKD,CAAK,CAAGE,CAAG,CAACF,KAAjB,CAAyB,CAC9B,IAAKC,CAAL,GAAaD,CAAAA,CAAb,CAAoB,CAClB,GAA0B,UAAtB,QAAOA,CAAAA,CAAK,CAACC,CAAD,CAAhB,CAAsC,CACpCF,CAAO,CAACE,CAAD,CAAP,CAAgBD,CAAK,CAACC,CAAD,CACtB,CACF,CACF,CACD,MAAOF,CAAAA,CACR,CACF,CACD,QACD,CACF,CArVI,CAuVR,CAxVK,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 * JavaScript code for the gapfill question type.\n *\n * @package qtype_gapfill\n * @copyright 2017 Marcus Green\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\n\n/* The data is stored in a hidden field */\ndefine(['jquery', 'qtype_gapfill/Item'], function($, Item) {\n return {\n init: function() {\n $('#id_answerdisplay').change(function() {\n var selected = $(this).val();\n if (selected == 'gapfill') {\n $('#id_fixedgapsize').prop('disabled',false);\n $(\"#id_optionsaftertext\").prop('disabled',true).prop('checked',false);\n $('#id_singleuse').prop('disabled',true).prop('checked', false);\n }\n if (selected == 'dragdrop') {\n $('#id_optionsaftertext').prop('disabled',false);\n $('#id_singleuse').prop('disabled',false);\n $('#id_fixedgapsize').prop('disabled',false);\n }\n if (selected == 'dropdown') {\n $('#id_fixedgapsize').prop('disabled',true).prop('checked',false);\n $('#id_optionsaftertext').prop('disabled',true).prop('checked',false);\n $('#id_singleuse').prop('disabled',true).prop('checked',false);\n }\n\n\n\n\n });\n /* A click on the itemsettings button */\n $('#id_itemsettings_button').on('click', function() {\n var attoIsLive = $('.editor_atto').length;\n /* Show error if Atto is not loaded. It might be because the page has not finished loading\n * or because plain text elements are being used or (perhaps less likely as time goes on)\n * the HTMLarea editor is being used. It might be possible to work with those other editors\n * but limiting to Atto keeps things straightforward and maintainable.\n */\n if (attoIsLive < 1) {\n $('#id_error_itemsettings_button').css({\n display: 'inline',\n color: 'red',\n });\n $('#id_error_itemsettings_button')[0].innerHTML = M.util.get_string(\n 'itemsettingserror',\n 'qtype_gapfill'\n );\n return;\n }\n $('#questiontext .atto_html_button').attr('disabled', 'true');\n if ($('#id_questiontexteditable').get(0).isContentEditable) {\n $('#id_questiontexteditable').attr('contenteditable', 'false');\n $('#fitem_id_questiontext')\n .find('button')\n .attr('disabled', 'true');\n var settingformheight = $('#id_questiontexteditable').css('height');\n var settingformwidth = $('#id_questiontexteditable').css('width');\n $('#id_questiontexteditable').css('display', 'none');\n /* Copy the styles from attos editable area so the canvas looks the same (except gray) */\n $('#id_itemsettings_canvas').css(\n copyStyles($('#id_questiontexteditable'))\n );\n var ed = $('#id_questiontexteditable').closest(\n '.editor_atto_content_wrap'\n );\n $('#id_itemsettings_canvas')\n .appendTo(ed)\n .css('position', 'relative');\n $('#id_itemsettings_canvas').css({\n display: 'block',\n background: 'lightgrey',\n });\n\n /* Copy the real html to the feedback editing html */\n $('#id_itemsettings_canvas').html(\n $('#id_questiontexteditable').prop('innerHTML')\n );\n $('#id_itemsettings_canvas').css({\n height: settingformheight,\n width: settingformwidth,\n });\n $('#id_itemsettings_canvas').css({height: '100%', width: '100%'});\n $('#id_itemsettings_button').html(\n M.util.get_string('editquestiontext', 'qtype_gapfill')\n );\n /* Setting the height by hand gets around a quirk of MSIE */\n $('#id_itemsettings_canvas').height(\n $('#id_questiontexteditable').height()\n );\n /* Disable the buttons on questiontext but not on the feedback form */\n /* wrapContent should be the last on this block as it sometimes falls over with an error */\n wrapContent($('#id_itemsettings_canvas')[0]);\n } else {\n $('#id_questiontexteditable').css({\n display: 'block',\n backgroundColor: 'white',\n });\n $('#id_questiontexteditable').attr('contenteditable', 'true');\n $('#id_itemsettings_canvas').css('display', 'none');\n $('#fitem_id_questiontext')\n .find('button')\n .removeAttr('disabled');\n $('#id_settings_popup').css('display', 'none');\n $('#id_itemsettings_button').html(\n M.util.get_string('additemsettings', 'qtype_gapfill')\n );\n $('[class^=atto_]').removeAttr('disabled');\n }\n });\n\n /* A click on the text */\n $('#id_itemsettings_canvas').on('click', function(e) {\n /*\n * Questiontext needs to be edditable and the target must start\n * with id followed by one or more digits and an underscore\n * */\n if (\n !$('#id_questiontexteditable').get(0).isContentEditable &&\n e.target.id.match(/^id[0-9]+_/)\n ) {\n var delimitchars = $('#id_delimitchars').val();\n var item = new Item(e.target.innerHTML, delimitchars);\n\n // Var item = new Item(e.target.innerHTML, delimitchars);\n var itemsettings = item.getItemSettings(e.target);\n if (itemsettings === null || itemsettings.length === 0) {\n $('#id_correcteditable').html('');\n $('#id_incorrecteditable').html('');\n } else {\n $('#id_correcteditable').html(itemsettings.correctfeedback);\n $('#id_incorrecteditable').html(itemsettings.incorrectfeedback);\n }\n $(\"label[for*='id_correct']\").text(\n M.util.get_string('correct', 'qtype_gapfill')\n );\n $(\"label[for*='id_incorrect']\").text(\n M.util.get_string('incorrect', 'qtype_gapfill')\n );\n $('#id_itemsettings_popup .atto_image_button').attr(\n 'disabled',\n 'true'\n );\n $('#id_itemsettings_popup .atto_media_button').attr(\n 'disabled',\n 'true'\n );\n $('#id_itemsettings_popup .atto_managefiles_button').attr(\n 'disabled',\n 'true'\n );\n var title = M.util.get_string('additemsettings', 'qtype_gapfill');\n /* The html jquery call will turn any encoded entities such as > to html, i.e. > */\n title +=\n ': ' +\n $('
')\n .html(item.stripdelim())\n .text();\n require(['jquery', 'jqueryui'], function($) {\n $('#id_itemsettings_popup').dialog({\n position: {\n my: 'right',\n at: 'right',\n of: '#id_itemsettings_canvas',\n },\n height: 500,\n width: '70%',\n modal: false,\n title: title,\n buttons: [\n {\n text: 'OK',\n click: function() {\n var JSONstr = item.updateJson(e);\n $('[class^=atto_]').removeAttr('disabled');\n $(\"[name='itemsettings']\").val(JSONstr);\n $('.ui-dialog-content').dialog('close');\n /* Set editable to true as it is checked at the start of click */\n $('#id_questiontexteditable').attr(\n 'contenteditable',\n 'true'\n );\n $('#id_itemsettings_button').click();\n },\n },\n ],\n });\n });\n }\n });\n\n /**\n * Convert an object to an array\n * @param {object} obj\n * @return {array}\n */\n function toArray(obj) {\n var arr = [];\n for (var i = 0, iLen = obj.length; i < iLen; i++) {\n arr.push(obj[i]);\n }\n return arr;\n }\n\n // Wrap the words of an element and child elements in a span.\n // Recurs over child elements, add an ID and class to the wrapping span.\n // Does not affect elements with no content, or those to be excluded.\n var wrapContent = (function() {\n return function(el) {\n var count = 0;\n var gaps = [];\n // If element provided, start there, otherwise use the body.\n el = el && el.parentNode ? el : document.body;\n // Get all child nodes as a static array.\n var node,\n nodes = toArray(el.childNodes);\n if (el.id === 'id_questiontextfeedback' && count > 0) {\n count = 0;\n }\n var frag, text;\n var delimitchars = $('#id_delimitchars').val();\n var l = delimitchars.substring(0, 1);\n var r = delimitchars.substring(1, 2);\n var regex = new RegExp('(\\\\' + l + '.*?\\\\' + r + ')', 'g');\n var sp,\n span = document.createElement('span');\n // Tag names of elements to skip, there are more to add.\n var skip = {\n script: '',\n button: '',\n input: '',\n select: '',\n textarea: '',\n option: '',\n };\n // For each child node...\n for (var i = 0, iLen = nodes.length; i < iLen; i++) {\n node = nodes[i];\n // If it's an element, call wrapContent.\n if (node.nodeType === 1 && !(node.tagName.toLowerCase() in skip)) {\n wrapContent(node);\n // If it's a text node, wrap words.\n } else if (node.nodeType === 3) {\n var textsplit = new RegExp('(\\\\' + l + '.*?\\\\' + r + ')', 'g');\n text = node.data.split(textsplit);\n if (text) {\n // Create a fragment, handy suckers these.\n frag = document.createDocumentFragment();\n for (var j = 0, jLen = text.length; j < jLen; j++) {\n // If not whitespace, wrap it and append to the fragment.\n doGap(text, span, j);\n }\n }\n // Replace the original node with the fragment.\n node.parentNode.replaceChild(frag, node);\n }\n }\n /**\n * Process each gap\n *\n * @param {*} text\n * @param {*} span\n * @param {*} j\n */\n function doGap(text, span, j) {\n gaps = [];\n if (regex.test(text[j])) {\n sp = span.cloneNode(false);\n count++;\n sp.className = 'item';\n var item = new Item(text[j], $('#id_delimitchars').val());\n if (item.gaptext > '') {\n var instance = 0;\n for (var k = 0; k < gaps.length; ++k) {\n if (gaps[k] === item.text) {\n instance++;\n }\n }\n item.id = 'id' + count + '_' + instance;\n sp.id = item.id;\n var is = item.getItemSettings(item);\n if (item.striptags(is.correctfeedback) > '') {\n sp.className = 'hascorrect';\n }\n if (item.striptags(is.incorrectfeedback) > '') {\n sp.className = sp.className + ' ' + 'hasnocorrect';\n }\n gaps.push(item.gaptext);\n }\n sp.appendChild(document.createTextNode(text[j]));\n frag.appendChild(sp);\n // Otherwise, just append it to the fragment.\n } else {\n frag.appendChild(document.createTextNode(text[j]));\n }\n }\n };\n })();\n /**\n *\n * @param {array} source\n * @return {array} product\n */\n function copyStyles(source) {\n // The map to return with requested styles and values as KVP.\n var product = {};\n // The style object from the DOM element we need to iterate through.\n var style;\n // Recycle the name of the style attribute.\n var name;\n // Prevent from empty selector.\n if (source.length) {\n // Otherwise, we need to get everything.\n var dom = source.get(0);\n if (window.getComputedStyle) {\n // Convenience methods to turn css case ('background-image') to camel ('backgroundImage').\n var pattern = /-([a-z])/g;\n var uc = function(a, b) {\n return b.toUpperCase();\n };\n var camelize = function(string) {\n return string.replace(pattern, uc);\n };\n // Make sure we're getting a good reference.\n if ((style = window.getComputedStyle(dom, null))) {\n var camel, value;\n for (var i = 0, l = style.length; i < l; i++) {\n name = style[i];\n camel = camelize(name);\n value = style.getPropertyValue(name);\n product[camel] = value;\n }\n } else if ((style = dom.currentStyle)) {\n for (name in style) {\n product[name] = style[name];\n }\n } else if ((style = dom.style)) {\n for (name in style) {\n if (typeof style[name] != 'function') {\n product[name] = style[name];\n }\n }\n }\n return product;\n }\n }\n return false;\n }\n },\n };\n});\n"],"file":"questionedit.min.js"} \ No newline at end of file diff --git a/amd/src/dragdrop.js b/amd/src/dragdrop.js index cac2fed5..40dda2c9 100755 --- a/amd/src/dragdrop.js +++ b/amd/src/dragdrop.js @@ -21,16 +21,22 @@ * @copyright 2020 Marcus Green * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -define(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], function ($) { +define(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], function($) { return { - init: function (singleuse) { - $(".droptarget").on('dblclick', function () { + init: function(singleuse) { + $(".droptarget").on('dblclick', function() { if (singleuse) { dragShow(this); $(this).val(""); } }); + /** + * Reveal draggables that are not + * the the current one + * + * @param {*} that + */ function dragShow(that) { var draggables = $(".draggable"); var targetVal = $(that).val(); @@ -43,7 +49,7 @@ define(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], f } } - $(".droptarget").on('keydown drop', function () { + $(".droptarget").on('keydown drop', function() { dragShow(this); }); @@ -56,7 +62,7 @@ define(['jquery', 'jqueryui', 'qtype_gapfill/jquery.ui.touch-punch-improved'], f $(".droptarget").droppable({ hoverClass: 'active', - drop: function (event, ui) { + drop: function(event, ui) { if ($(ui.draggable).hasClass('readonly')) { return; } diff --git a/amd/src/questionedit.js b/amd/src/questionedit.js index f29e0385..2d21bdf6 100755 --- a/amd/src/questionedit.js +++ b/amd/src/questionedit.js @@ -26,20 +26,19 @@ define(['jquery', 'qtype_gapfill/Item'], function($, Item) { return { init: function() { - $('#id_answerdisplay').change(function(evt) { - debugger; + $('#id_answerdisplay').change(function() { var selected = $(this).val(); - if(selected == 'gapfill'){ + if (selected == 'gapfill') { $('#id_fixedgapsize').prop('disabled',false); $("#id_optionsaftertext").prop('disabled',true).prop('checked',false); $('#id_singleuse').prop('disabled',true).prop('checked', false); } - if(selected == 'dragdrop'){ + if (selected == 'dragdrop') { $('#id_optionsaftertext').prop('disabled',false); $('#id_singleuse').prop('disabled',false); $('#id_fixedgapsize').prop('disabled',false); } - if(selected == 'dropdown'){ + if (selected == 'dropdown') { $('#id_fixedgapsize').prop('disabled',true).prop('checked',false); $('#id_optionsaftertext').prop('disabled',true).prop('checked',false); $('#id_singleuse').prop('disabled',true).prop('checked',false);