tasklib_book.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. //播放音频图片地址
  2. var PicInfo = {
  3. answerPointImgUrl: "file:///android_asset/js/update-answer.png", //../Images/update-answer.png
  4. yaoshiShowImgUrl: "file:///android_asset/js/yaoshi-show.png",
  5. yaoshiHideImgUrl: "file:///android_asset/js/yaoshi-hide.png",
  6. recordPlayImgUrl: "file:///android_asset/js/play.png",
  7. recordPauseImgUrl: "file:///android_asset/js/pause.png",
  8. audioPlayImgUrl: "file:///android_asset/js/dynaiselaba.gif",
  9. audioPauseImgUrl: "file:///android_asset/js/dynaiselaba.png"
  10. }
  11. //显示、隐藏答案
  12. function showHideAnswer(flag) {
  13. if (flag) {
  14. //$(".underlineContent").show();
  15. $(".underlineContent").css("color", "#92D050");
  16. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  17. }
  18. else {
  19. //$(".underlineContent").hide();
  20. $(".underlineContent").css("color", "#ffffff");
  21. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  22. }
  23. }
  24. ///显示、隐藏钥匙及答案 isShowYX:显示和隐藏钥匙,isShowAS:显示和隐藏答案
  25. function showHideAnswerEx(isShowYX, isShowAS) {
  26. if (isShowYX) {
  27. $(".yaoshi").show();
  28. }
  29. else {
  30. $(".yaoshi").hide();
  31. }
  32. if (isShowAS) {
  33. $.each($(".underlineContent"), function (index, item) {
  34. //$(item).html($(item).attr("data-text"));
  35. if (!$(item).hasClass("no-answer")) {
  36. $(item).css("color", "#92D050");
  37. }
  38. else {
  39. $(item).css("color", "#989898");
  40. }
  41. $(item).find(".wordStyle").css("color", "#db5d00");
  42. $(item).find(".phraseStyle").css("background-color", "#f2db8b");
  43. });
  44. $(".yaoshi").attr("data-status", "1");
  45. $(".yaoshi").attr("src", PicInfo.yaoshiShowImgUrl);
  46. }
  47. else {
  48. $.each($(".underlineContent,.underlineContent.no-answer"), function (index, item) {
  49. $(item).css("color", "#ffffff");
  50. $(item).find(".wordStyle").css("color", "#ffffff");
  51. $(item).find(".phraseStyle").css("background-color", "#ffffff");
  52. });
  53. $(".yaoshi").attr("data-status", "0");
  54. $(".yaoshi").attr("src", PicInfo.yaoshiHideImgUrl);
  55. }
  56. }
  57. //页面加载完,原文 绑定事件
  58. function bindEventTeaOrignalYS() {
  59. var bodyWidth = $(document.body).width();
  60. //显示/隐藏习题答案
  61. $(".yaoshi").on("click", function () {
  62. var curDisplay = $(this).nextUntil(".yaoshi").find(".underlineContent").eq(0).css("display");
  63. if (curDisplay == "undefined" || curDisplay == undefined) return;
  64. if (curDisplay == "none" || $(this).attr("data-status") == "0") {
  65. $(this).attr("data-status", "1");
  66. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  67. //$(this).nextUntil(".yaoshi").find(".underlineContent").show();
  68. //$(this).nextUntil(".yaoshi").find(".underlineContent").css("color", "#92D050");
  69. $.each($(this).nextUntil(".yaoshi").find(".underlineContent"), function (index, item) {
  70. if (!$(item).hasClass("no-answer")) {
  71. $(item).css("color", "#92D050");
  72. }
  73. else {
  74. $(item).css("color", "#989898");
  75. }
  76. $(item).find(".wordStyle").css("color", "#db5d00");
  77. $(item).find(".phraseStyle").css("background-color", "#f2db8b");
  78. });
  79. //不再存在已隐藏的钥匙,移动端回调
  80. if ($(".yaoshi[data-status='0']").length == 0) {
  81. //添加回调
  82. console.log("全部显示了");
  83. }
  84. } else {
  85. $(this).attr("data-status", "0");
  86. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  87. //$(this).nextUntil(".yaoshi").find(".underlineContent").hide();
  88. //$(this).nextUntil(".yaoshi").find(".underlineContent").css("color", "#ffffff");
  89. $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  90. $(item).css("color", "#ffffff");
  91. $(item).find(".wordStyle").css("color", "#ffffff");
  92. $(item).find(".phraseStyle").css("background-color", "#ffffff");
  93. });
  94. //添加回调
  95. onClickKeyHide();
  96. }
  97. });
  98. //处理答题点
  99. $.each($(".underlineContent"), function (index, item) {
  100. $(item).attr("data-text", $(item).html());
  101. });
  102. //给音频绑定一个ID
  103. $.each($(".audioImg"), function (index, item) {
  104. $(item).attr("audiourl", "");
  105. $(item).attr('audio-id', index);
  106. });
  107. //给视频图标处理
  108. $.each($(".videoImg"), function (index, item) {
  109. $(item).attr("audiourl", "");
  110. });
  111. //给口语图标处理
  112. $.each($(".oralLanguageImg"), function (index, item) {
  113. $(item).attr("audiourl", "");
  114. });
  115. //去除多余的U空标签
  116. $.each($("u"), function (index, item) {
  117. var text = $(item).text();
  118. text = text.replace(/\s+/g, "");
  119. if (text == "") {
  120. $(item).remove();
  121. }
  122. });
  123. //处理暂无参考答案
  124. $.each($(".yaoshi"), function (index, item) {
  125. var prev = $(item).nextUntil(".yaoshi").find(".underlineContent");
  126. if (prev.length == 0) {
  127. var spanHtml = document.createElement("span");
  128. //添加子节点
  129. var uHtml = document.createElement("u");
  130. uHtml.className = "underlineContent no-answer";
  131. uHtml.innerText = "暂无参考答案";
  132. uHtml.setAttribute("data-text", uHtml.innerText);
  133. $(spanHtml).html(uHtml.outerHTML);
  134. $(item).after(spanHtml);
  135. }
  136. });
  137. //处理表格宽度
  138. $.each($(".wordTable"), function (index, item) {
  139. $(item).css("width", bodyWidth + "px");
  140. });
  141. //点击喇叭事件,音频播放
  142. $(".audioImg").on("click", function () {
  143. audioPlayClick(this);
  144. });
  145. //点击播放事件,视频播放
  146. $(".videoImg").on("click", function () {
  147. var curHtml = $(this).parent().find(".videoUrl").html();
  148. var curAlt = $(this).attr("alt");//播放视频地址
  149. playVisiableAudioCallBack(2, $(this).attr("alt"));
  150. });
  151. //处理表格样式
  152. $("td").attr("style", "");
  153. }
  154. //页面加载完,课件 绑定事件
  155. function bindEventYS() {
  156. var bodyWidth = $(document.body).width();
  157. //给每个答题点加上ID
  158. $.each($(".yaoshi"), function (index, item) {
  159. $(item).attr('answer-id', index);
  160. });
  161. //给音频绑定一个ID
  162. $.each($(".audioImg"), function (index, item) {
  163. $(item).attr("audiourl", "");
  164. $(item).attr('audio-id', index);
  165. });
  166. //给视频图标处理
  167. $.each($(".videoImg"), function (index, item) {
  168. $(item).attr("audiourl", "");
  169. });
  170. //给口语图标处理
  171. $.each($(".oralLanguageImg"), function (index, item) {
  172. $(item).attr("audiourl", "");
  173. });
  174. //去除多余的U空标签
  175. $.each($("u"), function (index, item) {
  176. var text = $(item).text();
  177. text = text.replace(/\s+/g, "");
  178. if (text == "") {
  179. $(item).remove();
  180. }
  181. });
  182. //处理暂无参考答案
  183. $.each($(".yaoshi"), function (index, item) {
  184. var prev = $(item).nextAll(".underlineContent");
  185. if (prev.length == 0) {
  186. var uHtml = document.createElement("u");
  187. uHtml.className = "underlineContent no-answer";
  188. uHtml.innerText = "暂无参考答案";
  189. uHtml.setAttribute("data-text", uHtml.innerText);
  190. $(item).after(uHtml);
  191. }
  192. });
  193. //处理表格宽度
  194. $.each($(".wordTable"), function (index, item) {
  195. $(item).css("width", bodyWidth + "px");
  196. });
  197. //显示/隐藏习题答案
  198. $(".yaoshi").on("click", function () {
  199. if ($(this).attr("data-status") == "0") {
  200. $(this).attr("data-status", "1");
  201. $(this).attr("src", PicInfo.yaoshiShowImgUrl);
  202. //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#92D050");
  203. $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  204. if (!$(item).hasClass("no-answer")) {
  205. $(item).css("color", "#92D050");
  206. }
  207. else {
  208. $(item).css("color", "#989898");
  209. }
  210. $(item).find(".wordStyle").css("color", "#db5d00");
  211. $(item).find(".phraseStyle").css("background-color", "#f2db8b");
  212. });
  213. //不再存在已隐藏的钥匙,移动端回调
  214. if ($(".yaoshi[data-status='0']").length == 0) {
  215. //添加回调
  216. console.log("全部显示了");
  217. }
  218. }
  219. else {
  220. $(this).attr("data-status", "0");
  221. $(this).attr("src", PicInfo.yaoshiHideImgUrl);
  222. //$(this).nextUntil(".yaoshi").filter(".underlineContent").css("color", "#ffffff");
  223. $.each($(this).nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  224. $(item).css("color", "#ffffff");
  225. $(item).find(".wordStyle").css("color", "#ffffff");
  226. $(item).find(".phraseStyle").css("background-color", "#ffffff");
  227. });
  228. //添加回调
  229. onClickKeyHide();
  230. }
  231. });
  232. //点击喇叭事件,音频播放
  233. $(".audioImg").on("click", function () {
  234. audioPlayClick(this);
  235. });
  236. //点击播放事件,视频播放
  237. $(".videoImg").on("click", function () {
  238. $(this).attr("audiourl", "");
  239. var curHtml = $(this).parent().find(".videoUrl").html();
  240. var curAlt = $(this).attr("alt");//播放视频地址
  241. playVisiableAudioCallBack(2, $(this).attr("alt"));
  242. });
  243. //处理表格样式
  244. $("td").attr("style", "");
  245. }
  246. //学生端 处理作答区域
  247. var answerData = new Array();
  248. function handleAnswerRange() {
  249. //规范文本格式
  250. var answerId = "";
  251. var tempJson = new Array();
  252. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underline"), function (index, item) {
  253. tempId = $(item).prevAll(".yaoshi").attr("answer-id");
  254. //记录上一次的ID
  255. if (tempId == undefined) {
  256. tempId = answerId;
  257. }
  258. else {
  259. answerId = tempId;
  260. }
  261. var prev = $(item).prev();
  262. if ((prev.length == 0 || $(prev).attr("class") != "tag-span") && $(prev).attr("class") != "underlineContent") {
  263. if ($("span[answer-id='" + tempId + "']").length == 0) {
  264. $(item).prop("outerHTML", "<span answer-id='" + tempId + "' class='tag-span' answer-isky='0'>_</span>");
  265. }
  266. }
  267. $(item).remove();
  268. });
  269. //提取参考答案并规范文本格式
  270. answerId = "";
  271. $.each($(".yaoshi").nextUntil(".yaoshi").filter(".underlineContent"), function (index, item) {
  272. var info = new Object();
  273. info.Id = $(item).prevAll(".yaoshi").attr("answer-id");
  274. //记录上一次的ID
  275. if (info.Id == undefined) {
  276. info.Id = answerId;
  277. }
  278. else {
  279. answerId = info.Id;
  280. }
  281. info.AnsText = $(item).text();
  282. tempJson.push(info);
  283. var prev = $(item).prev();
  284. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  285. //替换答案
  286. $(item).prop("outerHTML", "<span answer-id='" + info.Id + "' class='tag-span' answer-isky='0'>_</span>");
  287. }
  288. else {
  289. $(item).remove();
  290. }
  291. });
  292. //补充空钥匙的处理
  293. $.each($(".yaoshi"), function (index, item) {
  294. var Id = $(item).attr("answer-id");
  295. var prev = $(item).next();
  296. if (prev.length == 0 || $(prev).attr("class") != "tag-span") {
  297. if ($("span[answer-id='" + Id + "']").length == 0) {
  298. var uHtml = document.createElement("span");
  299. uHtml.className = "tag-span";
  300. uHtml.innerText = "_";
  301. uHtml.setAttribute("answer-id", Id);
  302. $(item).after(uHtml);
  303. }
  304. }
  305. });
  306. //处理口语试题
  307. $.each($(".oralLanguage").nextUntil(".oralLanguageDone"), function (num, part) {
  308. if (part.tagName != "p") {
  309. $.each($(part).find(".tag-span"), function (index, item) {
  310. $(item).attr("answer-isky", "1");
  311. });
  312. }
  313. else {
  314. if ($(part).hasClass("underlinePart")) {
  315. $.each($(part).find(".tag-span"), function (index, item) {
  316. $(item).attr("answer-isky", "1");
  317. });
  318. }
  319. }
  320. });
  321. //合并参考答案数据
  322. var tempid = "";
  323. var temptext = "";
  324. for (var i = 0; i < tempJson.length; i++) {
  325. if (tempid == tempJson[i].Id) {
  326. temptext = temptext + tempJson[i].AnsText;
  327. }
  328. else {
  329. if (tempid != "") {
  330. var info = new Object();
  331. info.Id = tempid;
  332. info.AnsText = temptext;
  333. answerData.push(info);
  334. //重置
  335. tempid = "";
  336. temptext = "";
  337. }
  338. tempid = tempJson[i].Id;
  339. temptext = tempJson[i].AnsText;
  340. //最后一个存入
  341. if (i == tempJson.length - 1) {
  342. var info = new Object();
  343. info.Id = tempid;
  344. info.AnsText = temptext;
  345. answerData.push(info);
  346. }
  347. }
  348. }
  349. //补全答题点
  350. var Num = 0;
  351. if (answerData.length > 0) {
  352. //Num = Number.parseInt(answerData[answerData.length - 1].Id);
  353. Num = Number.parseInt($(".yaoshi:last").attr('answer-id'));
  354. for (var i = 0; i < Num + 1; i++) {
  355. if (i < answerData.length) {
  356. var index = Number(answerData[i].Id) - i;
  357. for (var j = 0; j < index; j++) {
  358. var info = new Object();
  359. info.Id = (i + j).toString();
  360. info.AnsText = "";
  361. answerData.splice(i, 0, info);
  362. }
  363. }
  364. else {
  365. var info = new Object();
  366. info.Id = (i).toString();
  367. info.AnsText = "";
  368. answerData.splice(i, 0, info);
  369. }
  370. }
  371. }
  372. //添加答题点的点击UI及交互
  373. $.each($(".tag-span"), function (index, item) {
  374. var answerText = "";
  375. var isky = $(item).attr('answer-isky');
  376. var answerid = $(item).attr('answer-id');
  377. for (var i = 0; i < answerData.length; i++) {
  378. if (answerid == answerData[i].Id) {
  379. answerText = answerData[i].AnsText;
  380. break;
  381. }
  382. }
  383. $(item).prop("outerHTML", "<div class='answer-range' answer-id='" + answerid + "' answer-anstext='" + answerText + "' answer-isky='" + isky + "'><img src='" + PicInfo.answerPointImgUrl + "'/><span class='answertext'>答题点</span></div>");
  384. //删除钥匙节点
  385. var prev = $("img[answer-id='" + answerid + "']");
  386. if (prev.length > 0) {
  387. $(prev).remove();
  388. }
  389. });
  390. //添加点击事件
  391. $(".answer-range").on("click", function () {
  392. var curObj = new Object();
  393. curObj.Id = $(this).attr("answer-id");//答题点ID
  394. curObj.IsKY = $(this).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  395. curObj.Text = $(this).attr("answer-text");//用户作答内容
  396. curObj.Score = $(this).attr("answer-score");//作答评分
  397. curObj.AnsText = $(this).attr("answer-anstext");//参考答案
  398. curObj.Comment = $(this).attr("answer-comment");//评语
  399. $(".answer-range").removeClass("select-answer");
  400. $(this).addClass("select-answer");
  401. //已作答,弹出作答答案
  402. if ($(this).data("ans-status") == "1") {
  403. //移动端添加外部处理
  404. onClickAnswerPoint(JSON.stringify(curObj));
  405. }
  406. else {
  407. //移动端添加外部处理,弹出作答操作
  408. onClickAnswerPoint(JSON.stringify(curObj));
  409. }
  410. });
  411. //去除多余的空格横线
  412. $.each($(".underline"), function (index, item) {
  413. var text = $(item).text();
  414. text = text.replace(/\s+/g, "");
  415. if (text == "") {
  416. $(item).remove();
  417. }
  418. });
  419. return answerData;
  420. }
  421. //接收学生的作答
  422. function reviewAnswer(answerJson) {
  423. if (answerJson != "" && answerJson) {
  424. var answerObj = JSON.parse(answerJson);
  425. var selectElement = $(".answer-range[answer-id='" + answerObj.Id + "']");
  426. var audioElement = $(selectElement).children("img").eq(0);
  427. answerObj.IsKY = $(selectElement).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  428. //有内容时,要动态处理单词长度
  429. if (answerObj.Text != "") {
  430. $(selectElement).addClass("break-word");
  431. }
  432. else {
  433. $(selectElement).removeClass("break-word");
  434. }
  435. //是否是音频作答
  436. if ((answerObj.Type == 3 || answerObj.Type == 4) && answerObj.AudioUrl != "") {
  437. $(selectElement).attr("answer-text", answerObj.Text);//填充作答内容
  438. answerObj.Text = answerObj.Text == "" ? "作答音频[" + answerObj.AudioLength + "s]" : "作答音频[" + answerObj.AudioLength + "s]" + "(" + answerObj.Text + ")";
  439. $(selectElement).children("span").text(answerObj.Text);
  440. //是否之前存在作答音频
  441. $(selectElement).attr("play-status", "0");
  442. $(audioElement).attr("src", PicInfo.recordPlayImgUrl);
  443. var curDisplay = $(audioElement).css("display");
  444. if (curDisplay == "none") {
  445. $(audioElement).show();
  446. }
  447. $(selectElement).attr("answer-url", answerObj.AudioUrl);
  448. //独立绑定事件
  449. $(audioElement).on("click", function () {
  450. recordAudioClick(this, answerObj.Id, answerObj.AudioUrl);
  451. });
  452. $(selectElement).children("span").on("click", function () {
  453. $(".answer-range").removeClass("select-answer");
  454. $(item).addClass("select-answer");
  455. onClickAnswerPoint(JSON.stringify(answerObj));
  456. });
  457. }
  458. else {
  459. $(selectElement).attr("answer-text", answerObj.Text);//填充作答内容
  460. if (answerObj.Text == "") {
  461. answerObj.Text = "答题点";
  462. $(audioElement).show();
  463. $(audioElement).attr("src", PicInfo.answerPointImgUrl);
  464. }
  465. else {
  466. //之前作答存在音频,但是现在没有音频传入,要隐藏音频节点
  467. $(audioElement).hide();
  468. }
  469. $(selectElement).children("span").text(answerObj.Text);
  470. }
  471. }
  472. }
  473. //提交,获取所有作答答案及参考答案
  474. function getAllAnswer() {
  475. //处理作答
  476. $.each($(".answer-range"), function (index, item) {
  477. var mytext = $(item).children("span").text();
  478. if (mytext == "答题点") {
  479. mytext = "未作答";
  480. $(item).children("span").addClass("no-answer");
  481. $(item).children("img").hide();
  482. $(item).children("span").text(mytext);
  483. }
  484. });
  485. $(".answer-range").unbind('click');//取消点击绑定事件
  486. $(".answer-range>span").unbind('click');//取消点击绑定事件
  487. return answerData;
  488. }
  489. //回填所有答案,answerJson:所有作答及参考答案List,statusType:0-可作答,1-已提交,2-查看评阅
  490. function backupAllAnswer(answerJson, statusType) {
  491. if (answerJson != "" && answerJson) {
  492. var answerList = JSON.parse(answerJson);
  493. //answerList = JSON.parse(answerList);
  494. //获取Dom一个个回填
  495. $.each($(".answer-range"), function (index, item) {
  496. //提交直接还原作答现场
  497. var mytext = answerList[index].Text;//我的答案
  498. answerList[index].IsKY = $(item).attr("answer-isky");//是否是口语试题,0-不是口语题,1-是口语题
  499. //有内容时,要动态处理单词长度
  500. if (mytext != "") {
  501. $(item).addClass("break-word");
  502. }
  503. //添加音频控制
  504. var audioElement = $(item).children("img").eq(0);
  505. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  506. $(item).attr("answer-text", mytext);//填充作答内容
  507. mytext = mytext == "" ? "作答音频[" + answerList[index].AudioLength + "s]" : "作答音频[" + answerList[index].AudioLength + "s]" + "(" + mytext + ")";
  508. $(item).children("span").text(mytext);
  509. $(item).attr("play-status", "0");
  510. $(item).attr("answer-url", answerList[index].AudioUrl);
  511. $(audioElement).attr("src", PicInfo.recordPlayImgUrl);
  512. }
  513. //可作答状态,作答还原
  514. if (statusType == 0) {
  515. //已作答过,还原作答,增加作答后的UI节点
  516. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  517. //独立绑定事件
  518. $(item).children("img").on("click", function () {
  519. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  520. });
  521. $(item).children("span").on("click", function () {
  522. $(".answer-range").removeClass("select-answer");
  523. $(item).addClass("select-answer");
  524. onClickAnswerPoint(JSON.stringify(answerList[index]));
  525. });
  526. }
  527. else {
  528. $(item).attr("answer-text", mytext);//填充作答内容
  529. if (mytext == "") {
  530. mytext = "答题点";
  531. $(audioElement).attr("src", PicInfo.answerPointImgUrl);
  532. }
  533. else {
  534. //之前作答存在音频,但是现在没有音频传入,要隐藏音频节点
  535. $(audioElement).hide();
  536. }
  537. $(item).children("span").text(mytext);
  538. }
  539. }
  540. //已提交,作答还原
  541. if (statusType == 1) {
  542. //取消点击绑定事件
  543. $(item).unbind('click');
  544. //添加音频控制
  545. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  546. //独立绑定事件
  547. $(item).children("img").on("click", function () {
  548. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  549. });
  550. }
  551. else {
  552. $(item).attr("answer-text", mytext);//填充作答内容
  553. if (mytext == "") {
  554. mytext = "未作答";
  555. $(item).children("span").addClass("no-answer");
  556. }
  557. $(audioElement).hide();
  558. $(item).children("span").text(mytext);
  559. }
  560. }
  561. //已评阅,查看评阅详情
  562. if (statusType == 2) {
  563. //添加音频控制
  564. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  565. //独立绑定事件
  566. $(item).children("img").on("click", function () {
  567. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  568. });
  569. $(item).children("span").on("click", function () {
  570. $(".answer-range").removeClass("select-answer");
  571. $(item).addClass("select-answer");
  572. onClickAnswerPoint(JSON.stringify(answerList[index]));
  573. });
  574. }
  575. else {
  576. $(item).attr("answer-text", mytext);//填充作答内容
  577. if (mytext == "") {
  578. mytext = "未作答";
  579. $(item).children("span").addClass("no-answer");
  580. }
  581. $(audioElement).hide();
  582. $(item).children("span").text(mytext);
  583. }
  584. //评阅样式
  585. if (answerList[index].Score == 0 && answerList[index].Text != "") {
  586. $(item).children("span").addClass("bad-answer");
  587. }
  588. if (answerList[index].Score > 0) {
  589. $(item).children("span").addClass("good-answer");
  590. }
  591. }
  592. });
  593. }
  594. }
  595. //老师评阅学生作答
  596. function reviewStuAnswer(answerJson) {
  597. if (answerJson != "" && answerJson) {
  598. var answerObj = JSON.parse(answerJson);
  599. var selectElement = $(".answer-range[answer-id='" + answerObj.Id + "']");
  600. //$(selectElement).attr("answer-text", answerObj.Text);//用户作答内容
  601. $(selectElement).attr("answer-score", answerObj.Score);//作答评分
  602. $(selectElement).attr("answer-anstext ", answerObj.AnsText);//参考答案
  603. $(selectElement).attr("answer-comment", answerObj.Comment);//评语
  604. //评阅样式
  605. if (answerObj.Score == 0) {
  606. $(selectElement).children("span").removeClass("good-answer");
  607. $(selectElement).children("span").addClass("bad-answer");
  608. }
  609. if (answerObj.Score > 0) {
  610. $(selectElement).children("span").removeClass("bad-answer");
  611. $(selectElement).children("span").addClass("good-answer");
  612. }
  613. }
  614. }
  615. //回填所有评阅信息,answerJson:所有作答及参考答案评阅信息List
  616. function backupAllReview(answerJson) {
  617. if (answerJson != "" && answerJson) {
  618. var answerList = JSON.parse(answerJson);
  619. $.each($(".answer-range"), function (index, item) {
  620. //$(item).attr("answer-id", answerList[index].Id);//答题点ID
  621. //$(item).attr("answer-text", answerList[index].Text);//用户作答内容
  622. $(item).attr("answer-score", answerList[index].Score);//作答评分
  623. $(item).attr("answer-anstext ", answerList[index].AnsText);//参考答案
  624. $(item).attr("answer-comment", answerList[index].Comment);//评语
  625. //提交直接还原作答现场
  626. var mytext = answerList[index].Text;//我的答案
  627. var audioElement = $(item).children("img").eq(0);
  628. if ((answerList[index].Type == 3 || answerList[index].Type == 4) && answerList[index].AudioUrl != "") {
  629. $(item).attr("answer-text", mytext);//填充作答内容
  630. mytext = mytext == "" ? "作答音频[" + answerList[index].AudioLength + "s]" : "作答音频[" + answerList[index].AudioLength + "s]" + "(" + mytext + ")";
  631. $(item).children("span").text(mytext);
  632. $(item).attr("play-status", "0");
  633. $(item).attr("answer-url", answerList[index].AudioUrl);
  634. $(audioElement).attr("src", PicInfo.recordPlayImgUrl);
  635. //独立绑定事件
  636. $(item).children("img").on("click", function () {
  637. recordAudioClick(this, answerList[index].Id, answerList[index].AudioUrl);
  638. });
  639. $(item).children("span").on("click", function () {
  640. $(".answer-range").removeClass("select-answer");
  641. $(item).addClass("select-answer");
  642. onClickAnswerPoint(JSON.stringify(answerList[index]));//移动端的修改
  643. });
  644. }
  645. else {
  646. $(item).attr("answer-text", mytext);//填充作答内容
  647. if (mytext == "") {
  648. mytext = "未作答";
  649. $(item).children("span").addClass("no-answer");
  650. }
  651. $(audioElement).hide();
  652. $(item).children("span").text(mytext);
  653. }
  654. //评阅样式
  655. if (answerList[index].Score == 0) {
  656. $(item).children("span").addClass("bad-answer");
  657. }
  658. if (answerList[index].Score > 0) {
  659. $(item).children("span").addClass("good-answer");
  660. }
  661. });
  662. }
  663. }
  664. //处理播放录音,answerid:答题点ID,isPlay:是否播放(0-暂停,1-播放)
  665. function playRecordAudio(answerid, isPlay) {
  666. //获取其他正在播放的音频
  667. var playing = $(".answer-range[answer-id='" + answerid + "']");
  668. if (playing.length > 0) {
  669. if (isPlay == "1") {
  670. $(playing).attr("play-status", "1");
  671. $(playing).find("img").attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  672. }
  673. else {
  674. $(playing).attr("play-status", "0");
  675. $(playing).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  676. }
  677. }
  678. }
  679. //滚动到相应DIV
  680. function scrollAnswer(answerid) {
  681. //console.log(answerid);
  682. $(".answer-range").removeClass("select-answer");
  683. var ansDom = $(".answer-range[answer-id='" + answerid + "']");
  684. $(ansDom).addClass("select-answer");
  685. var scroll_offset = $(ansDom).offset(); //得到box这个div层的offset,包含两个值,top和left
  686. var offset_top = scroll_offset.top;
  687. if (offset_top > 150) {
  688. offset_top = offset_top - 200;
  689. }
  690. $("body,html").animate({
  691. scrollTop: offset_top //让body的scrollTop等于pos的top,就实现了滚动
  692. });
  693. }
  694. //暂停播放原文音频
  695. function pauseTextAudio(audioid) {
  696. //获取其他正在播放的音频
  697. var playing = $(".audioImg[audio-id='" + audioid + "']");
  698. if (playing.length > 0) {
  699. $(playing).attr("play-status", "0");
  700. $(playing).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  701. }
  702. }
  703. //原文音频播放按钮点击事件
  704. function audioPlayClick(myobj) {
  705. var curHtml = $(myobj).parent().find(".audioUrl").html();
  706. var curAlt = $(myobj).attr("alt");
  707. //处理当前按钮的状
  708. if ($(myobj).attr("play-status") == "1") {
  709. $(myobj).attr("play-status", "0");
  710. $(myobj).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  711. }
  712. else {
  713. //停止其他作答音频播放
  714. var isRecordPlaying = $(".answer-range[play-status='1']");
  715. if (isRecordPlaying.length > 0) {
  716. $(isRecordPlaying).attr("play-status", "0");
  717. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  718. }
  719. //停止其他原文音频播放
  720. var audioPlaying = $(".audioImg[play-status='1']");
  721. if (audioPlaying.length > 0) {
  722. $(audioPlaying).attr("play-status", "0");
  723. $(audioPlaying).attr("src", PicInfo.audioPauseImgUrl);//移动端要根据本地 喇叭 路径替换
  724. }
  725. //设置播放状态
  726. $(myobj).attr("play-status", "1");
  727. $(myobj).attr("src", PicInfo.audioPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  728. }
  729. var info = new Object();
  730. info.Id = $(myobj).attr("audio-id");
  731. info.AudioUrl = curAlt;
  732. //移动端添加外部处理
  733. playVisiableAudioCallBack(1, JSON.stringify(info));
  734. }
  735. //作答录音播放按钮点击事件
  736. function recordAudioClick(myobj, id, url) {
  737. //处理当前按钮的状态
  738. if ($(myobj).parent().attr("play-status") == "0") {
  739. //停止其他作答音频播放
  740. var isRecordPlaying = $(".answer-range[play-status='1']");
  741. if (isRecordPlaying.length > 0) {
  742. $(isRecordPlaying).attr("play-status", "0");
  743. $(isRecordPlaying).find("img").attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  744. }
  745. //停止其他原文音频播放
  746. var audioPlaying = $(".audioImg[play-status='1']");
  747. if (audioPlaying.length > 0) {
  748. $(audioPlaying).attr("play-status", "0");
  749. $(audioPlaying).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地 喇叭 路径替换
  750. }
  751. //设置播放状态
  752. $(myobj).parent().attr("play-status", "1");
  753. $(myobj).attr("src", PicInfo.recordPauseImgUrl);//移动端要根据本地路径替换
  754. }
  755. else {
  756. $(myobj).parent().attr("play-status", "0");
  757. $(myobj).attr("src", PicInfo.recordPlayImgUrl);//移动端要根据本地路径替换
  758. }
  759. //移动端添加外部处理,播放录音
  760. var info = new Object();
  761. info.Id = id;
  762. info.AudioUrl = url;
  763. //移动端添加外部处理,播放录音
  764. playVisiableAudioCallBack(3, JSON.stringify(info));
  765. }
  766. function playVisiableAudioCallBack(type, url) {
  767. //console.log(url);
  768. cancelBubble();
  769. plugin.startPlay(type, url);
  770. }
  771. function onClickAnswerPoint(data) {
  772. //alert(JSON.stringify(data));
  773. //console.log(JSON.stringify(data));
  774. cancelBubble();
  775. plugin.onClickAnswerPoint(data);
  776. }
  777. function onClickKeyHide() {
  778. //alert(JSON.stringify(data));
  779. cancelBubble();
  780. plugin.onClickKeyHide();
  781. }
  782. function cancelBubble(e) {
  783. var evt = e ? e : window.event;
  784. if (evt.stopPropagation) { //W3C
  785. evt.stopPropagation();
  786. } else { //IE
  787. evt.cancelBubble = true;
  788. }
  789. }
  790. function getSelectedText(title) {
  791. var txt;
  792. if (window.getSelection) {
  793. txt = window.getSelection().toString();
  794. } else if (window.document.getSelection) {
  795. txt = window.document.getSelection().toString();
  796. } else if (window.document.selection) {
  797. txt = window.document.selection.createRange().text;
  798. }
  799. JSInterface.callback(txt, title);
  800. }