ui.js 19 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160
  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. value = String( value );
  256. if ( this.dom.value !== value ) {
  257. this.dom.value = value;
  258. }
  259. return this;
  260. };
  261. // FancySelect
  262. UI.FancySelect = function () {
  263. UI.Element.call( this );
  264. var scope = this;
  265. var dom = document.createElement( 'div' );
  266. dom.className = 'FancySelect';
  267. dom.tabIndex = 0; // keyup event is ignored without setting tabIndex
  268. // Broadcast for object selection after arrow navigation
  269. var changeEvent = document.createEvent('HTMLEvents');
  270. changeEvent.initEvent( 'change', true, true );
  271. // Prevent native scroll behavior
  272. dom.addEventListener( 'keydown', function (event) {
  273. switch ( event.keyCode ) {
  274. case 38: // up
  275. case 40: // down
  276. event.preventDefault();
  277. event.stopPropagation();
  278. break;
  279. }
  280. }, false);
  281. // Keybindings to support arrow navigation
  282. dom.addEventListener( 'keyup', function (event) {
  283. switch ( event.keyCode ) {
  284. case 38: // up
  285. case 40: // down
  286. scope.selectedIndex += ( event.keyCode == 38 ) ? -1 : 1;
  287. if ( scope.selectedIndex >= 0 && scope.selectedIndex < scope.options.length ) {
  288. // Highlight selected dom elem and scroll parent if needed
  289. scope.setValue( scope.options[ scope.selectedIndex ].value );
  290. scope.dom.dispatchEvent( changeEvent );
  291. }
  292. break;
  293. }
  294. }, false);
  295. this.dom = dom;
  296. this.options = [];
  297. this.selectedIndex = -1;
  298. this.selectedValue = null;
  299. return this;
  300. };
  301. UI.FancySelect.prototype = Object.create( UI.Element.prototype );
  302. UI.FancySelect.prototype.setOptions = function ( options ) {
  303. var scope = this;
  304. var changeEvent = document.createEvent( 'HTMLEvents' );
  305. changeEvent.initEvent( 'change', true, true );
  306. while ( scope.dom.children.length > 0 ) {
  307. scope.dom.removeChild( scope.dom.firstChild );
  308. }
  309. scope.options = [];
  310. for ( var i = 0; i < options.length; i ++ ) {
  311. var option = options[ i ];
  312. var div = document.createElement( 'div' );
  313. div.className = 'option';
  314. div.innerHTML = option.html;
  315. div.value = option.value;
  316. scope.dom.appendChild( div );
  317. scope.options.push( div );
  318. div.addEventListener( 'click', function ( event ) {
  319. scope.setValue( this.value );
  320. scope.dom.dispatchEvent( changeEvent );
  321. }, false );
  322. }
  323. return scope;
  324. };
  325. UI.FancySelect.prototype.getValue = function () {
  326. return this.selectedValue;
  327. };
  328. UI.FancySelect.prototype.setValue = function ( value ) {
  329. for ( var i = 0; i < this.options.length; i ++ ) {
  330. var element = this.options[ i ];
  331. if ( element.value === value ) {
  332. element.classList.add( 'active' );
  333. // scroll into view
  334. var y = element.offsetTop - this.dom.offsetTop;
  335. var bottomY = y + element.offsetHeight;
  336. var minScroll = bottomY - this.dom.offsetHeight;
  337. if ( this.dom.scrollTop > y ) {
  338. this.dom.scrollTop = y
  339. } else if ( this.dom.scrollTop < minScroll ) {
  340. this.dom.scrollTop = minScroll;
  341. }
  342. this.selectedIndex = i;
  343. } else {
  344. element.classList.remove( 'active' );
  345. }
  346. }
  347. this.selectedValue = value;
  348. return this;
  349. };
  350. // Checkbox
  351. UI.Checkbox = function ( boolean ) {
  352. UI.Element.call( this );
  353. var scope = this;
  354. var dom = document.createElement( 'input' );
  355. dom.className = 'Checkbox';
  356. dom.type = 'checkbox';
  357. this.dom = dom;
  358. this.setValue( boolean );
  359. return this;
  360. };
  361. UI.Checkbox.prototype = Object.create( UI.Element.prototype );
  362. UI.Checkbox.prototype.getValue = function () {
  363. return this.dom.checked;
  364. };
  365. UI.Checkbox.prototype.setValue = function ( value ) {
  366. if ( value !== undefined ) {
  367. this.dom.checked = value;
  368. }
  369. return this;
  370. };
  371. // Color
  372. UI.Color = function () {
  373. UI.Element.call( this );
  374. var scope = this;
  375. var dom = document.createElement( 'input' );
  376. dom.className = 'Color';
  377. dom.style.width = '64px';
  378. dom.style.height = '16px';
  379. dom.style.border = '0px';
  380. dom.style.padding = '0px';
  381. dom.style.backgroundColor = 'transparent';
  382. try {
  383. dom.type = 'color';
  384. dom.value = '#ffffff';
  385. } catch ( exception ) {}
  386. this.dom = dom;
  387. return this;
  388. };
  389. UI.Color.prototype = Object.create( UI.Element.prototype );
  390. UI.Color.prototype.getValue = function () {
  391. return this.dom.value;
  392. };
  393. UI.Color.prototype.getHexValue = function () {
  394. return parseInt( this.dom.value.substr( 1 ), 16 );
  395. };
  396. UI.Color.prototype.setValue = function ( value ) {
  397. this.dom.value = value;
  398. return this;
  399. };
  400. UI.Color.prototype.setHexValue = function ( hex ) {
  401. this.dom.value = "#" + ( '000000' + hex.toString( 16 ) ).slice( -6 );
  402. return this;
  403. };
  404. // Number
  405. UI.Number = function ( number ) {
  406. UI.Element.call( this );
  407. var scope = this;
  408. var dom = document.createElement( 'input' );
  409. dom.className = 'Number';
  410. dom.value = '0.00';
  411. dom.addEventListener( 'keydown', function ( event ) {
  412. event.stopPropagation();
  413. if ( event.keyCode === 13 ) dom.blur();
  414. }, false );
  415. this.min = - Infinity;
  416. this.max = Infinity;
  417. this.precision = 2;
  418. this.step = 1;
  419. this.dom = dom;
  420. this.setValue( number );
  421. var changeEvent = document.createEvent( 'HTMLEvents' );
  422. changeEvent.initEvent( 'change', true, true );
  423. var distance = 0;
  424. var onMouseDownValue = 0;
  425. var pointer = new THREE.Vector2();
  426. var prevPointer = new THREE.Vector2();
  427. var onMouseDown = function ( event ) {
  428. event.preventDefault();
  429. distance = 0;
  430. onMouseDownValue = parseFloat( dom.value );
  431. prevPointer.set( event.clientX, event.clientY );
  432. document.addEventListener( 'mousemove', onMouseMove, false );
  433. document.addEventListener( 'mouseup', onMouseUp, false );
  434. };
  435. var onMouseMove = function ( event ) {
  436. var currentValue = dom.value;
  437. pointer.set( event.clientX, event.clientY );
  438. distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
  439. var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  440. dom.value = Math.min( scope.max, Math.max( scope.min, number ) ).toFixed( scope.precision );
  441. if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
  442. prevPointer.set( event.clientX, event.clientY );
  443. };
  444. var onMouseUp = function ( event ) {
  445. document.removeEventListener( 'mousemove', onMouseMove, false );
  446. document.removeEventListener( 'mouseup', onMouseUp, false );
  447. if ( Math.abs( distance ) < 2 ) {
  448. dom.focus();
  449. dom.select();
  450. }
  451. };
  452. var onChange = function ( event ) {
  453. var number = parseFloat( dom.value );
  454. dom.value = isNaN( number ) === false ? number : 0;
  455. };
  456. var onFocus = function ( event ) {
  457. dom.style.backgroundColor = '';
  458. dom.style.borderColor = '#ccc';
  459. dom.style.cursor = '';
  460. };
  461. var onBlur = function ( event ) {
  462. dom.style.backgroundColor = 'transparent';
  463. dom.style.borderColor = 'transparent';
  464. dom.style.cursor = 'col-resize';
  465. };
  466. dom.addEventListener( 'mousedown', onMouseDown, false );
  467. dom.addEventListener( 'change', onChange, false );
  468. dom.addEventListener( 'focus', onFocus, false );
  469. dom.addEventListener( 'blur', onBlur, false );
  470. return this;
  471. };
  472. UI.Number.prototype = Object.create( UI.Element.prototype );
  473. UI.Number.prototype.getValue = function () {
  474. return parseFloat( this.dom.value );
  475. };
  476. UI.Number.prototype.setValue = function ( value ) {
  477. if ( value !== undefined ) {
  478. this.dom.value = value.toFixed( this.precision );
  479. }
  480. return this;
  481. };
  482. UI.Number.prototype.setRange = function ( min, max ) {
  483. this.min = min;
  484. this.max = max;
  485. return this;
  486. };
  487. UI.Number.prototype.setPrecision = function ( precision ) {
  488. this.precision = precision;
  489. return this;
  490. };
  491. // Integer
  492. UI.Integer = function ( number ) {
  493. UI.Element.call( this );
  494. var scope = this;
  495. var dom = document.createElement( 'input' );
  496. dom.className = 'Number';
  497. dom.value = '0.00';
  498. dom.addEventListener( 'keydown', function ( event ) {
  499. event.stopPropagation();
  500. }, false );
  501. this.min = - Infinity;
  502. this.max = Infinity;
  503. this.step = 1;
  504. this.dom = dom;
  505. this.setValue( number );
  506. var changeEvent = document.createEvent( 'HTMLEvents' );
  507. changeEvent.initEvent( 'change', true, true );
  508. var distance = 0;
  509. var onMouseDownValue = 0;
  510. var pointer = new THREE.Vector2();
  511. var prevPointer = new THREE.Vector2();
  512. var onMouseDown = function ( event ) {
  513. event.preventDefault();
  514. distance = 0;
  515. onMouseDownValue = parseFloat( dom.value );
  516. prevPointer.set( event.clientX, event.clientY );
  517. document.addEventListener( 'mousemove', onMouseMove, false );
  518. document.addEventListener( 'mouseup', onMouseUp, false );
  519. };
  520. var onMouseMove = function ( event ) {
  521. var currentValue = dom.value;
  522. pointer.set( event.clientX, event.clientY );
  523. distance += ( pointer.x - prevPointer.x ) - ( pointer.y - prevPointer.y );
  524. var number = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  525. dom.value = Math.min( scope.max, Math.max( scope.min, number ) ) | 0;
  526. if ( currentValue !== dom.value ) dom.dispatchEvent( changeEvent );
  527. prevPointer.set( event.clientX, event.clientY );
  528. };
  529. var onMouseUp = function ( event ) {
  530. document.removeEventListener( 'mousemove', onMouseMove, false );
  531. document.removeEventListener( 'mouseup', onMouseUp, false );
  532. if ( Math.abs( distance ) < 2 ) {
  533. dom.focus();
  534. dom.select();
  535. }
  536. };
  537. var onChange = function ( event ) {
  538. var number = parseInt( dom.value );
  539. if ( isNaN( number ) === false ) {
  540. dom.value = number;
  541. }
  542. };
  543. var onFocus = function ( event ) {
  544. dom.style.backgroundColor = '';
  545. dom.style.borderColor = '#ccc';
  546. dom.style.cursor = '';
  547. };
  548. var onBlur = function ( event ) {
  549. dom.style.backgroundColor = 'transparent';
  550. dom.style.borderColor = 'transparent';
  551. dom.style.cursor = 'col-resize';
  552. };
  553. dom.addEventListener( 'mousedown', onMouseDown, false );
  554. dom.addEventListener( 'change', onChange, false );
  555. dom.addEventListener( 'focus', onFocus, false );
  556. dom.addEventListener( 'blur', onBlur, false );
  557. return this;
  558. };
  559. UI.Integer.prototype = Object.create( UI.Element.prototype );
  560. UI.Integer.prototype.getValue = function () {
  561. return parseInt( this.dom.value );
  562. };
  563. UI.Integer.prototype.setValue = function ( value ) {
  564. if ( value !== undefined ) {
  565. this.dom.value = value | 0;
  566. }
  567. return this;
  568. };
  569. UI.Integer.prototype.setRange = function ( min, max ) {
  570. this.min = min;
  571. this.max = max;
  572. return this;
  573. };
  574. // Break
  575. UI.Break = function () {
  576. UI.Element.call( this );
  577. var dom = document.createElement( 'br' );
  578. dom.className = 'Break';
  579. this.dom = dom;
  580. return this;
  581. };
  582. UI.Break.prototype = Object.create( UI.Element.prototype );
  583. // HorizontalRule
  584. UI.HorizontalRule = function () {
  585. UI.Element.call( this );
  586. var dom = document.createElement( 'hr' );
  587. dom.className = 'HorizontalRule';
  588. this.dom = dom;
  589. return this;
  590. };
  591. UI.HorizontalRule.prototype = Object.create( UI.Element.prototype );
  592. // Button
  593. UI.Button = function ( value ) {
  594. UI.Element.call( this );
  595. var scope = this;
  596. var dom = document.createElement( 'button' );
  597. dom.className = 'Button';
  598. this.dom = dom;
  599. this.dom.textContent = value;
  600. return this;
  601. };
  602. UI.Button.prototype = Object.create( UI.Element.prototype );
  603. UI.Button.prototype.setLabel = function ( value ) {
  604. this.dom.textContent = value;
  605. return this;
  606. };
  607. // Dialog
  608. UI.Dialog = function ( value ) {
  609. var scope = this;
  610. var dom = document.createElement( 'dialog' );
  611. if ( dom.showModal === undefined ) {
  612. // fallback
  613. dom = document.createElement( 'div' );
  614. dom.style.display = 'none';
  615. dom.showModal = function () {
  616. dom.style.position = 'absolute';
  617. dom.style.left = '100px';
  618. dom.style.top = '100px';
  619. dom.style.zIndex = 1;
  620. dom.style.display = '';
  621. };
  622. }
  623. dom.className = 'Dialog';
  624. this.dom = dom;
  625. return this;
  626. };
  627. UI.Dialog.prototype = Object.create( UI.Panel.prototype );
  628. UI.Dialog.prototype.showModal = function () {
  629. this.dom.showModal();
  630. return this;
  631. };