| 1 |
/******/ (() => { // webpackBootstrap |
| 2 |
/******/ var __webpack_modules__ = ({ |
| 3 |
|
| 4 |
/***/ "./assets/src/apps/js/frontend/quiz/components/attempts/index.js" |
| 5 |
/*!***********************************************************************!*\ |
| 6 |
!*** ./assets/src/apps/js/frontend/quiz/components/attempts/index.js ***! |
| 7 |
\***********************************************************************/ |
| 8 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 9 |
|
| 10 |
"use strict"; |
| 11 |
__webpack_require__.r(__webpack_exports__); |
| 12 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 13 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 14 |
/* harmony export */ }); |
| 15 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 16 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 17 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 18 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); |
| 19 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 20 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__); |
| 21 |
/* harmony import */ var _duration__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../duration */ "./assets/src/apps/js/frontend/quiz/components/duration/index.js"); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
/** |
| 28 |
* Displays list of all attempt from a quiz. |
| 29 |
*/ |
| 30 |
const Attempts = () => { |
| 31 |
const attempts = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz').getData('attempts') || []; |
| 32 |
const hasAttempts = attempts && !!attempts.length; |
| 33 |
return !hasAttempts ? false : (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 34 |
className: "quiz-attempts" |
| 35 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h4", { |
| 36 |
className: "attempts-heading" |
| 37 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Last Attempt', 'learnpress')), hasAttempts && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("table", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("thead", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("tr", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("th", { |
| 38 |
className: "quiz-attempts__questions" |
| 39 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Questions', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("th", { |
| 40 |
className: "quiz-attempts__spend" |
| 41 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Time spent', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("th", { |
| 42 |
className: "quiz-attempts__marks" |
| 43 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Marks', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("th", { |
| 44 |
className: "quiz-attempts__grade" |
| 45 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Passing grade', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("th", { |
| 46 |
className: "quiz-attempts__result" |
| 47 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Result', 'learnpress')))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("tbody", null, attempts.map((row, key) => { |
| 48 |
// Re-write value to attempts.timeSpend |
| 49 |
/*if ( lpQuizSettings.checkNorequizenroll === 1 ) { |
| 50 |
const timespendStart = window.localStorage.getItem( 'quiz_start_' + lpQuizSettings.id ), |
| 51 |
timespendEnd = window.localStorage.getItem( 'quiz_end_' + lpQuizSettings.id ); |
| 52 |
if ( timespendStart && timespendEnd ) { |
| 53 |
row.timeSpend = timeDifference( timespendStart, timespendEnd ).duration; |
| 54 |
} |
| 55 |
}*/ |
| 56 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("tr", { |
| 57 |
key: `attempt-${key}` |
| 58 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("td", { |
| 59 |
className: "quiz-attempts__questions" |
| 60 |
}, `${row.questionCorrect} / ${row.questionCount}`), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("td", { |
| 61 |
className: "quiz-attempts__spend" |
| 62 |
}, row.timeSpend || '--'), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("td", { |
| 63 |
className: "quiz-attempts__marks" |
| 64 |
}, `${row.userMark} / ${row.mark}`), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("td", { |
| 65 |
className: "quiz-attempts__grade" |
| 66 |
}, row.passingGrade || '-'), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("td", { |
| 67 |
className: "quiz-attempts__result" |
| 68 |
}, `${parseFloat(row.result).toFixed(2)}%`, " ", (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, row.graduationText))); |
| 69 |
}))))); |
| 70 |
}; |
| 71 |
function timeDifference(earlierDate, laterDate) { |
| 72 |
const oDiff = new Object(); |
| 73 |
|
| 74 |
// Calculate Differences |
| 75 |
// ------------------------------------------------------------------- // |
| 76 |
let nTotalDiff = laterDate - earlierDate; |
| 77 |
oDiff.days = Math.floor(nTotalDiff / 1000 / 60 / 60 / 24); |
| 78 |
nTotalDiff -= oDiff.days * 1000 * 60 * 60 * 24; |
| 79 |
oDiff.hours = Math.floor(nTotalDiff / 1000 / 60 / 60); |
| 80 |
nTotalDiff -= oDiff.hours * 1000 * 60 * 60; |
| 81 |
oDiff.minutes = Math.floor(nTotalDiff / 1000 / 60); |
| 82 |
nTotalDiff -= oDiff.minutes * 1000 * 60; |
| 83 |
oDiff.seconds = Math.floor(nTotalDiff / 1000); |
| 84 |
// ------------------------------------------------------------------- // |
| 85 |
|
| 86 |
// Format Duration |
| 87 |
// ------------------------------------------------------------------- // |
| 88 |
// Format Hours |
| 89 |
let hourtext = '00'; |
| 90 |
if (oDiff.days > 0) { |
| 91 |
hourtext = String(oDiff.days); |
| 92 |
} |
| 93 |
if (hourtext.length == 1) { |
| 94 |
hourtext = '0' + hourtext; |
| 95 |
} |
| 96 |
|
| 97 |
// Format Minutes |
| 98 |
let mintext = '00'; |
| 99 |
if (oDiff.minutes > 0) { |
| 100 |
mintext = String(oDiff.minutes); |
| 101 |
} |
| 102 |
if (mintext.length == 1) { |
| 103 |
mintext = '0' + mintext; |
| 104 |
} |
| 105 |
|
| 106 |
// Format Seconds |
| 107 |
let sectext = '00'; |
| 108 |
if (oDiff.seconds > 0) { |
| 109 |
sectext = String(oDiff.seconds); |
| 110 |
} |
| 111 |
if (sectext.length == 1) { |
| 112 |
sectext = '0' + sectext; |
| 113 |
} |
| 114 |
// Set Duration |
| 115 |
const sDuration = hourtext + ':' + mintext + ':' + sectext; |
| 116 |
oDiff.duration = sDuration; |
| 117 |
// ------------------------------------------------------------------- // |
| 118 |
|
| 119 |
return oDiff; |
| 120 |
} |
| 121 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Attempts); |
| 122 |
|
| 123 |
/***/ }, |
| 124 |
|
| 125 |
/***/ "./assets/src/apps/js/frontend/quiz/components/buttons/button-check.js" |
| 126 |
/*!*****************************************************************************!*\ |
| 127 |
!*** ./assets/src/apps/js/frontend/quiz/components/buttons/button-check.js ***! |
| 128 |
\*****************************************************************************/ |
| 129 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 130 |
|
| 131 |
"use strict"; |
| 132 |
__webpack_require__.r(__webpack_exports__); |
| 133 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 134 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 135 |
/* harmony export */ }); |
| 136 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 137 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 138 |
/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! classnames */ "./node_modules/classnames/index.js"); |
| 139 |
/* harmony import */ var classnames__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(classnames__WEBPACK_IMPORTED_MODULE_1__); |
| 140 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 141 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_2__); |
| 142 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 143 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__); |
| 144 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 145 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_4__); |
| 146 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 147 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__); |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
class ButtonCheck extends _wordpress_element__WEBPACK_IMPORTED_MODULE_2__.Component { |
| 155 |
constructor() { |
| 156 |
super(...arguments); |
| 157 |
this.state = { |
| 158 |
loading: false |
| 159 |
}; |
| 160 |
} |
| 161 |
checkAnswer = () => { |
| 162 |
const { |
| 163 |
checkAnswer, |
| 164 |
question, |
| 165 |
answered |
| 166 |
} = this.props; |
| 167 |
|
| 168 |
// Fix temporary for FIB. |
| 169 |
if (question.type === 'fill_in_blanks') { |
| 170 |
const elFIB = document.querySelector(`.question-fill_in_blanks[data-id="${question.id}"]`); |
| 171 |
const elInputs = elFIB.querySelectorAll('.lp-fib-input > input'); |
| 172 |
elInputs.forEach(elInput => { |
| 173 |
if (elInput.value.length > 0) { |
| 174 |
this.setState({ |
| 175 |
loading: true |
| 176 |
}); |
| 177 |
checkAnswer(question.id); |
| 178 |
return false; |
| 179 |
} |
| 180 |
}); |
| 181 |
} |
| 182 |
if (answered) { |
| 183 |
checkAnswer(question.id); |
| 184 |
this.setState({ |
| 185 |
loading: true |
| 186 |
}); |
| 187 |
} |
| 188 |
}; |
| 189 |
render() { |
| 190 |
const { |
| 191 |
answered |
| 192 |
} = this.props; |
| 193 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 194 |
className: classnames__WEBPACK_IMPORTED_MODULE_1___default()('lp-button', 'instant-check', { |
| 195 |
loading: this.state.loading |
| 196 |
}), |
| 197 |
onClick: this.checkAnswer |
| 198 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 199 |
className: "instant-check__icon" |
| 200 |
}), (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('Check answers', 'learnpress'), !answered && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 201 |
className: "instant-check__info", |
| 202 |
dangerouslySetInnerHTML: { |
| 203 |
__html: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_5__.__)('You need to answer the question before checking the answer key.', 'learnpress') |
| 204 |
} |
| 205 |
}))); |
| 206 |
} |
| 207 |
} |
| 208 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_4__.compose)((0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.withSelect)((select, { |
| 209 |
question: { |
| 210 |
id |
| 211 |
} |
| 212 |
}) => { |
| 213 |
const { |
| 214 |
getQuestionAnswered |
| 215 |
} = select('learnpress/quiz'); |
| 216 |
return { |
| 217 |
answered: getQuestionAnswered(id) |
| 218 |
}; |
| 219 |
}), (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.withDispatch)((dispatch, { |
| 220 |
id |
| 221 |
}) => { |
| 222 |
const { |
| 223 |
checkAnswer |
| 224 |
} = dispatch('learnpress/quiz'); |
| 225 |
return { |
| 226 |
checkAnswer(id) { |
| 227 |
checkAnswer(id); |
| 228 |
} |
| 229 |
}; |
| 230 |
}))(ButtonCheck)); |
| 231 |
|
| 232 |
/***/ }, |
| 233 |
|
| 234 |
/***/ "./assets/src/apps/js/frontend/quiz/components/buttons/button-hint.js" |
| 235 |
/*!****************************************************************************!*\ |
| 236 |
!*** ./assets/src/apps/js/frontend/quiz/components/buttons/button-hint.js ***! |
| 237 |
\****************************************************************************/ |
| 238 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 239 |
|
| 240 |
"use strict"; |
| 241 |
__webpack_require__.r(__webpack_exports__); |
| 242 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 243 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 244 |
/* harmony export */ }); |
| 245 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 246 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 247 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 248 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 249 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 250 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 251 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 252 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__); |
| 253 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 254 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
class ButtonHint extends _wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Component { |
| 261 |
/** |
| 262 |
* Callback to show hint of question |
| 263 |
*/ |
| 264 |
showHint = () => { |
| 265 |
const { |
| 266 |
showHint, |
| 267 |
question |
| 268 |
} = this.props; |
| 269 |
showHint(question.id, !question.showHint); |
| 270 |
}; |
| 271 |
render() { |
| 272 |
const { |
| 273 |
question |
| 274 |
} = this.props; |
| 275 |
return question.hint ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 276 |
className: "btn-show-hint", |
| 277 |
onClick: this.showHint |
| 278 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Hint', 'learnpress'))) : ''; |
| 279 |
} |
| 280 |
} |
| 281 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__.compose)((0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withDispatch)((dispatch, { |
| 282 |
id |
| 283 |
}) => { |
| 284 |
const { |
| 285 |
showHint |
| 286 |
} = dispatch('learnpress/quiz'); |
| 287 |
return { |
| 288 |
showHint(id, show) { |
| 289 |
showHint(id, show); |
| 290 |
} |
| 291 |
}; |
| 292 |
}))(ButtonHint)); |
| 293 |
|
| 294 |
/***/ }, |
| 295 |
|
| 296 |
/***/ "./assets/src/apps/js/frontend/quiz/components/buttons/index.js" |
| 297 |
/*!**********************************************************************!*\ |
| 298 |
!*** ./assets/src/apps/js/frontend/quiz/components/buttons/index.js ***! |
| 299 |
\**********************************************************************/ |
| 300 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 301 |
|
| 302 |
"use strict"; |
| 303 |
__webpack_require__.r(__webpack_exports__); |
| 304 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 305 |
/* harmony export */ MaybeShowButton: () => (/* binding */ MaybeShowButton), |
| 306 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 307 |
/* harmony export */ }); |
| 308 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 309 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 310 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 311 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 312 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 313 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 314 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 315 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__); |
| 316 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 317 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
class Buttons extends _wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Component { |
| 324 |
startQuiz = event => { |
| 325 |
event && event.preventDefault(); |
| 326 |
const btn = document.querySelector('.lp-button.start'); |
| 327 |
btn && btn.setAttribute('disabled', 'disabled'); |
| 328 |
btn.classList.add('loading'); |
| 329 |
const { |
| 330 |
startQuiz, |
| 331 |
status |
| 332 |
} = this.props; |
| 333 |
if (status === 'completed') { |
| 334 |
const { |
| 335 |
confirm, |
| 336 |
isOpen |
| 337 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/modal'); |
| 338 |
if ('no' === confirm((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Are you sure you want to retake the quiz?', 'learnpress'), this.startQuiz)) { |
| 339 |
!isOpen() && btn && btn.removeAttribute('disabled'); |
| 340 |
btn.classList.remove('loading'); |
| 341 |
return; |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
// No require enroll |
| 346 |
/*if ( lpQuizSettings.checkNorequizenroll === 1 ) { |
| 347 |
// Reset data |
| 348 |
window.localStorage.removeItem( 'quiz_start_' + lpQuizSettings.id ); |
| 349 |
window.localStorage.removeItem( 'quiz_userdata_' + lpQuizSettings.id ); |
| 350 |
window.localStorage.setItem( 'quiz_start_' + lpQuizSettings.id, Date.now() ); |
| 351 |
// Set retake to local.storage |
| 352 |
const retakenNumber = window.localStorage.getItem( 'quiz_retake_' + lpQuizSettings.id ); |
| 353 |
if ( retakenNumber >= 1 ) { |
| 354 |
window.localStorage.setItem( 'quiz_retake_' + lpQuizSettings.id, parseInt( retakenNumber ) + 1 ); |
| 355 |
} else { |
| 356 |
window.localStorage.setItem( 'quiz_retake_' + lpQuizSettings.id, 1 ); |
| 357 |
} |
| 358 |
}*/ |
| 359 |
|
| 360 |
startQuiz(); |
| 361 |
}; |
| 362 |
nav = to => event => { |
| 363 |
let { |
| 364 |
questionNav, |
| 365 |
currentPage, |
| 366 |
numPages, |
| 367 |
setCurrentPage |
| 368 |
} = this.props; |
| 369 |
switch (to) { |
| 370 |
case 'prev': |
| 371 |
if (currentPage > 1) { |
| 372 |
currentPage = currentPage - 1; |
| 373 |
} else if (questionNav === 'infinity') { |
| 374 |
currentPage = numPages; |
| 375 |
} else { |
| 376 |
currentPage = 1; |
| 377 |
} |
| 378 |
break; |
| 379 |
default: |
| 380 |
if (currentPage < numPages) { |
| 381 |
currentPage = currentPage + 1; |
| 382 |
} else if (questionNav === 'infinity') { |
| 383 |
currentPage = 1; |
| 384 |
} else { |
| 385 |
currentPage = numPages; |
| 386 |
} |
| 387 |
} |
| 388 |
setCurrentPage(currentPage); |
| 389 |
}; |
| 390 |
moveTo = pageNum => event => { |
| 391 |
event.preventDefault(); |
| 392 |
const { |
| 393 |
numPages, |
| 394 |
setCurrentPage |
| 395 |
} = this.props; |
| 396 |
if (pageNum < 1 || pageNum > numPages) { |
| 397 |
return; |
| 398 |
} |
| 399 |
setCurrentPage(pageNum); |
| 400 |
}; |
| 401 |
isLast = () => { |
| 402 |
const { |
| 403 |
currentPage, |
| 404 |
numPages |
| 405 |
} = this.props; |
| 406 |
return currentPage === numPages; |
| 407 |
}; |
| 408 |
isFirst = () => { |
| 409 |
const { |
| 410 |
currentPage |
| 411 |
} = this.props; |
| 412 |
return currentPage === 1; |
| 413 |
}; |
| 414 |
submit = () => { |
| 415 |
const { |
| 416 |
submitQuiz |
| 417 |
} = this.props; |
| 418 |
const { |
| 419 |
confirm |
| 420 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/modal'); |
| 421 |
if ('no' === confirm((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Are you sure to submit the quiz?', 'learnpress'), this.submit)) { |
| 422 |
return; |
| 423 |
} |
| 424 |
submitQuiz(); |
| 425 |
}; |
| 426 |
setQuizMode = mode => () => { |
| 427 |
const { |
| 428 |
setQuizMode |
| 429 |
} = this.props; |
| 430 |
setQuizMode(mode); |
| 431 |
}; |
| 432 |
isReviewing = () => { |
| 433 |
const { |
| 434 |
isReviewing |
| 435 |
} = this.props; |
| 436 |
return isReviewing; |
| 437 |
}; |
| 438 |
pageNumbers(args) { |
| 439 |
const { |
| 440 |
numPages, |
| 441 |
currentPage |
| 442 |
} = this.props; |
| 443 |
if (numPages < 2) { |
| 444 |
return ''; |
| 445 |
} |
| 446 |
args = { |
| 447 |
numPages, |
| 448 |
currentPage, |
| 449 |
midSize: 1, |
| 450 |
endSize: 1, |
| 451 |
prevNext: true, |
| 452 |
...(args || {}) |
| 453 |
}; |
| 454 |
if (args.endSize < 1) { |
| 455 |
args.endSize = 1; |
| 456 |
} |
| 457 |
if (args.midSize < 0) { |
| 458 |
args.midSize = 1; |
| 459 |
} |
| 460 |
const numbers = [...Array(numPages).keys()]; |
| 461 |
let dots = false; |
| 462 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 463 |
className: "nav-links" |
| 464 |
}, args.prevNext && !this.isFirst() && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 465 |
className: "page-numbers prev", |
| 466 |
"data-type": "question-navx", |
| 467 |
onClick: this.nav('prev') |
| 468 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Prev', 'learnpress')), numbers.map(number => { |
| 469 |
number = number + 1; |
| 470 |
if (number === args.currentPage) { |
| 471 |
dots = true; |
| 472 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 473 |
key: `page-number-${number}`, |
| 474 |
className: "page-numbers current" |
| 475 |
}, number); |
| 476 |
} |
| 477 |
if (number <= args.endSize || args.currentPage && number >= args.currentPage - args.midSize && number <= args.currentPage + args.midSize || number > args.numPages - args.endSize) { |
| 478 |
dots = true; |
| 479 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 480 |
key: `page-number-${number}`, |
| 481 |
className: "page-numbers", |
| 482 |
onClick: this.moveTo(number) |
| 483 |
}, number); |
| 484 |
} else if (dots) { |
| 485 |
dots = false; |
| 486 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 487 |
key: `page-number-${number}`, |
| 488 |
className: "page-numbers dots" |
| 489 |
}, "\u2026"); |
| 490 |
} |
| 491 |
return ''; |
| 492 |
}), args.prevNext && !this.isLast() && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 493 |
className: "page-numbers next", |
| 494 |
"data-type": "question-navx", |
| 495 |
onClick: this.nav('next') |
| 496 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Next', 'learnpress'))); |
| 497 |
} |
| 498 |
render() { |
| 499 |
const { |
| 500 |
status, |
| 501 |
questionNav, |
| 502 |
isReviewing, |
| 503 |
showReview, |
| 504 |
numPages, |
| 505 |
question, |
| 506 |
questionsPerPage, |
| 507 |
canRetry, |
| 508 |
retakeNumber, |
| 509 |
requiredPassword, |
| 510 |
allowRetake |
| 511 |
} = this.props; |
| 512 |
const classNames = ['quiz-buttons']; |
| 513 |
if (status === 'started' || isReviewing) { |
| 514 |
classNames.push('align-center'); |
| 515 |
} |
| 516 |
if (questionNav === 'questionNav') { |
| 517 |
classNames.push('infinity'); |
| 518 |
} |
| 519 |
if (this.isFirst()) { |
| 520 |
classNames.push('is-first'); |
| 521 |
} |
| 522 |
if (this.isLast()) { |
| 523 |
classNames.push('is-last'); |
| 524 |
} |
| 525 |
const popupSidebar = document.querySelector('#popup-sidebar'); |
| 526 |
const quizzApp = document.querySelector('#learn-press-quiz-app'); |
| 527 |
let styles = ''; |
| 528 |
if (status === 'started' || isReviewing) { |
| 529 |
styles = { |
| 530 |
marginLeft: popupSidebar && popupSidebar.offsetWidth / 2, |
| 531 |
width: quizzApp && quizzApp.offsetWidth |
| 532 |
}; |
| 533 |
} else { |
| 534 |
styles = null; |
| 535 |
} |
| 536 |
let navPositionClass = ' fixed'; |
| 537 |
if (lpQuizSettings.navigationPosition == 'no') { |
| 538 |
navPositionClass = ' nav-center'; |
| 539 |
} |
| 540 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 541 |
className: classNames.join(' ') |
| 542 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 543 |
className: `button-left` + (status === 'started' || isReviewing ? navPositionClass : ''), |
| 544 |
style: styles |
| 545 |
}, (status === 'completed' && canRetry || -1 !== ['', 'viewed'].indexOf(status)) && !isReviewing && !requiredPassword && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 546 |
className: "lp-button start", |
| 547 |
onClick: this.startQuiz |
| 548 |
}, status === 'completed' ? `${(0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Retake', 'learnpress')} ${!allowRetake ? ` ${retakeNumber ? ` (${retakeNumber})` : ''}` : ''} ` : ' ' + (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Start', 'learnpress')), ('started' === status || isReviewing) && numPages > 1 && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 549 |
className: "questions-pagination" |
| 550 |
}, this.pageNumbers()))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 551 |
className: "button-right" |
| 552 |
}, 'started' === status && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, ('infinity' === questionNav || this.isLast()) && !isReviewing && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 553 |
className: "lp-button submit-quiz", |
| 554 |
onClick: this.submit |
| 555 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Finish Quiz', 'learnpress'))), isReviewing && showReview && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 556 |
className: "lp-button back-quiz", |
| 557 |
onClick: this.setQuizMode('') |
| 558 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Result', 'learnpress')), 'completed' === status && showReview && !isReviewing && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 559 |
className: "lp-button review-quiz", |
| 560 |
onClick: this.setQuizMode('reviewing') |
| 561 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Review', 'learnpress')))), this.props.message && this.props.success !== true && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 562 |
className: "learn-press-message error" |
| 563 |
}, this.props.message)); |
| 564 |
} |
| 565 |
} |
| 566 |
|
| 567 |
/** |
| 568 |
* Helper function to check a button should be show or not. |
| 569 |
* |
| 570 |
* Buttons [hint, check] |
| 571 |
*/ |
| 572 |
const MaybeShowButton = (0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__.compose)((0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withSelect)(select => { |
| 573 |
const { |
| 574 |
getData |
| 575 |
} = select('learnpress/quiz'); |
| 576 |
return { |
| 577 |
status: getData('status'), |
| 578 |
showCheck: getData('instantCheck'), |
| 579 |
checkedQuestions: getData('checkedQuestions'), |
| 580 |
hintedQuestions: getData('hintedQuestions'), |
| 581 |
questionsPerPage: getData('questionsPerPage') |
| 582 |
}; |
| 583 |
}))(props => { |
| 584 |
const { |
| 585 |
showCheck, |
| 586 |
checkedQuestions, |
| 587 |
hintedQuestions, |
| 588 |
question, |
| 589 |
status, |
| 590 |
type, |
| 591 |
Button |
| 592 |
} = props; |
| 593 |
if (status !== 'started') { |
| 594 |
return false; |
| 595 |
} |
| 596 |
const theButton = (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Button, { |
| 597 |
question: question |
| 598 |
}); |
| 599 |
switch (type) { |
| 600 |
case 'hint': |
| 601 |
if (!hintedQuestions) { |
| 602 |
return theButton; |
| 603 |
} |
| 604 |
if (!question.hasHint) { |
| 605 |
return false; |
| 606 |
} |
| 607 |
return hintedQuestions.indexOf(question.id) === -1 && theButton; |
| 608 |
case 'check': |
| 609 |
if (!showCheck) { |
| 610 |
return false; |
| 611 |
} |
| 612 |
if (!checkedQuestions) { |
| 613 |
return theButton; |
| 614 |
} |
| 615 |
return checkedQuestions.indexOf(question.id) === -1 && theButton; |
| 616 |
} |
| 617 |
}); |
| 618 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__.compose)([(0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withSelect)(select => { |
| 619 |
const { |
| 620 |
getData, |
| 621 |
getCurrentQuestion |
| 622 |
} = select('learnpress/quiz'); |
| 623 |
const data = { |
| 624 |
id: getData('id'), |
| 625 |
status: getData('status'), |
| 626 |
questionIds: getData('questionIds'), |
| 627 |
questionNav: getData('questionNav'), |
| 628 |
isReviewing: getData('reviewQuestions') && getData('mode') === 'reviewing', |
| 629 |
showReview: getData('reviewQuestions'), |
| 630 |
showCheck: getData('instantCheck'), |
| 631 |
checkedQuestions: getData('checkedQuestions'), |
| 632 |
hintedQuestions: getData('hintedQuestions'), |
| 633 |
numPages: getData('numPages'), |
| 634 |
pages: getData('pages'), |
| 635 |
currentPage: getData('currentPage'), |
| 636 |
questionsPerPage: getData('questionsPerPage'), |
| 637 |
pageNumbers: getData('pageNumbers'), |
| 638 |
keyPressed: getData('keyPressed'), |
| 639 |
canRetry: getData('retakeCount') > 0 && getData('retaken') < getData('retakeCount'), |
| 640 |
retakeNumber: getData('retakeCount') > 0 && getData('retaken') < getData('retakeCount') ? getData('retakeCount') - getData('retaken') : null, |
| 641 |
message: getData('messageResponse') || false, |
| 642 |
success: getData('successResponse') !== undefined ? getData('successResponse') : true, |
| 643 |
requiredPassword: getData('requiredPassword'), |
| 644 |
allowRetake: getData('allowRetake') |
| 645 |
}; |
| 646 |
if (data.questionsPerPage === 1) { |
| 647 |
data.question = getCurrentQuestion('object'); |
| 648 |
} |
| 649 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 650 |
const retakenCurrent = window.localStorage.getItem('quiz_off_retaken_' + lpQuizSettings.id); |
| 651 |
if (getData('retakeCount') > retakenCurrent) { |
| 652 |
data.retakeNumber = getData('retakeCount') - retakenCurrent; |
| 653 |
data.canRetry = true; |
| 654 |
} else { |
| 655 |
data.canRetry = false; |
| 656 |
} |
| 657 |
} |
| 658 |
if (data.allowRetake) { |
| 659 |
data.canRetry = true; |
| 660 |
} |
| 661 |
return data; |
| 662 |
}), (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withDispatch)((dispatch, { |
| 663 |
id |
| 664 |
}) => { |
| 665 |
const { |
| 666 |
startQuiz, |
| 667 |
setCurrentQuestion, |
| 668 |
submitQuiz, |
| 669 |
setQuizMode, |
| 670 |
showHint, |
| 671 |
checkAnswer, |
| 672 |
setCurrentPage |
| 673 |
} = dispatch('learnpress/quiz'); |
| 674 |
return { |
| 675 |
startQuiz, |
| 676 |
setCurrentQuestion, |
| 677 |
setQuizMode, |
| 678 |
setCurrentPage, |
| 679 |
submitQuiz(id) { |
| 680 |
submitQuiz(id); |
| 681 |
}, |
| 682 |
showHint(id) { |
| 683 |
showHint(id); |
| 684 |
}, |
| 685 |
checkAnswer(id) { |
| 686 |
checkAnswer(id); |
| 687 |
} |
| 688 |
}; |
| 689 |
})])(Buttons)); |
| 690 |
|
| 691 |
/***/ }, |
| 692 |
|
| 693 |
/***/ "./assets/src/apps/js/frontend/quiz/components/content/index.js" |
| 694 |
/*!**********************************************************************!*\ |
| 695 |
!*** ./assets/src/apps/js/frontend/quiz/components/content/index.js ***! |
| 696 |
\**********************************************************************/ |
| 697 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 698 |
|
| 699 |
"use strict"; |
| 700 |
__webpack_require__.r(__webpack_exports__); |
| 701 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 702 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 703 |
/* harmony export */ }); |
| 704 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 705 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 706 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 707 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); |
| 708 |
|
| 709 |
/** |
| 710 |
* Quiz Content. |
| 711 |
* Edit: Use React hook. |
| 712 |
* |
| 713 |
* @author nhamdv - ThimPress |
| 714 |
*/ |
| 715 |
|
| 716 |
const Content = () => { |
| 717 |
const content = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz').getData('content'); |
| 718 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 719 |
className: "quiz-content", |
| 720 |
dangerouslySetInnerHTML: { |
| 721 |
__html: content |
| 722 |
} |
| 723 |
}); |
| 724 |
}; |
| 725 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Content); |
| 726 |
|
| 727 |
/***/ }, |
| 728 |
|
| 729 |
/***/ "./assets/src/apps/js/frontend/quiz/components/duration/index.js" |
| 730 |
/*!***********************************************************************!*\ |
| 731 |
!*** ./assets/src/apps/js/frontend/quiz/components/duration/index.js ***! |
| 732 |
\***********************************************************************/ |
| 733 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 734 |
|
| 735 |
"use strict"; |
| 736 |
__webpack_require__.r(__webpack_exports__); |
| 737 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 738 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 739 |
/* harmony export */ }); |
| 740 |
const formatDuration = seconds => { |
| 741 |
let d; |
| 742 |
const dayInSeconds = 3600 * 24; |
| 743 |
if (seconds > dayInSeconds) { |
| 744 |
d = (seconds - seconds % dayInSeconds) / dayInSeconds; |
| 745 |
seconds = seconds % dayInSeconds; |
| 746 |
} else if (seconds == dayInSeconds) { |
| 747 |
return '24:00'; |
| 748 |
} |
| 749 |
const x = new Date(seconds * 1000).toUTCString().match(/\d{2}:\d{2}:\d{2}/)[0].split(':'); |
| 750 |
if (d) { |
| 751 |
x[0] = parseInt(x[0]) + d * 24; |
| 752 |
} |
| 753 |
const html = x.join(':'); |
| 754 |
return html; |
| 755 |
}; |
| 756 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (formatDuration); |
| 757 |
|
| 758 |
/***/ }, |
| 759 |
|
| 760 |
/***/ "./assets/src/apps/js/frontend/quiz/components/index.js" |
| 761 |
/*!**************************************************************!*\ |
| 762 |
!*** ./assets/src/apps/js/frontend/quiz/components/index.js ***! |
| 763 |
\**************************************************************/ |
| 764 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 765 |
|
| 766 |
"use strict"; |
| 767 |
__webpack_require__.r(__webpack_exports__); |
| 768 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 769 |
/* harmony export */ Attempts: () => (/* reexport safe */ _attempts__WEBPACK_IMPORTED_MODULE_5__["default"]), |
| 770 |
/* harmony export */ Buttons: () => (/* reexport safe */ _buttons__WEBPACK_IMPORTED_MODULE_3__["default"]), |
| 771 |
/* harmony export */ Content: () => (/* reexport safe */ _content__WEBPACK_IMPORTED_MODULE_1__["default"]), |
| 772 |
/* harmony export */ Meta: () => (/* reexport safe */ _meta__WEBPACK_IMPORTED_MODULE_2__["default"]), |
| 773 |
/* harmony export */ Questions: () => (/* reexport safe */ _questions__WEBPACK_IMPORTED_MODULE_4__["default"]), |
| 774 |
/* harmony export */ Result: () => (/* reexport safe */ _result__WEBPACK_IMPORTED_MODULE_7__["default"]), |
| 775 |
/* harmony export */ Status: () => (/* reexport safe */ _status__WEBPACK_IMPORTED_MODULE_8__["default"]), |
| 776 |
/* harmony export */ Timer: () => (/* reexport safe */ _timer__WEBPACK_IMPORTED_MODULE_6__["default"]), |
| 777 |
/* harmony export */ Title: () => (/* reexport safe */ _title__WEBPACK_IMPORTED_MODULE_0__["default"]) |
| 778 |
/* harmony export */ }); |
| 779 |
/* harmony import */ var _title__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./title */ "./assets/src/apps/js/frontend/quiz/components/title/index.js"); |
| 780 |
/* harmony import */ var _content__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./content */ "./assets/src/apps/js/frontend/quiz/components/content/index.js"); |
| 781 |
/* harmony import */ var _meta__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./meta */ "./assets/src/apps/js/frontend/quiz/components/meta/index.js"); |
| 782 |
/* harmony import */ var _buttons__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./buttons */ "./assets/src/apps/js/frontend/quiz/components/buttons/index.js"); |
| 783 |
/* harmony import */ var _questions__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./questions */ "./assets/src/apps/js/frontend/quiz/components/questions/index.js"); |
| 784 |
/* harmony import */ var _attempts__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./attempts */ "./assets/src/apps/js/frontend/quiz/components/attempts/index.js"); |
| 785 |
/* harmony import */ var _timer__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ./timer */ "./assets/src/apps/js/frontend/quiz/components/timer/index.js"); |
| 786 |
/* harmony import */ var _result__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ./result */ "./assets/src/apps/js/frontend/quiz/components/result/index.js"); |
| 787 |
/* harmony import */ var _status__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ./status */ "./assets/src/apps/js/frontend/quiz/components/status/index.js"); |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
/***/ }, |
| 799 |
|
| 800 |
/***/ "./assets/src/apps/js/frontend/quiz/components/meta/index.js" |
| 801 |
/*!*******************************************************************!*\ |
| 802 |
!*** ./assets/src/apps/js/frontend/quiz/components/meta/index.js ***! |
| 803 |
\*******************************************************************/ |
| 804 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 805 |
|
| 806 |
"use strict"; |
| 807 |
__webpack_require__.r(__webpack_exports__); |
| 808 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 809 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 810 |
/* harmony export */ }); |
| 811 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 812 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 813 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 814 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); |
| 815 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 816 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__); |
| 817 |
/* harmony import */ var _duration__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../duration */ "./assets/src/apps/js/frontend/quiz/components/duration/index.js"); |
| 818 |
|
| 819 |
/** |
| 820 |
* Quiz Meta. |
| 821 |
* Edit: Use React Hook. |
| 822 |
* |
| 823 |
* @author Nhamdv - ThimPress |
| 824 |
*/ |
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
const { |
| 829 |
Hook |
| 830 |
} = LP; |
| 831 |
const Meta = () => { |
| 832 |
const getData = attr => { |
| 833 |
return (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz').getData(attr); |
| 834 |
}; |
| 835 |
const metaFields = Hook.applyFilters('quiz-meta-fields', { |
| 836 |
duration: { |
| 837 |
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Duration:', 'learnpress'), |
| 838 |
name: 'duration', |
| 839 |
content: (0,_duration__WEBPACK_IMPORTED_MODULE_3__["default"])(getData('duration')) || '--' |
| 840 |
}, |
| 841 |
passingGrade: { |
| 842 |
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Passing grade:', 'learnpress'), |
| 843 |
name: 'passing-grade', |
| 844 |
content: getData('passingGrade') || '--' |
| 845 |
}, |
| 846 |
questionsCount: { |
| 847 |
title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_2__.__)('Questions:', 'learnpress'), |
| 848 |
name: 'questions-count', |
| 849 |
content: getData('questionIds') ? getData('questionIds').length : 0 |
| 850 |
} |
| 851 |
}); |
| 852 |
return metaFields && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("ul", { |
| 853 |
className: "quiz-intro" |
| 854 |
}, Object.values(metaFields).map((field, i) => { |
| 855 |
const id = field.name || i; |
| 856 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 857 |
key: `quiz-intro-field-${i}`, |
| 858 |
className: `quiz-intro-item quiz-intro-item--${id}` |
| 859 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 860 |
className: "quiz-intro-item__title", |
| 861 |
dangerouslySetInnerHTML: { |
| 862 |
__html: field.title |
| 863 |
} |
| 864 |
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 865 |
className: "quiz-intro-item__content", |
| 866 |
dangerouslySetInnerHTML: { |
| 867 |
__html: field.content |
| 868 |
} |
| 869 |
})); |
| 870 |
}))); |
| 871 |
}; |
| 872 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Meta); |
| 873 |
|
| 874 |
/***/ }, |
| 875 |
|
| 876 |
/***/ "./assets/src/apps/js/frontend/quiz/components/questions/buttons.js" |
| 877 |
/*!**************************************************************************!*\ |
| 878 |
!*** ./assets/src/apps/js/frontend/quiz/components/questions/buttons.js ***! |
| 879 |
\**************************************************************************/ |
| 880 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 881 |
|
| 882 |
"use strict"; |
| 883 |
__webpack_require__.r(__webpack_exports__); |
| 884 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 885 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 886 |
/* harmony export */ }); |
| 887 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 888 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 889 |
/* harmony import */ var _buttons_button_hint__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../buttons/button-hint */ "./assets/src/apps/js/frontend/quiz/components/buttons/button-hint.js"); |
| 890 |
/* harmony import */ var _buttons_button_check__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../buttons/button-check */ "./assets/src/apps/js/frontend/quiz/components/buttons/button-check.js"); |
| 891 |
/* harmony import */ var _buttons__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../buttons */ "./assets/src/apps/js/frontend/quiz/components/buttons/index.js"); |
| 892 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 893 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_4__); |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
const Buttons = function Buttons(props) { |
| 900 |
const { |
| 901 |
question |
| 902 |
} = props; |
| 903 |
const buttons = { |
| 904 |
'instant-check': () => { |
| 905 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_buttons__WEBPACK_IMPORTED_MODULE_3__.MaybeShowButton, { |
| 906 |
type: "check", |
| 907 |
Button: _buttons_button_check__WEBPACK_IMPORTED_MODULE_2__["default"], |
| 908 |
question: question |
| 909 |
}); |
| 910 |
}, |
| 911 |
hint: () => { |
| 912 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_buttons__WEBPACK_IMPORTED_MODULE_3__.MaybeShowButton, { |
| 913 |
type: "hint", |
| 914 |
Button: _buttons_button_hint__WEBPACK_IMPORTED_MODULE_1__["default"], |
| 915 |
question: question |
| 916 |
}); |
| 917 |
} |
| 918 |
}; |
| 919 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_4__.Fragment, null, LP.config.questionFooterButtons().map(name => { |
| 920 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_4__.Fragment, { |
| 921 |
key: `button-${name}` |
| 922 |
}, buttons[name] && buttons[name]()); |
| 923 |
})); |
| 924 |
}; |
| 925 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Buttons); |
| 926 |
|
| 927 |
/***/ }, |
| 928 |
|
| 929 |
/***/ "./assets/src/apps/js/frontend/quiz/components/questions/index.js" |
| 930 |
/*!************************************************************************!*\ |
| 931 |
!*** ./assets/src/apps/js/frontend/quiz/components/questions/index.js ***! |
| 932 |
\************************************************************************/ |
| 933 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 934 |
|
| 935 |
"use strict"; |
| 936 |
__webpack_require__.r(__webpack_exports__); |
| 937 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 938 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 939 |
/* harmony export */ }); |
| 940 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 941 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 942 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 943 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 944 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 945 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 946 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 947 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__); |
| 948 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 949 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); |
| 950 |
/* harmony import */ var _question__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./question */ "./assets/src/apps/js/frontend/quiz/components/questions/question.js"); |
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
class Questions extends _wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Component { |
| 958 |
constructor(props) { |
| 959 |
super(...arguments); |
| 960 |
this.needToTop = false; |
| 961 |
this.state = { |
| 962 |
isReviewing: null, |
| 963 |
currentPage: 0, |
| 964 |
self: this |
| 965 |
}; |
| 966 |
} |
| 967 |
static getDerivedStateFromProps(props, state) { |
| 968 |
const checkProps = ['isReviewing', 'currentPage']; |
| 969 |
const changedProps = {}; |
| 970 |
for (let i = 0; i < checkProps.length; i++) { |
| 971 |
if (props[checkProps[i]] !== state[checkProps[i]]) { |
| 972 |
changedProps[checkProps[i]] = props[checkProps[i]]; |
| 973 |
} |
| 974 |
} |
| 975 |
if (Object.values(changedProps).length) { |
| 976 |
if (props.questionsPerPage === 1) { |
| 977 |
state.self.needToTop = true; |
| 978 |
} |
| 979 |
return changedProps; |
| 980 |
} |
| 981 |
return null; |
| 982 |
} |
| 983 |
|
| 984 |
// componentWillReceiveProps(nextProps){ |
| 985 |
// const checkProps = ['isReviewing', 'currentPage']; |
| 986 |
// |
| 987 |
// for(let i = 0; i < checkProps.length; i++){ |
| 988 |
// if(this.props[checkProps[i]] !== nextProps[checkProps[i]]){ |
| 989 |
// this.needToTop = true; |
| 990 |
// return; |
| 991 |
// } |
| 992 |
// } |
| 993 |
// |
| 994 |
// } |
| 995 |
|
| 996 |
// componentWillUpdate() { |
| 997 |
// this.needToTop = this.state.needToTop; |
| 998 |
// this.setState({needToTop: false}); |
| 999 |
// } |
| 1000 |
|
| 1001 |
componentDidUpdate() { |
| 1002 |
if (this.needToTop) { |
| 1003 |
jQuery('#popup-content').animate({ |
| 1004 |
scrollTop: 0 |
| 1005 |
}).find('.content-item-scrollable:last').animate({ |
| 1006 |
scrollTop: 0 |
| 1007 |
}); |
| 1008 |
this.needToTop = false; |
| 1009 |
} |
| 1010 |
} |
| 1011 |
startQuiz = event => { |
| 1012 |
event.preventDefault(); |
| 1013 |
const { |
| 1014 |
startQuiz |
| 1015 |
} = this.props; |
| 1016 |
startQuiz(); |
| 1017 |
}; |
| 1018 |
isInVisibleRange = (id, index) => { |
| 1019 |
const { |
| 1020 |
currentPage, |
| 1021 |
questionsPerPage |
| 1022 |
} = this.props; |
| 1023 |
return currentPage === Math.ceil(index / questionsPerPage); |
| 1024 |
}; |
| 1025 |
nav = event => { |
| 1026 |
const { |
| 1027 |
sendKey |
| 1028 |
} = this.props; |
| 1029 |
switch (event.keyCode) { |
| 1030 |
case 37: |
| 1031 |
return sendKey('left'); |
| 1032 |
case 38: |
| 1033 |
return; |
| 1034 |
case 39: |
| 1035 |
return sendKey('right'); |
| 1036 |
case 40: |
| 1037 |
return; |
| 1038 |
default: |
| 1039 |
if (event.keyCode >= 49 && event.keyCode <= 57) { |
| 1040 |
sendKey(event.keyCode - 48); |
| 1041 |
} |
| 1042 |
} |
| 1043 |
}; |
| 1044 |
render() { |
| 1045 |
const { |
| 1046 |
status, |
| 1047 |
currentQuestion, |
| 1048 |
questions, |
| 1049 |
questionsRendered, |
| 1050 |
isReviewing, |
| 1051 |
questionsPerPage |
| 1052 |
} = this.props; |
| 1053 |
let isShow = true; |
| 1054 |
if (status === 'completed' && !isReviewing) { |
| 1055 |
isShow = false; |
| 1056 |
} |
| 1057 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1058 |
tabIndex: 100, |
| 1059 |
onKeyUp: this.nav |
| 1060 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1061 |
className: "quiz-questions", |
| 1062 |
style: { |
| 1063 |
display: isShow ? '' : 'none' |
| 1064 |
} |
| 1065 |
}, questions.map((question, index) => { |
| 1066 |
const isCurrent = questionsPerPage ? false : currentQuestion === question.id; |
| 1067 |
const isRendered = questionsRendered && questionsRendered.indexOf(question.id) !== -1; |
| 1068 |
const isVisible = this.isInVisibleRange(question.id, index + 1); |
| 1069 |
return isRendered || !isRendered || isVisible ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_question__WEBPACK_IMPORTED_MODULE_5__["default"], { |
| 1070 |
key: `loop-question-${question.id}`, |
| 1071 |
isCurrent: isCurrent, |
| 1072 |
isShow: isVisible, |
| 1073 |
isShowIndex: questionsPerPage ? index + 1 : false, |
| 1074 |
questionsPerPage: questionsPerPage, |
| 1075 |
question: question |
| 1076 |
}) : ''; |
| 1077 |
})))); |
| 1078 |
} |
| 1079 |
} |
| 1080 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__.compose)((0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withSelect)((select, a, b) => { |
| 1081 |
const { |
| 1082 |
getData, |
| 1083 |
getQuestions |
| 1084 |
} = select('learnpress/quiz'); |
| 1085 |
return { |
| 1086 |
status: getData('status'), |
| 1087 |
currentQuestion: getData('currentQuestion'), |
| 1088 |
questions: getQuestions(), |
| 1089 |
questionsRendered: getData('questionsRendered'), |
| 1090 |
isReviewing: getData('mode') === 'reviewing', |
| 1091 |
numPages: getData('numPages'), |
| 1092 |
currentPage: getData('currentPage'), |
| 1093 |
questionsPerPage: getData('questionsPerPage') || 1 |
| 1094 |
}; |
| 1095 |
}), (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withDispatch)(dispatch => { |
| 1096 |
const { |
| 1097 |
startQuiz, |
| 1098 |
sendKey |
| 1099 |
} = dispatch('learnpress/quiz'); |
| 1100 |
return { |
| 1101 |
startQuiz, |
| 1102 |
sendKey |
| 1103 |
}; |
| 1104 |
}))(Questions)); |
| 1105 |
|
| 1106 |
/***/ }, |
| 1107 |
|
| 1108 |
/***/ "./assets/src/apps/js/frontend/quiz/components/questions/question.js" |
| 1109 |
/*!***************************************************************************!*\ |
| 1110 |
!*** ./assets/src/apps/js/frontend/quiz/components/questions/question.js ***! |
| 1111 |
\***************************************************************************/ |
| 1112 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1113 |
|
| 1114 |
"use strict"; |
| 1115 |
__webpack_require__.r(__webpack_exports__); |
| 1116 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1117 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1118 |
/* harmony export */ }); |
| 1119 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1120 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1121 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 1122 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 1123 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 1124 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 1125 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 1126 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__); |
| 1127 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 1128 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); |
| 1129 |
/* harmony import */ var _buttons__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./buttons */ "./assets/src/apps/js/frontend/quiz/components/questions/buttons.js"); |
| 1130 |
/* harmony import */ var _buttons__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(/*! ../buttons */ "./assets/src/apps/js/frontend/quiz/components/buttons/index.js"); |
| 1131 |
/* harmony import */ var _buttons_button_check__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(/*! ../buttons/button-check */ "./assets/src/apps/js/frontend/quiz/components/buttons/button-check.js"); |
| 1132 |
/* harmony import */ var _buttons_button_hint__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(/*! ../buttons/button-hint */ "./assets/src/apps/js/frontend/quiz/components/buttons/button-hint.js"); |
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
const $ = window.jQuery; |
| 1143 |
const { |
| 1144 |
uniqueId, |
| 1145 |
isArray, |
| 1146 |
isNumber, |
| 1147 |
bind |
| 1148 |
} = lodash; |
| 1149 |
class Question extends _wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Component { |
| 1150 |
constructor() { |
| 1151 |
super(...arguments); |
| 1152 |
this.state = { |
| 1153 |
time: null, |
| 1154 |
showHint: false |
| 1155 |
}; |
| 1156 |
this.$wrap = null; |
| 1157 |
} |
| 1158 |
componentDidMount(a) { |
| 1159 |
const { |
| 1160 |
question, |
| 1161 |
isCurrent, |
| 1162 |
markQuestionRendered |
| 1163 |
} = this.props; |
| 1164 |
if (isCurrent) { |
| 1165 |
markQuestionRendered(question.id); |
| 1166 |
} |
| 1167 |
if (!this.state.time) { |
| 1168 |
this.setState({ |
| 1169 |
time: new Date() |
| 1170 |
}); |
| 1171 |
} |
| 1172 |
LP.Hook.doAction('lp-question-compatible-builder'); |
| 1173 |
if (typeof MathJax !== 'undefined' && typeof MathJax.Hub !== 'undefined') { |
| 1174 |
MathJax.Hub.Queue(['Typeset', MathJax.Hub]); |
| 1175 |
} |
| 1176 |
return a; |
| 1177 |
} |
| 1178 |
setRef = el => { |
| 1179 |
this.$wrap = $(el); |
| 1180 |
}; |
| 1181 |
parseOptions = options => { |
| 1182 |
if (options) { |
| 1183 |
options = !isArray(options) ? JSON.parse(CryptoJS.AES.decrypt(options.data, options.key, { |
| 1184 |
format: CryptoJSAesJson |
| 1185 |
}).toString(CryptoJS.enc.Utf8)) : options; |
| 1186 |
options = !isArray(options) ? JSON.parse(options) : options; |
| 1187 |
} |
| 1188 |
return options || []; |
| 1189 |
}; |
| 1190 |
getWrapperClass = () => { |
| 1191 |
const { |
| 1192 |
question, |
| 1193 |
answered |
| 1194 |
} = this.props; |
| 1195 |
const classes = ['question', 'question-' + question.type]; |
| 1196 |
const options = this.parseOptions(question.options); |
| 1197 |
if (options.length && options[0].isTrue !== undefined) { |
| 1198 |
classes.push('question-answered'); |
| 1199 |
} |
| 1200 |
return classes; |
| 1201 |
}; |
| 1202 |
getEditLink = () => { |
| 1203 |
const { |
| 1204 |
question, |
| 1205 |
editPermalink |
| 1206 |
} = this.props; |
| 1207 |
return editPermalink ? editPermalink.replace(/post=(.*[0-9])/, `post=${question.id}`) : ''; |
| 1208 |
}; |
| 1209 |
editPermalink = editPermalink => { |
| 1210 |
return (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)('<a href="%s">%s</a>', editPermalink, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Edit', 'learnpress')); |
| 1211 |
}; |
| 1212 |
render() { |
| 1213 |
const { |
| 1214 |
question, |
| 1215 |
isShow, |
| 1216 |
isShowIndex, |
| 1217 |
isShowHint, |
| 1218 |
status, |
| 1219 |
results |
| 1220 |
} = this.props; |
| 1221 |
if (results && results.questions && results.questions[question.id]) { |
| 1222 |
if (typeof results.questions[question.id].correct !== 'undefined') { |
| 1223 |
question.correct = results.questions[question.id].correct; |
| 1224 |
} |
| 1225 |
} |
| 1226 |
const QuestionTypes = LP.questionTypes.default; |
| 1227 |
const editPermalink = this.getEditLink(); |
| 1228 |
if (editPermalink) { |
| 1229 |
jQuery('#wp-admin-bar-edit-lp_question').find('.ab-item').attr('href', editPermalink); |
| 1230 |
} |
| 1231 |
const titleParts = { |
| 1232 |
index: () => { |
| 1233 |
return isShowIndex ? (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 1234 |
className: "question-index" |
| 1235 |
}, isShowIndex, ".") : ''; |
| 1236 |
}, |
| 1237 |
title: () => { |
| 1238 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 1239 |
dangerouslySetInnerHTML: { |
| 1240 |
__html: question.title |
| 1241 |
} |
| 1242 |
}); |
| 1243 |
}, |
| 1244 |
hint: () => { |
| 1245 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_buttons_button_hint__WEBPACK_IMPORTED_MODULE_8__["default"], { |
| 1246 |
question: question |
| 1247 |
}); |
| 1248 |
}, |
| 1249 |
'edit-permalink': () => { |
| 1250 |
return editPermalink && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 1251 |
dangerouslySetInnerHTML: { |
| 1252 |
__html: this.editPermalink(editPermalink) |
| 1253 |
}, |
| 1254 |
className: "edit-link" |
| 1255 |
}); |
| 1256 |
} |
| 1257 |
}; |
| 1258 |
const blocks = { |
| 1259 |
title: () => { |
| 1260 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h4", { |
| 1261 |
className: "question-title" |
| 1262 |
}, LP.config.questionTitleParts().map(name => { |
| 1263 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Fragment, { |
| 1264 |
key: `title-part-${name}` |
| 1265 |
}, titleParts[name] && titleParts[name]()); |
| 1266 |
})); |
| 1267 |
}, |
| 1268 |
content: () => { |
| 1269 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1270 |
className: "question-content", |
| 1271 |
dangerouslySetInnerHTML: { |
| 1272 |
__html: question.content |
| 1273 |
} |
| 1274 |
}); |
| 1275 |
}, |
| 1276 |
'answer-options': () => { |
| 1277 |
return this.$wrap && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(QuestionTypes, { |
| 1278 |
...this.props, |
| 1279 |
$wrap: this.$wrap |
| 1280 |
}); |
| 1281 |
}, |
| 1282 |
explanation: () => { |
| 1283 |
return question.explanation && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1284 |
className: "question-explanation-content" |
| 1285 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("strong", { |
| 1286 |
className: "explanation-title" |
| 1287 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Explanation', 'learnpress'), ":"), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1288 |
dangerouslySetInnerHTML: { |
| 1289 |
__html: question.explanation |
| 1290 |
} |
| 1291 |
}))); |
| 1292 |
}, |
| 1293 |
hint: () => { |
| 1294 |
return question.hint && !question.explanation && question.showHint && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1295 |
className: "question-hint-content" |
| 1296 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("strong", { |
| 1297 |
className: "hint-title" |
| 1298 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Hint', 'learnpress'), ":"), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1299 |
dangerouslySetInnerHTML: { |
| 1300 |
__html: question.hint |
| 1301 |
} |
| 1302 |
}))); |
| 1303 |
}, |
| 1304 |
buttons: () => { |
| 1305 |
return 'started' === status && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_buttons__WEBPACK_IMPORTED_MODULE_5__["default"], { |
| 1306 |
question: question |
| 1307 |
}); |
| 1308 |
} |
| 1309 |
}; |
| 1310 |
const configBlocks = LP.config.questionBlocks(); |
| 1311 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1312 |
className: this.getWrapperClass().join(' '), |
| 1313 |
style: { |
| 1314 |
display: isShow ? '' : 'none' |
| 1315 |
}, |
| 1316 |
"data-id": question.id, |
| 1317 |
ref: this.setRef |
| 1318 |
}, configBlocks.map(name => { |
| 1319 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Fragment, { |
| 1320 |
key: `block-${name}` |
| 1321 |
}, blocks[name] ? blocks[name]() : ''); |
| 1322 |
}))); |
| 1323 |
} |
| 1324 |
} |
| 1325 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_3__.compose)([(0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withSelect)((select, { |
| 1326 |
question: { |
| 1327 |
id |
| 1328 |
} |
| 1329 |
}) => { |
| 1330 |
const { |
| 1331 |
getData, |
| 1332 |
getQuestionAnswered, |
| 1333 |
getQuestionMark |
| 1334 |
} = select('learnpress/quiz'); |
| 1335 |
return { |
| 1336 |
status: getData('status'), |
| 1337 |
questions: getData('question'), |
| 1338 |
answered: getQuestionAnswered(id), |
| 1339 |
questionsRendered: getData('questionsRendered'), |
| 1340 |
editPermalink: getData('editPermalink'), |
| 1341 |
numPages: getData('numPages'), |
| 1342 |
mark: getQuestionMark(id) || '', |
| 1343 |
results: getData('results') |
| 1344 |
}; |
| 1345 |
}), (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.withDispatch)(dispatch => { |
| 1346 |
const { |
| 1347 |
updateUserQuestionAnswers, |
| 1348 |
updateUserQuestionFibAnswers, |
| 1349 |
markQuestionRendered |
| 1350 |
} = dispatch('learnpress/quiz'); |
| 1351 |
return { |
| 1352 |
markQuestionRendered, |
| 1353 |
updateUserQuestionAnswers, |
| 1354 |
updateUserQuestionFibAnswers |
| 1355 |
}; |
| 1356 |
})])(Question)); |
| 1357 |
|
| 1358 |
/***/ }, |
| 1359 |
|
| 1360 |
/***/ "./assets/src/apps/js/frontend/quiz/components/result/index.js" |
| 1361 |
/*!*********************************************************************!*\ |
| 1362 |
!*** ./assets/src/apps/js/frontend/quiz/components/result/index.js ***! |
| 1363 |
\*********************************************************************/ |
| 1364 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1365 |
|
| 1366 |
"use strict"; |
| 1367 |
__webpack_require__.r(__webpack_exports__); |
| 1368 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1369 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1370 |
/* harmony export */ }); |
| 1371 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1372 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1373 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 1374 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 1375 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 1376 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 1377 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 1378 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__); |
| 1379 |
/* harmony import */ var _single_curriculum_components_items_progress__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ../../../single-curriculum/components/items-progress */ "./assets/src/apps/js/frontend/single-curriculum/components/items-progress.js"); |
| 1380 |
|
| 1381 |
/** |
| 1382 |
* Quizz Result. |
| 1383 |
* Edit: Use React hook. |
| 1384 |
* |
| 1385 |
* @author Nhamdv - ThimPress |
| 1386 |
*/ |
| 1387 |
|
| 1388 |
|
| 1389 |
|
| 1390 |
|
| 1391 |
const { |
| 1392 |
debounce |
| 1393 |
} = lodash; |
| 1394 |
const Result = () => { |
| 1395 |
const [percentage, setPercentage] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(0); |
| 1396 |
const [done, setDone] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(false); |
| 1397 |
const QuizID = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => { |
| 1398 |
return select('learnpress/quiz').getData('id'); |
| 1399 |
}, []); |
| 1400 |
const results = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => { |
| 1401 |
return select('learnpress/quiz').getData('results'); |
| 1402 |
}, []); |
| 1403 |
const passingGrade = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => { |
| 1404 |
return select('learnpress/quiz').getData('passingGrade'); |
| 1405 |
}, []); |
| 1406 |
const submitting = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.useSelect)(select => { |
| 1407 |
return select('learnpress/quiz').getData('submitting'); |
| 1408 |
}, []); |
| 1409 |
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => { |
| 1410 |
animate(); |
| 1411 |
let graduation = ''; |
| 1412 |
if (results.graduation) { |
| 1413 |
graduation = results.graduation; |
| 1414 |
} else if (results.result >= passingGradeValue) { |
| 1415 |
graduation = 'passed'; |
| 1416 |
} else { |
| 1417 |
graduation = 'failed'; |
| 1418 |
} |
| 1419 |
if (graduation) { |
| 1420 |
const ele = document.querySelector(`.course-curriculum .course-item.course-item-${QuizID}`); |
| 1421 |
if (ele) { |
| 1422 |
ele.classList.remove('failed', 'passed'); |
| 1423 |
ele.classList.add('has-status', 'status-completed', graduation); |
| 1424 |
} |
| 1425 |
} |
| 1426 |
const item = [...document.querySelectorAll('#popup-header .items-progress')][0]; |
| 1427 |
if (item) { |
| 1428 |
const totalItems = item.dataset.totalItems; |
| 1429 |
const itemCompleted = item.querySelector('.items-completed'); |
| 1430 |
const elProgress = item.querySelector('.learn-press-progress__active'); |
| 1431 |
if (itemCompleted) { |
| 1432 |
// const number = parseInt( itemCompleted.textContent ); |
| 1433 |
|
| 1434 |
const allItemCompleted = document.querySelectorAll('#popup-sidebar .course-curriculum .course-item__status .completed'); |
| 1435 |
itemCompleted.textContent = parseInt(allItemCompleted.length); |
| 1436 |
|
| 1437 |
// Set progress |
| 1438 |
const perCent = parseInt(allItemCompleted.length) * 100 / parseInt(totalItems); |
| 1439 |
const percentSet = 100 - perCent; |
| 1440 |
elProgress.style.left = '-' + percentSet + '%'; |
| 1441 |
} |
| 1442 |
} |
| 1443 |
}, [results]); |
| 1444 |
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => { |
| 1445 |
if (submitting !== undefined) { |
| 1446 |
updateItemsProgress(); |
| 1447 |
} |
| 1448 |
}, [submitting]); |
| 1449 |
const updateItemsProgress = () => { |
| 1450 |
const elements = document.querySelectorAll('.popup-header__inner'); |
| 1451 |
if (elements.length > 0 && elements[0].querySelectorAll('form.form-button-finish-course').length === 0) { |
| 1452 |
(0,_single_curriculum_components_items_progress__WEBPACK_IMPORTED_MODULE_4__.getResponse)(elements[0]); |
| 1453 |
} |
| 1454 |
}; |
| 1455 |
const animate = () => { |
| 1456 |
setPercentage(0); |
| 1457 |
setDone(false); |
| 1458 |
jQuery.easing._customEasing = function (e, f, a, h, g) { |
| 1459 |
return h * Math.sqrt(1 - (f = f / g - 1) * f) + a; |
| 1460 |
}; |
| 1461 |
debounce(() => { |
| 1462 |
const $el = jQuery('<span />').css({ |
| 1463 |
width: 1, |
| 1464 |
height: 1 |
| 1465 |
}).appendTo(document.body); |
| 1466 |
$el.css('left', 0).animate({ |
| 1467 |
left: results.result |
| 1468 |
}, { |
| 1469 |
duration: 1500, |
| 1470 |
step: (now, fx) => { |
| 1471 |
setPercentage(now); |
| 1472 |
}, |
| 1473 |
done: () => { |
| 1474 |
setDone(true); |
| 1475 |
$el.remove(); |
| 1476 |
jQuery('#quizResultGrade').css({ |
| 1477 |
transform: 'scale(1.3)', |
| 1478 |
transition: 'all 0.25s' |
| 1479 |
}); |
| 1480 |
debounce(() => { |
| 1481 |
jQuery('#quizResultGrade').css({ |
| 1482 |
transform: 'scale(1)' |
| 1483 |
}); |
| 1484 |
}, 500)(); |
| 1485 |
}, |
| 1486 |
easing: '_customEasing' |
| 1487 |
}); |
| 1488 |
}, results.result > 0 ? 1000 : 10)(); |
| 1489 |
}; |
| 1490 |
|
| 1491 |
/** |
| 1492 |
* Render HTML elements. |
| 1493 |
* |
| 1494 |
*/ |
| 1495 |
|
| 1496 |
let percentResult = percentage; |
| 1497 |
if (!Number.isInteger(percentage)) { |
| 1498 |
percentResult = parseFloat(percentage).toFixed(2); |
| 1499 |
} |
| 1500 |
const border = 10; |
| 1501 |
const width = 200; |
| 1502 |
const radius = width / 2; |
| 1503 |
const r = (width - border) / 2; |
| 1504 |
const circumference = r * 2 * Math.PI; |
| 1505 |
const offset = circumference - percentResult / 100 * circumference; |
| 1506 |
const styles = { |
| 1507 |
strokeDasharray: `${circumference} ${circumference}`, |
| 1508 |
strokeDashoffset: offset |
| 1509 |
}; |
| 1510 |
const passingGradeValue = parseFloat(results.passingGrade || passingGrade); |
| 1511 |
let graduation = ''; |
| 1512 |
if (results.graduation) { |
| 1513 |
graduation = results.graduation; |
| 1514 |
} else if (percentResult >= passingGradeValue) { |
| 1515 |
graduation = 'passed'; |
| 1516 |
} else { |
| 1517 |
graduation = 'failed'; |
| 1518 |
} |
| 1519 |
let message = ''; |
| 1520 |
if (results.graduationText) { |
| 1521 |
message = results.graduationText; |
| 1522 |
} else if (graduation === 'passed') { |
| 1523 |
message = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Passed', 'learnpress'); |
| 1524 |
} else { |
| 1525 |
message = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Failed', 'learnpress'); |
| 1526 |
} |
| 1527 |
const classNames = ['quiz-result', graduation]; |
| 1528 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1529 |
className: classNames.join(' ') |
| 1530 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h3", { |
| 1531 |
className: "result-heading" |
| 1532 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Your Result', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1533 |
id: "quizResultGrade", |
| 1534 |
className: "result-grade" |
| 1535 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("svg", { |
| 1536 |
className: "circle-progress-bar", |
| 1537 |
width: width, |
| 1538 |
height: width |
| 1539 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("circle", { |
| 1540 |
className: "circle-progress-bar__circle", |
| 1541 |
stroke: "", |
| 1542 |
strokeWidth: border, |
| 1543 |
style: styles, |
| 1544 |
fill: "transparent", |
| 1545 |
r: r, |
| 1546 |
cx: radius, |
| 1547 |
cy: radius |
| 1548 |
})), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 1549 |
className: "result-achieved" |
| 1550 |
}, `${percentResult}%`), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", { |
| 1551 |
className: "result-require" |
| 1552 |
}, passingGradeValue + '%' || 0)), done && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", { |
| 1553 |
className: "result-message" |
| 1554 |
}, message), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("ul", { |
| 1555 |
className: "result-statistic" |
| 1556 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1557 |
className: "result-statistic-field result-time-spend" |
| 1558 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Time spent', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.timeSpend)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1559 |
className: "result-statistic-field result-point" |
| 1560 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Points', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.userMark, " / ", results.mark)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1561 |
className: "result-statistic-field result-questions" |
| 1562 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Questions', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.questionCount)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1563 |
className: "result-statistic-field result-questions-correct" |
| 1564 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Correct', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.questionCorrect)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1565 |
className: "result-statistic-field result-questions-wrong" |
| 1566 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Wrong', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.questionWrong)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1567 |
className: "result-statistic-field result-questions-skipped" |
| 1568 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Skipped', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.questionEmpty)), typeof results.minusPoint !== 'undefined' && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("li", { |
| 1569 |
className: "result-statistic-field result-questions-minus" |
| 1570 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Minus points', 'learnpress')), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("p", null, results.minusPoint)))); |
| 1571 |
function timeDifference(earlierDate, laterDate) { |
| 1572 |
const oDiff = new Object(); |
| 1573 |
|
| 1574 |
// Calculate Differences |
| 1575 |
// ------------------------------------------------------------------- // |
| 1576 |
let nTotalDiff = laterDate - earlierDate; |
| 1577 |
oDiff.days = Math.floor(nTotalDiff / 1000 / 60 / 60 / 24); |
| 1578 |
nTotalDiff -= oDiff.days * 1000 * 60 * 60 * 24; |
| 1579 |
oDiff.hours = Math.floor(nTotalDiff / 1000 / 60 / 60); |
| 1580 |
nTotalDiff -= oDiff.hours * 1000 * 60 * 60; |
| 1581 |
oDiff.minutes = Math.floor(nTotalDiff / 1000 / 60); |
| 1582 |
nTotalDiff -= oDiff.minutes * 1000 * 60; |
| 1583 |
oDiff.seconds = Math.floor(nTotalDiff / 1000); |
| 1584 |
// ------------------------------------------------------------------- // |
| 1585 |
|
| 1586 |
// Format Duration |
| 1587 |
// ------------------------------------------------------------------- // |
| 1588 |
// Format Hours |
| 1589 |
let hourtext = '00'; |
| 1590 |
if (oDiff.days > 0) { |
| 1591 |
hourtext = String(oDiff.days); |
| 1592 |
} |
| 1593 |
if (hourtext.length == 1) { |
| 1594 |
hourtext = '0' + hourtext; |
| 1595 |
} |
| 1596 |
|
| 1597 |
// Format Minutes |
| 1598 |
let mintext = '00'; |
| 1599 |
if (oDiff.minutes > 0) { |
| 1600 |
mintext = String(oDiff.minutes); |
| 1601 |
} |
| 1602 |
if (mintext.length == 1) { |
| 1603 |
mintext = '0' + mintext; |
| 1604 |
} |
| 1605 |
|
| 1606 |
// Format Seconds |
| 1607 |
let sectext = '00'; |
| 1608 |
if (oDiff.seconds > 0) { |
| 1609 |
sectext = String(oDiff.seconds); |
| 1610 |
} |
| 1611 |
if (sectext.length == 1) { |
| 1612 |
sectext = '0' + sectext; |
| 1613 |
} |
| 1614 |
// Set Duration |
| 1615 |
const sDuration = hourtext + ':' + mintext + ':' + sectext; |
| 1616 |
oDiff.duration = sDuration; |
| 1617 |
// ------------------------------------------------------------------- // |
| 1618 |
|
| 1619 |
return oDiff; |
| 1620 |
} |
| 1621 |
}; |
| 1622 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Result); |
| 1623 |
|
| 1624 |
/***/ }, |
| 1625 |
|
| 1626 |
/***/ "./assets/src/apps/js/frontend/quiz/components/status/index.js" |
| 1627 |
/*!*********************************************************************!*\ |
| 1628 |
!*** ./assets/src/apps/js/frontend/quiz/components/status/index.js ***! |
| 1629 |
\*********************************************************************/ |
| 1630 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1631 |
|
| 1632 |
"use strict"; |
| 1633 |
__webpack_require__.r(__webpack_exports__); |
| 1634 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1635 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1636 |
/* harmony export */ }); |
| 1637 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1638 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1639 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 1640 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 1641 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 1642 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 1643 |
/* harmony import */ var _timer__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ../timer */ "./assets/src/apps/js/frontend/quiz/components/timer/index.js"); |
| 1644 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! @wordpress/i18n */ "@wordpress/i18n"); |
| 1645 |
/* harmony import */ var _wordpress_i18n__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__); |
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
const $ = jQuery; |
| 1652 |
const { |
| 1653 |
debounce |
| 1654 |
} = lodash; |
| 1655 |
const Status = () => { |
| 1656 |
const { |
| 1657 |
submitQuiz |
| 1658 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.dispatch)('learnpress/quiz'); |
| 1659 |
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => { |
| 1660 |
const $pc = $('#popup-content'); |
| 1661 |
if (!$pc.length) { |
| 1662 |
return; |
| 1663 |
} |
| 1664 |
const $sc = $pc.find('.content-item-scrollable:eq(1)'); |
| 1665 |
const $qs = $pc.find('.quiz-status'); |
| 1666 |
const pcTop = $qs.offset().top - 92; |
| 1667 |
let isFixed = false; |
| 1668 |
|
| 1669 |
/** |
| 1670 |
* Check when status bar is stopped in the top |
| 1671 |
* to add new class into html |
| 1672 |
*/ |
| 1673 |
$sc.on('scroll', () => { |
| 1674 |
if ($sc.scrollTop() >= pcTop) { |
| 1675 |
if (isFixed) { |
| 1676 |
return; |
| 1677 |
} |
| 1678 |
isFixed = true; |
| 1679 |
} else { |
| 1680 |
if (!isFixed) { |
| 1681 |
return; |
| 1682 |
} |
| 1683 |
isFixed = false; |
| 1684 |
} |
| 1685 |
if (isFixed) { |
| 1686 |
$pc.addClass('fixed-quiz-status'); |
| 1687 |
} else { |
| 1688 |
$pc.removeClass('fixed-quiz-status'); |
| 1689 |
} |
| 1690 |
}); |
| 1691 |
}, []); |
| 1692 |
|
| 1693 |
/** |
| 1694 |
* Submit question to record results. |
| 1695 |
*/ |
| 1696 |
const submit = () => { |
| 1697 |
const { |
| 1698 |
confirm |
| 1699 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/modal'); |
| 1700 |
if ('no' === confirm((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Are you sure to submit the quiz?', 'learnpress'), submit)) { |
| 1701 |
return; |
| 1702 |
} |
| 1703 |
submitQuiz(); |
| 1704 |
}; |
| 1705 |
const getMark = () => { |
| 1706 |
const answered = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/quiz').getData('answered'); |
| 1707 |
return Object.values(answered).reduce((m, r) => { |
| 1708 |
return m + r.mark; |
| 1709 |
}, 0); |
| 1710 |
}; |
| 1711 |
const { |
| 1712 |
getData, |
| 1713 |
getUserMark |
| 1714 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/quiz'); |
| 1715 |
const currentPage = getData('currentPage'); |
| 1716 |
const questionsPerPage = getData('questionsPerPage'); |
| 1717 |
const questionsCount = getData('numberQuestionsToDo'); |
| 1718 |
const submitting = getData('submitting'); |
| 1719 |
const duration = getData('duration'); |
| 1720 |
const userMark = getUserMark(); |
| 1721 |
const classNames = ['quiz-status']; |
| 1722 |
const start = (currentPage - 1) * questionsPerPage + 1; |
| 1723 |
let end = start + questionsPerPage - 1; |
| 1724 |
let indexHtml = ''; |
| 1725 |
end = Math.min(end, questionsCount); |
| 1726 |
if (submitting) { |
| 1727 |
classNames.push('submitting'); |
| 1728 |
} |
| 1729 |
if (end < questionsCount) { |
| 1730 |
if (questionsPerPage > 1) { |
| 1731 |
indexHtml = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Question <span>%d to %d of %d</span>', 'learnpress'), start, end, questionsCount); |
| 1732 |
} else { |
| 1733 |
indexHtml = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Question <span>%d of %d</span>', 'learnpress'), start, questionsCount); |
| 1734 |
} |
| 1735 |
} else { |
| 1736 |
indexHtml = (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Question <span>%d of %d</span>', 'learnpress'), start, end); |
| 1737 |
} |
| 1738 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1739 |
className: classNames.join(' ') |
| 1740 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1741 |
className: "questions-index", |
| 1742 |
dangerouslySetInnerHTML: { |
| 1743 |
__html: indexHtml |
| 1744 |
} |
| 1745 |
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1746 |
className: "current-point" |
| 1747 |
}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.sprintf)((0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Earned Point: %s', 'learnpress'), userMark)), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1748 |
className: "submit-quiz" |
| 1749 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("button", { |
| 1750 |
className: "lp-button", |
| 1751 |
id: "button-submit-quiz", |
| 1752 |
onClick: submit |
| 1753 |
}, !submitting ? (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Finish Quiz', 'learnpress') : (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_4__.__)('Submitting…', 'learnpress'))), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_timer__WEBPACK_IMPORTED_MODULE_3__["default"], null)))); |
| 1754 |
}; |
| 1755 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Status); |
| 1756 |
|
| 1757 |
/***/ }, |
| 1758 |
|
| 1759 |
/***/ "./assets/src/apps/js/frontend/quiz/components/timer/index.js" |
| 1760 |
/*!********************************************************************!*\ |
| 1761 |
!*** ./assets/src/apps/js/frontend/quiz/components/timer/index.js ***! |
| 1762 |
\********************************************************************/ |
| 1763 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1764 |
|
| 1765 |
"use strict"; |
| 1766 |
__webpack_require__.r(__webpack_exports__); |
| 1767 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1768 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1769 |
/* harmony export */ }); |
| 1770 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1771 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1772 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 1773 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 1774 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 1775 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_2__); |
| 1776 |
|
| 1777 |
/** |
| 1778 |
* Edit: React hook. |
| 1779 |
* |
| 1780 |
* @author Nhamdv - ThimPress |
| 1781 |
*/ |
| 1782 |
|
| 1783 |
|
| 1784 |
const Timer = () => { |
| 1785 |
const { |
| 1786 |
getData |
| 1787 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.select)('learnpress/quiz'); |
| 1788 |
const { |
| 1789 |
submitQuiz |
| 1790 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_2__.dispatch)('learnpress/quiz'); |
| 1791 |
let totalTime = getData('totalTime'); |
| 1792 |
const durationTime = getData('duration'); |
| 1793 |
const timeSpendG = getData('timeSpend'); |
| 1794 |
const [seconds, setSeconds] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(totalTime); |
| 1795 |
let [timeSpend, setTimeSpend] = (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useState)(timeSpendG); |
| 1796 |
(0,_wordpress_element__WEBPACK_IMPORTED_MODULE_1__.useEffect)(() => { |
| 1797 |
const myInterval = setInterval(() => { |
| 1798 |
if (durationTime > 0) { |
| 1799 |
let remainSeconds = seconds; |
| 1800 |
remainSeconds -= 1; |
| 1801 |
remainSeconds = wp.hooks.applyFilters('js-lp-quiz-remaining_time', remainSeconds, durationTime); |
| 1802 |
if (remainSeconds > 0) { |
| 1803 |
setSeconds(remainSeconds); |
| 1804 |
timeSpend++; |
| 1805 |
setTimeSpend(durationTime - remainSeconds); |
| 1806 |
} else { |
| 1807 |
clearInterval(myInterval); |
| 1808 |
submitQuiz(); |
| 1809 |
} |
| 1810 |
} else { |
| 1811 |
// Apply when set duration = 0 |
| 1812 |
timeSpend++; |
| 1813 |
setTimeSpend(timeSpend); |
| 1814 |
setSeconds(timeSpend); |
| 1815 |
} |
| 1816 |
}, 1000); |
| 1817 |
return () => clearInterval(myInterval); |
| 1818 |
}, [seconds, timeSpend]); |
| 1819 |
const formatTime = (separator = ':') => { |
| 1820 |
const t = []; |
| 1821 |
let m; |
| 1822 |
if (timeSpendG) { |
| 1823 |
totalTime = timeSpendG; |
| 1824 |
} |
| 1825 |
if (totalTime < 3600) { |
| 1826 |
t.push((seconds - seconds % 60) / 60); |
| 1827 |
t.push(seconds % 60); |
| 1828 |
} else if (totalTime) { |
| 1829 |
t.push((seconds - seconds % 3600) / 3600); |
| 1830 |
m = seconds % 3600; |
| 1831 |
t.push((m - m % 60) / 60); |
| 1832 |
t.push(m % 60); |
| 1833 |
} |
| 1834 |
return t.map(a => { |
| 1835 |
return a < 10 ? `0${a}` : a; |
| 1836 |
}).join(separator); |
| 1837 |
}; |
| 1838 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", { |
| 1839 |
className: "countdown" |
| 1840 |
}, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("i", { |
| 1841 |
className: "lp-icon-stopwatch" |
| 1842 |
}), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("span", null, formatTime()), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("input", { |
| 1843 |
type: "hidden", |
| 1844 |
name: "lp-quiz-time-spend", |
| 1845 |
value: timeSpend |
| 1846 |
})); |
| 1847 |
}; |
| 1848 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Timer); |
| 1849 |
|
| 1850 |
/***/ }, |
| 1851 |
|
| 1852 |
/***/ "./assets/src/apps/js/frontend/quiz/components/title/index.js" |
| 1853 |
/*!********************************************************************!*\ |
| 1854 |
!*** ./assets/src/apps/js/frontend/quiz/components/title/index.js ***! |
| 1855 |
\********************************************************************/ |
| 1856 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1857 |
|
| 1858 |
"use strict"; |
| 1859 |
__webpack_require__.r(__webpack_exports__); |
| 1860 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1861 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1862 |
/* harmony export */ }); |
| 1863 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1864 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1865 |
|
| 1866 |
const Title = () => { |
| 1867 |
return (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("h3", null, "The title"); |
| 1868 |
}; |
| 1869 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Title); |
| 1870 |
|
| 1871 |
/***/ }, |
| 1872 |
|
| 1873 |
/***/ "./assets/src/apps/js/frontend/quiz/index.js" |
| 1874 |
/*!***************************************************!*\ |
| 1875 |
!*** ./assets/src/apps/js/frontend/quiz/index.js ***! |
| 1876 |
\***************************************************/ |
| 1877 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1878 |
|
| 1879 |
"use strict"; |
| 1880 |
__webpack_require__.r(__webpack_exports__); |
| 1881 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1882 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 1883 |
/* harmony export */ }); |
| 1884 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 1885 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 1886 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/element */ "@wordpress/element"); |
| 1887 |
/* harmony import */ var _wordpress_element__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_element__WEBPACK_IMPORTED_MODULE_1__); |
| 1888 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! @wordpress/compose */ "@wordpress/compose"); |
| 1889 |
/* harmony import */ var _wordpress_compose__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__); |
| 1890 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 1891 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_3__); |
| 1892 |
/* harmony import */ var _components__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./components */ "./assets/src/apps/js/frontend/quiz/components/index.js"); |
| 1893 |
/* harmony import */ var _store__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(/*! ./store */ "./assets/src/apps/js/frontend/quiz/store/index.js"); |
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
const { |
| 1901 |
chunk |
| 1902 |
} = lodash; |
| 1903 |
class Quiz extends _wordpress_element__WEBPACK_IMPORTED_MODULE_1__.Component { |
| 1904 |
constructor(props) { |
| 1905 |
super(...arguments); |
| 1906 |
this.state = { |
| 1907 |
currentPage: 1, |
| 1908 |
numPages: 0, |
| 1909 |
pages: [] |
| 1910 |
}; |
| 1911 |
} |
| 1912 |
componentDidMount() { |
| 1913 |
const { |
| 1914 |
settings, |
| 1915 |
setQuizData |
| 1916 |
} = this.props; |
| 1917 |
const { |
| 1918 |
question_ids, |
| 1919 |
questions_per_page |
| 1920 |
} = settings; |
| 1921 |
const chunks = chunk(question_ids, questions_per_page); |
| 1922 |
settings.currentPage = 1; |
| 1923 |
settings.numPages = chunks.length; |
| 1924 |
settings.pages = chunks; |
| 1925 |
const answered = settings.id ? localStorage.getItem(`LP_Quiz_${settings.id}_Answered`) : false; |
| 1926 |
if (answered) { |
| 1927 |
settings.answered = JSON.parse(answered); |
| 1928 |
} |
| 1929 |
setQuizData(settings); |
| 1930 |
} |
| 1931 |
componentDidUpdate(prevProps, prevState, snapshot) { |
| 1932 |
const { |
| 1933 |
status |
| 1934 |
} = prevProps; |
| 1935 |
const elQuizContent = document.querySelector('.quiz-content'); |
| 1936 |
if (status !== undefined && elQuizContent) { |
| 1937 |
elQuizContent.style.display = 'none'; |
| 1938 |
} |
| 1939 |
} |
| 1940 |
startQuiz = event => { |
| 1941 |
this.props.startQuiz(); |
| 1942 |
}; |
| 1943 |
render() { |
| 1944 |
const { |
| 1945 |
status, |
| 1946 |
isReviewing, |
| 1947 |
answered |
| 1948 |
} = this.props; |
| 1949 |
wp.hooks.doAction('lp-js-quiz-answer', answered, status); |
| 1950 |
const isA = -1 !== ['', 'completed', 'viewed'].indexOf(status) || !status; |
| 1951 |
const notStarted = -1 !== ['', 'viewed', undefined].indexOf(status) || !status; |
| 1952 |
|
| 1953 |
// Just render content if status !== undefined (meant all data loaded) |
| 1954 |
return undefined !== status && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(react__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)("div", null, !isReviewing && 'completed' === status && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Result, null), !isReviewing && notStarted && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Meta, null), 'started' === status && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Status, null), (-1 !== ['completed', 'started'].indexOf(status) || isReviewing) && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Questions, null), (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Buttons, null), isA && !isReviewing && (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_components__WEBPACK_IMPORTED_MODULE_4__.Attempts, null))); |
| 1955 |
} |
| 1956 |
} |
| 1957 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_compose__WEBPACK_IMPORTED_MODULE_2__.compose)([(0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.withSelect)(select => { |
| 1958 |
const { |
| 1959 |
getQuestions, |
| 1960 |
getData |
| 1961 |
} = select('learnpress/quiz'); |
| 1962 |
return { |
| 1963 |
questions: getQuestions(), |
| 1964 |
status: getData('status'), |
| 1965 |
store: getData(), |
| 1966 |
answered: getData('answered'), |
| 1967 |
isReviewing: getData('mode') === 'reviewing', |
| 1968 |
questionIds: getData('questionIds'), |
| 1969 |
checkCount: getData('instantCheck'), |
| 1970 |
questionsPerPage: getData('questionsPerPage') || 1 |
| 1971 |
}; |
| 1972 |
}), (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_3__.withDispatch)(dispatch => { |
| 1973 |
const { |
| 1974 |
setQuizData, |
| 1975 |
startQuiz |
| 1976 |
} = dispatch('learnpress/quiz'); |
| 1977 |
return { |
| 1978 |
setQuizData, |
| 1979 |
startQuiz |
| 1980 |
}; |
| 1981 |
})])(Quiz)); |
| 1982 |
|
| 1983 |
/***/ }, |
| 1984 |
|
| 1985 |
/***/ "./assets/src/apps/js/frontend/quiz/store/actions.js" |
| 1986 |
/*!***********************************************************!*\ |
| 1987 |
!*** ./assets/src/apps/js/frontend/quiz/store/actions.js ***! |
| 1988 |
\***********************************************************/ |
| 1989 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 1990 |
|
| 1991 |
"use strict"; |
| 1992 |
__webpack_require__.r(__webpack_exports__); |
| 1993 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 1994 |
/* harmony export */ __requestBeforeStartQuiz: () => (/* binding */ __requestBeforeStartQuiz), |
| 1995 |
/* harmony export */ __requestCheckAnswerSuccess: () => (/* binding */ __requestCheckAnswerSuccess), |
| 1996 |
/* harmony export */ __requestShowHintSuccess: () => (/* binding */ __requestShowHintSuccess), |
| 1997 |
/* harmony export */ __requestStartQuizSuccess: () => (/* binding */ __requestStartQuizSuccess), |
| 1998 |
/* harmony export */ __requestSubmitQuiz: () => (/* binding */ __requestSubmitQuiz), |
| 1999 |
/* harmony export */ __requestSubmitQuizSuccess: () => (/* binding */ __requestSubmitQuizSuccess), |
| 2000 |
/* harmony export */ checkAnswer: () => (/* binding */ checkAnswer), |
| 2001 |
/* harmony export */ markQuestionRendered: () => (/* binding */ markQuestionRendered), |
| 2002 |
/* harmony export */ sendKey: () => (/* binding */ sendKey), |
| 2003 |
/* harmony export */ setCurrentPage: () => (/* binding */ setCurrentPage), |
| 2004 |
/* harmony export */ setCurrentQuestion: () => (/* binding */ setCurrentQuestion), |
| 2005 |
/* harmony export */ setQuizData: () => (/* binding */ setQuizData), |
| 2006 |
/* harmony export */ setQuizMode: () => (/* binding */ setQuizMode), |
| 2007 |
/* harmony export */ showHint: () => (/* binding */ showHint), |
| 2008 |
/* harmony export */ startQuiz: () => (/* binding */ startQuiz), |
| 2009 |
/* harmony export */ submitQuiz: () => (/* binding */ submitQuiz), |
| 2010 |
/* harmony export */ updateUserQuestionAnswers: () => (/* binding */ updateUserQuestionAnswers), |
| 2011 |
/* harmony export */ updateUserQuestionFibAnswers: () => (/* binding */ updateUserQuestionFibAnswers) |
| 2012 |
/* harmony export */ }); |
| 2013 |
/* harmony import */ var _learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @learnpress/data-controls */ "@learnpress/data-controls"); |
| 2014 |
/* harmony import */ var _learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0__); |
| 2015 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 2016 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_1__); |
| 2017 |
|
| 2018 |
|
| 2019 |
function _dispatch() { |
| 2020 |
const args = [].slice.call(arguments, 2); |
| 2021 |
const d = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.dispatch)(arguments[0]); |
| 2022 |
const f = arguments[1]; |
| 2023 |
d[f](...args); |
| 2024 |
} |
| 2025 |
const { |
| 2026 |
camelCaseDashObjectKeys, |
| 2027 |
Hook |
| 2028 |
} = LP; |
| 2029 |
/** |
| 2030 |
* Set user data for app. |
| 2031 |
* |
| 2032 |
* @param key |
| 2033 |
* @param data |
| 2034 |
*/ |
| 2035 |
function setQuizData(key, data) { |
| 2036 |
if (typeof key === 'string') { |
| 2037 |
data = { |
| 2038 |
[key]: data |
| 2039 |
}; |
| 2040 |
} else { |
| 2041 |
data = key; |
| 2042 |
} |
| 2043 |
return { |
| 2044 |
type: 'SET_QUIZ_DATA', |
| 2045 |
data: camelCaseDashObjectKeys(data) |
| 2046 |
}; |
| 2047 |
} |
| 2048 |
|
| 2049 |
/** |
| 2050 |
* Set question will display. |
| 2051 |
* |
| 2052 |
* @param questionId |
| 2053 |
*/ |
| 2054 |
function setCurrentQuestion(questionId) { |
| 2055 |
return { |
| 2056 |
type: 'SET_CURRENT_QUESTION', |
| 2057 |
questionId |
| 2058 |
}; |
| 2059 |
} |
| 2060 |
function setCurrentPage(currentPage) { |
| 2061 |
return { |
| 2062 |
type: 'SET_CURRENT_PAGE', |
| 2063 |
currentPage |
| 2064 |
}; |
| 2065 |
} |
| 2066 |
function __requestBeforeStartQuiz(quizId, courseId, userId) { |
| 2067 |
return { |
| 2068 |
type: 'BEFORE_START_QUIZ' |
| 2069 |
}; |
| 2070 |
} |
| 2071 |
function __requestStartQuizSuccess(results, quizId, courseId, userId) { |
| 2072 |
Hook.doAction('quiz-started', results, quizId, courseId, userId); |
| 2073 |
return { |
| 2074 |
type: 'START_QUIZ_SUCCESS', |
| 2075 |
quizId, |
| 2076 |
courseId, |
| 2077 |
userId, |
| 2078 |
results |
| 2079 |
}; |
| 2080 |
} |
| 2081 |
|
| 2082 |
/** |
| 2083 |
* Request to api for starting a quiz. |
| 2084 |
*/ |
| 2085 |
const startQuiz = function* () { |
| 2086 |
const { |
| 2087 |
itemId, |
| 2088 |
courseId |
| 2089 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz').getDefaultRestArgs(); |
| 2090 |
const doStart = Hook.applyFilters('before-start-quiz', true, itemId, courseId); |
| 2091 |
if (true !== doStart) { |
| 2092 |
return; |
| 2093 |
} |
| 2094 |
let response = yield (0,_learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0__.apiFetch)({ |
| 2095 |
path: 'lp/v1/users/start-quiz', |
| 2096 |
method: 'POST', |
| 2097 |
data: { |
| 2098 |
item_id: itemId, |
| 2099 |
course_id: courseId |
| 2100 |
} |
| 2101 |
}); |
| 2102 |
const btnStart = document.querySelector('.lp-button.start'); |
| 2103 |
if (response.status !== 'error') { |
| 2104 |
response = Hook.applyFilters('request-start-quiz-response', response, itemId, courseId); |
| 2105 |
const { |
| 2106 |
results |
| 2107 |
} = response; |
| 2108 |
const { |
| 2109 |
duration, |
| 2110 |
status, |
| 2111 |
question_ids, |
| 2112 |
questions |
| 2113 |
} = results; |
| 2114 |
|
| 2115 |
// No require enroll |
| 2116 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 2117 |
const keyQuizOff = 'quiz_off_' + lpQuizSettings.id; |
| 2118 |
window.localStorage.removeItem(keyQuizOff); |
| 2119 |
const quizDataOff = { |
| 2120 |
endTime: Date.now() + duration * 1000, |
| 2121 |
status, |
| 2122 |
question_ids, |
| 2123 |
questions |
| 2124 |
}; |
| 2125 |
window.localStorage.setItem(keyQuizOff, JSON.stringify(quizDataOff)); |
| 2126 |
|
| 2127 |
// Set Retake quiz |
| 2128 |
const keyQuizOffRetaken = 'quiz_off_retaken_' + lpQuizSettings.id; |
| 2129 |
let quizOffRetaken = window.localStorage.getItem(keyQuizOffRetaken); |
| 2130 |
if (null === quizOffRetaken) { |
| 2131 |
quizOffRetaken = 0; |
| 2132 |
} else { |
| 2133 |
quizOffRetaken++; |
| 2134 |
} |
| 2135 |
window.localStorage.setItem(keyQuizOffRetaken, quizOffRetaken); |
| 2136 |
// End |
| 2137 |
} |
| 2138 |
|
| 2139 |
// Reload when start/retake quiz |
| 2140 |
window.localStorage.removeItem('LP'); |
| 2141 |
window.location.href = response.redirect_url; |
| 2142 |
//window.location.reload(); |
| 2143 |
|
| 2144 |
//yield _dispatch( 'learnpress/quiz', '__requestStartQuizSuccess', camelCaseDashObjectKeys( response ), itemId, courseId ); |
| 2145 |
} else { |
| 2146 |
const elButtons = document.querySelector('.quiz-buttons'); |
| 2147 |
const message = `<div class="learn-press-message error">${response.message}</div>`; |
| 2148 |
elButtons.insertAdjacentHTML('afterend', message); |
| 2149 |
btnStart.classList.remove('loading'); |
| 2150 |
} |
| 2151 |
}; |
| 2152 |
|
| 2153 |
function __requestSubmitQuiz() { |
| 2154 |
return { |
| 2155 |
type: 'SUBMIT_QUIZ' |
| 2156 |
}; |
| 2157 |
} |
| 2158 |
function __requestSubmitQuizSuccess(results, quizId, courseId) { |
| 2159 |
Hook.doAction('quiz-submitted', results, quizId, courseId); |
| 2160 |
return { |
| 2161 |
type: 'SUBMIT_QUIZ_SUCCESS', |
| 2162 |
results |
| 2163 |
}; |
| 2164 |
} |
| 2165 |
function* submitQuiz() { |
| 2166 |
const { |
| 2167 |
getDefaultRestArgs, |
| 2168 |
getQuestionsSelectedAnswers |
| 2169 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz'); |
| 2170 |
const { |
| 2171 |
itemId, |
| 2172 |
courseId |
| 2173 |
} = getDefaultRestArgs(); |
| 2174 |
const doSubmit = Hook.applyFilters('before-submit-quiz', true); |
| 2175 |
if (true !== doSubmit) { |
| 2176 |
return; |
| 2177 |
} |
| 2178 |
const answered = getQuestionsSelectedAnswers(); |
| 2179 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 2180 |
const keyQuizOff = `quiz_off_${lpQuizSettings.id}`; |
| 2181 |
const quizDataOffStr = window.localStorage.getItem(keyQuizOff); |
| 2182 |
const quizDataOff = JSON.parse(quizDataOffStr); |
| 2183 |
const keyAnswer = `LP_Quiz_${itemId}_Answered`; |
| 2184 |
const answerDataStr = localStorage.getItem(keyAnswer); |
| 2185 |
if (null !== answerDataStr) { |
| 2186 |
const data = JSON.parse(answerDataStr); |
| 2187 |
for (const [k, v] of Object.entries(data)) { |
| 2188 |
answered[k] = v.answered; |
| 2189 |
} |
| 2190 |
} |
| 2191 |
|
| 2192 |
// Added questions not answered |
| 2193 |
quizDataOff.question_ids.forEach(question_id => { |
| 2194 |
if (!answered[question_id]) { |
| 2195 |
answered[question_id] = ''; |
| 2196 |
} |
| 2197 |
}); |
| 2198 |
} |
| 2199 |
|
| 2200 |
// Get time spend did quiz - tungnx |
| 2201 |
let timeSpend = 0; |
| 2202 |
const elTimeSpend = document.querySelector('input[name=lp-quiz-time-spend]'); |
| 2203 |
if (elTimeSpend) { |
| 2204 |
timeSpend = elTimeSpend.value; |
| 2205 |
} |
| 2206 |
// End |
| 2207 |
|
| 2208 |
let response = yield (0,_learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0__.apiFetch)({ |
| 2209 |
path: 'lp/v1/users/submit-quiz', |
| 2210 |
method: 'POST', |
| 2211 |
data: { |
| 2212 |
item_id: itemId, |
| 2213 |
course_id: courseId, |
| 2214 |
answered, |
| 2215 |
time_spend: timeSpend |
| 2216 |
} |
| 2217 |
}); |
| 2218 |
response = Hook.applyFilters('request-submit-quiz-response', response, itemId, courseId); |
| 2219 |
if (response.status === 'success') { |
| 2220 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 2221 |
const keyQuizOff = 'quiz_off_' + lpQuizSettings.id; |
| 2222 |
const quizDataOffStr = window.localStorage.getItem(keyQuizOff); |
| 2223 |
if (null !== quizDataOffStr) { |
| 2224 |
const quizDataOff = JSON.parse(quizDataOffStr); |
| 2225 |
quizDataOff.status = response.results.status; |
| 2226 |
quizDataOff.results = response.results.results; |
| 2227 |
window.localStorage.setItem(keyQuizOff, JSON.stringify(quizDataOff)); |
| 2228 |
window.localStorage.removeItem('LP_Quiz_' + lpQuizSettings.id + '_Answered'); |
| 2229 |
} |
| 2230 |
} |
| 2231 |
yield _dispatch('learnpress/quiz', '__requestSubmitQuizSuccess', camelCaseDashObjectKeys(response.results), itemId, courseId); |
| 2232 |
} |
| 2233 |
} |
| 2234 |
function updateUserQuestionAnswers(questionId, answers, quizId, courseId = 0, userId = 0) { |
| 2235 |
return { |
| 2236 |
type: 'UPDATE_USER_QUESTION_ANSWERS', |
| 2237 |
questionId, |
| 2238 |
answers |
| 2239 |
}; |
| 2240 |
} |
| 2241 |
|
| 2242 |
/** |
| 2243 |
* Handle when user change value on input fill in blanks. |
| 2244 |
* |
| 2245 |
* @param questionId |
| 2246 |
* @param idInput |
| 2247 |
* @param valueInput |
| 2248 |
* @param quizId |
| 2249 |
* @param courseId |
| 2250 |
* @param userId |
| 2251 |
* @since 4.2.5.9 |
| 2252 |
* @version 1.0.0 |
| 2253 |
*/ |
| 2254 |
function updateUserQuestionFibAnswers(questionId, idInput, valueInput, quizId, courseId = 0, userId = 0) { |
| 2255 |
return { |
| 2256 |
type: 'UPDATE_USER_QUESTION_FIB_ANSWERS', |
| 2257 |
questionId, |
| 2258 |
idInput, |
| 2259 |
valueInput |
| 2260 |
}; |
| 2261 |
} |
| 2262 |
function __requestShowHintSuccess(id, showHint) { |
| 2263 |
return { |
| 2264 |
type: 'SET_QUESTION_HINT', |
| 2265 |
questionId: id, |
| 2266 |
showHint |
| 2267 |
}; |
| 2268 |
} |
| 2269 |
function* showHint(id, showHint) { |
| 2270 |
yield _dispatch('learnpress/quiz', '__requestShowHintSuccess', id, showHint); |
| 2271 |
} |
| 2272 |
function __requestCheckAnswerSuccess(id, result) { |
| 2273 |
return { |
| 2274 |
type: 'CHECK_ANSWER', |
| 2275 |
questionId: id, |
| 2276 |
...result |
| 2277 |
}; |
| 2278 |
} |
| 2279 |
function* checkAnswer(id) { |
| 2280 |
const { |
| 2281 |
getDefaultRestArgs, |
| 2282 |
getQuestionAnswered |
| 2283 |
} = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_1__.select)('learnpress/quiz'); |
| 2284 |
const { |
| 2285 |
itemId, |
| 2286 |
courseId |
| 2287 |
} = getDefaultRestArgs(); |
| 2288 |
const result = yield (0,_learnpress_data_controls__WEBPACK_IMPORTED_MODULE_0__.apiFetch)({ |
| 2289 |
path: 'lp/v1/users/check-answer', |
| 2290 |
method: 'POST', |
| 2291 |
data: { |
| 2292 |
item_id: itemId, |
| 2293 |
course_id: courseId, |
| 2294 |
question_id: id, |
| 2295 |
answered: getQuestionAnswered(id) || '' |
| 2296 |
} |
| 2297 |
}); |
| 2298 |
if (result.status === 'success') { |
| 2299 |
// No require enroll |
| 2300 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 2301 |
const keyQuizOff = 'quiz_off_' + lpQuizSettings.id; |
| 2302 |
const quizDataOffStr = window.localStorage.getItem(keyQuizOff); |
| 2303 |
if (null !== quizDataOffStr) { |
| 2304 |
const quizDataOff = JSON.parse(quizDataOffStr); |
| 2305 |
const questionOptions = result.options; |
| 2306 |
if (undefined === quizDataOff.checked_questions) { |
| 2307 |
quizDataOff.checked_questions = []; |
| 2308 |
quizDataOff.checked_questions.push(id); |
| 2309 |
} else if (-1 === quizDataOff.checked_questions.indexOf(id)) { |
| 2310 |
quizDataOff.checked_questions.push(id); |
| 2311 |
} |
| 2312 |
if (undefined === quizDataOff.question_options) { |
| 2313 |
quizDataOff.question_options = {}; |
| 2314 |
quizDataOff.question_options[id] = questionOptions; |
| 2315 |
} else if (undefined === quizDataOff.question_options[id]) { |
| 2316 |
quizDataOff.question_options[id] = questionOptions; |
| 2317 |
} |
| 2318 |
window.localStorage.setItem(keyQuizOff, JSON.stringify(quizDataOff)); |
| 2319 |
|
| 2320 |
//console.log( quizDataOff ); |
| 2321 |
} |
| 2322 |
} |
| 2323 |
yield _dispatch('learnpress/quiz', '__requestCheckAnswerSuccess', id, camelCaseDashObjectKeys(result)); |
| 2324 |
} |
| 2325 |
} |
| 2326 |
function markQuestionRendered(questionId) { |
| 2327 |
return { |
| 2328 |
type: 'MARK_QUESTION_RENDERED', |
| 2329 |
questionId |
| 2330 |
}; |
| 2331 |
} |
| 2332 |
function setQuizMode(mode) { |
| 2333 |
return { |
| 2334 |
type: 'SET_QUIZ_MODE', |
| 2335 |
mode |
| 2336 |
}; |
| 2337 |
} |
| 2338 |
function sendKey(keyPressed) { |
| 2339 |
setTimeout(() => { |
| 2340 |
_dispatch('learnpress/quiz', 'sendKey', ''); |
| 2341 |
}, 300); |
| 2342 |
return { |
| 2343 |
type: 'SEND_KEY', |
| 2344 |
keyPressed |
| 2345 |
}; |
| 2346 |
} |
| 2347 |
|
| 2348 |
/***/ }, |
| 2349 |
|
| 2350 |
/***/ "./assets/src/apps/js/frontend/quiz/store/index.js" |
| 2351 |
/*!*********************************************************!*\ |
| 2352 |
!*** ./assets/src/apps/js/frontend/quiz/store/index.js ***! |
| 2353 |
\*********************************************************/ |
| 2354 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 2355 |
|
| 2356 |
"use strict"; |
| 2357 |
__webpack_require__.r(__webpack_exports__); |
| 2358 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2359 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 2360 |
/* harmony export */ }); |
| 2361 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 2362 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); |
| 2363 |
/* harmony import */ var _reducer__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./reducer */ "./assets/src/apps/js/frontend/quiz/store/reducer.js"); |
| 2364 |
/* harmony import */ var _actions__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./actions */ "./assets/src/apps/js/frontend/quiz/store/actions.js"); |
| 2365 |
/* harmony import */ var _selectors__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./selectors */ "./assets/src/apps/js/frontend/quiz/store/selectors.js"); |
| 2366 |
/* harmony import */ var _middlewares__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(/*! ./middlewares */ "./assets/src/apps/js/frontend/quiz/store/middlewares.js"); |
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
const { |
| 2373 |
controls: dataControls |
| 2374 |
} = LP.dataControls; |
| 2375 |
const store = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.registerStore)('learnpress/quiz', { |
| 2376 |
reducer: _reducer__WEBPACK_IMPORTED_MODULE_1__["default"], |
| 2377 |
selectors: _selectors__WEBPACK_IMPORTED_MODULE_3__, |
| 2378 |
actions: _actions__WEBPACK_IMPORTED_MODULE_2__, |
| 2379 |
controls: { |
| 2380 |
...dataControls |
| 2381 |
} |
| 2382 |
}); |
| 2383 |
(0,_middlewares__WEBPACK_IMPORTED_MODULE_4__["default"])(store); |
| 2384 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (store); |
| 2385 |
|
| 2386 |
/***/ }, |
| 2387 |
|
| 2388 |
/***/ "./assets/src/apps/js/frontend/quiz/store/middlewares.js" |
| 2389 |
/*!***************************************************************!*\ |
| 2390 |
!*** ./assets/src/apps/js/frontend/quiz/store/middlewares.js ***! |
| 2391 |
\***************************************************************/ |
| 2392 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 2393 |
|
| 2394 |
"use strict"; |
| 2395 |
__webpack_require__.r(__webpack_exports__); |
| 2396 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2397 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 2398 |
/* harmony export */ }); |
| 2399 |
/* harmony import */ var refx__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! refx */ "./node_modules/refx/refx.js"); |
| 2400 |
/* harmony import */ var refx__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(refx__WEBPACK_IMPORTED_MODULE_0__); |
| 2401 |
/** |
| 2402 |
* External dependencies |
| 2403 |
*/ |
| 2404 |
|
| 2405 |
|
| 2406 |
/** |
| 2407 |
* Internal dependencies |
| 2408 |
*/ |
| 2409 |
//import effects from './effects'; |
| 2410 |
|
| 2411 |
const effects = { |
| 2412 |
ENROLL_COURSE_X: (action, store) => { |
| 2413 |
enrollCourse: (action, store) => { |
| 2414 |
const { |
| 2415 |
dispatch |
| 2416 |
} = store; |
| 2417 |
|
| 2418 |
//dispatch() |
| 2419 |
}; |
| 2420 |
} |
| 2421 |
}; |
| 2422 |
|
| 2423 |
/** |
| 2424 |
* Applies the custom middlewares used specifically in the editor module. |
| 2425 |
* |
| 2426 |
* @param {Object} store Store Object. |
| 2427 |
* |
| 2428 |
* @return {Object} Update Store Object. |
| 2429 |
*/ |
| 2430 |
function applyMiddlewares(store) { |
| 2431 |
let enhancedDispatch = () => { |
| 2432 |
throw new Error('Dispatching while constructing your middleware is not allowed. ' + 'Other middleware would not be applied to this dispatch.'); |
| 2433 |
}; |
| 2434 |
const middlewareAPI = { |
| 2435 |
getState: store.getState, |
| 2436 |
dispatch: (...args) => enhancedDispatch(...args) |
| 2437 |
}; |
| 2438 |
enhancedDispatch = refx__WEBPACK_IMPORTED_MODULE_0___default()(effects)(middlewareAPI)(store.dispatch); |
| 2439 |
store.dispatch = enhancedDispatch; |
| 2440 |
return store; |
| 2441 |
} |
| 2442 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (applyMiddlewares); |
| 2443 |
|
| 2444 |
/***/ }, |
| 2445 |
|
| 2446 |
/***/ "./assets/src/apps/js/frontend/quiz/store/reducer.js" |
| 2447 |
/*!***********************************************************!*\ |
| 2448 |
!*** ./assets/src/apps/js/frontend/quiz/store/reducer.js ***! |
| 2449 |
\***********************************************************/ |
| 2450 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 2451 |
|
| 2452 |
"use strict"; |
| 2453 |
__webpack_require__.r(__webpack_exports__); |
| 2454 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2455 |
/* harmony export */ blocks: () => (/* binding */ blocks), |
| 2456 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__), |
| 2457 |
/* harmony export */ setItemStatus: () => (/* binding */ setItemStatus), |
| 2458 |
/* harmony export */ userQuiz: () => (/* binding */ userQuiz) |
| 2459 |
/* harmony export */ }); |
| 2460 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 2461 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); |
| 2462 |
|
| 2463 |
const { |
| 2464 |
omit, |
| 2465 |
flow, |
| 2466 |
isArray, |
| 2467 |
chunk |
| 2468 |
} = lodash; |
| 2469 |
const { |
| 2470 |
camelCaseDashObjectKeys |
| 2471 |
} = LP; |
| 2472 |
const { |
| 2473 |
get: storageGet, |
| 2474 |
set: storageSet |
| 2475 |
} = LP.localStorage; |
| 2476 |
const STORE_DATA = {}; |
| 2477 |
const setItemStatus = (item, status) => { |
| 2478 |
const userSettings = { |
| 2479 |
...item.userSettings, |
| 2480 |
status |
| 2481 |
}; |
| 2482 |
return { |
| 2483 |
...item, |
| 2484 |
userSettings |
| 2485 |
}; |
| 2486 |
}; |
| 2487 |
const updateUserQuestionAnswer = (state, action) => { |
| 2488 |
const { |
| 2489 |
answered, |
| 2490 |
id |
| 2491 |
} = state; |
| 2492 |
const newAnswer = { |
| 2493 |
...(answered[action.questionId] || {}), |
| 2494 |
answered: action.answers, |
| 2495 |
temp: true |
| 2496 |
}; |
| 2497 |
if (id) { |
| 2498 |
localStorage.setItem(`LP_Quiz_${id}_Answered`, JSON.stringify({ |
| 2499 |
...state.answered, |
| 2500 |
[action.questionId]: newAnswer |
| 2501 |
})); |
| 2502 |
} |
| 2503 |
return { |
| 2504 |
...state, |
| 2505 |
answered: { |
| 2506 |
...state.answered, |
| 2507 |
[action.questionId]: newAnswer |
| 2508 |
} |
| 2509 |
}; |
| 2510 |
}; |
| 2511 |
const updateUserQuestionFibAnswer = (state, action) => { |
| 2512 |
const { |
| 2513 |
id |
| 2514 |
} = state; |
| 2515 |
const { |
| 2516 |
questionId, |
| 2517 |
idInput, |
| 2518 |
valueInput |
| 2519 |
} = action; |
| 2520 |
if (state.answered.hasOwnProperty(questionId)) { |
| 2521 |
state.answered[questionId].answered[idInput] = valueInput; |
| 2522 |
} else { |
| 2523 |
state.answered[action.questionId] = { |
| 2524 |
answered: { |
| 2525 |
[idInput]: valueInput |
| 2526 |
}, |
| 2527 |
temp: true |
| 2528 |
}; |
| 2529 |
} |
| 2530 |
localStorage.setItem(`LP_Quiz_${id}_Answered`, JSON.stringify(state.answered)); |
| 2531 |
return state; |
| 2532 |
}; |
| 2533 |
const markQuestionRendered = (state, action) => { |
| 2534 |
const { |
| 2535 |
questionsRendered |
| 2536 |
} = state; |
| 2537 |
if (isArray(questionsRendered)) { |
| 2538 |
questionsRendered.push(action.questionId); |
| 2539 |
return { |
| 2540 |
...state, |
| 2541 |
questionsRendered: [...questionsRendered] |
| 2542 |
}; |
| 2543 |
} |
| 2544 |
return { |
| 2545 |
...state, |
| 2546 |
questionsRendered: [action.questionId] |
| 2547 |
}; |
| 2548 |
}; |
| 2549 |
const resetCurrentPage = (state, args) => { |
| 2550 |
if (args.currentPage) { |
| 2551 |
storageSet(`Q${state.id}.currentPage`, args.currentPage); |
| 2552 |
} |
| 2553 |
return { |
| 2554 |
...state, |
| 2555 |
...args |
| 2556 |
}; |
| 2557 |
}; |
| 2558 |
const setQuestionHint = (state, action) => { |
| 2559 |
const questions = state.questions.map(question => { |
| 2560 |
return question.id == action.questionId ? { |
| 2561 |
...question, |
| 2562 |
showHint: action.showHint |
| 2563 |
} : question; |
| 2564 |
}); |
| 2565 |
return { |
| 2566 |
...state, |
| 2567 |
questions: [...questions] |
| 2568 |
}; |
| 2569 |
}; |
| 2570 |
const checkAnswer = (state, action) => { |
| 2571 |
const questions = state.questions.map(question => { |
| 2572 |
if (question.id !== action.questionId) { |
| 2573 |
return question; |
| 2574 |
} |
| 2575 |
const newArgs = { |
| 2576 |
explanation: action.explanation |
| 2577 |
}; |
| 2578 |
if (action.options) { |
| 2579 |
newArgs.options = action.options; |
| 2580 |
} |
| 2581 |
return { |
| 2582 |
...question, |
| 2583 |
...newArgs |
| 2584 |
}; |
| 2585 |
}); |
| 2586 |
const answered = { |
| 2587 |
...state.answered, |
| 2588 |
[action.questionId]: action.result |
| 2589 |
}; |
| 2590 |
let newAnswered = localStorage.getItem(`LP_Quiz_${state.id}_Answered`); |
| 2591 |
if (newAnswered) { |
| 2592 |
newAnswered = { |
| 2593 |
...JSON.parse(newAnswered), |
| 2594 |
...answered |
| 2595 |
}; |
| 2596 |
localStorage.setItem(`LP_Quiz_${state.id}_Answered`, JSON.stringify(newAnswered)); |
| 2597 |
} |
| 2598 |
return { |
| 2599 |
...state, |
| 2600 |
questions: [...questions], |
| 2601 |
answered, |
| 2602 |
checkedQuestions: [...state.checkedQuestions, action.questionId] |
| 2603 |
}; |
| 2604 |
}; |
| 2605 |
const submitQuiz = (state, action) => { |
| 2606 |
localStorage.removeItem(`LP_Quiz_${state.id}_Answered`); |
| 2607 |
const questions = state.questions.map(question => { |
| 2608 |
const newArgs = {}; |
| 2609 |
if (state.reviewQuestions) { |
| 2610 |
if (action.results.questions[question.id]?.explanation) { |
| 2611 |
newArgs.explanation = action.results.questions[question.id].explanation; |
| 2612 |
} |
| 2613 |
if (action.results.questions[question.id]?.options) { |
| 2614 |
newArgs.options = action.results.questions[question.id].options; |
| 2615 |
} |
| 2616 |
} |
| 2617 |
return { |
| 2618 |
...question, |
| 2619 |
...newArgs |
| 2620 |
}; |
| 2621 |
}); |
| 2622 |
return resetCurrentPage(state, { |
| 2623 |
submitting: false, |
| 2624 |
currentPage: 1, |
| 2625 |
...action.results, |
| 2626 |
questions: [...questions] |
| 2627 |
}); |
| 2628 |
}; |
| 2629 |
const startQuizz = (state, action) => { |
| 2630 |
const successResponse = action.results.success !== undefined ? action.results.success : false; |
| 2631 |
const messageResponse = action.results.message || false; |
| 2632 |
const chunks = chunk(action.results.results.questionIds, state.questionsPerPage); |
| 2633 |
state.numPages = chunks.length; |
| 2634 |
return resetCurrentPage(state, { |
| 2635 |
checkedQuestions: [], |
| 2636 |
hintedQuestions: [], |
| 2637 |
mode: '', |
| 2638 |
currentPage: 1, |
| 2639 |
...action.results.results, |
| 2640 |
successResponse, |
| 2641 |
messageResponse |
| 2642 |
}); |
| 2643 |
}; |
| 2644 |
const userQuiz = (state = STORE_DATA, action) => { |
| 2645 |
switch (action.type) { |
| 2646 |
case 'SET_QUIZ_DATA': |
| 2647 |
if (1 > action.data.questionsPerPage) { |
| 2648 |
action.data.questionsPerPage = 1; |
| 2649 |
} |
| 2650 |
const chunks = chunk(state.questionIds || action.data.questionIds, action.data.questionsPerPage); |
| 2651 |
action.data.numPages = chunks.length; |
| 2652 |
action.data.pages = chunks; |
| 2653 |
return { |
| 2654 |
...state, |
| 2655 |
...action.data, |
| 2656 |
currentPage: storageGet(`Q${action.data.id}.currentPage`) || action.data.currentPage |
| 2657 |
}; |
| 2658 |
case 'SUBMIT_QUIZ': |
| 2659 |
return { |
| 2660 |
...state, |
| 2661 |
submitting: true |
| 2662 |
}; |
| 2663 |
case 'START_QUIZ': |
| 2664 |
case 'START_QUIZ_SUCCESS': |
| 2665 |
return startQuizz(state, action); |
| 2666 |
case 'SET_CURRENT_QUESTION': |
| 2667 |
storageSet(`Q${state.id}.currentQuestion`, action.questionId); |
| 2668 |
return { |
| 2669 |
...state, |
| 2670 |
currentQuestion: action.questionId |
| 2671 |
}; |
| 2672 |
case 'SET_CURRENT_PAGE': |
| 2673 |
storageSet(`Q${state.id}.currentPage`, action.currentPage); |
| 2674 |
return { |
| 2675 |
...state, |
| 2676 |
currentPage: action.currentPage |
| 2677 |
}; |
| 2678 |
case 'SUBMIT_QUIZ_SUCCESS': |
| 2679 |
return submitQuiz(state, action); |
| 2680 |
case 'UPDATE_USER_QUESTION_ANSWERS': |
| 2681 |
return state.status === 'started' ? updateUserQuestionAnswer(state, action) : state; |
| 2682 |
case 'UPDATE_USER_QUESTION_FIB_ANSWERS': |
| 2683 |
return state.status === 'started' ? updateUserQuestionFibAnswer(state, action) : state; |
| 2684 |
case 'MARK_QUESTION_RENDERED': |
| 2685 |
return markQuestionRendered(state, action); |
| 2686 |
case 'SET_QUIZ_MODE': |
| 2687 |
if (action.mode == 'reviewing') { |
| 2688 |
return resetCurrentPage(state, { |
| 2689 |
mode: action.mode |
| 2690 |
}); |
| 2691 |
} |
| 2692 |
return { |
| 2693 |
...state, |
| 2694 |
mode: action.mode |
| 2695 |
}; |
| 2696 |
case 'SET_QUESTION_HINT': |
| 2697 |
return setQuestionHint(state, action); |
| 2698 |
case 'CHECK_ANSWER': |
| 2699 |
return checkAnswer(state, action); |
| 2700 |
case 'SEND_KEY': |
| 2701 |
return { |
| 2702 |
...state, |
| 2703 |
keyPressed: action.keyPressed |
| 2704 |
}; |
| 2705 |
} |
| 2706 |
return state; |
| 2707 |
}; |
| 2708 |
const blocks = flow(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.combineReducers, reducer => (state, action) => { |
| 2709 |
return reducer(state, action); |
| 2710 |
}, reducer => (state, action) => { |
| 2711 |
return reducer(state, action); |
| 2712 |
}, reducer => (state, action) => { |
| 2713 |
return reducer(state, action); |
| 2714 |
})({ |
| 2715 |
a(state = { |
| 2716 |
a: 1 |
| 2717 |
}, action) { |
| 2718 |
return state; |
| 2719 |
}, |
| 2720 |
b(state = { |
| 2721 |
b: 2 |
| 2722 |
}, action) { |
| 2723 |
return state; |
| 2724 |
} |
| 2725 |
}); |
| 2726 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ((0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.combineReducers)({ |
| 2727 |
blocks, |
| 2728 |
userQuiz |
| 2729 |
})); |
| 2730 |
|
| 2731 |
/***/ }, |
| 2732 |
|
| 2733 |
/***/ "./assets/src/apps/js/frontend/quiz/store/selectors.js" |
| 2734 |
/*!*************************************************************!*\ |
| 2735 |
!*** ./assets/src/apps/js/frontend/quiz/store/selectors.js ***! |
| 2736 |
\*************************************************************/ |
| 2737 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 2738 |
|
| 2739 |
"use strict"; |
| 2740 |
__webpack_require__.r(__webpack_exports__); |
| 2741 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2742 |
/* harmony export */ getCurrentQuestion: () => (/* binding */ getCurrentQuestion), |
| 2743 |
/* harmony export */ getData: () => (/* binding */ getData), |
| 2744 |
/* harmony export */ getDefaultRestArgs: () => (/* binding */ getDefaultRestArgs), |
| 2745 |
/* harmony export */ getItemStatus: () => (/* binding */ getItemStatus), |
| 2746 |
/* harmony export */ getProp: () => (/* binding */ getProp), |
| 2747 |
/* harmony export */ getQuestion: () => (/* binding */ getQuestion), |
| 2748 |
/* harmony export */ getQuestionAnswered: () => (/* binding */ getQuestionAnswered), |
| 2749 |
/* harmony export */ getQuestionMark: () => (/* binding */ getQuestionMark), |
| 2750 |
/* harmony export */ getQuestionOptions: () => (/* binding */ getQuestionOptions), |
| 2751 |
/* harmony export */ getQuestions: () => (/* binding */ getQuestions), |
| 2752 |
/* harmony export */ getQuestionsSelectedAnswers: () => (/* binding */ getQuestionsSelectedAnswers), |
| 2753 |
/* harmony export */ getQuizAnswered: () => (/* binding */ getQuizAnswered), |
| 2754 |
/* harmony export */ getQuizAttempts: () => (/* binding */ getQuizAttempts), |
| 2755 |
/* harmony export */ getUserMark: () => (/* binding */ getUserMark), |
| 2756 |
/* harmony export */ isCheckedAnswer: () => (/* binding */ isCheckedAnswer), |
| 2757 |
/* harmony export */ isCorrect: () => (/* binding */ isCorrect) |
| 2758 |
/* harmony export */ }); |
| 2759 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/data */ "@wordpress/data"); |
| 2760 |
/* harmony import */ var _wordpress_data__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_data__WEBPACK_IMPORTED_MODULE_0__); |
| 2761 |
|
| 2762 |
const { |
| 2763 |
get, |
| 2764 |
isArray |
| 2765 |
} = lodash; |
| 2766 |
const getQuestionOptions = function getQuestionOptions(state, id) { |
| 2767 |
console.time('parseOptions'); |
| 2768 |
const question = getQuestion(state, id); |
| 2769 |
let options = question.options; |
| 2770 |
options = !isArray(options) ? JSON.parse(CryptoJS.AES.decrypt(options.data, options.key, { |
| 2771 |
format: CryptoJSAesJson |
| 2772 |
}).toString(CryptoJS.enc.Utf8)) : options; |
| 2773 |
options = !isArray(options) ? JSON.parse(options) : options; |
| 2774 |
console.timeEnd('parseOptions'); |
| 2775 |
return options; |
| 2776 |
}; |
| 2777 |
|
| 2778 |
|
| 2779 |
/** |
| 2780 |
* Get current status of an item in course. |
| 2781 |
* |
| 2782 |
* @param state |
| 2783 |
* @param itemId |
| 2784 |
*/ |
| 2785 |
function getItemStatus(state, itemId) { |
| 2786 |
const item = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.select)('course-learner/user').getItemById(itemId); |
| 2787 |
return item ? get(item, 'userSettings.status') : ''; |
| 2788 |
} |
| 2789 |
function getProp(state, prop, defaultValue) { |
| 2790 |
return state[prop] || defaultValue; |
| 2791 |
} |
| 2792 |
|
| 2793 |
/** |
| 2794 |
* Get quiz attempted. |
| 2795 |
* |
| 2796 |
* @param state |
| 2797 |
* @param itemId |
| 2798 |
* @return {Array} |
| 2799 |
*/ |
| 2800 |
function getQuizAttempts(state, itemId) { |
| 2801 |
const item = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.select)('course-learner/user').getItemById(itemId); |
| 2802 |
return item ? get(item, 'userSettings.attempts') : []; |
| 2803 |
} |
| 2804 |
|
| 2805 |
/** |
| 2806 |
* Get answers for a quiz user has did. |
| 2807 |
* |
| 2808 |
* @param state |
| 2809 |
* @param itemId |
| 2810 |
* @return {{}} |
| 2811 |
*/ |
| 2812 |
function getQuizAnswered(state, itemId) { |
| 2813 |
const item = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.select)('course-learner/user').getItemById(itemId); |
| 2814 |
return item ? get(item, 'userSettings.answered', {}) : {}; |
| 2815 |
} |
| 2816 |
|
| 2817 |
/** |
| 2818 |
* Get all questions in quiz. |
| 2819 |
* |
| 2820 |
* @param state |
| 2821 |
* @return {*} |
| 2822 |
*/ |
| 2823 |
function getQuestions(state) { |
| 2824 |
const { |
| 2825 |
userQuiz |
| 2826 |
} = state; |
| 2827 |
const questions = get(userQuiz, 'questions'); |
| 2828 |
return questions ? Object.values(questions) : []; |
| 2829 |
} |
| 2830 |
|
| 2831 |
/** |
| 2832 |
* Get property of store data. |
| 2833 |
* |
| 2834 |
* @param state - Store data |
| 2835 |
* @param prop - Optional. NULL will return all data. |
| 2836 |
* @return {*} |
| 2837 |
*/ |
| 2838 |
function getData(state, prop) { |
| 2839 |
const { |
| 2840 |
userQuiz |
| 2841 |
} = state; |
| 2842 |
if (prop) { |
| 2843 |
return get(userQuiz, prop); |
| 2844 |
} |
| 2845 |
return userQuiz; |
| 2846 |
} |
| 2847 |
function getDefaultRestArgs(state) { |
| 2848 |
const { |
| 2849 |
userQuiz |
| 2850 |
} = state; |
| 2851 |
return { |
| 2852 |
itemId: userQuiz.id, |
| 2853 |
courseId: userQuiz.courseId |
| 2854 |
}; |
| 2855 |
} |
| 2856 |
function getQuestionAnswered(state, id) { |
| 2857 |
const { |
| 2858 |
userQuiz |
| 2859 |
} = state; |
| 2860 |
return get(userQuiz, `answered.${id}.answered`) || undefined; |
| 2861 |
} |
| 2862 |
function getQuestionMark(state, id) { |
| 2863 |
const { |
| 2864 |
userQuiz |
| 2865 |
} = state; |
| 2866 |
return get(userQuiz, `answered.${id}.mark`) || undefined; |
| 2867 |
} |
| 2868 |
|
| 2869 |
/** |
| 2870 |
* Get current question is doing. |
| 2871 |
* |
| 2872 |
* @param {Object} state |
| 2873 |
* @param {string} ret |
| 2874 |
* @return {*} |
| 2875 |
*/ |
| 2876 |
function getCurrentQuestion(state, ret = '') { |
| 2877 |
const questionsPerPage = get(state, 'userQuiz.questionsPerPage') || 1; |
| 2878 |
if (questionsPerPage > 1) { |
| 2879 |
return false; |
| 2880 |
} |
| 2881 |
const currentPage = get(state, 'userQuiz.currentPage') || 1; |
| 2882 |
return ret === 'object' ? get(state, `userQuiz.questions[${currentPage - 1}]`) : get(state, `userQuiz.questionIds[${currentPage - 1}]`); |
| 2883 |
} |
| 2884 |
|
| 2885 |
/** |
| 2886 |
* Return a question contains fully data with title, content, ... |
| 2887 |
* |
| 2888 |
* @param state |
| 2889 |
* @param theId |
| 2890 |
*/ |
| 2891 |
const getQuestion = function getQuestion(state, theId) { |
| 2892 |
const { |
| 2893 |
userQuiz |
| 2894 |
} = state; |
| 2895 |
const s = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_0__.select)('learnpress/quiz'); |
| 2896 |
const questions = s.getQuestions(); |
| 2897 |
return questions.find(q => { |
| 2898 |
return q.id == theId; |
| 2899 |
}); |
| 2900 |
}; |
| 2901 |
|
| 2902 |
|
| 2903 |
/** |
| 2904 |
* If user has used 'Instant check' for a question. |
| 2905 |
* |
| 2906 |
* @param {Object} state - Global state for app. |
| 2907 |
* @param {number} id |
| 2908 |
* @return {boolean} |
| 2909 |
*/ |
| 2910 |
function isCheckedAnswer(state, id) { |
| 2911 |
const checkedQuestions = get(state, 'userQuiz.checkedQuestions') || []; |
| 2912 |
return checkedQuestions.indexOf(id) !== -1; |
| 2913 |
} |
| 2914 |
function isCorrect(state, id) {} |
| 2915 |
|
| 2916 |
/** |
| 2917 |
* Get questions user has selected answers. |
| 2918 |
* |
| 2919 |
* @param {Object} state. Global app state |
| 2920 |
* @param state |
| 2921 |
* @param {number} questionId |
| 2922 |
* @return {{}} |
| 2923 |
*/ |
| 2924 |
const getQuestionsSelectedAnswers = function (state, questionId) { |
| 2925 |
const data = get(state, 'userQuiz.answered'); |
| 2926 |
const returnData = {}; |
| 2927 |
for (const loopId in data) { |
| 2928 |
if (!data.hasOwnProperty(loopId)) { |
| 2929 |
continue; |
| 2930 |
} |
| 2931 |
|
| 2932 |
// Answer filled by user |
| 2933 |
if (data[loopId].temp || data[loopId].blanks) { |
| 2934 |
// If specific a question then return it only. |
| 2935 |
if (questionId && loopId === questionId) { |
| 2936 |
return data[loopId].answered; |
| 2937 |
} |
| 2938 |
returnData[loopId] = data[loopId].answered; |
| 2939 |
} |
| 2940 |
} |
| 2941 |
return returnData; |
| 2942 |
}; |
| 2943 |
|
| 2944 |
|
| 2945 |
/** |
| 2946 |
* Get mark user earned. |
| 2947 |
* Just for questions user has used 'Instant check' button. |
| 2948 |
* |
| 2949 |
* @param state |
| 2950 |
* @return {number} |
| 2951 |
*/ |
| 2952 |
function getUserMark(state) { |
| 2953 |
const userQuiz = state.userQuiz || {}; |
| 2954 |
const { |
| 2955 |
answered, |
| 2956 |
negativeMarking, |
| 2957 |
questions, |
| 2958 |
checkedQuestions |
| 2959 |
} = userQuiz; |
| 2960 |
let totalMark = 0; |
| 2961 |
for (let id in answered) { |
| 2962 |
if (!answered.hasOwnProperty(id)) { |
| 2963 |
continue; |
| 2964 |
} |
| 2965 |
id = parseInt(id); |
| 2966 |
const data = answered[id]; |
| 2967 |
const questionMark = data.questionMark ? data.questionMark : function () { |
| 2968 |
const question = questions.find(q => { |
| 2969 |
return q.id === id; |
| 2970 |
}); |
| 2971 |
return question ? question.point : 0; |
| 2972 |
}(); |
| 2973 |
const isChecked = checkedQuestions.indexOf(id) !== -1; |
| 2974 |
if (data.temp) { |
| 2975 |
continue; |
| 2976 |
} |
| 2977 |
if (negativeMarking) { |
| 2978 |
if (data.answered) { |
| 2979 |
totalMark = data.correct ? totalMark + data.mark : totalMark - questionMark; |
| 2980 |
} |
| 2981 |
} else if (data.answered && data.correct) { |
| 2982 |
totalMark += data.mark; |
| 2983 |
} |
| 2984 |
} |
| 2985 |
return totalMark > 0 ? totalMark : 0; |
| 2986 |
} |
| 2987 |
|
| 2988 |
/***/ }, |
| 2989 |
|
| 2990 |
/***/ "./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js" |
| 2991 |
/*!**********************************************************************!*\ |
| 2992 |
!*** ./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js ***! |
| 2993 |
\**********************************************************************/ |
| 2994 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 2995 |
|
| 2996 |
"use strict"; |
| 2997 |
__webpack_require__.r(__webpack_exports__); |
| 2998 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 2999 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 3000 |
/* harmony export */ }); |
| 3001 |
/* harmony import */ var _utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../utils/lp-modal-overlay */ "./assets/src/apps/js/utils/lp-modal-overlay.js"); |
| 3002 |
|
| 3003 |
const lpModalOverlayCompleteItem = { |
| 3004 |
elBtnFinishCourse: null, |
| 3005 |
elBtnCompleteItem: null, |
| 3006 |
init() { |
| 3007 |
if (!_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].init()) { |
| 3008 |
return; |
| 3009 |
} |
| 3010 |
if (undefined === lpGlobalSettings || 'yes' !== lpGlobalSettings.option_enable_popup_confirm_finish) { |
| 3011 |
return; |
| 3012 |
} |
| 3013 |
this.elBtnFinishCourse = document.querySelectorAll('.lp-btn-finish-course'); |
| 3014 |
this.elBtnCompleteItem = document.querySelector('.lp-btn-complete-item'); |
| 3015 |
if (this.elBtnCompleteItem) { |
| 3016 |
this.elBtnCompleteItem.addEventListener('click', e => { |
| 3017 |
e.preventDefault(); |
| 3018 |
const form = e.target.closest('form'); |
| 3019 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].elLPOverlay.show(); |
| 3020 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setTitleModal(form.dataset.title); |
| 3021 |
// ESC html |
| 3022 |
const div = document.createElement('div'); |
| 3023 |
div.appendChild(document.createTextNode(form.dataset.confirm)); |
| 3024 |
const contentModal = div.innerHTML; |
| 3025 |
// End ESC html |
| 3026 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setContentModal('<div class="pd-2em">' + contentModal + '</div>'); |
| 3027 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].callBackYes = () => { |
| 3028 |
form.submit(); |
| 3029 |
}; |
| 3030 |
}); |
| 3031 |
} |
| 3032 |
if (this.elBtnFinishCourse) { |
| 3033 |
this.elBtnFinishCourse.forEach(element => element.addEventListener('click', e => { |
| 3034 |
e.preventDefault(); |
| 3035 |
const form = e.target.closest('form'); |
| 3036 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].elLPOverlay.show(); |
| 3037 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setTitleModal(form.dataset.title); |
| 3038 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].setContentModal('<div class="pd-2em">' + form.dataset.confirm + '</div>'); |
| 3039 |
_utils_lp_modal_overlay__WEBPACK_IMPORTED_MODULE_0__["default"].callBackYes = () => { |
| 3040 |
form.submit(); |
| 3041 |
}; |
| 3042 |
})); |
| 3043 |
} |
| 3044 |
} |
| 3045 |
}; |
| 3046 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lpModalOverlayCompleteItem); |
| 3047 |
|
| 3048 |
/***/ }, |
| 3049 |
|
| 3050 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/components/compatible.js" |
| 3051 |
/*!********************************************************************************!*\ |
| 3052 |
!*** ./assets/src/apps/js/frontend/single-curriculum/components/compatible.js ***! |
| 3053 |
\********************************************************************************/ |
| 3054 |
() { |
| 3055 |
|
| 3056 |
/** |
| 3057 |
* Compatible with Page Builder. |
| 3058 |
* |
| 3059 |
* @author nhamdv |
| 3060 |
*/ |
| 3061 |
|
| 3062 |
LP.Hook.addAction('lp-compatible-builder', () => { |
| 3063 |
LP.Hook.removeAction('lp-compatible-builder'); |
| 3064 |
if (typeof elementorFrontend !== 'undefined') { |
| 3065 |
[...document.querySelectorAll('#popup-content')][0].addEventListener('scroll', () => { |
| 3066 |
//Waypoint.refreshAll(); |
| 3067 |
window.dispatchEvent(new Event('resize')); |
| 3068 |
}); |
| 3069 |
} |
| 3070 |
|
| 3071 |
/*if ( typeof vc_js !== 'undefined' && typeof VcWaypoint !== 'undefined' ) { |
| 3072 |
[ ...document.querySelectorAll( '#popup-content' ) ][ 0 ].addEventListener( 'scroll', () => { |
| 3073 |
VcWaypoint.refreshAll(); |
| 3074 |
} ); |
| 3075 |
}*/ |
| 3076 |
}); |
| 3077 |
LP.Hook.addAction('lp-quiz-compatible-builder', () => { |
| 3078 |
LP.Hook.removeAction('lp-quiz-compatible-builder'); |
| 3079 |
LP.Hook.doAction('lp-compatible-builder'); |
| 3080 |
if (typeof elementorFrontend !== 'undefined') { |
| 3081 |
return window.elementorFrontend.init(); |
| 3082 |
} |
| 3083 |
if (typeof vc_js !== 'undefined') { |
| 3084 |
if (typeof vc_round_charts !== 'undefined') { |
| 3085 |
vc_round_charts(); |
| 3086 |
} |
| 3087 |
if (typeof vc_pieChart !== 'undefined') { |
| 3088 |
vc_pieChart(); |
| 3089 |
} |
| 3090 |
if (typeof vc_line_charts !== 'undefined') { |
| 3091 |
vc_line_charts(); |
| 3092 |
} |
| 3093 |
return window.vc_js(); |
| 3094 |
} |
| 3095 |
}); |
| 3096 |
LP.Hook.addAction('lp-question-compatible-builder', () => { |
| 3097 |
LP.Hook.removeAction('lp-question-compatible-builder'); |
| 3098 |
LP.Hook.removeAction('lp-quiz-compatible-builder'); |
| 3099 |
LP.Hook.doAction('lp-compatible-builder'); |
| 3100 |
if (typeof elementorFrontend !== 'undefined') { |
| 3101 |
return window.elementorFrontend.init(); |
| 3102 |
} |
| 3103 |
if (typeof vc_js !== 'undefined') { |
| 3104 |
if (typeof vc_round_charts !== 'undefined') { |
| 3105 |
vc_round_charts(); |
| 3106 |
} |
| 3107 |
if (typeof vc_pieChart !== 'undefined') { |
| 3108 |
vc_pieChart(); |
| 3109 |
} |
| 3110 |
if (typeof vc_line_charts !== 'undefined') { |
| 3111 |
vc_line_charts(); |
| 3112 |
} |
| 3113 |
return window.vc_js(); |
| 3114 |
} |
| 3115 |
}); |
| 3116 |
|
| 3117 |
/***/ }, |
| 3118 |
|
| 3119 |
/***/ "./assets/src/apps/js/frontend/single-curriculum/components/items-progress.js" |
| 3120 |
/*!************************************************************************************!*\ |
| 3121 |
!*** ./assets/src/apps/js/frontend/single-curriculum/components/items-progress.js ***! |
| 3122 |
\************************************************************************************/ |
| 3123 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 3124 |
|
| 3125 |
"use strict"; |
| 3126 |
__webpack_require__.r(__webpack_exports__); |
| 3127 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3128 |
/* harmony export */ getResponse: () => (/* binding */ getResponse), |
| 3129 |
/* harmony export */ itemsProgress: () => (/* binding */ itemsProgress) |
| 3130 |
/* harmony export */ }); |
| 3131 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @wordpress/url */ "@wordpress/url"); |
| 3132 |
/* harmony import */ var _wordpress_url__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_wordpress_url__WEBPACK_IMPORTED_MODULE_0__); |
| 3133 |
/* harmony import */ var _show_lp_overlay_complete_item__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../show-lp-overlay-complete-item */ "./assets/src/apps/js/frontend/show-lp-overlay-complete-item.js"); |
| 3134 |
// Rest API load content course progress - Nhamdv. |
| 3135 |
|
| 3136 |
|
| 3137 |
const itemsProgress = () => { |
| 3138 |
const elements = document.querySelectorAll('.popup-header__inner'); |
| 3139 |
if (!elements.length) { |
| 3140 |
return; |
| 3141 |
} |
| 3142 |
if (document.querySelector('#learn-press-quiz-app div.quiz-result') !== null) { |
| 3143 |
return; |
| 3144 |
} |
| 3145 |
if (elements[0].querySelectorAll('form.form-button-finish-course').length !== 0) { |
| 3146 |
return; |
| 3147 |
} |
| 3148 |
const user_id = lpGlobalSettings.user_id || 0; |
| 3149 |
if (user_id === 0) { |
| 3150 |
return; |
| 3151 |
} |
| 3152 |
if ('IntersectionObserver' in window) { |
| 3153 |
const eleObserver = new IntersectionObserver((entries, observer) => { |
| 3154 |
entries.forEach(entry => { |
| 3155 |
if (entry.isIntersecting) { |
| 3156 |
const ele = entry.target; |
| 3157 |
getResponse(ele); |
| 3158 |
eleObserver.unobserve(ele); |
| 3159 |
} |
| 3160 |
}); |
| 3161 |
}); |
| 3162 |
[...elements].map(ele => eleObserver.observe(ele)); |
| 3163 |
} |
| 3164 |
}; |
| 3165 |
const getResponse = async ele => { |
| 3166 |
const response = await wp.apiFetch({ |
| 3167 |
path: (0,_wordpress_url__WEBPACK_IMPORTED_MODULE_0__.addQueryArgs)('lp/v1/lazy-load/items-progress', { |
| 3168 |
courseId: lpGlobalSettings.post_id || '', |
| 3169 |
userId: lpGlobalSettings.user_id || '' |
| 3170 |
}), |
| 3171 |
method: 'GET' |
| 3172 |
}); |
| 3173 |
const { |
| 3174 |
data |
| 3175 |
} = response; |
| 3176 |
ele.innerHTML += data; |
| 3177 |
ele.classList.add('can-finish-course'); |
| 3178 |
_show_lp_overlay_complete_item__WEBPACK_IMPORTED_MODULE_1__["default"].init(); |
| 3179 |
}; |
| 3180 |
|
| 3181 |
/***/ }, |
| 3182 |
|
| 3183 |
/***/ "./assets/src/apps/js/utils/lp-modal-overlay.js" |
| 3184 |
/*!******************************************************!*\ |
| 3185 |
!*** ./assets/src/apps/js/utils/lp-modal-overlay.js ***! |
| 3186 |
\******************************************************/ |
| 3187 |
(__unused_webpack_module, __webpack_exports__, __webpack_require__) { |
| 3188 |
|
| 3189 |
"use strict"; |
| 3190 |
__webpack_require__.r(__webpack_exports__); |
| 3191 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3192 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) |
| 3193 |
/* harmony export */ }); |
| 3194 |
const $ = jQuery; |
| 3195 |
let elLPOverlay = null; |
| 3196 |
const lpModalOverlay = { |
| 3197 |
elLPOverlay: null, |
| 3198 |
elMainContent: null, |
| 3199 |
elTitle: null, |
| 3200 |
elBtnYes: null, |
| 3201 |
elBtnNo: null, |
| 3202 |
elFooter: null, |
| 3203 |
elCalledModal: null, |
| 3204 |
callBackYes: null, |
| 3205 |
instance: null, |
| 3206 |
init() { |
| 3207 |
if (this.instance) { |
| 3208 |
return true; |
| 3209 |
} |
| 3210 |
this.elLPOverlay = $('.lp-overlay'); |
| 3211 |
if (!this.elLPOverlay.length) { |
| 3212 |
return false; |
| 3213 |
} |
| 3214 |
elLPOverlay = this.elLPOverlay; |
| 3215 |
this.elMainContent = elLPOverlay.find('.main-content'); |
| 3216 |
this.elTitle = elLPOverlay.find('.modal-title'); |
| 3217 |
this.elBtnYes = elLPOverlay.find('.btn-yes'); |
| 3218 |
this.elBtnNo = elLPOverlay.find('.btn-no'); |
| 3219 |
this.elFooter = elLPOverlay.find('.lp-modal-footer'); |
| 3220 |
$(document).on('click', '.close, .btn-no', function () { |
| 3221 |
elLPOverlay.hide(); |
| 3222 |
}); |
| 3223 |
$(document).on('click', '.btn-yes', function (e) { |
| 3224 |
e.preventDefault(); |
| 3225 |
e.stopPropagation(); |
| 3226 |
if ('function' === typeof lpModalOverlay.callBackYes) { |
| 3227 |
lpModalOverlay.callBackYes(e); |
| 3228 |
} |
| 3229 |
}); |
| 3230 |
this.instance = this; |
| 3231 |
return true; |
| 3232 |
}, |
| 3233 |
setElCalledModal(elCalledModal) { |
| 3234 |
this.elCalledModal = elCalledModal; |
| 3235 |
}, |
| 3236 |
setContentModal(content, event) { |
| 3237 |
this.elMainContent.html(content); |
| 3238 |
if ('function' === typeof event) { |
| 3239 |
event(); |
| 3240 |
} |
| 3241 |
}, |
| 3242 |
setTitleModal(content) { |
| 3243 |
this.elTitle.html(content); |
| 3244 |
} |
| 3245 |
}; |
| 3246 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (lpModalOverlay); |
| 3247 |
|
| 3248 |
/***/ }, |
| 3249 |
|
| 3250 |
/***/ "./node_modules/refx/refx.js" |
| 3251 |
/*!***********************************!*\ |
| 3252 |
!*** ./node_modules/refx/refx.js ***! |
| 3253 |
\***********************************/ |
| 3254 |
(module) { |
| 3255 |
|
| 3256 |
"use strict"; |
| 3257 |
|
| 3258 |
|
| 3259 |
function flattenIntoMap( map, effects ) { |
| 3260 |
var i; |
| 3261 |
if ( Array.isArray( effects ) ) { |
| 3262 |
for ( i = 0; i < effects.length; i++ ) { |
| 3263 |
flattenIntoMap( map, effects[ i ] ); |
| 3264 |
} |
| 3265 |
} else { |
| 3266 |
for ( i in effects ) { |
| 3267 |
map[ i ] = ( map[ i ] || [] ).concat( effects[ i ] ); |
| 3268 |
} |
| 3269 |
} |
| 3270 |
} |
| 3271 |
|
| 3272 |
function refx( effects ) { |
| 3273 |
var map = {}, |
| 3274 |
middleware; |
| 3275 |
|
| 3276 |
flattenIntoMap( map, effects ); |
| 3277 |
|
| 3278 |
middleware = function( store ) { |
| 3279 |
return function( next ) { |
| 3280 |
return function( action ) { |
| 3281 |
var handlers = map[ action.type ], |
| 3282 |
result = next( action ), |
| 3283 |
i, handlerAction; |
| 3284 |
|
| 3285 |
if ( handlers ) { |
| 3286 |
for ( i = 0; i < handlers.length; i++ ) { |
| 3287 |
handlerAction = handlers[ i ]( action, store ); |
| 3288 |
if ( handlerAction ) { |
| 3289 |
store.dispatch( handlerAction ); |
| 3290 |
} |
| 3291 |
} |
| 3292 |
} |
| 3293 |
|
| 3294 |
return result; |
| 3295 |
}; |
| 3296 |
}; |
| 3297 |
}; |
| 3298 |
|
| 3299 |
middleware.effects = map; |
| 3300 |
|
| 3301 |
return middleware; |
| 3302 |
} |
| 3303 |
|
| 3304 |
module.exports = refx; |
| 3305 |
|
| 3306 |
|
| 3307 |
/***/ }, |
| 3308 |
|
| 3309 |
/***/ "react" |
| 3310 |
/*!************************!*\ |
| 3311 |
!*** external "React" ***! |
| 3312 |
\************************/ |
| 3313 |
(module) { |
| 3314 |
|
| 3315 |
"use strict"; |
| 3316 |
module.exports = window["React"]; |
| 3317 |
|
| 3318 |
/***/ }, |
| 3319 |
|
| 3320 |
/***/ "@learnpress/data-controls" |
| 3321 |
/*!**************************************!*\ |
| 3322 |
!*** external ["LP","dataControls"] ***! |
| 3323 |
\**************************************/ |
| 3324 |
(module) { |
| 3325 |
|
| 3326 |
"use strict"; |
| 3327 |
module.exports = window["LP"]["dataControls"]; |
| 3328 |
|
| 3329 |
/***/ }, |
| 3330 |
|
| 3331 |
/***/ "@wordpress/compose" |
| 3332 |
/*!*********************************!*\ |
| 3333 |
!*** external ["wp","compose"] ***! |
| 3334 |
\*********************************/ |
| 3335 |
(module) { |
| 3336 |
|
| 3337 |
"use strict"; |
| 3338 |
module.exports = window["wp"]["compose"]; |
| 3339 |
|
| 3340 |
/***/ }, |
| 3341 |
|
| 3342 |
/***/ "@wordpress/data" |
| 3343 |
/*!******************************!*\ |
| 3344 |
!*** external ["wp","data"] ***! |
| 3345 |
\******************************/ |
| 3346 |
(module) { |
| 3347 |
|
| 3348 |
"use strict"; |
| 3349 |
module.exports = window["wp"]["data"]; |
| 3350 |
|
| 3351 |
/***/ }, |
| 3352 |
|
| 3353 |
/***/ "@wordpress/element" |
| 3354 |
/*!*********************************!*\ |
| 3355 |
!*** external ["wp","element"] ***! |
| 3356 |
\*********************************/ |
| 3357 |
(module) { |
| 3358 |
|
| 3359 |
"use strict"; |
| 3360 |
module.exports = window["wp"]["element"]; |
| 3361 |
|
| 3362 |
/***/ }, |
| 3363 |
|
| 3364 |
/***/ "@wordpress/i18n" |
| 3365 |
/*!******************************!*\ |
| 3366 |
!*** external ["wp","i18n"] ***! |
| 3367 |
\******************************/ |
| 3368 |
(module) { |
| 3369 |
|
| 3370 |
"use strict"; |
| 3371 |
module.exports = window["wp"]["i18n"]; |
| 3372 |
|
| 3373 |
/***/ }, |
| 3374 |
|
| 3375 |
/***/ "@wordpress/url" |
| 3376 |
/*!*****************************!*\ |
| 3377 |
!*** external ["wp","url"] ***! |
| 3378 |
\*****************************/ |
| 3379 |
(module) { |
| 3380 |
|
| 3381 |
"use strict"; |
| 3382 |
module.exports = window["wp"]["url"]; |
| 3383 |
|
| 3384 |
/***/ }, |
| 3385 |
|
| 3386 |
/***/ "./node_modules/classnames/index.js" |
| 3387 |
/*!******************************************!*\ |
| 3388 |
!*** ./node_modules/classnames/index.js ***! |
| 3389 |
\******************************************/ |
| 3390 |
(module, exports) { |
| 3391 |
|
| 3392 |
var __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/*! |
| 3393 |
Copyright (c) 2018 Jed Watson. |
| 3394 |
Licensed under the MIT License (MIT), see |
| 3395 |
http://jedwatson.github.io/classnames |
| 3396 |
*/ |
| 3397 |
/* global define */ |
| 3398 |
|
| 3399 |
(function () { |
| 3400 |
'use strict'; |
| 3401 |
|
| 3402 |
var hasOwn = {}.hasOwnProperty; |
| 3403 |
|
| 3404 |
function classNames () { |
| 3405 |
var classes = ''; |
| 3406 |
|
| 3407 |
for (var i = 0; i < arguments.length; i++) { |
| 3408 |
var arg = arguments[i]; |
| 3409 |
if (arg) { |
| 3410 |
classes = appendClass(classes, parseValue(arg)); |
| 3411 |
} |
| 3412 |
} |
| 3413 |
|
| 3414 |
return classes; |
| 3415 |
} |
| 3416 |
|
| 3417 |
function parseValue (arg) { |
| 3418 |
if (typeof arg === 'string' || typeof arg === 'number') { |
| 3419 |
return arg; |
| 3420 |
} |
| 3421 |
|
| 3422 |
if (typeof arg !== 'object') { |
| 3423 |
return ''; |
| 3424 |
} |
| 3425 |
|
| 3426 |
if (Array.isArray(arg)) { |
| 3427 |
return classNames.apply(null, arg); |
| 3428 |
} |
| 3429 |
|
| 3430 |
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) { |
| 3431 |
return arg.toString(); |
| 3432 |
} |
| 3433 |
|
| 3434 |
var classes = ''; |
| 3435 |
|
| 3436 |
for (var key in arg) { |
| 3437 |
if (hasOwn.call(arg, key) && arg[key]) { |
| 3438 |
classes = appendClass(classes, key); |
| 3439 |
} |
| 3440 |
} |
| 3441 |
|
| 3442 |
return classes; |
| 3443 |
} |
| 3444 |
|
| 3445 |
function appendClass (value, newClass) { |
| 3446 |
if (!newClass) { |
| 3447 |
return value; |
| 3448 |
} |
| 3449 |
|
| 3450 |
if (value) { |
| 3451 |
return value + ' ' + newClass; |
| 3452 |
} |
| 3453 |
|
| 3454 |
return value + newClass; |
| 3455 |
} |
| 3456 |
|
| 3457 |
if ( true && module.exports) { |
| 3458 |
classNames.default = classNames; |
| 3459 |
module.exports = classNames; |
| 3460 |
} else if (true) { |
| 3461 |
// register as 'classnames', consistent with npm package name |
| 3462 |
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_RESULT__ = (function () { |
| 3463 |
return classNames; |
| 3464 |
}).apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__), |
| 3465 |
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); |
| 3466 |
} else // removed by dead control flow |
| 3467 |
{} |
| 3468 |
}()); |
| 3469 |
|
| 3470 |
|
| 3471 |
/***/ } |
| 3472 |
|
| 3473 |
/******/ }); |
| 3474 |
/************************************************************************/ |
| 3475 |
/******/ // The module cache |
| 3476 |
/******/ var __webpack_module_cache__ = {}; |
| 3477 |
/******/ |
| 3478 |
/******/ // The require function |
| 3479 |
/******/ function __webpack_require__(moduleId) { |
| 3480 |
/******/ // Check if module is in cache |
| 3481 |
/******/ var cachedModule = __webpack_module_cache__[moduleId]; |
| 3482 |
/******/ if (cachedModule !== undefined) { |
| 3483 |
/******/ return cachedModule.exports; |
| 3484 |
/******/ } |
| 3485 |
/******/ // Create a new module (and put it into the cache) |
| 3486 |
/******/ var module = __webpack_module_cache__[moduleId] = { |
| 3487 |
/******/ // no module.id needed |
| 3488 |
/******/ // no module.loaded needed |
| 3489 |
/******/ exports: {} |
| 3490 |
/******/ }; |
| 3491 |
/******/ |
| 3492 |
/******/ // Execute the module function |
| 3493 |
/******/ if (!(moduleId in __webpack_modules__)) { |
| 3494 |
/******/ delete __webpack_module_cache__[moduleId]; |
| 3495 |
/******/ var e = new Error("Cannot find module '" + moduleId + "'"); |
| 3496 |
/******/ e.code = 'MODULE_NOT_FOUND'; |
| 3497 |
/******/ throw e; |
| 3498 |
/******/ } |
| 3499 |
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); |
| 3500 |
/******/ |
| 3501 |
/******/ // Return the exports of the module |
| 3502 |
/******/ return module.exports; |
| 3503 |
/******/ } |
| 3504 |
/******/ |
| 3505 |
/************************************************************************/ |
| 3506 |
/******/ /* webpack/runtime/compat get default export */ |
| 3507 |
/******/ (() => { |
| 3508 |
/******/ // getDefaultExport function for compatibility with non-harmony modules |
| 3509 |
/******/ __webpack_require__.n = (module) => { |
| 3510 |
/******/ var getter = module && module.__esModule ? |
| 3511 |
/******/ () => (module['default']) : |
| 3512 |
/******/ () => (module); |
| 3513 |
/******/ __webpack_require__.d(getter, { a: getter }); |
| 3514 |
/******/ return getter; |
| 3515 |
/******/ }; |
| 3516 |
/******/ })(); |
| 3517 |
/******/ |
| 3518 |
/******/ /* webpack/runtime/define property getters */ |
| 3519 |
/******/ (() => { |
| 3520 |
/******/ // define getter functions for harmony exports |
| 3521 |
/******/ __webpack_require__.d = (exports, definition) => { |
| 3522 |
/******/ for(var key in definition) { |
| 3523 |
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { |
| 3524 |
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); |
| 3525 |
/******/ } |
| 3526 |
/******/ } |
| 3527 |
/******/ }; |
| 3528 |
/******/ })(); |
| 3529 |
/******/ |
| 3530 |
/******/ /* webpack/runtime/hasOwnProperty shorthand */ |
| 3531 |
/******/ (() => { |
| 3532 |
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) |
| 3533 |
/******/ })(); |
| 3534 |
/******/ |
| 3535 |
/******/ /* webpack/runtime/make namespace object */ |
| 3536 |
/******/ (() => { |
| 3537 |
/******/ // define __esModule on exports |
| 3538 |
/******/ __webpack_require__.r = (exports) => { |
| 3539 |
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { |
| 3540 |
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); |
| 3541 |
/******/ } |
| 3542 |
/******/ Object.defineProperty(exports, '__esModule', { value: true }); |
| 3543 |
/******/ }; |
| 3544 |
/******/ })(); |
| 3545 |
/******/ |
| 3546 |
/************************************************************************/ |
| 3547 |
var __webpack_exports__ = {}; |
| 3548 |
// This entry needs to be wrapped in an IIFE because it needs to be in strict mode. |
| 3549 |
(() => { |
| 3550 |
"use strict"; |
| 3551 |
/*!*********************************************!*\ |
| 3552 |
!*** ./assets/src/apps/js/frontend/quiz.js ***! |
| 3553 |
\*********************************************/ |
| 3554 |
__webpack_require__.r(__webpack_exports__); |
| 3555 |
/* harmony export */ __webpack_require__.d(__webpack_exports__, { |
| 3556 |
/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__), |
| 3557 |
/* harmony export */ init: () => (/* binding */ init) |
| 3558 |
/* harmony export */ }); |
| 3559 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! react */ "react"); |
| 3560 |
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__); |
| 3561 |
/* harmony import */ var _quiz_index__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./quiz/index */ "./assets/src/apps/js/frontend/quiz/index.js"); |
| 3562 |
/* harmony import */ var _single_curriculum_components_compatible__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./single-curriculum/components/compatible */ "./assets/src/apps/js/frontend/single-curriculum/components/compatible.js"); |
| 3563 |
/* harmony import */ var _single_curriculum_components_compatible__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_single_curriculum_components_compatible__WEBPACK_IMPORTED_MODULE_2__); |
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
const { |
| 3568 |
modal: { |
| 3569 |
default: Modal |
| 3570 |
} |
| 3571 |
} = LP; |
| 3572 |
/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (_quiz_index__WEBPACK_IMPORTED_MODULE_1__["default"]); |
| 3573 |
const init = (elem, settings) => { |
| 3574 |
// For no require enroll |
| 3575 |
if (lpQuizSettings.checkNorequizenroll === 1) { |
| 3576 |
const keyQuizOff = 'quiz_off_' + lpQuizSettings.id; |
| 3577 |
const quizDataOffStr = window.localStorage.getItem(keyQuizOff); |
| 3578 |
if (null !== quizDataOffStr) { |
| 3579 |
const quizDataOff = JSON.parse(quizDataOffStr); |
| 3580 |
settings.status = quizDataOff.status; |
| 3581 |
settings.questions = quizDataOff.questions; |
| 3582 |
if ('started' === quizDataOff.status) { |
| 3583 |
const now = Date.now(); |
| 3584 |
settings.total_time = Math.floor((quizDataOff.endTime - now) / 1000); |
| 3585 |
} else if ('completed' === quizDataOff.status) { |
| 3586 |
settings.results = quizDataOff.results; |
| 3587 |
settings.answered = quizDataOff.results.answered; |
| 3588 |
settings.questions = quizDataOff.results.questions; |
| 3589 |
} |
| 3590 |
if (undefined !== quizDataOff.checked_questions) { |
| 3591 |
settings.checked_questions = quizDataOff.checked_questions; |
| 3592 |
} |
| 3593 |
if (undefined !== quizDataOff.question_options) { |
| 3594 |
//settings.checked_questions = quizDataOff.checked_questions; |
| 3595 |
|
| 3596 |
for (const i in settings.questions) { |
| 3597 |
const question = settings.questions[i]; |
| 3598 |
if (undefined !== quizDataOff.question_options[question.id]) { |
| 3599 |
question.options = quizDataOff.question_options[question.id]; |
| 3600 |
} |
| 3601 |
settings.questions[i] = question; |
| 3602 |
} |
| 3603 |
} |
| 3604 |
} |
| 3605 |
} |
| 3606 |
|
| 3607 |
//console.log(settings); |
| 3608 |
|
| 3609 |
wp.element.render((0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(Modal, null, (0,react__WEBPACK_IMPORTED_MODULE_0__.createElement)(_quiz_index__WEBPACK_IMPORTED_MODULE_1__["default"], { |
| 3610 |
settings: settings |
| 3611 |
})), [...document.querySelectorAll(elem)][0]); |
| 3612 |
LP.Hook.doAction('lp-quiz-compatible-builder'); |
| 3613 |
}; |
| 3614 |
})(); |
| 3615 |
|
| 3616 |
(window.LP = window.LP || {}).quiz = __webpack_exports__; |
| 3617 |
/******/ })() |
| 3618 |
; |
| 3619 |
//# sourceMappingURL=quiz.js.map |