2
0

ui.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. '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.dom = dom;
  374. this.setValue( number );
  375. var changeEvent = document.createEvent( 'HTMLEvents' );
  376. changeEvent.initEvent( 'change', true, true );
  377. var distance = 0;
  378. var onMouseDownValue = 0;
  379. var pointer = [ 0, 0 ];
  380. var prevPointer = [ 0, 0 ];
  381. function onMouseDown( event ) {
  382. event.preventDefault();
  383. distance = 0;
  384. onMouseDownValue = scope.value;
  385. prevPointer = [ event.clientX, event.clientY ];
  386. document.addEventListener( 'mousemove', onMouseMove, false );
  387. document.addEventListener( 'mouseup', onMouseUp, false );
  388. }
  389. function onMouseMove( event ) {
  390. var currentValue = scope.value;
  391. pointer = [ event.clientX, event.clientY ];
  392. distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
  393. var value = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  394. value = Math.min( scope.max, Math.max( scope.min, value ) );
  395. if ( currentValue !== value ) {
  396. scope.setValue( value );
  397. dom.dispatchEvent( changeEvent );
  398. }
  399. prevPointer = [ event.clientX, event.clientY ];
  400. }
  401. function onMouseUp( event ) {
  402. document.removeEventListener( 'mousemove', onMouseMove, false );
  403. document.removeEventListener( 'mouseup', onMouseUp, false );
  404. if ( Math.abs( distance ) < 2 ) {
  405. dom.focus();
  406. dom.select();
  407. }
  408. }
  409. function onChange( event ) {
  410. var value = 0;
  411. try {
  412. value = eval( dom.value );
  413. } catch ( error ) {
  414. console.error( error.message );
  415. }
  416. scope.setValue( parseFloat( value ) );
  417. }
  418. function onFocus( event ) {
  419. dom.style.backgroundColor = '';
  420. dom.style.cursor = '';
  421. }
  422. function onBlur( event ) {
  423. dom.style.backgroundColor = 'transparent';
  424. dom.style.cursor = 'col-resize';
  425. }
  426. onBlur();
  427. dom.addEventListener( 'mousedown', onMouseDown, false );
  428. dom.addEventListener( 'change', onChange, false );
  429. dom.addEventListener( 'focus', onFocus, false );
  430. dom.addEventListener( 'blur', onBlur, false );
  431. return this;
  432. };
  433. UI.Number.prototype = Object.create( UI.Element.prototype );
  434. UI.Number.prototype.constructor = UI.Number;
  435. UI.Number.prototype.getValue = function () {
  436. return this.value;
  437. };
  438. UI.Number.prototype.setValue = function ( value ) {
  439. if ( value !== undefined ) {
  440. this.value = value;
  441. this.dom.value = value.toFixed( this.precision );
  442. }
  443. return this;
  444. };
  445. UI.Number.prototype.setRange = function ( min, max ) {
  446. this.min = min;
  447. this.max = max;
  448. return this;
  449. };
  450. UI.Number.prototype.setPrecision = function ( precision ) {
  451. this.precision = precision;
  452. return this;
  453. };
  454. // Integer
  455. UI.Integer = function ( number ) {
  456. UI.Element.call( this );
  457. var scope = this;
  458. var dom = document.createElement( 'input' );
  459. dom.className = 'Number';
  460. dom.value = '0';
  461. dom.addEventListener( 'keydown', function ( event ) {
  462. event.stopPropagation();
  463. }, false );
  464. this.value = 0;
  465. this.min = - Infinity;
  466. this.max = Infinity;
  467. this.step = 1;
  468. this.dom = dom;
  469. this.setValue( number );
  470. var changeEvent = document.createEvent( 'HTMLEvents' );
  471. changeEvent.initEvent( 'change', true, true );
  472. var distance = 0;
  473. var onMouseDownValue = 0;
  474. var pointer = [ 0, 0 ];
  475. var prevPointer = [ 0, 0 ];
  476. function onMouseDown( event ) {
  477. event.preventDefault();
  478. distance = 0;
  479. onMouseDownValue = scope.value;
  480. prevPointer = [ event.clientX, event.clientY ];
  481. document.addEventListener( 'mousemove', onMouseMove, false );
  482. document.addEventListener( 'mouseup', onMouseUp, false );
  483. }
  484. function onMouseMove( event ) {
  485. var currentValue = scope.value;
  486. pointer = [ event.clientX, event.clientY ];
  487. distance += ( pointer[ 0 ] - prevPointer[ 0 ] ) - ( pointer[ 1 ] - prevPointer[ 1 ] );
  488. var value = onMouseDownValue + ( distance / ( event.shiftKey ? 5 : 50 ) ) * scope.step;
  489. value = Math.min( scope.max, Math.max( scope.min, value ) ) | 0;
  490. if ( currentValue !== value ) {
  491. scope.setValue( value );
  492. dom.dispatchEvent( changeEvent );
  493. }
  494. prevPointer = [ event.clientX, event.clientY ];
  495. }
  496. function onMouseUp( event ) {
  497. document.removeEventListener( 'mousemove', onMouseMove, false );
  498. document.removeEventListener( 'mouseup', onMouseUp, false );
  499. if ( Math.abs( distance ) < 2 ) {
  500. dom.focus();
  501. dom.select();
  502. }
  503. }
  504. function onChange( event ) {
  505. var value = 0;
  506. try {
  507. value = eval( dom.value );
  508. } catch ( error ) {
  509. console.error( error.message );
  510. }
  511. scope.setValue( value );
  512. }
  513. function onFocus( event ) {
  514. dom.style.backgroundColor = '';
  515. dom.style.cursor = '';
  516. }
  517. function onBlur( event ) {
  518. dom.style.backgroundColor = 'transparent';
  519. dom.style.cursor = 'col-resize';
  520. }
  521. onBlur();
  522. dom.addEventListener( 'mousedown', onMouseDown, false );
  523. dom.addEventListener( 'change', onChange, false );
  524. dom.addEventListener( 'focus', onFocus, false );
  525. dom.addEventListener( 'blur', onBlur, false );
  526. return this;
  527. };
  528. UI.Integer.prototype = Object.create( UI.Element.prototype );
  529. UI.Integer.prototype.constructor = UI.Integer;
  530. UI.Integer.prototype.getValue = function () {
  531. return this.value;
  532. };
  533. UI.Integer.prototype.setValue = function ( value ) {
  534. if ( value !== undefined ) {
  535. this.value = value | 0;
  536. this.dom.value = value | 0;
  537. }
  538. return this;
  539. };
  540. UI.Integer.prototype.setRange = function ( min, max ) {
  541. this.min = min;
  542. this.max = max;
  543. return this;
  544. };
  545. // Break
  546. UI.Break = function () {
  547. UI.Element.call( this );
  548. var dom = document.createElement( 'br' );
  549. dom.className = 'Break';
  550. this.dom = dom;
  551. return this;
  552. };
  553. UI.Break.prototype = Object.create( UI.Element.prototype );
  554. UI.Break.prototype.constructor = UI.Break;
  555. // HorizontalRule
  556. UI.HorizontalRule = function () {
  557. UI.Element.call( this );
  558. var dom = document.createElement( 'hr' );
  559. dom.className = 'HorizontalRule';
  560. this.dom = dom;
  561. return this;
  562. };
  563. UI.HorizontalRule.prototype = Object.create( UI.Element.prototype );
  564. UI.HorizontalRule.prototype.constructor = UI.HorizontalRule;
  565. // Button
  566. UI.Button = function ( value ) {
  567. UI.Element.call( this );
  568. var scope = this;
  569. var dom = document.createElement( 'button' );
  570. dom.className = 'Button';
  571. this.dom = dom;
  572. this.dom.textContent = value;
  573. return this;
  574. };
  575. UI.Button.prototype = Object.create( UI.Element.prototype );
  576. UI.Button.prototype.constructor = UI.Button;
  577. UI.Button.prototype.setLabel = function ( value ) {
  578. this.dom.textContent = value;
  579. return this;
  580. };
  581. // Modal
  582. UI.Modal = function ( value ) {
  583. var scope = this;
  584. var dom = document.createElement( 'div' );
  585. dom.style.position = 'absolute';
  586. dom.style.width = '100%';
  587. dom.style.height = '100%';
  588. dom.style.backgroundColor = 'rgba(0,0,0,0.5)';
  589. dom.style.display = 'none';
  590. dom.style.alignItems = 'center';
  591. dom.style.justifyContent = 'center';
  592. dom.addEventListener( 'click', function ( event ) {
  593. scope.hide();
  594. } );
  595. this.dom = dom;
  596. this.container = new UI.Panel();
  597. this.container.dom.style.width = '200px';
  598. this.container.dom.style.padding = '20px';
  599. this.container.dom.style.backgroundColor = '#ffffff';
  600. this.container.dom.style.boxShadow = '0px 5px 10px rgba(0,0,0,0.5)';
  601. this.add( this.container );
  602. return this;
  603. };
  604. UI.Modal.prototype = Object.create( UI.Element.prototype );
  605. UI.Modal.prototype.constructor = UI.Modal;
  606. UI.Modal.prototype.show = function ( content ) {
  607. this.container.clear();
  608. this.container.add( content );
  609. this.dom.style.display = 'flex';
  610. return this;
  611. };
  612. UI.Modal.prototype.hide = function () {
  613. this.dom.style.display = 'none';
  614. return this;
  615. };