Skip to content

Commit 7303852

Browse files
author
Cyrille Jouineau
committed
replaces a <div> inside a <a> with a <span>
and minor code cleaning
1 parent 75edea8 commit 7303852

2 files changed

Lines changed: 77 additions & 88 deletions

File tree

select2.css

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ Version: @@ver@@ Timestamp: @@timestamp@@
8282
background-image: linear-gradient(top, #eeeeee 0%,#ffffff 90%);
8383
}
8484

85-
.select2-container.select2-allowclear .select2-choice span {
85+
.select2-container.select2-allowclear .select2-choice .select2-chosen {
8686
margin-right: 42px;
8787
}
8888

89-
.select2-container .select2-choice > span {
89+
.select2-container .select2-choice > .select2-chosen {
9090
margin-right: 26px;
9191
display: block;
9292
overflow: hidden;
@@ -152,7 +152,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@
152152

153153
.select2-drop {
154154
width: 100%;
155-
margin-top:-1px;
155+
margin-top: -1px;
156156
position: absolute;
157157
z-index: 9999;
158158
top: 100%;
@@ -203,7 +203,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@
203203
border-top: 1px solid #5897fb;
204204
}
205205

206-
.select2-container .select2-choice div {
206+
.select2-container .select2-choice .select2-arrow {
207207
display: inline-block;
208208
width: 18px;
209209
height: 100%;
@@ -230,7 +230,7 @@ Version: @@ver@@ Timestamp: @@timestamp@@
230230
background-image: linear-gradient(top, #cccccc 0%, #eeeeee 60%);
231231
}
232232

233-
.select2-container .select2-choice div b {
233+
.select2-container .select2-choice .select2-arrow b {
234234
display: block;
235235
width: 100%;
236236
height: 100%;
@@ -342,12 +342,12 @@ Version: @@ver@@ Timestamp: @@timestamp@@
342342
background-image: linear-gradient(bottom, #ffffff 0%,#eeeeee 50%);
343343
}
344344

345-
.select2-dropdown-open .select2-choice div {
345+
.select2-dropdown-open .select2-choice .select2-arrow {
346346
background: transparent;
347347
border-left: none;
348348
filter: none;
349349
}
350-
.select2-dropdown-open .select2-choice div b {
350+
.select2-dropdown-open .select2-choice .select2-arrow b {
351351
background-position: -18px 1px;
352352
}
353353

@@ -464,7 +464,7 @@ disabled look for disabled choices in the results dropdown
464464
cursor: default;
465465
}
466466

467-
.select2-container.select2-container-disabled .select2-choice div {
467+
.select2-container.select2-container-disabled .select2-choice .select2-arrow {
468468
background-color: #f4f4f4;
469469
background-image: none;
470470
border-left: 0;
@@ -584,7 +584,7 @@ disabled look for disabled choices in the results dropdown
584584
background-image: -ms-linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
585585
background-image: linear-gradient(top, #f4f4f4 20%, #f0f0f0 50%, #e8e8e8 52%, #eeeeee 100%);
586586
}
587-
.select2-container-multi .select2-choices .select2-search-choice span {
587+
.select2-container-multi .select2-choices .select2-search-choice .select2-chosen {
588588
cursor: default;
589589
}
590590
.select2-container-multi .select2-choices .select2-search-choice-focus {
@@ -669,7 +669,7 @@ disabled look for disabled choices in the results dropdown
669669
/* Retina-ize icons */
670670

671671
@media only screen and (-webkit-min-device-pixel-ratio: 1.5), only screen and (min-resolution: 144dpi) {
672-
.select2-search input, .select2-search-choice-close, .select2-container .select2-choice abbr, .select2-container .select2-choice div b {
672+
.select2-search input, .select2-search-choice-close, .select2-container .select2-choice abbr, .select2-container .select2-choice .select2-arrow b {
673673
background-image: url('select2x2.png') !important;
674674
background-repeat: no-repeat !important;
675675
background-size: 60px 40px !important;

select2.js

Lines changed: 67 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ Apache License or the GPL Licesnse is distributed on an "AS IS" BASIS, WITHOUT W
1818
CONDITIONS OF ANY KIND, either express or implied. See the Apache License and the GPL License for
1919
the specific language governing permissions and limitations under the Apache License and the GPL License.
2020
*/
21-
(function ($) {
22-
if(typeof $.fn.each2 == "undefined"){
23-
$.fn.extend({
24-
/*
25-
* 4-10 times faster .each replacement
26-
* use it carefully, as it overrides jQuery context of element on each iteration
27-
*/
28-
each2 : function (c) {
29-
var j = $([0]), i = -1, l = this.length;
30-
while (
31-
++i < l
32-
&& (j.context = j[0] = this[i])
33-
&& c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
34-
);
35-
return this;
36-
}
37-
});
38-
}
21+
(function ($) {
22+
if(typeof $.fn.each2 == "undefined") {
23+
$.fn.extend({
24+
/*
25+
* 4-10 times faster .each replacement
26+
* use it carefully, as it overrides jQuery context of element on each iteration
27+
*/
28+
each2 : function (c) {
29+
var j = $([0]), i = -1, l = this.length;
30+
while (
31+
++i < l
32+
&& (j.context = j[0] = this[i])
33+
&& c.call(j[0], i, j) !== false //"this"=DOM, i=index, j=jQuery object
34+
);
35+
return this;
36+
}
37+
});
38+
}
3939
})(jQuery);
4040

4141
(function ($, undefined) {
@@ -183,7 +183,7 @@ the specific language governing permissions and limitations under the Apache Lic
183183
* the elements under the pointer are scrolled.
184184
*/
185185
function installFilteredMouseMove(element) {
186-
element.on("mousemove", function (e) {
186+
element.on("mousemove", function (e) {
187187
var lastpos = lastMousePosition;
188188
if (lastpos === undefined || lastpos.x !== e.pageX || lastpos.y !== e.pageY) {
189189
$(e.target).trigger("mousemove-filtered", e);
@@ -291,22 +291,22 @@ the specific language governing permissions and limitations under the Apache Lic
291291

292292
function measureTextWidth(e) {
293293
if (!sizer){
294-
var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
295-
sizer = $(document.createElement("div")).css({
296-
position: "absolute",
297-
left: "-10000px",
298-
top: "-10000px",
299-
display: "none",
300-
fontSize: style.fontSize,
301-
fontFamily: style.fontFamily,
302-
fontStyle: style.fontStyle,
303-
fontWeight: style.fontWeight,
304-
letterSpacing: style.letterSpacing,
305-
textTransform: style.textTransform,
306-
whiteSpace: "nowrap"
307-
});
294+
var style = e[0].currentStyle || window.getComputedStyle(e[0], null);
295+
sizer = $(document.createElement("div")).css({
296+
position: "absolute",
297+
left: "-10000px",
298+
top: "-10000px",
299+
display: "none",
300+
fontSize: style.fontSize,
301+
fontFamily: style.fontFamily,
302+
fontStyle: style.fontStyle,
303+
fontWeight: style.fontWeight,
304+
letterSpacing: style.letterSpacing,
305+
textTransform: style.textTransform,
306+
whiteSpace: "nowrap"
307+
});
308308
sizer.attr("class","select2-sizer");
309-
$("body").append(sizer);
309+
$("body").append(sizer);
310310
}
311311
sizer.text(e.val());
312312
return sizer.width();
@@ -464,12 +464,12 @@ the specific language governing permissions and limitations under the Apache Lic
464464
tmp,
465465
text = function (item) { return ""+item.text; }; // function used to retrieve the text portion of a data item that is matched against the search
466466

467-
if ($.isArray(data)) {
467+
if ($.isArray(data)) {
468468
tmp = data;
469469
data = { results: tmp };
470470
}
471471

472-
if ($.isFunction(data) === false) {
472+
if ($.isFunction(data) === false) {
473473
tmp = data;
474474
data = function() { return tmp; };
475475
}
@@ -985,7 +985,6 @@ the specific language governing permissions and limitations under the Apache Lic
985985
var enabled, readonly, self = this;
986986

987987
// sync enabled state
988-
989988
var disabled = el.prop("disabled");
990989
if (disabled === undefined) disabled = false;
991990
this.enable(!disabled);
@@ -1105,14 +1104,14 @@ the specific language governing permissions and limitations under the Apache Lic
11051104
height = this.container.outerHeight(false),
11061105
width = this.container.outerWidth(false),
11071106
dropHeight = $dropdown.outerHeight(false),
1108-
viewPortRight = $(window).scrollLeft() + $(window).width(),
1107+
viewPortRight = $(window).scrollLeft() + $(window).width(),
11091108
viewportBottom = $(window).scrollTop() + $(window).height(),
11101109
dropTop = offset.top + height,
11111110
dropLeft = offset.left,
11121111
enoughRoomBelow = dropTop + dropHeight <= viewportBottom,
11131112
enoughRoomAbove = (offset.top - dropHeight) >= this.body().scrollTop(),
1114-
dropWidth = $dropdown.outerWidth(false),
1115-
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
1113+
dropWidth = $dropdown.outerWidth(false),
1114+
enoughRoomOnRight = dropLeft + dropWidth <= viewPortRight,
11161115
aboveNow = $dropdown.hasClass("select2-drop-above"),
11171116
bodyOffset,
11181117
above,
@@ -1136,15 +1135,13 @@ the specific language governing permissions and limitations under the Apache Lic
11361135
//console.log("above/ offset.top", offset.top, "dropHeight", dropHeight, "top", (offset.top-dropHeight), "scrollTop", this.body().scrollTop(), "enough?", enoughRoomAbove);
11371136

11381137
// fix positioning when body has an offset and is not position: static
1139-
11401138
if (this.body().css('position') !== 'static') {
11411139
bodyOffset = this.body().offset();
11421140
dropTop -= bodyOffset.top;
11431141
dropLeft -= bodyOffset.left;
11441142
}
11451143

11461144
// always prefer the current above/below alignment, unless there is not enough room
1147-
11481145
if (aboveNow) {
11491146
above = true;
11501147
if (!enoughRoomAbove && enoughRoomBelow) above = false;
@@ -1435,7 +1432,7 @@ the specific language governing permissions and limitations under the Apache Lic
14351432
highlightUnderEvent: function (event) {
14361433
var el = $(event.target).closest(".select2-result-selectable");
14371434
if (el.length > 0 && !el.is(".select2-highlighted")) {
1438-
var choices = this.findHighlightableChoices();
1435+
var choices = this.findHighlightableChoices();
14391436
this.highlight(choices.index(el));
14401437
} else if (el.length == 0) {
14411438
// if we are over an unselectable item remove al highlights
@@ -1532,8 +1529,8 @@ the specific language governing permissions and limitations under the Apache Lic
15321529
if (maxSelSize >=1) {
15331530
data = this.data();
15341531
if ($.isArray(data) && data.length >= maxSelSize && checkFormatter(opts.formatSelectionTooBig, "formatSelectionTooBig")) {
1535-
render("<li class='select2-selection-limit'>" + opts.formatSelectionTooBig(maxSelSize) + "</li>");
1536-
return;
1532+
render("<li class='select2-selection-limit'>" + opts.formatSelectionTooBig(maxSelSize) + "</li>");
1533+
return;
15371534
}
15381535
}
15391536

@@ -1741,21 +1738,21 @@ the specific language governing permissions and limitations under the Apache Lic
17411738

17421739
// single
17431740

1744-
createContainer: function () {
1741+
createContainer: function () {
17451742
var container = $(document.createElement("div")).attr({
17461743
"class": "select2-container"
17471744
}).html([
17481745
"<a href='javascript:void(0)' onclick='return false;' class='select2-choice' tabindex='-1'>",
1749-
" <span>&nbsp;</span><abbr class='select2-search-choice-close'></abbr>",
1750-
" <div><b></b></div>" ,
1746+
" <span class='select2-chosen'>&nbsp;</span><abbr class='select2-search-choice-close'></abbr>",
1747+
" <span class='select2-arrow'><b></b></span>",
17511748
"</a>",
17521749
"<input class='select2-focusser select2-offscreen' type='text'/>",
1753-
"<div class='select2-drop select2-display-none'>" ,
1754-
" <div class='select2-search'>" ,
1755-
" <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'/>" ,
1756-
" </div>" ,
1757-
" <ul class='select2-results'>" ,
1758-
" </ul>" ,
1750+
"<div class='select2-drop select2-display-none'>",
1751+
" <div class='select2-search'>",
1752+
" <input type='text' autocomplete='off' autocorrect='off' autocapitalize='off' spellcheck='false' class='select2-input'/>",
1753+
" </div>",
1754+
" <ul class='select2-results'>",
1755+
" </ul>",
17591756
"</div>"].join(""));
17601757
return container;
17611758
},
@@ -1995,7 +1992,7 @@ the specific language governing permissions and limitations under the Apache Lic
19951992
if (data) { // guard against queued quick consecutive clicks
19961993
var placeholderOption = this.getPlaceholderOption();
19971994
this.opts.element.val(placeholderOption ? placeholderOption.val() : "");
1998-
this.selection.find("span").empty();
1995+
this.selection.find(".select2-chosen").empty();
19991996
this.selection.removeData("select2-data");
20001997
this.setPlaceholder();
20011998

@@ -2093,7 +2090,7 @@ the specific language governing permissions and limitations under the Apache Lic
20932090
// check for a placeholder option if attached to a select
20942091
if (this.select && this.getPlaceholderOption() === undefined) return;
20952092

2096-
this.selection.find("span").html(this.opts.escapeMarkup(placeholder));
2093+
this.selection.find(".select2-chosen").html(this.opts.escapeMarkup(placeholder));
20972094

20982095
this.selection.addClass("select2-default");
20992096

@@ -2169,7 +2166,7 @@ the specific language governing permissions and limitations under the Apache Lic
21692166
// single
21702167
updateSelection: function (data) {
21712168

2172-
var container=this.selection.find("span"), formatted, cssClass;
2169+
var container=this.selection.find(".select2-chosen"), formatted, cssClass;
21732170

21742171
this.selection.data("select2-data", data);
21752172

@@ -2277,17 +2274,16 @@ the specific language governing permissions and limitations under the Apache Lic
22772274
var container = $(document.createElement("div")).attr({
22782275
"class": "select2-container select2-container-multi"
22792276
}).html([
2280-
" <ul class='select2-choices'>",
2281-
//"<li class='select2-search-choice'><span>California</span><a href="javascript:void(0)" class="select2-search-choice-close"></a></li>" ,
2282-
" <li class='select2-search-field'>" ,
2283-
" <input type='text' autocomplete='off' autocorrect='off' autocapitilize='off' spellcheck='false' class='select2-input'>" ,
2284-
" </li>" ,
2285-
"</ul>" ,
2286-
"<div class='select2-drop select2-drop-multi select2-display-none'>" ,
2287-
" <ul class='select2-results'>" ,
2288-
" </ul>" ,
2277+
"<ul class='select2-choices'>",
2278+
" <li class='select2-search-field'>",
2279+
" <input type='text' autocomplete='off' autocorrect='off' autocapitilize='off' spellcheck='false' class='select2-input'>",
2280+
" </li>",
2281+
"</ul>",
2282+
"<div class='select2-drop select2-drop-multi select2-display-none'>",
2283+
" <ul class='select2-results'>",
2284+
" </ul>",
22892285
"</div>"].join(""));
2290-
return container;
2286+
return container;
22912287
},
22922288

22932289
// multi
@@ -2380,11 +2376,6 @@ the specific language governing permissions and limitations under the Apache Lic
23802376
_this.search[0].focus();
23812377
_this.selectChoice($(this));
23822378
})
2383-
//.sortable({
2384-
// items: " > li",
2385-
// tolerance: "pointer",
2386-
// revert: 100
2387-
//});
23882379

23892380
// rewrite labels from original element to focusser
23902381
this.search.attr("id", "s2id_autogen"+nextUid());
@@ -2619,7 +2610,6 @@ the specific language governing permissions and limitations under the Apache Lic
26192610
focus: function () {
26202611
this.close();
26212612
this.search.focus();
2622-
//this.opts.element.triggerHandler("focus");
26232613
},
26242614

26252615
// multi
@@ -2821,11 +2811,11 @@ the specific language governing permissions and limitations under the Apache Lic
28212811

28222812
//If all results are chosen render formatNoMAtches
28232813
if(!this.opts.createSearchChoice && !choices.filter('.select2-result:not(.select2-selected)').length > 0){
2824-
if(!data || data && !data.more && this.results.find(".select2-no-results").length === 0) {
2825-
if (checkFormatter(self.opts.formatNoMatches, "formatNoMatches")) {
2814+
if(!data || data && !data.more && this.results.find(".select2-no-results").length === 0) {
2815+
if (checkFormatter(self.opts.formatNoMatches, "formatNoMatches")) {
28262816
this.results.append("<li class='select2-no-results'>" + self.opts.formatNoMatches(self.search.val()) + "</li>");
28272817
}
2828-
}
2818+
}
28292819
}
28302820

28312821
},
@@ -2838,7 +2828,7 @@ the specific language governing permissions and limitations under the Apache Lic
28382828
// multi
28392829
resizeSearch: function () {
28402830
var minimumWidth, left, maxWidth, containerLeft, searchWidth,
2841-
sideBorderPadding = getSideBorderPadding(this.search);
2831+
sideBorderPadding = getSideBorderPadding(this.search);
28422832

28432833
minimumWidth = measureTextWidth(this.search) + 10;
28442834

@@ -2985,7 +2975,6 @@ the specific language governing permissions and limitations under the Apache Lic
29852975
this.resizeSearch();
29862976

29872977
// update selection
2988-
29892978
this.selection.find(".select2-search-choice").each(function() {
29902979
val.push(self.opts.id($(this).data("select2-data")));
29912980
});

0 commit comments

Comments
 (0)