Merge pull request #2830 from jguille2/langLauncher

Fixing 'lang' flag and anchor launcher
pull/95/head
Jens Mönig 2021-06-09 12:28:48 +02:00 zatwierdzone przez GitHub
commit 8c5d981e2a
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
1 zmienionych plików z 43 dodań i 21 usunięć

Wyświetl plik

@ -364,9 +364,6 @@ IDE_Morph.prototype.openIn = function (world) {
if (dict.noExitWarning) {
window.onbeforeunload = nop;
}
if (dict.lang) {
myself.setLanguage(dict.lang, null, true); // don't persist
}
// only force my world to get focus if I'm not in embed mode
// to prevent the iFrame from involuntarily scrolling into view
@ -460,26 +457,38 @@ IDE_Morph.prototype.openIn = function (world) {
}
);
}
} else if (location.hash.substr(0, 5) === '#run:') {
} else if (location.hash.substr(0, 5) === '#run:') {
dict = '';
hash = location.hash.substr(5);
idx = hash.indexOf("&");
if (idx > 0) {
hash = hash.slice(0, idx);
}
//decoding if hash is an encoded URI
if (hash.charAt(0) === '%'
|| hash.search(/\%(?:[0-9a-f]{2})/i) > -1) {
hash = decodeURIComponent(hash);
}
if (hash.substr(0, 8) === '<project>') {
this.rawOpenProjectString(hash);
applyFlags(myself.cloud.parseDict(location.hash.substr(5)));
idx = hash.indexOf("&");
// supporting three URL cases
// xml project
if (hash.substr(0, 8) === '<project') {
this.rawOpenProjectString(hash.slice(0,hash.indexOf('</project>') + 10));
applyFlags(myself.cloud.parseDict(hash.substr(hash.indexOf('</project>') + 10)));
// no project, only flags
} else if (idx == 0){
applyFlags(myself.cloud.parseDict(hash));
// xml file path
// three path types allowed: absolute (http...) , relative to site ("/path") or relative to folder ("path")
} else {
this.shield = new Morph();
this.shield.alpha = 0;
this.shield.setExtent(this.parent.extent());
this.parent.add(this.shield);
this.showMessage('Fetching project...');
if (idx > 0) {
dict = myself.cloud.parseDict(hash.substr(idx));
hash = hash.slice(0,idx);
}
this.getURL(
hash,
projectData => {
@ -501,11 +510,7 @@ IDE_Morph.prototype.openIn = function (world) {
this.shield = null;
msg.destroy();
// this.toggleAppMode(true);
applyFlags(
this.cloud.parseDict(
location.hash.substr(5)
)
);
applyFlags(dict);
}
]);
}
@ -606,16 +611,33 @@ IDE_Morph.prototype.openIn = function (world) {
this.cloudError()
);
} else if (location.hash.substr(0, 6) === '#lang:') {
urlLanguage = location.hash.substr(6);
this.setLanguage(urlLanguage, null, true); // don't persist
this.loadNewProject = true;
dict = myself.cloud.parseDict(location.hash.substr(6));
applyFlags(dict);
} else if (location.hash.substr(0, 7) === '#signup') {
this.createCloudAccount();
}
this.loadNewProject = false;
}
if (this.userLanguage) {
function launcherLangSetting() {
var langSetting = null;
if (location.hash.substr(0, 6) === '#lang:') {
if (location.hash.charAt(8) === '_') {
langSetting = location.hash.slice(6,11);
} else {
langSetting = location.hash.slice(6,8);
}
}
// lang-flag wins lang-anchor setting
langSetting = myself.cloud.parseDict(location.hash).lang || langSetting;
return langSetting;
}
if (launcherLangSetting()) {
// launch with this non-persisten lang setting
this.loadNewProject = true;
this.setLanguage(launcherLangSetting(), interpretUrlAnchors, true);
} else if (this.userLanguage) {
this.loadNewProject = true;
this.setLanguage(this.userLanguage, interpretUrlAnchors);
} else {