mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-29 03:00:45 -04:00
Since these classes were added, we've decided to handle more of this kind of thing in the bootscss package, so bs3 markup can work without modification in many cases.
53 lines
1.5 KiB
JavaScript
53 lines
1.5 KiB
JavaScript
var bootstrapTabInputBinding = new InputBinding();
|
|
$.extend(bootstrapTabInputBinding, {
|
|
find: function(scope) {
|
|
return $(scope).find('ul.nav.shiny-tab-input');
|
|
},
|
|
getValue: function(el) {
|
|
var anchor = $(el).find('li:not(.dropdown).active').children('a');
|
|
if (anchor.length === 1)
|
|
return this._getTabName(anchor);
|
|
|
|
return null;
|
|
},
|
|
setValue: function(el, value) {
|
|
let self = this;
|
|
let success = false;
|
|
if (value) {
|
|
let anchors = $(el).find('li:not(.dropdown)').children('a');
|
|
anchors.each(function() {
|
|
if (self._getTabName($(this)) === value) {
|
|
$(this).tab('show');
|
|
success = true;
|
|
return false; // Break out of each()
|
|
}
|
|
return true;
|
|
});
|
|
}
|
|
if (!success) {
|
|
// This is to handle the case where nothing is selected, e.g. the last tab
|
|
// was removed using removeTab.
|
|
$(el).trigger("change");
|
|
}
|
|
},
|
|
getState: function(el) {
|
|
return { value: this.getValue(el) };
|
|
},
|
|
receiveMessage: function(el, data) {
|
|
if (data.hasOwnProperty('value'))
|
|
this.setValue(el, data.value);
|
|
},
|
|
subscribe: function(el, callback) {
|
|
$(el).on('change shown.bootstrapTabInputBinding shown.bs.tab.bootstrapTabInputBinding', function(event) {
|
|
callback();
|
|
});
|
|
},
|
|
unsubscribe: function(el) {
|
|
$(el).off('.bootstrapTabInputBinding');
|
|
},
|
|
_getTabName: function(anchor) {
|
|
return anchor.attr('data-value') || anchor.text();
|
|
}
|
|
});
|
|
inputBindings.register(bootstrapTabInputBinding, 'shiny.bootstrapTabInput');
|