Commit 67635842 by Anto Stupak Committed by Vasyl Nakvasiuk

Word cloud JS: data is not loaded without page refresh. Fixed. Also was fixed…

Word cloud JS: data is not loaded without page refresh. Fixed. Also was fixed bug, when font-size is 0
parent 72b094e5
...@@ -40,8 +40,6 @@ WordCloudMain.prototype = { ...@@ -40,8 +40,6 @@ WordCloudMain.prototype = {
this.wordCloudEl.find('#input-cloud-section').hide(); this.wordCloudEl.find('#input-cloud-section').hide();
console.log('response: ', response);
words = response.top_words; words = response.top_words;
maxSize = 0; maxSize = 0;
...@@ -63,13 +61,9 @@ WordCloudMain.prototype = { ...@@ -63,13 +61,9 @@ WordCloudMain.prototype = {
}) })
.font('Impact') .font('Impact')
.fontSize(function (d) { .fontSize(function (d) {
var size; var size = (d.size / maxSize) * 100;
size = (d.size / maxSize) * 100;
if (size < 20) { size = size >= 15 ? size : 15;
return 0;
}
return size; return size;
}) })
...@@ -147,9 +141,33 @@ function WordCloudMain(el) { ...@@ -147,9 +141,33 @@ function WordCloudMain(el) {
hash += 1; hash += 1;
this.hash = hash; this.hash = hash;
this.configJson = null; // Get the URL to which we will post the users words.
this.ajax_url = this.wordCloudEl.data('ajax-url');
// Hide WordCloud container before Ajax request done
this.wordCloudEl.hide();
// Retriveing response from the server as an AJAX request. Attach a callback that will
// be fired on server's response.
$.postWithPrefix(
_this.ajax_url + '/' + 'get_state', null,
function (response) {
if (response.status !== 'success') {
logme('ERROR: ' + response.error);
return;
}
_this.configJson = response;
}
)
.done(function(){
// Show WordCloud container after Ajax request done
_this.wordCloudEl.show();
try { try {
this.configJson = JSON.parse(this.wordCloudEl.find('.word_cloud_div').html()); _this.configJson = _this.configJson || JSON.parse(_this.wordCloudEl.find('.word_cloud_div').html());
} catch (err) { } catch (err) {
logme('ERROR: Incorrect JSON config was given.'); logme('ERROR: Incorrect JSON config was given.');
logme(err.message); logme(err.message);
...@@ -157,16 +175,15 @@ function WordCloudMain(el) { ...@@ -157,16 +175,15 @@ function WordCloudMain(el) {
return; return;
} }
if (this.configJson.submitted) { if (_this.configJson.submitted) {
this.showWordCloud(this.configJson); _this.showWordCloud(_this.configJson);
return; return;
} }
this.inputSaveEl = $(el).find('input.save'); });
// Get the URL to which we will post the users words. this.inputSaveEl = $(el).find('input.save');
this.ajax_url = this.wordCloudEl.data('ajax-url');
this.inputSaveEl.on('click', function () { this.inputSaveEl.on('click', function () {
_this.submitAnswer(); _this.submitAnswer();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment