tasklib_book.js 35 KB

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