Fixes for jQuery/ServiceWorker switch, jQuery mode, and workaround for javascript/css content in ServiceWorker mode

This commit is contained in:
mossroy 2016-01-07 16:39:28 +01:00
parent a4feca9930
commit 369f8a9b0f
2 changed files with 149 additions and 125 deletions

View File

@ -113,7 +113,19 @@ function(util, utf8) {
else if (regexpCSS.test(titleName)) {
contentType = 'image/css';
}
reject("temporarily refuse javascript and css dependencies");
var responseInit = {
status: 200,
statusText: 'OK',
headers: {
'Content-Type': contentType
}
};
var httpResponse = new Response(';', responseInit);
// TODO : temporary before the backend actually sends a proper content
resolve(httpResponse);
return;
}
// Let's instanciate a new messageChannel, to allow app.s to give us the content

View File

@ -363,7 +363,8 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
console.log("init message sent to ServiceWorker");
}
}
$('input:radio[name=contentInjectionMode]').filter('[value="' + value + '"]').attr('checked', true);
$('input:radio[name=contentInjectionMode]').prop('checked', false);
$('input:radio[name=contentInjectionMode]').filter('[value="' + value + '"]').prop('checked', true);
contentInjectionMode = value;
// Save the value in a cookie, so that to be able to keep it after a reload/restart
cookies.setItem('lastContentInjectionMode', value, Infinity);
@ -388,6 +389,9 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
if (lastContentInjectionMode) {
setContentInjectionMode(lastContentInjectionMode);
}
else {
setContentInjectionMode('jquery');
}
var serviceWorkerRegistration = null;
@ -790,10 +794,10 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
$('#titleListHeaderMessage').empty();
$('#suggestEnlargeMaxDistance').hide();
$('#suggestReduceMaxDistance').hide();
$("#prefix").val("");
findTitleFromTitleIdAndLaunchArticleRead(titleId);
var title = selectedArchive.parseTitleId(titleId);
pushBrowserHistoryState(title.name());
$("#prefix").val("");
return false;
}
@ -897,17 +901,22 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
// Scroll the iframe to its top
$("#articleContent").contents().scrollTop(0);
// Display the article inside the web page.
var ifrm = document.getElementById('articleContent');
ifrm = (ifrm.contentWindow) ? ifrm.contentWindow : (ifrm.contentDocument.document) ? ifrm.contentDocument.document : ifrm.contentDocument;
ifrm.document.open();
ifrm.document.write(htmlArticle);
ifrm.document.close();
//$(document.getElementById('#articleContent').contentWindow.document).load(function () {
$('iframe#articleContent').load(function() {
// Apply Mediawiki CSS only when it's an Evopedia archive
if (selectedArchive.needsWikimediaCSS() === true) {
$('#articleContent').contents().find('head').empty();
var currentHref = $(location).attr('href');
var currentPath = regexpPath.exec(currentHref)[1];
$('#articleContent').contents().find('head').append("<link rel='stylesheet' type='text/css' href='" + currentPath + "css/mediawiki-main.css' id='mediawiki-stylesheet' />");
}
// Display the article inside the web page.
$('#articleContent').contents().find('body').html(htmlArticle);
// If the ServiceWorker is not useable, we need to fallback to parse the DOM
// to inject math images, and replace some links with javascript calls
if (contentInjectionMode === 'jquery') {
@ -969,7 +978,6 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
});
}
});
}
// Load images
$('#articleContent').contents().find('body').find('img').each(function() {
@ -1028,6 +1036,10 @@ define(['jquery', 'abstractBackend', 'util', 'cookies','geometry','osabstraction
});
}
});
}
});
}
/**