mirror of
https://github.com/lubosz/overte.git
synced 2025-08-27 08:25:53 +02:00
Replace Clara download button with own
This commit is contained in:
parent
39070fe0d1
commit
530b176d09
1 changed files with 13 additions and 39 deletions
|
@ -111,61 +111,35 @@
|
|||
element.setAttribute("href", href + parameters);
|
||||
}
|
||||
|
||||
// Replace download options with a single, "Download to High Fidelity" option.
|
||||
// Remove unwanted buttons and replace download options with a single "Download to High Fidelity" button.
|
||||
var buttons = $("a.embed-button").parent("div");
|
||||
if (buttons.length > 0) {
|
||||
var downloadFBX = buttons.find("a[data-extension=\'fbx\']")[0];
|
||||
downloadFBX.addEventListener("click", startAutoDownload);
|
||||
var firstButton = buttons.children(":first-child")[0];
|
||||
buttons[0].insertBefore(downloadFBX, firstButton);
|
||||
downloadFBX.setAttribute("class", "btn btn-primary download");
|
||||
downloadFBX.innerHTML = "<i class=\'glyphicon glyphicon-download-alt\'></i> Download to High Fidelity";
|
||||
buttons.children(":nth-child(2), .btn-group , .embed-button").each(function () { this.remove(); });
|
||||
var downloadFBX;
|
||||
if (buttons.find("div.btn-group").length > 0) {
|
||||
buttons.children(".btn-primary, .btn-group , .embed-button").each(function () { this.remove(); });
|
||||
if ($("#hifi-download-container").length === 0) { // Button hasn't been moved already.
|
||||
downloadFBX = $('<a class="btn btn-primary"><i class=\'glyphicon glyphicon-download-alt\'></i> Download to High Fidelity</a>');
|
||||
buttons.prepend(downloadFBX);
|
||||
downloadFBX[0].addEventListener("click", startAutoDownload);
|
||||
}
|
||||
}
|
||||
|
||||
// Move the "Download to High Fidelity" button to be more visible on tablet.
|
||||
if ($("#hifi-download-container").length === 0 && window.innerWidth < 700) {
|
||||
// Moving the button stops the Clara.io download from starting so instead, make a visual copy in the right place
|
||||
// and wire its click event to click the original button.
|
||||
var downloadContainer = $('<div id="hifi-download-container"></div>');
|
||||
$(".top-title .col-sm-4").append(downloadContainer);
|
||||
var downloadButton = $("a[data-extension=\'fbx\']").clone();
|
||||
downloadButton[0].addEventListener("click", function () { downloadFBX.click(); });
|
||||
downloadContainer.append(downloadButton);
|
||||
downloadFBX.style.visibility = "hidden";
|
||||
downloadContainer.append(downloadFBX);
|
||||
}
|
||||
|
||||
// Automatic download to High Fidelity.
|
||||
var downloadTimer;
|
||||
function startAutoDownload(event) {
|
||||
function startAutoDownload() {
|
||||
if (!canWriteAssets) {
|
||||
console.log("Clara.io FBX file download cancelled because no permissions to write to Asset Server");
|
||||
EventBridge.emitWebEvent(WARN_USER_NO_PERMISSIONS);
|
||||
event.stopPropagation();
|
||||
return;
|
||||
}
|
||||
|
||||
window.scrollTo(0, 0); // Scroll to top ready for history.back().
|
||||
if (!downloadTimer) {
|
||||
downloadTimer = setInterval(autoDownload, 1000);
|
||||
}
|
||||
}
|
||||
function autoDownload() {
|
||||
if ($("div.download-body").length !== 0) {
|
||||
var downloadButton = $("div.download-body a.download-file");
|
||||
if (downloadButton.length > 0) {
|
||||
clearInterval(downloadTimer);
|
||||
downloadTimer = null;
|
||||
var href = downloadButton[0].href;
|
||||
EventBridge.emitWebEvent(CLARA_IO_DOWNLOAD + " " + href);
|
||||
console.log("Clara.io FBX file download initiated for " + href);
|
||||
$("a.btn.cancel").click();
|
||||
history.back(); // Remove history item created by clicking "download".
|
||||
};
|
||||
} else if ($("div#view-signup_login_dialog").length === 0) {
|
||||
// Don't stop checking for button if user is asked to log in.
|
||||
clearInterval(downloadTimer);
|
||||
downloadTimer = null;
|
||||
}
|
||||
// TODO: Initiate download using Clara.io API.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue