mtm_temp.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. test($(this).attr("hitCode"));
  89. }
  90. });
  91. }
  92. case 'wordStyle':
  93. ele.unbind().bind({
  94. 'click': function (e) {
  95. e.stopPropagation();
  96. //plugin.call(code);
  97. //alert($(this).attr("hitCode"));
  98. test($(this).attr("hitCode"));
  99. }
  100. });
  101. break;
  102. case 'sentenceStyle':
  103. ele.unbind().bind({
  104. 'click': function (e) {
  105. e.stopPropagation();
  106. //plugin.call(code);
  107. //alert($(this).attr("hitCode"));
  108. test($(this).attr("hitCode"));
  109. }
  110. }).prev().filter('.sentImagcs').unbind().bind({
  111. 'click': function (e) {
  112. e.stopPropagation();
  113. //plugin.call(code);
  114. //alert($(this).attr("hitCode"));
  115. test($(this).next().attr("hitCode"));
  116. }
  117. });
  118. break;
  119. }
  120. }
  121. else {
  122. ele.unbind();
  123. }
  124. }
  125. function test(code) {
  126. //alert(code);
  127. cancelBubble();
  128. plugin.call(code);
  129. }