Gazelle/static/functions/artist_cloud.js

105 lines
2.1 KiB
JavaScript
Raw Normal View History

2012-06-28 08:00:13 +00:00
(function($) {
2012-06-29 08:00:08 +00:00
var LIMIT = 10;
2012-06-28 08:00:13 +00:00
var artistId, artistName;
var artistTags;
2013-04-19 08:00:55 +00:00
$(document).ready(function() {
2012-06-28 08:00:13 +00:00
initArtistCloud();
2013-04-19 08:00:55 +00:00
});
2012-06-28 08:00:13 +00:00
function initArtistCloud() {
2013-04-19 08:00:55 +00:00
$("#currentArtist").text();
2012-06-28 08:00:13 +00:00
artistTags = $("#artistTags").find('ul');
artistName = $("#content").find("h2:first").text();
artistId = window.location.search.split("?id=")[1];
addArtistMain(artistName);
loadArtists();
}
function loadArtists() {
2012-06-29 08:00:08 +00:00
$.getJSON('ajax.php?action=similar_artists&id='+artistId+'&limit='+LIMIT, function(data) {
var first = true;
2013-04-19 08:00:55 +00:00
var ratio;
2012-06-29 08:00:08 +00:00
$.each(data, function(key, val) {
2013-04-19 08:00:55 +00:00
if (first) {
2012-06-29 08:00:08 +00:00
ratio = val['score'] / 300;
first = false;
}
var score = val['score'] / ratio;
score = score <= 150 ? 150 : score;
addArtist(val['id'], val['name'], score);
2013-04-19 08:00:55 +00:00
});
2012-06-28 08:00:13 +00:00
createCloud();
});
}
function addArtist(id, name, score) {
2013-04-19 08:00:55 +00:00
var item = $('<li><a style="color:#007DC6;" data-weight="' + score + '">' + name + '</a></li>');
2012-06-28 08:00:13 +00:00
2013-04-19 08:00:55 +00:00
$(item).click(function(e) {
e.preventDefault();
2012-06-28 08:00:13 +00:00
reinit(id, name);
2013-04-19 08:00:55 +00:00
});
2012-06-28 08:00:13 +00:00
artistTags.append(item);
}
function addArtistMain(name) {
2013-04-19 08:00:55 +00:00
var item = $('<li><a style="color: #007DC6;" data-weight="350">' + name + '</a></li>');
2013-02-22 08:00:24 +00:00
2012-06-28 08:00:13 +00:00
$("#currentArtist").attr('href', 'artist.php?id=' + artistId);
$("#currentArtist").text(artistName);
2013-02-22 08:00:24 +00:00
2012-06-28 08:00:13 +00:00
$(item).click(function(e) {
2013-04-19 08:00:55 +00:00
e.preventDefault();
2012-06-28 08:00:13 +00:00
reinit(artistId, name);
2013-04-19 08:00:55 +00:00
});
2012-06-28 08:00:13 +00:00
2013-04-19 08:00:55 +00:00
artistTags.append(item);
2013-02-22 08:00:24 +00:00
}
2012-06-28 08:00:13 +00:00
function reinit(id, name) {
artistId = id;
artistName = name;
artistTags.empty();
addArtistMain(artistName);
loadArtists();
}
function createCloud() {
2013-04-19 08:00:55 +00:00
if (!$('#similarArtistsCanvas').tagcanvas({
// textFont: 'Impact,"Arial Black",sans-serif',
wheelZoom: false,
freezeActive: true,
weightSize: 0.15,
interval: 20,
textFont: null,
textColour: null,
textHeight: 25,
outlineColour: '#f96',
outlineThickness: 4,
maxSpeed: 0.04,
minBrightness: 0.1,
depth: 0.92,
pulsateTo: 0.2,
pulsateTime: 0.75,
initial: [0.1,-0.1],
decel: 0.98,
reverse: true,
shadow: '#ccf',
shadowBlur: 3,
weight : true,
weightFrom: 'data-weight'
},'artistTags')) {
// something went wrong, hide the canvas container
$('#flip_view_2').hide();
}
2012-06-28 08:00:13 +00:00
}
} ) ( jQuery );