<commit_before>/*global define*/

define([
	'jquery',
	'underscore',
	'backbone',
	'collections/dictionary',
	'views/word_view',
	'views/search_view',
	'templates'
], function ($, _, Backbone, DictionaryCollection, WordView, SearchView, JST) {
	'use strict';

	window.app = window.app || {};

	var DictionaryView = Backbone.View.extend({
		el: '#dictionary',

		initialize: function(words) {
			// this.$dictionary = this.$el.find('#dictionary');
			this.$addWord = this.$el.find('.add-word');

			this.collections = new DictionaryCollection();
			this.collections.fetch();

			// create search view, words are still being fetched using ajax!!
			// that's why it's empty
			this.searchView = new SearchView();

			this.listenTo(this.collections, "add", this.addWord);
			this.listenTo(this.collections, "destroy", this.removeWord);
		},

		render: function(wordNames) {
			var filteredModels;

			this.$el.empty();
			if (app.wordType === 'all') {
				filteredModels = this.collections.models;
			} else {
				var remembered = app.wordType === "remembered" ? true : false;
				filteredModels = this.collections.where( {remembered: remembered} );
			}
			if (wordNames) {
				wordNames = wordNames.map(function(word) {
					return word.toLowerCase();
				});
				filteredModels = filteredModels.filter(function(model) {
					return wordNames.indexOf(model.get('name')) + 1;
				});
			}

			var wordViews = [];
			var $words = $('<div class="word-container">');
			filteredModels.map(function(word) {
				var wordView = new WordView({ model: word });
				$words.append( wordView.render().el );
				wordViews.push(wordView);
			}, this);

			this.$el.append($words);

			for (var i = 0; i < wordViews.length; i++) {
				wordViews[i].afterAppend();
			}

			this.searchView.clear();
			hideOtherContainers();

			return this;
		},

		addWord: function(word) {
			this.renderWord(word);
			this.searchView.addWord( word.get('name') );
		},

		removeWord: function(word) {
			this.searchView.removeWord( word.get('name') );
		},

		renderWord: function(word) {
			var wordView = new WordView({ model: word });
			var $wordContainer = this.$('.word-container');
			if (!$wordContainer.length) {
				$wordContainer = $('<div class="word-container">');
				this.$el.append($wordContainer);
			}
			$wordContainer.append( wordView.render().el );
			wordView.afterAppend();<commit_msg>fix bug when searching for text<commit_after>/*global define*/

define([
	'jquery',
	'underscore',
	'backbone',
	'collections/dictionary',
	'views/word_view',
	'views/search_view',
	'templates'
], function ($, _, Backbone, DictionaryCollection, WordView, SearchView, JST) {
	'use strict';

	window.app = window.app || {};

	var DictionaryView = Backbone.View.extend({
		el: '#dictionary',

		initialize: function(words) {
			// this.$dictionary = this.$el.find('#dictionary');
			this.$addWord = this.$el.find('.add-word');

			this.collections = new DictionaryCollection();
			this.collections.fetch();

			// create search view, words are still being fetched using ajax!!
			// that's why it's empty
			this.searchView = new SearchView();

			this.listenTo(this.collections, "add", this.addWord);
			this.listenTo(this.collections, "destroy", this.removeWord);
		},

		render: function(wordNames) {
			var filteredModels;

			this.$el.empty();
			if (app.wordType === 'all') {
				filteredModels = this.collections.models;
			} else {
				var remembered = app.wordType === "remembered" ? true : false;
				filteredModels = this.collections.where( {remembered: remembered} );
			}
			if (wordNames) {
				wordNames = wordNames.map(function(word) {
					return word.toLowerCase();
				});
				filteredModels = filteredModels.filter(function(model) {
					return wordNames.indexOf(model.get('name')) + 1;
				});
			}

			var wordViews = [];
			var $words = $('<div class="word-container">');
			filteredModels.map(function(word) {
				var wordView = new WordView({ model: word });
				$words.append( wordView.render().el );
				wordViews.push(wordView);
			}, this);

			this.$el.append($words);

			for (var i = 0; i < wordViews.length; i++) {
				wordViews[i].afterAppend();
			}

			// this.searchView.clear();
			hideOtherContainers();

			return this;
		},

		addWord: function(word) {
			this.renderWord(word);
			this.searchView.addWord( word.get('name') );
		},

		removeWord: function(word) {
			this.searchView.removeWord( word.get('name') );
		},

		renderWord: function(word) {
			var wordView = new WordView({ model: word });
			var $wordContainer = this.$('.word-container');
			if (!$wordContainer.length) {
				$wordContainer = $('<div class="word-container">');
				this.$el.append($wordContainer);
			}
			$wordContainer.append( wordView.render().el );
			wordView.afterAppend();
{'fraction_non_alphanumeric': 0.1701236119840771, 'fraction_numerical': 0.0008380473496752566, 'mean_word_length': 3.6941986234021633, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '5611615', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1504, 'n_words': 302}