mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-15 04:40:02 +01:00
* Add manifest.json * cache static assets for offline use * update cache * add meta theme-color and change static files to be cache * cache the files on network request * caching on first run Signed-off-by: tech4GT <varun.gupta1798@gmail.com> * add a button to clear cache * add styling to clear cache link
91 lines
2.7 KiB
JavaScript
91 lines
2.7 KiB
JavaScript
window.onload = function() {
|
|
sequencer = ImageSequencer();
|
|
|
|
function refreshOptions() {
|
|
// Load information of all modules (Name, Inputs, Outputs)
|
|
var modulesInfo = sequencer.modulesInfo();
|
|
|
|
var addStepSelect = $("#addStep select");
|
|
addStepSelect.html("");
|
|
|
|
// Add modules to the addStep dropdown
|
|
for (var m in modulesInfo) {
|
|
addStepSelect.append(
|
|
'<option value="' + m + '">' + modulesInfo[m].name + "</option>"
|
|
);
|
|
}
|
|
}
|
|
refreshOptions();
|
|
|
|
// UI for each step:
|
|
sequencer.setUI(DefaultHtmlStepUi(sequencer));
|
|
|
|
// UI for the overall demo:
|
|
var ui = DefaultHtmlSequencerUi(sequencer);
|
|
|
|
sequencer.loadImage("images/tulips.png", ui.onLoad);
|
|
|
|
$("#addStep select").on("change", ui.selectNewStepUi);
|
|
$("#addStep #add-step-btn").on("click", ui.addStepUi);
|
|
$('#addStep #download-btn').click(function() {
|
|
$('img:last()').trigger("click");
|
|
|
|
return false;
|
|
});
|
|
$('body').on('click', 'button.remove', ui.removeStepUi);
|
|
$('#save-seq').click(() => {
|
|
sequencer.saveSequence(window.prompt("Please give a name to your sequence..."), sequencer.toString());
|
|
sequencer.loadModules();
|
|
refreshOptions();
|
|
});
|
|
|
|
// image selection and drag/drop handling from examples/lib/imageSelection.js
|
|
sequencer.setInputStep({
|
|
dropZoneSelector: "#dropzone",
|
|
fileInputSelector: "#fileInput",
|
|
onLoad: function onFileReaderLoad(progress) {
|
|
var reader = progress.target;
|
|
var step = sequencer.images.image1.steps[0];
|
|
step.output.src = reader.result;
|
|
sequencer.run({ index: 0 });
|
|
step.options.step.imgElement.src = reader.result;
|
|
}
|
|
});
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
navigator.serviceWorker.register('sw.js', { scope: '/examples/' })
|
|
.then(function(registration) {
|
|
const installingWorker = registration.installing;
|
|
installingWorker.onstatechange = () => {
|
|
console.log(installingWorker)
|
|
if (installingWorker.state === 'installed') {
|
|
location.reload();
|
|
}
|
|
}
|
|
console.log('Registration successful, scope is:', registration.scope);
|
|
})
|
|
.catch(function(error) {
|
|
console.log('Service worker registration failed, error:', error);
|
|
});
|
|
}
|
|
|
|
if ('serviceWorker' in navigator) {
|
|
caches.keys().then(function(cacheNames) {
|
|
cacheNames.forEach(function(cacheName) {
|
|
$("#clear-cache").append(" " + cacheName);
|
|
});
|
|
});
|
|
}
|
|
|
|
$("#clear-cache").click(function() {
|
|
if ('serviceWorker' in navigator) {
|
|
caches.keys().then(function(cacheNames) {
|
|
cacheNames.forEach(function(cacheName) {
|
|
caches.delete(cacheName);
|
|
});
|
|
});
|
|
}
|
|
location.reload();
|
|
});
|
|
};
|