add final fantasy data
This commit is contained in:
@@ -227,6 +227,7 @@
|
||||
<Content Include="Scripts\jquery.validate.min.js" />
|
||||
<Content Include="Scripts\jquery.validate.unobtrusive.js" />
|
||||
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
|
||||
<Content Include="Scripts\lodestoneapi.js" />
|
||||
<Content Include="Scripts\main.js" />
|
||||
<Content Include="Scripts\main.min.js">
|
||||
<DependentUpon>main.js</DependentUpon>
|
||||
|
||||
@@ -21,9 +21,10 @@ namespace AboutMe.Mvc.Web
|
||||
"~/Scripts/modernizr-*"));
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/site").Include(
|
||||
"~/Scripts/main.js",
|
||||
"~/Scripts/Mustache.js",
|
||||
"~/Scripts/GithubActivity.js"));
|
||||
"~/Scripts/GithubActivity.js",
|
||||
"~/Scripts/lodestoneapi.js",
|
||||
"~/Scripts/main.js"));
|
||||
|
||||
bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
|
||||
"~/Scripts/bootstrap.js",
|
||||
|
||||
Binary file not shown.
150
src/AboutMe.Mvc.Web/Scripts/lodestoneapi.js
Normal file
150
src/AboutMe.Mvc.Web/Scripts/lodestoneapi.js
Normal file
@@ -0,0 +1,150 @@
|
||||
/* --------------------------------------------------
|
||||
* XIVPads.com (v5) - Lodestone API (Javascript)
|
||||
* This runs off: XIVSync.com
|
||||
*
|
||||
* > requires jquery.
|
||||
* --------------------------------------------------
|
||||
* API calls will match those of the PHP API, so for
|
||||
* example, you can do:
|
||||
*
|
||||
* LodestoneAPI.Search.Character(Name, Server);
|
||||
* LodestoneAPI.Search.Character(123456);
|
||||
*/
|
||||
var LodestoneAPI =
|
||||
{
|
||||
logEnabled: false,
|
||||
|
||||
paths:
|
||||
{
|
||||
sync: 'http://xivsync.com',
|
||||
search: '/search/character',
|
||||
character: '/character/get',
|
||||
},
|
||||
|
||||
// Initialize
|
||||
init: function()
|
||||
{
|
||||
LodestoneAPI.log('init()');
|
||||
|
||||
// check for jquery.
|
||||
if (typeof window.jQuery == 'undefined') {
|
||||
console.error('Please include https://jquery.com/, this API requires it.');
|
||||
}
|
||||
},
|
||||
|
||||
// wrapper for ajaxing
|
||||
get: function(url, data, callback)
|
||||
{
|
||||
LodestoneAPI.log('get', url);
|
||||
LodestoneAPI.log('get', data);
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
data: data,
|
||||
crossDomain: true,
|
||||
dataType: 'json',
|
||||
success: function(data)
|
||||
{
|
||||
LodestoneAPI.log('get > return', data);
|
||||
if (data.ok) {
|
||||
return callback(data.data);
|
||||
}
|
||||
|
||||
console.error('XIVSync API Error: '+ data.msg);
|
||||
return callback(false);
|
||||
},
|
||||
error: function(data, status, error)
|
||||
{
|
||||
console.error('Error attempting to ajax to: ' + url);
|
||||
console.error(status);
|
||||
console.error(error);
|
||||
console.error('Please open an issue on Github: https://github.com/viion/XIVPads-LodestoneAPI');
|
||||
return callback(false);
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
// Logging
|
||||
log: function(text, data)
|
||||
{
|
||||
if (LodestoneAPI.logEnabled) {
|
||||
if (data) {
|
||||
console.log('[LODESTONE-API]', text, data);
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('[LODESTONE-API]', text);
|
||||
}
|
||||
},
|
||||
|
||||
// Search for thingz
|
||||
Search:
|
||||
{
|
||||
Character: function(nameOrId, server, callback, recurrsive)
|
||||
{
|
||||
if (!callback || typeof callback !== 'function') {
|
||||
console.error('Callback function not defined.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!nameOrId) {
|
||||
console.error('Name or ID is empty');
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
// if numeric, can just get character
|
||||
// else we have to search!
|
||||
if ($.isNumeric(nameOrId))
|
||||
{
|
||||
LodestoneAPI.log('search > character > isNumeric = true =', nameOrId);
|
||||
|
||||
var url = LodestoneAPI.paths.sync + LodestoneAPI.paths.character,
|
||||
data = { lodestone: nameOrId }
|
||||
|
||||
LodestoneAPI.get(url, data, function(data)
|
||||
{
|
||||
// if empty
|
||||
if (data.length == 0) {
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
return callback(data);
|
||||
});
|
||||
}
|
||||
else if (!recurrsive)
|
||||
{
|
||||
LodestoneAPI.log('search > character > isNumeric = false =', nameOrId);
|
||||
|
||||
var url = LodestoneAPI.paths.sync + LodestoneAPI.paths.search,
|
||||
data = { name: nameOrId, server: server }
|
||||
|
||||
// get
|
||||
LodestoneAPI.get(url, data, function(data)
|
||||
{
|
||||
// if empty
|
||||
if (data.length == 0) {
|
||||
return callback(false);
|
||||
}
|
||||
|
||||
|
||||
// Try match server and name
|
||||
for (var i in data)
|
||||
{
|
||||
var c = data[i];
|
||||
if (c.name == nameOrId && c.world == server && $.isNumeric(c.i));
|
||||
{
|
||||
// recurrsive callback on character using id
|
||||
LodestoneAPI.log('search > character > recurrsion with id:', c.id);
|
||||
LodestoneAPI.Search.Character(c.id, null, callback, true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
LodestoneAPI.log('search > character > no results for: ', nameOrId);
|
||||
return callback(false);
|
||||
});
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
LodestoneAPI.init();
|
||||
@@ -49,4 +49,30 @@ jQuery(document).ready(function ($) {
|
||||
limit: 20 // optional
|
||||
});
|
||||
|
||||
var buildFinalFantasy = function (data) {
|
||||
return "<aside class=\"list aside section\"> \
|
||||
<div class=\"section-inner\"> \
|
||||
<h2 class=\"heading\">Final Fantasy Data</h2> \
|
||||
<div class=\"content\"> \
|
||||
<ul class=\"list-unstyled\"> \
|
||||
<li><i class=\"fa \"></i><img src=\"" + data.avatar + "\" </li> \
|
||||
<li><i class=\"fa \"></i> Name: <a href=\"http://na.finalfantasyxiv.com/lodestone/character/8696200/\"> " + data.name + "</a> </li> \
|
||||
<li><i class=\"fa \"></i> Active Level: " + data.activeLevel + " </li> \
|
||||
<li><i class=\"fa \"></i> Active Job: " + data.activeJob+ " </li> \
|
||||
<li><i class=\"fa \"></i> Current City: " + data.city+ " </li> \
|
||||
<li><i class=\"fa \"></i> World: " + data.world + " </li> \
|
||||
</ul> \
|
||||
</div> \
|
||||
</div> \
|
||||
</aside>";
|
||||
};
|
||||
|
||||
LodestoneAPI.Search.Character(8696200, null, function (data) {
|
||||
if (data !== undefined && data !== null) {
|
||||
$('.secondary').append(buildFinalFantasy(data));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user