<commit_before>KEYCODES = require( "../utils/keycodes" )

class SelectorView extends require( "./facets/base" )
	template: require( "../tmpls/selector.jade" )
	templateEl: require( "../tmpls/selectorli.jade" )
	selectCount: 1

	className: =>
		cls = [ "add-facet" ]
		if @custom
			cls.push "custom"
		return cls.join( " " )

	events: =>
		"mousedown a": "_onClick"
		"focus input##{@cid}": "open"
		#"blur input##{@cid}": "close"
		"keydown input##{@cid}": "search"
		"keyup input##{@cid}": "search"

	constructor: ( options )->
		@custom =  options.custom or false
		@activeIdx = 0
		@currQuery = ""
		super
		return
		
	initialize: ( options )=>
		@searchcoll = @collection.sub( ->true )
		@result = new @collection.constructor()
		
		@listenTo( @searchcoll, "add", @renderRes )
		@listenTo( @searchcoll, "remove", @renderRes )
		@listenTo( @searchcoll, "remove", @checkOptionsEmpty )
		
		return

	getTemplateData: =>
		return _.extend( super, custom: @custom )

	render: =>
		super
		@$list = @$el.find( "##{@cid}typelist" )
		@renderRes()
		return @el

	renderRes: =>
		@$list.empty()

		_list = []
		for model, idx in @searchcoll.models
			_lbl = model.getLabel()
			_id = model.id
			_cssclass = model.get( "cssclass" )
			if @currQuery?.length > 1
				_lbl = _lbl.replace( new RegExp( @currQuery, "gi" ), (( str )->return "<b>#{str}</b>" ) )
			_list.push label: _lbl, id: _id, cssclass: _cssclass
		@$list.append( @templateEl( list: _list, query: @currQuery, activeIdx: @activeIdx, custom: @custom ) )

		@_checkScroll()
		
		return @$list

	_scrollTill: 198
	_checkScroll: =>
		_height = @$list.height()
		if _height > 0
			@scrollHelper( _height )
			return

		# exit the the call stack to check height after the module has been added to the dom
		setTimeout( =>
			@scrollHelper( @$list.height() )
		, 0 )
		return

	scrollHelper: ( height )=>
		if height >= @_scrollTill
			@scrolling = true
		else
			@scrolling = false
		return<commit_msg>added option `labeltemplate` to ba able to design the option. closes #34<commit_after>KEYCODES = require( "../utils/keycodes" )

class SelectorView extends require( "./facets/base" )
	template: require( "../tmpls/selector.jade" )
	templateEl: require( "../tmpls/selectorli.jade" )
	selectCount: 1

	className: =>
		cls = [ "add-facet" ]
		if @custom
			cls.push "custom"
		return cls.join( " " )

	events: =>
		"mousedown a": "_onClick"
		"focus input##{@cid}": "open"
		#"blur input##{@cid}": "close"
		"keydown input##{@cid}": "search"
		"keyup input##{@cid}": "search"

	constructor: ( options )->
		@custom =  options.custom or false
		@activeIdx = 0
		@currQuery = ""
		super
		return
		
	initialize: ( options )=>
		@searchcoll = @collection.sub( ->true )
		@result = new @collection.constructor()
		
		@listenTo( @searchcoll, "add", @renderRes )
		@listenTo( @searchcoll, "remove", @renderRes )
		@listenTo( @searchcoll, "remove", @checkOptionsEmpty )
		
		return

	getTemplateData: =>
		return _.extend( super, custom: @custom )

	render: =>
		super
		@$list = @$el.find( "##{@cid}typelist" )
		@renderRes()
		return @el

	renderRes: =>
		@$list.empty()

		_list = []
		for model, idx in @searchcoll.models
			_lbl = model.getLabel()
			_tmpl = model.get( "labeltemplate" )
			if _tmpl?
				_lbl = _tmpl.replace( "{{label}}", _lbl )
				
			_id = model.id
			_cssclass = model.get( "cssclass" )
			if @currQuery?.length > 1
				_lbl = _lbl.replace( new RegExp( @currQuery, "gi" ), (( str )->return "<b>#{str}</b>" ) )
			_list.push label: _lbl, id: _id, cssclass: _cssclass
		@$list.append( @templateEl( list: _list, query: @currQuery, activeIdx: @activeIdx, custom: @custom ) )

		@_checkScroll()
		
		return @$list

	_scrollTill: 198
	_checkScroll: =>
		_height = @$list.height()
		if _height > 0
			@scrollHelper( _height )
			return

		# exit the the call stack to check height after the module has been added to the dom
		setTimeout( =>
			@scrollHelper( @$list.height() )
		, 0 )
		return

	scrollHelper: ( height )=>
		if height >= @_scrollTill
			@scrolling = true
		else
			@scrolling = false
		return
{'fraction_non_alphanumeric': 0.16449791308617726, 'fraction_numerical': 0.00441934691873312, 'mean_word_length': 3.501657458563536, 'pattern_counts': {'":': 10, '<': 7, '<?xml version=': 0, '>': 37, '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': '5911105', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1480, 'n_words': 375}