mtm_temp.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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').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').addClass('phraseStyle');
  42. bindEvent(item, true);
  43. }
  44. else {
  45. bindEvent(item.attr('iskeyklg', 'true').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').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").attr("uLFlag", "0").attr("shcode", 0).attr("showFlag", "1");
  57. $(document).find(".underlineContent").attr("shcode", 0).attr("uLFlag", "1").attr("showFlag", "1");
  58. $(document).find(".underlineContent").find(".wordStyle,.phraseStyle,.phraseStyle,u,span").attr("shcode", 0).attr("uLFlag", "1").attr("showFlag", "1");
  59. });
  60. }
  61. function clearHighlight() {
  62. $('span.klg-selected').removeClass('klg-selected');
  63. $('span[iskeyklg="true"]').each(function (i, item) {
  64. $(item).removeAttr('hitCode');
  65. $(item).attr('iskeyklg', 'false');
  66. if ($(item).attr('flag') == 'word') {
  67. $(item).removeClass('wordStyle').unbind();
  68. }
  69. else if ($(item).attr('flag') == 'phrase') {
  70. $(item).removeClass().unbind();
  71. }
  72. else if ($(item).attr('flag') == 'sentence') {
  73. $(item).removeClass('sentenceStyle').unbind();
  74. $(item).prev().filter('img.sentImagcs').remove();
  75. }
  76. })
  77. }
  78. function bindEvent(ele, opt) {
  79. if (opt) {
  80. var className = '';
  81. if (ele.hasClass('phraseStyle'))
  82. className = 'phraseStyle';
  83. else if (ele.hasClass('wordStyle'))
  84. className = 'wordStyle';
  85. else if (ele.hasClass('sentenceStyle'))
  86. className = 'sentenceStyle';
  87. switch (className) {
  88. case 'phraseStyle':
  89. if (ele.attr('separate') != null) {
  90. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  91. 'click': function (e) {
  92. e.stopPropagation();
  93. //plugin.call(code);
  94. //alert($(this).attr("hitCode"));
  95. var sHCode = $(this).attr("shcode");
  96. if (sHCode != 1) {
  97. test($(this).attr("hitCode"));
  98. }
  99. }
  100. });
  101. }
  102. case 'wordStyle':
  103. ele.unbind().bind({
  104. 'click': function (e) {
  105. e.stopPropagation();
  106. //plugin.call(code);
  107. //alert($(this).attr("hitCode"));
  108. var sHCode = $(this).attr("shcode");
  109. if (sHCode != 1) {
  110. test($(this).attr("hitCode"));
  111. }
  112. }
  113. });
  114. break;
  115. case 'sentenceStyle':
  116. ele.unbind().bind({
  117. 'click': function (e) {
  118. e.stopPropagation();
  119. //plugin.call(code);
  120. //alert($(this).attr("hitCode"));
  121. var sHCode = $(this).attr("shcode");
  122. if (sHCode != 1) {
  123. test($(this).attr("hitCode"));
  124. }
  125. }
  126. }).prev().filter('.sentImagcs').unbind().bind({
  127. 'click': function (e) {
  128. e.stopPropagation();
  129. //plugin.call(code);
  130. //alert($(this).attr("hitCode"));
  131. var sHCode = $(this).attr("shcode");
  132. if (sHCode != 1) {
  133. test($(this).next().attr("hitCode"));
  134. }
  135. }
  136. });
  137. break;
  138. }
  139. }
  140. else {
  141. ele.unbind();
  142. }
  143. }
  144. function test(code) {
  145. //alert(code);
  146. cancelBubble();
  147. plugin.call(code);
  148. }