Skip to content

Commit 145797d

Browse files
committed
New data-attribute-based implementation for api.dom.email()
This method uses a better documented and more reliable way to create email DOM-instances from IDs, or to obtain IDs from resolved DOM-elements. This fixes https://github.com/josteink/gmail.js/issues/6.
1 parent b9923a9 commit 145797d

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- New, safer DOM-based approach to resolving email-thread IDs.
99
- `api.get.email_id()` replaced by `api.get.thread_id()`. Using old
1010
method now generates warning!
11+
- New, safer data-attribute-based implementation for `api.dom.email`.
1112

1213
## Version 0.6.14
1314

src/gmail.js

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2763,26 +2763,18 @@ var Gmail = function(localJQuery) {
27632763

27642764
if (typeof element === "string") {
27652765
this.id = element;
2766-
var message_class_id = "m" + this.id;
2767-
this.id_element = $("div.ii.gt div.a3s.aXjCH." + message_class_id);
2768-
element = this.id_element.closest("div.adn");
2766+
element = $("div.adn[data-legacy-message-id='" + this.id + "']");
27692767
} else {
27702768
element = $(element);
27712769
}
2770+
27722771
if (!element || (!element.hasClass("adn"))) api.tools.error("api.dom.email called with invalid element/id");
27732772

2774-
// if no id specified, extract from the body wrapper class (starts with "m" followed by the id)
2773+
this.$el = element;
27752774
if (!this.id) {
2776-
this.id_element = element.find("div.ii.gt div.a3s.aXjCH");
2777-
var classValue = this.id_element.attr("class");
2778-
if (classValue !== null) {
2779-
var matches = classValue.match(/(^|\s)m([\S]*)/);
2780-
if (matches !== null) {
2781-
this.id = matches.pop();
2782-
}
2783-
}
2775+
this.id = this.$el.data("legacyMessageId");
27842776
}
2785-
this.$el = element;
2777+
27862778
return this;
27872779
};
27882780

0 commit comments

Comments
 (0)