Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ var tribute = new Tribute({
Once initialized, Tribute can be attached to an `input`, `textarea`, or an element that supports `contenteditable`.

```html
<div id="caaanDo">I'm Mr. Meeseeks, look at me!</div>
<div id="caaanDo" contenteditable="true">I'm Mr. Meeseeks, look at me!</div>

<div class="mentionable">Some text here.</div>
<div class="mentionable">Some more text over here.</div>
<div class="mentionable" contenteditable="true">Some text here.</div>
<div class="mentionable" contenteditable="true">Some more text over here.</div>

<script>
tribute.attach(document.getElementById("caaanDo"));
Expand Down
2 changes: 1 addition & 1 deletion dist/tribute.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ class Tribute {

ensureEditable(element) {
if (Tribute.inputTypes().indexOf(element.nodeName) === -1) {
if (!element.contentEditable) {
if (!element.isContentEditable) {
throw new Error("[Tribute] Cannot bind to " + element.nodeName + ", not contentEditable");
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@
key: "ensureEditable",
value: function ensureEditable(element) {
if (Tribute.inputTypes().indexOf(element.nodeName) === -1) {
if (!element.contentEditable) {
if (!element.isContentEditable) {
throw new Error("[Tribute] Cannot bind to " + element.nodeName + ", not contentEditable");
}
}
Expand Down
2 changes: 1 addition & 1 deletion dist/tribute.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/tribute.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@
key: "ensureEditable",
value: function ensureEditable(element) {
if (Tribute.inputTypes().indexOf(element.nodeName) === -1) {
if (!element.contentEditable) {
if (!element.isContentEditable) {
throw new Error("[Tribute] Cannot bind to " + element.nodeName + ", not contentEditable");
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "tributejs",
"packageManager": "yarn@4.13.0",
"version": "5.1.3",
"version": "5.1.4",
"description": "Native ES6 @mentions",
"main": "dist/tribute.js",
"module": "dist/tribute.esm.js",
Expand Down
2 changes: 1 addition & 1 deletion src/Tribute.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ class Tribute {

ensureEditable(element) {
if (Tribute.inputTypes().indexOf(element.nodeName) === -1) {
if (!element.contentEditable) {
if (!element.isContentEditable) {
throw new Error("[Tribute] Cannot bind to " + element.nodeName + ", not contentEditable");
}
}
Expand Down
57 changes: 56 additions & 1 deletion test/spec/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@ describe("Tribute instantiation", function() {
});
});

describe("Tribute attachment eligibility", function() {
let container, element, tribute;

beforeEach(function() {
container = document.createElement("div");
document.body.appendChild(container);
element = document.createElement("div");
container.appendChild(element);
tribute = new Tribute({ values: [] });
});

afterEach(function() {
if (element.hasAttribute("data-tribute")) tribute.detach(element);
container.remove();
});

it("rejects a plain non-editable div", function() {
expect(() => tribute.attach(element)).toThrowError(
"[Tribute] Cannot bind to DIV, not contentEditable"
);
expect(element.hasAttribute("data-tribute")).toBe(false);
});

it("rejects explicit non-editability inside an editable parent", function() {
container.contentEditable = "true";
element.contentEditable = "false";
expect(() => tribute.attach(element)).toThrowError(
"[Tribute] Cannot bind to DIV, not contentEditable"
);
expect(element.hasAttribute("data-tribute")).toBe(false);
});

it("accepts an explicitly editable div", function() {
element.contentEditable = "true";
tribute.attach(element);
expect(element.hasAttribute("data-tribute")).toBe(true);
});

it("accepts editability inherited from a parent", function() {
container.contentEditable = "true";
tribute.attach(element);
expect(element.hasAttribute("data-tribute")).toBe(true);
});

["input", "textarea"].forEach(tag => {
it(`accepts ${tag} without contenteditable`, function() {
element.remove();
element = document.createElement(tag);
container.appendChild(element);
tribute.attach(element);
expect(element.hasAttribute("data-tribute")).toBe(true);
});
});
});

describe("Tribute @mentions cases", function() {
afterEach(function() {
clearDom();
Expand Down Expand Up @@ -797,4 +852,4 @@ describe("Tribute loadingItemTemplate", function() {
}, 1000);
});
});
});
});
Loading