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();
|
|
|
|
window.open(event.target.href, '_blank');
|
2018-10-18 01:50:25 +08:00
|
|
|
});
|
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'
|
|
|
|
}
|
|
|
|
}
|
2021-02-21 23:46:06 +08:00
|
|
|
window.matchMedia('(display-mode: standalone)').addEventListener('change', (evt) => {
|
|
|
|
if (!Blockbench.isMobile) $('#web_download_button').toggle(!evt.matches);
|
|
|
|
});
|
2020-09-27 23:18:15 +08:00
|
|
|
|
|
|
|
function loadInfoFromURL() {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (location.hash.substr(1, 8) == 'session=') {
|
|
|
|
EditSession.dialog()
|
|
|
|
$('#edit_session_token').val(location.hash.substr(9))
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
2020-03-05 03:56:17 +08:00
|
|
|
if (location.hash.substr(1, 5) == 'load=') {
|
|
|
|
$.getJSON('https://blockbench.net/api/rawtext.php?url='+location.hash.substr(6), (model) => {
|
2021-05-08 17:43:40 +08:00
|
|
|
Codecs.project.load(model, {path: ''});
|
2020-03-05 03:56:17 +08:00
|
|
|
})
|
|
|
|
} else if (location.hash.substr(1, 5) == 'pbin=') {
|
|
|
|
$.getJSON('https://blockbench.net/api/rawtext.php?url='+'https://pastebin.com/raw/'+location.hash.substr(6), (model) => {
|
2021-05-08 17:43:40 +08:00
|
|
|
Codecs.project.load(model, {path: ''});
|
2020-03-05 03:56:17 +08:00
|
|
|
})
|
2020-11-14 03:43:22 +08:00
|
|
|
} else if (location.hash.substr(1, 2) == 'm=') {
|
|
|
|
$.getJSON(`https://blckbn.ch/api/models/${location.hash.substr(3)}`, (model) => {
|
|
|
|
if (showSaveDialog()) {
|
|
|
|
resetProject();
|
|
|
|
Codecs.project.load(model, {path: ''});
|
|
|
|
}
|
|
|
|
})
|
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-05-05 19:54:41 +08:00
|
|
|
if (Project.saved === false && elements.length > 0) {
|
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')
|
2019-04-13 04:39:53 +08:00
|
|
|
EditSession.quit()
|
2017-10-27 01:00:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
function showSaveDialog(close) {
|
2018-10-18 01:50:25 +08:00
|
|
|
var unsaved_textures = 0;
|
|
|
|
textures.forEach(function(t) {
|
|
|
|
if (!t.saved) {
|
|
|
|
unsaved_textures++;
|
|
|
|
}
|
|
|
|
})
|
2021-05-05 19:54:41 +08:00
|
|
|
if ((Project.saved === false && elements.length > 0) || unsaved_textures) {
|
2018-10-18 01:50:25 +08:00
|
|
|
|
|
|
|
var answer = confirm(tl('message.close_warning.web'))
|
2019-12-16 03:04:31 +08:00
|
|
|
return answer;
|
2018-10-18 01:50:25 +08:00
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
|
|
|
|
2020-10-11 22:54:52 +08:00
|
|
|
function setupMobilePanelSelector() {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (Blockbench.isMobile) {
|
2020-10-11 22:54:52 +08:00
|
|
|
Interface.PanelSelectorVue = new Vue({
|
|
|
|
el: '#panel_selector_bar',
|
|
|
|
data: {
|
|
|
|
all_panels: Interface.Panels,
|
|
|
|
selected: null,
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
panels() {
|
|
|
|
let arr = [];
|
|
|
|
arr.push({
|
|
|
|
icon: '3d_rotation',
|
|
|
|
name: tl('data.preview'),
|
|
|
|
id: 'preview'
|
|
|
|
})
|
|
|
|
for (var id in this.all_panels) {
|
|
|
|
let panel = this.all_panels[id];
|
|
|
|
if (Condition(panel.condition)) {
|
|
|
|
arr.push(panel)
|
|
|
|
}
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
2020-10-11 22:54:52 +08:00
|
|
|
return arr;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
select(panel) {
|
|
|
|
this.selected = panel && panel.id;
|
|
|
|
let overlay = $('#mobile_panel_overlay');
|
|
|
|
$('#left_bar').append(overlay.children());
|
|
|
|
if (panel instanceof Panel) {
|
|
|
|
overlay.append(panel.node);
|
|
|
|
overlay.show();
|
2020-10-26 22:27:07 +08:00
|
|
|
$(panel.node).show();
|
2020-12-30 23:37:16 +08:00
|
|
|
if (panel.onResize) panel.onResize();
|
2019-12-16 03:04:31 +08:00
|
|
|
} else {
|
2020-10-11 22:54:52 +08:00
|
|
|
overlay.hide();
|
2019-12-16 03:04:31 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-11 22:54:52 +08:00
|
|
|
})
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2020-10-11 22:54:52 +08:00
|
|
|
}
|