sonata_front_js_base_3.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. jQuery(document).ready(function() {
  2. SonataCore.setup_select2(document);
  3. });
  4. var SonataCore = {
  5. setup_select2: function(subject) {
  6. jQuery('select:not([data-sonata-select2="false"])', subject).each(function() {
  7. var select = $(this);
  8. var allowClearEnabled = false;
  9. if (select.find('option[value=""]').length) {
  10. allowClearEnabled = true;
  11. }
  12. if (select.attr('data-sonata-select2-allow-clear')==='true') {
  13. allowClearEnabled = true;
  14. } else if (select.attr('data-sonata-select2-allow-clear')==='false') {
  15. allowClearEnabled = false;
  16. }
  17. select.select2({
  18. width: 'resolve',
  19. minimumResultsForSearch: 10,
  20. allowClear: allowClearEnabled
  21. });
  22. var popover = select.data('popover');
  23. if (undefined !== popover) {
  24. select
  25. .select2('container')
  26. .popover(popover.options)
  27. ;
  28. }
  29. });
  30. }
  31. };