<commit_before>$.widget( "readmore.carddeck", {
	// Default options
	options: {
		controlwidget: "articleviewer",
		cover: null,
		carddecks: [{ 'url': '/widgets/dictionary/', 'params': {'word':"%%WORD%%"}}]
	},
	_create: function(){
		var _self = this
		// Find any instance of the controlwidget and
		// bind to the `wordclick' event
		$(":readmore-"+this.options.controlwidget).bind(
			this.options.controlwidget+"wordclick",
			function(event, data){
				location.hash = "#cover-"+data['word'];
			}
		)
		$(window).hashchange(function(){
			if(location.hash == ''){
				_self.close(_self.options.cover);
			}else{
				hash_parts = location.hash.split("-");
				if(hash_parts[0] == '#cover'){
					_self.load(hash_parts[1])
				}
			}
		});
		$(this.options.cover).find("#closeCover").click(
				function(){
					window.history.back();
					return false;
				});
		$(this.options.cover).find("#closeOnBackground").click(
				function(){
					window.history.back();
					return false;
				});
	},
	decks: function(word){
		decks = []
		for(var i = 0; i < this.options.carddecks.length ; i++){
			var url = this.options.carddecks[i].url;
			var params = {};
			for(key in this.options.carddecks[i].params){
				params[key] = this.options.carddecks[i].params[key]
					.replace("%%WORD%%", word);
			}
			decks.push({'url':url, 'params':params});
		}
        $.post( "/add_to_history/", {
                article: location.pathname.split('/')[3],
                value: word,
                type: 'word',
                csrfmiddlewaretoken: getCookie('csrftoken'),
        });
		return decks;
	},
    load: function(word){
        var _self = this;
		if(this.options.cover){
			if($(this.options.cover).hasClass('open')){
				this.carddeck.close();
			}else{
				$(this.options.cover).addClass('open');
			}
		}
		this.carddeck = new CardDeck(this.element, this.decks(word));
	},
    close: function(cover){
		if(cover){
		    $(cover).removeClass('open');
        }
        $('.lastSelected.prevSelected').removeClass('lastSelected');
        $('#selected').addClass('lastSelected');
        $('#selected').addClass('prevSelected');
        $('#selected').removeAttr('id');
        this.carddeck.close();
    }
})
<commit_msg>Close card cover upon escape key press<commit_after>$.widget( "readmore.carddeck", {
	// Default options
	options: {
		controlwidget: "articleviewer",
		cover: null,
		carddecks: [{ 'url': '/widgets/dictionary/', 'params': {'word':"%%WORD%%"}}]
	},
	_create: function(){
		var _self = this
		// Find any instance of the controlwidget and
		// bind to the `wordclick' event
		$(":readmore-"+this.options.controlwidget).bind(
			this.options.controlwidget+"wordclick",
			function(event, data){
				location.hash = "#cover-"+data['word'];
			}
		)
		$(window).hashchange(function(){
			if(location.hash == ''){
				_self.close(_self.options.cover);
			}else{
				hash_parts = location.hash.split("-");
				if(hash_parts[0] == '#cover'){
					_self.load(hash_parts[1])
				}
			}
		});
		$(this.options.cover).find("#closeCover").click(
				function(){
					window.history.back();
					return false;
				});
		$(this.options.cover).find("#closeOnBackground").click(
				function(){
					window.history.back();
					return false;
				});
		//Close card window upon pressing escape
		$(document).keyup(
				function(e){
					if(e.which == 27) {
						window.history.back();
						return false;
					}
				});
	},
	decks: function(word){
		decks = []
		for(var i = 0; i < this.options.carddecks.length ; i++){
			var url = this.options.carddecks[i].url;
			var params = {};
			for(key in this.options.carddecks[i].params){
				params[key] = this.options.carddecks[i].params[key]
					.replace("%%WORD%%", word);
			}
			decks.push({'url':url, 'params':params});
		}
        $.post( "/add_to_history/", {
                article: location.pathname.split('/')[3],
                value: word,
                type: 'word',
                csrfmiddlewaretoken: getCookie('csrftoken'),
        });
		return decks;
	},
    load: function(word){
        var _self = this;
		if(this.options.cover){
			if($(this.options.cover).hasClass('open')){
				this.carddeck.close();
			}else{
				$(this.options.cover).addClass('open');
			}
		}
		this.carddeck = new CardDeck(this.element, this.decks(word));
	},
    close: function(cover){
		if(cover){
		    $(cover).removeClass('open');
        }
        $('.lastSelected.prevSelected').removeClass('lastSelected');
        $('#selected').addClass('lastSelected');
        $('#selected').addClass('prevSelected');
        $('#selected').removeAttr('id');
        this.carddeck.close();
    }
})

{'fraction_non_alphanumeric': 0.19669315009662874, 'fraction_numerical': 0.002147305132059266, 'mean_word_length': 2.927487352445194, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, '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': '3517764', 'n_tokens_mistral': 1778, 'n_tokens_neox': 1521, 'n_words': 247}