mtm_temp.js 6.6 KB

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