mtm_temp.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*高亮文本标注*/
  2. function Fill(data) {
  3. var highlightArr = [];
  4. clearHighlight();
  5. styleWPSContrl.wordFlag = false;
  6. styleWPSContrl.phraseFlag = false;
  7. styleWPSContrl.sentenceFlag = false;
  8. //data = JSON.parse(data);
  9. $.each(data, function (i, item) {
  10. if (typeof (item.HightCode) != 'undefined' && item.HightCode != null && item.HightCode != "") {
  11. var highlightItem = $('span[id=' + item.HightCode + ']').eq(0);
  12. if (highlightItem.length > 0) {
  13. var hitCode = highlightItem.attr('hitCode');
  14. if (hitCode) {
  15. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  16. }
  17. else {
  18. highlightItem.attr('hitCode', item.SourceCode);
  19. }
  20. highlightArr.push(highlightItem);
  21. }
  22. }
  23. else if (typeof (item.SourceCode) == 'undefined' || item.SourceCode == null || item.SourceCode != "") {
  24. var highlightItem = $('span[kcode*=' + item.SourceCode + ']:first');
  25. if (highlightItem.length > 0) {
  26. var hitCode = highlightItem.attr('hitCode');
  27. if (hitCode) {
  28. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  29. }
  30. else {
  31. highlightItem.attr('hitCode', item.SourceCode);
  32. }
  33. highlightArr.push(highlightItem);
  34. }
  35. }
  36. $.each(highlightArr, function (i, item) {
  37. if (item.attr('flag') == 'word') {
  38. styleWPSContrl.wordFlag = true;
  39. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").addClass('wordStyle'), true);
  40. }
  41. else if (item.attr('flag') == 'phrase') {
  42. styleWPSContrl.phraseFlag = true;
  43. if (item != null && item.attr('separate') != null) {
  44. $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle');
  45. bindEvent(item, true);
  46. }
  47. else {
  48. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle'), true);
  49. if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
  50. }
  51. }
  52. else if (item.attr('flag') == 'sentence') {
  53. if (item.attr('iskeyklg') == 'true') return;
  54. styleWPSContrl.sentenceFlag = true;
  55. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "sentenceStyle").addClass('sentenceStyle')
  56. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
  57. }
  58. });
  59. });
  60. // 绑定横线内处理
  61. if (typeof (addFillAssist) == "function") {
  62. addFillAssist();
  63. }
  64. // 处理不显示高亮
  65. if (typeof (dealNotShowFill) == "function") {
  66. dealNotShowFill();
  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("phraseStyle").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. if (ele.attr("data-lstatus") == "1") {
  104. return;
  105. }
  106. var sHCode = $(this).attr("shcode");
  107. if (sHCode != undefined && sHCode == 1) {
  108. test($(this).attr("hitCode"));
  109. }
  110. else if (sHCode == undefined) {
  111. test($(this).attr("hitCode"));
  112. }
  113. }
  114. });
  115. }
  116. case 'wordStyle':
  117. ele.unbind().bind({
  118. 'click': function (e) {
  119. e.stopPropagation();
  120. //plugin.call(code);
  121. //alert($(this).attr("hitCode"));
  122. if (ele.attr("data-lstatus") == "1") {
  123. return;
  124. }
  125. var sHCode = $(this).attr("shcode");
  126. if (sHCode != undefined && sHCode == 1) {
  127. test($(this).attr("hitCode"));
  128. }
  129. else if (sHCode == undefined) {
  130. test($(this).attr("hitCode"));
  131. }
  132. }
  133. });
  134. break;
  135. case 'sentenceStyle':
  136. ele.unbind().bind({
  137. 'click': function (e) {
  138. e.stopPropagation();
  139. //plugin.call(code);
  140. //alert($(this).attr("hitCode"));
  141. if (ele.attr("data-lstatus") == "1") {
  142. return;
  143. }
  144. var sHCode = $(this).attr("shcode");
  145. if (sHCode != undefined && sHCode == 1) {
  146. test($(this).attr("hitCode"));
  147. }
  148. else if (sHCode == undefined) {
  149. test($(this).attr("hitCode"));
  150. }
  151. }
  152. }).prev().filter('.sentImagcs').unbind().bind({
  153. 'click': function (e) {
  154. e.stopPropagation();
  155. //plugin.call(code);
  156. //alert($(this).attr("hitCode"));
  157. if (ele.attr("data-lstatus") == "1") {
  158. return;
  159. }
  160. var sHCode = $(this).attr("shcode");
  161. if (sHCode != undefined && sHCode == 1) {
  162. test($(this).next().attr("hitCode"));
  163. }
  164. else if (sHCode == undefined) {
  165. test($(this).next().attr("hitCode"));
  166. }
  167. }
  168. });
  169. break;
  170. }
  171. }
  172. else {
  173. ele.unbind();
  174. }
  175. }
  176. function test(code) {
  177. //alert(code);
  178. cancelBubble();
  179. plugin.call(code);
  180. }