(function($){
    $.fn.extend({
        '_data': $.fn.data,
        'data' : function( key, value ) {
            if ( typeof key === "undefined" && this.length ) {
                return jQuery.data( this[0] );
            } else if ( typeof key === "object" ) {
                return this.each(function() {
                    jQuery.data( this, key );
                });
            }
            var retValue;
            retValue = $.fn._data(key, value);
            if ('undefined' == (typeof retValue) || retValue.length == 0) {
                var nakedElem = this.get(0);
                if (nakedElem.hasOwnProperty('dataset')) {
                    if ('undefined' != (typeof nakedElem.dataset[key])) {
                        retValue = nakedElem.dataset[key];
                    }
                } else {
                    retValue = this.attr('data-'+key);
                }
            }
            return retValue;
        }
    });
})(jQuery);
