Fix #676: getId(el) not being used in output binding

This commit is contained in:
Joe Cheng
2015-08-03 10:20:56 -07:00
committed by Joe Cheng
parent 8773b1b38f
commit 431b345c82
6 changed files with 58 additions and 26 deletions

View File

@@ -3004,6 +3004,9 @@ var OutputBindingAdapter = function(el, binding) {
}
};
(function() {
this.getId = function() {
return this.binding.getId(this.el);
};
this.onValueChange = function(data) {
this.binding.onValueChange(this.el, data);
};
@@ -4632,6 +4635,15 @@ function initShiny() {
}
exports.initializeInputs = initializeInputs;
function getIdFromEl(el) {
var $el = $(el);
var bindingAdapter = $el.data("shiny-output-binding");
if (!bindingAdapter)
return null;
else
return bindingAdapter.getId();
}
// Initialize all input objects in the document, before binding
initializeInputs(document);
@@ -4642,16 +4654,18 @@ function initShiny() {
// The server needs to know the size of each image and plot output element,
// in case it is auto-sizing
$('.shiny-image-output, .shiny-plot-output').each(function() {
var id = getIdFromEl(this);
if (this.offsetWidth !== 0 || this.offsetHeight !== 0) {
initialValues['.clientdata_output_' + this.id + '_width'] = this.offsetWidth;
initialValues['.clientdata_output_' + this.id + '_height'] = this.offsetHeight;
initialValues['.clientdata_output_' + id + '_width'] = this.offsetWidth;
initialValues['.clientdata_output_' + id + '_height'] = this.offsetHeight;
}
});
function doSendImageSize() {
$('.shiny-image-output, .shiny-plot-output').each(function() {
var id = getIdFromEl(this);
if (this.offsetWidth !== 0 || this.offsetHeight !== 0) {
inputs.setInput('.clientdata_output_' + this.id + '_width', this.offsetWidth);
inputs.setInput('.clientdata_output_' + this.id + '_height', this.offsetHeight);
inputs.setInput('.clientdata_output_' + id + '_width', this.offsetWidth);
inputs.setInput('.clientdata_output_' + id + '_height', this.offsetHeight);
}
});
$('.shiny-bound-output').each(function() {
@@ -4691,28 +4705,30 @@ function initShiny() {
var lastKnownVisibleOutputs = {};
// Set initial state of outputs to hidden, if needed
$('.shiny-bound-output').each(function() {
var id = getIdFromEl(this);
if (isHidden(this)) {
initialValues['.clientdata_output_' + this.id + '_hidden'] = true;
initialValues['.clientdata_output_' + id + '_hidden'] = true;
} else {
lastKnownVisibleOutputs[this.id] = true;
initialValues['.clientdata_output_' + this.id + '_hidden'] = false;
lastKnownVisibleOutputs[id] = true;
initialValues['.clientdata_output_' + id + '_hidden'] = false;
}
});
// Send update when hidden state changes
function doSendOutputHiddenState() {
var visibleOutputs = {};
$('.shiny-bound-output').each(function() {
delete lastKnownVisibleOutputs[this.id];
var id = getIdFromEl(this);
delete lastKnownVisibleOutputs[id];
// Assume that the object is hidden when width and height are 0
var hidden = isHidden(this), evt = {
type: 'shiny:visualchange',
visible: !hidden
};
if (hidden) {
inputs.setInput('.clientdata_output_' + this.id + '_hidden', true);
inputs.setInput('.clientdata_output_' + id + '_hidden', true);
} else {
visibleOutputs[this.id] = true;
inputs.setInput('.clientdata_output_' + this.id + '_hidden', false);
visibleOutputs[id] = true;
inputs.setInput('.clientdata_output_' + id + '_hidden', false);
}
var $this = $(this);
evt.binding = $this.data('shiny-output-binding');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long