summaryrefslogtreecommitdiff
path: root/static/js/fullscreen.js
blob: f99d48bd42259a9dca352ae5cb0b6b5e371b6506 (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
function initFullscreen(room){
    Room = room || "dumpfm";
    refresh();
    ImageCache = [];
    SeenImages = {};
    FavedMap = {};
    $('#tools-button').click(toolsToggle);
}
function toolsToggle(){
  if ($("#msgInputDiv").css("display") == "none")
    toolsShow()
  else
    toolsHide()
}
function toolsShow(){
  $("#msgInputDiv").css("display", "block")
 
}
function toolsHide(){
  $("#msgInputDiv").css("display", "none")
}

function scanMessagesForImages(messages){
  for(var m=0; m<messages.length; m++) {
    var images = getImagesAsArray(messages[m].content)
    for (var i = 0; i<images.length; i++){
      NextImage = new Image()
      NextImage.onload = displayImage
      NextImage.src = images[i]
      NextImage.msg_id = messages[m].msg_id;
    }
  }
}

function clickImage(img) {
    if (!LoggedIn) return;
    var msg_id = $(img).attr('msg_id');
    if (!$(img).hasClass('fullscreen-favorite')) {
        FavedMap[msg_id] = true;
        $('#fav-indicator').show();
        Tag.add(msg_id, "favorite");
        $(img).addClass("fullscreen-favorite");
        track('UI', 'FullscreenFav');
    } else {
        delete FavedMap[msg_id];
        $('#fav-indicator').hide();
        Tag.rm(msg_id, "favorite");
        $(img).removeClass("fullscreen-favorite");
        track('UI', 'FullscreenDeFav');
    }
}

function displayImage(){
    $("#big-image").html('<img src="'+this.src+'" msg_id = "' + this.msg_id + '" onclick="clickImage(this)">');
    if (FavedMap[this.msg_id])
        $('#fav-indicator').show();
    else
        $('#fav-indicator').hide();
}

function refresh() {
  var onSuccess = function(json) {
    try {
      if (json.messages && json.messages.length)
        scanMessagesForImages(json.messages);
      Timestamp = json.timestamp;
    } catch(e) {
      
    }
    setTimeout(refresh, 1000);
  };

  var onError = function(resp, textStatus, errorThrown) {
    setTimeout(refresh, 4000);
  };

  $.ajax({
    type: 'GET',
    timeout: 5000,
    url: '/refresh',
    data: { 'room': Room, 'since': Timestamp },
    cache: false,
    dataType: 'json',
    success: onSuccess,
    error: onError
  });
}

function initLogin() {
    $('#logininner').ridgificate('2px solid #dd0000',
                                 '2px solid #fe6230',
                                 '2px solid #fef600',
                                 '2px solid #00bc00',
                                 '2px solid #009bfe',
                                 '2px solid #000083',
                                 '2px solid #30009b',
                                 '2px solid #dd0000',
                                 '2px solid #fe6230',
                                 '2px solid #fef600',
                                 '2px solid #00bc00',
                                 '2px solid #009bfe',
                                 '2px solid #000083',
                                 '2px solid #30009b');
}

function showLogin() {
    $('#nickInput').val('');
    $('#passwordInput').val('');
    $('#loginbox').show().center().center();
    $('#username').focus();
    $('input').removeAttr('disabled');
}

function login() {
    $('#spinner').show();
    $('input').attr('disabled', 'disabled');
    var nick = $('#nickInput').val();
    var password = $('#passwordInput').val();
    var rememberme = $('#remembermeInput').attr('checked') ? 'yes' : '';
    var hash = hex_sha1(nick + '$' + password + '$dumpfm');

    var onSuccess = function(json) {
	 if (typeof pageTracker !== 'undefined') {
	     pageTracker._setCustomVar(1, "logged-in", nick);
         }
        LoggedIn = true;
        $('#loginbox').hide();
        $('.sublogo').text('click to fav');
    };

    var onError = function(resp, textStatus, errorThrown) {
        $('#spinner').hide();
        $('input').removeAttr('disabled');
        $('#errormsg').text("Couldn't log you in :( Bad password?");
    }

    $.ajax({
        type: 'POST',
        timeout: 5000,
        url: '/login',
        data: {'nick': nick, ts: '', 'hash': hash, 'rememberme': rememberme},
        cache: false,
        dataType: 'json',
        success: onSuccess,
        error: onError
    });
}

// http://plugins.jquery.com/project/autocenter
(function($){
    $.fn.extend({
        center: function () {
            return this.each(function() {
                var top = ($(window).height() - $(this).outerHeight()) / 2;
                var left = ($(window).width() - $(this).outerWidth()) / 2;
                $(this).css({position:'absolute', margin:0, top: (top > 0 ? top : 0)+'px', left: (left > 0 ? left : 0)+'px'});
            });
        }
    }); 
})(jQuery);

(function($) {
    $.fn.extend({
        ridgificate: function() {
            var ridges = arguments;
            return this.each(function() {
                for (var i = 0; i < ridges.length; i++) {
                    $(this).wrap('<div style="border: ' + ridges[i] + '">');
                }
            });
        }});
})(jQuery);

var LogoFadeDelay = 3000;
var PrevMouseCoord = [-1, -1];

$(function() {
    $(document).mousemove(function(e) {
        if (e.pageX == PrevMouseCoord[0] && e.pageY == PrevMouseCoord[1])
            return;
        PrevMouseCoord = [e.pageX, e.pageY];
        $('#memelogo').stop(true, false).animate({opacity: 1.0}, "fast").delay(LogoFadeDelay).animate({opacity: 0}, "slow");
    });
    $('#memelogo').delay(LogoFadeDelay).animate({opacity: 0}, "slow");
});