Skip to content

Commit 16c154d

Browse files
committed
Convert live example to TypeScript
1 parent 1374c6d commit 16c154d

File tree

15 files changed

+4051
-1005
lines changed

15 files changed

+4051
-1005
lines changed

examples/live-example/js/CheckboxOption.js

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*global $, Option */
2+
3+
namespace LiveExample {
4+
5+
interface CheckboxOptionCfg extends LiveExample.OptionCfg {
6+
defaultValue?: boolean;
7+
}
8+
9+
10+
/**
11+
* @class CheckboxOption
12+
*
13+
* A checkbox option for the live example.
14+
*/
15+
export class CheckboxOption extends LiveExample.Option {
16+
17+
/**
18+
* @cfg {Boolean} [defaultValue=false]
19+
*
20+
* `true` to check the checkbox by default.
21+
*/
22+
private defaultValue: boolean = false;
23+
24+
private $checkboxEl: JQuery;
25+
private $valueDisplayEl: JQuery;
26+
27+
28+
/**
29+
* @constructor
30+
* @param {CheckboxOptionCfg} cfg The configuration options for this
31+
* class, specified in an Object (map).
32+
*/
33+
constructor( cfg: CheckboxOptionCfg ) {
34+
super( cfg );
35+
36+
this.defaultValue = cfg.defaultValue || false;
37+
38+
this.$containerEl.html( this.generateHtml() );
39+
this.$checkboxEl = this.$containerEl.find( ':checkbox' ).on( 'change', this.updateDisplayEl.bind( this ) );
40+
this.$valueDisplayEl = this.$containerEl.find( '#' + this.containerId + '-value' );
41+
}
42+
43+
44+
/**
45+
* @private
46+
* @return {string}
47+
*/
48+
private generateHtml() {
49+
var containerId = this.containerId,
50+
optionDescription = this.optionDescription,
51+
defaultValue = this.defaultValue,
52+
checkboxId = containerId + '-checkbox';
53+
54+
return `
55+
<input type="checkbox" id="${checkboxId}" ${ defaultValue ? 'checked' : '' }>
56+
<label for="${checkboxId}">${optionDescription}</label>
57+
(<code>${ this.getApiDocAnchor() }: <span id="${containerId}-value">${defaultValue}</span></code>)
58+
`;
59+
}
60+
61+
62+
/**
63+
* @private
64+
*/
65+
private updateDisplayEl() {
66+
this.$valueDisplayEl.html( this.getValue() + '' );
67+
this.fireChange();
68+
}
69+
70+
71+
/**
72+
* @return {Boolean}
73+
*/
74+
getValue() {
75+
return this.$checkboxEl.prop( 'checked' );
76+
}
77+
78+
}
79+
80+
}

examples/live-example/js/Option.js

Lines changed: 0 additions & 118 deletions
This file was deleted.

0 commit comments

Comments
 (0)