📄 common.js
字号:
} else if (!ele.value) { markClozeWord(ele, NOT_ATTEMPTED); return NOT_ATTEMPTED; } else { markClozeWord(ele, WRONG); return WRONG; }}// Marks a cloze question (at the moment just changes the color)// 'mark' should be 0=Not Answered, 1=Wrong, 2=Rightfunction markClozeWord(ele, mark) { switch (mark) { case 0: // Not attempted ele.style.backgroundColor = ""; break; case 1: // Wrong ele.style.backgroundColor = "red"; break; case 2: // Correct ele.style.backgroundColor = "lime"; break; } return mark}// Return the last mark applied to a wordfunction getClozeMark(ele) { // Return last mark applied switch (ele.style.backgroundColor) { case 'red': return 1; // Wrong case 'lime': return 2; // Correct default: return 0; // Not attempted }}// Decrypts and returns the answer for a certain cloze field wordfunction getClozeAnswer(ele) { var idents = getClozeIds(ele) var ident = idents[0] var inputId = idents[1] var answerSpan = document.getElementById('clozeAnswer'+ident+'.'+inputId); var code = answerSpan.innerHTML; code = decode64(code) code = unescape(code) // XOR "Decrypt" result = ''; var key = 'X'.charCodeAt(0); for (var i=0; i<code.length; i++) { var letter = code.charCodeAt(i); key ^= letter result += String.fromCharCode(key); } return result}// Base64 Decode// Base64 code from Tyler Akins -- http://rumkin.comfunction decode64(input) { var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; // Remove all characters that are not A-Z, a-z, 0-9, +, /, or = input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); do { enc1 = keyStr.indexOf(input.charAt(i++)); enc2 = keyStr.indexOf(input.charAt(i++)); enc3 = keyStr.indexOf(input.charAt(i++)); enc4 = keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } while (i < input.length); return output;}// Returns the corrected word or an empty stringfunction checkClozeWord(ele) { var guess = ele.value; // Extract the idevice id and the input number out of the element's id var original = getClozeAnswer(ele); var answer = original; var guess = ele.value var ident = getClozeIds(ele)[0] // Read the flags for checking answers var strictMarking = eval(document.getElementById( 'clozeFlag'+ident+'.strictMarking').value); var checkCaps = eval(document.getElementById( 'clozeFlag'+ident+'.checkCaps').value); if (!checkCaps) { guess = guess.toLowerCase(); answer = original.toLowerCase(); } if (guess == answer) // You are right! return original else if (strictMarking || answer.length <= 4) // You are wrong! return ""; else { // Now use the similarity check algorythm var i = 0; var j = 0; var orders = [[answer, guess], [guess, answer]]; var maxMisses = Math.floor(answer.length / 6) + 1; var misses = 0; if (guess.length <= maxMisses) { misses = Math.abs(guess.length - answer.length); for (i = 0; i < guess.length; i++ ) { if (answer.search(guess[i]) == -1) { misses += 1; } } if (misses <= maxMisses) { return answer; } else { return ""; } } // Iterate through the different orders of checking for (i = 0; i < 2; i++) { var string1 = orders[i][0]; var string2 = orders[i][1]; while (string1) { misses = Math.floor( (Math.abs(string1.length - string2.length) + Math.abs(guess.length - answer.length)) / 2) var max = Math.min(string1.length, string2.length) for (j = 0; j < max; j++) { var a = string2.charAt(j); var b = string1.charAt(j); if (a != b) misses += 1; if (misses > maxMisses) break; } if (misses <= maxMisses) // You are right return answer; string1 = string1.substr(1); } } // You are wrong! return ""; }}// Extracts the idevice id and input id from a javascript elementfunction getClozeIds(ele) { // Extract the idevice id and the input number out of the element's id // id is "clozeBlank%s.%s" % (idevice.id, input number) var id = ele.id.slice(10); var dotindex = id.indexOf('.') var ident = id.slice(0, dotindex) var inputId = id.slice(id.indexOf('.')+1) return [ident, inputId]}// Calculate the score for cloze idevicefunction showClozeScore(ident, mark) { var score = 0 var div = document.getElementById('cloze' + ident) var inputs = getCloseInputs(ident) for (var i=0; i<inputs.length; i++) { var input = inputs[i]; if (mark) { var result = checkAndMarkClozeWord(input); } else { var result = getClozeMark(input); } if (result == 2) { score++; } } // Show it in a nice paragraph var scorePara = document.getElementById('clozeScore' + ident); scorePara.innerHTML = YOUR_SCORE_IS + score + "/" + inputs.length + ".";}// Returns an array of input elements that are associated with a certain idevicefunction getCloseInputs(ident) { var result = new Array; var clozeDiv = document.getElementById('cloze'+ident) recurseFindClozeInputs(clozeDiv, ident, result) return result}// Adds any cloze inputs found to result, recurses downfunction recurseFindClozeInputs(dad, ident, result) { for (var i=0; i<dad.childNodes.length; i++) { var ele = dad.childNodes[i]; // See if it is a blank if (ele.id) { if (ele.id.search('clozeBlank'+ident) == 0) { result.push(ele); continue; } } // See if it contains blanks if (ele.hasChildNodes()) { recurseFindClozeInputs(ele, ident, result); } }} // Pass the cloze element's id, and the visible property of the feedback element// associated with it will be toggled. If there is no feedback field, does// nothingfunction toggleClozeFeedback(ident) { var feedbackIdEle = document.getElementById( 'clozeVar'+ident+'.feedbackId'); if (feedbackIdEle) { var feedbackId = feedbackIdEle.value; toggleElementVisible(feedbackId); }}// Toggle the visiblity of an element from it's idfunction toggleElementVisible(ident) { // Toggle the visibility of an element var element = document.getElementById(ident); if (element) { if (element.style.display != "none") { element.style.display = "none"; } else { element.style.display = ""; } }}// Reflection Idevice code ////////////////////////////////////////////////// Show or hide the feedback for reflection idevicefunction showAnswer(id,isShow) { if (isShow==1) { document.getElementById("s"+id).style.display = "block"; document.getElementById("hide"+id).style.display = "block"; document.getElementById("view"+id).style.display = "none"; } else { document.getElementById("s"+id).style.display = "none"; document.getElementById("hide"+id).style.display = "none"; document.getElementById("view"+id).style.display = "block"; }}//change forum or discussion topic or lms for discussion idevice.function submitChange(action, selectId) { var form = document.getElementById("contentForm") form.action.value = action var select = document.getElementById(selectId) form.object.value = select.value; form.isChanged.value = 1; form.submit();}// show or hide the feedback for cloze idevicefunction toggleFeedback(id) { var ele = document.getElementById('fb'+id); if (ele.style.display == "block") { ele.style.display = "none"; } else { ele.style.display = "block"; }}// Call the function like this://insertAtCursor(document.formName.fieldName, this value);function insertAtCursor(myField, myValue, num) { //MOZILLA/NETSCAPE support if (myField.selectionStart || myField.selectionStart == '0') { var startPos = myField.selectionStart; var endPos = myField.selectionEnd; myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length); myField.selectionStart = startPos + myValue.length - num } else { myField.value += myValue; } myField.selectionEnd = myField.selectionStart myField.focus();}//used by maths idevicefunction insertSymbol(id, string, num){ var ele = document.getElementById(id); insertAtCursor(ele, string, num)}//used for multiple select idevice for calculating score and showing feedback.function calcScore(num, ident){ var score = 0; for(i=0; i<num; i++){ var chkele = document.getElementById(ident+i.toString()); var ansele = document.getElementById("ans"+ident+i.toString()) chk = "False" if (chkele.checked==1) chk = "True" if (chk == chkele.value){ score++ ansele.style.color = "black" }else{ ansele.style.color = "red" } } var fele = document.getElementById("f"+ident) fele.style.display = "block" alert(YOUR_SCORE_IS + score + "/" + num)}// used to show question's feedback for multi-select idevice function showFeedback(num, ident){ for(i=0; i<num; i++){ var ele = document.getElementById(ident+i.toString()) var ele0 = document.getElementById(ident+i.toString()+"0") var ele1 = document.getElementById(ident+i.toString()+"1") var ansele = document.getElementById("ans"+ident+i.toString()) chk = "False" if (ele.checked==1) chk = "True" if (chk == ele.value){ ele1.style.display = "block" ele0.style.display = "none" ansele.style.color = "black" }else{ ele0.style.display = "block" ele1.style.display = "none" ansele.style.color = "red" } } var fele = document.getElementById("f"+ident) fele.style.display = "block"}///////////////////////////////////////////////// Media plugin detection codes, modified from:// http://developer.apple.com/internet/webcontent/detectplugins.htmlfunction detectQuickTime() { pluginFound = detectPlugin('QuickTime'); return pluginFound;}function detectReal() { pluginFound = detectPlugin('RealPlayer'); return pluginFound;}function detectFlash() { pluginFound = detectPlugin('Shockwave','Flash'); return pluginFound;}function detectDirector() { pluginFound = detectPlugin('Shockwave','Director'); return pluginFound;}function detectWindowsMedia() { pluginFound = detectPlugin('Windows Media'); return pluginFound;}function detectPlugin() { // allow for multiple checks in a single pass var daPlugins = detectPlugin.arguments; // consider pluginFound to be false until proven true var pluginFound = false; // if plugins array is there and not fake if (navigator.plugins && navigator.plugins.length > 0) { var pluginsArrayLength = navigator.plugins.length; // for each plugin... for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) { // loop through all desired names and check each against the current plugin name var numFound = 0; for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) { // if desired plugin name is found in either plugin name or description if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) { // this name was found numFound++; } } // now that we have checked all the required names against this one plugin, // if the number we found matches the total number provided then we were successful if(numFound == daPlugins.length) { pluginFound = true; // if we've found the plugin, we can stop looking through at the rest of the plugins break; } } } return pluginFound;} // detectPlugin///////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -