From b7e6b00ac849e1cf785e77c3757200acb6176fec Mon Sep 17 00:00:00 2001 From: JasonOffutt Date: Fri, 27 Apr 2018 15:25:50 -0700 Subject: [PATCH 1/3] Debounce input to allow Mac users to type international characters --- src/debounce.js | 26 ++++++++++++++++++++++++++ src/scribe.js | 12 ++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 src/debounce.js 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..45dc8577 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'; @@ -33,6 +35,8 @@ define([ function Scribe(el, options) { EventEmitter.call(this); + var INPUT_DELAY = 300; + this.el = el; this.commands = {}; @@ -68,7 +72,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 +80,7 @@ define([ * these actions, so instead we run the transaction in this event. */ this.transactionManager.run(); - }.bind(this), false); + }.bind(this), INPUT_DELAY).bind(this), false); /** * Core Plugins From 5fda960a74cecf04395746f350b567e29c333e63 Mon Sep 17 00:00:00 2001 From: JasonOffutt Date: Tue, 1 May 2018 12:19:08 -0700 Subject: [PATCH 2/3] Update debounce call to take an option to support config. Update readme w/ new config setting --- README.md | 2 ++ src/config.js | 4 +++- src/scribe.js | 4 +--- 3 files changed, 6 insertions(+), 4 deletions(-) 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/scribe.js b/src/scribe.js index 45dc8577..861e8986 100644 --- a/src/scribe.js +++ b/src/scribe.js @@ -35,8 +35,6 @@ define([ function Scribe(el, options) { EventEmitter.call(this); - var INPUT_DELAY = 300; - this.el = el; this.commands = {}; @@ -80,7 +78,7 @@ define([ * these actions, so instead we run the transaction in this event. */ this.transactionManager.run(); - }.bind(this), INPUT_DELAY).bind(this), false); + }.bind(this), this.options.inputDelay).bind(this), false); /** * Core Plugins From 16736c114ac9efe9601b4d6516bb2e945fe007a4 Mon Sep 17 00:00:00 2001 From: jvanbuskirk-keap <168024014+jvanbuskirk-keap@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:22:25 -0700 Subject: [PATCH 3/3] Create CODEOWNERS --- CODEOWNERS | 1 + 1 file changed, 1 insertion(+) create mode 100644 CODEOWNERS diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 00000000..517ce1ef --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1 @@ +* @infusionsoft/pi