Example #1
0
 /**
  * fix_js_WriteToInstructions
  *
  * @param xxx $str (passed by reference)
  * @param xxx $start
  * @param xxx $length
  */
 function fix_js_WriteToInstructions(&$str, $start, $length)
 {
     $substr = substr($str, $start, $length);
     $search = "/(\\s*)document\\.getElementById\\('InstructionsDiv'\\)\\.innerHTML = Feedback;/";
     $replace = '$1' . "var AllDone = true;" . '$1' . "for (var QNum=0; QNum<State.length; QNum++){" . '$1' . "\tif (State[QNum]){" . '$1' . "\t\tif (State[QNum][0] < 0){" . '$1' . "\t\t\tAllDone = false;" . '$1' . "\t\t}" . '$1' . "\t}" . '$1' . "}" . '$1' . "if (AllDone) {" . '$1' . "\tvar obj = document.getElementById('InstructionsDiv');" . '$1' . "\tif (obj) {" . '$1' . "\t\tobj.innerHTML = Feedback;" . '$1' . "\t\tobj.style.display = '';" . '$1' . "\t}" . '$1' . "\tFinished = true;" . '$1' . "\tShowMessage(Feedback);" . '$1' . "}";
     $substr = preg_replace($search, $replace, $substr, 1);
     parent::fix_js_WriteToInstructions($substr, 0, strlen($substr));
     $str = substr_replace($str, $substr, $start, $length);
 }
Example #2
0
 /**
  * expand_HeaderCode
  *
  * @return xxx
  */
 function expand_HeaderCode()
 {
     $vars = array('minimumScore' => 0, 'maximumWrong' => 0, 'maximumTriesPerQuestion' => 0, 'neutralProgressBar' => 0);
     $headercode = parent::expand_HeaderCode();
     if ($headercode = $this->hotpot->source->single_line($headercode)) {
         $search = '/\\s*(?:var\\s+)?(\\w+)\\s*=\\s*(\\d+)(?:\\s*;)?/s';
         if (preg_match_all($search, $headercode, $matches, PREG_OFFSET_CAPTURE)) {
             $i_max = count($matches[0]) - 1;
             for ($i = $i_max; $i >= 0; $i--) {
                 list($match, $start) = $matches[0][$i];
                 if (array_key_exists($matches[1][$i][0], $vars)) {
                     $vars[$matches[1][$i][0]] = intval($matches[2][$i][0]);
                     $headercode = substr_replace($headercode, '', $start, strlen($match));
                 }
             }
         }
     }
     $search = array('/(?:\\s*\\/\\/?)\\s*<!\\[CDATA(?:\\s*\\/\\/)?\\s*\\]\\]>/is', '/(?:\\s*\\/\\/)?\\s*<!--(?:\\s*\\/\\/)?\\s*-->/s', '/\\s*<script type="text\\/javascript">\\s*<\\/script>/is');
     $headercode = preg_replace($search, '', $headercode);
     if ($headercode = trim($headercode)) {
         $headercode .= "\n";
     }
     $headercode .= '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n\n";
     foreach ($vars as $name => $value) {
         $headercode .= "    var {$name} = {$value};\n";
     }
     $headercode .= '//]]>' . "\n\n" . '</script>' . "\n";
     $headercode = '' . '<style type="text/css">' . "\n" . 'li.QuizQuestion div.JumbledItems {' . "\n" . '	margin-bottom: 1.0em;' . "\n" . '	padding-right: 8px;' . "\n" . '}' . "\n" . 'li.QuizQuestion div.JumbledItems span.JumbledItem {' . "\n" . '	padding: 2px 6px;' . "\n" . '	margin: 0px 8px;' . "\n" . '	border: 2px solid #ff9999;' . "\n" . '	background-color: #fff9f9;' . "\n" . '}' . "\n" . 'li.QuizQuestion span.JumbledItemsPrefix {' . "\n" . '	font-size: 1.1em;' . "\n" . '}' . "\n" . 'li.QuizQuestion span.DropArea {' . "\n" . '	padding: 2px 8px;' . "\n" . '	border: 2px solid #99ff99;' . "\n" . '	background-color: #f9fff9;' . "\n" . '}' . "\n" . 'li.QuizQuestion span.DropArea span.JumbledItem {' . "\n" . '	padding: 0px 4px;' . "\n" . '}' . "\n" . 'li.QuizQuestion span.JumbledItemsSuffix {' . "\n" . '	font-size: 1.1em;' . "\n" . '}' . "\n" . '</style>' . "\n" . $headercode;
     return $headercode;
 }