1
2
3
4
5
6
7
8
9
10
11
12
|
/**
This file contains the client-side implementation of fossil's /chat
application.
*/
(function(){
const F = window.fossil, D = F.dom;
const E1 = function(selector){
const e = document.querySelector(selector);
if(!e) throw new Error("missing required DOM element: "+selector);
return e;
};
/**
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
|
/**
This file contains the client-side implementation of fossil's /chat
application.
*/
window.fossil.onPageLoad(function(){
const F = window.fossil, D = F.dom;
const E1 = function(selector){
const e = document.querySelector(selector);
if(!e) throw new Error("missing required DOM element: "+selector);
return e;
};
/**
|
| ︙ | | | ︙ | |
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
document.querySelector('body > div.header'),
document.querySelector('body > div.mainmenu'),
document.querySelector('body > #hbdrop'),
document.querySelector('body > div.footer')
];
f.contentArea = E1('div.content');
}
const bcl = document.body.classList;
const resized = function(){
const wh = window.innerHeight,
com = bcl.contains('chat-only-mode');
var ht;
var extra = 0;
if(com){
ht = wh;
}else{
f.elemsToCount.forEach((e)=>e ? extra += D.effectiveHeight(e) : false);
ht = wh - extra;
|
<
|
|
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
document.querySelector('body > div.header'),
document.querySelector('body > div.mainmenu'),
document.querySelector('body > #hbdrop'),
document.querySelector('body > div.footer')
];
f.contentArea = E1('div.content');
}
const resized = function(){
const wh = window.innerHeight,
com = document.body.classList.contains('chat-only-mode');
var ht;
var extra = 0;
if(com){
ht = wh;
}else{
f.elemsToCount.forEach((e)=>e ? extra += D.effectiveHeight(e) : false);
ht = wh - extra;
|
| ︙ | | | ︙ | |
887
888
889
890
891
892
893
894
895
896
897
898
899
900
|
cs.e.btnClearFilter.addEventListener('click',function(){
D.addClass(this,'hidden');
cs.clearFilters();
}, false);
return cs;
})()/*Chat initialization*/;
/** To be passed each MessageWidget's top-level DOM element
after initial processing of the message, to set up
hashtag references. */
const setupHashtags = function f(elem){
if(!f.$click){
f.$click = function(ev){
/* Click handler for hashtags */
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
886
887
888
889
890
891
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
|
cs.e.btnClearFilter.addEventListener('click',function(){
D.addClass(this,'hidden');
cs.clearFilters();
}, false);
return cs;
})()/*Chat initialization*/;
/**
An experiment in history navigation: when a message numref is
clicked, we push the origin message onto the history and
set up the back button to return to that message.
*/
if(0) window.onpopstate = function(event){
console.debug("onpopstate event",event.state, event);
if(event.state && event.state.msgId){
const e = Chat.setCurrentView(Chat.e.viewMessages).
querySelector('.message-widget[data-msgid="'+event.state.msgId+'"]');
console.debug("Popping history back to",event.state, e);
if(e){
Chat.MessageWidget.scrollToMessageElem(e);
//F.page.setPageTitle("Fossil Chat #"+event.state.msgId);
return;
}
}
Chat.scrollMessagesTo(1);
};
const findParentWithClass = function(e, className){
while(e && !e.classList.contains(className)){
e = e.parentNode;
}
return e;
};
/** To be passed each MessageWidget's top-level DOM element
after initial processing of the message, to set up
hashtag references. */
const setupHashtags = function f(elem){
if(!f.$click){
f.$click = function(ev){
/* Click handler for hashtags */
|
| ︙ | | | ︙ | |
911
912
913
914
915
916
917
918
919
920
921
922
923
924
|
const tag = ev.target.dataset.numtag;
if(tag){
const e = Chat.e.viewMessages.querySelector(
'.message-widget[data-msgid="'+tag+'"]'
);
if(e){
Chat.MessageWidget.scrollToMessageElem(e);
}else{
F.toast.warning("Message #"+tag+" not found in loaded messages.");
}
}
};
}
elem.querySelectorAll('[data-hashtag]').forEach(function(e){
|
>
>
>
>
>
>
>
>
|
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
|
const tag = ev.target.dataset.numtag;
if(tag){
const e = Chat.e.viewMessages.querySelector(
'.message-widget[data-msgid="'+tag+'"]'
);
if(e){
Chat.MessageWidget.scrollToMessageElem(e);
//Set up window.history() state...
const p = 1 ? false : findParentWithClass(ev.target, 'message-widget');
if(p){
const state = {msgId: p.dataset.msgid};
console.debug("Pushing history for msgid", state);
const rc = window.history.pushState(state, "?");
console.debug("History length =",window.history.length, rc);
}
}else{
F.toast.warning("Message #"+tag+" not found in loaded messages.");
}
}
};
}
elem.querySelectorAll('[data-hashtag]').forEach(function(e){
|
| ︙ | | | ︙ | |
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
|
/** Assumes that e is a MessageWidget element, ensures that
Chat.e.viewMessages is visible, scrolls the message,
and animates it a bit to make it more visible. */
cf.scrollToMessageElem = function(e){
if(e.firstElementChild){
Chat.setCurrentView(Chat.e.viewMessages);
e.scrollIntoView(false);
Chat.animate(e.firstElementChild, 'anim-flip-h');
}
};
return cf;
})()/*MessageWidget*/;
const BlobXferState = (function(){/*drag/drop bits...*/
/* State for paste and drag/drop */
|
|
|
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
|
/** Assumes that e is a MessageWidget element, ensures that
Chat.e.viewMessages is visible, scrolls the message,
and animates it a bit to make it more visible. */
cf.scrollToMessageElem = function(e){
if(e.firstElementChild){
Chat.setCurrentView(Chat.e.viewMessages);
e.scrollIntoView(false);
Chat.animate(e, 'anim-fade-out-in');
}
};
return cf;
})()/*MessageWidget*/;
const BlobXferState = (function(){/*drag/drop bits...*/
/* State for paste and drag/drop */
|
| ︙ | | | ︙ | |
1788
1789
1790
1791
1792
1793
1794
1795
|
document.querySelectorAll('#chat-edit-buttons button').forEach(function(e){
e.addEventListener('click',flip, false);
});
}
setTimeout( ()=>Chat.inputFocus(), 0 );
Chat.animate.$disabled = false;
F.page.chat = Chat/* enables testing the APIs via the dev tools */;
})();
|
|
|
1822
1823
1824
1825
1826
1827
1828
1829
|
document.querySelectorAll('#chat-edit-buttons button').forEach(function(e){
e.addEventListener('click',flip, false);
});
}
setTimeout( ()=>Chat.inputFocus(), 0 );
Chat.animate.$disabled = false;
F.page.chat = Chat/* enables testing the APIs via the dev tools */;
});
|