Skip to content

Commit

Permalink
Close #490: remove old, problematic, and unnecessary renderError and …
Browse files Browse the repository at this point in the history
…clearError method defaults

By removing these defaults, when the widget is in rendered in Shiny, it will simply fallback to Shiny's OutputBinding default methods, which does a better and simpler job of rendering and clearing errors.

And, when rendering statically, the renderError/clearError methods aren't relevant
  • Loading branch information
cpsievert committed Dec 12, 2024
1 parent 373eede commit ceeefa2
Showing 1 changed file with 0 additions and 82 deletions.
82 changes: 0 additions & 82 deletions inst/www/htmlwidgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@
}
}

function asArray(value) {
if (value === null)
return [];
if ($.isArray(value))
return value;
return [value];
}

// Implement jQuery's extend
function extend(target /*, ... */) {
if (arguments.length == 1) {
Expand Down Expand Up @@ -317,80 +309,6 @@
find: function(scope) {
return querySelectorAll(scope, "." + this.name);
},
renderError: function(el, err) {
var $el = $(el);

this.clearError(el);

// Add all these error classes, as Shiny does
var errClass = "shiny-output-error";
if (err.type !== null) {
// use the classes of the error condition as CSS class names
errClass = errClass + " " + $.map(asArray(err.type), function(type) {
return errClass + "-" + type;
}).join(" ");
}
errClass = errClass + " htmlwidgets-error";

// Is el inline or block? If inline or inline-block, just display:none it
// and add an inline error.
var display = $el.css("display");
$el.data("restore-display-mode", display);

if (display === "inline" || display === "inline-block") {
$el.hide();
if (err.message !== "") {
var errorSpan = $("<span>").addClass(errClass);
errorSpan.text(err.message);
$el.after(errorSpan);
}
} else if (display === "block") {
// If block, add an error just after the el, set visibility:none on the
// el, and position the error to be on top of the el.
// Mark it with a unique ID and CSS class so we can remove it later.
$el.css("visibility", "hidden");
if (err.message !== "") {
var errorDiv = $("<div>").addClass(errClass).css("position", "absolute")
.css("top", el.offsetTop)
.css("left", el.offsetLeft)
// setting width can push out the page size, forcing otherwise
// unnecessary scrollbars to appear and making it impossible for
// the element to shrink; so use max-width instead
.css("maxWidth", el.offsetWidth)
.css("height", el.offsetHeight);
errorDiv.text(err.message);
$el.after(errorDiv);

// Really dumb way to keep the size/position of the error in sync with
// the parent element as the window is resized or whatever.
var intId = setInterval(function() {
if (!errorDiv[0].parentElement) {
clearInterval(intId);
return;
}
errorDiv
.css("top", el.offsetTop)
.css("left", el.offsetLeft)
.css("maxWidth", el.offsetWidth)
.css("height", el.offsetHeight);
}, 500);
}
}
},
clearError: function(el) {
var $el = $(el);
var display = $el.data("restore-display-mode");
$el.data("restore-display-mode", null);

if (display === "inline" || display === "inline-block") {
if (display)
$el.css("display", display);
$(el.nextSibling).filter(".htmlwidgets-error").remove();
} else if (display === "block"){
$el.css("visibility", "inherit");
$(el.nextSibling).filter(".htmlwidgets-error").remove();
}
},
sizing: {}
};

Expand Down

0 comments on commit ceeefa2

Please sign in to comment.