diff --git a/CODEOWNERS b/CODEOWNERS
new file mode 100644
index 00000000..517ce1ef
--- /dev/null
+++ b/CODEOWNERS
@@ -0,0 +1 @@
+* @infusionsoft/pi
diff --git a/README.md b/README.md
index 7241cc4c..7c9c7a1c 100644
--- a/README.md
+++ b/README.md
@@ -73,6 +73,8 @@ AMD syntax example as well as a CommonJS (browserify) example.
Defines which of Scribe's built-in plugins should be active
defaultFormatters
Defines which of Scribe's default formatters should be active
+ inputDelay
+ Defines the debounce delay for input events on editor container (default is 0)
For detailed documentation see the [wiki page on options](https://github.com/guardian/scribe/wiki/Scribe-configuration-options).
diff --git a/src/config.js b/src/config.js
index 77f30519..16870cba 100644
--- a/src/config.js
+++ b/src/config.js
@@ -31,7 +31,9 @@ define(['immutable'], function (immutable) {
defaultFormatters: [
'escapeHtmlCharactersFormatter',
'replaceNbspCharsFormatter'
- ]
+ ],
+
+ inputDelay: 0
};
diff --git a/src/debounce.js b/src/debounce.js
new file mode 100644
index 00000000..abd35066
--- /dev/null
+++ b/src/debounce.js
@@ -0,0 +1,26 @@
+define([], function () {
+ return function (func, wait, immediate) {
+ var timeout;
+
+ return function () {
+ var context = this, args = arguments;
+
+ var later = function () {
+ timeout = null;
+
+ if (!immediate) {
+ func.apply(context, args);
+ }
+ };
+
+ var callNow = immediate && !timeout;
+
+ clearTimeout(timeout);
+ timeout = setTimeout(later, wait);
+
+ if (callNow) {
+ func.apply(context, args);
+ }
+ };
+ };
+});
diff --git a/src/scribe.js b/src/scribe.js
index eb54983d..861e8986 100644
--- a/src/scribe.js
+++ b/src/scribe.js
@@ -11,7 +11,8 @@ define([
'./node',
'immutable',
'./config',
- './events'
+ './events',
+ './debounce'
], function (
plugins,
commands,
@@ -25,7 +26,8 @@ define([
nodeHelpers,
Immutable,
config,
- eventNames
+ eventNames,
+ debounce
) {
'use strict';
@@ -68,7 +70,7 @@ define([
this.el.setAttribute('contenteditable', true);
- this.el.addEventListener('input', function () {
+ this.el.addEventListener('input', debounce(function () {
/**
* This event triggers when either the user types something or a native
* command is executed which causes the content to change (i.e.
@@ -76,7 +78,7 @@ define([
* these actions, so instead we run the transaction in this event.
*/
this.transactionManager.run();
- }.bind(this), false);
+ }.bind(this), this.options.inputDelay).bind(this), false);
/**
* Core Plugins