mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-09-07 00:17:03 +03: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 { forEachObjectEntry, pInt } from 'Common/Utils';
|
||||||
import { SettingsUserStore } from 'Stores/User/Settings';
|
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]),
|
replaceWithChildren = node => node.replaceWith(...[...node.childNodes]),
|
||||||
|
|
||||||
url = /(^|\s|\n|\/?>)(https?:\/\/[-A-Z0-9+&#/%?=()~_|!:,.;]*[-A-Z0-9+&#/%=~()_|])/gi,
|
url = /(^|\s|\n|\/?>)(https?:\/\/[-A-Z0-9+&#/%?=()~_|!:,.;]*[-A-Z0-9+&#/%=~()_|])/gi,
|
||||||
|
|
@ -79,6 +97,8 @@ const
|
||||||
return url;
|
return url;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
doc.body.append(hcont);
|
||||||
|
|
||||||
export const
|
export const
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -435,6 +455,8 @@ export const
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
blockquoteSwitcher();
|
||||||
|
|
||||||
// return tpl.content.firstChild;
|
// return tpl.content.firstChild;
|
||||||
result.html = tpl.innerHTML.trim();
|
result.html = tpl.innerHTML.trim();
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -588,7 +610,7 @@ export const
|
||||||
aText = aNextText;
|
aText = aNextText;
|
||||||
} while (bDo);
|
} while (bDo);
|
||||||
|
|
||||||
return aText.join('\n')
|
tpl.innerHTML = aText.join('\n')
|
||||||
// .replace(/~~~\/blockquote~~~\n~~~blockquote~~~/g, '\n')
|
// .replace(/~~~\/blockquote~~~\n~~~blockquote~~~/g, '\n')
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
|
|
@ -602,6 +624,8 @@ export const
|
||||||
.replace(/~~~blockquote~~~\s*/g, '<blockquote>')
|
.replace(/~~~blockquote~~~\s*/g, '<blockquote>')
|
||||||
.replace(/\s*~~~\/blockquote~~~/g, '</blockquote>')
|
.replace(/\s*~~~\/blockquote~~~/g, '</blockquote>')
|
||||||
.replace(/\n/g, '<br>');
|
.replace(/\n/g, '<br>');
|
||||||
|
blockquoteSwitcher();
|
||||||
|
return tpl.innerHTML.trim();
|
||||||
},
|
},
|
||||||
|
|
||||||
WYSIWYGS = ko.observableArray();
|
WYSIWYGS = ko.observableArray();
|
||||||
|
|
|
||||||
|
|
@ -25,14 +25,6 @@ import { LanguageStore } from 'Stores/Language';
|
||||||
import Remote from 'Remote/User/Fetch';
|
import Remote from 'Remote/User/Fetch';
|
||||||
|
|
||||||
const
|
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) => {
|
toggleTag = (message, keyword) => {
|
||||||
const lower = keyword.toLowerCase(),
|
const lower = keyword.toLowerCase(),
|
||||||
flags = message.flags,
|
flags = message.flags,
|
||||||
|
|
@ -60,8 +52,6 @@ const
|
||||||
unic[email.email] || localEmails.has(email.email) || localEmails.set(email.email, email)
|
unic[email.email] || localEmails.has(email.email) || localEmails.set(email.email, email)
|
||||||
);
|
);
|
||||||
|
|
||||||
doc.body.append(hcont);
|
|
||||||
|
|
||||||
export class MessageModel extends AbstractModel {
|
export class MessageModel extends AbstractModel {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -307,7 +297,6 @@ export class MessageModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isHtml(true);
|
this.isHtml(true);
|
||||||
this.initView();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -327,25 +316,10 @@ export class MessageModel extends AbstractModel {
|
||||||
);
|
);
|
||||||
this.isHtml(false);
|
this.isHtml(false);
|
||||||
this.hasImages(false);
|
this.hasImages(false);
|
||||||
this.initView();
|
|
||||||
return true;
|
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) {
|
viewPopupMessage(print) {
|
||||||
const timeStampInUTC = this.dateTimeStampInUTC() || 0,
|
const timeStampInUTC = this.dateTimeStampInUTC() || 0,
|
||||||
ccLine = this.cc.toString(),
|
ccLine = this.cc.toString(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue