2022-03-26 05:39:06 +08:00
|
|
|
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-16 03:04:31 +08:00
|
|
|
function initializeWebApp() {
|
2019-07-18 00:02:07 +08:00
|
|
|
|
|
|
|
$(document.body).on('click', 'a[href]', (event) => {
|
|
|
|
event.preventDefault();
|
2022-09-01 04:54:46 +08:00
|
|
|
window.open(event.currentTarget.href, '_blank');
|
2018-10-18 01:50:25 +08:00
|
|
|
});
|
2021-09-19 19:22:29 +08: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');
|
|
|
|
}
|
2021-02-21 23:46:06 +08:00
|
|
|
if (!Blockbench.isTouch && !Blockbench.isPWA) {
|
2019-07-18 00:02:07 +08:00
|
|
|
$('#web_download_button').show()
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
2020-09-27 23:18:15 +08:00
|
|
|
|
|
|
|
if (Blockbench.browser == 'firefox') {
|
|
|
|
document.body.style.imageRendering = 'crisp-edges'
|
|
|
|
}
|
|
|
|
}
|
2022-08-21 03:11:47 +08:00
|
|
|
addEventListener('load', function() {
|
|
|
|
window.history.pushState({}, '')
|
|
|
|
})
|
|
|
|
addEventListener('popstate', e => {
|
|
|
|
if (ModelProject.all.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open_interface) {
|
|
|
|
if (typeof open_interface.cancel == 'function') {
|
|
|
|
open_interface.cancel(event);
|
|
|
|
} else if (typeof open_interface == 'string' && open_dialog) {
|
|
|
|
$('dialog#'+open_dialog).find('.cancel_btn:not([disabled])').trigger('click');
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (Interface.tab_bar.new_tab.visible) {
|
|
|
|
Interface.tab_bar.new_tab.close()
|
|
|
|
|
|
|
|
} else if (open_menu) {
|
|
|
|
open_menu.hide()
|
|
|
|
|
|
|
|
} else if (Undo && Undo.index) {
|
|
|
|
Undo.undo()
|
|
|
|
|
|
|
|
} else if (!Blockbench.isMobile) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window.history.pushState({}, '');
|
|
|
|
})
|
|
|
|
|
2021-07-02 18:04:05 +08:00
|
|
|
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();
|
|
|
|
}
|
2020-09-27 23:18:15 +08:00
|
|
|
|
|
|
|
function loadInfoFromURL() {
|
2022-03-26 05:39:06 +08:00
|
|
|
if (Blockbench.queries.session) {
|
|
|
|
EditSession.token = Blockbench.queries.session;
|
2021-07-24 19:51:42 +08:00
|
|
|
BarItems.edit_session.click();
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
2021-07-07 03:34:46 +08:00
|
|
|
|
2022-03-26 05:39:06 +08:00
|
|
|
if (Blockbench.queries.m) {
|
|
|
|
$.getJSON(`https://blckbn.ch/api/models/${Blockbench.queries.m}`, (model) => {
|
2021-07-07 03:34:46 +08:00
|
|
|
Codecs.project.load(model, {path: ''});
|
2020-11-14 03:43:22 +08:00
|
|
|
})
|
2020-03-05 03:56:17 +08:00
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
2020-09-27 23:18:15 +08:00
|
|
|
|
2017-10-27 01:00:52 +08:00
|
|
|
//Misc
|
|
|
|
window.onbeforeunload = function() {
|
2021-09-16 06:49:57 +08:00
|
|
|
let unsaved_projects = ModelProject.all.find(project => !project.saved);
|
2021-09-15 23:50:46 +08:00
|
|
|
if (unsaved_projects) {
|
2019-07-18 00:02:07 +08:00
|
|
|
return 'Unsaved Changes';
|
2019-04-13 04:39:53 +08:00
|
|
|
} else {
|
2020-07-16 15:32:59 +08:00
|
|
|
Blockbench.dispatchEvent('before_closing')
|
2021-07-24 19:51:42 +08:00
|
|
|
if (Project.EditSession) Project.EditSession.quit()
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
}
|