MediaWiki:AdvancedLBSSearch.js: Difference between revisions
Jcblmaster (talk | contribs) Created page with "mw.loader.load( ['jquery.ui.autocomplete'] ); $(function() { var url = '/mediawiki/api.php?action=query&prop=revisions&redirects=1&titles=Persist:ListMainchain&rvprop=conten..." |
Jcblmaster (talk | contribs) No edit summary |
||
| Line 12: | Line 12: | ||
if(this.status == HTTP_STATUS_OK) { | if(this.status == HTTP_STATUS_OK) { | ||
// success | // success | ||
var xml = this.response.trim( | var xml = this.response.trim(); | ||
var parser = new DOMParser(); | var parser = new DOMParser(); | ||
console.log(xml); | |||
var dom = parser.parseFromString(xml, 'text/xml'); | var dom = parser.parseFromString(xml, 'text/xml'); | ||
var choices = dom.getElementsByTagName("rev")[0].innerHTML.replace(",</li></ul>","").split("</li><li>"); | var choices = dom.getElementsByTagName("rev")[0].innerHTML.replace(",</li></ul>","").split("</li><li>"); | ||
console.log(choices.length); | |||
for(var i = 0; i < choices.length; i ++){ | for(var i = 0; i < choices.length; i ++){ | ||
choices[i] = choices[i].replace(/^.*=/, "").replace(/,$/,""); | choices[i] = choices[i].replace(/^.*=/, "").replace(/,$/,""); | ||
} | } | ||
choices = Array.from(new Set(choices)); // 重複を削除 | |||
console.log(choices.length); | |||
$('#advanced_polysaccharide_sequence').autocomplete({ | $('#advanced_polysaccharide_sequence').autocomplete({ | ||
| Line 24: | Line 28: | ||
autoFocus: false, | autoFocus: false, | ||
delay: 0, | delay: 0, | ||
minLength: | minLength: 3 | ||
}); | }); | ||
} else { | } else { | ||
Revision as of 09:48, 24 April 2017
mw.loader.load( ['jquery.ui.autocomplete'] );
$(function() {
var url = '/mediawiki/api.php?action=query&prop=revisions&redirects=1&titles=Persist:ListMainchain&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();
console.log(xml);
var dom = parser.parseFromString(xml, 'text/xml');
var choices = dom.getElementsByTagName("rev")[0].innerHTML.replace(",</li></ul>","").split("</li><li>");
console.log(choices.length);
for(var i = 0; i < choices.length; i ++){
choices[i] = choices[i].replace(/^.*=/, "").replace(/,$/,"");
}
choices = Array.from(new Set(choices)); // 重複を削除
console.log(choices.length);
$('#advanced_polysaccharide_sequence').autocomplete({
source: choices,
autoFocus: false,
delay: 0,
minLength: 3
});
} 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);
var submit = document.getElementById("advanced_search_button");
submit.onclick = function(){
var mainchain = document.getElementById("advanced_polysaccharide_sequence").value;
var searchchain = mainchain.replace(/\?/g, "\\?");
window.open("/wiki/Volatile:ListMol/LBS?my_1=" + searchchain + "&my_2=&my_3=" + mainchain, "_blank");
}
});