ui.js 19 KB

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