mtm_temp.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*高亮文本标注*/
  2. function Fill(data) {
  3. var highlightArr = [];
  4. if ($(document.body).find(".wordStyle,.phraseStyle,.phraseStyle").length > 0) {
  5. dealAnswerFunc(document.body, false, false);
  6. }
  7. clearHighlight();
  8. $.each(data, function (i, item) {
  9. if (typeof (item.HightCode) != 'undefined' && item.HightCode != null && item.HightCode != "") {
  10. var highlightItem = $('span[id=' + item.HightCode + ']').eq(0);
  11. if (highlightItem.length > 0) {
  12. var hitCode = highlightItem.attr('hitCode');
  13. if (hitCode) {
  14. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  15. }
  16. else {
  17. highlightItem.attr('hitCode', item.SourceCode);
  18. }
  19. highlightArr.push(highlightItem);
  20. }
  21. }
  22. else if (typeof (item.SourceCode) == 'undefined' || item.SourceCode == null || item.SourceCode != "") {
  23. var highlightItem = $('span[kcode*=' + item.SourceCode + ']:first');
  24. if (highlightItem.length > 0) {
  25. var hitCode = highlightItem.attr('hitCode');
  26. if (hitCode) {
  27. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  28. }
  29. else {
  30. highlightItem.attr('hitCode', item.SourceCode);
  31. }
  32. highlightArr.push(highlightItem);
  33. }
  34. }
  35. $.each(highlightArr, function (i, item) {
  36. if (item.attr('flag') == 'word') {
  37. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").addClass('wordStyle'), true);
  38. }
  39. else if (item.attr('flag') == 'phrase') {
  40. if (item != null && item.attr('separate') != null) {
  41. $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle');
  42. bindEvent(item, true);
  43. }
  44. else {
  45. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle'), true);
  46. if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
  47. }
  48. }
  49. else if (item.attr('flag') == 'sentence') {
  50. if (item.attr('iskeyklg') == 'true') return;
  51. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "sentenceStyle").addClass('sentenceStyle')
  52. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
  53. }
  54. });
  55. // 绑定横线内处理
  56. $(document).find(".wordStyle,.phraseStyle,.phraseStyle,u,span,p").attr("ulflag", "0").attr("shcode", 1).attr("showFlag", "1");
  57. $(document).find(".underlineContent").attr("shcode", 1).attr("ulflag", "1").attr("showFlag", "1");
  58. $.each($(".underlineContent").find(".wordStyle,.phraseStyle,.phraseStyle,u,span,p"), function (index,element) {
  59. $(element).attr("shcode", 1).attr("ulflag", "1").attr("showFlag", "1");
  60. });
  61. });
  62. }
  63. function clearHighlight() {
  64. $('span.klg-selected').removeClass('klg-selected');
  65. $('span[iskeyklg="true"]').each(function (i, item) {
  66. $(item).removeAttr('hitCode');
  67. $(item).attr('iskeyklg', 'false');
  68. if ($(item).attr('flag') == 'word') {
  69. $(item).removeClass('wordStyle').unbind();
  70. }
  71. else if ($(item).attr('flag') == 'phrase') {
  72. $(item).removeClass().unbind();
  73. }
  74. else if ($(item).attr('flag') == 'sentence') {
  75. $(item).removeClass('sentenceStyle').unbind();
  76. $(item).prev().filter('img.sentImagcs').remove();
  77. }
  78. })
  79. }
  80. function bindEvent(ele, opt) {
  81. if (opt) {
  82. var className = '';
  83. if (ele.hasClass('phraseStyle'))
  84. className = 'phraseStyle';
  85. else if (ele.hasClass('wordStyle'))
  86. className = 'wordStyle';
  87. else if (ele.hasClass('sentenceStyle'))
  88. className = 'sentenceStyle';
  89. switch (className) {
  90. case 'phraseStyle':
  91. if (ele.attr('separate') != null) {
  92. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  93. 'click': function (e) {
  94. e.stopPropagation();
  95. //plugin.call(code);
  96. //alert($(this).attr("hitCode"));
  97. var sHCode = $(this).attr("shcode");
  98. if (sHCode == 1) {
  99. test($(this).attr("hitCode"));
  100. }
  101. }
  102. });
  103. }
  104. case 'wordStyle':
  105. ele.unbind().bind({
  106. 'click': function (e) {
  107. e.stopPropagation();
  108. //plugin.call(code);
  109. //alert($(this).attr("hitCode"));
  110. var sHCode = $(this).attr("shcode");
  111. if (sHCode == 1) {
  112. test($(this).attr("hitCode"));
  113. }
  114. }
  115. });
  116. break;
  117. case 'sentenceStyle':
  118. ele.unbind().bind({
  119. 'click': function (e) {
  120. e.stopPropagation();
  121. //plugin.call(code);
  122. //alert($(this).attr("hitCode"));
  123. var sHCode = $(this).attr("shcode");
  124. if (sHCode == 1) {
  125. test($(this).attr("hitCode"));
  126. }
  127. }
  128. }).prev().filter('.sentImagcs').unbind().bind({
  129. 'click': function (e) {
  130. e.stopPropagation();
  131. //plugin.call(code);
  132. //alert($(this).attr("hitCode"));
  133. var sHCode = $(this).attr("shcode");
  134. if (sHCode == 1) {
  135. test($(this).next().attr("hitCode"));
  136. }
  137. }
  138. });
  139. break;
  140. }
  141. }
  142. else {
  143. ele.unbind();
  144. }
  145. }
  146. function test(code) {
  147. //alert(code);
  148. cancelBubble();
  149. plugin.call(code);
  150. }