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-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'
|
|
|
|
}
|
|
|
|
}
|
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() {
|
2019-07-18 00:02:07 +08:00
|
|
|
if (location.hash.substr(1, 8) == 'session=') {
|
2021-07-24 19:51:42 +08:00
|
|
|
EditSession.token = location.hash.substr(9);
|
|
|
|
BarItems.edit_session.click();
|
2018-12-27 21:03:04 +08:00
|
|
|
}
|
2021-07-07 03:34:46 +08:00
|
|
|
|
2021-06-12 06:07:23 +08:00
|
|
|
if (location.hash.substr(1, 2) == 'm=') {
|
2020-11-14 03:43:22 +08:00
|
|
|
$.getJSON(`https://blckbn.ch/api/models/${location.hash.substr(3)}`, (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
|
|
|
}
|
|
|
|
}
|
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,
|
2021-05-29 05:42:35 +08:00
|
|
|
modifiers: Pressing.overrides
|
2020-10-11 22:54:52 +08:00
|
|
|
},
|
|
|
|
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();
|
2021-10-15 18:15:11 +08:00
|
|
|
panel.update();
|
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
|
|
|
}
|
2021-05-29 05:42:35 +08:00
|
|
|
},
|
|
|
|
openKeyboardMenu(event) {
|
|
|
|
let menu = new Menu([
|
|
|
|
{icon: Pressing.overrides.ctrl ? 'check_box' : 'check_box_outline_blank', name: 'keys.ctrl', click() {Pressing.overrides.ctrl = !Pressing.overrides.ctrl}},
|
|
|
|
{icon: Pressing.overrides.shift ? 'check_box' : 'check_box_outline_blank', name: 'keys.shift', click() {Pressing.overrides.shift = !Pressing.overrides.shift}},
|
|
|
|
{icon: Pressing.overrides.alt ? 'check_box' : 'check_box_outline_blank', name: 'keys.alt', click() {Pressing.overrides.alt = !Pressing.overrides.alt}},
|
|
|
|
'_',
|
|
|
|
{icon: 'clear_all', name: 'menu.mobile_keyboard.disable_all', condition: () => {
|
|
|
|
let {length} = [Pressing.overrides.ctrl, Pressing.overrides.shift, Pressing.overrides.alt].filter(key => key);
|
|
|
|
return length;
|
|
|
|
}, click() {
|
|
|
|
Pressing.overrides.ctrl = false; Pressing.overrides.shift = false; Pressing.overrides.alt = false;
|
|
|
|
}},
|
|
|
|
])
|
|
|
|
menu.open(this.$refs.mobile_keyboard_menu)
|
2021-10-03 01:51:12 +08:00
|
|
|
},
|
|
|
|
Condition,
|
|
|
|
getIconNode: Blockbench.getIconNode
|
2021-05-29 05:42:35 +08:00
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<div id="panel_selector_bar">
|
|
|
|
<div class="panel_selector" :class="{selected: selected == null}" @click="select(null)">
|
|
|
|
<div class="icon_wrapper"><i class="material-icons icon">3d_rotation</i></div>
|
|
|
|
</div>
|
|
|
|
<div class="panel_selector" :class="{selected: selected == panel.id}" v-for="panel in all_panels" v-if="Condition(panel.condition)" @click="select(panel)">
|
2021-09-21 17:20:10 +08:00
|
|
|
<div class="icon_wrapper" v-html="getIconNode(panel.icon).outerHTML"></div>
|
2021-05-29 05:42:35 +08:00
|
|
|
</div>
|
|
|
|
<div id="mobile_keyboard_menu" @click="openKeyboardMenu($event)" ref="mobile_keyboard_menu" :class="{enabled: modifiers.ctrl || modifiers.shift || modifiers.alt}">
|
|
|
|
<i class="material-icons">keyboard</i>
|
|
|
|
</div>
|
|
|
|
</div>`
|
2020-10-11 22:54:52 +08:00
|
|
|
})
|
2019-07-18 00:02:07 +08:00
|
|
|
}
|
2020-10-11 22:54:52 +08:00
|
|
|
}
|