nicolas-t / Chocolat

Chocolat : the lightbox so cool horses use it :horse:
http://chocolat.insipi.de
GNU General Public License v3.0
1.69k stars 169 forks source link

calling chocolat from innerhtml #88

Closed jonnythesniper closed 6 years ago

jonnythesniper commented 6 years ago

hello fellows,

i have the problem that tags generated innerhtml do not open the lightbox.

how can i solve it?

this is my code

function putImages(){

    if (xmlhttp.readyState==4)
      {
          if(xmlhttp.responseText){
             var resp = xmlhttp.responseText.replace("\r\n", ""); 
             var files = resp.split(";");
              var j = 0;
              for(i=0; i<files.length; i++){
                  if(files[i] != ""){

                      var name = files[i];
                        var time_trim = name.split('screenshot_')[1];
                        var time = time_trim.replace(/\.[^/.]+$/, "");
                        var filename = name.split('_screenshot')[0];

                  document.getElementById("screenshotload").innerHTML += '<li id="" class="col-md-4 col-sm-6 wow fadeInDown screenshots"><div style="width:320px;height:220px;background:url(<?php echo  $_GET['id'] ?>/screenshots/'+files[i]+');"><a target="load2" data-confirm="do you want to delete the screenshot?" class="delshot" href="?load=delfile&path=<?php echo  $_GET['id'] ?>/screenshots/'+files[i]+'"></a><a class="chocolat-image" href="<?php echo  $_GET['id'] ?>/screenshots/'+files[i]+'"></a><a target="_blank" href="?load=player&id=<?php echo $_GET['id'] ?>/'+filename+'.mp4&title='+filename+'.mp4&backlink=<?php echo $_GET['id'] ?>&num=<?php echo  $_GET['num'] ?>&sc#'+time+'"></a></div></li>';

 j++;

                  }
              }
          }
      }
}
jonnythesniper commented 6 years ago

i solved my problem like this

$('body').on('click', '.chocolat-image', function(e) {
                e.preventDefault();
        $('.chocolat-parent').Chocolat();
});

and for the scroll function

            $('.chocolat-parent').removeData('chocolat').Chocolat({
            });