text
stringlengths
0
106k
.btn {
height: 3rem;
font-size: 1.2rem;
width: 100%;
}
function isMobile() {
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}
let textareas = document.querySelectorAll('textarea');
textareas.forEach(textarea => {
textarea.addEventListener('input', autoResize, false);
});
function autoResize() {
this.style.height = 'auto';
this.style.height = this.scrollHeight + 'px';
}
['Imagine', 'Replicate', 'Leonardo', 'PlaygroundAI'].forEach(provider => document.getElementById('provider').add(new Option(provider, provider)));
document.getElementById('provider').value = 'Leonardo';
['SDXL', 'Stable Diffusion 2.1', 'Stable Diffusion 1.5', 'Playground V1'].forEach(model => document.getElementById('model').add(new Option(model, model)));
document.getElementById('model').value = 'SDXL';
['Photoreal', 'Pixar 3D', 'Painting', 'None'].forEach(style => document.getElementById('style').add(new Option(style, style)));
document.getElementById('style').value = 'None';
['16:9', '9:16', '4:3', '3:4', "3:2","2:3","1:1"].forEach(ratio => document.getElementById('ratio').add(new Option(ratio, ratio)));
document.getElementById('ratio').value = '16:9';
document.querySelector('.btn').addEventListener('click', generateImages);
function generateImages() {
// Get the values from the form inputs
let provider = document.getElementById('provider').value;
let model = document.getElementById('model').value;
let style = document.getElementById('style').value;
let ratio = document.getElementById('ratio').value;
let numImages = document.getElementById('num-images').value;
// Generate the URLs
let urls = []; //
for (let i = 0; i < numImages; i++) {
urls.push('http://example.com/image' + i + '.jpg');
}
// Display the images
let imageContainer = document.createElement('div');
imageContainer.style.display = 'flex';
imageContainer.style.flexWrap = 'wrap';
imageContainer.style.justifyContent = 'space-around';
imageContainer.style.marginTop = '20px';
urls.forEach(url => {
let img = document.createElement('img');
img.src = url;
img.style.width = isMobile() ? 'calc(100% - 20px)' : 'calc(50% - 20px)';
img.style.height = 'auto';
img.style.margin = '10px';
img.style.borderRadius = '10px';
imageContainer.appendChild(img);
});
// Add the image container to the DOM, right after the Generate button
document.querySelector('.btn').after(imageContainer);
}
I want it so that when image is clicked on it opens in gallery view with thumbnail strip using fancybox https://fancyapps.com/fancybox/
[AI]: Sure! To open an image in a gallery view with thumbnail strip using Fancybox, you need to first include the Fancybox library in your HTML file. So, add these lines in the `<head>` tag to include the Fancybox CSS:
```html
<!-- Fancybox CSS -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.css" />
```
And this line before the closing `</body>` tag to include the Fancybox JS:
```html
<!-- Fancybox JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/fancybox/3.5.7/jquery.fancybox.min.js"></script>
```
Then, modify your `generateImages` JavaScript function to add the `data-fancybox` attribute to the image elements. The images also need to be wrapped in an `<a>` tag linking to the image source:
```javascript
function generateImages() {
// Get the values from the form inputs
let provider = document.getElementById('provider').value;
let model = document.getElementById('model').value;
let style = document.getElementById('style').value;
let ratio = document.getElementById('ratio').value;
let numImages = document.getElementById('num-images').value;
// Generate the URLs
let urls = []; //
for (let i = 0; i < numImages; i++) {
urls.push('http://example.com/image' + i + '.jpg');