Skip to content

Instantly share code, notes, and snippets.

@robbieaverill
Created October 24, 2017 22:38
Show Gist options
  • Save robbieaverill/090f2f0bf8d977c4489a96c0ad3cecd5 to your computer and use it in GitHub Desktop.
Save robbieaverill/090f2f0bf8d977c4489a96c0ad3cecd5 to your computer and use it in GitHub Desktop.
Reacting to change
diff --git a/client/src/legacy/TinyMCE_sslink-internal.js b/client/src/legacy/TinyMCE_sslink-internal.js
index c20a6c0d..ba5312f5 100644
--- a/client/src/legacy/TinyMCE_sslink-internal.js
+++ b/client/src/legacy/TinyMCE_sslink-internal.js
@@ -61,10 +61,7 @@ jQuery.entwine('ss', ($) => {
const handleHide = () => this.close();
const handleInsert = (...args) => this.handleInsert(...args);
const attrs = this.getOriginalAttributes();
- const selection = tinymce.activeEditor.selection;
- const selectionContent = selection.getContent() || '';
- const tagName = selection.getNode().tagName;
- const requireLinkText = tagName !== 'A' && selectionContent.trim() === '';
+ const requireLinkText = this.getRequireLinkText();
// create/update the react component
ReactDOM.render(
@@ -86,6 +83,20 @@ jQuery.entwine('ss', ($) => {
},
/**
+ * Determine whether to show the link text field
+ *
+ * @return {Boolean}
+ */
+ getRequireLinkText() {
+ const selection = tinymce.activeEditor.selection;
+ const selectionContent = selection.getContent() || '';
+ const tagName = selection.getNode().tagName;
+ const requireLinkText = tagName !== 'A' && selectionContent.trim() === '';
+
+ return requireLinkText;
+ },
+
+ /**
* @param {Object} data - Posted data
* @return {Object}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment