Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <h1 class="h5 mb-3">Flmngr: manage image gallery</h1>

<div id="btn" class="btn btn-primary" style="opacity:0.2;cursor:default">Manage gallery...</div>
<div id="loading" style="font-size:12px">Loading file manager...</div>
<p class="hint"><b>Hint</b>: after you selected gallery images,<br/> you can re-manage the existing gallery.</p>

<h2 class="h5 mt-5">Image gallery</h2>

<p id="hint" style="display:none" class="hint"><b>Hint</b>: the previews are clickable.</p>

<div id="images">
  <p>0 images selected</p>
</div>

              
            
!

CSS

              
                body {
  padding: 20px;
  background-color: #F4F4F4;
}

#images {
  
  .image {
    border: 1px solid #DDD;
    box-shadow: 5px 5px 0 0 #DDD;
    background-color: white;
    padding: 10px;
    display: inline-flex;
    flex-direction: column;
    margin: 0 25px 25px 0;
    
    img {
      max-height: 250px;
      cursor: pointer;
      border: 2px solid #007FFF;

      &:hover {
        border-color: orange;
      }
    }
    
    p {
      margin: 5px 0 0 0;
      font-size: 14px;
      color: #444;
    }
  }
  
}

.lum-img {
  cursor: zoom-out;
  max-width: 100vw !important;
  max-height: 100vh !important;
}

.lum-lightbox {
  z-index: 1000;
  cursor: zoom-out;
}

.lum-lightbox-inner img {
  margin: 0 auto;
}

.lum-lightbox-image-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
}

.lum-close-button {
  cursor: pointer;
}

.lum-lightbox-image-wrapper {
    background: rgba(0, 0, 0, 0.7);
}

.hint {
  color: #007FFF; 
  font-size:14px; 
  margin-top: 10px; 
  line-height: 16px;
}
              
            
!

JS

              
                // In real app replace with:
// import Flmngr from "flmngr";
import Flmngr from "https://cdn.skypack.dev/flmngr";

// This demo uses a script for animating showing full-screen image when user clicks on a preview (a-la LightBox)
import {LuminousGallery} from "https://cdn.skypack.dev/luminous-lightbox@2.4.0";

Flmngr.load({
  apiKey: "FLMNFLMN",
  urlFileManager: 'https://fm.flmngr.com/fileManager',
  urlFiles: 'https://fm.flmngr.com/files',
  imageFormats: [
     {
        id: "preview",
        title: "Preview",
        suffix: "-preview",
        maxWidth: 250,
        maxHeight: 250
     }
  ]
}, {
  onFlmngrLoaded: () => {
    attachOnClickListenerToButton();
  }
});

function selectFiles() {
  
  // Collect URLs of images of existing gallery set
  let elsExistingImages = document.querySelectorAll(".image > img");
  let urls = [];
  for (let i=0; i<elsExistingImages.length; i++)
    urls.push(elsExistingImages.item(i).src);

  Flmngr.open({
    list: urls,
    isMultiple: true,
    acceptExtensions: ["png", "jpeg", "jpg", "webp", "gif"],
    createImageFormats: ["preview"],
    onFinish: (files) => {
      showSelectedImages(files);
    }
  });
}

function showSelectedImages(files) {
  let elImages = document.getElementById("images");
  elImages.innerHTML = "";
  
  let elP =  document.createElement("p");
  elP.textContent = files.length + " images selected";
  elImages.appendChild(elP);
  
  for (let file of files) {
    
    let filePreview = file.formats.find(file => file.format === "preview");
    let urlPreview = Flmngr.getNoCacheUrl(filePreview.url);
    let urlOriginal = Flmngr.getNoCacheUrl(file.url)
    
    let el = document.createElement("div");
    el.className = "image";
    elImages.appendChild(el);   
    
    let elImg = document.createElement("img");
    elImg.src = urlPreview;
    elImg.alt = "Image selected in Flmngr";
    elImg.setAttribute("data-src-original", urlOriginal);
    el.appendChild(elImg);
    
    let elP = document.createElement("p");
    elP.textContent = file.url;
    el.appendChild(elP);
    
  }        
  
  attachLightBoxToGallery();
}

function attachLightBoxToGallery() {

  let elsPreviews = document.querySelectorAll(".image > img");
  
  document.getElementById("hint").style.display = elsPreviews.length > 0 ? "block" : "none";

  elsPreviews.forEach(el => {
    if (!el.hasAttribute("data-src-original"))
      el.setAttribute("data-src-original", el.getAttribute("src"));
  });

  new LuminousGallery(
    elsPreviews,
    {
      "arrowNavigation": true
    },
    {
      "showCloseButton": true,
      "sourceAttribute": "data-src-original",
    }
  );
}

function attachOnClickListenerToButton() {
  let elBtn = document.getElementById("btn");
  
  // Style button as ready to be pressed
  elBtn.style.opacity = 1;
  elBtn.style.cursor = "pointer";
  let elLoading = document.getElementById("loading");
  elLoading.parentElement.removeChild(elLoading);
  
  // Add a listener for selecting files
  elBtn.addEventListener("click", () => {
    selectFiles();
  });
}
              
            
!
999px

Console