blockbench/js/web.js

66 lines
2.0 KiB
JavaScript
Raw Normal View History

Blockbench.queries = {};
(function() {
let query_string = location.search || location.hash;
if (query_string) {
query_string = decodeURIComponent(query_string.substring(1));
let queries = query_string.split('&');
queries.forEach(string => {
let [key, value] = string.split(/=\s*(.+)/);
Blockbench.queries[key] = value || true;
})
}
})()
2019-12-15 20:04:31 +01:00
function initializeWebApp() {
2019-07-17 18:02:07 +02:00
$(document.body).on('click', 'a[href]', (event) => {
event.preventDefault();
window.open(event.target.href, '_blank');
2018-10-17 19:50:25 +02:00
});
if (location.host == 'blockbench-dev.netlify.app') {
let button = $(`<a href="https://www.netlify.com/" style="padding: 3px 8px; color: white; cursor: pointer; text-decoration: none;" target="_blank" rel="noopener">
Hosted by
<img src="https://www.blockbench.net/_nuxt/74d4819838c06fa271394f626e8c4b16.svg" height="20px" style="vertical-align: text-top;">
</div>`);
button.insertBefore('#web_download_button');
}
if (!Blockbench.isTouch && !Blockbench.isPWA) {
2019-07-17 18:02:07 +02:00
$('#web_download_button').show()
2017-10-26 19:00:52 +02:00
}
if (Blockbench.browser == 'firefox') {
document.body.style.imageRendering = 'crisp-edges'
}
}
try {
window.matchMedia('(display-mode: standalone)').addEventListener('change', (evt) => {
if (!Blockbench.isMobile) $('#web_download_button').toggle(!evt.matches);
});
} catch (err) {
if (!Blockbench.isMobile) $('#web_download_button').hide();
}
function loadInfoFromURL() {
if (Blockbench.queries.session) {
EditSession.token = Blockbench.queries.session;
BarItems.edit_session.click();
2018-12-27 14:03:04 +01:00
}
2021-07-06 21:34:46 +02:00
if (Blockbench.queries.m) {
$.getJSON(`https://blckbn.ch/api/models/${Blockbench.queries.m}`, (model) => {
2021-07-06 21:34:46 +02:00
Codecs.project.load(model, {path: ''});
2020-11-13 20:43:22 +01:00
})
2020-03-04 20:56:17 +01:00
}
2019-12-15 20:04:31 +01:00
}
2017-10-26 19:00:52 +02:00
//Misc
window.onbeforeunload = function() {
let unsaved_projects = ModelProject.all.find(project => !project.saved);
if (unsaved_projects) {
2019-07-17 18:02:07 +02:00
return 'Unsaved Changes';
2019-04-12 22:39:53 +02:00
} else {
2020-07-16 09:32:59 +02:00
Blockbench.dispatchEvent('before_closing')
if (Project.EditSession) Project.EditSession.quit()
2017-10-26 19:00:52 +02:00
}
}