$(function() { $.widget( "custom.iconselectmenu", $.ui.selectmenu, { _create: function() { this._super(); this._setTabIndex(); }, _setTabIndex: function() { this.button.attr( "tabindex", this.options.disabled ? -1 : this.element.attr( "tabindex" ) || 0 ); }, _setOption: function( key, value ) { this._super( key, value ); if ( key === "disabled" ) { this._setTabIndex(); } }, _renderItem: function( ul, item ) { var li = $( "
  • ", { 'text': item.label, 'class': (item.element.attr( "data-class" ) ? 'damx-icon' : ' no-icon') } ); if ( item.disabled ) { li.addClass( "ui-state-disabled" ); } $( "", { style: item.element.attr( "data-style" ), "class": "ui-icon " + (item.element.attr( "data-class" ) || ' no-icon') }) .appendTo( li ); return li.appendTo( ul ); } }); jQuery.ui.autocomplete.prototype._resizeMenu = function () { var ul = this.menu.element; ul.outerWidth(this.element.outerWidth()); } }); $(document).ready( function() { $('body').append($('
    ', {id: 'damx-jqueryui-normal'})).append($('
    ', {id: 'damx-jqueryui-headline'})).append($('
    ', {id: 'damx-jqueryui-white'})); window.changeFunction = function(e,u){ var _t = e.target.dataset.change || 1; eval(_t); }; $('select.damx').iconselectmenu({width:'100%',appendTo:'#damx-jqueryui-normal',change:changeFunction}); $('.white select.damx').iconselectmenu({width:'100%',appendTo:'#damx-jqueryui-white',change:changeFunction}); $('.headline select.damx').iconselectmenu({width:'100%',appendTo:'#damx-jqueryui-headline',change:changeFunction}); $('.file-upload input').each( function() { $(this).change( function() { $('[for='+$(this).attr('id')+']').text(this.value); } ); } ); $('input.toggle').each( function() { this.toggle = function() { if ('true' == this.value || 'false' == this.value) this.value = 'true' == this.value ? 'false' : 'true'; else if (1 == this.value || 0 == this.value) this.value = 1 == this.value ? 0 : 1; } } ); var sortUpdateHelper = function(e, ui) {} var sortStartHelper = function(e, ui) { ui.item.addClass('active'); $('[data-toggle="tooltip"]').tooltip('destroy'); } var sortStopHelper = function(e, ui) { ui.item.removeClass('active'); $('[data-toggle="tooltip"]').tooltip('enable'); } var sortReceiveHelper = function(e, ui) { var ul = ui.item.parent('[data-id]'); if (!ui.sender.find('> li').length) { ui.sender.append('
  • '+ui.sender.data('on-empty')+'
  • '); } ul.find('> li.empty-row').remove(); ui.item.find('> [data-id]').val($(this).data('id')); console.log( $(this).data('id'), ui.item, ui.item.find('> [data-id]')); } $('ul.sortable').sortable({ start: sortStartHelper, stop: sortStopHelper, receive: sortReceiveHelper, update: sortUpdateHelper, items: '> li:not(.not-sortable)', placeholder: 'sortable-placeholder', connectWith: 'ul.sortable', handle: '.drag-handle:not(.disabled)', }); $('ul.sortable').each(function(){ if ( $(this).find('> li:not(.empty-row)').length === 0 ) { $(this).append('
  • '+$(this).data('on-empty')+'
  • '); } }); $('.replace-komma-with-dot').keyup( function( event ) { if (event.which == 110 || event.which == 188) { this.value = this.value.substr(0, this.value.length - 1) + '.'; } } ); $('[data-damx-tooltip]').each( function() { var $this = $(this); var $parent = $this.parent().addClass('has-damx-tooltip'); var $tooltip = $('
    ').text( $this.data('damx-tooltip') ).addClass('damx-tooltip'); $parent.append($tooltip); $tooltip.click( function() { $this.focus(); } ); } ); } );