コード例 #1
0
ファイル: renderer.php プロジェクト: OctaveBabel/moodle-itop
 /**
  * fix_bodycontent
  *
  * @return xxx
  */
 function fix_bodycontent()
 {
     parent::fix_bodycontent_DragAndDrop();
     $search = 'onclick="location.reload()"';
     $replace = 'onclick="hotpot_jmix_restart()"';
     $this->bodycontent = str_replace($search, $replace, $this->bodycontent);
     $this->bodycontent .= "\n" . '<script type="text/javascript">' . "\n" . "//<![CDATA[\n" . "function GetLastCard(){\n" . "\tvar LastLine = -1;\n" . "\tvar Lines = new Array();\n" . "\tfor (var Lines_i=0; Lines_i<L.length; Lines_i++){\n" . "\t\tvar LineT = L[Lines_i].GetT() - 4;\n" . "\t\tvar LineB = L[Lines_i].GetB() + 4;\n" . "\t\tfor (var Cards_i=0; Cards_i<Cds.length; Cards_i++){\n" . "\t\t\tvar CardT = Cds[Cards_i].GetT();\n" . "\t\t\tvar CardB = Cds[Cards_i].GetB();\n" . "\t\t\tif (CardT >= LineT && CardB <= LineB) {\n" . "\t\t\t\tif (Lines_i > LastLine) {\n" . "\t\t\t\t\tLines[Lines_i] = new Array();\n" . "\t\t\t\t\tLastLine = Lines_i;\n" . "\t\t\t\t}\n" . "\t\t\t\tLines[Lines_i][Lines[Lines_i].length] = Cds[Cards_i];\n" . "\t\t\t}\n" . "\t\t}\n" . "\t}\n" . "\tvar LastCard = null;\n" . "\tif (LastLine >= 0) {\n" . "\t\tfor (var i=0; i<Lines[LastLine].length; i++){\n" . "\t\t\tif (LastCard==null || LastCard.GetL() < Lines[LastLine][i].GetL()) {\n" . "\t\t\t\tLastCard = Lines[LastLine][i];\n" . "\t\t\t}\n" . "\t\t}\n" . "\t}\n" . "\treturn LastCard;\n" . "}\n" . "function GetIndexByProperty(array, property, value, i_min) {\n" . "\tif (typeof(i_min)=='undefined') {\n" . "\t\ti_min = 0;\n" . "\t} else {\n" . "\t\ti_min = i_min + 1;\n" . "\t}\n" . "\tvar i_max = array.length;\n" . "\tfor (var i=i_min; i<i_max; i++) {\n" . "\t\tif (typeof(array[i][property])=='string' && typeof(value)=='string') {\n" . "\t\t\tvar len = Math.min(value.length, array[i][property].length);\n" . "\t\t\tif (len && value.substr(0, len)==array[i][property].substr(0, len)) {\n" . "\t\t\t\treturn i;\n" . "\t\t\t}\n" . "\t\t} else if (array[i][property]==value) {\n" . "\t\t\treturn i;\n" . "\t\t}\n" . "\t}\n" . "\treturn i_max;\n" . "}\n" . "function hotpot_jmix_get_unicode(e) {\n" . "\tif (typeof(e)=='undefined' && window.event) {\n" . "\t\te = window.event;\n" . "\t}\n" . "\tvar unicode = 0;\n" . "\tif (e) {\n" . "\t\tif (e.altKey || e.ctrlKey) {\n" . "\t\t\tunicode = 0;\n" . "\t\t} else if (e.charCode) {\n" . "\t\t\tunicode = e.charCode;\n" . "\t\t} else if (e.keyCode) {\n" . "\t\t\tunicode = e.keyCode;\n" . "\t\t}\n" . "\t}\n" . "\treturn unicode;\n" . "}\n" . "function hotpot_jmix_onkeypress(e) {\n" . "\tvar unicode = hotpot_jmix_get_unicode(e);\n" . "\tif (unicode) {\n" . "\t\tvar char = String.fromCharCode(unicode);\n" . "\t\tvar LastLine_Bottom = L[L.length - 1].GetB();\n" . "\t\tvar Segment_i = GetIndexByProperty(Segments, 0, char);\n" . "\t\tvar ThisCard_i = GetIndexByProperty(Cds, 'index', Segment_i);\n" . "\t\tvar found = false;\n" . "\t\twhile (true) {\n" . "\t\t\tif (Segment_i >= Segments.length) {\n" . "\t\t\t\tbreak;\n" . "\t\t\t}\n" . "\t\t\tif (ThisCard_i >= Cds.length) {\n" . "\t\t\t\tbreak;\n" . "\t\t\t}\n" . "\t\t\tif (Cds[ThisCard_i].GetT() > LastLine_Bottom) {\n" . "\t\t\t\tfound = true;\n" . "\t\t\t\tbreak;\n" . "\t\t\t}\n" . "\t\t\tSegment_i = GetIndexByProperty(Segments, 0, char, Segment_i);\n" . "\t\t\tThisCard_i = GetIndexByProperty(Cds, 'index', Segment_i);\n" . "\t\t}\n" . "\t\tif (found) {\n" . "\t\t\tvar LastCard = GetLastCard();\n" . "\t\t\tif (LastCard) {\n" . "\t\t\t\tvar l = LastCard.GetR() + 4;\n" . "\t\t\t\tif (window.hotpot_jmix_whitespace) {\n" . "\t\t\t\t\tl += LastCard.GetW();\n" . "\t\t\t\t}\n" . "\t\t\t\tvar t = LastCard.GetT();\n" . "\t\t\t} else {\n" . "\t\t\t\tvar l = Cds[0].HomeL;\n" . "\t\t\t\tvar t = L[0].GetT();\n" . "\t\t\t}\n" . "\t\t\tCds[ThisCard_i].SetL(l);\n" . "\t\t\tCds[ThisCard_i].SetT(t);\n" . "\t\t\twindow.hotpot_jmix_whitespace = false;\n" . "\t\t\twindow.hotpot_jmix_checkresults = true;\n" . "\t\t\t// adjust css top of ThisCard in standard HP way (required for Mac FF)\n" . "\t\t\tCurrDrag = ThisCard_i;" . "\t\t\tonEndDrag();" . "\t\t\tCurrDrag = -1;" . "\t\t\t// all done\n" . "\t\t\treturn false;\n" . "\t\t}\n" . "\t\t// 10=Enter, 13=Return\n" . "\t\tif (unicode==10 || unicode==13) {\n" . "\t\t\twindow.hotpot_jmix_whitespace = false;\n" . "\t\t\tif (window.hotpot_jmix_checkresults) {\n" . "\t\t\t\tCheckResults(0);\n" . "\t\t\t\twindow.hotpot_jmix_checkresults = false;\n" . "\t\t\t\treturn false;\n" . "\t\t\t}\n" . "\t\t}\n" . "\t\t// 32=Space\n" . "\t\tif (unicode==32) {\n" . "\t\t\twindow.hotpot_jmix_whitespace = true;\n" . "\t\t\twindow.hotpot_jmix_checkresults = true;\n" . "\t\t\treturn false;\n" . "\t\t}\n" . "\t}\n" . "\treturn true;\n" . "}\n" . "document.onkeypress = hotpot_jmix_onkeypress;\n" . "function hotpot_jmix_onkeydown(e) {\n" . "\tvar unicode = hotpot_jmix_get_unicode(e);\n" . "\tif (unicode) {\n" . "\t\t// 8=Backspace, 46=Delete\n" . "\t\tif (unicode==8 || unicode==46) {\n" . "\t\t\tvar LastCard = GetLastCard();\n" . "\t\t\tif (LastCard) {\n" . "\t\t\t\tLastCard.GoHome();\n" . "\t\t\t}\n" . "\t\t\twindow.hotpot_jmix_whitespace = false;\n" . "\t\t\twindow.hotpot_jmix_checkresults = true;\n" . "\t\t\treturn false;\n" . "\t\t}\n" . "\t\t// 27=Esc\n" . "\t\tif (unicode==27) {\n" . "\t\t\thotpot_jmix_restart();\n" . "\t\t\treturn false;\n" . "\t\t}\n" . "\t}\n" . "\treturn true;\n" . "}\n" . "document.onkeydown = hotpot_jmix_onkeydown;\n" . "function hotpot_jmix_restart() {\n" . "\tfor (var i=0; i<Cds.length; i++){\n" . "\t\tCds[i].GoHome();\n" . "\t}\n" . "\twindow.hotpot_jmix_whitespace = false;\n" . "\twindow.hotpot_jmix_checkresults = true;\n" . "\treturn true;\n" . "}\n" . "//]]>\n" . '</script>';
 }
コード例 #2
0
 /**
  * expand_SegmentArray
  *
  * @return xxx
  */
 function expand_SegmentArray($more_values = array())
 {
     // user-string-3: (optional)
     //   distractor words: words, delimited, by, commas, like, this
     //   phrases: (one phrase) [another phrase] {yet another phrase}
     if ($value = $this->expand_UserDefined3()) {
         if (preg_match('/^(\\()|(\\[)|(\\{).*(?(1)\\)|(?(2)\\]|(?(3)\\})))$/', $value)) {
             $search = '/\\s*\\' . substr($value, -1) . '\\s*\\' . substr($value, 0, 1) . '\\s*/';
             $more_values = preg_split($search, substr($value, 1, -1));
         } else {
             $more_values = preg_split('/\\s*,\\s*/', trim($value));
         }
     } else {
         $more_values = array();
     }
     return parent::expand_SegmentArray($more_values);
 }