How to reload jquery dropkick object

后端 未结 6 976
执念已碎
执念已碎 2021-02-08 16:39

Im using a simple select list and the jquery.dropkick library to make it beautiful. Now i want to change that dropkick content after the corresponding select element has been ch

6条回答
  •  醉话见心
    2021-02-08 17:22

    I encountered the same problem, I made some patching to the jquery-dropkick-1.0.0 script to solve this problem. I added a forceSyncWithSelect method to the dropkick object.

    Here's a list of changes I made:

    • add support for tag
    • add autoWidth settings to leave width to css
    • add method for open, close, forceSyncWithSelect and isDropkicked
    • keep default tabindex 0
    • add optgroup class option with the data-dkgroupclass attribute on optgroup element
    • fix forceSyncWithSelect method if value appear multiple of time, take the first occurrence only
    • toggle on click on the menu selection
    • prevent IE from closing the menu on scroll bar interaction (a blur event is launched on scroll bar interaction, this behavior is so wrong)

    You may not want all those change but you can make a diff patch and take what you need (would be glad if you let the change log or add the source of it into the header, I want to propose those changes to Jamie Lottering, but I need to make a git hub account to do so.

    /**
     * DropKick
     *
     * Highly customizable  element that gets dropkicked
        lists = [],
    
        // Convenience keys for keyboard navigation
        keyMap = {
            'left': 37,
            'up': 38,
            'right': 39,
            'down': 40,
            'enter': 13
        },
    
        // HTML template for the dropdowns
        dropdownTemplate = [
          '
    ', '', '{{ label }}', '', '
    ', '
      ', '
    ', '
    ', '
    ' ].join(''), // HTML template for dropdown options optionTemplate = '
  • {{ text }}
  • ', optionGroupTemplate = '
  • {{ text }}
  • ', // Some nice default values defaults = { startSpeed: 1000, // I recommend a high value here, I feel it makes the changes less noticeable to the user theme: false, change: false, autoWidth: true }, // Make sure we only bind keydown on the document once keysBound = false ; // Called by using $('foo').dropkick(); methods.init = function (settings) { settings = $.extend({}, defaults, settings); return this.each(function () { var // The current list and place our new one in front of it $select.before($dk); // Update the reference to $dk $dk = $('#dk_container_' + id).fadeIn(settings.startSpeed); // Save the current theme theme = settings.theme ? settings.theme : 'default'; $dk.addClass('dk_theme_' + theme); data.theme = theme; // Save the updated $dk reference into our data object data.$dk = $dk; // Save the dropkick data onto the
    提交评论

提交回复
热议问题