mirror of
https://github.com/the-djmaze/snappymail.git
synced 2025-01-01 04:22:15 +08:00
Move blockquote switcher to HTML parser #902
This commit is contained in:
parent
39bb3719c2
commit
c6db5f1def
2 changed files with 26 additions and 28 deletions
|
@ -1,4 +1,4 @@
|
|||
import { createElement } from 'Common/Globals';
|
||||
import { doc, createElement } from 'Common/Globals';
|
||||
import { forEachObjectEntry, pInt } from 'Common/Utils';
|
||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
||||
|
||||
|
@ -14,6 +14,24 @@ const
|
|||
"'": '''
|
||||
},
|
||||
|
||||
hcont = Element.fromHTML('<div area="hidden" style="position:absolute;left:-200vw;width:max(50vw,400px)"></div>'),
|
||||
getRealHeight = el => {
|
||||
hcont.innerHTML = el.outerHTML;
|
||||
const result = hcont.clientHeight;
|
||||
hcont.innerHTML = '';
|
||||
return result;
|
||||
},
|
||||
blockquoteSwitcher = () => {
|
||||
tpl.content.querySelectorAll('blockquote').forEach(node => {
|
||||
let h = node.clientHeight || getRealHeight(node);
|
||||
if (0 === h || 100 < h) {
|
||||
const el = Element.fromHTML('<details class="sm-bq-switcher"><summary>•••</summary></details>');
|
||||
node.replaceWith(el);
|
||||
el.append(node);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
replaceWithChildren = node => node.replaceWith(...[...node.childNodes]),
|
||||
|
||||
url = /(^|\s|\n|\/?>)(https?:\/\/[-A-Z0-9+&#/%?=()~_|!:,.;]*[-A-Z0-9+&#/%=~()_|])/gi,
|
||||
|
@ -79,6 +97,8 @@ const
|
|||
return url;
|
||||
};
|
||||
|
||||
doc.body.append(hcont);
|
||||
|
||||
export const
|
||||
|
||||
/**
|
||||
|
@ -435,6 +455,8 @@ export const
|
|||
}
|
||||
});
|
||||
|
||||
blockquoteSwitcher();
|
||||
|
||||
// return tpl.content.firstChild;
|
||||
result.html = tpl.innerHTML.trim();
|
||||
return result;
|
||||
|
@ -588,7 +610,7 @@ export const
|
|||
aText = aNextText;
|
||||
} while (bDo);
|
||||
|
||||
return aText.join('\n')
|
||||
tpl.innerHTML = aText.join('\n')
|
||||
// .replace(/~~~\/blockquote~~~\n~~~blockquote~~~/g, '\n')
|
||||
.replace(/&/g, '&')
|
||||
.replace(/>/g, '>')
|
||||
|
@ -602,6 +624,8 @@ export const
|
|||
.replace(/~~~blockquote~~~\s*/g, '<blockquote>')
|
||||
.replace(/\s*~~~\/blockquote~~~/g, '</blockquote>')
|
||||
.replace(/\n/g, '<br>');
|
||||
blockquoteSwitcher();
|
||||
return tpl.innerHTML.trim();
|
||||
},
|
||||
|
||||
WYSIWYGS = ko.observableArray();
|
||||
|
|
|
@ -25,14 +25,6 @@ import { LanguageStore } from 'Stores/Language';
|
|||
import Remote from 'Remote/User/Fetch';
|
||||
|
||||
const
|
||||
hcont = Element.fromHTML('<div area="hidden" style="position:absolute;left:-200vw;width:max(50vw,400px)"></div>'),
|
||||
getRealHeight = el => {
|
||||
hcont.innerHTML = el.outerHTML;
|
||||
const result = hcont.clientHeight;
|
||||
hcont.innerHTML = '';
|
||||
return result;
|
||||
},
|
||||
|
||||
toggleTag = (message, keyword) => {
|
||||
const lower = keyword.toLowerCase(),
|
||||
flags = message.flags,
|
||||
|
@ -60,8 +52,6 @@ const
|
|||
unic[email.email] || localEmails.has(email.email) || localEmails.set(email.email, email)
|
||||
);
|
||||
|
||||
doc.body.append(hcont);
|
||||
|
||||
export class MessageModel extends AbstractModel {
|
||||
constructor() {
|
||||
super();
|
||||
|
@ -307,7 +297,6 @@ export class MessageModel extends AbstractModel {
|
|||
}
|
||||
|
||||
this.isHtml(true);
|
||||
this.initView();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -327,25 +316,10 @@ export class MessageModel extends AbstractModel {
|
|||
);
|
||||
this.isHtml(false);
|
||||
this.hasImages(false);
|
||||
this.initView();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
initView() {
|
||||
// init BlockquoteSwitcher
|
||||
this.body.querySelectorAll('blockquote').forEach(node => {
|
||||
if (node.textContent.trim()) {
|
||||
let h = node.clientHeight || getRealHeight(node);
|
||||
if (0 === h || 100 < h) {
|
||||
const el = Element.fromHTML('<details class="sm-bq-switcher"><summary>•••</summary></details>');
|
||||
node.replaceWith(el);
|
||||
el.append(node);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
viewPopupMessage(print) {
|
||||
const timeStampInUTC = this.dateTimeStampInUTC() || 0,
|
||||
ccLine = this.cc.toString(),
|
||||
|
|
Loading…
Reference in a new issue