How to extend a jquery ui widget ? (1.7)

前端 未结 6 1382
终归单人心
终归单人心 2020-12-08 00:40

I would like to create a custom version of the sortable widget. I have been searching for documentation, but could not find something really accurate. The best information I

6条回答
  •  佛祖请我去吃肉
    2020-12-08 01:30

    After several tries, I finally found out how to do this easily :

    $.widget("ui.customsortable", $.extend({}, $.ui.sortable.prototype, {
    
      _init: function(){
        this.element.data('sortable', this.element.data('customsortable'));
        return $.ui.sortable.prototype._init.apply(this, arguments);
      }
    
      // Override other methods here.
    
    }));
    
    $.ui.customsortable.defaults = $.extend({}, $.ui.sortable.defaults);
    

    The key is to copy data from your custom widget to the original one. Don't forget to use $.ui.sortable.prototype.[overriden method].apply(this, arguments); in each overriden method.

    Holly crap !

提交回复
热议问题