From 1931ce887c13a8d84bc433ecd199737238769b31 Mon Sep 17 00:00:00 2001
From: Joe Cheng Unsubscribe DOM event listeners that were bound in Example:
@@ -74,9 +80,9 @@ Each custom input component you design needs an *input binding*, an object you c
subscribe.exampleInputBinding.unsubscribe = function(el) {
+
+};exampleInputBinding.unsubscribe = function(el) {
$(el).off(".exampleComponentName");
-};getRatePolicy()
@@ -104,4 +110,62 @@ Each custom input component you design needs an *input binding*, an object you c
Rate policies are only applied when the callback function in subscribe is called with true as the first parameter. It's important that input components be able to control which events are rate-limited and which are not, as different events may have different expectations to the user. For example, for a textbox, it would make sense to rate-limit events while the user is typing, but if the user hits Enter or focus leaves the textbox, then the input should always be sent immediately.
Example:
++ +
+ + +HTML:
+<button class="increment btn" type="button">0</button>
+JavaScript:
+// Non-Shiny-specific code that drives the basic behavior
+
+$(document).on("click", "button.increment", function(evt) {
+ var el = $(evt.target);
+ el.text(parseInt(el.text()) + 1);
+ el.trigger("change");
+});
+
+
+// Shiny-specific binding code
+
+var incrementBinding = new Shiny.InputBinding();
+$.extend(incrementBinding, {
+ find: function(scope) {
+ return $(scope).find(".increment");
+ },
+ getValue: function(el) {
+ return parseInt($(el).text());
+ },
+ setValue: function(el, value) {
+ $(el).text(value);
+ },
+ subscribe: function(el, callback) {
+ $(el).on("change.incrementBinding", function(e) {
+ callback();
+ });
+ },
+ unsubscribe: function(el) {
+ $(el).off(".incrementBinding");
+ }
+});
+
+Shiny.inputBindings.register(incrementBinding);
diff --git a/tutorial/index.html b/tutorial/index.html
index ab4d36b9f..69454a56f 100644
--- a/tutorial/index.html
+++ b/tutorial/index.html
@@ -86,6 +86,8 @@ var hljs=new function(){function m(p){return p.replace(/&/gm,"&").replace(/<
hljs.initHighlightingOnLoad();
+
+
@@ -275,7 +277,6 @@ hljs.initHighlightingOnLoad();
-