ui.js 18 KB

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