/** * fix_js_StartUp * * @param xxx $str (passed by reference) * @param xxx $start * @param xxx $length */ function fix_js_StartUp(&$str, $start, $length) { $substr = substr($str, $start, $length); $search = '/(\\s*)strInstructions = [^;]*;/'; $replace = '$1' . "var obj = document.getElementById('Instructions');" . '$1' . "if (obj==null || obj.innerHTML=='') {" . '$1' . "\tvar obj = document.getElementById('InstructionsDiv');" . '$1' . "\tif (obj) {" . '$1' . "\t\tobj.style.display = 'none';" . '$1' . "\t}" . '$1' . "}"; $substr = preg_replace($search, $replace, $substr, 1); parent::fix_js_StartUp($substr, 0, strlen($substr)); // append the PlaySound() and StopSound() functions if ($pos = strrpos($substr, '}')) { $append = "\n" . "function PlaySound(i, count) {\n" . ' // li (id="Q_99") -> p (class="questionText") -> span (class="mediaplugin_mp3") -> object' . "\n" . "\tvar li = QArray[i];\n" . "\ttry {\n" . "\t\tvar SoundLoaded = li.childNodes[0].childNodes[0].childNodes[0].isSoundLoadedFromJS();\n" . "\t} catch (err) {\n" . "\t\tvar SoundLoaded = false;\n" . "\t}\n" . "\tif (SoundLoaded) {\n" . "\t\ttry {\n" . "\t\t\tli.childNodes[0].childNodes[0].childNodes[0].playSoundFromJS();\n" . "\t\t\tvar SoundPlayed = true;\n" . "\t\t} catch (err) {\n" . "\t\t\tvar SoundPlayed = false;\n" . "\t\t}\n" . "\t}\n" . "\tif (SoundLoaded && SoundPlayed) {\n" . "\t\t// sound was successfully played\n" . "\t} else {\n" . "\t\t// sound could not be loaded or played\n" . "\t\tif (count<=100) {\n" . "\t\t\t// try again in 1/10th of a second\n" . "\t\t\tsetTimeout('PlaySound('+i+','+(count+1)+')', 100);\n" . "\t\t}\n" . "\t}\n" . "}\n" . "function StopSound(i) {\n" . ' // li (id="Q_99") -> p (class="questionText") -> span (class="mediaplugin_mp3") -> object' . "\n" . "\tvar li = QArray[i];\n" . "\ttry {\n" . "\t\tvar SoundLoaded = li.childNodes[0].childNodes[0].childNodes[0].isSoundLoadedFromJS();\n" . "\t} catch (err) {\n" . "\t\tvar SoundLoaded = false;\n" . "\t}\n" . "\tif (SoundLoaded) {\n" . "\t\ttry {\n" . "\t\t\tli.childNodes[0].childNodes[0].childNodes[0].stopSoundFromJS();\n" . "\t\t\tvar SoundStopped = true;\n" . "\t\t} catch (err) {\n" . "\t\t\tvar SoundStopped = false;\n" . "\t\t}\n" . "\t}\n" . "}"; $substr = substr_replace($substr, $append, $pos + 1, 0); } $str = substr_replace($str, $substr, $start, $length); }
/** * fix_js_StartUp * * @param xxx $str (passed by reference) * @param xxx $start * @param xxx $length */ function fix_js_StartUp(&$str, $start, $length) { $substr = substr($str, $start, $length); // hide instructions, if they are not required $search = '/(\\s*)strInstructions = document.getElementById[^;]*;/s'; $replace = '' . '\\1' . "var obj = document.getElementById('Instructions');" . '\\1' . "if (obj==null || obj.innerHTML=='') {" . '\\1' . "\tvar obj = document.getElementById('InstructionsDiv');" . '\\1' . "\tif (obj) {" . '\\1' . "\t\tobj.style.display = 'none';" . '\\1' . "\t}" . '\\1' . "}"; //$substr = preg_replace($search, $replace, $substr, 1); $insert = ''; if ($this->expand_UserDefined1()) { $insert .= "\tAA_SetProgressBar();\n"; } if ($this->expand_UserDefined2()) { $insert .= "\tsetTimeout('AA_PlaySound(0,0)', 500);"; } if ($insert) { $pos = strrpos($substr, '}'); $substr = substr_replace($substr, $insert, $pos, 0); } // call the fix_js_StartUp() method on the parent object parent::fix_js_StartUp($substr, 0, strlen($substr)); $str = substr_replace($str, $substr, $start, $length); }