Skip to content

Commit 1197960

Browse files
committed
Add proof-of-concept decorator for clearing
1 parent a25883c commit 1197960

9 files changed

Lines changed: 295 additions & 98 deletions

File tree

dist/js/select2.amd.full.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ define('select2/utils',[], function () {
4646
function DecoratedClass () {
4747
var unshift = Array.prototype.unshift;
4848

49-
unshift.call(arguments, SuperClass.prototype.constructor);
50-
5149
var argCount = DecoratorClass.prototype.constructor.length;
5250

5351
var calledConstructor = SuperClass.prototype.constructor;
5452

5553
if (argCount > 0) {
54+
unshift.call(arguments, SuperClass.prototype.constructor);
55+
5656
calledConstructor = DecoratorClass.prototype.constructor;
5757
}
5858

@@ -74,23 +74,26 @@ define('select2/utils',[], function () {
7474
for (var m = 0; m < decoratedMethods.length; m++) {
7575
var methodName = decoratedMethods[m];
7676

77-
var originalMethod = function () {};
77+
function calledMethod (methodName) {
78+
// Stub out the original method if it's not decorating an actual method
79+
var originalMethod = function () {};
7880

79-
if (methodName in DecoratedClass.prototype) {
80-
originalMethod = DecoratedClass.prototype[methodName];
81-
}
81+
if (methodName in DecoratedClass.prototype) {
82+
originalMethod = DecoratedClass.prototype[methodName];
83+
}
8284

83-
var decoratedMethod = DecoratorClass.prototype[methodName];
85+
var decoratedMethod = DecoratorClass.prototype[methodName];
8486

85-
function calledMethod () {
86-
var unshift = Array.prototype.unshift;
87+
return function () {
88+
var unshift = Array.prototype.unshift;
8789

88-
unshift.call(arguments, originalMethod);
90+
unshift.call(arguments, originalMethod);
8991

90-
return decoratedMethod.apply(this, arguments);
92+
return decoratedMethod.apply(this, arguments);
93+
}
9194
}
9295

93-
DecoratedClass.prototype[methodName] = calledMethod;
96+
DecoratedClass.prototype[methodName] = calledMethod(methodName);
9497
}
9598

9699
return DecoratedClass;
@@ -275,8 +278,6 @@ define('select2/results',[
275278

276279
var $options = self.$results.find(".option");
277280

278-
console.log($options);
279-
280281
$options.each(function () {
281282
var $option = $(this);
282283
var item = $option.data("data");
@@ -430,7 +431,7 @@ define('select2/options',[
430431
this.dataAdapter = SelectData;
431432
this.resultsAdapter = ResultsList;
432433
this.dropdownAdapter = Dropdown;
433-
this.selectionAdapter = Selection;
434+
this.selectionAdapter = options.selectionAdapter || Selection;
434435
}
435436

436437
return Options;

dist/js/select2.amd.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ define('select2/utils',[], function () {
4646
function DecoratedClass () {
4747
var unshift = Array.prototype.unshift;
4848

49-
unshift.call(arguments, SuperClass.prototype.constructor);
50-
5149
var argCount = DecoratorClass.prototype.constructor.length;
5250

5351
var calledConstructor = SuperClass.prototype.constructor;
5452

5553
if (argCount > 0) {
54+
unshift.call(arguments, SuperClass.prototype.constructor);
55+
5656
calledConstructor = DecoratorClass.prototype.constructor;
5757
}
5858

@@ -74,23 +74,26 @@ define('select2/utils',[], function () {
7474
for (var m = 0; m < decoratedMethods.length; m++) {
7575
var methodName = decoratedMethods[m];
7676

77-
var originalMethod = function () {};
77+
function calledMethod (methodName) {
78+
// Stub out the original method if it's not decorating an actual method
79+
var originalMethod = function () {};
7880

79-
if (methodName in DecoratedClass.prototype) {
80-
originalMethod = DecoratedClass.prototype[methodName];
81-
}
81+
if (methodName in DecoratedClass.prototype) {
82+
originalMethod = DecoratedClass.prototype[methodName];
83+
}
8284

83-
var decoratedMethod = DecoratorClass.prototype[methodName];
85+
var decoratedMethod = DecoratorClass.prototype[methodName];
8486

85-
function calledMethod () {
86-
var unshift = Array.prototype.unshift;
87+
return function () {
88+
var unshift = Array.prototype.unshift;
8789

88-
unshift.call(arguments, originalMethod);
90+
unshift.call(arguments, originalMethod);
8991

90-
return decoratedMethod.apply(this, arguments);
92+
return decoratedMethod.apply(this, arguments);
93+
}
9194
}
9295

93-
DecoratedClass.prototype[methodName] = calledMethod;
96+
DecoratedClass.prototype[methodName] = calledMethod(methodName);
9497
}
9598

9699
return DecoratedClass;
@@ -275,8 +278,6 @@ define('select2/results',[
275278

276279
var $options = self.$results.find(".option");
277280

278-
console.log($options);
279-
280281
$options.each(function () {
281282
var $option = $(this);
282283
var item = $option.data("data");
@@ -430,7 +431,7 @@ define('select2/options',[
430431
this.dataAdapter = SelectData;
431432
this.resultsAdapter = ResultsList;
432433
this.dropdownAdapter = Dropdown;
433-
this.selectionAdapter = Selection;
434+
this.selectionAdapter = options.selectionAdapter || Selection;
434435
}
435436

436437
return Options;

dist/js/select2.full.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9583,13 +9583,13 @@ define('select2/utils',[], function () {
95839583
function DecoratedClass () {
95849584
var unshift = Array.prototype.unshift;
95859585

9586-
unshift.call(arguments, SuperClass.prototype.constructor);
9587-
95889586
var argCount = DecoratorClass.prototype.constructor.length;
95899587

95909588
var calledConstructor = SuperClass.prototype.constructor;
95919589

95929590
if (argCount > 0) {
9591+
unshift.call(arguments, SuperClass.prototype.constructor);
9592+
95939593
calledConstructor = DecoratorClass.prototype.constructor;
95949594
}
95959595

@@ -9611,23 +9611,26 @@ define('select2/utils',[], function () {
96119611
for (var m = 0; m < decoratedMethods.length; m++) {
96129612
var methodName = decoratedMethods[m];
96139613

9614-
var originalMethod = function () {};
9614+
function calledMethod (methodName) {
9615+
// Stub out the original method if it's not decorating an actual method
9616+
var originalMethod = function () {};
96159617

9616-
if (methodName in DecoratedClass.prototype) {
9617-
originalMethod = DecoratedClass.prototype[methodName];
9618-
}
9618+
if (methodName in DecoratedClass.prototype) {
9619+
originalMethod = DecoratedClass.prototype[methodName];
9620+
}
96199621

9620-
var decoratedMethod = DecoratorClass.prototype[methodName];
9622+
var decoratedMethod = DecoratorClass.prototype[methodName];
96219623

9622-
function calledMethod () {
9623-
var unshift = Array.prototype.unshift;
9624+
return function () {
9625+
var unshift = Array.prototype.unshift;
96249626

9625-
unshift.call(arguments, originalMethod);
9627+
unshift.call(arguments, originalMethod);
96269628

9627-
return decoratedMethod.apply(this, arguments);
9629+
return decoratedMethod.apply(this, arguments);
9630+
}
96289631
}
96299632

9630-
DecoratedClass.prototype[methodName] = calledMethod;
9633+
DecoratedClass.prototype[methodName] = calledMethod(methodName);
96319634
}
96329635

96339636
return DecoratedClass;
@@ -9812,8 +9815,6 @@ define('select2/results',[
98129815

98139816
var $options = self.$results.find(".option");
98149817

9815-
console.log($options);
9816-
98179818
$options.each(function () {
98189819
var $option = $(this);
98199820
var item = $option.data("data");
@@ -9967,7 +9968,7 @@ define('select2/options',[
99679968
this.dataAdapter = SelectData;
99689969
this.resultsAdapter = ResultsList;
99699970
this.dropdownAdapter = Dropdown;
9970-
this.selectionAdapter = Selection;
9971+
this.selectionAdapter = options.selectionAdapter || Selection;
99719972
}
99729973

99739974
return Options;

dist/js/select2.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -474,13 +474,13 @@ define('select2/utils',[], function () {
474474
function DecoratedClass () {
475475
var unshift = Array.prototype.unshift;
476476

477-
unshift.call(arguments, SuperClass.prototype.constructor);
478-
479477
var argCount = DecoratorClass.prototype.constructor.length;
480478

481479
var calledConstructor = SuperClass.prototype.constructor;
482480

483481
if (argCount > 0) {
482+
unshift.call(arguments, SuperClass.prototype.constructor);
483+
484484
calledConstructor = DecoratorClass.prototype.constructor;
485485
}
486486

@@ -502,23 +502,26 @@ define('select2/utils',[], function () {
502502
for (var m = 0; m < decoratedMethods.length; m++) {
503503
var methodName = decoratedMethods[m];
504504

505-
var originalMethod = function () {};
505+
function calledMethod (methodName) {
506+
// Stub out the original method if it's not decorating an actual method
507+
var originalMethod = function () {};
506508

507-
if (methodName in DecoratedClass.prototype) {
508-
originalMethod = DecoratedClass.prototype[methodName];
509-
}
509+
if (methodName in DecoratedClass.prototype) {
510+
originalMethod = DecoratedClass.prototype[methodName];
511+
}
510512

511-
var decoratedMethod = DecoratorClass.prototype[methodName];
513+
var decoratedMethod = DecoratorClass.prototype[methodName];
512514

513-
function calledMethod () {
514-
var unshift = Array.prototype.unshift;
515+
return function () {
516+
var unshift = Array.prototype.unshift;
515517

516-
unshift.call(arguments, originalMethod);
518+
unshift.call(arguments, originalMethod);
517519

518-
return decoratedMethod.apply(this, arguments);
520+
return decoratedMethod.apply(this, arguments);
521+
}
519522
}
520523

521-
DecoratedClass.prototype[methodName] = calledMethod;
524+
DecoratedClass.prototype[methodName] = calledMethod(methodName);
522525
}
523526

524527
return DecoratedClass;
@@ -703,8 +706,6 @@ define('select2/results',[
703706

704707
var $options = self.$results.find(".option");
705708

706-
console.log($options);
707-
708709
$options.each(function () {
709710
var $option = $(this);
710711
var item = $option.data("data");
@@ -858,7 +859,7 @@ define('select2/options',[
858859
this.dataAdapter = SelectData;
859860
this.resultsAdapter = ResultsList;
860861
this.dropdownAdapter = Dropdown;
861-
this.selectionAdapter = Selection;
862+
this.selectionAdapter = options.selectionAdapter || Selection;
862863
}
863864

864865
return Options;

playground/basic/basic.html

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -120,29 +120,6 @@
120120
<option value="WV">West Virginia</option>
121121
</select>
122122

123-
<div style="width: 300px; height: 300px; border: 1px solid black" tabindex="10" id="outer">
124-
<div style="width:100px; height: 100px; border: 1px solid blue" id="inner"></div>
125-
</div>
126-
127-
</div>
128-
129-
130-
<div style="position: absolute; left:0; top:0; background: white; border: 1px solid red;" id="focus-spy">hello there
131-
</div>
132-
<script>
133-
$(function () {
134-
var el = $("#focus-spy");
135-
$(window).bind("scroll", function () {
136-
el.css({top: $(window).scrollTop()});
137-
});
138-
window.setInterval(function () {
139-
var a = document.activeElement;
140-
var b = $(a);
141-
el.html("tag: " + a.tagName + " id:" + a.id + " class:" + b.attr("class") + " val:" + b.val());
142-
}, 100);
143-
});
144-
</script>
145-
146123
<script>
147124
require(["select2/core"], function (Select2) {
148125
var s2 = new Select2($("#source"));

0 commit comments

Comments
 (0)