ui.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. var UI = {};
  2. UI.Element = function () {};
  3. UI.Element.prototype = {
  4. setId: function ( id ) {
  5. this.dom.id = id;
  6. return this;
  7. },
  8. setClass: function ( name ) {
  9. this.dom.className = name;
  10. return this;
  11. },
  12. setStyle: function ( style, array ) {
  13. for ( var i = 0; i < array.length; i ++ ) {
  14. this.dom.style[ style ] = array[ i ];
  15. }
  16. },
  17. setDisabled: function ( value ) {
  18. this.dom.disabled = value;
  19. return this;
  20. },
  21. setTextContent: function ( value ) {
  22. this.dom.textContent = value;
  23. return this;
  24. }
  25. }
  26. // properties
  27. var properties = [ 'position', 'left', 'top', 'right', 'bottom', 'width', 'height', 'border', 'borderLeft',
  28. 'borderTop', 'borderRight', 'borderBottom', 'borderColor', 'display', 'overflow', 'margin', 'marginLeft', 'marginTop', 'marginRight', 'marginBottom', 'padding', 'paddingLeft', 'paddingTop', 'paddingRight', 'paddingBottom', 'color',
  29. 'backgroundColor', 'opacity', 'fontSize', 'fontWeight', 'textAlign', 'textTransform', 'cursor' ];
  30. properties.forEach( function ( property ) {
  31. var method = 'set' + property.substr( 0, 1 ).toUpperCase() + property.substr( 1, property.length );
  32. UI.Element.prototype[ method ] = function () {
  33. this.setStyle( property, arguments );
  34. return this;
  35. };
  36. } );
  37. // events
  38. var events = [ 'KeyUp', 'KeyDown', 'MouseOver', 'MouseOut', 'Click', 'DblClick', 'Change' ];
  39. events.forEach( function ( event ) {
  40. var method = 'on' + event;
  41. UI.Element.prototype[ method ] = function ( callback ) {
  42. this.dom.addEventListener( event.toLowerCase(), callback.bind( this ), false );
  43. return this;
  44. };
  45. } );
  46. // Panel
  47. UI.Panel = function () {
  48. UI.Element.call( this );
  49. var dom = document.createElement( 'div' );
  50. dom.className = 'Panel';
  51. this.dom = dom;
  52. return this;
  53. };
  54. UI.Panel.prototype = Object.create( UI.Element.prototype );
  55. UI.Panel.prototype.add = function () {
  56. for ( var i = 0; i < arguments.length; i ++ ) {
  57. var argument = arguments[ i ];
  58. if ( argument instanceof UI.Element ) {
  59. this.dom.appendChild( argument.dom );
  60. } else {
  61. console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' )
  62. }
  63. }
  64. return this;
  65. };
  66. UI.Panel.prototype.remove = function () {
  67. for ( var i = 0; i < arguments.length; i ++ ) {
  68. var argument = arguments[ i ];
  69. if ( argument instanceof UI.Element ) {
  70. this.dom.removeChild( argument.dom );
  71. } else {
  72. console.error( 'UI.Panel:', argument, 'is not an instance of UI.Element.' )
  73. }
  74. }
  75. return this;
  76. };
  77. UI.Panel.prototype.clear = function () {
  78. while ( this.dom.children.length ) {
  79. this.dom.removeChild( this.dom.lastChild );
  80. }
  81. };
  82. // Collapsible Panel
  83. UI.CollapsiblePanel = function () {
  84. UI.Panel.call( this );
  85. this.setClass( 'Panel Collapsible' );
  86. var scope = this;
  87. this.static = new UI.Panel();
  88. this.static.setClass( 'Static' );
  89. this.static.onClick( function () {
  90. scope.toggle();
  91. } );
  92. this.dom.appendChild( this.static.dom );
  93. this.contents = new UI.Panel();
  94. this.contents.setClass( 'Content' );
  95. this.dom.appendChild( this.contents.dom );
  96. var button = new UI.Panel();
  97. button.setClass( 'Button' );
  98. this.static.add( button );
  99. this.isCollapsed = false;
  100. return this;
  101. };
  102. UI.CollapsiblePanel.prototype = Object.create( UI.Panel.prototype );
  103. UI.CollapsiblePanel.prototype.addStatic = function () {
  104. this.static.add.apply( this.static, arguments );
  105. return this;
  106. };
  107. UI.CollapsiblePanel.prototype.removeStatic = function () {
  108. this.static.remove.apply( this.static, arguments );
  109. return this;
  110. };
  111. UI.CollapsiblePanel.prototype.clearStatic = function () {
  112. this.static.clear();
  113. return this;
  114. };
  115. UI.CollapsiblePanel.prototype.add = function () {
  116. this.contents.add.apply( this.contents, arguments );
  117. return this;
  118. };
  119. UI.CollapsiblePanel.prototype.remove = function () {
  120. this.contents.remove.apply( this.contents, arguments );
  121. return this;
  122. };
  123. UI.CollapsiblePanel.prototype.clear = function () {
  124. this.contents.clear();
  125. return this;
  126. };
  127. UI.CollapsiblePanel.prototype.toggle = function() {
  128. this.setCollapsed( !this.isCollapsed );
  129. };
  130. UI.CollapsiblePanel.prototype.collapse = function() {
  131. this.setCollapsed( true );
  132. };
  133. UI.CollapsiblePanel.prototype.expand = function() {
  134. this.setCollapsed( false );
  135. };
  136. UI.CollapsiblePanel.prototype.setCollapsed = function( boolean ) {
  137. if ( boolean ) {
  138. this.dom.classList.add( 'collapsed' );
  139. } else {
  140. this.dom.classList.remove( 'collapsed' );
  141. }
  142. this.isCollapsed = boolean;
  143. if ( this.onCollapsedChangeCallback !== undefined ) {
  144. this.onCollapsedChangeCallback( boolean );
  145. }
  146. };
  147. UI.CollapsiblePanel.prototype.onCollapsedChange = function ( callback ) {
  148. this.onCollapsedChangeCallback = callback;
  149. };
  150. // Text
  151. UI.Text = function ( text ) {
  152. UI.Element.call( this );
  153. var dom = document.createElement( 'span' );
  154. dom.className = 'Text';
  155. dom.style.cursor = 'default';
  156. dom.style.display = 'inline-block';
  157. dom.style.verticalAlign = 'middle';
  158. this.dom = dom;
  159. this.setValue( text );
  160. return this;
  161. };
  162. UI.Text.prototype = Object.create( UI.Element.prototype );
  163. UI.Text.prototype.setValue = function ( value ) {
  164. if ( value !== undefined ) {
  165. this.dom.textContent = value;
  166. }
  167. return this;
  168. };
  169. // Input
  170. UI.Input = function () {
  171. UI.Element.call( this );
  172. var scope = this;
  173. var dom = document.createElement( 'input' );
  174. dom.className = 'Input';
  175. dom.style.padding = '2px';
  176. dom.style.border = '1px solid #ccc';
  177. dom.addEventListener( 'keydown', function ( event ) {
  178. event.stopPropagation();
  179. }, false );
  180. this.dom = dom;
  181. return this;
  182. };
  183. UI.Input.prototype = Object.create( UI.Element.prototype );
  184. UI.Input.prototype.getValue = function () {
  185. return this.dom.value;
  186. };
  187. UI.Input.prototype.setValue = function ( value ) {
  188. this.dom.value = value;
  189. return this;
  190. };
  191. // TextArea
  192. UI.TextArea = function () {
  193. UI.Element.call( this );
  194. var scope = this;
  195. var dom = document.createElement( 'textarea' );
  196. dom.className = 'TextArea';
  197. dom.style.padding = '2px';
  198. dom.style.border = '1px solid #ccc';
  199. dom.spellcheck = false;
  200. dom.addEventListener( 'keydown', function ( event ) {
  201. event.stopPropagation();
  202. if ( event.keyCode === 9 ) {
  203. event.preventDefault();
  204. var cursor = dom.selectionStart;
  205. dom.value = dom.value.substring( 0, cursor ) + '\t' + dom.value.substring( cursor );
  206. dom.selectionStart = cursor + 1;
  207. dom.selectionEnd = dom.selectionStart;
  208. }
  209. }, false );
  210. this.dom = dom;
  211. return this;
  212. };
  213. UI.TextArea.prototype = Object.create( UI.Element.prototype );
  214. UI.TextArea.prototype.getValue = function () {
  215. return this.dom.value;
  216. };
  217. UI.TextArea.prototype.setValue = function ( value ) {
  218. this.dom.value = value;
  219. return this;
  220. };
  221. // Select
  222. UI.Select = function () {
  223. UI.Element.call( this );
  224. var scope = this;
  225. var dom = document.createElement( 'select' );
  226. dom.className = 'Select';
  227. dom.style.width = '64px';
  228. dom.style.height = '16px';
  229. dom.style.border = '0px';
  230. dom.style.padding = '0px';
  231. this.dom = dom;
  232. return this;
  233. };
  234. UI.Select.prototype = Object.create( UI.Element.prototype );
  235. UI.Select.prototype.setMultiple = function ( boolean ) {
  236. this.dom.multiple = boolean;
  237. return this;
  238. };
  239. UI.Select.prototype.setOptions = function ( options ) {
  240. var selected = this.dom.value;
  241. while ( this.dom.children.length > 0 ) {
  242. this.dom.removeChild( this.dom.firstChild );
  243. }
  244. for ( var key in options ) {
  245. var option = document.createElement( 'option' );
  246. option.value = key;
  247. option.innerHTML = options[ key ];
  248. this.dom.appendChild( option );
  249. }
  250. this.dom.value = selected;
  251. return this;
  252. };
  253. UI.Select.prototype.getValue = function () {
  254. return this.dom.value;
  255. };
  256. UI.Select.prototype.setValue = function ( value ) {
  257. value = String( value );
  258. if ( this.dom.value !== value ) {
  259. this.dom.value = value;
  260. }
  261. return this;
  262. };
  263. // FancySelect
  264. UI.FancySelect = function () {
  265. UI.Element.call( this );
  266. var scope = this;
  267. var dom = document.createElement( 'div' );
  268. dom.className = 'FancySelect';
  269. dom.tabIndex = 0; // keyup event is ignored without setting tabIndex
  270. // Broadcast for object selection after arrow navigation
  271. var changeEvent = document.createEvent('HTMLEvents');
  272. changeEvent.initEvent( 'change', true, true );
  273. // Prevent native scroll behavior
  274. dom.addEventListener( 'keydown', function (event) {
  275. switch ( event.keyCode ) {
  276. case 38: // up
  277. case 40: // down
  278. event.preventDefault();
  279. event.stopPropagation();
  280. break;
  281. }
  282. }, false);
  283. // Keybindings to support arrow navigation
  284. dom.addEventListener( 'keyup', function (event) {
  285. switch ( event.keyCode ) {
  286. case 38: // up
  287. case 40: // down
  288. scope.selectedIndex += ( event.keyCode == 38 ) ? -1 : 1;
  289. if ( scope.selectedIndex >= 0 && scope.selectedIndex < scope.options.length ) {
  290. // Highlight selected dom elem and scroll parent if needed
  291. scope.setValue( scope.options[ scope.selectedIndex ].value );
  292. scope.dom.dispatchEvent( changeEvent );
  293. }
  294. break;
  295. }
  296. }, false);
  297. this.dom = dom;
  298. this.options = [];
  299. this.selectedIndex = -1;
  300. this.selectedValue = null;
  301. return this;
  302. };
  303. UI.FancySelect.prototype = Object.create( UI.Element.prototype );
  304. UI.FancySelect.prototype.setOptions = function ( options ) {
  305. var scope = this;
  306. var changeEvent = document.createEvent( 'HTMLEvents' );
  307. changeEvent.initEvent( 'change', true, true );
  308. while ( scope.dom.children.length > 0 ) {
  309. scope.dom.removeChild( scope.dom.firstChild );
  310. }
  311. scope.options = [];
  312. for ( var i = 0; i < options.length; i ++ ) {
  313. var option = options[ i ];
  314. var div = document.createElement( 'div' );
  315. div.className = 'option';
  316. div.innerHTML = option.html;
  317. div.value = option.value;
  318. scope.dom.appendChild( div );
  319. scope.options.push( div );
  320. div.addEventListener( 'click', function ( event ) {
  321. scope.setValue( this.value );
  322. scope.dom.dispatchEvent( changeEvent );
  323. }, false );
  324. }
  325. return scope;
  326. };
  327. UI.FancySelect.prototype.getValue = function () {
  328. return this.selectedValue;
  329. };
  330. UI.FancySelect.prototype.setValue = function ( value ) {
  331. for ( var i = 0; i < this.options.length; i ++ ) {
  332. var element = this.options[ i ];
  333. if ( element.value === value ) {
  334. element.classList.add( 'active' );
  335. // scroll into view
  336. var y = element.offsetTop - this.dom.offsetTop;
  337. var bottomY = y + element.offsetHeight;
  338. var minScroll = bottomY - this.dom.offsetHeight;
  339. if ( this.dom.scrollTop > y ) {
  340. this.dom.scrollTop = y
  341. } else if ( this.dom.scrollTop < minScroll ) {
  342. this.dom.scrollTop = minScroll;
  343. }
  344. this.selectedIndex = i;
  345. } else {
  346. element.classList.remove( 'active' );
  347. }
  348. }
  349. this.selectedValue = value;
  350. return this;
  351. };
  352. // Checkbox
  353. UI.Checkbox = function ( boolean ) {
  354. UI.Element.call( this );
  355. var scope = this;
  356. var dom = document.createElement( 'input' );
  357. dom.className = 'Checkbox';
  358. dom.type = 'checkbox';
  359. this.dom = dom;
  360. this.setValue( boolean );
  361. return this;
  362. };
  363. UI.Checkbox.prototype = Object.create( UI.Element.prototype );
  364. UI.Checkbox.prototype.getValue = function () {
  365. return this.dom.checked;
  366. };
  367. UI.Checkbox.prototype.setValue = function ( value ) {
  368. if ( value !== undefined ) {
  369. this.dom.checked = value;
  370. }
  371. return this;
  372. };
  373. // Color
  374. UI.Color = function () {
  375. UI.Element.call( this );
  376. var scope = this;
  377. var dom = document.createElement( 'input' );
  378. dom.className = 'Color';
  379. dom.style.width = '64px';
  380. dom.style.height = '16px';
  381. dom.style.border = '0px';
  382. dom.style.padding = '0px';
  383. dom.style.backgroundColor = 'transparent';
  384. try {
  385. dom.type = 'color';
  386. dom.value = '#ffffff';
  387. } catch ( exception ) {}
  388. this.dom = dom;
  389. return this;
  390. };
  391. UI.Color.prototype = Object.create( UI.Element.prototype );
  392. UI.Color.prototype.getValue = function () {
  393. return this.dom.value;
  394. };
  395. UI.Color.prototype.getHexValue = function () {
  396. return parseInt( this.dom.value.substr( 1 ), 16 );
  397. };
  398. UI.Color.prototype.setValue = function ( value ) {
  399. this.dom.value = value;
  400. return this;
  401. };
  402. UI.Color.prototype.setHexValue = function ( hex ) {
  403. this.dom.value = "#" + ( '000000' + hex.toString( 16 ) ).slice( -6 );
  404. return this;
  405. };
  406. // Number
  407. UI.Number = function ( number ) {
  408. UI.Element.call( this );
  409. var scope = this;
  410. var dom = document.createElement( 'input' );
  411. dom.className = 'Number';
  412. dom.value = '0.00';
  413. dom.addEventListener( 'keydown', function ( event ) {
  414. event.stopPropagation();
  415. if ( event.keyCode === 13 ) dom.blur();
  416. }, false );
  417. this.min = - Infinity;
  418. this.max = Infinity;
  419. this.precision = 2;
  420. this.step = 1;
  421. this.dom = dom;
  422. this.setValue( number );
  423. var changeEvent = document.createEvent( 'HTMLEvents' );
  424. changeEvent.initEvent( 'change', true, true );
  425. var distance = 0;
  426. var onMouseDownValue = 0;
  427. var pointer = new THREE.Vector2();
  428. var prevPointer = new THREE.Vector2();
  429. var onMouseDown = function ( event ) {
  430. event.preventDefault();
  431. distance = 0;
  432. onMouseDownValue = parseFloat( dom.value );
  433. prevPointer.set( event.clientX, event.clientY );
  434. document.addEventListener( 'mousemove', onMouseMove, false );
  435. document.addEventListener( 'mouseup', onMouseUp, false );
  436. };
  437. var onMouseMove = function ( event ) {
  438. var currentValue = dom.value;
  439. pointer.set( event.clientX, event.clientY );
  440. distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
  441. var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  442. dom.value = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( scope.precision );
  443. if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
  444. prevPointer.set( event.clientX, event.clientY );
  445. };
  446. var onMouseUp = function ( event ) {
  447. document.removeEventListener( 'mousemove', onMouseMove, false );
  448. document.removeEventListener( 'mouseup', onMouseUp, false );
  449. if ( Math.abs( distance ) < 2 ) {
  450. dom.focus();
  451. dom.select();
  452. }
  453. };
  454. var onChange = function ( event ) {
  455. var value = 0;
  456. try {
  457. value = eval( dom.value );
  458. } catch ( error ) {
  459. console.error( error.message );
  460. }
  461. dom.value = parseFloat( value );
  462. };
  463. var onFocus = function ( event ) {
  464. dom.style.backgroundColor = '';
  465. dom.style.borderColor = '#ccc';
  466. dom.style.cursor = '';
  467. };
  468. var onBlur = function ( event ) {
  469. dom.style.backgroundColor = 'transparent';
  470. dom.style.borderColor = 'transparent';
  471. dom.style.cursor = 'col-resize';
  472. };
  473. dom.addEventListener( 'mousedown', onMouseDown, false );
  474. dom.addEventListener( 'change', onChange, false );
  475. dom.addEventListener( 'focus', onFocus, false );
  476. dom.addEventListener( 'blur', onBlur, false );
  477. return this;
  478. };
  479. UI.Number.prototype = Object.create( UI.Element.prototype );
  480. UI.Number.prototype.getValue = function () {
  481. return parseFloat( this.dom.value );
  482. };
  483. UI.Number.prototype.setValue = function ( value ) {
  484. if ( value !== undefined ) {
  485. this.dom.value = value.toFixed( this.precision );
  486. }
  487. return this;
  488. };
  489. UI.Number.prototype.setRange = function ( min, max ) {
  490. this.min = min;
  491. this.max = max;
  492. return this;
  493. };
  494. UI.Number.prototype.setPrecision = function ( precision ) {
  495. this.precision = precision;
  496. return this;
  497. };
  498. // Integer
  499. UI.Integer = function ( number ) {
  500. UI.Element.call( this );
  501. var scope = this;
  502. var dom = document.createElement( 'input' );
  503. dom.className = 'Number';
  504. dom.value = '0.00';
  505. dom.addEventListener( 'keydown', function ( event ) {
  506. event.stopPropagation();
  507. }, false );
  508. this.min = - Infinity;
  509. this.max = Infinity;
  510. this.step = 1;
  511. this.dom = dom;
  512. this.setValue( number );
  513. var changeEvent = document.createEvent( 'HTMLEvents' );
  514. changeEvent.initEvent( 'change', true, true );
  515. var distance = 0;
  516. var onMouseDownValue = 0;
  517. var pointer = new THREE.Vector2();
  518. var prevPointer = new THREE.Vector2();
  519. var onMouseDown = function ( event ) {
  520. event.preventDefault();
  521. distance = 0;
  522. onMouseDownValue = parseFloat( dom.value );
  523. prevPointer.set( event.clientX, event.clientY );
  524. document.addEventListener( 'mousemove', onMouseMove, false );
  525. document.addEventListener( 'mouseup', onMouseUp, false );
  526. };
  527. var onMouseMove = function ( event ) {
  528. var currentValue = dom.value;
  529. pointer.set( event.clientX, event.clientY );
  530. distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
  531. var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  532. dom.value = Math.min( scope.max, Math.max( scope.min, number ) ) | 0;
  533. if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
  534. prevPointer.set( event.clientX, event.clientY );
  535. };
  536. var onMouseUp = function ( event ) {
  537. document.removeEventListener( 'mousemove', onMouseMove, false );
  538. document.removeEventListener( 'mouseup', onMouseUp, false );
  539. if ( Math.abs( distance ) < 2 ) {
  540. dom.focus();
  541. dom.select();
  542. }
  543. };
  544. var onChange = function ( event ) {
  545. var value = 0;
  546. try {
  547. value = eval( dom.value );
  548. } catch ( error ) {
  549. console.error( error.message );
  550. }
  551. dom.value = parseInt( value );
  552. };
  553. var onFocus = function ( event ) {
  554. dom.style.backgroundColor = '';
  555. dom.style.borderColor = '#ccc';
  556. dom.style.cursor = '';
  557. };
  558. var onBlur = function ( event ) {
  559. dom.style.backgroundColor = 'transparent';
  560. dom.style.borderColor = 'transparent';
  561. dom.style.cursor = 'col-resize';
  562. };
  563. dom.addEventListener( 'mousedown', onMouseDown, false );
  564. dom.addEventListener( 'change', onChange, false );
  565. dom.addEventListener( 'focus', onFocus, false );
  566. dom.addEventListener( 'blur', onBlur, false );
  567. return this;
  568. };
  569. UI.Integer.prototype = Object.create( UI.Element.prototype );
  570. UI.Integer.prototype.getValue = function () {
  571. return parseInt( this.dom.value );
  572. };
  573. UI.Integer.prototype.setValue = function ( value ) {
  574. if ( value !== undefined ) {
  575. this.dom.value = value | 0;
  576. }
  577. return this;
  578. };
  579. UI.Integer.prototype.setRange = function ( min, max ) {
  580. this.min = min;
  581. this.max = max;
  582. return this;
  583. };
  584. // Break
  585. UI.Break = function () {
  586. UI.Element.call( this );
  587. var dom = document.createElement( 'br' );
  588. dom.className = 'Break';
  589. this.dom = dom;
  590. return this;
  591. };
  592. UI.Break.prototype = Object.create( UI.Element.prototype );
  593. // HorizontalRule
  594. UI.HorizontalRule = function () {
  595. UI.Element.call( this );
  596. var dom = document.createElement( 'hr' );
  597. dom.className = 'HorizontalRule';
  598. this.dom = dom;
  599. return this;
  600. };
  601. UI.HorizontalRule.prototype = Object.create( UI.Element.prototype );
  602. // Button
  603. UI.Button = function ( value ) {
  604. UI.Element.call( this );
  605. var scope = this;
  606. var dom = document.createElement( 'button' );
  607. dom.className = 'Button';
  608. this.dom = dom;
  609. this.dom.textContent = value;
  610. return this;
  611. };
  612. UI.Button.prototype = Object.create( UI.Element.prototype );
  613. UI.Button.prototype.setLabel = function ( value ) {
  614. this.dom.textContent = value;
  615. return this;
  616. };
  617. // Dialog
  618. UI.Dialog = function ( value ) {
  619. var scope = this;
  620. var dom = document.createElement( 'dialog' );
  621. if ( dom.showModal === undefined ) {
  622. // fallback
  623. dom = document.createElement( 'div' );
  624. dom.style.display = 'none';
  625. dom.showModal = function () {
  626. dom.style.position = 'absolute';
  627. dom.style.left = '100px';
  628. dom.style.top = '100px';
  629. dom.style.zIndex = 1;
  630. dom.style.display = '';
  631. };
  632. }
  633. dom.className = 'Dialog';
  634. this.dom = dom;
  635. return this;
  636. };
  637. UI.Dialog.prototype = Object.create( UI.Panel.prototype );
  638. UI.Dialog.prototype.showModal = function () {
  639. this.dom.showModal();
  640. return this;
  641. };