<commit_before>/**
 *
 * Tumblr Album Photoset Lightbox
 *
 * Inspired by: https://github.com/PixelUnion/Extended-Tumblr-Photoset
 */

var albumPhotoset = require('tumblrPhotoset.albumPhotoset');

albumPhotoset.registerEventHandler('row-ready', function (albumPhotosetInstance, row) {
	row = row[0];
	var baseImages = row.getElementsByTagName('IMG'),
		rolloverImages = [];

	console.log('baseImages:', baseImages);
	for (var imageCounter = 0; imageCounter < baseImages.length; imageCounter++ ) {
		var image = baseImages[imageCounter];
		console.log('image:', image, image.getAttribute('data-caption'));
		if (image.getAttribute('data-caption').match(/#rollover/)) {
			var baseImage = baseImages[imageCounter - 1],
				rolloverImageSrc = image.getAttribute('src'),
				baseImageSrc = image.getAttribute('src');
			console.log('rolloverSrc', rolloverImageSrc);
			console.log('baseSrc', baseImageSrc);

			baseImage.addEventListener('mouseover', function () { this.src = rolloverImageSrc; });
			baseImage.addEventListener('mouseout', function () { this.src = baseImageSrc; });

			baseImages.splice(imageCounter, 1);
			imageCounter--;
		}
	}
	console.log('rollovers:', rolloverImages); // TODO: mod even
	console.log('bases:', baseImages); // TODO: mod even
});
console.log('rollover registered');
<commit_msg>added support for caption and tag-based rollovers<commit_after>/**
 *
 * Tumblr Album Photoset Lightbox
 *
 * Inspired by: https://github.com/PixelUnion/Extended-Tumblr-Photoset
 */

var albumPhotoset = require('tumblrPhotoset.albumPhotoset');

albumPhotoset.registerEventHandler('pre-render', function (albumPhotosetInstance) {
	var images = albumPhotosetInstance.photosetImages.slice(),
		baseImages = Array.prototype.slice.call(images),
		captionFound = false;

	for (var imageCounter = 1; imageCounter < baseImages.length; imageCounter++ ) {
		var image = baseImages[imageCounter],
			caption = '';

		caption = image.getAttribute('data-caption');
		if (caption && caption.match(/#rollover/)) {
			albumPhotosetInstance.tagRollover = false;
			captionFound = true;

			var baseImage = baseImages[imageCounter - 1],
				rolloverImageSrc = image.getAttribute('src'),
				baseImageSrc = baseImage.getAttribute('src');

			baseImage.addEventListener('mouseover', function () { this.src = rolloverImageSrc; });
			baseImage.addEventListener('mouseout', function () { this.src = baseImageSrc; });

			baseImages.splice(imageCounter, 1);
			image.parentElement.removeChild(image);
			imageCounter--;
		}
	}

	if (captionFound) {
		albumPhotosetInstance.photosetImages = baseImages;
	}
});

albumPhotoset.registerEventHandler('row-ready', function (albumPhotosetInstance, row) {
	if (albumPhotosetInstance.tagRollover == false || albumPhotosetInstance.photosetTags.indexOf('#rollover') === -1) {
		albumPhotosetInstance.tagRollover == false
		return;
	}

	row = row[0];
	var baseImages = Array.prototype.slice.call(row.getElementsByTagName('IMG'));

	for (var imageCounter = 1; imageCounter < baseImages.length; imageCounter += 2 ) {
		var baseImage = baseImages[imageCounter - 1],
			rolloverImage = baseImages[imageCounter],
			rolloverImageSrc = rolloverImage.getAttribute('src'),
			baseImageSrc = baseImage.getAttribute('src');

		baseImage.addEventListener('mouseover', function () { this.src = rolloverImageSrc; });
		baseImage.addEventListener('mouseout', function () { this.src = baseImageSrc; });

		baseImages.splice(imageCounter, 1);
		rolloverImage.parentElement.removeChild(rolloverImage);
		imageCounter--;
	}
});
console.log('rollover registered');

{'fraction_non_alphanumeric': 0.1421376608841634, 'fraction_numerical': 0.0036373810856183547, 'mean_word_length': 5.372549019607843, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7488663', 'n_tokens_mistral': 1181, 'n_tokens_neox': 1052, 'n_words': 193}