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,26 +141,49 @@ function WordCloudMain(el) { ...@@ -147,26 +141,49 @@ 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.
try { this.ajax_url = this.wordCloudEl.data('ajax-url');
this.configJson = JSON.parse(this.wordCloudEl.find('.word_cloud_div').html());
} catch (err) {
logme('ERROR: Incorrect JSON config was given.');
logme(err.message);
return; // Hide WordCloud container before Ajax request done
} this.wordCloudEl.hide();
if (this.configJson.submitted) { // Retriveing response from the server as an AJAX request. Attach a callback that will
this.showWordCloud(this.configJson); // be fired on server's response.
$.postWithPrefix(
_this.ajax_url + '/' + 'get_state', null,
function (response) {
if (response.status !== 'success') {
logme('ERROR: ' + response.error);
return; return;
} }
this.inputSaveEl = $(el).find('input.save'); _this.configJson = response;
}
)
.done(function(){
// Show WordCloud container after Ajax request done
_this.wordCloudEl.show();
try {
_this.configJson = _this.configJson || JSON.parse(_this.wordCloudEl.find('.word_cloud_div').html());
} catch (err) {
logme('ERROR: Incorrect JSON config was given.');
logme(err.message);
return;
}
if (_this.configJson.submitted) {
_this.showWordCloud(_this.configJson);
// Get the URL to which we will post the users words. return;
this.ajax_url = this.wordCloudEl.data('ajax-url'); }
});
this.inputSaveEl = $(el).find('input.save');
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