', {
'class': 'h5p-question-explanation-text',
html: feedback.text,
appendTo: $explanationItem
});
}
}
};
createHTML();
/**
* Return the container HTMLElement
*
* @return {HTMLElement}
*/
self.getElement = function () {
return self.$explanation;
};
}
return Explainer;
})(H5P.jQuery);
;
(function (Question) {
/**
* Makes it easy to add animated score points for your question type.
*
* @class H5P.Question.ScorePoints
*/
Question.ScorePoints = function () {
var self = this;
var elements = [];
var showElementsTimer;
/**
* Create the element that displays the score point element for questions.
*
* @param {boolean} isCorrect
* @return {HTMLElement}
*/
self.getElement = function (isCorrect) {
var element = document.createElement('div');
element.classList.add(isCorrect ? 'h5p-question-plus-one' : 'h5p-question-minus-one');
element.classList.add('h5p-question-hidden-one');
elements.push(element);
// Schedule display animation of all added elements
if (showElementsTimer) {
clearTimeout(showElementsTimer);
}
showElementsTimer = setTimeout(showElements, 0);
return element;
};
/**
* @private
*/
var showElements = function () {
// Determine delay between triggering animations
var delay = 0;
var increment = 150;
var maxTime = 1000;
if (elements.length && elements.length > Math.ceil(maxTime / increment)) {
// Animations will run for more than ~1 second, reduce it.
increment = maxTime / elements.length;
}
for (var i = 0; i < elements.length; i++) {
// Use timer to trigger show
setTimeout(showElement(elements[i]), delay);
// Increse delay for next element
delay += increment;
}
};
/**
* Trigger transition animation for the given element
*
* @private
* @param {HTMLElement} element
* @return {function}
*/
var showElement = function (element) {
return function () {
element.classList.remove('h5p-question-hidden-one');
};
};
};
})(H5P.Question);
;
var H5P = H5P || {};
/**
* Constructor.
*
* @param {Object} params Options for this library.
* @param {Number} id Content identifier
* @returns {undefined}
*/
(function ($) {
H5P.Image = function (params, id, extras) {
H5P.EventDispatcher.call(this);
this.extras = extras;
if (params.file === undefined || !(params.file instanceof Object)) {
this.placeholder = true;
}
else {
this.source = H5P.getPath(params.file.path, id);
this.width = params.file.width;
this.height = params.file.height;
}
this.alt = (!params.decorative && params.alt !== undefined) ?
this.stripHTML(this.htmlDecode(params.alt)) :
'';
if (params.title !== undefined) {
this.title = this.stripHTML(this.htmlDecode(params.title));
}
};
H5P.Image.prototype = Object.create(H5P.EventDispatcher.prototype);
H5P.Image.prototype.constructor = H5P.Image;
/**
* Wipe out the content of the wrapper and put our HTML in it.
*
* @param {jQuery} $wrapper
* @returns {undefined}
*/
H5P.Image.prototype.attach = function ($wrapper) {
var self = this;
var source = this.source;
if (self.$img === undefined) {
if(self.placeholder) {
self.$img = $('
', {
width: '100%',
height: '100%',
class: 'h5p-placeholder',
title: this.title === undefined ? '' : this.title,
on: {
load: function () {
self.trigger('loaded');
}
}
});
} else {
self.$img = $('
![]()
', {
width: '100%',
height: '100%',
src: source,
alt: this.alt,
title: this.title === undefined ? '' : this.title,
on: {
load: function () {
self.trigger('loaded');
}
}
});
}
}
$wrapper.addClass('h5p-image').html(self.$img);
};
/**
* Retrieve decoded HTML encoded string.
*
* @param {string} input HTML encoded string.
* @returns {string} Decoded string.
*/
H5P.Image.prototype.htmlDecode = function (input) {
const dparser = new DOMParser().parseFromString(input, 'text/html');
return dparser.documentElement.textContent;
};
/**
* Retrieve string without HTML tags.
*
* @param {string} input Input string.
* @returns {string} Output string.
*/
H5P.Image.prototype.stripHTML = function (html) {
const div = document.createElement('div');
div.innerHTML = html;
return div.textContent || div.innerText || '';
};
return H5P.Image;
}(H5P.jQuery));
;
!function(){"use strict";var t=function(){function t(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;this.params=t,this.callbacks=e||{},this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-clue-announcer"),this.clueId=document.createElement("span"),this.clueId.classList.add("h5p-crossword-clue-announcer-clue-id"),this.content.appendChild(this.clueId),this.clue=document.createElement("span"),this.clue.classList.add("h5p-crossword-clue-announcer-clue"),this.content.appendChild(this.clue),this.answerLength=document.createElement("span"),this.answerLength.classList.add("h5p-crossword-clue-announcer-answer-length"),this.content.appendChild(this.answerLength)}var e=t.prototype;return e.getDOM=function(){return this.content},e.setClue=function(t){t.orientation&&t.clueId&&t.clue&&t.answerLength&&(this.clueId.innerText="".concat(t.clueId," ").concat(t.orientation),this.clue.innerText=t.clue,this.answerLength.innerText="(".concat(t.answerLength,")"))},e.show=function(){this.content.classList.remove("h5p-crossword-display-none")},e.hide=function(){this.content.classList.add("h5p-crossword-display-none")},e.reset=function(){this.clueId.innerText="",this.clue.innerText="",this.answerLength.innerText=""},t}();function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var n=function(){function t(){}return t.extend=function(){for(var t=1;t
1)for(var r=Array.prototype.slice.call(arguments,1);o--;)n[e-1-o]=t.createArray.apply(this,r);return n},t.shuffleArray=function(t){var e,n,o;for(o=t.length-1;o>0;o--)e=Math.floor(Math.random()*(o+1)),n=t[o],t[o]=t[e],t[e]=n;return t},t.formatLanguageCode=function(t){if("string"!=typeof t)return t;var e=t.split("-");return e[0]=e[0].toLowerCase(),e.length>1&&(e[1]=e[1].toUpperCase()),t=e.join("-")},t.toUpperCase=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return"string"!=typeof t?null:("string"==typeof e&&(e=e.split("").map((function(t){return{lowerCase:t,upperCase:t}}))),Array.isArray(e)||(e=[]),(e=e.filter((function(t){return"string"==typeof t.lowerCase&&1===t.lowerCase.length&&"string"==typeof t.upperCase&&1===t.upperCase.length}))).forEach((function(e,n){for(;-1!==t.indexOf(e.lowerCase);)t=t.replace(e.lowerCase,"[CROSSWORDPLACEHOLDER".concat(n,"]"))})),t=t.toUpperCase(),e.forEach((function(e,n){for(;-1!==t.indexOf("[CROSSWORDPLACEHOLDER".concat(n,"]"));)t=t.replace("[CROSSWORDPLACEHOLDER".concat(n,"]"),e.upperCase)})),t)},t.waitForDOM=function(t,e){var n=this,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:function(){},r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:50,s=arguments.length>4&&void 0!==arguments[4]?arguments[4]:100;if(0!==r&&t&&"function"==typeof e&&"function"==typeof o){s=Math.max(s,50);var i=document.querySelector(t);i?e():setTimeout((function(){n.waitForDOM(t,e,o,r<0?-1:r-1,s)}),s)}else o()},t}();n.CONTROL_KEY_CODES=[8,9,13,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46,91,92,93,112,113,114,115,116,117,118,119,120,121,122,123,144,145],n.UPPERCASE_EXCEPTIONS=[{lowerCase:"ß",upperCase:"ẞ"}],n.CHARACTER_PLACEHOLDER="_";var o=n,r=function(){function t(t){var e=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.params=o.extend({container:document.body,content:document.createElement("div"),styleBase:"h5p-crossword-overlay",position:{offsetHorizontal:0,offsetVertical:0},l10n:{closeWindow:"Close"}},t),this.callbacks=n,this.callbacks.onClose=n.onClose||function(){},this.callbacks.onRead=n.onRead||function(){},this.isVisible=!1,this.focusableElements=[],this.overlay=document.createElement("div"),this.overlay.classList.add("".concat(this.params.styleBase,"-outer-wrapper")),this.overlay.classList.add("h5p-crossword-invisible"),this.overlay.setAttribute("role","dialog"),this.params.l10n.title&&this.overlay.setAttribute("aria-label",this.params.l10n.title),this.overlay.setAttribute("aria-modal","true"),this.content=document.createElement("div"),this.content.classList.add("".concat(this.params.styleBase,"-content")),this.content.appendChild(this.params.content),this.buttonClose=document.createElement("button"),this.buttonClose.classList.add("".concat(this.params.styleBase,"-button-close")),this.buttonClose.setAttribute("title",this.params.l10n.closeWindow),this.buttonClose.addEventListener("click",(function(){e.callbacks.onClose()})),this.overlay.appendChild(this.buttonClose),this.overlay.appendChild(this.content),document.addEventListener("focus",(function(t){e.isVisible&&0!==e.focusableElements.length&&e.trapFocus(t)}),!0),this.blocker=document.createElement("div"),this.blocker.classList.add("h5p-crossword-overlay-blocker"),this.blocker.classList.add("h5p-crossword-display-none")}var e=t.prototype;return e.getDOM=function(){return this.overlay},e.setContent=function(t){for(;this.content.firstChild;)this.content.removeChild(this.content.firstChild);this.content.appendChild(t),this.content.scrollTop=0},e.trapFocus=function(t){this.isChild(t.target)?this.currentFocusElement=t.target:(this.currentFocusElement===this.focusableElements[0]?this.currentFocusElement=this.focusableElements[this.focusableElements.length-1]:this.currentFocusElement=this.focusableElements[0],this.currentFocusElement.focus())},e.isChild=function(t){var e=t.parentNode;return!!e&&(e===this.overlay||this.isChild(e))},e.updateFocusableElements=function(){this.focusableElements=[].slice.call(this.overlay.querySelectorAll('video, audio, button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter((function(t){return"true"!==t.getAttribute("disabled")&&!0!==t.getAttribute("disabled")}))},e.show=function(){var t=this;this.blockerAppended||(this.container=document.body.querySelector(".h5p-container"),this.container.appendChild(this.blocker)),this.blockerAppended=!0,this.overlay.classList.remove("h5p-crossword-invisible"),this.blocker.classList.remove("h5p-crossword-display-none"),setTimeout((function(){t.updateFocusableElements(),t.focusableElements.length>0&&t.focusableElements[0].focus();var e,n=t.overlay.querySelector(".h5p-advanced-text");n?t.callbacks.onRead(n.innerText):e=t.overlay.querySelector(".h5p-image > img"),e&&t.callbacks.onRead(e.getAttribute("alt")||""),t.isVisible=!0,t.resize()}),0)},e.hide=function(){this.isVisible=!1,this.overlay.classList.add("h5p-crossword-invisible"),this.blocker.classList.add("h5p-crossword-display-none")},e.resize=function(){this.container&&(this.content.style.maxHeight="calc(".concat(this.container.offsetHeight,"px - ").concat(t.CONTENT_MARGIN,")"))},t}();r.CONTENT_MARGIN="7em";var s=function(){function t(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.params=o.extend({a11y:{listLabel:""}},t),this.charMarked=null,this.content=this.buildListContainer({listLabel:this.params.a11y.listLabel})}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildListContainer=function(t){var e=this,n=document.createElement("div");n.classList.add("h5p-crossword-input-fields-group-solution-container"),n.classList.add("h5p-crossword-display-none");var o=document.createElement("div");return o.classList.add("h5p-crossword-input-fields-group-solution-inner"),n.appendChild(o),this.list=document.createElement("div"),this.list.classList.add("h5p-crossword-input-fields-group-solution-word"),this.list.setAttribute("role","list"),this.list.setAttribute("aria-label",t.listLabel),this.list.setAttribute("aria-expanded","false"),this.list.setAttribute("tabindex","0"),o.appendChild(this.list),this.list.addEventListener("keydown",(function(t){var n=e.charMarked||e.list.firstChild,o=e.list.getAttribute("aria-expanded");switch(t.code){case"Enter":case"Space":if(t.target!==t.currentTarget)return;"false"===o?(e.list.setAttribute("aria-expanded","true"),n&&(n.setAttribute("tabindex","0"),n.focus())):(e.list.setAttribute("aria-expanded","false"),n&&n.setAttribute("tabindex","-1"))}})),n},e.buildListItem=function(t){var e=this,n=document.createElement("span");n.classList.add("h5p-crossword-input-fields-group-solution-char-wrapper"),n.setAttribute("role","listitem"),n.setAttribute("tabindex","-1"),n.setAttribute("aria-label",t.ariaLabel),"neutral"===t.result?(n.classList.add("h5p-crossword-solution-no-input")," "!==t.char&&t.char!==o.CHARACTER_PLACEHOLDER||n.classList.add("h5p-crossword-solution-no-char")):"correct"===t.result?n.classList.add("h5p-crossword-solution-correct"):n.classList.add("h5p-crossword-solution-wrong"),t.scoreExplanation&&n.appendChild(t.scoreExplanation),n.addEventListener("focus",(function(t){e.charMarked=t.target})),n.addEventListener("keydown",(function(t){var e=t.target.parentNode.firstChild,n=t.target.parentNode.lastChild;switch(t.keyCode){case 37:case 38:t.preventDefault(),t.target.previousSibling&&(t.target.setAttribute("tabindex","-1"),t.target.previousSibling.setAttribute("tabindex","0"),t.target.previousSibling.focus());break;case 39:case 40:t.preventDefault(),t.target.nextSibling&&(t.target.setAttribute("tabindex","-1"),t.target.nextSibling.setAttribute("tabindex","0"),t.target.nextSibling.focus());break;case 36:t.preventDefault(),t.target!==e&&(t.target.setAttribute("tabindex","-1"),e.setAttribute("tabindex","0"),e.focus());break;case 35:t.preventDefault(),t.target!==n&&(t.target.setAttribute("tabindex","-1"),n.setAttribute("tabindex","0"),n.focus())}}));var r=document.createElement("span");return r.classList.add("h5p-crossword-input-fields-group-solution-char"),r.innerHTML=t.char&&" "!==t.char.trim()?o.toUpperCase(t.char,o.UPPERCASE_EXCEPTIONS):" ",n.appendChild(r),n},e.setChars=function(t){var e=this;this.reset(),t.forEach((function(t){e.list.appendChild(e.buildListItem(t))}))},e.show=function(){this.content.classList.remove("h5p-crossword-display-none")},e.hide=function(){this.content.classList.add("h5p-crossword-display-none")},e.enable=function(){if(this.tabindexState&&this.tabindexState.list&&this.list.setAttribute("tabindex",this.tabindexState.list),this.tabindexState&&this.tabindexState.listItems)for(var t=this.list.children,e=0;e=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:r}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,i=!0,l=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return i=t.done,t},e:function(t){l=!0,s=t},f:function(){try{i||null==n.return||n.return()}finally{if(l)throw s}}}}function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1?arguments[1]:void 0;this.params=o.extend({l10n:{extraClue:"Extra clue",closeWindow:"Close Window"}},e),this.callbacks=n||{},this.callbacks.onFieldInput=this.callbacks.onFieldInput||function(){},this.callbacks.onRead=n.onRead||function(){},this.inputFields=[],this.extraClues=[],this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-input-container");var s=this.buildInputFieldsGroup({words:this.params.words.filter((function(t){return"across"===t.orientation})),title:e.l10n.across});this.content.appendChild(s);var i=this.buildInputFieldsGroup({words:this.params.words.filter((function(t){return"down"===t.orientation})),title:e.l10n.down});this.content.appendChild(i),this.overlay=new r({l10n:{closeWindow:this.params.l10n.closeWindow}},{onClose:function(){t.handleOverlayClosed()},onRead:function(e){t.callbacks.onRead(e)}}),e.overlayContainer.appendChild(this.overlay.getDOM())}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildInputFieldsGroup=function(t){var e=this;t.words=t.words.sort((function(t,e){return t.orientation2&&void 0!==arguments[2]?arguments[2]:{forceValue:!0};e=o.toUpperCase(e,o.UPPERCASE_EXCEPTIONS);var r="";if(n.forceValue){r=e;var s=new Array(t.maxLength+1).join(o.CHARACTER_PLACEHOLDER);r=s.split("").map((function(t,e){return r.length>e&&" "!==r[e]?r[e]:t})).join("")}else{var a,l=i(e.split(""));try{for(l.s();!(a=l.n()).done;){var c=a.value;if(" "===c)break;r="".concat(r).concat(c)}}catch(t){l.e(t)}finally{l.f()}}t.value=o.toUpperCase(r,o.UPPERCASE_EXCEPTIONS)},e.buildAriaLabel=function(t){var e=["".concat(t.clueId," ").concat(this.params.a11y[t.orientation],". ").concat(t.clue)];return t.length&&e.push(this.params.a11y.lettersWord.replace("@length",t.length)),e.join(", ")},e.fillFields=function(t){var e=this;t.forEach((function(t){var n=e.inputFields.filter((function(e){return e.orientation===t.orientation&&e.clueId===t.clueId}));n.length>0&&e.setInputFieldValue(n[0].inputField,t.text)}))},e.focusClue=function(t){this.inputFields.forEach((function(t){t.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus")}));var e=this.inputFields.filter((function(e){return e.orientation===t.orientation&&e.clueId===t.clueId}));e.length>0&&e[0].clue.classList.add("h5p-crossword-input-fields-group-clue-highlight-focus")},e.checkAnswerWords=function(t){var e=this;this.scorePoints=this.scorePoints||new H5P.Question.ScorePoints,this.inputFields.forEach((function(n){n.solution.show();var r,s,i=t.filter((function(t){return t.clueId===n.clueId&&t.orientation===n.orientation})).shift(),a=[];a.push(i.answer),-1===i.score?(r=e.scorePoints.getElement(!1),s="wrong",a.push(e.params.a11y.wrong),a.push("-1 ".concat(e.params.a11y.point))):1===i.score?(r=e.scorePoints.getElement(!0),s="correct",a.push(e.params.a11y.correct),a.push("1 ".concat(e.params.a11y.point))):s="neutral",n.solution.setChars([{ariaLabel:"".concat(a.join(". "),"."),char:n.inputField.value.replace(o.CHARACTER_PLACEHOLDER," "),result:s,scoreExplanation:r}])}))},e.checkAnswer=function(t){var e=this;this.scorePoints=this.scorePoints||new H5P.Question.ScorePoints;var n=[];this.inputFields.forEach((function(r){r.solution.show();var s=t.filter((function(t){return"across"===r.orientation?t.clueIdAcross===r.clueId:"down"===r.orientation&&t.clueIdDown===r.clueId})),i=o.toUpperCase(r.inputField.value,o.UPPERCASE_EXCEPTIONS).split(""),a=[];s.forEach((function(t,r){var l=n.some((function(e){return e.row===t.position.row&&e.column===t.position.column}));n.push(t.position);var c,u,h=i.length>r?i[r]:" ";t.answer&&""!==t.answer.trim()&&t.answer!==o.CHARACTER_PLACEHOLDER?t.answer===t.solution?(c="correct",l||(u=e.scorePoints.getElement(!0))):e.params.applyPenalties?(c="wrong",l||(u=e.scorePoints.getElement(!1))):c="neutral":c="neutral";var d=[];d.push("".concat(e.params.a11y.letterSevenOfNine.replace("@position",r+1).replace("@length",s.length))),d.push(t.answer&&""!==t.answer.trim()?t.answer:e.params.a11y.empty),"correct"===c?(d.push(e.params.a11y.correct),d.push("1 ".concat(e.params.a11y.point))):"wrong"===c&&(d.push(e.params.a11y.wrong),d.push("-1 ".concat(e.params.a11y.point))),a.push({ariaLabel:"".concat(d.join(". "),"."),char:h.replace(o.CHARACTER_PLACEHOLDER," ")||" ",result:c,scoreExplanation:u})})),r.solution.setChars(a)}))},e.showSolutions=function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.inputFields.forEach((function(n){var o=e.filter((function(t){return t.clueId===n.clueId&&t.orientation===n.orientation}));if(o&&0!==o.length){o=o[0],t.setInputFieldValue(n.inputField,o.answer),n.inputField.readOnly=!0,n.inputField.removeAttribute("disabled");var r=t.params.a11y.solutionFor.replace("@clue","".concat(o.clueId," ").concat(t.params.a11y[o.orientation],". ").concat(o.clue," .")).replace("@solution",o.answer);n.inputField.setAttribute("aria-label",r),n.solution.disable()}}))},e.reset=function(){var t=this;this.inputFields.forEach((function(e){t.setInputFieldValue(e.inputField,""),e.inputField.readOnly=!1,e.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus"),e.solution.hide(),e.solution.reset()}))},e.resize=function(){this.extraClueInstance&&this.extraClueInstance.trigger("resize"),this.overlay.resize()},e.enable=function(){this.inputFields.forEach((function(t){t.inputField.removeAttribute("disabled")})),this.extraClues.forEach((function(t){t.removeAttribute("disabled")})),this.content.classList.remove("h5p-crossword-disabled"),this.disabled=!1},e.disable=function(){this.disabled=!0,this.extraClues.forEach((function(t){t.setAttribute("disabled",!0)})),this.content.classList.add("h5p-crossword-disabled"),this.inputFields.forEach((function(t){t.inputField.setAttribute("disabled",!0)}))},e.unhighlight=function(){this.inputFields.forEach((function(t){t.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus")}))},e.handleOverlayClosed=function(){this.extraClueInstance&&"function"==typeof this.extraClueInstance.pause&&this.extraClueInstance.pause(),this.overlay.hide(),this.enable(),this.previousFocus&&this.previousFocus.focus(),this.previousFocus=null},t}(),c=function(){function t(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.params=o.extend({instantFeedback:!1,clueIdMarker:null,solution:null},e),this.callbacks=n||{},this.callbacks.onClick=n.onClick||function(){},this.callbacks.onFocus=n.onFocus||function(){},this.callbacks.onKeyup=n.onKeyup||function(){},this.callbacks.onRead=n.onRead||function(){},this.enabled=!0,this.previousTabIndex=null,this.position={row:e.row,column:e.column},this.solutionWordId=null,this.cell=this.buildCell(e);var r=this.buildCellContentWrapper();if(this.cell.appendChild(r),this.params.solution?(this.cellInput=this.buildCellInput(e),r.appendChild(this.cellInput),this.cellCanvas=this.buildCellCanvas(),r.appendChild(this.cellCanvas),this.cell.addEventListener("click",(function(){t.enabled&&(t.callbacks.onClick(t.position),t.focus())}))):(this.cell.classList.add("h5p-crossword-cell-empty"),this.cell.setAttribute("aria-label",this.params.a11y.empty),this.params.hasBackgroundImage||(this.cell.style.backgroundColor=this.params.theme.backgroundColor)),this.params.clueIdMarker){var s=document.createElement("div");s.classList.add("h5p-crossword-cell-clue-id-marker"),s.innerText=this.params.clueIdMarker,r.appendChild(s)}}var e=t.prototype;return e.getDOM=function(){return this.cell},e.buildCell=function(t){var e=document.createElement("td");return e.classList.add("h5p-crossword-cell"),e.style.width="".concat(t.width,"%"),e.setAttribute("role","gridcell"),e.dataset.col=t.column,e.dataset.row=t.row,e},e.buildCellContentWrapper=function(){var t=document.createElement("div");return t.classList.add("h5p-crossword-cell-content-wrapper"),t},e.buildCellCanvas=function(){var t=document.createElement("div");return t.classList.add("h5p-crossword-cell-canvas"),t},e.buildCellInput=function(){var t=this,e=document.createElement("input");return e.classList.add("h5p-crossword-cell-content"),e.setAttribute("type","text"),e.setAttribute("maxLength",1),e.setAttribute("autocomplete","new-password"),e.setAttribute("autocorrect","off"),e.setAttribute("spellcheck","false"),e.setAttribute("tabindex","-1"),e.addEventListener("input",(function(t){t.preventDefault()})),e.addEventListener("change",(function(t){t.preventDefault()})),e.addEventListener("keydown",(function(e){if(t.enabled&&e.key&&"Unidentified"!==e.key&&("Delete"===e.key||"Backspace"===e.key)){var n=t.getAnswer()?0:-1;t.setAnswer("");var o=t.getInformation();o.keepPosition=!0,o.nextPositionOffset=n,t.cellInput.value="",t.callbacks.onKeyup(o)}})),e.addEventListener("keypress",(function(e){e.preventDefault(),t.enabled&&!e.repeat&&e.key&&"Unidentified"!==e.key&&(e.key.length>1||(t.setAnswer(o.toUpperCase(e.key,o.UPPERCASE_EXCEPTIONS),!0),t.cellInput.value="",t.callbacks.onKeyup(t.getInformation())))})),e.addEventListener("keyup",(function(e){if(t.enabled&&!(e.key&&"Unidentified"!==e.key||(e.preventDefault(),e.repeat)))if(-1!==o.CONTROL_KEY_CODES.indexOf(e.keyCode)){if(8===e.keyCode||46===e.keyCode){var n=t.getAnswer()?0:-1;t.setAnswer("");var r=t.getInformation();r.keepPosition=!0,r.nextPositionOffset=n,t.cellInput.value="",t.callbacks.onKeyup(r)}}else{if((187===e.keyCode||192===e.keyCode)&&"Dead"===e.key)return;if(""===t.cellInput.value.substr(0,1)&&229!==e.keyCode)return;t.setAnswer(t.cellInput.value,!0),t.cellInput.value="";var s=t.getInformation();t.callbacks.onKeyup(s)}})),e.addEventListener("focus",(function(e){t.callbacks.onFocus(t.position,e)})),e},e.getSolution=function(){return this.params.solution},e.getCurrentAnswer=function(){return this.cell.innerText.substr(0,1)},e.getInformation=function(){return{answer:this.answer?o.toUpperCase(this.answer,o.UPPERCASE_EXCEPTIONS):this.answer,clueIdAcross:this.params.clueIdAcross,clueIdDown:this.params.clueIdDown,position:this.position,score:this.getScore(),solution:this.params.solution,solutionWordId:this.solutionWordId||null}},e.getPosition=function(){return this.position},e.getClueId=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"across";return"down"===t?this.params.clueIdDown:"across"===t?this.params.clueIdAcross:void 0},e.getAnswer=function(){return this.answer},e.getScore=function(){if(this.params.solution&&(" "!==this.params.solution||this.answer&&""!==this.answer.trim()&&this.answer!==o.CHARACTER_PLACEHOLDER))return this.answer&&""!==this.answer.trim()?this.answer!==this.params.solution?this.params.applyPenalties?-1:0:1:0},e.isFilled=function(){return this.params.solution?" "===this.params.solution?null:!(!this.answer||" "===this.answer):null},e.setTabIndex=function(t){isNaN(parseInt(t))||(this.cellInput?this.cellInput.setAttribute("tabindex",t):this.cell.setAttribute("tabindex",t))},e.setAriaLabel=function(t){this.cellInput.setAttribute("aria-label",t)},e.setSolutionState=function(t){if(this.cell.classList.remove("h5p-crossword-solution-correct"),this.cell.classList.remove("h5p-crossword-solution-wrong"),this.cell.classList.remove("h5p-crossword-solution-neutral"),t){var e="h5p-crossword-solution"+(t?"-".concat(t):"");this.cell.classList.add(e)}},e.setAnswer=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.cellInput&&(""===t?(this.cellCanvas.innerText="",this.answer=void 0):(this.cellCanvas.innerText=o.toUpperCase(t.replace(new RegExp(o.CHARACTER_PLACEHOLDER,"g")," "),o.UPPERCASE_EXCEPTIONS),this.answer=o.toUpperCase(t,o.UPPERCASE_EXCEPTIONS)),this.params.instantFeedback&&this.checkAnswer(e))},e.setWidth=function(t){"number"!=typeof t||t<=0||(this.cell.style.width="".concat(t,"px"))},e.focus=function(){var t=this;setTimeout((function(){t.cellInput?t.cellInput.focus():t.cell.focus()}),0)},e.highlight=function(t){if(this.getSolution()||"focus"===t){var e="h5p-crossword-highlight"+(t?"-".concat(t):"");this.cell.classList.add(e)}},e.unhighlight=function(t){if(t){var e="h5p-crossword-highlight"+(t?"-".concat(t):"");this.cell.classList.remove(e)}else this.cell.classList.remove("h5p-crossword-highlight-normal"),this.cell.classList.remove("h5p-crossword-highlight-focus")},e.showSolutions=function(){this.params.solution&&(this.setAnswer(this.params.solution),this.setSolutionState())},e.checkAnswer=function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],e=(this.answer||"").trim();e===this.params.solution&&""!==e?(this.setSolutionState("correct"),t&&this.callbacks.onRead(this.params.a11y.correct)):""===e||e===o.CHARACTER_PLACEHOLDER?this.setSolutionState():this.params.applyPenalties?(this.setSolutionState("wrong"),t&&this.callbacks.onRead(this.params.a11y.wrong)):(this.setSolutionState("neutral"),t&&this.callbacks.onRead(this.params.a11y.wrong))},e.reset=function(){this.setAnswer("",!1),this.unhighlight(),this.setSolutionState()},e.enable=function(){this.cellInput&&(this.previousTabIndex&&this.cell.setAttribute("tabindex",this.previousTabIndex),this.cellInput.removeAttribute("disabled")),this.enabled=!0},e.disable=function(){this.enabled=!1,this.cellInput&&this.cellInput.setAttribute("disabled","disabled"),this.previousTabIndex=this.cell.getAttribute("tabindex"),this.cell.removeAttribute("tabindex")},e.addSolutionWordIdMarker=function(t){t&&(this.solutionWordMarker=document.createElement("div"),this.solutionWordMarker.classList.add("h5p-crossword-cell-solution-word-marker"),this.solutionWordMarker.innerText=t,this.cell.insertBefore(this.solutionWordMarker,this.cell.firstChild),this.solutionWordCircle=document.createElement("div"),this.solutionWordCircle.classList.add("h5p-crossword-cell-solution-word-circle"),this.cell.insertBefore(this.solutionWordCircle,this.cell.firstChild),this.solutionWordId=t)},t}();function u(t){return function(t){if(Array.isArray(t))return h(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,e){if(!t)return;if("string"==typeof t)return h(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return h(t,e)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function h(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=new Array(e);n0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;this.params=o.extend({},n),this.params.theme.backgroundImage=this.params.theme.backgroundImage||null,this.callbacks=r||{},this.callbacks.onInput=this.callbacks.onInput||function(){},this.callbacks.onFocus=this.callbacks.onFocus||function(){},this.callbacks.onRead=r.onRead||function(){},this.currentPosition={},this.currentOrientation="across",this.maxScore=null,this.cells=this.buildCells(this.params.dimensions,this.params.words),this.content=this.buildGrid(this.params),(t=[]).concat.apply(t,u(this.cells)).filter((function(t){return null!==t.getSolution()}))[0].setTabIndex("0"),this.content.addEventListener("keydown",(function(t){if(!e.disabled){var n,o,r=t.target;switch(t.target.classList.contains("h5p-crossword-cell-content")&&(r=t.target.parentNode.parentNode),t.key){case"ArrowRight":t.preventDefault(),e.setcurrentOrientation("across",{row:parseInt(r.dataset.row),column:parseInt(r.dataset.col)+1}),e.moveTo({row:parseInt(r.dataset.row),column:parseInt(r.dataset.col)+1});break;case"ArrowLeft":t.preventDefault(),e.setcurrentOrientation("across",{row:parseInt(r.dataset.row),column:parseInt(r.dataset.col)-1}),e.moveTo({row:parseInt(r.dataset.row),column:parseInt(r.dataset.col)-1});break;case"ArrowDown":t.preventDefault(),e.setcurrentOrientation("across",{row:parseInt(r.dataset.row)+1,column:parseInt(r.dataset.col)}),e.moveTo({row:parseInt(r.dataset.row)+1,column:parseInt(r.dataset.col)});break;case"ArrowUp":t.preventDefault(),e.setcurrentOrientation("across",{row:parseInt(r.dataset.row)-1,column:parseInt(r.dataset.col)}),e.moveTo({row:parseInt(r.dataset.row)-1,column:parseInt(r.dataset.col)});break;case"Home":t.preventDefault(),t.ctrlKey?e.moveTo({row:0,column:0}):e.moveTo({row:parseInt(r.dataset.row),column:0});break;case"End":t.preventDefault(),t.ctrlKey?e.moveTo({row:e.params.dimensions.rows-1,column:e.params.dimensions.columns-1}):e.moveTo({row:parseInt(r.dataset.row),column:document.querySelector('[data-row="'+r.dataset.row+'"]:last-of-type').dataset.col});break;case"PageUp":t.preventDefault(),n=0;do{o=e.moveTo({row:n,column:r.dataset.col}),n++}while(!1===o);break;case"PageDown":t.preventDefault(),n=e.params.dimensions.rows-1;do{o=e.moveTo({row:n,column:r.dataset.col}),n--}while(!1===o)}}}))}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildCells=function(t){for(var e,n=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],s=o.createArray(t.rows,t.columns),i=0;i0},e.buildGrid=function(t){var e=document.createElement("table");if(e.classList.add("h5p-crossword-grid"),e.style.backgroundColor=t.theme.backgroundColor,t.theme.backgroundImage){e.classList.add("h5p-crossword-grid-background-image");var n=document.createElement("img");H5P.setSource(n,t.theme.backgroundImage,t.contentId),e.style.backgroundImage="url('".concat(n.src,"')")}e.setAttribute("role","grid"),e.setAttribute("aria-label",this.params.a11y.crosswordGrid);var o=document.createElement("tbody");o.setAttribute("role","rowgroup");for(var r=0;r0&&void 0!==arguments[0]?arguments[0]:{},n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(e.row<0||e.row>this.params.dimensions.rows-1)return!1;if(e.column<0||e.column>this.params.dimensions.columns-1)return!1;var o=this.cells[e.row][e.column];return!!o&&((t=[]).concat.apply(t,u(this.cells)).forEach((function(t){t.setTabIndex("-1")})),o.setTabIndex("0"),this.currentPosition=e,this.focusCell(e,n),!0)},e.getUpdates=function(t){var e,n=this,o=[],r="across"===this.currentOrientation?"down":"across",s=this.cells[t.row][t.column].getClueId(r);if(s){var i,a=(i=[]).concat.apply(i,u(this.cells)).filter((function(t){return t.getClueId(r)===s})).reduce((function(t,e){return t+(e.answer||" ")}),"").replace(/[\s\uFEFF\xA0]+$/g,"");o.push({clueId:s,orientation:r,text:a})}var l=this.cells[t.row][t.column].getClueId(this.currentOrientation),c=(e=[]).concat.apply(e,u(this.cells)).filter((function(t){return t.getClueId(n.currentOrientation)===l})).reduce((function(t,e){return t+(e.answer||" ")}),"").replace(/[\s\uFEFF\xA0]+$/g,"");return o.push({clueId:l,orientation:this.currentOrientation,text:c}),o},e.getAnswers=function(){var t;return(t=[]).concat.apply(t,u(this.cells)).map((function(t){return t.getAnswer()}))},e.setAnswers=function(t){var e,n=this;(e=[]).concat.apply(e,u(this.cells)).forEach((function(e,o){if(e.setAnswer(t[o]||""),e.getSolution()){var r=e.getInformation();n.callbacks.onInput({answer:r.answer,inputFieldUpdates:n.getUpdates(r.position),clueId:r.clueId,solutionWordId:r.solutionWordId||null,checkFilled:!0})}}))},e.getScore=function(){var t,e,n=this;this.params.scoreWords?t=this.params.words.reduce((function(t,e){return t+n.getWordScore(e.clueId,e.orientation)}),0):t=(e=[]).concat.apply(e,u(this.cells)).reduce((function(t,e){return t+(e.getScore()||0)}),0);return Math.max(0,t)},e.getMaxScore=function(){var t;this.params.scoreWords?this.maxScore=this.params.words.length:this.maxScore=this.maxScore||(t=[]).concat.apply(t,u(this.cells)).reduce((function(t,e){return t+(void 0!==e.getScore()?1:0)}),0);return this.maxScore},e.getWordScore=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"across",n=this.getWordInformation(t,e),o=n.reduce((function(t,e){return-1===t||-1===e.score?-1:t+(1===e.score||void 0===e.score?1:0)}),0);return-1===o?-1:o===n.length?1:0},e.setcurrentOrientation=function(t,e){if(("across"===t||"down"===t)&&("number"==typeof(e=e||this.currentPosition).row&&"number"==typeof e.column&&!(e.row<0||e.row>this.params.dimensions.rows-1)&&!(e.column<0||e.column>this.params.dimensions.columns-1)&&this.cells[e.row][e.column].getSolution())){var n=e.column>0&&this.cells[e.row][e.column-1].getSolution(),o=e.column0&&this.cells[e.row-1][e.column].getSolution(),s=e.row1&&void 0!==arguments[1]&&arguments[1];if(this.ignoreNextClick)this.ignoreNextClick=!1;else{var n=this.cells[t.row][t.column];n.getSolution()&&(e||(n.getClueId("across")?this.currentPosition.row===t.row&&this.currentPosition.column===t.column&&"across"===this.currentOrientation?this.setcurrentOrientation("down",t):this.setcurrentOrientation("across",t):this.setcurrentOrientation("down",t)),this.currentPosition=t,this.moveTo(t,!0))}},e.handleCellFocus=function(t,e){this.cells[t.row][t.column].getSolution()&&(e.relatedTarget&&(e.relatedTarget.classList.contains("h5p-crossword-cell")||e.relatedTarget.classList.contains("h5p-crossword-cell-content"))||(this.setcurrentOrientation(this.currentOrientation,t),this.handleCellClick(t,!0),this.ignoreNextClick="boolean"!=typeof this.ignoreNextClick||this.ignoreNextClick))},e.handleCellKeyup=function(t){void 0===t.nextPositionOffset&&(t.nextPositionOffset=1),(!this.currentOrientation||"across"===this.currentOrientation)&&t.position.column+t.nextPositionOffset>=0&&t.position.column+t.nextPositionOffset=0&&t.position.row+t.nextPositionOffset1&&void 0!==arguments[1]?arguments[1]:"across",r=this.cells[t.row][t.column].getClueId(o);if(r){var s=this.params.words.filter((function(t){return t.clueId===r&&t.orientation===o}))[0];(e=[]).concat.apply(e,u(this.cells)).filter((function(t){return t.getClueId(o)===r})).forEach((function(t,e){var i=t.getPosition(),a={row:i.row,column:i.column,clueId:r,orientation:o,clue:s.clue,position:e,length:s.answer.length};t.setAriaLabel(n.buildAriaLabel(a)),t.highlight("normal")}))}},e.buildAriaLabel=function(t){var e="".concat(this.params.a11y.row," ").concat(t.row+1,", ").concat(this.params.a11y.column," ").concat(t.column+1),n="".concat(t.clueId," ").concat(this.params.a11y[t.orientation],". ").concat(t.clue),o="".concat(this.params.a11y.letterSevenOfNine.replace("@position",t.position+1).replace("@length",t.length));return"".concat(e,". ").concat(n,", ").concat(o,".")},e.getFocus=function(){return{position:this.currentPosition,orientation:this.currentOrientation}},e.getWordInformation=function(t){var e,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"across";return t?(e=[]).concat.apply(e,u(this.cells)).filter((function(e){return e.getClueId(n)===t})).map((function(t){return t.getInformation()})):""},e.focusCell=function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.clearCellHighlights(),this.setcurrentOrientation(this.currentOrientation,t),this.highlightWord(t,this.currentOrientation),this.cells[t.row][t.column].highlight("focus"),this.callbacks.onFocus({clueId:this.cells[t.row][t.column].getClueId(this.currentOrientation),orientation:this.currentOrientation}),e||this.cells[t.row][t.column].focus()},e.clearCellHighlights=function(){var t;(t=[]).concat.apply(t,u(this.cells)).forEach((function(t){t.unhighlight()}))},e.fillGrid=function(t){var e,n=this,o=(e=[]).concat.apply(e,u(this.cells)).filter((function(e){return e.getClueId(t.orientation)===t.clueId}));if(o.forEach((function(e,o){if(e.setAnswer(t.text[o]||"",-1!==t.readOffset&&o===t.cursorPosition-t.readOffset),e.getClueId("down")&&e.getClueId("across")){var r="across"===t.orientation?n.getWordInformation(e.getClueId("down"),"down"):n.getWordInformation(e.getClueId("across"),"across"),s=[{clueId:"across"===t.orientation?e.getClueId("down"):e.getClueId("across"),orientation:"across"===t.orientation?"down":"across",text:r.reduce((function(t,e){return"".concat(t).concat(e.answer||" ")}),"")}];n.callbacks.onInput({inputFieldUpdates:s})}var i=e.getInformation();i.solutionWordId&&n.callbacks.onInput(i)})),t.cursorPosition".concat(o," br>").concat(r.join(" "),"")})).join("")},t}();d.XAPI_PLACEHOLDER="__________";var p=function(){function t(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.solutionWord=o.toUpperCase(t.solutionWord.replace(/\s/g,""),o.UPPERCASE_EXCEPTIONS),this.scaleWidth=Math.max(t.tableWidth,this.solutionWord.length),this.cells=this.createCells(this.solutionWord),this.content=this.createSolution(this.cells)}var e=t.prototype;return e.getDOM=function(){return this.content},e.createSolution=function(t){var e=document.createElement("div");e.classList.add("h5p-crossword-solution-word-wrapper");var n=document.createElement("table");n.classList.add("h5p-crossword-solution-word"),n.setAttribute("aria-hidden",!0),e.appendChild(n);var o=document.createElement("tr");return t.forEach((function(t){o.appendChild(t.getDOM())})),n.appendChild(o),e},e.createCells=function(t){var e=o.createArray(t.length);return t.split("").forEach((function(n,o){e[o]=new c({width:100/t.length,solution:t[o],clueIdMarker:o+1}),e[o].disable()})),e},e.setCell=function(t,e){this.cells[t].setAnswer(e||"")},e.showSolutions=function(){this.cells.forEach((function(t){t.showSolutions()}))},e.reset=function(){this.cells.forEach((function(t){t.reset()}))},e.resize=function(){var t=this.content.clientWidth/this.scaleWidth;this.content.style.fontSize="".concat(t/2,"px"),this.cells.forEach((function(e){e.setWidth(t)}))},t}(),f=function(){function t(e){this.params=o.extend({words:[{answer:"BAT",clue:"BAT"},{answer:"CAT",clue:"CAT"}],config:{poolSize:0}},e||{}),this.params.words=this.params.words.filter((function(t){return t.answer&&t.clue})).map((function(t){var e={answer:o.toUpperCase(t.answer,o.UPPERCASE_EXCEPTIONS),clue:t.clue,extraClue:t.extraClue};return t.fixWord&&void 0!==t.row&&void 0!==t.column&&void 0!==t.orientation&&(e.row=t.row-1,e.column=t.column-1,e.orientation=t.orientation),e})),this.indexChar={},this.badWords,this.cells=o.createArray(t.GRID_ROWS,t.GRID_COLUMNS),this.wordElements=this.createWordElements(this.params.words,this.params.config.poolSize)}var e=t.prototype;return e.getSquareGrid=function(){for(var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=null,n=0,o=0;on&&(e=r,n=s),1===n)break}}return e},e.getGrid=function(){for(var t,e=this,n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,o=0;o0){if(r.forEach((function(t){if(!1===e.canPlaceAnswerAt(t.answer,{row:t.row,column:t.column,orientation:t.orientation}))return e.badWords=[t],null;e.placeAnswerAt(t,{row:t.row,column:t.column,orientation:t.orientation})})),r.length>=this.params.config.poolSize||r.length===this.wordElements.length)return this.minimizeGrid()}else{var s=Math.floor(this.cells.length/2),i=Math.floor(this.cells[0].length/2),a=this.wordElements[0],l=this.getRandomOrientation();if("across"===l?i-=Math.floor(a.answer.length/2):s-=Math.floor(a.answer.length/2),!1===this.canPlaceAnswerAt(a.answer,{row:s,column:i,orientation:l}))return this.badWords=[a],null;this.placeAnswerAt(a,{row:s,column:i,orientation:l})}this.groups=[],r.length>0?this.groups.push(this.wordElements.slice(r.length)):this.groups.push(this.wordElements.slice(1));for(var c=0;cn&&(n=i),as&&(s=a))}for(var l=n-e+1,c=s-r+1,u=o.createArray(l,c),h=e,d=0;d=this.cells.length||e.column<0||e.column>=this.cells[e.row].length)return!1;if("across"===e.orientation){for(var n=0;nthis.cells[e.row].length)return!1;if(e.column-1>=0&&null!==this.cells[e.row][e.column-1])return!1;if(e.column+t.length=0&&sthis.cells.length)return!1;if(e.row-1>=0&&null!==this.cells[e.row-1][e.column])return!1;if(e.row+t.length=0&&bo?-1:e.answer.length-t.answer.length}))},e.getWordElement=function(t,e){if("number"!=typeof t)return null;var n=this.wordElements.filter((function(e){return e.index===t}));return n.length<1?null:"string"!=typeof e?n[0]:n[0][e]},e.export=function(t){for(var e=t.length,n=t[0].length,o=[],r=1,s=0;s0&&void 0!==arguments[0]?arguments[0]:{},r=arguments.length>1?arguments[1]:void 0;if(this.params=o,this.contentId=o.contentId,this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-content"),this.callbacks=r||{},this.callbacks.onInitialized=r.onInitialized||function(){},this.callbacks.onRead=r.onRead||function(){},this.callbacks.onTableFilled=r.onTableFilled||function(){},this.answerGiven=!1,this.params.previousState&&this.params.previousState.crosswordLayout)this.crosswordLayout=this.params.previousState.crosswordLayout;else{var s,i,a;if(o.words.length<2?s=o.l10n.couldNotGenerateCrosswordTooFewWords:(a=(i=new f({words:o.words,config:{poolSize:o.poolSize}})).getSquareGrid(e.MAXIMUM_TRIES))||(s=o.l10n.couldNotGenerateCrossword),s){if(i){var c=i.getBadWords().map((function(t){return"".concat(t.answer)})).join(", ");s="".concat(s," ").concat(o.l10n.problematicWords.replace(/@words/g,c))}var u=document.createElement("div");return u.classList.add("h5p-crossword-message"),u.innerText=s,this.content.appendChild(u),this.couldNotGenerateCrossword=!0,void this.callbacks.onInitialized(!1)}this.crosswordLayout=i.export(a)}var h=document.createElement("div");h.classList.add("h5p-crossword-table-wrapper"),this.clueAnnouncer=new t,h.appendChild(this.clueAnnouncer.getDOM()),this.table=new d({scoreWords:this.params.scoreWords,applyPenalties:this.params.applyPenalties,theme:this.params.theme,contentId:this.contentId,dimensions:{rows:this.crosswordLayout.rows,columns:this.crosswordLayout.cols},instantFeedback:this.params.instantFeedback,solutionWord:this.params.solutionWord,words:this.crosswordLayout.result,a11y:this.params.a11y,l10n:{across:this.params.l10n.across,down:this.params.l10n.down}},{onInput:function(t){n.handleTableInput(t)},onFocus:function(t){n.handleTableFocus(t)},onRead:function(t){n.callbacks.onRead(t)}}),h.appendChild(this.table.getDOM()),this.content.appendChild(h);var m=this.table.addSolutionWord(this.params.solutionWord);""!==this.params.solutionWord&&m&&(this.solutionWord=new p({solutionWord:this.params.solutionWord,tableWidth:this.crosswordLayout.cols}),h.appendChild(this.solutionWord.getDOM())),this.inputarea=new l({words:this.crosswordLayout.result.filter((function(t){return"none"!==t.orientation})),contentId:this.contentId,overlayContainer:this.content,applyPenalties:this.params.applyPenalties,l10n:{across:this.params.l10n.across,down:this.params.l10n.down,extraClue:this.params.l10n.extraClue,closeWindow:this.params.l10n.closeWindow},a11y:this.params.a11y},{onFieldInput:function(t){n.handleFieldInput(t)},onRead:function(t){n.callbacks.onRead(t)}}),this.content.appendChild(this.inputarea.getDOM()),this.params.previousState.cells&&(this.table.setAnswers(this.params.previousState.cells),this.answerGiven=!0),this.params.previousState.focus&&this.params.previousState.focus.position&&this.params.previousState.focus.position.row&&(this.table.setcurrentOrientation(this.params.previousState.focus.orientation,this.params.previousState.focus.position),this.table.focusCell(this.params.previousState.focus.position)),this.overrideCSS(this.params.theme),this.callbacks.onInitialized(!0)}var n=e.prototype;return n.getDOM=function(){return this.content},n.resize=function(){this.table&&(this.table.resize(),this.inputarea.resize(),this.solutionWord&&this.solutionWord.resize())},n.getXAPICorrectResponsesPattern=function(){return this.table.getXAPICorrectResponsesPattern()},n.getXAPIResponse=function(){return this.table.getXAPIResponse()},n.getXAPIDescription=function(){return this.table.getXAPIDescription()},n.reset=function(){this.params.words.length<2||(this.table.reset(),this.solutionWord&&this.solutionWord.reset(),this.inputarea.reset(),this.answerGiven=!1)},n.getAnswerGiven=function(){return this.answerGiven},n.getScore=function(){return this.params.words.length<2?0:this.table.getScore()},n.getMaxScore=function(){return this.params.words.length<2?0:this.table.getMaxScore()},n.getCurrentState=function(){if(!(this.params.words.length<2)&&this.table)return{crosswordLayout:this.crosswordLayout,cells:this.table.getAnswers(),focus:this.table.getFocus()}},n.checkAnswer=function(){if(this.disable(),this.params.scoreWords){var t=this.table.checkAnswerWords();this.inputarea.checkAnswerWords(t)}else{var e=this.table.checkAnswer();this.inputarea.checkAnswer(e)}},n.isTableFilled=function(){return this.table&&this.table.isFilled()},n.showSolutions=function(){this.params.words.length<2||(this.disable(),this.table.showSolutions(),this.solutionWord&&this.solutionWord.showSolutions(),this.inputarea.showSolutions(this.crosswordLayout.result))},n.handleFieldInput=function(t){this.table.fillGrid(t),this.answerGiven=!0},n.handleTableInput=function(t){this.solutionWord&&t.solutionWordId&&this.solutionWord.setCell(t.solutionWordId-1,t.answer),t.inputFieldUpdates&&this.inputarea.fillFields(t.inputFieldUpdates),this.answerGiven=!0,t.checkFilled&&this.isTableFilled()&&this.callbacks.onTableFilled()},n.handleTableFocus=function(t){var e=this.crosswordLayout.result.filter((function(t){return"none"!==t.orientation})).filter((function(e){return e.orientation===t.orientation&&e.clueId===t.clueId}));e.length>0&&this.clueAnnouncer.setClue({clue:e[0].clue,orientation:this.params.l10n[e[0].orientation],clueId:e[0].clueId,answerLength:e[0].answer.length}),this.inputarea.focusClue(t)},n.enable=function(){this.table.enable(),this.inputarea.enable()},n.disable=function(){this.table.disable(),this.table.unhighlight(),this.inputarea.disable(),this.inputarea.unhighlight(),this.clueAnnouncer.reset()},n.overrideCSS=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.gridColor&&this.addStyle(".h5p-crossword .h5p-crossword-grid th, .h5p-crossword .h5p-crossword-grid td,.h5p-crossword .h5p-crossword-grid{border-color:".concat(t.gridColor,"};")),t.cellBackgroundColor&&(this.addStyle(".h5p-crossword .h5p-crossword-cell{background-color:".concat(t.cellBackgroundColor,"};")),this.addStyle(".h5p-crossword .h5p-crossword-cell-clue-id-marker{background-color:".concat(t.cellBackgroundColor,"};"))),t.clueIdColor&&this.addStyle(".h5p-crossword .h5p-crossword-cell-clue-id-marker{color:".concat(t.clueIdColor,"};")),t.cellColor&&this.addStyle(".h5p-crossword .h5p-crossword-cell-canvas{color:".concat(t.cellColor,"};")),t.cellBackgroundColorHighlight&&(this.addStyle(".h5p-crossword .h5p-crossword-cell:not(.h5p-crossword-solution-correct):not(.h5p-crossword-solution-wrong):not(.h5p-crossword-solution-neutral).h5p-crossword-highlight-normal{background-color:".concat(t.cellBackgroundColorHighlight,"};")),this.addStyle(".h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-clue-id-marker, .h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-solution-word-marker{background-color:".concat(t.cellBackgroundColorHighlight,"}")),this.addStyle(".h5p-crossword .h5p-crossword-input-fields-group-wrapper-clue.h5p-crossword-input-fields-group-clue-highlight-focus .h5p-crossword-input-fields-group-clue-id{background-color:".concat(t.cellBackgroundColorHighlight,"}"))),t.clueIdColorHighlight&&this.addStyle(".h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-clue-id-marker, .h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-solution-word-marker{color:".concat(t.clueIdColorHighlight,"}")),t.cellColorHighlight&&(this.addStyle(".h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-canvas{color:".concat(t.cellColorHighlight,"};")),this.addStyle(".h5p-crossword .h5p-crossword-input-fields-group-wrapper-clue.h5p-crossword-input-fields-group-clue-highlight-focus .h5p-crossword-input-fields-group-clue-id{color:".concat(t.cellColorHighlight,"}")))},n.addStyle=function(t){var e=document.createElement("style");e.appendChild(document.createTextNode(t)),document.querySelector("head").appendChild(e)},e}();function w(t,e){return(w=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}m.MAXIMUM_TRIES=20;var g=function(t){var e,n;function r(e,n){var r,s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};(r=t.call(this,"crossword")||this).params=e,r.contentId=n,r.extras=s,r.params=o.extend({solutionWord:"",theme:{backgroundColor:"#173354"},behaviour:{enableSolutionsButton:!0,enableRetry:!0,enableInstantFeedback:!1,scoreWords:!0,applyPenalties:!1},l10n:{across:"across",down:"down",checkAnswer:"Check answer",couldNotGenerateCrossword:"Could not generate a crossword with the given words. Please try again with fewer words or words that have more characters in common.",couldNotGenerateCrosswordTooFewWords:"Could not generate a crossword. You need at least two words.",problematicWords:"Problematic word(s): @words",showSolution:"Show solution",tryAgain:"Retry",extraClue:"Extra clue",closeWindow:"Close window",submitAnswer:"Submit"},a11y:{crosswordGrid:"Crossword grid. Use arrow keys to navigate and keyboard to enter characters. Use tab to use input fields instead.",column:"column",row:"row",across:"across",down:"down",empty:"Empty",resultFor:"Result for: @clue",correct:"Correct",wrong:"Wrong",point:"Point",solutionFor:"The solution for @clue is: @solution",extraClueFor:"Open extra clue for @clue",letterSevenOfNine:"Letter @position of @length",lettersWord:"@length letter word",check:"Check the characters. The responses will be marked as correct, incorrect, or unanswered.",showSolution:"Show the solution. The crossword will be filled with its correct solution.",retry:"Retry the task. Reset all responses and start the task over again.",yourResult:"You got @score out of @total points"}},r.params),r.params.theme=r.getDifference(r.params.theme,{gridColor:"#000000",cellBackgroundColor:"#ffffff",cellColor:"#000000",clueIdColor:"#606060",cellBackgroundColorHighlight:"#3e8de8",cellColorHighlight:"#ffffff",clueIdColorHighlight:"#e0e0e0"}),r.initialButtons={check:!r.params.behaviour.enableInstantFeedback,showSolution:r.params.behaviour.enableSolutionsButton,retry:r.params.behaviour.enableRetry};var i=s.metadata&&s.metadata.defaultLanguage||"en";for(var a in r.languageTag=o.formatLanguageCode(i),r.params.l10n)r.params.l10n[a]=o.stripHTML(o.htmlDecode(r.params.l10n[a]));return r.params.a11y.yourResult=r.params.a11y.yourResult.replace(/\.$/,""),r.previousState=r.extras.previousState||{},r.previousState.crosswordLayout&&r.previousState.cells||(r.previousState={}),r.params.words=(r.params.words||[]).filter((function(t){return void 0!==t.answer&&void 0!==t.clue})).map((function(t){return t.answer=o.stripHTML(o.htmlDecode(o.toUpperCase(t.answer,o.UPPERCASE_EXCEPTIONS))),t.clue=o.stripHTML(o.htmlDecode(t.clue)),t})),r}n=t,(e=r).prototype=Object.create(n.prototype),e.prototype.constructor=e,w(e,n);var s=r.prototype;return s.registerDomElements=function(){var t=this;this.params.taskDescription&&""!==this.params.taskDescription&&(this.introduction=document.createElement("div"),this.introduction.innerHTML=this.params.taskDescription,this.setIntroduction(this.introduction)),this.content=new m({scoreWords:this.params.behaviour.scoreWords,applyPenalties:this.params.behaviour.applyPenalties,theme:this.params.theme,contentId:this.contentId,instantFeedback:this.params.behaviour.enableInstantFeedback,l10n:{couldNotGenerateCrossword:this.params.l10n.couldNotGenerateCrossword,couldNotGenerateCrosswordTooFewWords:this.params.l10n.couldNotGenerateCrosswordTooFewWords,problematicWords:this.params.l10n.problematicWords,across:this.params.l10n.across,down:this.params.l10n.down,extraClue:this.params.l10n.extraClue,closeWindow:this.params.l10n.closeWindow},a11y:this.params.a11y,poolSize:this.params.behaviour.poolSize,solutionWord:o.toUpperCase(this.params.solutionWord.replace(/'\s'/g,""),o.UPPERCASE_EXCEPTIONS),words:this.params.words,previousState:this.previousState},{onTableFilled:function(){t.handleContentFilled()},onInitialized:function(e){t.handleContentInitialized(e)},onRead:function(e){t.handleRead(e)}}),this.setContent(this.content.getDOM()),this.params.behaviour.enableInstantFeedback&&this.content.isTableFilled()&&this.checkAnswer(),o.waitForDOM(".h5p-crossword-input-container",(function(){setTimeout((function(){t.trigger("resize")}),100)}))},s.handleContentInitialized=function(t){var e=this;t&&this.addButtons(),this.on("resize",(function(){e.content.resize()}))},s.addButtons=function(){var t=this;this.addButton("check-answer",this.params.l10n.checkAnswer,(function(){t.checkAnswer(),t.trigger(t.getXAPIAnswerEvent())}),this.initialButtons.check,{"aria-label":this.params.a11y.check},{contentData:this.extras,textIfSubmitting:this.params.l10n.submitAnswer}),this.addButton("show-solution",this.params.l10n.showSolution,(function(){t.showSolutions()}),this.initialButtons.showSolution,{"aria-label":this.params.a11y.showSolution},{}),this.addButton("try-again",this.params.l10n.tryAgain,(function(){t.resetTask()}),this.initialButtons.retry,{"aria-label":this.params.a11y.retry},{})},s.checkAnswer=function(){if(this.content){this.content.checkAnswer(),this.hideButton("check-answer");var t=this.getScore(),e=this.getMaxScore(),n=H5P.Question.determineOverallFeedback(this.params.overallFeedback,t/e),o=this.params.a11y.yourResult.replace("@score",":num").replace("@total",":total");this.setFeedback(n,t,e,o),this.params.behaviour.enableSolutionsButton&&this.showButton("show-solution"),this.params.behaviour.enableRetry&&this.showButton("try-again")}},s.handleRead=function(t){this.read(t)},s.handleContentFilled=function(){this.getMaxScore()>0&&this.getScore()===this.getMaxScore()?(this.checkAnswer(),this.trigger(this.getXAPIAnswerEvent())):this.showButton("check-answer")},s.getAnswerGiven=function(){return!!this.content&&this.content.getAnswerGiven()},s.getScore=function(){return this.content?this.content.getScore():0},s.getMaxScore=function(){return this.content?this.content.getMaxScore():0},s.showSolutions=function(){this.content&&(this.hideButton("check-answer"),this.hideButton("show-solution"),this.content.showSolutions(),this.trigger("resize"))},s.resetTask=function(){this.content&&(this.initialButtons.check?this.showButton("check-answer"):this.hideButton("check-answer"),this.initialButtons.showSolution?this.showButton("show-solution"):this.hideButton("show-solution"),this.initialButtons.retry?this.showButton("try-again"):this.hideButton("try-again"),this.trigger("resize"),this.removeFeedback(),this.content.reset(),this.content.enable())},s.getXAPIData=function(){return{statement:this.getXAPIAnswerEvent().data.statement}},s.getXAPIAnswerEvent=function(){var t=this.createXAPIEvent("answered");return t.setScoredResult(this.getScore(),this.getMaxScore(),this,!0,this.isPassed()),t.data.statement.result.response=this.content.getXAPIResponse(),t},s.createXAPIEvent=function(t){var e=this.createXAPIEventTemplate(t);return o.extend(e.getVerifiedStatementValue(["object","definition"]),this.getxAPIDefinition()),e},s.getxAPIDefinition=function(){var t={name:{}};return t.name[this.languageTag]=this.getTitle(),t.name["en-US"]=t.name[this.languageTag],t.description={},t.description[this.languageTag]="".concat(this.getDescription()),t.description["en-US"]=t.description[this.languageTag],t.type="http://adlnet.gov/expapi/activities/cmi.interaction",t.interactionType="fill-in",t.correctResponsesPattern=this.content.getXAPICorrectResponsesPattern(),t},s.isPassed=function(){return this.getScore()>=this.getMaxScore()||!this.getMaxScore()||0===this.getMaxScore()},s.getTitle=function(){var t;return this.extras.metadata&&(t=this.extras.metadata.title),t=t||r.DEFAULT_DESCRIPTION,H5P.createTitle(t)},s.getDescription=function(){var t=this.params.taskDescription||r.DEFAULT_DESCRIPTION,e=this.content.getXAPIDescription();return"".concat(t).concat(e)},s.getCurrentState=function(){return this.content.getCurrentState()},s.getDifference=function(t,e){for(var n in e)t[n]===e[n]&&delete t[n];return t},r}(H5P.Question);g.DEFAULT_DESCRIPTION="Crossword",H5P=H5P||{},H5P.Crossword=g}();;