mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-06 08:20:04 +01:00
* Adds thumbnail to insert step view * removed redundant code * Resolved merge conflicts * Resolved merge conflicts * made changes in intermediateHtmlStepUi * Update intermediateHtmlStepUi.js
205 lines
5.7 KiB
JavaScript
205 lines
5.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) {
|
|
if (modulesInfo[m] && modulesInfo[m].name)
|
|
addStepSelect.append(
|
|
'<option value="' + m + '">' + modulesInfo[m].name + "</option>"
|
|
);
|
|
}
|
|
// Null option
|
|
addStepSelect.append('<option value="none" disabled selected>More modules...</option>');
|
|
}
|
|
refreshOptions();
|
|
|
|
$(window).on('scroll', scrollFunction);
|
|
|
|
function scrollFunction() {
|
|
var shouldDisplay = $('body').scrollTop() > 20 || $(':root').scrollTop() > 20;
|
|
|
|
$('#move-up').css({
|
|
display: shouldDisplay ? 'block' : 'none'
|
|
});
|
|
}
|
|
|
|
|
|
function topFunction() {
|
|
$('body').animate({scrollTop: 0});
|
|
$(':root').animate({scrollTop: 0});
|
|
}
|
|
|
|
$('#move-up').on("click",topFunction);
|
|
|
|
|
|
// UI for each step:
|
|
sequencer.setUI(DefaultHtmlStepUi(sequencer));
|
|
|
|
// UI for the overall demo:
|
|
var ui = DefaultHtmlSequencerUi(sequencer);
|
|
|
|
// find any `src` parameters in URL hash and attempt to source image from them and run the sequencer
|
|
if (getUrlHashParameter('src')) {
|
|
sequencer.loadImage(getUrlHashParameter('src'), ui.onLoad);
|
|
} else {
|
|
sequencer.loadImage("images/tulips.png", ui.onLoad);
|
|
}
|
|
|
|
var resetSequence = function(){
|
|
var r=confirm("Do you want to reset the sequence?");
|
|
if (r)
|
|
window.location = "/";
|
|
}
|
|
|
|
$("#addStep select").on("change", ui.selectNewStepUi);
|
|
$("#addStep #add-step-btn").on("click", ui.addStepUi);
|
|
$("#resetButton").on("click",resetSequence);
|
|
|
|
//Module button radio selection
|
|
$('.radio-group .radio').on("click", function() {
|
|
$(this).parent().find('.radio').removeClass('selected');
|
|
$(this).addClass('selected');
|
|
newStep = $(this).attr('data-value');
|
|
//$("#addStep option[value=" + newStep + "]").attr('selected', 'selected');
|
|
$("#addStep select").val(newStep);
|
|
ui.selectNewStepUi();
|
|
ui.addStepUi();
|
|
$(this).removeClass('selected');
|
|
});
|
|
|
|
$('#download-btn').click(function() {
|
|
$('.step-thumbnail:last()').trigger("click");
|
|
return false;
|
|
});
|
|
|
|
function displayMessageOnSaveSequence(){
|
|
$(".savesequencemsg").fadeIn();
|
|
setTimeout(function() {
|
|
$(".savesequencemsg").fadeOut();
|
|
}, 1000);
|
|
}
|
|
|
|
$('body').on('click', 'button.remove', ui.removeStepUi);
|
|
$('#save-seq').click(() => {
|
|
var result = window.prompt("Please give a name to your sequence... (Saved sequence will only be available in this browser).");
|
|
if(result){
|
|
result = result + " (local)";
|
|
sequencer.saveSequence(result, sequencer.toString());
|
|
sequencer.loadModules();
|
|
displayMessageOnSaveSequence();
|
|
refreshOptions();
|
|
}
|
|
});
|
|
|
|
var isWorkingOnGifGeneration = false;
|
|
|
|
$('.js-view-as-gif').on('click', function(event) {
|
|
// Prevent user from triggering generation multiple times
|
|
if (isWorkingOnGifGeneration) return;
|
|
|
|
isWorkingOnGifGeneration = true;
|
|
|
|
var button = event.target;
|
|
button.disabled = true;
|
|
|
|
|
|
try {
|
|
// Select all images from previous steps
|
|
var imgs = document.getElementsByClassName("step-thumbnail");
|
|
|
|
var imgSrcs = [];
|
|
|
|
for (var i = 0; i < imgs.length; i++) {
|
|
imgSrcs.push(imgs[i].src);
|
|
}
|
|
|
|
var options = {
|
|
'gifWidth': imgs[0].width,
|
|
'gifHeight': imgs[0].height,
|
|
'images': imgSrcs,
|
|
'frameDuration': 7,
|
|
}
|
|
|
|
gifshot.createGIF(options, function(obj) {
|
|
if (!obj.error) {
|
|
// Final gif encoded with base64 format
|
|
var image = obj.image;
|
|
var animatedImage = document.createElement('img');
|
|
|
|
animatedImage.id = "gif_element";
|
|
animatedImage.src = image;
|
|
|
|
|
|
var modal = $('#js-download-gif-modal');
|
|
|
|
$("#js-download-as-gif-button").one("click", function() {
|
|
// Trigger download
|
|
download(image, "index.gif", "image/gif");
|
|
|
|
// Close modal
|
|
modal.modal('hide');
|
|
})
|
|
|
|
var gifContainer = document.getElementById("js-download-modal-gif-container");
|
|
|
|
// Clear previous results
|
|
gifContainer.innerHTML = '';
|
|
|
|
// Insert image
|
|
gifContainer.appendChild(animatedImage);
|
|
|
|
|
|
// Open modal
|
|
modal.modal();
|
|
|
|
button.disabled = false;
|
|
isWorkingOnGifGeneration = false;
|
|
}
|
|
});
|
|
}
|
|
catch (e) {
|
|
console.error(e);
|
|
button.disabled = false;
|
|
isWorkingOnGifGeneration = false;
|
|
|
|
}
|
|
});
|
|
|
|
// image selection and drag/drop handling from examples/lib/imageSelection.js
|
|
sequencer.setInputStep({
|
|
dropZoneSelector: "#dropzone",
|
|
fileInputSelector: "#fileInput",
|
|
takePhotoSelector: "#take-photo",
|
|
onLoad: function onFileReaderLoad(progress) {
|
|
var reader = progress.target;
|
|
var step = sequencer.images.image1.steps[0];
|
|
var util=IntermediateHtmlStepUi(sequencer);
|
|
step.output.src = reader.result;
|
|
sequencer.run({ index: 0 });
|
|
step.options.step.imgElement.src = reader.result;
|
|
updatePreviews(reader.result,'addStep');
|
|
updatePreviews(sequencer.images.image1.steps[0].options.step.imgElement.src,'insertStep');
|
|
},
|
|
onTakePhoto: function (url) {
|
|
var step = sequencer.images.image1.steps[0];
|
|
step.output.src = url;
|
|
sequencer.run({ index: 0 });
|
|
step.options.step.imgElement.src = url;
|
|
}
|
|
});
|
|
|
|
setupCache();
|
|
|
|
if (getUrlHashParameter('src')) {
|
|
updatePreviews(getUrlHashParameter('src'),'addStep');
|
|
} else {
|
|
updatePreviews("images/tulips.png",'addStep');
|
|
}
|
|
}; |