<commit_before>'use strict';

var unbox = function(selector, options)
{
	if( !( this instanceof unbox ) )
		return new unbox(selector, options);

	this.options = Object.assign({
		group: false,
	}, options);

	this.elts = document.querySelectorAll( selector );
	this.currentIdx = null;
	this.box = this.parseHTML('<div class="unbox"><div class="unbox-next"></div><div class="unbox-prev"></div><div class="unbox-loader-ctr"><div class="unbox-loader"></div></div></div>');
	this.loader = this.box.querySelector('.unbox-loader-ctr');
	this.nextBtn = this.box.querySelector('.unbox-next');
	this.prevBtn = this.box.querySelector('.unbox-prev');
	this.content = null;

	this.wrpTpl = {
		content : '<div class="unbox-content-ctr"></div>',
		video   : [
			'<div class="unbox-content unbox-video-outer"></div>',
			'<div class="unbox-video-inner"></div>',
		],
	}
	this.wrpTpl.youtube = this.wrpTpl.video;

	this.coreTpl = {
		image   : function( srcData, alt ){ return '<img src="'+srcData[1]+'" alt="'+alt+'" class="unbox-content">' },
		youtube : function( srcData ){ return '<iframe src="https://www.youtube-nocookie.com/embed/'+srcData[2]+'?autoplay=1&rel=0" frameborder="0" allowfullscreen></iframe>' },
	};

	this.regex = {
		image      : /(^data:image\/)|(.+\.(png|jpe?g|gif|svg|webp|bmp|ico|tiff?))/i,
		youtube    : /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube(-nocookie)?\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})/i,

		//vimeo      : /(vimeo(pro)?.com)\/(?:[^\d]+)?(\d+)\??(.*)?$/,  //TODO
		//googlemaps : /((maps|www)\.)?google\.([^\/\?]+)\/?((maps\/?)?\?)(.*)/i, //TODO
		//fbvideo    : /(facebook\.com)\/([a-z0-9_-]*)\/videos\/([0-9]*)(.*)?$/i  //TODO
	};



	if(!NodeList.prototype.forEach)
		NodeList.prototype.forEach = Array.prototype.forEach;

	var	me = this;

	this.elts.forEach( function( elt, i ){
		elt.dataset.unboxIndex = i;
		elt.addEventListener( 'click', function( e ){
			e.preventDefault();
			me.create().open( elt );
		});
	});

	this.box.addEventListener('click', function unboxClick( evt ){
		evt.preventDefault();

		switch( true ){
			case evt.target.matches( '.unbox-content-ctr' ):
			case evt.target.matches( '.unbox-loader-ctr' ):
			case evt.target.matches( '.unbox-close' ):
			case evt.target === evt.currentTarget:
				me.close().destroy();
				break;

			case evt.target.matches( '.unbox-next' ):
				me.goTo( +1 );
				break;

			case evt.target.matches( '.unbox-prev' ):
				me.goTo( -1 );
				break;
		}
	});

	this.evt = {
		swipeLeft  : function(e){ me.goTo( +1 ) },
		swipeRight : function(e){ me.goTo( -1 ) },
		keyDown    : function(e){
			e.preventDefault();
			var key = (window.event) ? event.keyCode : e.keyCode;
			switch(key){
				case 37: me.goTo( -1 );    break; // left arrow to prev
				case 39: me.goTo( +1 );    break; // right arrow to next
				case 27: me.close().destroy(); break; // escape key closes
			}
		}
	};

	return this;
}


unbox.prototype.create = function()
{
	var d = document;

	d.on = d.addEventListener;
	d.body.appendChild( this.box );
	d.on('swipeleft',  this.evt.swipeLeft );
	d.on('swiperight', this.evt.swipeRight );
	d.on('keydown',    this.evt.keyDown );

	this.reflow( this.box );
	this.flip( 'on', this.box );
	return this;
}



unbox.prototype.open = function( elt )
{
	if( this.content !== null )
		this.close();

	this.currentIdx = Number( elt.dataset.unboxIndex );
	this.handleNavigation();

	var
		src = elt.href || elt.dataset.unboxSrc,
		alt = elt.alt || elt.dataset.unboxTitle,
		me = this;

	if(!src)
		return;

	var
		srcData = this.getSrcData( src ),
		srcType = srcData[0];

	var core = this.parseHTML( this.coreTpl[ srcType ]( srcData, alt ) );

	this.flip( 'on', me.loader );

	core.addEventListener( 'load', function onLoad( e ){
		core.removeEventListener( 'load', onLoad );
		me.reflow( me.content );
		me.flip( 'off', me.loader );
		me.flip( 'on', me.content );
	});

	if( this.wrpTpl[ srcType ] )
		for( var i = this.wrpTpl[ srcType ].length; i--; )
			core = this.wrapHTML( core, this.wrpTpl[ srcType ][ i ] )

	console.log( core );

	this.content = this.parseHTML( this.wrpTpl.content );
	this.content.appendChild( core );
	this.box.appendChild( this.content );

	return;
}



unbox.prototype.getSrcData = function( src )
{
	var srcData;

	for( var srcType in this.regex )
	{
		srcData = src.match( this.regex[ srcType ] );
		if( srcData !== null )
		{
			srcData.unshift( srcType );
			return srcData;
		}
	}

	return ['image', src ];
}
<commit_msg>YouNoob improvement<commit_after>'use strict';

var unbox = function(selector, options)
{
	if( !( this instanceof unbox ) )
		return new unbox(selector, options);

	this.options = Object.assign({
		group: false,
	}, options);

	this.elts = document.querySelectorAll( selector );
	this.currentIdx = null;
	this.box = this.parseHTML('<div class="unbox"><div class="unbox-next"></div><div class="unbox-prev"></div><div class="unbox-loader-ctr"><div class="unbox-loader"></div></div></div>');
	this.loader = this.box.querySelector('.unbox-loader-ctr');
	this.nextBtn = this.box.querySelector('.unbox-next');
	this.prevBtn = this.box.querySelector('.unbox-prev');
	this.content = null;

	this.wrpTpl = {
		content : '<div class="unbox-content-ctr"></div>',
		video   : [
			'<div class="unbox-content unbox-video-outer"></div>',
			'<div class="unbox-video-inner"></div>',
		],
	}
	this.wrpTpl.youtube = this.wrpTpl.video;

	this.coreTpl = {
		image   : function( srcData, alt ){ return '<img src="'+srcData[1]+'" alt="'+alt+'" class="unbox-content">' },
		youtube : function( srcData ){ return '<iframe src="https://www.youtube'+srcData[2]+'.com/embed/'+srcData[3]+srcData[4]+'" frameborder="0" allowfullscreen></iframe>' },
	};

	this.regex = {
		image      : /(^data:image\/)|(.+\.(png|jpe?g|gif|svg|webp|bmp|ico|tiff?))/i,
		youtube    : /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube(-nocookie)?\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))([\w-]{11})(.*)?/i,

		//vimeo      : /(vimeo(pro)?.com)\/(?:[^\d]+)?(\d+)\??(.*)?$/,  //TODO
		//googlemaps : /((maps|www)\.)?google\.([^\/\?]+)\/?((maps\/?)?\?)(.*)/i, //TODO
		//fbvideo    : /(facebook\.com)\/([a-z0-9_-]*)\/videos\/([0-9]*)(.*)?$/i  //TODO
	};



	if(!NodeList.prototype.forEach)
		NodeList.prototype.forEach = Array.prototype.forEach;

	var	me = this;

	this.elts.forEach( function( elt, i ){
		elt.dataset.unboxIndex = i;
		elt.addEventListener( 'click', function( e ){
			e.preventDefault();
			me.create().open( elt );
		});
	});

	this.box.addEventListener('click', function unboxClick( evt ){
		evt.preventDefault();

		switch( true ){
			case evt.target.matches( '.unbox-content-ctr' ):
			case evt.target.matches( '.unbox-loader-ctr' ):
			case evt.target.matches( '.unbox-close' ):
			case evt.target === evt.currentTarget:
				me.close().destroy();
				break;

			case evt.target.matches( '.unbox-next' ):
				me.goTo( +1 );
				break;

			case evt.target.matches( '.unbox-prev' ):
				me.goTo( -1 );
				break;
		}
	});

	this.evt = {
		swipeLeft  : function(e){ me.goTo( +1 ) },
		swipeRight : function(e){ me.goTo( -1 ) },
		keyDown    : function(e){
			e.preventDefault();
			var key = (window.event) ? event.keyCode : e.keyCode;
			switch(key){
				case 37: me.goTo( -1 );    break; // left arrow to prev
				case 39: me.goTo( +1 );    break; // right arrow to next
				case 27: me.close().destroy(); break; // escape key closes
			}
		}
	};

	return this;
}


unbox.prototype.create = function()
{
	var d = document;

	d.on = d.addEventListener;
	d.body.appendChild( this.box );
	d.on('swipeleft',  this.evt.swipeLeft );
	d.on('swiperight', this.evt.swipeRight );
	d.on('keydown',    this.evt.keyDown );

	this.reflow( this.box );
	this.flip( 'on', this.box );
	return this;
}



unbox.prototype.open = function( elt )
{
	if( this.content !== null )
		this.close();

	this.currentIdx = Number( elt.dataset.unboxIndex );
	this.handleNavigation();

	var
		src = elt.href || elt.dataset.unboxSrc,
		alt = elt.alt || elt.dataset.unboxTitle,
		me = this;

	if(!src)
		return;

	var
		srcData = this.getSrcData( src ),
		srcType = srcData[0];

	var core = this.parseHTML( this.coreTpl[ srcType ]( srcData, alt ) );

	this.flip( 'on', me.loader );

	core.addEventListener( 'load', function onLoad( e ){
		core.removeEventListener( 'load', onLoad );
		me.reflow( me.content );
		me.flip( 'off', me.loader );
		me.flip( 'on', me.content );
	});

	if( this.wrpTpl[ srcType ] )
		for( var i = this.wrpTpl[ srcType ].length; i--; )
			core = this.wrapHTML( core, this.wrpTpl[ srcType ][ i ] )

	console.log( core );

	this.content = this.parseHTML( this.wrpTpl.content );
	this.content.appendChild( core );
	this.box.appendChild( this.content );

	return;
}



unbox.prototype.getSrcData = function( src )
{
	var srcData;

	for( var srcType in this.regex )
	{
		srcData = src.match( this.regex[ srcType ] );
		if( srcData !== null )
		{
			srcData = srcData.map( function( match ){
				return match || '';
			});

			srcData.unshift( srcType );
			return srcData;
		}
	}

	return ['image', src ];
}

{'fraction_non_alphanumeric': 0.21646980902969423, 'fraction_numerical': 0.005298598079258196, 'mean_word_length': 3.3411595591758507, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 2, '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': '3238012', 'n_tokens_mistral': 3730, 'n_tokens_neox': 3458, 'n_words': 619}