Skip to content

Commit

Permalink
Merge pull request #3 from DivadNojnarg/path-issue1
Browse files Browse the repository at this point in the history
initializeInputs for more complex bindings
  • Loading branch information
pvictor authored Jan 10, 2025
2 parents 3365526 + 579bcd5 commit 6cc1628
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
36 changes: 19 additions & 17 deletions inst/htmlwidgets/gridstack.js

Large diffs are not rendered by default.

34 changes: 18 additions & 16 deletions srcjs/widgets/gridstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,33 @@ HTMLWidgets.widget({

type: "output",

factory: function(el, width, height) {
factory: function (el, width, height) {

var grid;

return {

renderValue: function(x) {
renderValue: function (x) {

el.classList.add("grid-stack");
el.classList.add("grid-stack-edit");
el.style.background = x.bg;
el.innerHTML = x.html;

grid = GridStack.init(x.options, el);
grid.on("resizestop", function(event, el) {
grid.on("resizestop", function (event, el) {
window.dispatchEvent(new Event("resize"));
});
if (HTMLWidgets.shinyMode) {
var $all = $(el);
Shiny.initializeInputs($all);
Shiny.bindAll($all);
}
grid.on("added", function(event, items) {
grid.on("added", function (event, items) {
if (HTMLWidgets.shinyMode) {
items.forEach(function(item) {
items.forEach(function (item) {
var $item = $(item);
Shiny.initializeInputs($item);
Shiny.bindAll($item);
});
}
Expand All @@ -44,19 +46,19 @@ HTMLWidgets.widget({
if (HTMLWidgets.shinyMode) {
var serializedFull = grid.save(true, true);
Shiny.setInputValue(el.id + "_layout", serializedFull);
grid.on("added removed change", function(event, items) {
grid.on("added removed change", function (event, items) {
serializedFull = grid.save(true, true);
Shiny.setInputValue(el.id + "_layout", serializedFull);
});
}

},

getWidget: function() {
getWidget: function () {
return grid;
},

resize: function(width, height) {
resize: function (width, height) {

// TODO: code to re-render the widget with a new size

Expand All @@ -70,63 +72,63 @@ HTMLWidgets.widget({
if (HTMLWidgets.shinyMode) {

// add a widget
Shiny.addCustomMessageHandler("gridstackr-add-widget", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-add-widget", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.addWidget(obj.data.options);
}
});

// compact layout
Shiny.addCustomMessageHandler("gridstackr-compact", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-compact", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.compact(obj.data);
}
});

// disable
Shiny.addCustomMessageHandler("gridstackr-disable", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-disable", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.disable();
}
});

// enable
Shiny.addCustomMessageHandler("gridstackr-enable", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-enable", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.enable();
}
});

// enableMove
Shiny.addCustomMessageHandler("gridstackr-enable-move", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-enable-move", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.enableMove(obj.data.doEnable);
}
});

// enableResize
Shiny.addCustomMessageHandler("gridstackr-enable-resize", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-enable-resize", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.enableResize(obj.data.doEnable);
}
});

// removeAll
Shiny.addCustomMessageHandler("gridstackr-remove-all", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-remove-all", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
grid.removeAll();
}
});

// removeWidget
Shiny.addCustomMessageHandler("gridstackr-remove-widget", function(obj) {
Shiny.addCustomMessageHandler("gridstackr-remove-widget", function (obj) {
var grid = utils.getWidget(obj.id);
if (typeof grid != "undefined") {
var container = document.getElementById(obj.id);
Expand Down

0 comments on commit 6cc1628

Please sign in to comment.