Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve compatibility with Jquery >= 3.0 #227

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion selectable/static/selectable/js/jquery.dj.selectable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@
* BSD License
*
*/
function positionDropdown(input, ul) {
//Given an input element and a ul, positions the ul dropdown appropriately
//Uses native javascript where necessary to fix compatibility with Jquery 3.0 and newer
var selectRect = document.getElementById($(input.element[0]).attr('id')).getBoundingClientRect();
//Account for scrollbar position
var left = parseFloat(selectRect.left) + parseFloat(window.scrollX);
var top = parseFloat(selectRect.bottom) + parseFloat(window.scrollY);
//Use element style attribute to set the position
var style = $(ul).attr('style')+ 'left:'+left+'px;' + 'top: '+top+'px;';
$(ul).attr('style', style);
}

(function ($) {

$.widget("ui.djselectable", $.ui.autocomplete, {
Expand Down Expand Up @@ -278,7 +290,8 @@
// size and position menu
ul.show();
this._resizeMenu();
ul.position($.extend({of: this.element}, this.options.position));
positionDropdown(this, ul); //Call function that uses native Javascript
//ul.position($.extend/({of: $(this).element}, $(this).position));
if (this.options.autoFocus) {
this.menu.next(new $.Event("mouseover"));
} else if (page) {
Expand Down