814 lines · 37.7 KB · JavaScript
RawDownload
/*jslint browser:true *//*jslint maxlen: 180*/"use strict";////  SnapshotReview.js//  scripts/system/html/js/////  Created by Howard Stearns 8/22/2016//  Copyright 2016 High Fidelity, Inc.////  Distributed under the Apache License, Version 2.0.//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html// var paths = [];var idCounter = 0;var imageCount = 0;var blastShareText = "Blast to my Connections",    blastAlreadySharedText = "Already Blasted to Connections",    hifiShareText = "Share to Snaps Feed",    hifiAlreadySharedText = "Already Shared to Snaps Feed",    facebookShareText = "Share to Facebook",    twitterShareText = "Share to Twitter",    shareButtonLabelTextActive = "SHARE&#58;",    shareButtonLabelTextInactive = "SHARE"; function fileExtensionMatches(filePath, extension) {    return filePath.split('.').pop().toLowerCase() === extension;} function showSetupInstructions() {    var snapshotImagesDiv = document.getElementById("snapshot-images");    snapshotImagesDiv.className = "snapshotInstructions";    snapshotImagesDiv.innerHTML = '<img class="centeredImage" src="./img/snapshotIcon.png" alt="Snapshot Instructions" width="64" height="64"/>' +        '<br/>' +        '<p>Take and share snaps and GIFs with people in Overte, Facebook, and Twitter.</p>' +        "<h4>Setup Instructions</h4>" +        "<p>Before you can begin taking snaps, please choose where you'd like to save snaps on your computer:</p>" +        '<br/>' +        '<div style="text-align:center;">' +            '<input class="blueButton" style="margin-left:auto;margin-right:auto;width:130px;" type="button" value="CHOOSE" onclick="chooseSnapshotLocation()" />' +        '</div>';    document.getElementById("snap-button").disabled = true;}function showSetupComplete() {    var snapshotImagesDiv = document.getElementById("snapshot-images");    snapshotImagesDiv.className = "snapshotInstructions";    snapshotImagesDiv.innerHTML = '<img class="centeredImage" src="./img/snapshotIcon.png" alt="Snapshot Instructions" width="64" height="64"/>' +        '<br/>' +        '<div style="text-align:center;font-weight:bold;">' +            '<p>Snapshot location set.</p>' +            '<p>Press the big red button to take a snap!</p>' +        '</div>';    document.getElementById("snap-button").disabled = false;}function showSnapshotInstructions() {    var snapshotImagesDiv = document.getElementById("snapshot-images");    snapshotImagesDiv.className = "snapshotInstructions";    snapshotImagesDiv.innerHTML = '<img class="centeredImage" src="./img/snapshotIcon.png" alt="Snapshot Instructions" width="64" height="64"/>' +        '<br/>' +        '<p>Take and share snaps and GIFs with people in Overte, Facebook, and Twitter.</p>' +        '<br/>' +        '<div style="text-align:center;font-weight:bold;">' +            '<p>Press the big red button to take a snap!</p>' +        '</div>';}function chooseSnapshotLocation() {    EventBridge.emitWebEvent(JSON.stringify({        type: "snapshot",        action: "chooseSnapshotLocation"    }));}function login() {    EventBridge.emitWebEvent(JSON.stringify({        type: "snapshot",        action: "login"    }));}function clearImages() {    var snapshotImagesDiv = document.getElementById("snapshot-images");    snapshotImagesDiv.classList.remove("snapshotInstructions");    while (snapshotImagesDiv.hasChildNodes()) {        snapshotImagesDiv.removeChild(snapshotImagesDiv.lastChild);    }    paths = [];    imageCount = 0;    idCounter = 0;} function selectImageWithHelpText(selectedID, isSelected) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `selectedID` is passed as an HTML object to these functions; we just want the ID    }    var imageContainer = document.getElementById(selectedID),        image = document.getElementById(selectedID + 'img'),        shareBar = document.getElementById(selectedID + "shareBar"),        helpTextDiv = document.getElementById(selectedID + "helpTextDiv"),        showShareButtonsButtonDiv = document.getElementById(selectedID + "showShareButtonsButtonDiv"),        itr,        containers = document.getElementsByClassName("shareControls");     if (isSelected) {        showShareButtonsButtonDiv.onclick = function () { selectImageWithHelpText(selectedID, false); };        showShareButtonsButtonDiv.classList.remove("inactive");        showShareButtonsButtonDiv.classList.add("active");         image.onclick = function () { selectImageWithHelpText(selectedID, false); };        imageContainer.style.outline = "4px solid #00b4ef";        imageContainer.style.outlineOffset = "-4px";         shareBar.style.backgroundColor = "rgba(0, 0, 0, 0.45)";        shareBar.style.pointerEvents = "initial";         helpTextDiv.style.visibility = "visible";         for (itr = 0; itr < containers.length; itr += 1) {            var parentID = containers[itr].id.slice(0, 2);            if (parentID !== selectedID) {                selectImageWithHelpText(parentID, false);            }        }    } else {        showShareButtonsButtonDiv.onclick = function () { selectImageWithHelpText(selectedID, true); };        showShareButtonsButtonDiv.classList.remove("active");        showShareButtonsButtonDiv.classList.add("inactive");         image.onclick = function () { selectImageWithHelpText(selectedID, true); };        imageContainer.style.outline = "none";         shareBar.style.backgroundColor = "rgba(0, 0, 0, 0.0)";        shareBar.style.pointerEvents = "none";         helpTextDiv.style.visibility = "hidden";    }}function selectImageToShare(selectedID, isSelected) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `selectedID` is passed as an HTML object to these functions; we just want the ID    }    var imageContainer = document.getElementById(selectedID),        image = document.getElementById(selectedID + 'img'),        shareBar = document.getElementById(selectedID + "shareBar"),        showShareButtonsDots = document.getElementById(selectedID + "showShareButtonsDots"),        showShareButtonsLabel = document.getElementById(selectedID + "showShareButtonsLabel"),        shareButtonsDiv = document.getElementById(selectedID + "shareButtonsDiv"),        shareBarHelp = document.getElementById(selectedID + "shareBarHelp"),        showShareButtonsButtonDiv = document.getElementById(selectedID + "showShareButtonsButtonDiv"),        itr,        containers = document.getElementsByClassName("shareControls");     if (isSelected) {        showShareButtonsButtonDiv.onclick = function () { selectImageToShare(selectedID, false); };        showShareButtonsButtonDiv.classList.remove("inactive");        showShareButtonsButtonDiv.classList.add("active");         image.onclick = function () { selectImageToShare(selectedID, false); };        imageContainer.style.outline = "4px solid #00b4ef";        imageContainer.style.outlineOffset = "-4px";         shareBar.style.backgroundColor = "rgba(0, 0, 0, 0.45)";        shareBar.style.pointerEvents = "initial";         showShareButtonsDots.style.visibility = "hidden";        showShareButtonsLabel.innerHTML = shareButtonLabelTextActive;         shareButtonsDiv.style.visibility = "visible";        shareBarHelp.style.visibility = "visible";         for (itr = 0; itr < containers.length; itr += 1) {            var parentID = containers[itr].id.slice(0, 2);            if (parentID !== selectedID) {                selectImageToShare(parentID, false);            }        }    } else {        showShareButtonsButtonDiv.onclick = function () { selectImageToShare(selectedID, true); };        showShareButtonsButtonDiv.classList.remove("active");        showShareButtonsButtonDiv.classList.add("inactive");         image.onclick = function () { selectImageToShare(selectedID, true); };        imageContainer.style.outline = "none";         shareBar.style.backgroundColor = "rgba(0, 0, 0, 0.0)";        shareBar.style.pointerEvents = "none";         showShareButtonsDots.style.visibility = "visible";        showShareButtonsLabel.innerHTML = shareButtonLabelTextInactive;         shareButtonsDiv.style.visibility = "hidden";        shareBarHelp.style.visibility = "hidden";    }}function createShareBar(parentID, isLoggedIn, canShare, isGif, blastButtonDisabled, hifiButtonDisabled, canBlast) {    var shareBar = document.createElement("div"),        shareBarHelpID = parentID + "shareBarHelp",        shareButtonsDivID = parentID + "shareButtonsDiv",        showShareButtonsButtonDivID = parentID + "showShareButtonsButtonDiv",        showShareButtonsDotsID = parentID + "showShareButtonsDots",        showShareButtonsLabelID = parentID + "showShareButtonsLabel",        blastToConnectionsButtonID = parentID + "blastToConnectionsButton",        shareWithEveryoneButtonID = parentID + "shareWithEveryoneButton",        facebookButtonID = parentID + "facebookButton",        twitterButtonID = parentID + "twitterButton",        shareBarInnerHTML = '';     shareBar.id = parentID + "shareBar";    shareBar.className = "shareControls";     if (isLoggedIn) {        if (canShare) {            shareBarInnerHTML = '<div class="shareControlsHelp" id="' + shareBarHelpID + '" style="visibility:hidden;' + ((canBlast && blastButtonDisabled || !canBlast && hifiButtonDisabled) ? "background-color:#000;opacity:0.5;" : "") + '"></div>' +                '<div class="showShareButtonsButtonDiv inactive" id="' + showShareButtonsButtonDivID + '" onclick="selectImageToShare(' + parentID + ', true)">' +                    '<label id="' + showShareButtonsLabelID + '">' + shareButtonLabelTextInactive + '</label>' +                    '<span id="' + showShareButtonsDotsID + '" class="showShareButtonDots">' +                        '&#xe019;' +                    '</div>' +                '</div>' +                '<div class="shareButtons" id="' + shareButtonsDivID + '" style="visibility:hidden">';            if (canBlast) {                shareBarInnerHTML += '<div class="shareButton blastToConnections' + (blastButtonDisabled ? ' disabled' : '') + '" id="' + blastToConnectionsButtonID + '" onmouseover="shareButtonHovered(\'blast\', ' + parentID + ', true)" onclick="' + (blastButtonDisabled ? '' : 'blastToConnections(' + parentID + ', ' + isGif + ')') + '"><img src="img/blast_icon.svg"></div>';            }            shareBarInnerHTML += '<div class="shareButton shareWithEveryone' + (hifiButtonDisabled ? ' disabled' : '') + '" id="' + shareWithEveryoneButtonID + '" onmouseover="shareButtonHovered(\'hifi\', ' + parentID + ', true)" onclick="' + (hifiButtonDisabled ? '' : 'shareWithEveryone(' + parentID + ', ' + isGif + ')') + '"><img src="img/hifi_icon.svg" style="width:35px;height:35px;margin:2px 0 0 2px;"></div>' +                    '<a class="shareButton facebookButton" id="' + facebookButtonID + '" onmouseover="shareButtonHovered(\'facebook\', ' + parentID + ', true)" onclick="shareButtonClicked(\'facebook\', ' + parentID + ')"><img src="img/fb_icon.svg"></a>' +                    '<a class="shareButton twitterButton" id="' + twitterButtonID + '" onmouseover="shareButtonHovered(\'twitter\', ' + parentID + ', true)" onclick="shareButtonClicked(\'twitter\', ' + parentID + ')"><img src="img/twitter_icon.svg"></a>' +                '</div>';             // Add onclick handler to parent DIV's img to toggle share buttons            document.getElementById(parentID + 'img').onclick = function () { selectImageToShare(parentID, true); };        } else {            shareBarInnerHTML = '<div class="showShareButtonsButtonDiv inactive" id="' + showShareButtonsButtonDivID + '" onclick="selectImageToShare(' + parentID + ', true)">' +                    '<label id="' + showShareButtonsLabelID + '">' + shareButtonLabelTextInactive + '</label>' +                    '<span class="showShareButtonDots">' +                        '&#xe019;' +                    '</div>' +                '</div>' +                '<div class="helpTextDiv" id="' + parentID + 'helpTextDiv' + '" style="visibility:hidden;text-align:left;">' +                    'This snap was taken in an unshareable domain.' +                '</div>';            // Add onclick handler to parent DIV's img to toggle share buttons            document.getElementById(parentID + 'img').onclick = function () { selectImageWithHelpText(parentID, true); };        }    } else {        shareBarInnerHTML = '<div class="showShareButtonsButtonDiv inactive" id="' + showShareButtonsButtonDivID + '" onclick="selectImageToShare(' + parentID + ', true)">' +                '<label id="' + showShareButtonsLabelID + '">' + shareButtonLabelTextInactive + '</label>' +                '<span class="showShareButtonDots">' +                    '&#xe019;' +                '</div>' +            '</div>' +            '<div class="helpTextDiv" id="' + parentID + 'helpTextDiv' + '" style="visibility:hidden;text-align:right;">' +                'Please log in to share snaps' + '<input class="grayButton" style="margin-left:20px;width:95px;height:30px;" type="button" value="LOG IN" onclick="login()" />' +            '</div>';        // Add onclick handler to parent DIV's img to toggle share buttons        document.getElementById(parentID + 'img').onclick = function () { selectImageWithHelpText(parentID, true); };    }     shareBar.innerHTML = shareBarInnerHTML;     return shareBar;}function appendShareBar(divID, isLoggedIn, canShare, isGif, blastButtonDisabled, hifiButtonDisabled, canBlast) {    if (divID.id) {        divID = divID.id; // sometimes (?), `containerID` is passed as an HTML object to these functions; we just want the ID    }    document.getElementById(divID).appendChild(createShareBar(divID, isLoggedIn, canShare, isGif, blastButtonDisabled, hifiButtonDisabled, canBlast));    if (divID === "p0") {        if (isLoggedIn) {            if (canShare) {                selectImageToShare(divID, true);            } else {                selectImageWithHelpText(divID, true);            }        } else {            selectImageWithHelpText(divID, true);        }    }    if (isLoggedIn && canShare) {        if (canBlast) {            shareButtonHovered('blast', divID, false);        } else {            shareButtonHovered('hifi', divID, false);        }    }}function shareForUrl(selectedID) {    EventBridge.emitWebEvent(JSON.stringify({        type: "snapshot",        action: "shareSnapshotForUrl",        data: paths[parseInt(selectedID.substring(1), 10)]    }));}function addImage(image_data, isLoggedIn, canShare, isGifLoading, isShowingPreviousImages, blastButtonDisabled, hifiButtonDisabled, canBlast) {    if (!image_data.localPath) {        return;    }    var imageContainer = document.createElement("DIV"),        img = document.createElement("IMG"),        isGif = fileExtensionMatches(image_data.localPath, "gif"),        id = "p" + (isGif ? "1" : "0");    imageContainer.id = id;    imageContainer.style.width = "95%";    imageContainer.style.height = "240px";    imageContainer.style.margin = "5px auto";    imageContainer.style.display = "flex";    imageContainer.style.justifyContent = "center";    imageContainer.style.alignItems = "center";    imageContainer.style.position = "relative";    img.id = id + "img";    img.src = image_data.localPath;    imageContainer.appendChild(img);    document.getElementById("snapshot-images").appendChild(imageContainer);    paths.push(image_data.localPath);    img.onload = function () {        if (isGif) {            imageContainer.innerHTML += '<span class="gifLabel">GIF</span>';        }        /*if (!isGifLoading) {            appendShareBar(id, isLoggedIn, canShare, isGif, blastButtonDisabled, hifiButtonDisabled, canBlast);        }        if ((!isShowingPreviousImages && ((isGif && !isGifLoading) || !isGif)) || (isShowingPreviousImages && !image_data.story_id)) {            shareForUrl(id);        }        if (isShowingPreviousImages && isLoggedIn && image_data.story_id) {            updateShareInfo(id, image_data.story_id);        }        if (isShowingPreviousImages) {            requestPrintButtonUpdate();          }*/    };    img.onerror = function () {        img.onload = null;        img.src = image_data.errorPath;        EventBridge.emitWebEvent(JSON.stringify({            type: "snapshot",            action: "alertSnapshotLoadFailed"        }));    };}function showConfirmationMessage(selectedID, destination) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `containerID` is passed as an HTML object to these functions; we just want the ID    }     var opacity = 2.0,        fadeRate = 0.05,        timeBetweenFadesMS = 50,        confirmationMessageContainer = document.createElement("div"),        confirmationMessage = document.createElement("div");    confirmationMessageContainer.className = "confirmationMessageContainer";     confirmationMessage.className = "confirmationMessage";     var socialIcon = document.createElement("img");    switch (destination) {        case 'blast':            socialIcon.src = "img/blast_icon.svg";            confirmationMessage.appendChild(socialIcon);            confirmationMessage.innerHTML += '<span>Blast Sent!</span>';            confirmationMessage.style.backgroundColor = "#EA4C5F";            break;        case 'hifi':            socialIcon.src = "img/hifi_icon.svg";            confirmationMessage.appendChild(socialIcon);            confirmationMessage.innerHTML += '<span>Snap Shared!</span>';            confirmationMessage.style.backgroundColor = "#1FC6A6";            break;    }     confirmationMessageContainer.appendChild(confirmationMessage);    document.getElementById(selectedID).appendChild(confirmationMessageContainer);     setInterval(function () {        if (opacity <= fadeRate) {            confirmationMessageContainer.remove();        }        opacity -= fadeRate;        confirmationMessageContainer.style.opacity = opacity;    }, timeBetweenFadesMS);}function showUploadingMessage(selectedID, destination) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `containerID` is passed as an HTML object to these functions; we just want the ID    }     var shareBarHelp = document.getElementById(selectedID + "shareBarHelp");     shareBarHelp.innerHTML = '<img style="display:inline;width:25px;height:25px;" src="./img/loader.gif"></img><span style="position:relative;margin-left:5px;bottom:7px;">Preparing to Share</span>';    shareBarHelp.classList.add("uploading");    shareBarHelp.setAttribute("data-destination", destination);}function hideUploadingMessageAndMaybeShare(selectedID, storyID) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `containerID` is passed as an HTML object to these functions; we just want the ID    }     var shareBarHelp = document.getElementById(selectedID + "shareBarHelp"),        shareBarHelpDestination = shareBarHelp.getAttribute("data-destination");     shareBarHelp.classList.remove("uploading");    if (shareBarHelpDestination) {        switch (shareBarHelpDestination) {            case 'blast':                blastToConnections(selectedID, selectedID === "p1");                shareBarHelp.innerHTML = blastAlreadySharedText;                break;            case 'hifi':                shareWithEveryone(selectedID, selectedID === "p1");                shareBarHelp.innerHTML = hifiAlreadySharedText;                break;            case 'facebook':                var facebookButton = document.getElementById(selectedID + "facebookButton");                window.open(facebookButton.getAttribute("href"), "_blank");                shareBarHelp.innerHTML = facebookShareText;                // This emitWebEvent() call isn't necessary in the "hifi" and "blast" cases                // because the "removeFromStoryIDsToMaybeDelete()" call happens                // in snapshot.js when sharing with that method.                EventBridge.emitWebEvent(JSON.stringify({                    type: "snapshot",                    action: "removeFromStoryIDsToMaybeDelete",                    story_id: storyID                }));                break;            case 'twitter':                var twitterButton = document.getElementById(selectedID + "twitterButton");                window.open(twitterButton.getAttribute("href"), "_blank");                shareBarHelp.innerHTML = twitterShareText;                EventBridge.emitWebEvent(JSON.stringify({                    type: "snapshot",                    action: "removeFromStoryIDsToMaybeDelete",                    story_id: storyID                }));                break;        }         shareBarHelp.setAttribute("data-destination", "");    }}function updateShareInfo(containerID, storyID) {    if (containerID.id) {        containerID = containerID.id; // sometimes (?), `containerID` is passed as an HTML object to these functions; we just want the ID    }    var shareBar = document.getElementById(containerID + "shareBar"),        parentDiv = document.getElementById(containerID),        shareURL = "https://highfidelity.com/user_stories/" + storyID,        facebookButton = document.getElementById(containerID + "facebookButton"),        twitterButton = document.getElementById(containerID + "twitterButton");     parentDiv.setAttribute('data-story-id', storyID);     facebookButton.setAttribute("target", "_blank");    facebookButton.setAttribute("href", 'https://www.facebook.com/dialog/feed?app_id=1585088821786423&link=' + shareURL);     twitterButton.setAttribute("target", "_blank");    twitterButton.setAttribute("href", 'https://twitter.com/intent/tweet?text=I%20just%20took%20a%20snapshot!&url=' + shareURL + '&via=highfidelityVR&hashtags=VR,HiFi');     hideUploadingMessageAndMaybeShare(containerID, storyID);}function blastToConnections(selectedID, isGif) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `selectedID` is passed as an HTML object to these functions; we just want the ID    }     var blastToConnectionsButton = document.getElementById(selectedID + "blastToConnectionsButton"),        shareBar = document.getElementById(selectedID + "shareBar"),        shareBarHelp = document.getElementById(selectedID + "shareBarHelp");    blastToConnectionsButton.onclick = function () { };     var storyID = document.getElementById(selectedID).getAttribute("data-story-id");     if (storyID) {        EventBridge.emitWebEvent(JSON.stringify({            type: "snapshot",            action: "blastToConnections",            story_id: storyID,            isGif: isGif        }));        showConfirmationMessage(selectedID, 'blast');        blastToConnectionsButton.classList.add("disabled");        blastToConnectionsButton.style.backgroundColor = "#000000";        blastToConnectionsButton.style.opacity = "0.5";        shareBarHelp.style.backgroundColor = "#000000";        shareBarHelp.style.opacity = "0.5";    } else {        showUploadingMessage(selectedID, 'blast');    }}function shareWithEveryone(selectedID, isGif) {    if (selectedID.id) {        selectedID = selectedID.id; // sometimes (?), `selectedID` is passed as an HTML object to these functions; we just want the ID    }     var shareWithEveryoneButton = document.getElementById(selectedID + "shareWithEveryoneButton"),        shareBar = document.getElementById(selectedID + "shareBar"),        shareBarHelp = document.getElementById(selectedID + "shareBarHelp");    shareWithEveryoneButton.onclick = function () { };     var storyID = document.getElementById(selectedID).getAttribute("data-story-id");     if (storyID) {        EventBridge.emitWebEvent(JSON.stringify({            type: "snapshot",

Lines 1–500 of 814.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t