| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- /*高亮文本标注*/
- function Fill(data) {
- var wordFlag = false;
- var phraseFlag = false;
- var sentenceFlag = false;
- var highlightArr = [];
- clearHighlight();
- $.each(data, function (i, item) {
- if (typeof (item.HightCode) != 'undefined' && item.HightCode != null && item.HightCode != "") {
- var highlightItem = $('span[id=' + item.HightCode + ']').eq(0);
- if (highlightItem.length > 0) {
- var hitCode = highlightItem.attr('hitCode');
- if (hitCode) {
- highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
- }
- else {
- highlightItem.attr('hitCode', item.SourceCode);
- }
- highlightArr.push(highlightItem);
- }
- }
- else if (typeof (item.SourceCode) == 'undefined' || item.SourceCode == null || item.SourceCode != "") {
- var highlightItem = $('span[kcode*=' + item.SourceCode + ']:first');
- if (highlightItem.length > 0) {
- var hitCode = highlightItem.attr('hitCode');
- if (hitCode) {
- highlightItem.attr('hitCode', hitCode + "|" + item.SourceCode);
- }
- else {
- highlightItem.attr('hitCode', item.SourceCode);
- }
- highlightArr.push(highlightItem);
- }
- }
- $.each(highlightArr, function (i, item) {
- if (item.attr('flag') == 'word') {
- wordFlag = true;
- bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "wordStyle").addClass('wordStyle'), true);
- }
- else if (item.attr('flag') == 'phrase') {
- phraseFlag = true;
- if (item != null && item.attr('separate') != null) {
- $("span[separate=" + item.attr('separate') + "]").attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle');
- bindEvent(item, true);
- }
- else {
- bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "phraseStyle").addClass('phraseStyle'), true);
- if ($(item).parent().attr('iskeyklg') == 'true' && $(item).parent().attr('flag') == 'phrase') $(item).addClass('border1')
- }
- }
- else if (item.attr('flag') == 'sentence') {
- if (item.attr('iskeyklg') == 'true') return;
- sentenceFlag = true;
- bindEvent(item.attr('iskeyklg', 'true').attr("hitstyle", "sentenceStyle").addClass('sentenceStyle')
- .before('<img src="file:///android_asset/js/sentenceIco.png" class="sentImagcs">'), true);
- }
- });
- });
- // 绑定横线内处理
- $.each($(document).find("u,span,p"), function (Iindex, Iitem) {
- var ClsName = $(Iitem).attr("class");
- if ($(Iitem).attr("ulflag") == undefined) {
- $(Iitem).attr("ulflag", "0");
- }
- if ($(Iitem).attr("shcode") == undefined) {
- $(Iitem).attr("shcode", 1);
- }
- if ($(Iitem).attr("showflag") == undefined) {
- $(Iitem).attr("showflag", "1");
- }
- if (ClsName != undefined && ClsName.indexOf("underlineContent") > -1) {
- $(Iitem).attr("ulflag", "1");
- $.each($(Iitem).find("u,span,p"), function (index, element) {
- if ($(element).attr("ulflag") == undefined) {
- $(element).attr("ulflag", "1");
- }
- if ($(element).attr("shcode") == undefined) {
- $(element).attr("shcode", 1);
- }
- if ($(element).attr("showflag") == undefined) {
- $(element).attr("showflag", "1");
- }
- });
- }
- });
- if (typeof (showGLWorld) == "function") {
- showGLWorld(wordFlag, phraseFlag, sentenceFlag);
- }
- }
- function clearHighlight() {
- $('span.klg-selected').removeClass('klg-selected');
- $('span[iskeyklg="true"]').each(function (i, item) {
- $(item).removeAttr('hitCode');
- $(item).attr('iskeyklg', 'false');
- if ($(item).attr('flag') == 'word') {
- $(item).removeClass('wordStyle').unbind();
- }
- else if ($(item).attr('flag') == 'phrase') {
- $(item).removeClass().unbind();
- }
- else if ($(item).attr('flag') == 'sentence') {
- $(item).removeClass('sentenceStyle').unbind();
- $(item).prev().filter('img.sentImagcs').remove();
- }
- })
- }
- function bindEvent(ele, opt) {
- if (opt) {
- var className = '';
- if (ele.hasClass('phraseStyle'))
- className = 'phraseStyle';
- else if (ele.hasClass('wordStyle'))
- className = 'wordStyle';
- else if (ele.hasClass('sentenceStyle'))
- className = 'sentenceStyle';
- switch (className) {
- case 'phraseStyle':
- if (ele.attr('separate') != null) {
- $("span[separate=" + ele.attr('separate') + "]").unbind().bind({
- 'click': function (e) {
- e.stopPropagation();
- //plugin.call(code);
- //alert($(this).attr("hitCode"));
- var sHCode = $(this).attr("shcode");
- if (sHCode == 1) {
- test($(this).attr("hitCode"));
- }
- }
- });
- }
- case 'wordStyle':
- ele.unbind().bind({
- 'click': function (e) {
- e.stopPropagation();
- //plugin.call(code);
- //alert($(this).attr("hitCode"));
- var sHCode = $(this).attr("shcode");
- if (sHCode == 1) {
- test($(this).attr("hitCode"));
- }
- }
- });
- break;
- case 'sentenceStyle':
- ele.unbind().bind({
- 'click': function (e) {
- e.stopPropagation();
- //plugin.call(code);
- //alert($(this).attr("hitCode"));
- var sHCode = $(this).attr("shcode");
- if (sHCode == 1) {
- test($(this).attr("hitCode"));
- }
- }
- }).prev().filter('.sentImagcs').unbind().bind({
- 'click': function (e) {
- e.stopPropagation();
- //plugin.call(code);
- //alert($(this).attr("hitCode"));
- var sHCode = $(this).attr("shcode");
- if (sHCode == 1) {
- test($(this).next().attr("hitCode"));
- }
- }
- });
- break;
- }
- }
- else {
- ele.unbind();
- }
- }
- function test(code) {
- //alert(code);
- cancelBubble();
- plugin.call(code);
- }
|