Closed domchristie closed 9 years ago
So you are suggesting that the user would be in charge of deciding when to call this update? We could either expose a $("textarea").expanding("reflow")
or do as you say and automatically reflow when calling $("textarea").expanding()
on an element that is already initialized.
Typically I would prefer a separate function call b/c it is more explicit overloading the main plugin method could confuse things with instance options (if options are different between first and second call, which should be used?). We have so few options here (1) that we could almost just reuse the expanding()
call, but I'm not sure about this case:
$("textarea").expanding({update:someFunc});
setTimeout(function() {
// reflow the expanding area. But does my update function disappear?
$("textarea").expanding();
}, 1000);
From my POV, the following example is a bit more clear (it's a pattern used in jquery ui and that I've used in other plugins, like spectrum: https://bgrins.github.io/spectrum/)
$("textarea").expanding({update:someFunc});
setTimeout(function() {
// reflow the expanding area.
$("textarea").expanding("reflow");
}, 1000);
Yes: my initial thoughts were to just use .expanding()
with no args, as it keeps things simple, but as you say, handling options could get confusing.
.expanding('reflow')
sounds sensible, particularly if it’s standard practice. I’ll work on a getting a PR together…
Cool, sounds good. By they way, I looked into it a bit more and I think the term refresh
may be more widely used, at least within jQuery UI: http://api.jqueryui.com/accordion/#method-refresh. It may be a better name to go with.
There are some situation where it’d be handy to reinitialise the plugin to adjust to new situations e.g. when percentage padding is used and the window is resized.
Rather than ignoring subsequent calls to the plugin, should we reinitialise it? i.e. keep the additional elements intact, but recalculate styles, and perhaps override any options passed in e.g. update callback
Thoughts?