Skip to content
This repository has been archived by the owner on Jun 24, 2022. It is now read-only.

Commit

Permalink
feat(TCMention): add extra className map for trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchentw committed Nov 24, 2015
1 parent e791841 commit 0b6a64e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ export const TCMention = MediumEditor.Extension.extend({
*/
extraActivePanelClassName: ``,

extraTriggerClassNameMap: {},

extraActiveTriggerClassNameMap: {},

/* tagName: [string]
*
* Element tag name that would indicate that this mention. It will have
Expand Down Expand Up @@ -171,6 +175,9 @@ export const TCMention = MediumEditor.Extension.extend({
}
if (this.activeMentionAt) {
this.activeMentionAt.classList.remove(this.activeTriggerClassName);
if (this.extraActiveTriggerClassName) {
this.activeMentionAt.classList.remove(this.extraActiveTriggerClassName);
}
}
if (this.activeMentionAt) {
// http://stackoverflow.com/a/27004526/1458162
Expand Down Expand Up @@ -227,6 +234,9 @@ export const TCMention = MediumEditor.Extension.extend({
this.trigger = this.word.slice(0, 1);
this.triggerClassName = this.triggerClassNameMap[this.trigger];
this.activeTriggerClassName = this.activeTriggerClassNameMap[this.trigger];
//
this.extraTriggerClassName = this.extraTriggerClassNameMap[this.trigger];
this.extraActiveTriggerClassName = this.extraActiveTriggerClassNameMap[this.trigger];
},

showPanel () {
Expand Down Expand Up @@ -261,6 +271,9 @@ export const TCMention = MediumEditor.Extension.extend({
// TODO: Not sure why, but using <span> tag doens't work here
const element = this.document.createElement(this.tagName);
element.classList.add(this.triggerClassName);
if (this.extraTriggerClassName) {
element.classList.add(this.extraTriggerClassName);
}
this.activeMentionAt = element;
//
range.surroundContents(element);
Expand All @@ -269,6 +282,9 @@ export const TCMention = MediumEditor.Extension.extend({
}
MediumEditor.selection.select(this.document, this.activeMentionAt.firstChild, this.word.length);
this.activeMentionAt.classList.add(this.activeTriggerClassName);
if (this.extraActiveTriggerClassName) {
this.activeMentionAt.classList.add(this.extraActiveTriggerClassName);
}
},

positionPanel () {
Expand Down

0 comments on commit 0b6a64e

Please sign in to comment.