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

Remove jQuery in Utils and Translation #6233

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/js/select2/translation.js
@@ -1,7 +1,6 @@
define([
'jquery',
'require'
], function ($, require) {
], function (require) {
function Translation (dict) {
this.dict = dict || {};
}
Expand All @@ -15,7 +14,7 @@ define([
};

Translation.prototype.extend = function (translation) {
this.dict = $.extend({}, translation.all(), this.dict);
this.dict = Object.assign({}, translation.all(), this.dict);
};

// Static functions
Expand Down
18 changes: 11 additions & 7 deletions src/js/select2/utils.js
@@ -1,6 +1,5 @@
define([
'jquery'
], function ($) {
], function () {
var Utils = {};

Utils.Extend = function (ChildClass, SuperClass) {
Expand Down Expand Up @@ -216,7 +215,6 @@ define([
// http://codereview.stackexchange.com/q/13338
// and was designed to be used with the Sizzle selector engine.

var $el = $(el);
var overflowX = el.style.overflowX;
var overflowY = el.style.overflowY;

Expand All @@ -230,8 +228,14 @@ define([
return true;
}

return ($el.innerHeight() < el.scrollHeight ||
$el.innerWidth() < el.scrollWidth);
var computed = window.getComputedStyle(el);
var paddingHeight = parseInt(computed.paddingTop, 10);
paddingHeight += parseInt(computed.paddingBottom, 10);
var paddingWidth = parseInt(computed.paddingLeft, 10);
paddingWidth += parseInt(computed.paddingRight, 10);

return ((el.clientHeight - paddingHeight) < el.scrollHeight ||
(el.clientWidth - paddingWidth) < el.scrollWidth);
};

Utils.escapeMarkup = function (markup) {
Expand Down Expand Up @@ -306,9 +310,9 @@ define([
if (Utils.__cache[id][name] != null) {
return Utils.__cache[id][name];
}
return $(element).data(name); // Fallback to HTML5 data attribs.
return element.dataset[name]; // Fallback to HTML5 data attribs.
}
return $(element).data(name); // Fallback to HTML5 data attribs.
return element.dataset[name]; // Fallback to HTML5 data attribs.
} else {
return Utils.__cache[id];
}
Expand Down