video_pro/modules/video_pro/_video_pro_widget_jqcloud1....

40 lines
1.3 KiB
Plaintext

<div class="w-video_data video_data-widget-2">
<%= javascript_include_tag 'video_pro/wordcloud2.js' %>
<div style="width: 100%; height: 60vw" class="my_favorite_latin_words jqcloud"><div>
<script>
$(document).ready(function(){
var container = $('[data-subpart-id="{{subpart-id}}"] .my_favorite_latin_words');
var width = container.width();
container.attr('width', width)
var jqcloud_words = {{jqcloud_words}};
var text_map = {};
var max_value = 1;
$.each(jqcloud_words, function(i, v){
if (max_value < v.weight){
max_value = v.weight;
}
});
var list = $.map(jqcloud_words, function(v){
text_map[v.text] = v.link;
return [[v.text, Math.ceil(v.weight/max_value*3), v.link]];
});
container.on('wordcloudstop', function (e) {
$(this).children('span').each(function (i, v) {
var text = $(this).html();
$(this).html('<a title="'+ list[i][0] + '" style="color: inherit" href="' + list[i][2] +'">' + text + '</a>');
});
});
WordCloud(container[0], {
list: list,
gridSize: 3,
weightFactor: jqcloud_words.length * width / 550,
rotateRatio: 0,
shuffle: false,
drawOutOfBound: false,
shrinkToFit: true,
shape: 'square'
});
})
</script>
</div>