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