<commit_before>// override default bookmark sharing link behavior and instead open modal with copyable link text

$(document).on('click', '#share_bookmarksLink', function( e ){
  
  e.preventDefault();
  
  var bookmarkShareText= $('#share_bookmarksLink').text(); //Share
  var bookmarkNameText= $('#content h2.page-heading').text(); //Bookmarks
  var shareBookmarksText = bookmarkShareText + " " + bookmarkNameText;
  var shareBookmarksHelperText = "Use this link to " + bookmarkShareText.toLowerCase() + " your " + bookmarkNameText.toLowerCase();
  var bookmarkShareURL = window.location.origin + $('#share_bookmarksLink').attr('href');


  // create modal
  $('#content').append('<div class="modal fade" id="bookmark-modal" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title">' + shareBookmarksText + '</h4></div><div class="modal-body"><p class="help-block">' + shareBookmarksHelperText + '</p><div class="input-group"><input id="sharing-url-holder" type="text" class="form-control" data-autoselect="" value="' + bookmarkShareURL + '" aria-label="' + shareBookmarksText + '" readonly=""><span class="input-group-btn"><button id="copy-to-clipboard" class="btn btn-default" type="button" data-toggle="tooltip" data-placement="bottom" title="Copy to clipboard"><i class="fa fa-clipboard" aria-hidden="true"></i></button></span></div></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div></div></div>'); 

  // open modal
  $('#bookmark-modal').modal('show');

  // initiate tooltip
  $('#copy-to-clipboard').tooltip();

  // copy URL
  $('#copy-to-clipboard').click(function() {

    $('#sharing-url-holder').focus();
    $('#sharing-url-holder').select();

    try {
      var successful = document.execCommand('copy');
      var msg = successful ? 'successful' : 'unsuccessful';
      $('#copy-to-clipboard').attr('title', 'Copied!').tooltip('fixTitle').tooltip('show');
      $('#bookmark-modal .tooltip').delay( 1000 ).fadeOut();
      $('#copy-to-clipboard').attr('title', 'Copy to clipboard').tooltip('fixTitle');
    } catch (err) {
      console.log('Oops, unable to copy');
    }

  });

});<commit_msg>fixes bookmark share URL copying for iOS; - note that it's not possible to programatically copy the text for iOS versions older than 10 - for those cases the URL only gets highlighted and relies on the user to copy manually.<commit_after>// override default bookmark sharing link behavior and instead open modal with copyable link text

$(document).on('click', '#share_bookmarksLink', function( e ){
  
  e.preventDefault();
  
  var bookmarkShareText= $('#share_bookmarksLink').text(); //Share
  var bookmarkNameText= $('#content h2.page-heading').text(); //Bookmarks
  var shareBookmarksText = bookmarkShareText + " " + bookmarkNameText;
  var shareBookmarksHelperText = "Use this link to " + bookmarkShareText.toLowerCase() + " your " + bookmarkNameText.toLowerCase();
  var bookmarkShareURL = window.location.origin + $('#share_bookmarksLink').attr('href');


  // create modal
  $('#content').append('<div class="modal fade" id="bookmark-modal" tabindex="-1" role="dialog"><div class="modal-dialog" role="document"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button><h4 class="modal-title">' + shareBookmarksText + '</h4></div><div class="modal-body"><p class="help-block">' + shareBookmarksHelperText + '</p><div class="input-group"><input id="sharing-url-holder" type="text" class="form-control" data-autoselect="" value="' + bookmarkShareURL + '" aria-label="' + shareBookmarksText + '" readonly=""><span class="input-group-btn"><button id="copy-to-clipboard" class="btn btn-default" type="button" data-toggle="tooltip" data-placement="bottom" title="Copy to clipboard"><i class="fa fa-clipboard" aria-hidden="true"></i></button></span></div></div><div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">Close</button></div></div></div></div>'); 

  // open modal
  $('#bookmark-modal').modal('show');

  // don't use toopltip for iOS
  if (!navigator.userAgent.match(/ipad|ipod|iphone/i)) {
    $('#copy-to-clipboard').tooltip();
  }

  // copy URL
  $('#copy-to-clipboard').click(function() {

    // separate approach for iOS
    if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
      $('#sharing-url-holder').attr('readonly', false);
      $('#sharing-url-holder').attr('contenteditable', true);
      range = document.createRange();
      range.selectNodeContents($('#sharing-url-holder')[0]);
      var s = window.getSelection();
      s.removeAllRanges();
      s.addRange(range);
      $('#sharing-url-holder')[0].setSelectionRange(0, $('#sharing-url-holder').val().length);
      document.execCommand('copy'); // only works with iOS 10+
      $('#sharing-url-holder').attr('readonly', true);
      $('#sharing-url-holder').attr('contenteditable', false);

    } else {

      $('#sharing-url-holder').focus();
      $('#sharing-url-holder').select();
      
      try {
        var successful = document.execCommand('copy');
        var msg = successful ? 'successful' : 'unsuccessful';
        $('#copy-to-clipboard').attr('title', 'Copied!').tooltip('fixTitle').tooltip('show');
        $('#bookmark-modal .tooltip').delay( 1000 ).fadeOut();
        $('#copy-to-clipboard').attr('title', 'Copy to clipboard').tooltip('fixTitle');
      } catch (err) {
        console.log('Oops, unable to copy');
      }

    }

  });

});
{'fraction_non_alphanumeric': 0.20178909341131945, 'fraction_numerical': 0.0039566488904180285, 'mean_word_length': 4.825651302605211, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '7243710', 'n_tokens_mistral': 1728, 'n_tokens_neox': 1701, 'n_words': 342}