Skip to content

Commit

Permalink
[1-vanilla] TabView 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jeonghwan-kim committed Dec 26, 2017
1 parent 26de5be commit 0a9ceab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 1-vanilla/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ <h2 class="container">검색</h2>
</form>

<div class="content">
<ul id="tabs" class="tabs">
<li>추천 검색어</li>
<li>최근 검색어</li>
</ul>
<div id="search-keyword"></div>
<div id="search-history"></div>
<div id="search-result"></div>
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions 1-vanilla/js/views/FormView.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,9 @@ FormView.onClickReset = function() {
this.showResetBtn(false)
}

FormView.setValue = function (value = '') {
this.inputEl.value = value
this.showResetBtn(this.inputEl.value.length)
}

export default FormView
36 changes: 36 additions & 0 deletions 1-vanilla/js/views/TabView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import View from './View.js'

const tag = '[TabView]'

const TabView = Object.create(View)

TabView.tabNames = {
recommand: '추천 검색어',
recent: '최근 검색어',
}

TabView.setup = function(el) {
this.init(el)
this.bindClick()
return this
}

TabView.setActiveTab = function (tabName) {
Array.from(this.el.children).forEach(li => {
li.className = li.innerHTML === tabName ? 'active' : ''
})
this.show()
}

TabView.bindClick = function() {
Array.from(this.el.children).forEach(li => {
li.addEventListener('click', e => this.onClick(li.innerHTML))
})
}

TabView.onClick = function (tabName) {
this.setActiveTab(tabName)
this.emit('@change', {tabName})
}

export default TabView

0 comments on commit 0a9ceab

Please sign in to comment.