mtm_temp.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. /*高亮文本标注*/
  2. function Fill(data) {
  3. var highlightArr = [];
  4. clearHighlight();
  5. styleWPSContrl.wordFlag = false;
  6. styleWPSContrl.phraseFlag = false;
  7. styleWPSContrl.sentenceFlag = false;
  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. styleWPSContrl.wordFlag = true;
  38. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").addClass('wordStyle'), true);
  39. }
  40. else if (item.attr('flag') == 'phrase') {
  41. styleWPSContrl.phraseFlag = true;
  42. if (item != null && item.attr('separate') != null) {
  43. $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle');
  44. bindEvent(item, true);
  45. }
  46. else {
  47. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle'), true);
  48. if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
  49. }
  50. }
  51. else if (item.attr('flag') == 'sentence') {
  52. if (item.attr('iskeyklg') == 'true') return;
  53. styleWPSContrl.sentenceFlag = true;
  54. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "sentenceStyle").addClass('sentenceStyle')
  55. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
  56. }
  57. });
  58. });
  59. // 绑定横线内处理
  60. if (typeof (addFillAssist) == "function") {
  61. addFillAssist();
  62. }
  63. }
  64. function clearHighlight() {
  65. $('span.klg-selected').removeClass('klg-selected');
  66. $('span[iskeyklg="true"]').each(function (i, item) {
  67. $(item).removeAttr('hitCode');
  68. $(item).attr('iskeyklg', 'false');
  69. if ($(item).attr('flag') == 'word') {
  70. $(item).removeClass('wordStyle').unbind();
  71. }
  72. else if ($(item).attr('flag') == 'phrase') {
  73. $(item).removeClass("phraseStyle").unbind();
  74. }
  75. else if ($(item).attr('flag') == 'sentence') {
  76. $(item).removeClass('sentenceStyle').unbind();
  77. $(item).prev().filter('img.sentImagcs').remove();
  78. }
  79. })
  80. }
  81. function bindEvent(ele, opt) {
  82. if (opt) {
  83. var className = '';
  84. if (ele.hasClass('phraseStyle'))
  85. className = 'phraseStyle';
  86. else if (ele.hasClass('wordStyle'))
  87. className = 'wordStyle';
  88. else if (ele.hasClass('sentenceStyle'))
  89. className = 'sentenceStyle';
  90. switch (className) {
  91. case 'phraseStyle':
  92. if (ele.attr('separate') != null) {
  93. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  94. 'click': function (e) {
  95. e.stopPropagation();
  96. //plugin.call(code);
  97. //alert($(this).attr("hitCode"));
  98. var sHCode = $(this).attr("shcode");
  99. if (sHCode != undefined && sHCode==1) {
  100. test($(this).attr("hitCode"));
  101. }
  102. else if (sHCode == undefined) {
  103. test($(this).attr("hitCode"));
  104. }
  105. }
  106. });
  107. }
  108. case 'wordStyle':
  109. ele.unbind().bind({
  110. 'click': function (e) {
  111. e.stopPropagation();
  112. //plugin.call(code);
  113. //alert($(this).attr("hitCode"));
  114. var sHCode = $(this).attr("shcode");
  115. if (sHCode != undefined && sHCode == 1) {
  116. test($(this).attr("hitCode"));
  117. }
  118. else if (sHCode == undefined) {
  119. test($(this).attr("hitCode"));
  120. }
  121. }
  122. });
  123. break;
  124. case 'sentenceStyle':
  125. ele.unbind().bind({
  126. 'click': function (e) {
  127. e.stopPropagation();
  128. //plugin.call(code);
  129. //alert($(this).attr("hitCode"));
  130. var sHCode = $(this).attr("shcode");
  131. if (sHCode != undefined && sHCode == 1) {
  132. test($(this).attr("hitCode"));
  133. }
  134. else if (sHCode == undefined) {
  135. test($(this).attr("hitCode"));
  136. }
  137. }
  138. }).prev().filter('.sentImagcs').unbind().bind({
  139. 'click': function (e) {
  140. e.stopPropagation();
  141. //plugin.call(code);
  142. //alert($(this).attr("hitCode"));
  143. var sHCode = $(this).attr("shcode");
  144. if (sHCode != undefined && sHCode == 1) {
  145. test($(this).attr("hitCode"));
  146. }
  147. else if (sHCode == undefined) {
  148. test($(this).attr("hitCode"));
  149. }
  150. }
  151. });
  152. break;
  153. }
  154. }
  155. else {
  156. ele.unbind();
  157. }
  158. }
  159. function test(code) {
  160. //alert(code);
  161. cancelBubble();
  162. plugin.call(code);
  163. }