ui.js 19 KB

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