").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 = $("").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: {}
};