summaryrefslogtreecommitdiff
path: root/static/js/pages/chat_init.js
blob: 58dba07e5ce92703fe466c455d11b7785f9d0a39 (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
// 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;

    if (hasMessageList && typeof window.initChat === 'function') { window.initChat(); }
    if (hasMessageList && typeof window.initChatMsgs === 'function') { window.initChatMsgs(); }
    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);