Jaxel
Well-known member
Javascript is still new to me, especially jQuery... so I'm wondering if someone knowledgeable would help me out with this... Basically lets say I have the following HTML on my page...
I want to run some jQuery on this html... The jQuery should search for all elements of the class "streamTime" and run some code on it after the page has loaded...
This is what I got so far... but I dont know how to do the rest...
Basically, the question is, how do I use data-service and data-serviceval in the javascript? Right now I am forcing the justintv check with peacefuljay... I want this done automatically.
HTML:
<div class="streamTime" data-service="justintv" data-serviceval="peacefuljay">
there is some text here...
</div>
<div class="streamTime" data-service="justintv" data-serviceval="jaxelrod">
there is some text here too...
</div>
I want to run some jQuery on this html... The jQuery should search for all elements of the class "streamTime" and run some code on it after the page has loaded...
Code:
IF (data-service == justintv AND data-serviceval)
{
GET http://api.justin.tv/api/stream/summary.json?channel={data-serviceval}
REPLACE contents of streamTime div with "viewers_count" from JSON
}
PHP:
/** @param {jQuery} $ jQuery Object */
!function($, window, document, _undefined)
{
XenForo.StreamTime = function($time)
{
var query = 'http://api.justin.tv/api/stream/summary.json?jsonp=?';
args = { 'channel':'peacefuljay' };
$.getJSON(query, args, function(data)
{
var str = '<b>Currently Live</b> ('+data['viewers_count']+' viewers)';
$time.find('.streamTime').html(str);
});
}
// *********************************************************************
XenForo.register('#eventsUpcoming li', 'XenForo.StreamTime');
}
(jQuery, this, document);