summaryrefslogtreecommitdiff
path: root/static/js/pages/chat_init.js
blob: 7149291bad8ded0dd4916ca064b3174afd1d58c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Shared initializer for pages that include pichat.js and render a chat UI.
// Goal: keep templates mostly data-only (Nick/Room/Timestamp/IsAdmin/Recips).

(function($){
  function defaultShowAlert() {
    alert(window.Nick ? 'MUST LOGIN' : 'Join dump.fm @ /register');
  }

  function defaultPop(url) {
    var newwindow = window.open(
      url,
      'name',
      'height=50,width=400,left=20,top=20,location=0,status=0,scrollbar=0,resizable=0'
    );
    if (window.focus && newwindow) { newwindow.focus(); }
    return newwindow;
  }

  if (typeof window.showAlert !== 'function') { window.showAlert = defaultShowAlert; }
  if (typeof window.pop !== 'function') { window.pop = defaultPop; }

  $(function(){
    if (typeof window.Recips === 'undefined') { window.Recips = []; }

    var hasMessageList = document.getElementById('messageList') !== null;
    var hasChatInput = document.getElementById('msgInput') !== null;

    if (hasMessageList && hasChatInput && typeof window.initChat === 'function') { window.initChat(); }
    if (hasMessageList && hasChatInput && typeof window.initChatMsgs === 'function') { window.initChatMsgs(); }

    // Some room pages render dumps in `.logged-dump` containers without the full chat UI.
    // In that case, run the log initializer so URLs become hotlinked images.
    if (!hasChatInput && typeof window.initLog === 'function' && jQuery('.logged-dump .content').length) {
      window.initLog(window.Recips);
    }

    if (typeof window.Away !== 'undefined' && typeof window.Away.startTitleUpdater === 'function') { window.Away.startTitleUpdater(); }

    if (window.Nick && typeof window.setupUpload === 'function' && typeof window.Room !== 'undefined') {
      window.setupUpload('upload', window.Room);
    }
  });
})(jQuery);