<commit_before>/*!
 * jQuery Pongstagr.am Plugin 
 * Copyright (c) 2013 <NAME>
 * Version: 2.0.5
 * Code license under Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 * Requires: jQuery v1.9 and Bootstrap JS
 */

;(function ($, window, document, undefined){
  
  "use strict";
  
  function renderHTML( targetElement, request, pager ){
    var galleryList      = '<ul class="thumbnails"></ul>',
        galleryContainer = '<div class="row-fluid">' + galleryList + '</div>',
        paginateTarget   = $(targetElement).attr('id'),
        paginateBtn      = '<div class="row-fluid"><a href="javascript:void(0);" data-paginate="'+ paginateTarget +'" class="span4 offset4 btn btn-large btn-block btn-success">Load More</a></div>';

    $( targetElement ).append( galleryContainer ); 
    
    if ( pager === null || pager === true ){
      $( targetElement ).after( paginateBtn );
    }      
  }
  
  function renderModal( imageOwner, imageId, imageTitle, imageUrl, imgUser, comments ){

    var modal  = '<div id="' + imageId + '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">';
        modal += '<div class="modal-header">';
        modal += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
        modal += '<div class="row-fluid">';
        modal += '<div class="span1"><img src="' + imgUser + '" alt="" class="img-polaroid" style="width: 32px; height: 32px; margin-right: 10px; vertical-align: middle;" /></div>';
        modal += '<div class="span10"><strong><a href="http://www.instagram.com/' + imageOwner + '">' + imageOwner + '</a>&nbsp;' + imageTitle + '</strong></div>';
        modal += '</div><!-- end of .row-fluid -->';
        modal += '</div><!-- end of .modal-header -->';
        modal += '<div class="modal-body">';
        modal += '<div class="row-fluid">';
    
    if ( comments !== 0 ) {
        modal += '<div class="span7"><img src="' + imageUrl +'" alt="' + imageTitle + '" class="img-polaroid" /><br /></div>';
        modal += '<div class="modal-comments span5"></div>';
      } else {
        modal += '<img src="' + imageUrl +'" alt="' + imageTitle + '" class="img-polaroid" />';
    }
        modal += '</div><!-- end of .modal-fluid -->';
        modal += '</div><!-- end of .modal-body -->';
        modal += '<div class="modal-footer">';
        modal += '<button class="btn btn-inverse btn-mini" data-dismiss="modal" aria-hidden="true">Close</button>';
        modal += '</div><!-- end of .modal-footer -->';
        modal += '</div><!-- end of .modal -->';
                
    $('body').append( modal ); //*! Append modal window to body 
    
    $('#' + imageId ).on('hidden', function(){
      $(this).remove();
      $('body').removeAttr('style');
    });
  }

  function ajaxRequest( endpoint, targetElement ){
    $.ajax({
      method   : "GET"    ,
      url      : endpoint ,
      cache    : true     ,
      dataType : "jsonp"  ,
      success  : function(data){

      var injectTo = '#' + $(targetElement).attr('id');    
                
        $.each( data.data, function( key, value ){

          var thumbnail  = value.images.low_resolution.url, 
              imgCaption = ( value.caption !== null ) ? ( value.caption.text !== null ) ? value.caption.text : '' : value.user.username,
              comments   = ( value.comments.count !== null ) ? value.comments.count : '0',
              likes      = ( value.likes.count !== null ) ? value.comments.count : '0',
              imageUrl   = value.images.standard_resolution.url,
              imageId    = value.id,
              imgUser    = value.user.profile_picture,
              imageOwner = value.user.username;
                            
          var thumbBlock  = '<li class="span3">';
              thumbBlock += '<div class="thumbnail">';
              thumbBlock += '<a href="#" class="btn btn-mini btn-info btn-likes"><i class="icon-heart icon-white"></i> &nbsp;' + likes + '</a>';
              thumbBlock += '<a href="#" class="btn btn-mini btn-info btn-comments"><i class="icon-comment icon-white"></i> &nbsp;' + comments + '</a>';
              thumbBlock += '<a href="#" role="button" data-toggle="modal" data-reveal-id="' + imageId + '"><img src="' + thumbnail + '" alt="' + imgCaption + '" /></a>';
              thumbBlock += '</div>';
              thumbBlock += '</li>';
                        
          $( injectTo + ' .thumbnails' ).append( thumbBlock );
          
          $('[data-reveal-id="' + imageId + '"]').click(function(){
            
            // add padding to body to be able to scroll
            var modalHeight = $('body').height(); 
            
                $('.modal').attr('id', imageId );
                $('body').css({ 'padding-bottom' : modalHeight * 1.5 });
            
            renderModal( imageOwner, imageId, imgCaption, imageUrl, imgUser, comments );
            
            $.each( value.comments.data, function( group, key ){
              
              var commentBlock  = '<div class="row-fluid">';
                  commentBlock += '<div class="span2"><img src="' + key.from.profile_picture + '" style="width: 36px; height: 36px; margin-right: 10px; vertical-align: middle;" class="img-polaroid" /></div>';
                  commentBlock += '<div class="span9 offset1">';
                  commentBlock += '<a href="http://www.instagram.com/' + key.from.username + '"><strong>' + key.from.username + '</strong></a><br />';
                  commentBlock += key.text;
                  commentBlock += '</div>';
                  commentBlock += '</div><!-- end of .row-fluid -->';
              
              $('.modal-comments').append(commentBlock);
            });            

            $('#' + imageId ).modal(); //*! fire modal window
            
          });
        });

        paginate( data.pagination.next_url, injectTo ); //*! paginate through images
      }
    });
  }

  function paginate( nextUrl, targetElement ){
    
    var pagBtn = $(targetElement).attr('id');
    
    if ( nextUrl === undefined || nextUrl === null ) {
      $('[data-paginate="' + pagBtn + '"]').click(function(event){<commit_msg>Fix for same image id but different parent div.<commit_after>/*!
 * jQuery Pongstagr.am Plugin 
 * Copyright (c) 2013 <NAME>
 * Version: 2.0.5
 * Code license under Apache License v2.0
 * http://www.apache.org/licenses/LICENSE-2.0
 * Requires: jQuery v1.9 and Bootstrap JS
 */

;(function ($, window, document, undefined){
  
  "use strict";
  
  function renderHTML( targetElement, request, pager ){
    var galleryList      = '<ul class="thumbnails"></ul>',
        galleryContainer = '<div class="row-fluid">' + galleryList + '</div>',
        paginateTarget   = $(targetElement).attr('id'),
        paginateBtn      = '<div class="row-fluid"><a href="javascript:void(0);" data-paginate="'+ paginateTarget +'" class="span4 offset4 btn btn-large btn-block btn-success">Load More</a></div>';

    $( targetElement ).append( galleryContainer ); 
    
    if ( pager === null || pager === true ){
      $( targetElement ).after( paginateBtn );
    }      
  }
  
  function renderModal( imageOwner, imageId, imageTitle, imageUrl, imgUser, comments, targetElement ){

    var modal  = '<div id="' + imageId + '-' + targetElement + '" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="' + imageId + '_label" aria-hidden="true">';
        modal += '<div class="modal-header">';
        modal += '<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
        modal += '<div class="row-fluid">';
        modal += '<div class="span1"><img src="' + imgUser + '" alt="" class="img-polaroid" style="width: 32px; height: 32px; margin-right: 10px; vertical-align: middle;" /></div>';
        modal += '<div class="span10"><strong><a href="http://www.instagram.com/' + imageOwner + '">' + imageOwner + '</a>&nbsp;' + imageTitle + '</strong></div>';
        modal += '</div><!-- end of .row-fluid -->';
        modal += '</div><!-- end of .modal-header -->';
        modal += '<div class="modal-body">';
        modal += '<div class="row-fluid">';
    
    if ( comments !== 0 ) {
        modal += '<div class="span7"><img src="' + imageUrl +'" alt="' + imageTitle + '" class="img-polaroid" /><br /></div>';
        modal += '<div class="modal-comments span5"></div>';
      } else {
        modal += '<img src="' + imageUrl +'" alt="' + imageTitle + '" class="img-polaroid" />';
    }
        modal += '</div><!-- end of .modal-fluid -->';
        modal += '</div><!-- end of .modal-body -->';
        modal += '<div class="modal-footer">';
        modal += '<button class="btn btn-inverse btn-mini" data-dismiss="modal" aria-hidden="true">Close</button>';
        modal += '</div><!-- end of .modal-footer -->';
        modal += '</div><!-- end of .modal -->';
                
    $('body').append( modal ); //*! Append modal window to body 
    $('#' + imageId + '-' + targetElement).on('hidden', function(){
      $(this).remove();
      $('body').removeAttr('style');
    });
  }

  function ajaxRequest( endpoint, targetElement ){
    $.ajax({
      method   : "GET"    ,
      url      : endpoint ,
      cache    : true     ,
      dataType : "jsonp"  ,
      success  : function(data){

      var injectTo = $(targetElement).attr('id');    
                
        $.each( data.data, function( key, value ){

          var thumbnail  = value.images.low_resolution.url, 
              imgCaption = ( value.caption !== null ) ? ( value.caption.text !== null ) ? value.caption.text : '' : value.user.username,
              comments   = ( value.comments.count !== null ) ? value.comments.count : '0',
              likes      = ( value.likes.count !== null ) ? value.comments.count : '0',
              imageUrl   = value.images.standard_resolution.url,
              imageId    = value.id,
              imgUser    = value.user.profile_picture,
              imageOwner = value.user.username;
                            
          var thumbBlock  = '<li class="span3">';
              thumbBlock += '<div class="thumbnail">';
              thumbBlock += '<a href="#" class="btn btn-mini btn-info btn-likes"><i class="icon-heart icon-white"></i> &nbsp;' + likes + '</a>';
              thumbBlock += '<a href="#" class="btn btn-mini btn-info btn-comments"><i class="icon-comment icon-white"></i> &nbsp;' + comments + '</a>';
              thumbBlock += '<a href="#" role="button" data-toggle="modal" data-modal-trigger="' + imageId + '-' + injectTo + '"><img src="' + thumbnail + '" alt="' + imgCaption + '" /></a>';
              thumbBlock += '</div>';
              thumbBlock += '</li>';
                        
          $( '#' + injectTo + ' .thumbnails' ).append( thumbBlock );
          
          $('[data-modal-trigger="' + imageId + '-' + injectTo + '"]').click(function(){
            
            // add padding to body to be able to scroll
            var modalHeight = $('body').height(); 
            
                $('.modal').attr('id', imageId );
                $('body').css({ 'padding-bottom' : modalHeight * 1.5 });
            
            renderModal( imageOwner, imageId, imgCaption, imageUrl, imgUser, comments, injectTo );
            console.log( injectTo );
            $.each( value.comments.data, function( group, key ){
              
              var commentBlock  = '<div class="row-fluid">';
                  commentBlock += '<div class="span2"><img src="' + key.from.profile_picture + '" style="width: 36px; height: 36px; margin-right: 10px; vertical-align: middle;" class="img-polaroid" /></div>';
                  commentBlock += '<div class="span9 offset1">';
                  commentBlock += '<a href="http://www.instagram.com/' + key.from.username + '"><strong>' + key.from.username + '</strong></a><br />';
                  commentBlock += key.text;
                  commentBlock += '</div>';
                  commentBlock += '</div><!-- end of .row-fluid -->';
              
              $('.modal-comments').append(commentBlock);
            });            

            $('#' + imageId + '-' + injectTo ).modal(); //*! fire modal window
            
          });
        });

        paginate( data.pagination.next_url, injectTo ); //*! paginate through images
      }
    });
  }

  function paginate( nextUrl, targetElement ){
    
    var pagBtn = $(targetElement).attr('id');
    
    if ( nextUrl === undefined || nextUrl === null ) {
      $('[data-paginate="' + pagBtn + '"]').click(function(event){
{'fraction_non_alphanumeric': 0.1955850937574175, 'fraction_numerical': 0.006804335786059023, 'mean_word_length': 2.1886982845610494, 'pattern_counts': {'":': 0, '<': 153, '<?xml version=': 0, '>': 153, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '297734', 'n_tokens_mistral': 3710, 'n_tokens_neox': 3552, 'n_words': 839}