Socialify

Folder ..

Viewing postHandler.js
186 lines (163 loc) • 5.7 KB

  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
function editComment(id) {
    document.getElementById('comment-body-' + id).style.display = 'none';
    document.getElementById('edit-form-' + id).style.display = 'block';
}

function cancelEdit(id) {
    document.getElementById('comment-body-' + id).style.display = 'block';
    document.getElementById('edit-form-' + id).style.display = 'none';
}

function cd() {
    // we will clear the user cookies
    document.cookie = 'anonymous_name=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
    document.cookie = 'anonymous_email=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
    document.cookie = 'anonymous_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
    window.location.reload();
}

function toggleTips() {
    var tips = document.getElementById('tips');
    $('#tips').slideToggle('fast');
}

function toggleGotchas() {
    var gotchas = document.getElementById('gotchas');
    $('#gotchas').slideToggle('fast');
}

function toggleAnon() {
    $('#ancmClick').toggle();
    $('#anonymous-comment-form').slideToggle('fast');
};

function toggleCreds() {
    $('#creds').slideToggle('fast');
};

function lightsOff() {
    // #overlay. Go from 0.8 -> 0.9 opacity
    var currentStatus = $('#lightsStatus').attr('data-status');
    var windowWidth = document.documentElement.clientWidth;
    if (currentStatus == 'on') {
        $('#overlay').fadeTo('fast', 0.8);
        if (windowWidth > 480) {
            $('#sidebar').children().fadeTo('fast', 1);
            $('#header').fadeTo('fast', 1);
            $('#footer').fadeTo('fast', 1);
        }
        $('#lightsStatus').attr('data-status', 'off');
        $('#lightsStatus').attr('src', offImage);
        localStorage.setItem('lights', 'off');
    } else {
        $('#overlay').fadeTo('fast', 0.9);
        if (windowWidth > 480) {
            $('#sidebar').children().fadeTo('fast', 0.2);
            $('#header').fadeTo('fast', 0.2);
            $('#footer').fadeTo('fast', 0.2);
        }
        $('#lightsStatus').attr('data-status', 'on');
        $('#lightsStatus').attr('src', onImage);
        localStorage.setItem('lights', 'on');
    }
}

function blindMode() {
    var articleBody = $('#article-body');
    var currentStatus = $('#blindStatus').attr('data-status');
    var windowWidth = document.documentElement.clientWidth;
    if (currentStatus == 'off') {
        // turn on. On phones set font-size to 16px (<480 units), on desktop set font-size to 13px
        if (windowWidth < 480) {
            articleBody.animate({
                fontSize: '15px'
              }, 100);             
        } else {
            articleBody.animate({
                fontSize: '13px'
              }, 100);
           
        }
        $('#blindStatus').attr('data-status', 'on');
        $('#blindStatus').attr('src', onImage);

        // we will allow blind mode to persist across pages, in local storage
        localStorage.setItem('blindMode', 'on');
    } else {
        // turn off. Phones - 12px, Desktop - 11px
        if (windowWidth < 480) {
            articleBody.animate({
                fontSize: '13px'
            }, 100);
        } else {
            articleBody.animate({
                fontSize: '11px'
            }, 100);
        }
        $('#blindStatus').attr('data-status', 'off');
        $('#blindStatus').attr('src', offImage);

        localStorage.setItem('blindMode', 'off');
    }
}

// if localStorage has blindMode set to on, then turn on blindMode
var blindModeStatus = localStorage.getItem('blindMode');
var lightsStatus = localStorage.getItem('lights');
if (!blindModeStatus) {
    localStorage.setItem('blindMode', 'on');
    blindModeStatus = 'on';
}

if (blindModeStatus == 'on') {
    blindMode();
}

if (!lightsStatus) {
    localStorage.setItem('lights', 'off');
    lightsStatus = 'off';
}

if (lightsStatus == 'on') {
    lightsOff();
}

var allInputElementsOnPage = $('input');

// If lights are off, then on hover on sidebar .children(), fadeTo 1 for currently hovered child
$('#sidebar').children().hover(function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        $(this).fadeTo('fast', 0.85);
    }
}, function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    // if none of the input elements are focused, then fadeTo 0.2
    if (currentStatus == 'on' && allInputElementsOnPage.is(':focus') == false) {
        $(this).fadeTo('fast', 0.2);
    }
});

// same for header and footer
$('#header').hover(function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        $(this).fadeTo('fast', 0.85);
    }
}, function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on' && allInputElementsOnPage.is(':focus') == false) {
        $(this).fadeTo('fast', 0.2);
    }
});

$('#search-form > input[type=text]').blur(function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        var isHovered = $('#header').is(':hover');
        if (isHovered == false) {
            $('#header').fadeTo('fast', 0.2);
        }
    }
});

$('#login-form > input').blur(function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        var isHovered = $('#login-area').is(':hover');
        if (isHovered == false) {
            $('#login-area').fadeTo('fast', 0.2);
        }
    }
});

$('#footer').hover(function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        $(this).fadeTo('fast', 0.85);
    }
}, function() {
    var currentStatus = $('#lightsStatus').attr('data-status');
    if (currentStatus == 'on') {
        $(this).fadeTo('fast', 0.2);
    }
});