-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7dd634e
commit 33d7611
Showing
7 changed files
with
148 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @fileoverview | ||
* @author Sungho Kim([email protected]) FE Development Team/NHN Ent. | ||
*/ | ||
'use strict'; | ||
|
||
var Button = require('./button'); | ||
|
||
var util = ne.util; | ||
|
||
/** | ||
* ToggleButton | ||
* initialize toggle button | ||
* @exports ToggleButton | ||
* @augments Button | ||
* @constructor | ||
* @class | ||
* @param {object[]} options 옵션 | ||
* @param {string} options.className 만들어진 RootElement에 추가할 클래스 | ||
* @param {string} options.command 클릭되면 실행될 커맨드명 | ||
* @param {string} options.text 버튼안에 들어갈 텍스트 | ||
* @param {string} options.style 추가적으로 적용될 CSS스타일 | ||
*/ | ||
function ToggleButton(options) { | ||
this.options = options; | ||
this.current = this.options[0]; | ||
|
||
Button.call(this, this.current); | ||
|
||
this._initEvent(); | ||
} | ||
|
||
ToggleButton.prototype = util.extend( | ||
{}, | ||
Button.prototype | ||
); | ||
|
||
ToggleButton.prototype._initEvent = function() { | ||
var self = this; | ||
|
||
this.on('clicked', function() { | ||
self._toggle(); | ||
}); | ||
}; | ||
|
||
ToggleButton.prototype._toggle = function() { | ||
if (this.current === this.options[0]) { | ||
this.current = this.options[1]; | ||
} else { | ||
this.current = this.options[0]; | ||
} | ||
|
||
this._setOptions(this.current); | ||
this.render(); | ||
}; | ||
|
||
module.exports = ToggleButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
'use strict'; | ||
|
||
var ToggleButton = require('../src/js/toggleButton'); | ||
|
||
describe('ToggleButton', function() { | ||
var button; | ||
|
||
beforeEach(function() { | ||
$('body').empty(); | ||
}); | ||
|
||
describe('버튼 생성', function() { | ||
it('버튼 태그를 만든다.', function() { | ||
button = new ToggleButton([{}]); | ||
expect(button.$el.prop('tagName')).toEqual('BUTTON'); | ||
}); | ||
|
||
it('옵션으로 전달된 className이 버튼태그에 적용된다.', function() { | ||
button = new ToggleButton([{ | ||
className: 'myclass' | ||
}]); | ||
expect(button.$el.hasClass('myclass')).toBe(true); | ||
}); | ||
|
||
it('옵션으로 전달된 text가 버튼태그에 적용된다.', function() { | ||
button = new ToggleButton([{ | ||
text: 'buttonText' | ||
}]); | ||
|
||
expect(button.$el.text()).toEqual('buttonText'); | ||
}); | ||
|
||
it('옵션으로 전달된 style 버튼태그에 적용된다.', function() { | ||
button = new ToggleButton([{ | ||
style: 'display:none' | ||
}]); | ||
|
||
expect(button.$el.css('display')).toEqual('none'); | ||
}); | ||
}); | ||
|
||
describe('toggle button', function() { | ||
it('toggle button with second options', function() { | ||
button = new ToggleButton([{ | ||
text: 'first' | ||
}, { | ||
text: 'second' | ||
}]); | ||
|
||
expect(button.text).toEqual('first'); | ||
|
||
button._onClick(); | ||
|
||
expect(button.text).toEqual('second'); | ||
}); | ||
}); | ||
}); |