|
72 | 72 | throw "Blob doesn't support slice";
|
73 | 73 | }
|
74 | 74 |
|
| 75 | + // Given an element and a function(width, height), returns a function(). When |
| 76 | + // the output function is called, it calls the input function with the offset |
| 77 | + // width and height of the input element--but only if the size of the element |
| 78 | + // is non-zero and the size is different than the last time the output |
| 79 | + // function was called. |
| 80 | + // |
| 81 | + // Basically we are trying to filter out extraneous calls to func, so that |
| 82 | + // when the window size changes or whatever, we don't run resize logic for |
| 83 | + // elements that haven't actually changed size or aren't visible anyway. |
| 84 | + function makeResizeFilter(el, func) { |
| 85 | + var lastSize = {}; |
| 86 | + return function() { |
| 87 | + var size = { w: el.offsetWidth, h: el.offsetHeight }; |
| 88 | + if (size.w === 0 && size.h === 0) |
| 89 | + return; |
| 90 | + if (size.w === lastSize.w && size.h === lastSize.h) |
| 91 | + return; |
| 92 | + lastSize = size; |
| 93 | + func(size.w, size.h); |
| 94 | + } |
| 95 | + } |
| 96 | + |
75 | 97 | var _BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder ||
|
76 | 98 | window.MozBlobBuilder || window.MSBlobBuilder;
|
77 | 99 |
|
|
2655 | 2677 | var OutputBindingAdapter = function(el, binding) {
|
2656 | 2678 | this.el = el;
|
2657 | 2679 | this.binding = binding;
|
| 2680 | + |
| 2681 | + // If the binding actually has a resize method, override the prototype of |
| 2682 | + // onResize with a version that does a makeResizeFilter on the element. |
| 2683 | + if (binding.resize) { |
| 2684 | + this.onResize = makeResizeFilter(el, function(width, height) { |
| 2685 | + binding.resize(el, width, height); |
| 2686 | + }); |
| 2687 | + } |
2658 | 2688 | };
|
2659 | 2689 | (function() {
|
2660 | 2690 | this.onValueChange = function(data) {
|
|
2666 | 2696 | this.showProgress = function(show) {
|
2667 | 2697 | this.binding.showProgress(this.el, show);
|
2668 | 2698 | };
|
| 2699 | + this.onResize = function() { |
| 2700 | + // Intentionally left blank; see constructor |
| 2701 | + }; |
2669 | 2702 | }).call(OutputBindingAdapter.prototype);
|
2670 | 2703 |
|
2671 | 2704 |
|
|
2996 | 3029 | inputs.setInput('.clientdata_output_' + this.id + '_height', this.offsetHeight);
|
2997 | 3030 | }
|
2998 | 3031 | });
|
| 3032 | + $('.shiny-bound-output').each(function() { |
| 3033 | + $(this).data('shiny-output-binding').onResize(); |
| 3034 | + }); |
2999 | 3035 | }
|
3000 | 3036 |
|
3001 | 3037 | // Return true if the object or one of its ancestors in the DOM tree has
|
|
0 commit comments