← Back
Editing: thk-highlight.min.js
var searchJcheck=function(callback){if(window.jQuery){callback(jQuery);}else{window.setTimeout(function(){searchJcheck(callback);},100);}};searchJcheck(function($){jQuery.fn.highlight=function(pat){function innerHighlight(node,pat){var skip=0;if(node.nodeType==3){var pos=node.data.toUpperCase().indexOf(pat);pos-=(node.data.substr(0,pos).toUpperCase().length-node.data.substr(0,pos).length);if(pos>=0){var spannode=document.createElement('span');spannode.className='highlight';var middlebit=node.splitText(pos);var endbit=middlebit.splitText(pat.length);var middleclone=middlebit.cloneNode(true);spannode.appendChild(middleclone);middlebit.parentNode.replaceChild(spannode,middlebit);skip=1;}} else if(node.nodeType==1&&node.childNodes&&!/(script|style)/i.test(node.tagName)){for(var i=0;i<node.childNodes.length;++i){i+=innerHighlight(node.childNodes[i],pat);}} return skip;} return this.length&&pat&&pat.length?this.each(function(){innerHighlight(this,pat.toUpperCase());}):this;};jQuery.fn.removeHighlight=function(){return this.find("span.highlight").each(function(){this.parentNode.firstChild.nodeName;with(this.parentNode){replaceChild(this.firstChild,this);normalize();}}).end();};(function(a,n){var t=function(a){var t=this;a=a||{},t.options=n.extend(!0,{widthMode:"toHankaku",kanaMode:!1,hankakuKatakanaMustDie:!0,convert:{punctuation:!0,tilda:!0,exclamation:!0,question:!0,space:!0,hyphen:!0},zenkakuHyphen:"ー",zenkakuChilda:"〜"},a),t.regexp={hankaku:/[A-Za-z0-9#$%&\\()*+,.\/<>\[\]{}=@;:_\^`]/g,zenkaku:/[A-Za-z0-9#$%&\()*+,./<>[]{}=@;:_^`]/g,katakana:/[ァ-ン]/g,hiragana:/[ぁ-ん]/g},t.fnc={toHankaku:function(a){return String.fromCharCode(a.charCodeAt(0)-65248)},toZenkaku:function(a){return String.fromCharCode(a.charCodeAt(0)+65248)},toKatakana:function(a){return String.fromCharCode(a.charCodeAt(0)+96)},toHiragana:function(a){return String.fromCharCode(a.charCodeAt(0)-96)}},t.list={toHankaku:[{zenkaku:/”/g,hankaku:'"'},{zenkaku:/’/g,hankaku:"'"},{zenkaku:/ /g,hankaku:" ",type:"space"},{zenkaku:/¥/g,hankaku:"¥"},{zenkaku:/[ー―‐−]/g,hankaku:"-",type:"hyphen"},{zenkaku:/|/g,hankaku:"|"},{zenkaku:/[~〜]/g,hankaku:"~",type:"tilda"},{zenkaku:/[、]/g,hankaku:",",type:"punctuation"},{zenkaku:/[。]/g,hankaku:".",type:"punctuation"},{zenkaku:/!/g,hankaku:"!",type:"exclamation"},{zenkaku:/?/g,hankaku:"?",type:"question"}],toZenkaku:[{hankaku:/"/g,zenkaku:"”"},{hankaku:/'/g,zenkaku:"’"},{hankaku:/ /g,zenkaku:" ",type:"space"},{hankaku:/[¥\\]/g,zenkaku:"¥"},{hankaku:/[\-ー]/g,zenkaku:t.options.zenkakuHyphen,type:"hyphen"},{hankaku:/\|/g,zenkaku:"|"},{hankaku:/~/g,zenkaku:t.options.zenkakuChilda,type:"tilda"},{hankaku:/!/g,zenkaku:"!",type:"exclamation"},{hankaku:/\?/g,zenkaku:"?",type:"question"}]},this.hankakuKanaList=[/ガ/g,/ギ/g,/グ/g,/ゲ/g,/ゴ/g,/ザ/g,/ジ/g,/ズ/g,/ゼ/g,/ゾ/g,/ダ/g,/ヂ/g,/ヅ/g,/デ/g,/ド/g,/バ/g,/ビ/g,/ブ/g,/ベ/g,/ボ/g,/パ/g,/ピ/g,/プ/g,/ペ/g,/ポ/g,/ア/g,/イ/g,/ウ/g,/エ/g,/オ/g,/カ/g,/キ/g,/ク/g,/ケ/g,/コ/g,/サ/g,/シ/g,/ス/g,/セ/g,/ソ/g,/タ/g,/チ/g,/ツ/g,/テ/g,/ト/g,/ナ/g,/ニ/g,/ヌ/g,/ネ/g,/ノ/g,/ハ/g,/ヒ/g,/フ/g,/ヘ/g,/ホ/g,/マ/g,/ミ/g,/ム/g,/メ/g,/モ/g,/ヤ/g,/ユ/g,/ヨ/g,/ラ/g,/リ/g,/ル/g,/レ/g,/ロ/g,/ワ/g,/ヲ/g,/ン/g,/ァ/g,/ィ/g,/ゥ/g,/ェ/g,/ォ/g,/ャ/g,/ュ/g,/ョ/g,/゙/g,/゚/g,/。/g,/、/g],this.zenkakuKanaList=["ガ","ギ","グ","ゲ","ゴ","ザ","ジ","ズ","ゼ","ゾ","ダ","ヂ","ヅ","デ","ド","バ","ビ","ブ","ベ","ボ","パ","ピ","プ","ペ","ポ","ア","イ","ウ","エ","オ","カ","キ","ク","ケ","コ","サ","シ","ス","セ","ソ","タ","チ","ツ","テ","ト","ナ","ニ","ヌ","ネ","ノ","ハ","ヒ","フ","ヘ","ホ","マ","ミ","ム","メ","モ","ヤ","ユ","ヨ","ラ","リ","ル","レ","ロ","ワ","ヲ","ン","ァ","ィ","ゥ","ェ","ォ","ャ","ュ","ョ","゛","゜","。","、"]};t.prototype.toHankaku=function(a,t){var k,e,g=this,u=0;for(t=n.extend(!0,g.options,t||{}),a=a.replace(g.regexp.zenkaku,g.fnc.toHankaku),k=g.list.toHankaku,e=k.length;e>u;u+=1)"string"==typeof k[u].type?t.convert[k[u].type]&&(a=a.replace(k[u].zenkaku,k[u].hankaku)):a=a.replace(k[u].zenkaku,k[u].hankaku);return a},t.prototype.toZenkaku=function(a,t){var k,e,g=this,u=0;for(t=n.extend(!0,g.options,t||{}),a=a.replace(g.regexp.hankaku,g.fnc.toZenkaku),k=g.list.toZenkaku,e=k.length;e>u;u+=1)"string"==typeof k[u].type?t.convert[k[u].type]&&(a=a.replace(k[u].hankaku,k[u].zenkaku)):a=a.replace(k[u].hankaku,k[u].zenkaku);return a},t.prototype.killHankakuKatakana=function(a){var n=this,t=0,k=n.hankakuKanaList.length;if(/[ヲ-゚]/.test(a))for(;k>t;t+=1)a=a.replace(n.hankakuKanaList[t],n.zenkakuKanaList[t]);return a},t.prototype.toHiragana=function(a){var n=this;return a.replace(n.regexp.katakana,n.fnc.toHiragana)},t.prototype.toKatakana=function(a){var n=this;return a.replace(n.regexp.hiragana,n.fnc.toKatakana)},t.prototype.autoConvert=function(a,t){var k,e=this;return t=n.extend(!0,e.options,t),t.widthMode&&"toHankaku"===t.widthMode?k=e.toHankaku(a,t.convert):"toZenkaku"===t.widthMode&&(k=e.toZenkaku(a,t.convert)),t.widthMode&&t.hankakuKatakanaMustDie&&(k=e.killHankakuKatakana(k)),t.kanaMode&&"toHiragana"===t.kanaMode?k=e.toHiragana(k):t.kanaMode&&"toKatakana"===t.kanaMode&&(k=e.toKatakana(k)),k},n.SuperTextConverter=function(a){return new t(a)},n.fn.superTextConverter=function(a,k){return n(this).each(function(){n(this).on("blur",function(){var e=new t,g="TEXTAREA"===this.tagName?n(this).text():n(this).val(),u=e.autoConvert(g,a,k);g!==u&&(n(this).val(u),n(this).trigger("superTextConverted",e.options))})}),this}})(this,jQuery);jQuery(function($){var words=[];var stc=$.SuperTextConverter();words=$("#search-result").val().replace(/^\s+|\s+$/g,"").replace(/\s+/g," ").split(" ");for(i in words){if(words[i]!=""){$("section").highlight(words[i]);if(words[i]!=stc.toHankaku(words[i]))$("section").highlight(stc.toHankaku(words[i]));if(words[i]!=stc.toHiragana(words[i]))$("section").highlight(stc.toHiragana(words[i]));if(words[i]!=stc.toKatakana(words[i]))$("section").highlight(stc.toKatakana(words[i]));if(words[i]!=stc.killHankakuKatakana(words[i]))$("section").highlight(stc.killHankakuKatakana(words[i]));if(words[i]!=stc.toHiragana(stc.killHankakuKatakana(words[i])))$("section").highlight(stc.toHiragana(stc.killHankakuKatakana(words[i])));}}});});
Save File
Cancel