ui.js 18 KB

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