First, include the jQuery library, jQuery.JamCity javascript (jQuery.JamCity.js or jQuery.JamCity.min.js) and the jQuery.JamCity CSS (jmc_styles.css) on the page(s) where you want to use jQuery.JamCity.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript"></script> <script src="jQuery.JamCity.min.js" type="text/javascript"></script> <link rel="stylesheet" href="css/jmc_styles.min.css" type="text/css">
Then, add a container div with an ID to your HTML so we can output jQuery.JamCity somewhere.
<div id="JMC_Container"›‹/div>
Then, initialize jQuery.JamCity. Put the following code before the closing tag of your body ().
<script type="text/javascript"> $(document).ready(function(){ $("#JMC_Container").JamCity({ apiKey: '{your_apiKey}', username: '{your_username}' }); }); </script>
NOTE: Please do not use my API key (c5d7bcc2600127f2c24e5b50c5f8ea5a) on your site. This API key is used only for demo purposes. You can generate your own key for free here http://www.last.fm/api/account! Thank you!
$("#demo1").JamCity({ apiKey: '', username: '', fetch: 5, contentType: 'recentTracks', artSize: 'medium', cssTooltips: true, cssThemeClass: null, _blankLinks: true, refreshResults: true, refreshResultsInterval: 600000, noAlbumArtImg: 'http://placehold.it/250x250&text=No Art', noResults: 'Sorry, nothing was found...', songsFetched: function () {}, htmlBuilt: function () {} });
Required params:
apiKey
- [string]
Your Last.fm API key (easily setup free: http://www.last.fm/api/account )
username
- [string]
Your Last.fm username (ie. http://www.last.fm/user/USERNAME )
Optional params:
fetch
- [integer]
The number of tracks to fetch/display. Default is 5.
contentType
- [string]
The content to display, accepted values are recentTracks, lovedTracks, topAlbums, topTracks, topArtists, weeklyArtistChart, weeklyAlbumChart, and weeklyTrackChart. Default is recentTracks.
artSize
- [string]
The album art size to use, accepted values are small, medium, and large. Default is medium.
cssTooltips
- [boolean]
Display the content name/plays/etc. in a CSS tooltip. Default is true.
cssThemeClass
- [string]
The CSS class attached to the displayed content, accepted value is jamCityTheme_whiteVinyl if you want the built in white theme. This can be changed to something custom. Default is null (a dark theme). (NOTE: If you change this to something custom, be sure to update your CSS file)
_blankLinks
- [boolean]
Open all links in the content in a new window/tab. Default is true.
refreshResults
- [boolean]
Auto refresh the content for new results without reloading the page. Default is true..
refreshResultsInterval
- [integer]
If refreshResults is true, how often do you want to pull new results (in milliseconds). Default is 600000 (60 seconds). (NOTE: For your protection against the Last.FM API, this number can't be below 10000).
noAlbumArtImg
- [string]
The default image to use if there is no album art for the track. Default is http://placehold.it/250x250&text=No Art..
noResults
- [string]
Text to display when no results are found. Default is 'Sorry, nothing was found...'..
songsFetched
- [function]
On complete of fetching the songs, run a function or do something else..
htmlBuilt
- [function]
On complete of building the HTML, run a function or do something else..
<ul id="jamCityWrapper" class="jamCitySize_{size}"> <li> <a href="{Link}" data-tip="{name}" class="case {nowplaying}" target="_blank"> <div class="overlay"></div> <div class="cover"><img src="{art}"></div> <div class="vinyl"></div> </a> </li> <li> <a href="{Link}" data-tip="{name}" class="case {nowplaying}" target="_blank"> <div class="overlay"></div> <div class="cover"><img src="{art}"></div> <div class="vinyl"></div> </a> </li> <!-- etc... --> </ul>
$("#demo1").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro' });
$("#demo2").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', fetch: 8, artSize: 'small' });
$("#demo3").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', artSize: 'large', fetch: 3, refreshResults: false });
$("#demo4").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', contentType: 'topArtists', fetch: 4, htmlBuilt: function () { console.log('This is a htmlBuilt callback function!'); } });
$("#demo5").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', contentType: 'weeklyAlbumChart', _blankLinks: false, fetch: 4 });
$("#demo6").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', contentType: 'topAlbums', cssThemeClass: 'jamCityTheme_whiteVinyl', fetch: 8 });
$("#demo7").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'bluetidepro', contentType: 'topTracks', fetch: 2, refreshResults: true, refreshResultsInterval: 400000 });
$("#demo8").JamCity({ apiKey: 'c5d7bcc2600127f2c24e5b50c5f8ea5a', username: 'St4rStruck4VT', noResults: 'Sorry homie, ain\'t no loved tracks here!', contentType: 'lovedTracks' });
jQuery.JamCity : v. 2.0 (Dec 11th, 2013)
Refactored the whole plugin, added new content types, and cleaned up the themes.
jQuery.JamCity : v. 1.1 (May 15th, 2012)
Added two new options (`refreshResults` and `refreshResultsInt`), so you can pull for new results. This is great for the contentType `recentTracks` to have it dynamically show what you're listening to. Cleaned up a few small miscellaneousness bugs.
jQuery.JamCity : v. 1.0 (May 14th, 2012)
First build of jQuery.JamCity.
Where do I get my own Last.FM api key?
It's very easy, and FREE. Simply signup for an API key (be sure to be logged into Last.FM) here (http://www.last.fm/api/account).
I don't use Last.FM, can I get this working for Spotify?
Yes! What you can do is connect your Spotify account to "scrobble" what you play from Spotify to Last.FM (this is built into Spotify already). You will still need to create a Last.FM account to connect everything but once you do that, everything you play on Spotify will automatically be sent to your Last.FM account, then used by jQuery.JamCity!
Where should I report any bugs?
Please report all jQuery.JamCity bugs on the github 'Issues' page. Thanks!
I have a feature request, what do I do?
Post it on the jQuery.JamCity github 'Issues' page. Thanks!
Code inspired from "Last.fm Plugin for jQuery" and "jQuery.nowPlaying"
Contact me (or tweet @bluetidepro) if you have any questions about jQuery.JamCity.
The MIT License (MIT)
Copyright (C) 2013 Zach Reed, http://iamzachreed.com/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.