mtm_temp.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*高亮文本标注*/
  2. function Fill(data) {
  3. var wordFlag = false;
  4. var phraseFlag = false;
  5. var sentenceFlag = false;
  6. var highlightArr = [];
  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. wordFlag = true;
  38. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").addClass('wordStyle'), true);
  39. }
  40. else if (item.attr('flag') == 'phrase') {
  41. 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. 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. $.each($(document).find("u,span,p"), function (Iindex, Iitem) {
  61. var ClsName = $(Iitem).attr("class");
  62. if ($(Iitem).attr("ulflag") == undefined) {
  63. $(Iitem).attr("ulflag", "0");
  64. }
  65. if ($(Iitem).attr("shcode") == undefined) {
  66. $(Iitem).attr("shcode", 1);
  67. }
  68. if ($(Iitem).attr("showflag") == undefined) {
  69. $(Iitem).attr("showflag", "1");
  70. }
  71. if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
  72. $(Iitem).attr("ulflag", "1");
  73. $.each($(Iitem).find("u,span,p"), function (index, element) {
  74. if ($(element).attr("ulflag") == undefined) {
  75. $(element).attr("ulflag", "1");
  76. }
  77. if ($(element).attr("shcode") == undefined) {
  78. $(element).attr("shcode", 1);
  79. }
  80. if ($(element).attr("showflag") == undefined) {
  81. $(element).attr("showflag", "1");
  82. }
  83. });
  84. }
  85. });
  86. if (typeof (showGLWorld) == "function") {
  87. showGLWorld(wordFlag, phraseFlag, sentenceFlag);
  88. }
  89. }
  90. function clearHighlight() {
  91. $('span.klg-selected').removeClass('klg-selected');
  92. $('span[iskeyklg="true"]').each(function (i, item) {
  93. $(item).removeAttr('hitCode');
  94. $(item).attr('iskeyklg', 'false');
  95. if ($(item).attr('flag') == 'word') {
  96. $(item).removeClass('wordStyle').unbind();
  97. }
  98. else if ($(item).attr('flag') == 'phrase') {
  99. $(item).removeClass().unbind();
  100. }
  101. else if ($(item).attr('flag') == 'sentence') {
  102. $(item).removeClass('sentenceStyle').unbind();
  103. $(item).prev().filter('img.sentImagcs').remove();
  104. }
  105. })
  106. }
  107. function bindEvent(ele, opt) {
  108. if (opt) {
  109. var className = '';
  110. if (ele.hasClass('phraseStyle'))
  111. className = 'phraseStyle';
  112. else if (ele.hasClass('wordStyle'))
  113. className = 'wordStyle';
  114. else if (ele.hasClass('sentenceStyle'))
  115. className = 'sentenceStyle';
  116. switch (className) {
  117. case 'phraseStyle':
  118. if (ele.attr('separate') != null) {
  119. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  120. 'click': function (e) {
  121. e.stopPropagation();
  122. //plugin.call(code);
  123. //alert($(this).attr("hitCode"));
  124. var sHCode = $(this).attr("shcode");
  125. if (sHCode == 1) {
  126. test($(this).attr("hitCode"));
  127. }
  128. }
  129. });
  130. }
  131. case 'wordStyle':
  132. ele.unbind().bind({
  133. 'click': function (e) {
  134. e.stopPropagation();
  135. //plugin.call(code);
  136. //alert($(this).attr("hitCode"));
  137. var sHCode = $(this).attr("shcode");
  138. if (sHCode == 1) {
  139. test($(this).attr("hitCode"));
  140. }
  141. }
  142. });
  143. break;
  144. case 'sentenceStyle':
  145. ele.unbind().bind({
  146. 'click': function (e) {
  147. e.stopPropagation();
  148. //plugin.call(code);
  149. //alert($(this).attr("hitCode"));
  150. var sHCode = $(this).attr("shcode");
  151. if (sHCode == 1) {
  152. test($(this).attr("hitCode"));
  153. }
  154. }
  155. }).prev().filter('.sentImagcs').unbind().bind({
  156. 'click': function (e) {
  157. e.stopPropagation();
  158. //plugin.call(code);
  159. //alert($(this).attr("hitCode"));
  160. var sHCode = $(this).attr("shcode");
  161. if (sHCode == 1) {
  162. test($(this).next().attr("hitCode"));
  163. }
  164. }
  165. });
  166. break;
  167. }
  168. }
  169. else {
  170. ele.unbind();
  171. }
  172. }
  173. function test(code) {
  174. //alert(code);
  175. cancelBubble();
  176. plugin.call(code);
  177. }