MediaWiki:Gadget-cs.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
No edit summary
No edit summary
 
(14 intermediate revisions by the same user not shown)
Line 5: Line 5:
    var citeIDNum = citeID.slice(23); //get number at end of ID
    var citeIDNum = citeID.slice(23); //get number at end of ID
    var toggle = $(".mw-customtoggle-cs" + citeIDNum);
    var toggle = $(".mw-customtoggle-cs" + citeIDNum);
    console.log(toggle);
    $(toggle).attr("aria-controls",citeID);
    $(toggle).attr("aria-controls",citeID);
$(toggle).attr("title","Show " + $(toggle).attr("title").slice(5));
$(toggle).attr("title","Show " + $(toggle).attr("title").slice(7).replace('"', '\\"'));
$(toggle).attr("aria-label",$(toggle).attr("title"));
$(toggle).attr("aria-label",$(toggle).attr("title"));
});
});
Line 16: Line 15:
var toggle = $(".mw-customtoggle-cs" + citeIDNum);
var toggle = $(".mw-customtoggle-cs" + citeIDNum);
$(toggle).attr("aria-expanded","true");
$(toggle).attr("aria-expanded","true");
$(toggle).attr("title","Hide " + $(toggle).attr("title").slice(5));
$(toggle).attr("title","Hide " + $(toggle).attr("title").slice(5).replace('"', '\\"'));
$(toggle).attr("aria-label",$(toggle).attr("title"));
$(toggle).attr("aria-label",$(toggle).attr("title"));
if ($($(this).children(".csl")).length) {
if ($($(this).children(".csl")).length) {
var csLoader = $(this).children(".csl")[0];
var csLoader = $(this).children(".csl")[0];
var json = $(csLoader).children(".csd")[0].innerHTML;
var json = $(csLoader).children(".csd")[0].innerHTML;
    var params = {
var storedText = sessionStorage.getItem('CS-' + json);
action: 'parse',
if (storedText != null) {
text: '{{#invoke:cite source|generateCollapsibleTextFromJSON|' + json + ' }}',
csLoader.innerHTML = storedText;
format: 'json'
};
var api = new mw.Api();
api.get(params).done(function(data) {
var response = $(data.parse.text['*']);
var citationText = $(response).children("p")[0].innerHTML;
csLoader.innerHTML = citationText;
$(csLoader).removeClass("csl");
$(csLoader).removeClass("csl");
sessionStorage.setItem('CS-' + json, citationText);
} else {
});
    var params = {
action: 'parse',
text: '{{#invoke:cite source|generateCollapsibleTextFromJSON|' + json + ' }}',
format: 'json',
useskin: 'timeless',
mobileformat: 'false'
};
var api = new mw.Api();
api.get(params).done(function(data) {
var response = $(data.parse.text['*']);
var citationText = $($(response).children("section")[0]).children("p")[0].innerHTML;
csLoader.innerHTML = citationText;
$(csLoader).removeClass("csl");
sessionStorage.setItem('CS-' + json, citationText);
});
}
}
}
});
});
Line 41: Line 48:
var toggle = $(".mw-customtoggle-cs" + citeIDNum);
var toggle = $(".mw-customtoggle-cs" + citeIDNum);
$(toggle).attr("aria-expanded","false");
$(toggle).attr("aria-expanded","false");
$(toggle).attr("title","Show " + $(toggle).attr("title").slice(5));
$(toggle).attr("title","Show " + $(toggle).attr("title").slice(5).replace('"', '\\"'));
$(toggle).attr("aria-label",$(toggle).attr("title"));
$(toggle).attr("aria-label",$(toggle).attr("title"));
});
});

Latest revision as of 22:08, 9 April 2024

mw.hook('wikipage.content').add(function(){
	$('.cse').each(function(i, obj) {
	    $(obj).attr("aria-hidden","true");
	    var citeID = $(obj).attr('id');
	    var citeIDNum = citeID.slice(23); //get number at end of ID
	    var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	    $(toggle).attr("aria-controls",citeID);
		$(toggle).attr("title","Show " + $(toggle).attr("title").slice(7).replace('"', '\\"'));
		$(toggle).attr("aria-label",$(toggle).attr("title"));
	});
}); 
$(".cse").on("afterExpand.mw-collapsible", function() {
	$(this).attr("aria-hidden","false");
	var citeIDNum = $(this).attr('id').slice(23); //get number at end of ID
	var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	$(toggle).attr("aria-expanded","true");
	$(toggle).attr("title","Hide " + $(toggle).attr("title").slice(5).replace('"', '\\"'));
	$(toggle).attr("aria-label",$(toggle).attr("title"));
	if ($($(this).children(".csl")).length) {
		var csLoader = $(this).children(".csl")[0];
		var json = $(csLoader).children(".csd")[0].innerHTML;
		var storedText = sessionStorage.getItem('CS-' + json);
		if (storedText != null) {
			csLoader.innerHTML = storedText;
			$(csLoader).removeClass("csl");
		} else {
		    var params = {
				action: 'parse',
				text: '{{#invoke:cite source|generateCollapsibleTextFromJSON|' + json + ' }}',
				format: 'json',
				useskin: 'timeless',
				mobileformat: 'false'
			};
			var api = new mw.Api();
			api.get(params).done(function(data) {
				var response = $(data.parse.text['*']);
				var citationText = $($(response).children("section")[0]).children("p")[0].innerHTML;
				csLoader.innerHTML = citationText;
				$(csLoader).removeClass("csl");
				sessionStorage.setItem('CS-' + json, citationText);
			});
		}
	}
});
$(".cse").on("afterCollapse.mw-collapsible", function() {
	$(this).attr("aria-hidden","true");
	var citeIDNum = $(this).attr('id').slice(23); //get number at end of ID
	var toggle = $(".mw-customtoggle-cs" + citeIDNum);
	$(toggle).attr("aria-expanded","false");
	$(toggle).attr("title","Show " + $(toggle).attr("title").slice(5).replace('"', '\\"'));
	$(toggle).attr("aria-label",$(toggle).attr("title"));
});