IE9 Thumbnail Controls for Webs.com

Javascript code posted by Mike Lu
created at 20 Dec 23:23, updated at 20 Dec 23:24

Edit | Back
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
// thumbnail control buttons section

// declare 2 buttons
var btnLogIn = window.external.msSiteModeAddThumbBarButton('http://i.hebimage.com/1211/4eebc7a8c0539.ico', 'Sign In');
var btnRegister = window.external.msSiteModeAddThumbBarButton('http://i.hebimage.com/1211/4eebc7f1305a2.ico', 'Register');

// declare 2 styles for button 1
var styleLogIn = 0;
var styleLogOut = window.external.msSiteModeAddButtonStyle(btnLogIn, 'http://i.hebimage.com/1211/4eebc7a8c0539.ico', 'Sign Out');

// declare flag for log-in detection
var loggedIn = false;

if (window.external.msIsSiteMode()) { // if pinned

    // add event listener (traditional IE style) for responding mouse clicks on buttons
    document.attachEvent('onmsthumbnailclick', onButtonClicked);
    window.attachEvent('onunload', onBodyUnloaded);
    }

    // detect log-in status by checking the existence of log-in module (Members Area)
    if (document.getElementById("login-module")) {
        loggedIn = false;
    }
    else {
        loggedIn = true;
    }
    if (loggedIn == false) { // if not logged in
        window.external.msSiteModeShowButtonStyle(btnLogIn, styleLogIn);
        window.external.msSiteModeUpdateThumbBarButton(btnRegister, true, true);
    }
    else { // if already logged in
        window.external.msSiteModeShowButtonStyle(btnLogIn, styleLogOut);
        window.external.msSiteModeUpdateThumbBarButton(btnRegister, false, true);
    }
    window.external.msSiteModeShowThumbBar();
}

// code for clicking buttons
function onButtonClicked(btn) {

    // button 1 (Sign In)
    if (btn.buttonID == btnLogIn) {
        if (loggedIn == false) { // if not logged in
            window.location = "/apps/auth/login?try=1&next=";
        }
        else { // if already logged in
            window.location = "/apps/auth/logout";
        }
    }

    // button 2 (Register)
    else if (btn.buttonID == btnRegister) {
        window.location = "/apps/auth/signup";
    }
}

// code to hide buttons after clicking them
function onBodyUnloaded() {
    window.external.msSiteModeUpdateThumbBarButton(btnLogIn, true, false);
    window.external.msSiteModeUpdateThumbBarButton(btnRegister, true, false);
}
2.19 KB in 3 ms with coderay