css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <h3>
   <a href="https://nanogallery2.nanostudio.org/" target="_blank">nanogallery2</a>
   - dynamic gallery handling (API)
</h3>

<div id="my_nanogallery2" 
     data-nanogallery2='{ 
        "itemsBaseURL":           "https://nanogallery2.nanostudio.org/samples/",
        "thumbnailWidth":         "auto",
        "thumbnailSelectable":    true,
        "thumbnailHoverEffect2":  null
        }'
     > nanogallery2
  <a href="berlin1.jpg" data-ngthumb="berlin1t.jpg" data-ngdesc="">Berlin 1 - image</a>
  <a href="berlin2.jpg" data-ngthumb="berlin2t.jpg" data-ngdesc="">Berlin 2 - image</a>
  <a href="berlin3.jpg" data-ngthumb="berlin3t.jpg" data-ngdesc="">Berlin 3 - image</a>
  <a href="" data-ngkind="album" data-ngid="1000" data-ngthumb="berlin3t.jpg" data-ngdesc="">Berlin 3 - album</a>
</div>



<button type="button" id="btn_add">add 1 image to the gallery</button>
<button type="button" id="btn_add_album">add 2 images to the "Berlin 3" album</button>
<button type="button" id="btn_add_album2">create 1 album with 2 images</button>
<button type="button" id="btn_del">delete selection</button>
<button type="button" id="btn_select_mode">switch selection mode on/off</button>


            
          
!
            
              var baseURL = 'https://nanogallery2.nanostudio.org/samples/';

// add one image
jQuery('#btn_add').on('click', function() {
  var ngy2data = $("#my_nanogallery2").nanogallery2('data');
  var instance = $("#my_nanogallery2").nanogallery2('instance');
        
  // create the new item
  var ID = ngy2data.items.length + 1;
  var albumID = '0';
  var newItem = NGY2Item.New(instance, 'new berlin ' + ID, '', ID, albumID, 'image', '' );

  // define thumbnail -> image displayed in the gallery
  newItem.thumbSet( baseURL + 'berlin2t.jpg', 135, 204); // w,h

  // define URL of the media to display in lightbox
  newItem.setMediaURL( baseURL + 'berlin2.jpg', 'img');
  
  // currently displayed album
  if( ngy2data.items[ngy2data.gallery.albumIdx].GetID() == 0 ) {

    // add new item to current Gallery Object Model (GOM) 
    newItem.addToGOM();
  
    // refresh the display (-> only once if you add multiple items)
    $("#my_nanogallery2").nanogallery2('resize');
  }
});



// add 2 images to existing album
jQuery('#btn_add_album').on('click', function() {
  var ngy2data = $("#my_nanogallery2").nanogallery2('data');
  var instance = $("#my_nanogallery2").nanogallery2('instance');
        
  var ID = ngy2data.items.length + 1001;
  var albumID = '1000';   // ID of the album which will contain the 2 new images

  // ADD FIRST IMAGE
  var newItem1 = NGY2Item.New(instance, 'new image ' + ID, '', ID, albumID, 'image', '' );
  newItem1.thumbSet( baseURL + 'berlin1t.jpg', 320, 212); 
  newItem1.setMediaURL(  baseURL + 'berlin1.jpg', 'img');
  
  // ADD SECOND IMAGE
  ID = ngy2data.items.length + 1001;
  var newItem2 = NGY2Item.New(instance, 'new image ' + ID, '', ID, albumID, 'image', '' );
  newItem2.thumbSet( baseURL + 'berlin1t.jpg', 320, 212);
  newItem2.setMediaURL( baseURL + 'berlin1.jpg', 'img');
  
  // refresh the display if the album is displayed
  if( ngy2data.items[ngy2data.gallery.albumIdx].GetID() == albumID ) {
    newItem1.addToGOM();
    newItem2.addToGOM();
    $("#my_nanogallery2").nanogallery2('resize');
  }
  else {
    alert('images added');
  }
});


// Add 1 album with 2 images
jQuery('#btn_add_album2').on('click', function() {
  var ngy2data = $("#my_nanogallery2").nanogallery2('data');
  var instance = $("#my_nanogallery2").nanogallery2('instance');

  // ADD NEW ALBUM
  var newAlbumID = ngy2data.items.length + 2001;
  var newAlbum = NGY2Item.New(instance, 'new album ' + newAlbumID, '', newAlbumID, '0', 'album', '' );
  newAlbum.thumbSet( baseURL + 'berlin1t.jpg', 320, 212); 
  newAlbum.contentIsLoaded = true;

  // ADD FIRST IMAGE
  var ID = ngy2data.items.length + 2001;
  var newItem1 = NGY2Item.New(instance, 'new image ' + ID, '', ID, newAlbumID, 'image', '' );
  newItem1.thumbSet( baseURL + 'berlin1t.jpg', 320, 212); 
  newItem1.setMediaURL(  baseURL + 'berlin1.jpg', 'img');

  // ADD SECOND IMAGE
  ID = ngy2data.items.length + 2001;
  var newItem2 = NGY2Item.New(instance, 'new image ' + ID, '', ID, newAlbumID, 'image', '' );
  newItem2.thumbSet( baseURL + 'berlin1t.jpg', 320, 212);
  newItem2.setMediaURL( baseURL + 'berlin1.jpg', 'img');
  
  if( ngy2data.items[ngy2data.gallery.albumIdx].GetID() == 0 ) {
    newAlbum.addToGOM();
    $("#my_nanogallery2").nanogallery2('resize');
  }
  
  // $("#my_nanogallery2").nanogallery2('refresh');
});


// delete selection
jQuery('#btn_del').on('click', function() {
  var ngy2data = $("#my_nanogallery2").nanogallery2('data');
  ngy2data.items.forEach( function(item) {
    if( item.selected ) {
      item.delete();
    }
  });
  $("#my_nanogallery2").nanogallery2('resize');
});

// switch selection mode on/off
jQuery('#btn_select_mode').on('click', function() {
  var b = !$('#my_nanogallery2').nanogallery2('option', 'thumbnailSelectable');
  $('#my_nanogallery2').nanogallery2('option', 'thumbnailSelectable', b);
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console