-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: shinyWidgets | ||
Title: Custom Inputs Widgets for Shiny | ||
Version: 0.3.1.110 | ||
Version: 0.3.2 | ||
Authors@R: c( | ||
person("Victor", "Perrier", email = "[email protected]", role = c("aut", "cre")), | ||
person("Fanny", "Meyer", email = "[email protected]", role = c("aut")), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// multi input binding | ||
var exportsMulti = window.Shiny = window.Shiny || {}; | ||
var $escapeMulti = exportsMulti.$escape = function(val) { | ||
return val.replace(/([!"#$%&'()*+,.\/:;<=>?@\[\\\]^`{|}~])/g, '\\$1'); | ||
}; | ||
|
||
var multiInputBinding = new Shiny.InputBinding(); | ||
$.extend(multiInputBinding, { | ||
find: function(scope) { | ||
return $(scope).find('.multijs'); | ||
}, | ||
getId: function(el) { | ||
return el.id; | ||
}, | ||
getValue: function(el) { | ||
return $(el).val(); | ||
}, | ||
setValue: function setValue(el, value) { | ||
$(el).val(value).change(); | ||
}, | ||
getState: function(el) { | ||
// Store options in an array of objects, each with with value and label | ||
var options = new Array(el.length); | ||
for (var i = 0; i < el.length; i++) { | ||
options[i] = { value: el[i].value, | ||
label: el[i].label }; | ||
} | ||
|
||
return { | ||
label: $(el).parent().find('label[for="' + $escapeMulti(el.id) + '"]').text(), | ||
value: this.getValue(el), | ||
options: options | ||
}; | ||
}, | ||
receiveMessage: function(el, data) { | ||
var $el = $(el); | ||
|
||
// This will replace all the options | ||
if (data.hasOwnProperty('options')) { | ||
// Clear existing options and add each new one | ||
$el.empty().append(data.options); | ||
//$(el).trigger( 'change' ); | ||
} | ||
|
||
if (data.hasOwnProperty('value')) { | ||
this.setValue(el, data.value); | ||
} | ||
|
||
if (data.hasOwnProperty('label')) $(el).parent().parent().find('label[for="' + $escapeMulti(el.id) + '"]').text(data.label); | ||
|
||
//$(el.id).trigger( 'change' ); | ||
$(el).trigger('change'); | ||
}, | ||
subscribe: function(el, callback) { | ||
$(el).on('change', function (event) { | ||
//$(el.id).trigger( 'change' ); | ||
//$(el).trigger('change'); | ||
callback(); | ||
}); | ||
}, | ||
unsubscribe: function(el) { | ||
$(el).off('.multiInputBinding'); | ||
} | ||
}); | ||
Shiny.inputBindings.register(multiInputBinding, 'shiny.multiInput'); |
Oops, something went wrong.