tasklib_book.js 32 KB

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