mtm_temp.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. function Fill(data) {
  2. var highlightArr = [];
  3. clearHighlight();
  4. $.each(data, function (i, item) {
  5. if (typeof (item.HightCode) != 'undefined' && item.HightCode != null && item.HightCode != "") {
  6. var highlightItem = $('span[id=' + item.HightCode + ']').eq(0);
  7. if (highlightItem.length > 0) {
  8. var hitCode = highlightItem.attr('hitCode');
  9. if (hitCode) {
  10. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  11. }
  12. else {
  13. highlightItem.attr('hitCode', item.SourceCode);
  14. }
  15. highlightArr.push(highlightItem);
  16. }
  17. }
  18. else if (typeof (item.SourceCode) == 'undefined' || item.SourceCode == null || item.SourceCode != "") {
  19. var highlightItem = $('span[kcode*=' + item.SourceCode + ']:first');
  20. if (highlightItem.length > 0) {
  21. var hitCode = highlightItem.attr('hitCode');
  22. if (hitCode) {
  23. highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
  24. }
  25. else {
  26. highlightItem.attr('hitCode', item.SourceCode);
  27. }
  28. highlightArr.push(highlightItem);
  29. }
  30. }
  31. $.each(highlightArr, function (i, item) {
  32. if (item.attr('flag') == 'word') {
  33. bindEvent(item.attr('iskeyklg', 'true').addClass('wordStyle'), true);
  34. }
  35. else if (item.attr('flag') == 'phrase') {
  36. if (item != null && item.attr('separate') != null) {
  37. $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').addClass('phraseStyle');
  38. bindEvent(item, true);
  39. }
  40. else {
  41. bindEvent(item.attr('iskeyklg', 'true').addClass('phraseStyle'), true);
  42. if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
  43. }
  44. }
  45. else if (item.attr('flag') == 'sentence') {
  46. if (item.attr('iskeyklg') == 'true') return;
  47. bindEvent(item.attr('iskeyklg', 'true').addClass('sentenceStyle')
  48. .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
  49. }
  50. });
  51. });
  52. }
  53. function clearHighlight() {
  54. $('span.klg-selected').removeClass('klg-selected');
  55. $('span[iskeyklg="true"]').each(function (i, item) {
  56. $(item).removeAttr('hitCode');
  57. $(item).attr('iskeyklg', 'false');
  58. if ($(item).attr('flag') == 'word') {
  59. $(item).removeClass('wordStyle').unbind();
  60. }
  61. else if ($(item).attr('flag') == 'phrase') {
  62. $(item).removeClass().unbind();
  63. }
  64. else if ($(item).attr('flag') == 'sentence') {
  65. $(item).removeClass('sentenceStyle').unbind();
  66. $(item).prev().filter('img.sentImagcs').remove();
  67. }
  68. })
  69. }
  70. function bindEvent(ele, opt) {
  71. if (opt) {
  72. var className = '';
  73. if (ele.hasClass('phraseStyle'))
  74. className = 'phraseStyle';
  75. else if (ele.hasClass('wordStyle'))
  76. className = 'wordStyle';
  77. else if (ele.hasClass('sentenceStyle'))
  78. className = 'sentenceStyle';
  79. switch (className) {
  80. case 'phraseStyle':
  81. if (ele.attr('separate') != null) {
  82. $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
  83. 'click': function (e) {
  84. e.stopPropagation();
  85. //plugin.call(code);
  86. // alert($(this).attr("hitCode"));
  87. test($(this).attr("hitCode"));
  88. }
  89. });
  90. }
  91. case 'wordStyle':
  92. ele.unbind().bind({
  93. 'click': function (e) {
  94. e.stopPropagation();
  95. //plugin.call(code);
  96. // alert($(this).attr("hitCode"));
  97. test($(this).attr("hitCode"));
  98. }
  99. });
  100. break;
  101. case 'sentenceStyle':
  102. ele.unbind().bind({
  103. 'click': function (e) {
  104. e.stopPropagation();
  105. //plugin.call(code);
  106. //alert($(this).attr("hitCode"));
  107. test($(this).attr("hitCode"));
  108. }
  109. }).prev().filter('.sentImagcs').unbind().bind({
  110. 'click': function (e) {
  111. e.stopPropagation();
  112. //plugin.call(code);
  113. //alert($(this).attr("hitCode"));
  114. test($(this).next().attr("hitCode"));
  115. }
  116. });
  117. break;
  118. }
  119. }
  120. else {
  121. ele.unbind();
  122. }
  123. }
  124. function test(code) {
  125. //alert(code);
  126. cancelBubble();
  127. plugin.call(code);
  128. }