892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
|
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
|
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
' ', dowMap[d.getDay()]
].join('');
};
const canEmbedFile = function f(msg){
if(!f.$rx){
f.$rx = /\.((html?)|(txt))$/i;
f.$specificTypes = [
'text/plain',
'text/html'
// add more as we discover which ones Firefox won't
// force the user to try to download.
];
}
if(msg.fmime){
return (msg.fmime.startsWith("text/")
|| msg.fmime.startsWith("image/"));
return (msg.fmime.startsWith("image/")
|| f.$specificTypes.indexOf(msg.fmime)>=0);
}
return msg.fname && f.$rx.test(msg.fname);
};
const adjustIFrameSize = function(msgObj){
const iframe = msgObj.e.iframe;
const body = iframe.contentWindow.document.querySelector('body');
if(body && !body.style.fontSize){
/** _Attempt_ to force the iframe to inherit the message's text size
if the body has no explicit size set. On desktop systems
the size is apparently being inherited in that case, but on mobile
not. */
body.style.fontSize = window.getComputedStyle(msgObj.e.content);
}
if('' === iframe.style.maxHeight){
/* Resize iframe height to fit the content. Workaround: if we
adjust the iframe height while it's hidden then its height
is 0, so we must briefly unhide it. */
const isHidden = iframe.classList.contains('hidden');
if(isHidden) D.removeClass(iframe, 'hidden');
iframe.style.maxHeight = iframe.style.height
= iframe.contentWindow.document.documentElement.scrollHeight + 'px';
if(isHidden) D.addClass(iframe, 'hidden');
}
};
cf.prototype = {
scrollIntoView: function(){
this.e.content.scrollIntoView();
},
setMessage: function(m){
const ds = this.e.body.dataset;
ds.timestamp = m.mtime;
|
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
|
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
|
+
+
+
+
+
+
+
-
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
+
+
-
-
-
|
use case is attached diffs. */
D.addClass(contentTarget, 'wide');
const embedTarget = this.e.content;
const self = this;
const btnEmbed = D.attr(D.checkbox("1", false), 'id',
'embed-'+ds.msgid);
const btnLabel = D.label(btnEmbed, "Embed");
/* Maintenance reminder: do not disable the toggle
button while the content is loading because that will
cause it to get stuck in disabled mode if the browser
decides that loading the content should prompt the
user to download it, rather than embed it in the
iframe. */
btnEmbed.addEventListener('change',function(){
if(self.e.iframe){
if(btnEmbed.checked){
if(btnEmbed.checked) D.removeClass(self.e.iframe, 'hidden');
D.removeClass(self.e.iframe, 'hidden');
if(self.e.$iframeLoaded) adjustIFrameSize(self);
}
else D.addClass(self.e.iframe, 'hidden');
return;
}
D.disable(btnEmbed);
const iframe = self.e.iframe = document.createElement('iframe');
D.append(embedTarget, iframe);
D.append(embedTarget, iframe);
iframe.addEventListener('load', function(){
D.enable(btnEmbed);
const body = iframe.contentWindow.document.querySelector('body');
if(body && !body.style.fontSize){
/** _Attempt_ to force the iframe to inherit the message's text size
if the body has no explicit size set. On desktop systems
the size is apparently being inherited in that case, but on mobile
not. */
const cs = window.getComputedStyle(self.e.content);
body.style.fontSize = cs.fontSize;
self.e.$iframeLoaded = true;
adjustIFrameSize(self);
}
iframe.style.maxHeight = iframe.style.height
= iframe.contentWindow.document.documentElement.scrollHeight + 'px';
});
iframe.setAttribute('src', downloadUri);
});
D.append(w, btnEmbed, btnLabel);
}
contentTarget.appendChild(w);
}
|