mtm_temp.js 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. // data-scolor显示的颜色等级卡控
  40. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").attr("data-scolor", cHPhraseStyleFunc(item)).addClass('wordStyle'), true);
  41. }
  42. else if (item.attr('flag') == 'phrase') {
  43. styleWPSContrl.phraseFlag = true;
  44. if (item != null && item.attr('separate') != null) {
  45. $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle');
  46. bindEvent(item, true);
  47. }
  48. else {
  49. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle'), true);
  50. if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
  51. }
  52. }
  53. else if (item.attr('flag') == 'sentence') {
  54. if (item.attr('iskeyklg') == 'true') return;
  55. styleWPSContrl.sentenceFlag = true;
  56. bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "sentenceStyle").addClass('sentenceStyle')
  57. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
  58. }
  59. });
  60. });
  61. // 绑定横线内处理
  62. if (typeof (addFillAssist) == "function") {
  63. addFillAssist();
  64. }
  65. // 处理不显示高亮
  66. if (typeof (dealNotShowFill) == "function") {
  67. dealNotShowFill();
  68. }
  69. }
  70. function clearHighlight() {
  71. $('span.klg-selected').removeClass('klg-selected');
  72. $('span[iskeyklg="true"]').each(function (i, item) {
  73. $(item).removeAttr('hitCode');
  74. $(item).attr('iskeyklg', 'false');
  75. if ($(item).attr('flag') == 'word') {
  76. $(item).removeClass('wordStyle').unbind();
  77. }
  78. else if ($(item).attr('flag') == 'phrase') {
  79. $(item).removeClass("phraseStyle").unbind();
  80. }
  81. else if ($(item).attr('flag') == 'sentence') {
  82. $(item).removeClass('sentenceStyle').unbind();
  83. $(item).prev().filter('img.sentImagcs').remove();
  84. }
  85. })
  86. }
  87. function bindEvent(ele, opt) {
  88. if (opt) {
  89. var className = '';
  90. if (ele.hasClass('phraseStyle'))
  91. className = 'phraseStyle';
  92. else if (ele.hasClass('wordStyle'))
  93. className = 'wordStyle';
  94. else if (ele.hasClass('sentenceStyle'))
  95. className = 'sentenceStyle';
  96. switch (className) {
  97. case 'phraseStyle':
  98. if (ele.attr('separate') != null) {
  99. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  100. 'click': function (e) {
  101. e.stopPropagation();
  102. //plugin.call(code);
  103. //alert($(this).attr("hitCode"));
  104. if (ele.attr("data-lstatus") == "1") {
  105. return;
  106. }
  107. var sHCode = $(this).attr("shcode");
  108. if (sHCode != undefined && sHCode == 1) {
  109. test($(this).attr("hitCode"));
  110. }
  111. else if (sHCode == undefined) {
  112. test($(this).attr("hitCode"));
  113. }
  114. }
  115. });
  116. }
  117. case 'wordStyle':
  118. ele.unbind().bind({
  119. 'click': function (e) {
  120. e.stopPropagation();
  121. //plugin.call(code);
  122. //alert($(this).attr("hitCode"));
  123. if (ele.attr("data-lstatus") == "1") {
  124. return;
  125. }
  126. var sHCode = $(this).attr("shcode");
  127. if (sHCode != undefined && sHCode == 1) {
  128. test($(this).attr("hitCode"));
  129. }
  130. else if (sHCode == undefined) {
  131. test($(this).attr("hitCode"));
  132. }
  133. }
  134. });
  135. break;
  136. case 'sentenceStyle':
  137. ele.unbind().bind({
  138. 'click': function (e) {
  139. e.stopPropagation();
  140. //plugin.call(code);
  141. //alert($(this).attr("hitCode"));
  142. if (ele.attr("data-lstatus") == "1") {
  143. return;
  144. }
  145. var sHCode = $(this).attr("shcode");
  146. if (sHCode != undefined && sHCode == 1) {
  147. test($(this).attr("hitCode"));
  148. }
  149. else if (sHCode == undefined) {
  150. test($(this).attr("hitCode"));
  151. }
  152. }
  153. }).prev().filter('.sentImagcs').unbind().bind({
  154. 'click': function (e) {
  155. e.stopPropagation();
  156. //plugin.call(code);
  157. //alert($(this).attr("hitCode"));
  158. if (ele.attr("data-lstatus") == "1") {
  159. return;
  160. }
  161. var sHCode = $(this).attr("shcode");
  162. if (sHCode != undefined && sHCode == 1) {
  163. test($(this).next().attr("hitCode"));
  164. }
  165. else if (sHCode == undefined) {
  166. test($(this).next().attr("hitCode"));
  167. }
  168. }
  169. });
  170. break;
  171. }
  172. }
  173. else {
  174. ele.unbind();
  175. }
  176. }
  177. // #region
  178. // 判断显示层级:0表示最外层;1表示在underlineContent里面;2表示在phraseStyle里面;5表示在underlineContent且phraseStyle在underlineContent里面,7表示在phraseStyle且underlineContent在phraseStyle里面
  179. function cHPhraseStyleFunc(element) {
  180. var ReNumber = 0;
  181. var wFlag=true;
  182. while (wFlag) {
  183. var ClsName = $(element).attr("class");
  184. if ($(element).parent() == null || $(element)[0].tagName.toUpperCase() == "BODY") {
  185. wFlag = false;
  186. return ReNumber;
  187. }
  188. else if (ClsName != undefined && ClsName.indexOf("phraseStyle") > -1) {
  189. wFlag = false;
  190. ReNumber += 1;
  191. }
  192. else if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
  193. wFlag = false;
  194. ReNumber += 2;
  195. }
  196. element = $(element).parent();
  197. };
  198. wFlag = true;
  199. while (wFlag) {
  200. var ClsName = $(element).attr("class");
  201. if ($(element).parent() == null || $(element)[0].tagName.toUpperCase() == "BODY") {
  202. wFlag = false;
  203. return ReNumber;
  204. }
  205. else if (ClsName != undefined && ClsName.indexOf("phraseStyle") > -1) {
  206. wFlag = false;
  207. ReNumber += 3;
  208. return ReNumber;
  209. }
  210. else if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
  211. wFlag = false;
  212. ReNumber += 5;
  213. return ReNumber;
  214. }
  215. element = $(element).parent();
  216. };
  217. return ReNumber;
  218. }
  219. // #endregion
  220. function test(code) {
  221. //alert(code);
  222. cancelBubble();
  223. plugin.call(code);
  224. }