MediaWiki:AdvancedLBSSearch.js: Difference between revisions

No edit summary
No edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
mw.loader.load( ['jquery.ui.autocomplete'] );
//mw.loader.load( ['jquery.ui.autocomplete'] );
//mw.loader.load("https://code.jquery.com/ui/1.12.1/themes/cupertino/jquery-ui.css", "text/css");
//mw.loader.load("/mediawiki/js/jquery/jquery-1.12.4.min.js", "text/javascript");
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");
 


$(function() {
$(function() {
Line 14: Line 19:
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 rev    = dom.getElementsByTagName("rev")[0];
console.log(choices.length);
var choices;
if(rev.innerHTML != undefined)
choices = rev.innerHTML.replace("</li></ul>","").split("</li><li>");
else // for Edge
choices = rev.textContent.replace("</li></ul>","").split("</li><li>");
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)); // 重複を削除
// choices    = Array.from(new Set(choices)); // 重複を削除 Edgeで使えない
console.log(choices.length);
var uniqChoices = Array();
for(var i = 0; i < choices.length; i ++){
if(uniqChoices.indexOf(choices[i]) == -1)
uniqChoices.push(choices[i]);
}
choices = uniqChoices;


$('#advanced_polysaccharide_sequence').autocomplete({
$('#advanced_polysaccharide_sequence').autocomplete({
Line 28: Line 41:
autoFocus: false,
autoFocus: false,
delay:    0,
delay:    0,
minLength: 3
minLength: 4
});
});
} else {
} else {
Line 46: Line 59:
var mainchain = document.getElementById("advanced_polysaccharide_sequence").value;
var mainchain = document.getElementById("advanced_polysaccharide_sequence").value;
var searchchain = mainchain.replace(/\?/g, "\\?");
var searchchain = mainchain.replace(/\?/g, "\\?");
window.open("/wiki/Volatile:ListMol/LBS?my_1=" + searchchain + "&my_2=&my_3=" + mainchain, "_blank");
var nre = ".*";
if(document.getElementById("advanced_search_nre").checked)
nre = "";
window.open("/wiki/Volatile:ListMol/LBS?my_1=Mainchain=" + nre + searchchain + "&my_2=LBS%&my_3=" + mainchain, "_blank");
}
}
});
});

Latest revision as of 23:41, 31 August 2017

//mw.loader.load( ['jquery.ui.autocomplete'] );
//mw.loader.load("https://code.jquery.com/ui/1.12.1/themes/cupertino/jquery-ui.css", "text/css");
//mw.loader.load("/mediawiki/js/jquery/jquery-1.12.4.min.js", "text/javascript");
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");


$(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();
				var dom     = parser.parseFromString(xml, 'text/xml');
				var rev     = dom.getElementsByTagName("rev")[0];
				var choices;
				if(rev.innerHTML != undefined)
					choices = rev.innerHTML.replace("&lt;/li&gt;&lt;/ul&gt;","").split("&lt;/li&gt;&lt;li&gt;");
				else // for Edge
					choices = rev.textContent.replace("</li></ul>","").split("</li><li>");
				for(var i = 0; i < choices.length; i ++){
					choices[i] = choices[i].replace(/^.*=/, "").replace(/,$/,"");
				}
//				choices     = Array.from(new Set(choices)); // 重複を削除 Edgeで使えない
				var uniqChoices = Array();
				for(var i = 0; i < choices.length; i ++){
					if(uniqChoices.indexOf(choices[i]) == -1)
						uniqChoices.push(choices[i]);
				}
				choices = uniqChoices;

				$('#advanced_polysaccharide_sequence').autocomplete({
					source:    choices,
					autoFocus: false,
					delay:     0,
					minLength: 4
				});
			} 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, "\\?");
		var nre = ".*";
		if(document.getElementById("advanced_search_nre").checked)
			nre = "";
		window.open("/wiki/Volatile:ListMol/LBS?my_1=Mainchain=" + nre + searchchain + "&my_2=LBS%&my_3=" + mainchain, "_blank");
	}
});