<commit_before>class cola.CardBook extends cola.AbstractItemGroup
	@tagName: "c-cardBook"
	@CLASS_NAME: "card-book"

	@events:
		beforeChange: null
		change: null

	_parseDom: (dom)->
		child = dom.firstChild
		while child
			if child.nodeType == 1
				if cola.util.hasClass(child, "item")
					@addItem(child) if child.nodeType == 1
			child = child.nextSibling
		return null

	_initDom: (dom)->
		super(dom)
		if @_items then @_itemsRender()
		return

	setCurrentIndex: (index)->
		@_currentIndex ?= -1
		return @ if @_currentIndex == index
		arg = {}

		if @_currentIndex > -1
			oldItem = @_items[@_currentIndex]
			oldItemDom = @getItemDom(@_currentIndex)
		if index > -1
			newItem = @_items[index]
			newItemDom = @getItemDom(index)

		arg =
			oldItem: oldItem
			newItem: newItem

		return @ if @fire("beforeChange", @, arg) is false

		$(oldItemDom).removeClass("active") if oldItemDom
		$(newItemDom).addClass("active") if newItemDom
		@_currentIndex = index

		@fire("change", @, arg)
		return @

cola.registerWidget(cola.CardBook)<commit_msg>小重构cardbook<commit_after>class cola.CardBook extends cola.AbstractItemGroup
	@tagName: "c-cardBook"
	@CLASS_NAME: "card-book"

	@events:
		beforeChange: null
		change: null

	_parseDom: (dom)->
		child = dom.firstChild
		while child
			if child.nodeType == 1
				if cola.util.hasClass(child, "item")
					@addItem(child) if child.nodeType == 1
			child = child.nextSibling
		return null

	_initDom: (dom)->
		super(dom)
		if @_items then @_itemsRender()
		return

	setCurrentIndex: (index)->
		@_currentIndex ?= -1
		arg = {}
		if @_dom
			$dom = $(@_dom)
			children = $dom.find(">.item")
			oldItem = $dom.find(">.item.active")[0]
			if children.length > index
				newItem = children[index]
				if newItem == oldItem then return
				@_currentIndex = index
				arg =
					oldItem: oldItem
					newItem: newItem
				return @ if @fire("beforeChange", @, arg) is false
				@_currentIndex = index
				if oldItem then $(oldItem).removeClass("active")
				if newItem then $(newItem).addClass("active")
				@fire("change", @, arg)
		else
			@_currentIndex=index
		return @

cola.registerWidget(cola.CardBook)
{'fraction_non_alphanumeric': 0.13259156235512284, 'fraction_numerical': 0.004172461752433936, 'mean_word_length': 3.630901287553648, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, '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': '3209870', 'n_tokens_mistral': 880, 'n_tokens_neox': 760, 'n_words': 179}