MediaWiki:LBSSearch.js: Difference between revisions
Jcblmaster (talk | contribs) mNo edit summary |
Jcblmaster (talk | contribs) No edit summary |
||
Line 1: | Line 1: | ||
mw.loader.load("http://jcbl.jp/mediawiki/js/jquery/jquery-ui.css", "text/css"); | |||
mw.loader.load("http://jcbl.jp/mediawiki/js/jquery/jquery-ui.min.js", "text/javascript"); | |||
addOnloadHook(init) | addOnloadHook(init) | ||
Line 4: | Line 7: | ||
function init() | function init() | ||
{ | { | ||
var button = document.getElementById(" | var button = document.getElementById("sequence_search_button"); | ||
button.onclick = function(){ | |||
sequenceSearch(); | |||
} | |||
button = document.getElementById("advanced_search_button"); | |||
button.onclick = function(){ | button.onclick = function(){ | ||
var mainchain = document.getElementById("advanced_polysaccharide_sequence").value; | |||
var searchchain = mainchain.replace(/\?/g, "\\?"); | |||
var nre = ".*"; | |||
if(document.getElementById("advanced_search_nre").checked) | |||
nre = "^"; | |||
chainSearch(nre + searchchain + ".*", mainchain, "AdvResult"); | |||
} | } | ||
Line 30: | Line 42: | ||
choices = rev.textContent.replace("<ui><ll>","").replace("</li></ul>","").split("</li><li>"); | choices = rev.textContent.replace("<ui><ll>","").replace("</li></ul>","").split("</li><li>"); | ||
var uniqChoices = Array(); | |||
for(var i = 0; i < choices.length; i ++){ | for(var i = 0; i < choices.length; i ++){ | ||
var w = choices[i].trim().split("=="); | var w = choices[i].trim().split("=="); | ||
allChain.push({"id":w[0], "chain":w[1], "img":w[2]}); | allChain.push({"id":w[0], "chain":w[1], "img":w[2]}); | ||
if(uniqChoices.indexOf(w[1]) == -1) | |||
uniqChoices.push(w[1]); | |||
} | } | ||
$('#advanced_polysaccharide_sequence').autocomplete({ | |||
source: uniqChoices, | |||
autoFocus: false, | |||
delay: 0, | |||
minLength: 4 | |||
}); | |||
// ボタン有効化 | // ボタン有効化 | ||
var button = document.getElementById(" | var button = document.getElementById("sequence_search_button"); | ||
button.disabled = false; | |||
button = document.getElementById("advanced_search_button"); | |||
button.disabled = false; | button.disabled = false; | ||
var loading = document.getElementById("loading"); | var loading = document.getElementById("loading"); | ||
Line 52: | Line 76: | ||
} | } | ||
function | function sequenceSearch() | ||
{ | { | ||
var ops = []; | var ops = []; | ||
Line 81: | Line 105: | ||
return; | return; | ||
} | } | ||
chainSearch(mainchain, searchtext, "PolySeqResult"); | |||
} | |||
function chainSearch(mainchain, searchtext, resultDiv) | |||
{ | |||
// search | // search | ||
var result = Array(); | var result = Array(); | ||
var regexp = new RegExp(mainchain); | var regexp = new RegExp(mainchain, "i"); | ||
for(var i = 0; i < allChain.length; i ++){ | for(var i = 0; i < allChain.length; i ++){ | ||
if(regexp.test(allChain[i]["chain"])){ | if(regexp.test(allChain[i]["chain"])){ | ||
result[allChain[i]["id"]] = allChain[i]["img"].replace(/</g,"<").replace(/>/g,">") | result[allChain[i]["id"]] = allChain[i]["img"].replace(/</g,"<").replace(/>/g,">") + allChain[i]["chain"]; | ||
} | } | ||
} | } | ||
Line 93: | Line 121: | ||
// display | // display | ||
var html = "Search Text: " + searchtext + "<br />"; | var html = "Search Text: " + searchtext + "<br />"; | ||
html += "Search Expression: " + mainchain + "<br />"; | |||
var keys = Object.keys(result); | var keys = Object.keys(result); | ||
html += keys.length + " Hit(s).<hr />"; | html += keys.length + " Hit(s) / " + allChain.length + ".<hr />"; | ||
html += "<ol>"; | html += "<ol>"; | ||
for(var i = 0; i < keys.length; i ++){ | for(var i = 0; i < keys.length; i ++){ | ||
Line 102: | Line 130: | ||
html += "</ol>"; | html += "</ol>"; | ||
var div = document.getElementById( | var div = document.getElementById(resultDiv); | ||
div.innerHTML = html; | div.innerHTML = html; | ||
div.style.display = "block"; | div.style.display = "block"; | ||
} | } |
Revision as of 05:59, 24 February 2018
mw.loader.load("http://jcbl.jp/mediawiki/js/jquery/jquery-ui.css", "text/css"); mw.loader.load("http://jcbl.jp/mediawiki/js/jquery/jquery-ui.min.js", "text/javascript"); addOnloadHook(init) allChain = Array(); function init() { var button = document.getElementById("sequence_search_button"); button.onclick = function(){ sequenceSearch(); } button = document.getElementById("advanced_search_button"); button.onclick = function(){ var mainchain = document.getElementById("advanced_polysaccharide_sequence").value; var searchchain = mainchain.replace(/\?/g, "\\?"); var nre = ".*"; if(document.getElementById("advanced_search_nre").checked) nre = "^"; chainSearch(nre + searchchain + ".*", mainchain, "AdvResult"); } // get all chain var url = '/mediawiki/api.php?action=query&prop=revisions&redirects=1&titles=Persist:ListAllChains&rvprop=content&rvparse=1&format=xml'; var xmlHttpRequest = new XMLHttpRequest(); xmlHttpRequest.onreadystatechange = function() { var READYSTATE_COMPLETED = 4; if(this.readyState == READYSTATE_COMPLETED){ var HTTP_STATUS_OK = 200; if(this.status == HTTP_STATUS_OK) { // success var xml = this.response.trim(); var parser = new DOMParser(); var dom = parser.parseFromString(xml, 'text/xml'); var rev = dom.getElementsByTagName("rev")[0]; var choices; if(rev.innerHTML != undefined) choices = rev.innerHTML.replace("<ul><li>","").replace("</li></ul>","").split("</li><li>"); else // for Edge choices = rev.textContent.replace("<ui><ll>","").replace("</li></ul>","").split("</li><li>"); var uniqChoices = Array(); for(var i = 0; i < choices.length; i ++){ var w = choices[i].trim().split("=="); allChain.push({"id":w[0], "chain":w[1], "img":w[2]}); if(uniqChoices.indexOf(w[1]) == -1) uniqChoices.push(w[1]); } $('#advanced_polysaccharide_sequence').autocomplete({ source: uniqChoices, autoFocus: false, delay: 0, minLength: 4 }); // ボタン有効化 var button = document.getElementById("sequence_search_button"); button.disabled = false; button = document.getElementById("advanced_search_button"); button.disabled = false; var loading = document.getElementById("loading"); loading.style.display = "none"; } else { // error console.log('retrieving is failed. ' + this.status + ':' + this.statusText + "/" + this.readyState); } } } // search xmlHttpRequest.open('GET', url, true); xmlHttpRequest.responseType = 'text'; xmlHttpRequest.send(null); } function sequenceSearch() { var ops = []; ops[0] = document.getElementById("nre"); ops[1] = document.getElementById("4th"); ops[2] = document.getElementById("3th"); ops[3] = document.getElementById("2nd"); ops[4] = document.getElementById("1st"); ops[5] = document.getElementById("re"); var st; var mc; var searchtext = ""; var mainchain = ""; var counter = 0; for(var i = 0; i < ops.length; i ++){ st = ops[i].options[ops[i].selectedIndex].innerHTML; mc = ops[i].options[ops[i].selectedIndex].value; searchtext += st; mainchain += mc; if(i == 0 || i == ops.length-1) continue; if(st === "Others") counter ++; } if(counter >= 3){ alert("3つ以上のあいまい条件指定はできません。"); return; } chainSearch(mainchain, searchtext, "PolySeqResult"); } function chainSearch(mainchain, searchtext, resultDiv) { // search var result = Array(); var regexp = new RegExp(mainchain, "i"); for(var i = 0; i < allChain.length; i ++){ if(regexp.test(allChain[i]["chain"])){ result[allChain[i]["id"]] = allChain[i]["img"].replace(/</g,"<").replace(/>/g,">") + allChain[i]["chain"]; } } // display var html = "Search Text: " + searchtext + "<br />"; html += "Search Expression: " + mainchain + "<br />"; var keys = Object.keys(result); html += keys.length + " Hit(s) / " + allChain.length + ".<hr />"; html += "<ol>"; for(var i = 0; i < keys.length; i ++){ html += "<li><a href=\"/wiki/" + keys[i] + "\" target=\"_blank\"><big><tt>" + keys[i] + "</tt></big></a>" + result[keys[i]] + "</li>"; } html += "</ol>"; var div = document.getElementById(resultDiv); div.innerHTML = html; div.style.display = "block"; }