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