tasklib_book.js 35 KB

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