mtm_temp.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. /*高亮文本标注*/
  2. function Fill(data) {
  3. var highlightArr = [];
  4. clearHighlight();
  5. //data = JSON.parse(data);
  6. $.each(data, function (i, item) {
  7. if (typeof (item.HightCode) != 'undefined' && item.HightCode != null && item.HightCode != "") {
  8. var highlightItem = $('span[id=' + item.HightCode + ']').eq(0);
  9. if (highlightItem.length > 0) {
  10. var hitCode = highlightItem.attr('hitCode');
  11. if (hitCode) {
  12. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  13. }
  14. else {
  15. highlightItem.attr('hitCode', item.SourceCode);
  16. }
  17. highlightArr.push(highlightItem);
  18. }
  19. }
  20. else if (typeof (item.SourceCode) == 'undefined' || item.SourceCode == null || item.SourceCode != "") {
  21. var highlightItem = $('span[kcode*=' + item.SourceCode + ']:first');
  22. if (highlightItem.length > 0) {
  23. var hitCode = highlightItem.attr('hitCode');
  24. if (hitCode) {
  25. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  26. }
  27. else {
  28. highlightItem.attr('hitCode', item.SourceCode);
  29. }
  30. highlightArr.push(highlightItem);
  31. }
  32. }
  33. $.each(highlightArr, function (i, item) {
  34. if (item.attr('flag') == 'word') {
  35. // data-scolor显示的颜色等级卡控,data-setstatus高亮是否处于显示状态,data-lstatus:卡控是否能点击(1单词,2短语,3句型)
  36. // 附加默认所有高亮都可见.attr("showflag", "1")
  37. bindEvent(item.attr('iskeyklg', 'true').attr("data-setstatus", "0").attr("showflag", "1").attr("data-scolor", cHPhraseStyleFunc(item)).addClass('wordStyle'), true);
  38. }
  39. else if (item.attr('flag') == 'phrase') {
  40. bindEvent(item.attr('iskeyklg', 'true').attr("data-setstatus", "0").attr("showflag", "1").addClass('phraseStyle'), true);
  41. }
  42. else if (item.attr('flag') == 'sentence') {
  43. if (item.attr('iskeyklg') == 'true') return;
  44. bindEvent(item.attr('iskeyklg', 'true').attr("data-setstatus", "0").attr("showflag", "1").addClass('sentenceStyle')
  45. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs" data-lstatus="0" data-setstatus="0">'), true);
  46. }
  47. });
  48. });
  49. // 绑定横线内处理
  50. if (typeof (addFillAssist) == "function") {
  51. addFillAssist();
  52. }
  53. adjustFillFunc(7);
  54. }
  55. function clearHighlight() {
  56. $('span.klg-selected').removeClass('klg-selected');
  57. $('span[iskeyklg="true"]').each(function (i, item) {
  58. $(item).removeAttr('hitCode');
  59. $(item).attr('iskeyklg', 'false');
  60. if ($(item).attr('flag') == 'word') {
  61. $(item).removeClass('wordStyle').unbind();
  62. }
  63. else if ($(item).attr('flag') == 'phrase') {
  64. $(item).removeClass("phraseStyle").unbind();
  65. }
  66. else if ($(item).attr('flag') == 'sentence') {
  67. $(item).removeClass('sentenceStyle').unbind();
  68. $(item).prev().filter('img.sentImagcs').remove();
  69. }
  70. })
  71. }
  72. function bindEvent(ele, opt) {
  73. if (opt) {
  74. var className = '';
  75. if (ele.hasClass('phraseStyle'))
  76. className = 'phraseStyle';
  77. else if (ele.hasClass('wordStyle'))
  78. className = 'wordStyle';
  79. else if (ele.hasClass('sentenceStyle'))
  80. className = 'sentenceStyle';
  81. switch (className) {
  82. case 'phraseStyle':
  83. ele.unbind().bind({
  84. 'click': function (e) {
  85. $(".wordStyle[data-nowclick='1'],.phraseStyle[data-nowclick='1'],.sentenceStyle[data-nowclick='1'],.sentImagcs[data-nowclick='1']").attr("data-nowclick", "0");
  86. ele.attr("data-nowclick", "1"); // 正在点击
  87. //plugin.call(code);
  88. //alert($(this).attr("hitCode"));
  89. if (ele.attr("data-lstatus") == "2") {
  90. return;
  91. }
  92. e.stopPropagation();
  93. var sHCode = $(this).attr("shcode");
  94. if (sHCode != undefined && sHCode == 1) {
  95. test($(this).attr("hitCode"));
  96. }
  97. else if (sHCode == undefined) {
  98. test($(this).attr("hitCode"));
  99. }
  100. }
  101. });
  102. break;
  103. case 'wordStyle':
  104. ele.unbind().bind({
  105. 'click': function (e) {
  106. $(".wordStyle[data-nowclick='1'],.phraseStyle[data-nowclick='1'],.sentenceStyle[data-nowclick='1'],.sentImagcs[data-nowclick='1']").attr("data-nowclick", "0");
  107. ele.attr("data-nowclick", "1"); // 正在点击
  108. //plugin.call(code);
  109. //alert($(this).attr("hitCode"));
  110. if (ele.attr("data-lstatus") == "1") {
  111. return;
  112. }
  113. e.stopPropagation();
  114. var sHCode = $(this).attr("shcode");
  115. if (sHCode != undefined && sHCode == 1) {
  116. test($(this).attr("hitCode"));
  117. }
  118. else if (sHCode == undefined) {
  119. test($(this).attr("hitCode"));
  120. }
  121. }
  122. });
  123. break;
  124. case 'sentenceStyle':
  125. ele.unbind().bind({
  126. 'click': function (e) {
  127. $(".wordStyle[data-nowclick='1'],.phraseStyle[data-nowclick='1'],.sentenceStyle[data-nowclick='1'],.sentImagcs[data-nowclick='1']").attr("data-nowclick", "0");
  128. ele.attr("data-nowclick", "1"); // 正在点击
  129. ele.next(".sentenceStyle").attr("data-nowclick", "1"); // 正在点击
  130. //plugin.call(code);
  131. //alert($(this).attr("hitCode"));
  132. if (ele.attr("data-lstatus") == "3") {
  133. return;
  134. }
  135. e.stopPropagation();
  136. var sHCode = $(this).attr("shcode");
  137. if (sHCode != undefined && sHCode == 1) {
  138. test($(this).attr("hitCode"));
  139. }
  140. else if (sHCode == undefined) {
  141. test($(this).attr("hitCode"));
  142. }
  143. }
  144. }).prev().filter('.sentImagcs').unbind().bind({
  145. 'click': function (e) {
  146. $(".wordStyle[data-nowclick='1'],.phraseStyle[data-nowclick='1'],.sentenceStyle[data-nowclick='1'],.sentImagcs[data-nowclick='1']").attr("data-nowclick", "0");
  147. ele.attr("data-nowclick", "1"); // 正在点击
  148. ele.next(".sentenceStyle").attr("data-nowclick", "1"); // 正在点击
  149. //plugin.call(code);
  150. //alert($(this).attr("hitCode"));
  151. if (ele.attr("data-lstatus") == "3") {
  152. return;
  153. }
  154. e.stopPropagation();
  155. var sHCode = $(this).attr("shcode");
  156. if (sHCode != undefined && sHCode == 1) {
  157. test($(this).next().attr("hitCode"));
  158. }
  159. else if (sHCode == undefined) {
  160. test($(this).next().attr("hitCode"));
  161. }
  162. }
  163. });
  164. break;
  165. }
  166. }
  167. else {
  168. ele.unbind();
  169. }
  170. }
  171. // #region
  172. // 判断显示层级:0表示最外层;1表示在underlineContent里面;2表示在phraseStyle里面;5表示在underlineContent且phraseStyle在underlineContent里面,7表示在phraseStyle且underlineContent在phraseStyle里面
  173. function cHPhraseStyleFunc(element) {
  174. var ReNumber = 0;
  175. var wFlag=true;
  176. while (wFlag) {
  177. var ClsName = $(element).attr("class");
  178. if ($(element).parent() == null || $(element)[0].tagName.toUpperCase() == "BODY") {
  179. wFlag = false;
  180. return ReNumber;
  181. }
  182. else if (ClsName != undefined && ClsName.indexOf("phraseStyle") > -1) {
  183. wFlag = false;
  184. ReNumber += 1;
  185. }
  186. else if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
  187. wFlag = false;
  188. ReNumber += 2;
  189. }
  190. element = $(element).parent();
  191. };
  192. wFlag = true;
  193. while (wFlag) {
  194. var ClsName = $(element).attr("class");
  195. if ($(element).parent() == null || $(element)[0].tagName.toUpperCase() == "BODY") {
  196. wFlag = false;
  197. return ReNumber;
  198. }
  199. else if (ClsName != undefined && ClsName.indexOf("phraseStyle") > -1) {
  200. wFlag = false;
  201. ReNumber += 3;
  202. return ReNumber;
  203. }
  204. else if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
  205. wFlag = false;
  206. ReNumber += 5;
  207. return ReNumber;
  208. }
  209. element = $(element).parent();
  210. };
  211. return ReNumber;
  212. }
  213. // 添加高亮新调用处理(1:单词;2:短语;4:句型)
  214. var fillDataNum = 0;
  215. function adjustFillFunc(DataNum) {
  216. fillDataNum = DataNum;
  217. switch (DataNum) {
  218. case 0:
  219. $(".wordStyle").attr("data-setstatus", "0").attr("data-lstatus", "1");
  220. $(".phraseStyle").attr("data-setstatus", "0").attr("data-lstatus", "2");
  221. $(".sentenceStyle").attr("data-setstatus", "0").attr("data-lstatus", "3");
  222. $(".sentImagcs").attr("data-setstatus", "0").attr("data-lstatus", "3");
  223. break;
  224. case 1:
  225. $(".wordStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  226. $(".phraseStyle").attr("data-setstatus", "0").attr("data-lstatus", "2");
  227. $(".sentenceStyle").attr("data-setstatus", "0").attr("data-lstatus", "3");
  228. $(".sentImagcs").attr("data-setstatus", "0").attr("data-lstatus", "3");
  229. break;
  230. case 2:
  231. $(".wordStyle").attr("data-setstatus", "0").attr("data-lstatus", "1");
  232. $(".phraseStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  233. $(".sentenceStyle").attr("data-setstatus", "0").attr("data-lstatus", "3");
  234. $(".sentImagcs").attr("data-setstatus", "0").attr("data-lstatus", "3");
  235. break;
  236. case 3:
  237. $(".wordStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  238. $(".phraseStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  239. $(".sentenceStyle").attr("data-setstatus", "0").attr("data-lstatus", "3");
  240. $(".sentImagcs").attr("data-setstatus", "0").attr("data-lstatus", "3");
  241. break;
  242. case 4:
  243. $(".wordStyle").attr("data-setstatus", "0").attr("data-lstatus", "1");
  244. $(".phraseStyle").attr("data-setstatus", "0").attr("data-lstatus", "2");
  245. $(".sentenceStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  246. $(".sentImagcs").attr("data-setstatus", "1").attr("data-lstatus", "0");
  247. break;
  248. case 5:
  249. $(".wordStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  250. $(".phraseStyle").attr("data-setstatus", "0").attr("data-lstatus", "2");
  251. $(".sentenceStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  252. $(".sentImagcs").attr("data-setstatus", "1").attr("data-lstatus", "0");
  253. break;
  254. case 6:
  255. $(".wordStyle").attr("data-setstatus", "0").attr("data-lstatus", "1");
  256. $(".phraseStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  257. $(".sentenceStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  258. $(".sentImagcs").attr("data-setstatus", "1").attr("data-lstatus", "0");
  259. break;
  260. case 7:
  261. $(".wordStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  262. $(".phraseStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  263. $(".sentenceStyle").attr("data-setstatus", "1").attr("data-lstatus", "0");
  264. $(".sentImagcs").attr("data-setstatus", "1").attr("data-lstatus", "0");
  265. break;
  266. default:
  267. break;
  268. };
  269. // 处理不显示高亮
  270. if (typeof (dealNotShowFill) == "function") {
  271. dealNotShowFill();
  272. }
  273. dealJXQTFunc();
  274. dealRecvHSFill();
  275. if (typeof (dealNSFillFunc) == "function") {
  276. dealNSFillFunc();
  277. }
  278. }
  279. // #endregion
  280. function test(code) {
  281. //alert(code);
  282. cancelBubble();
  283. plugin.call(code);
  284. }