diff --git a/share/static/js/libs/jquery-compat.js b/share/static/js/libs/jquery-compat.js index a191d0210b..d22f144746 100644 --- a/share/static/js/libs/jquery-compat.js +++ b/share/static/js/libs/jquery-compat.js @@ -20,13 +20,48 @@ if ( matched.browser ) { jQuery.browser.version = matched.version; } -(function($) { - var $old = $; - window.$ = window.jQuery = function(selector, context) { - if (selector === '#' || selector === '') { - console.warn('jquery # override'); - return $old([]); +(function ($) { + + const booleanAttrs = { + checked: true, + selected: true, + disabled: true, + readonly: true, + multiple: true + }; + + var oldInit = $.fn.init; + + $.fn.init = function (selector, context, root) { + + if (typeof selector === 'string') { + if (selector === '#' || selector.trim() === '') { + console.warn('jquery # override', new Error().stack); + return oldInit.call(this, [], context, root); + } + } + + return oldInit.call(this, selector, context, root); + }; + + $.fn.init.prototype = $.fn; + + const oldAttr = $.fn.attr; + + $.fn.attr = function (name, value) { + + if (booleanAttrs[name]) { + + // getter + if (value === undefined) { + return this.prop(name) ? name : undefined; + } + + // setter + return this.prop(name, !!value); } - return $old(selector, context); + + return oldAttr.apply(this, arguments); }; + })(jQuery); \ No newline at end of file