dropdown.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* globals window */
  6. import Model from '../../../src/model';
  7. import Collection from '@ckeditor/ckeditor5-utils/src/collection';
  8. import createDropdown from '../../../src/dropdown/createdropdown';
  9. import createListDropdown from '../../../src/dropdown/list/createlistdropdown';
  10. import testUtils from '../../_utils/utils';
  11. const ui = testUtils.createTestUIView( {
  12. dropdown: '#dropdown',
  13. listDropdown: '#list-dropdown',
  14. dropdownShared: '#dropdown-shared',
  15. dropdownLabel: '#dropdown-label'
  16. } );
  17. function testEmpty() {
  18. const dropdownView = createDropdown( new Model( {
  19. label: 'Dropdown',
  20. isEnabled: true,
  21. isOn: false,
  22. withText: true
  23. } ) );
  24. ui.dropdown.add( dropdownView );
  25. dropdownView.panelView.element.innerHTML = 'Empty panel. There is no child view in this DropdownPanelView.';
  26. }
  27. function testList() {
  28. const collection = new Collection( { idProperty: 'label' } );
  29. [ '0.8em', '1em', '1.2em', '1.5em', '2.0em', '3.0em' ].forEach( font => {
  30. collection.add( new Model( {
  31. label: font,
  32. style: `font-size: ${ font }`
  33. } ) );
  34. } );
  35. const model = new Model( {
  36. label: 'ListDropdown',
  37. isEnabled: true,
  38. isOn: false,
  39. withText: true,
  40. items: collection
  41. } );
  42. const dropdownView = createListDropdown( model );
  43. dropdownView.on( 'execute', evt => {
  44. /* global console */
  45. console.log( 'List#execute:', evt.source.label );
  46. } );
  47. ui.listDropdown.add( dropdownView );
  48. window.listDropdownModel = model;
  49. window.listDropdownCollection = collection;
  50. window.Model = Model;
  51. }
  52. function testSharedModel() {
  53. const model = new Model( {
  54. label: 'Shared Model',
  55. isEnabled: true,
  56. isOn: false,
  57. withText: true
  58. } );
  59. const dropdownView1 = createDropdown( model );
  60. const dropdownView2 = createDropdown( model );
  61. ui.dropdownShared.add( dropdownView1 );
  62. ui.dropdownShared.add( dropdownView2 );
  63. dropdownView1.panelView.element.innerHTML = dropdownView2.panelView.element.innerHTML = 'Empty panel.';
  64. }
  65. function testLongLabel() {
  66. const dropdownView = createDropdown( new Model( {
  67. label: 'Dropdown with a very long label',
  68. isEnabled: true,
  69. isOn: false,
  70. withText: true
  71. } ) );
  72. ui.dropdownLabel.add( dropdownView );
  73. dropdownView.panelView.element.innerHTML = 'Empty panel. There is no child view in this DropdownPanelView.';
  74. }
  75. testEmpty();
  76. testList();
  77. testSharedModel();
  78. testLongLabel();