<commit_before>// this file must be web-accessible.

console.log( "josiah_to_refworks_v2.js START" );


var bibnum = null;

$(document).ready(
  function() {
    get_bibnum();
  }
);

function get_bibnum() {
	/* Grabs and updates bib number if available; then triggers 'Add to RefWorks' button display.
	 * Called by document.ready()
	 */
	var target_element = document.getElementById( "recordnum" );
	console.log( "target_element, " + target_element );
	if ( target_element != null ) {
		var url = target_element.toString();
		var start_position = url.lastIndexOf( "b" );
		bibnum = url.substr( start_position, 8 );
	}
	console.log( "bibnum, " + bibnum );
	display_button()
}

function display_button() {
	console.log( "display_button() start" );
	console.log( "display_button() bibnum, " + bibnum );
	if ( bibnum == null ) {
		return
	}
	console.log( "display_button() not returning" );
	var newImg = new Image();
	newImg.src = '/screens/btn_refworks.gif';
	for (var m=0; m < document.images.length; m++) {

		if (	(document.images[m].src == "http://128.148.19.6/screens/blank.gif") ||
					(document.images[m].src == "http://carberry.brown.edu/screens/blank.gif") ||
					(document.images[m].src == "http://josiah.brown.edu/screens/blank.gif") ||
					(document.images[m].src == "https://128.148.19.6/screens/blank.gif") ||
					(document.images[m].src == "https://carberry.brown.edu/screens/blank.gif") ||
					(document.images[m].src == "https://josiah.brown.edu/screens/blank.gif") ||
					(document.images[m].src == "http://josiah.brown.edu:2082/screens/blank.gif")
					) {
						console.log( "display_button() condition is true" );
						document.images[m].src=newImg.src;
						document.images[m].alt="Add to RefWorks";
						}
	}
	console.log( "display_button() end" );
}


console.log( "josiah_to_refworks_v2.js END" );


// var bibno

// function open_refworks_win(url){
// 	url=url.replace('recordnum','recordnum='+bibno);
// 	new_refworks_win=window.open(url,"RefWorksMain",'toolbar=1,location=1,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=800,height=500');
// 	new_refworks_win.focus();
// 	}

// function get_recordnum() {
// 	var aTags = document.getElementsByTagName("a");
// 	var aTagsLen = aTags.length;
// 	for (var i=0; i < aTags.length; i++) {
// 		if (aTags[i].id == "recordnum") {
// 			bibno = aTags[i];
// 			bibno = bibno.toString();
// 			var start = bibno.lastIndexOf('b');
// 			bibno = bibno.substr(start,8);
// 			var newImg = new Image();
//   			newImg.src = '/screens/btn_refworks.gif';
// 			for (var m=0; m < document.images.length; m++) {
// 				if (
// 				    (document.images[m].src == "http://172.16.58.3/screens/blank.gif") ||
// 				    (document.images[m].src == "http://carberry.brown.edu/screens/blank.gif") ||
// 				    (document.images[m].src == "http://josiah.brown.edu/screens/blank.gif") ||
// 				    (document.images[m].src == "https://172.16.58.3/screens/blank.gif") ||
// 				    (document.images[m].src == "https://carberry.brown.edu/screens/blank.gif") ||
// 				    (document.images[m].src == "https://josiah.brown.edu/screens/blank.gif") ||
// 				    (document.images[m].src == "http://josiah.brown.edu:2082/screens/blank.gif")
// 				    ) {
// 					document.images[m].src=newImg.src;
// 					document.images[m].alt="Add to RefWorks";
// 				} // end if
// 			} // end for
// 		} // end if
// 	} // end for
// } // end function

// end javascript code
<commit_msg>finds and replaces stub image.<commit_after>// this file must be web-accessible.

console.log( "josiah_to_refworks_v2.js START" );


var bibnum = null;

$(document).ready(
  function() {
  	log_time();
    get_bibnum();
  }
);

function log_time() {
  /* Logs timestamp to console.
   * Called by document.ready()
   */
	now = new Date();
  now = now.getHours()+':'+now.getMinutes()+':'+now.getSeconds();
  console.log( "timestamp, " + now );
}

function get_bibnum() {
	/* Grabs and updates bib number if available; then triggers 'Add to RefWorks' button display.
	 * Called by document.ready()
	 */
	var target_element = document.getElementById( "recordnum" );
	console.log( "target_element, " + target_element );
	if ( target_element != null ) {
		var url = target_element.toString();
		var start_position = url.lastIndexOf( "b" );
		bibnum = url.substr( start_position, 8 );
	}
	console.log( "bibnum, " + bibnum );
	find_stub_image();
}

function find_stub_image() {
  /* Searches document's images to find the holder for the RefWorks image.
   * Called by get_bibnum() when josiah page contains a bibnum.
   */
	if ( bibnum == null ) { return };
	var images = document.images;
	for (var i=0; i < images.length; i++) {
		source_string = images[i].src;
		var find_position = source_string.search( "screens/blank.gif" );
		if ( find_position > 0 ) {
      console.log( "match at, " + images[i].src );
      add_refworks_image( images[i] )
		}
	}
}

function add_refworks_image( image ) {
  /* Replaces stub image with 'Add to Refworks' image-button.
   * Called by find_stub_image()
   */
  var new_image = new Image();
  new_image.src = "/screens/btn_refworks.gif";
  image.src=new_image.src;
  image.alt="Add to RefWorks";
  console.log( "image added" );
}


console.log( "josiah_to_refworks_v2.js END" );

{'fraction_non_alphanumeric': 0.18482601254991443, 'fraction_numerical': 0.01274006465107435, 'mean_word_length': 3.2973856209150325, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '4715153', 'n_tokens_mistral': 2123, 'n_tokens_neox': 1920, 'n_words': 356}