mtm_temp.js 5.6 KB

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