ui.js 19 KB

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