tasklib_book.js 38 KB

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