ui.js 18 KB

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