mtm_temp.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. function clearHighlight() {
  66. $('span.klg-selected').removeClass('klg-selected');
  67. $('span[iskeyklg="true"]').each(function (i, item) {
  68. $(item).removeAttr('hitCode');
  69. $(item).attr('iskeyklg', 'false');
  70. if ($(item).attr('flag') == 'word') {
  71. $(item).removeClass('wordStyle').unbind();
  72. }
  73. else if ($(item).attr('flag') == 'phrase') {
  74. $(item).removeClass("phraseStyle").unbind();
  75. }
  76. else if ($(item).attr('flag') == 'sentence') {
  77. $(item).removeClass('sentenceStyle').unbind();
  78. $(item).prev().filter('img.sentImagcs').remove();
  79. }
  80. })
  81. }
  82. function bindEvent(ele, opt) {
  83. if (opt) {
  84. var className = '';
  85. if (ele.hasClass('phraseStyle'))
  86. className = 'phraseStyle';
  87. else if (ele.hasClass('wordStyle'))
  88. className = 'wordStyle';
  89. else if (ele.hasClass('sentenceStyle'))
  90. className = 'sentenceStyle';
  91. switch (className) {
  92. case 'phraseStyle':
  93. if (ele.attr('separate') != null) {
  94. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  95. 'click': function (e) {
  96. e.stopPropagation();
  97. //plugin.call(code);
  98. //alert($(this).attr("hitCode"));
  99. var sHCode = $(this).attr("shcode");
  100. if (sHCode != undefined && sHCode == 1) {
  101. test($(this).attr("hitCode"));
  102. }
  103. else if (sHCode == undefined) {
  104. test($(this).attr("hitCode"));
  105. }
  106. }
  107. });
  108. }
  109. case 'wordStyle':
  110. ele.unbind().bind({
  111. 'click': function (e) {
  112. e.stopPropagation();
  113. //plugin.call(code);
  114. //alert($(this).attr("hitCode"));
  115. var sHCode = $(this).attr("shcode");
  116. if (sHCode != undefined && sHCode == 1) {
  117. test($(this).attr("hitCode"));
  118. }
  119. else if (sHCode == undefined) {
  120. test($(this).attr("hitCode"));
  121. }
  122. }
  123. });
  124. break;
  125. case 'sentenceStyle':
  126. ele.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 != undefined && sHCode == 1) {
  133. test($(this).attr("hitCode"));
  134. }
  135. else if (sHCode == undefined) {
  136. test($(this).attr("hitCode"));
  137. }
  138. }
  139. }).prev().filter('.sentImagcs').unbind().bind({
  140. 'click': function (e) {
  141. e.stopPropagation();
  142. //plugin.call(code);
  143. //alert($(this).attr("hitCode"));
  144. var sHCode = $(this).attr("shcode");
  145. if (sHCode != undefined && sHCode == 1) {
  146. test($(this).next().attr("hitCode"));
  147. }
  148. else if (sHCode == undefined) {
  149. test($(this).next().attr("hitCode"));
  150. }
  151. }
  152. });
  153. break;
  154. }
  155. }
  156. else {
  157. ele.unbind();
  158. }
  159. }
  160. function test(code) {
  161. //alert(code);
  162. cancelBubble();
  163. plugin.call(code);
  164. }