m (fix typo) |
m (add BBRadio fields) |
||
(4 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
$('div.expandgallery').click(function(){ | $('div.expandgallery').click(function(){ | ||
var t = $(this); | var t = $(this); | ||
Line 6: | Line 5: | ||
var msg = $(etext).html(); | var msg = $(etext).html(); | ||
var query = $(edata).find('.expandgallery-query').html(); | |||
var displayed = parseInt($(edata).find('.expandgallery-displayed').html(),10); | var displayed = parseInt($(edata).find('.expandgallery-displayed').html(),10); | ||
var count_all = parseInt($(edata).find('.expandgallery-count_all').html(),10); | var count_all = parseInt($(edata).find('.expandgallery-count_all').html(),10); | ||
Line 16: | Line 16: | ||
var source = $(edata).find('.expandgallery-source').html(); | var source = $(edata).find('.expandgallery-source').html(); | ||
var section = $(edata).find('.expandgallery-section').html(); | var section = $(edata).find('.expandgallery-section').html(); | ||
var sort = $(edata).find('.expandgallery- | var season = $(edata).find('.expandgallery-season').html(); | ||
var widths = $(edata).find('.expandgallery-widths').html(); | var episode = $(edata).find('.expandgallery-episode').html(); | ||
var sort = $(edata).find('.expandgallery-sort').html(); | |||
var widths = parseInt($(edata).find('.expandgallery-widths').html(),10); | |||
// build query | // build query | ||
var url = '//blazblue.wiki/api.php' | var url = '//blazblue.wiki/api.php' | ||
+ '?action=parse&text={{ | + '?action=parse&text={{' + query | ||
+ '|offset=' + displayed | + '|offset=' + displayed | ||
+ '|limit=' + load_limit; | + '|limit=' + load_limit; | ||
if (character !== undefined) { url = url + '|character=' + character; } | if (character !== undefined && character !== "") { url = url + '|character=' + character; } | ||
if (cameo !== undefined) { url = url + '|cameo=' + cameo; } | if (cameo !== undefined && cameo !== "") { url = url + '|cameo=' + cameo; } | ||
if (location !== undefined) { url = url + '|location=' + location; } | if (location !== undefined && location !== "") { url = url + '|location=' + location; } | ||
if (weapon !== undefined) { url = url + '|weapon=' + weapon; } | if (weapon !== undefined && weapon !== "") { url = url + '|weapon=' + weapon; } | ||
if (artist !== undefined) { url = url + '|artist=' + artist; } | if (artist !== undefined && artist !== "") { url = url + '|artist=' + artist; } | ||
if (source !== undefined) { url = url + '|source=' + source; } | if (source !== undefined && source !== "") { url = url + '|source=' + source; } | ||
if (section !== undefined) { url = url + '|section=' + section; } | if (section !== undefined && section !== "") { url = url + '|section=' + section; } | ||
if (sort !== undefined) { url = url + '|sort=' + sort; } | if (season !== undefined && season !== "") { url = url + '|season=' + season; } | ||
if (widths !== undefined) { url = url + '|widths=' + widths; } | if (episode !== undefined && episode !== "") { url = url + '|episode=' + episode; } | ||
if (sort !== undefined && sort !== "") { url = url + '|sort=' + sort; } | |||
if (widths !== undefined && !isNaN(widths)) { url = url + '|widths=' + widths; } | |||
url = url + '}}&contentmodel=wikitext'; | url = url + '}}&contentmodel=wikitext'; | ||
console.log(url); | console.log(url); | ||
Line 61: | Line 65: | ||
// if there's nothing left to display, disable the load more element | // if there's nothing left to display, disable the load more element | ||
if (displayed >= count_all) { $(t).css("display","none"); } | if ((displayed >= count_all) | ||
|| (html === undefined) | |||
|| (html === "") | |||
) { $(t).css("display","none"); } | |||
} | } | ||
}).done( function ( data ) { | }).done( function ( data ) { |
Latest revision as of 00:01, 13 June 2020
$('div.expandgallery').click(function(){
var t = $(this);
var etext = $(t).find('.expandgallery-text');
var edata = $(t).find('.expandgallery-data');
var msg = $(etext).html();
var query = $(edata).find('.expandgallery-query').html();
var displayed = parseInt($(edata).find('.expandgallery-displayed').html(),10);
var count_all = parseInt($(edata).find('.expandgallery-count_all').html(),10);
var load_limit = parseInt($(edata).find('.expandgallery-load_limit').html(),10);
var character = $(edata).find('.expandgallery-character').html();
var cameo = $(edata).find('.expandgallery-cameo').html();
var location = $(edata).find('.expandgallery-location').html();
var weapon = $(edata).find('.expandgallery-weapon').html();
var artist = $(edata).find('.expandgallery-artist').html();
var source = $(edata).find('.expandgallery-source').html();
var section = $(edata).find('.expandgallery-section').html();
var season = $(edata).find('.expandgallery-season').html();
var episode = $(edata).find('.expandgallery-episode').html();
var sort = $(edata).find('.expandgallery-sort').html();
var widths = parseInt($(edata).find('.expandgallery-widths').html(),10);
// build query
var url = '//blazblue.wiki/api.php'
+ '?action=parse&text={{' + query
+ '|offset=' + displayed
+ '|limit=' + load_limit;
if (character !== undefined && character !== "") { url = url + '|character=' + character; }
if (cameo !== undefined && cameo !== "") { url = url + '|cameo=' + cameo; }
if (location !== undefined && location !== "") { url = url + '|location=' + location; }
if (weapon !== undefined && weapon !== "") { url = url + '|weapon=' + weapon; }
if (artist !== undefined && artist !== "") { url = url + '|artist=' + artist; }
if (source !== undefined && source !== "") { url = url + '|source=' + source; }
if (section !== undefined && section !== "") { url = url + '|section=' + section; }
if (season !== undefined && season !== "") { url = url + '|season=' + season; }
if (episode !== undefined && episode !== "") { url = url + '|episode=' + episode; }
if (sort !== undefined && sort !== "") { url = url + '|sort=' + sort; }
if (widths !== undefined && !isNaN(widths)) { url = url + '|widths=' + widths; }
url = url + '}}&contentmodel=wikitext';
console.log(url);
$(etext).html("Loading images...");
$.ajax({
url: url,
data: { format: 'json' },
dataType: 'jsonp',
success: function (data) {
var text;
var html;
var gallery;
// single out the html returned from the ajax query
text = data.parse.text["*"];
console.log(text);
// append new images to gallery
gallery = $(t).prev();
html = $(text).find(".gallery").html();
$(gallery).find(".gallery").append(html);
// update existing count of displayed images
displayed = displayed + load_limit;
$(edata).find('.expandgallery-displayed').html(displayed);
// if there's nothing left to display, disable the load more element
if ((displayed >= count_all)
|| (html === undefined)
|| (html === "")
) { $(t).css("display","none"); }
}
}).done( function ( data ) {
// replace loading text with its original text
$(etext).html(msg);
});
});