Drop the playground
This commit is contained in:
parent
845f245e1c
commit
fa3495de24
@ -1,98 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>QUnit Example</title>
|
||||
<link href="../../dist/css/select2.css" rel="stylesheet"/>
|
||||
|
||||
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
|
||||
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../../dist/js/select2.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<select style="width:300px" id="array-single"></select>
|
||||
|
||||
<br />
|
||||
|
||||
<select style="width:300px" id="array-multiple" multiple="multiple"></select>
|
||||
|
||||
<br />
|
||||
|
||||
<select style="width:300px" id="remote-single"></select>
|
||||
|
||||
<br />
|
||||
|
||||
<select style="width:300px" id="remote-multiple" multiple="multiple"></select>
|
||||
|
||||
<script>
|
||||
require(["select2/core", "select2/data/array", "select2/data/ajax"],
|
||||
function (Select2, ArrayAdapter, AjaxAdapter) {
|
||||
var arrayData = [
|
||||
{
|
||||
id: 0,
|
||||
text: 'enhancement'
|
||||
},
|
||||
{
|
||||
id: 1,
|
||||
text: 'bug'
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
text: 'duplicate'
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
text: 'invalid'
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
text: 'wontfix'
|
||||
}
|
||||
];
|
||||
|
||||
var arraySingle = new Select2($("#array-single"), {
|
||||
dataAdapter: ArrayAdapter,
|
||||
data: arrayData
|
||||
});
|
||||
|
||||
var arrayMultiple = new Select2($("#array-multiple"), {
|
||||
dataAdapter: ArrayAdapter,
|
||||
data: arrayData
|
||||
});
|
||||
|
||||
var ajaxSettings = {
|
||||
url: "https://api.github.com/search/repositories",
|
||||
dataType: "json",
|
||||
data: function (params) {
|
||||
return {
|
||||
q: "test"
|
||||
}
|
||||
},
|
||||
processResults: function (data) {
|
||||
var results = $.map(data.items, function (d) {
|
||||
return {
|
||||
id: d.id,
|
||||
text: d.full_name
|
||||
}
|
||||
});
|
||||
|
||||
return results
|
||||
}
|
||||
};
|
||||
|
||||
var ajaxSingle = new Select2($("#remote-single"), {
|
||||
dataAdapter: AjaxAdapter,
|
||||
ajax: ajaxSettings
|
||||
});
|
||||
|
||||
var ajaxMultiple = new Select2($("#remote-multiple"), {
|
||||
dataAdapter: AjaxAdapter,
|
||||
ajax: ajaxSettings
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,189 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>QUnit Example</title>
|
||||
<link href="../../dist/css/select2.css" rel="stylesheet"/>
|
||||
|
||||
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
|
||||
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../../dist/js/select2.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<select style="width:300px" id="single">
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="HI">Hawaii</option>
|
||||
<option value="CA">California</option>
|
||||
<option value="NV">Nevada</option>
|
||||
<option value="OR">Oregon</option>
|
||||
<option value="WA">Washington</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="ID">Idaho</option>
|
||||
<option value="MT">Montana</option>
|
||||
<option value="NE">Nebraska</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
<option value="ND">North Dakota</option>
|
||||
<option value="UT">Utah</option>
|
||||
<option value="WY">Wyoming</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="IL">Illinois</option>
|
||||
<option value="IA">Iowa</option>
|
||||
<option value="KS">Kansas</option>
|
||||
<option value="KY">Kentucky</option>
|
||||
<option value="LA">Louisiana</option>
|
||||
<option value="MN">Minnesota</option>
|
||||
<option value="MS">Mississippi</option>
|
||||
<option value="MO">Missouri</option>
|
||||
<option value="OK">Oklahoma</option>
|
||||
<option value="SD">South Dakota</option>
|
||||
<option value="TX">Texas</option>
|
||||
<option value="TN">Tennessee</option>
|
||||
<option value="WI">Wisconsin</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
<option value="DE">Delaware</option>
|
||||
<option value="FL">Florida</option>
|
||||
<option value="GA">Georgia</option>
|
||||
<option value="IN">Indiana</option>
|
||||
<option value="ME">Maine</option>
|
||||
<option value="MD">Maryland</option>
|
||||
<option value="MA">Massachusetts</option>
|
||||
<option value="MI">Michigan</option>
|
||||
<option value="NH">New Hampshire</option>
|
||||
<option value="NJ">New Jersey</option>
|
||||
<option value="NY">New York</option>
|
||||
<option value="NC">North Carolina</option>
|
||||
<option value="OH">Ohio</option>
|
||||
<option value="PA">Pennsylvania</option>
|
||||
<option value="RI">Rhode Island</option>
|
||||
<option value="SC">South Carolina</option>
|
||||
<option value="VT">Vermont</option>
|
||||
<option value="VA">Virginia</option>
|
||||
<option value="WV">West Virginia</option>
|
||||
</select>
|
||||
|
||||
<br/>
|
||||
|
||||
<select style="width:300px" id="multiple" multiple="multiple">
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="HI">Hawaii</option>
|
||||
<option value="CA" selected="selected">California</option>
|
||||
<option value="NV">Nevada</option>
|
||||
<option value="OR">Oregon</option>
|
||||
<option value="WA">Washington</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="ID">Idaho</option>
|
||||
<option value="MT">Montana</option>
|
||||
<option value="NE">Nebraska</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
<option value="ND">North Dakota</option>
|
||||
<option value="UT">Utah</option>
|
||||
<option value="WY">Wyoming</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="IL">Illinois</option>
|
||||
<option value="IA">Iowa</option>
|
||||
<option value="KS">Kansas</option>
|
||||
<option value="KY">Kentucky</option>
|
||||
<option value="LA">Louisiana</option>
|
||||
<option value="MN">Minnesota</option>
|
||||
<option value="MS">Mississippi</option>
|
||||
<option value="MO">Missouri</option>
|
||||
<option value="OK">Oklahoma</option>
|
||||
<option value="SD">South Dakota</option>
|
||||
<option value="TX">Texas</option>
|
||||
<option value="TN">Tennessee</option>
|
||||
<option value="WI">Wisconsin</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
<option value="DE">Delaware</option>
|
||||
<option value="FL">Florida</option>
|
||||
<option value="GA">Georgia</option>
|
||||
<option value="IN">Indiana</option>
|
||||
<option value="ME">Maine</option>
|
||||
<option value="MD">Maryland</option>
|
||||
<option value="MA">Massachusetts</option>
|
||||
<option value="MI">Michigan</option>
|
||||
<option value="NH">New Hampshire</option>
|
||||
<option value="NJ">New Jersey</option>
|
||||
<option value="NY">New York</option>
|
||||
<option value="NC">North Carolina</option>
|
||||
<option value="OH">Ohio</option>
|
||||
<option value="PA">Pennsylvania</option>
|
||||
<option value="RI">Rhode Island</option>
|
||||
<option value="SC">South Carolina</option>
|
||||
<option value="VT">Vermont</option>
|
||||
<option value="VA">Virginia</option>
|
||||
<option value="WV">West Virginia</option>
|
||||
</select>
|
||||
|
||||
<br />
|
||||
|
||||
<select style="width:300px" id="single-multiple">
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="HI">Hawaii</option>
|
||||
<option value="CA">California</option>
|
||||
<option value="NV">Nevada</option>
|
||||
<option value="OR">Oregon</option>
|
||||
<option value="WA">Washington</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="ID">Idaho</option>
|
||||
<option value="MT">Montana</option>
|
||||
<option value="NE">Nebraska</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
<option value="ND">North Dakota</option>
|
||||
<option value="UT">Utah</option>
|
||||
<option value="WY">Wyoming</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="IL">Illinois</option>
|
||||
<option value="IA">Iowa</option>
|
||||
<option value="KS">Kansas</option>
|
||||
<option value="KY">Kentucky</option>
|
||||
<option value="LA">Louisiana</option>
|
||||
<option value="MN">Minnesota</option>
|
||||
<option value="MS">Mississippi</option>
|
||||
<option value="MO">Missouri</option>
|
||||
<option value="OK">Oklahoma</option>
|
||||
<option value="SD">South Dakota</option>
|
||||
<option value="TX">Texas</option>
|
||||
<option value="TN">Tennessee</option>
|
||||
<option value="WI">Wisconsin</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
<option value="DE">Delaware</option>
|
||||
<option value="FL">Florida</option>
|
||||
<option value="GA">Georgia</option>
|
||||
<option value="IN">Indiana</option>
|
||||
<option value="ME">Maine</option>
|
||||
<option value="MD">Maryland</option>
|
||||
<option value="MA">Massachusetts</option>
|
||||
<option value="MI">Michigan</option>
|
||||
<option value="NH">New Hampshire</option>
|
||||
<option value="NJ">New Jersey</option>
|
||||
<option value="NY">New York</option>
|
||||
<option value="NC">North Carolina</option>
|
||||
<option value="OH">Ohio</option>
|
||||
<option value="PA">Pennsylvania</option>
|
||||
<option value="RI">Rhode Island</option>
|
||||
<option value="SC">South Carolina</option>
|
||||
<option value="VT">Vermont</option>
|
||||
<option value="VA">Virginia</option>
|
||||
<option value="WV">West Virginia</option>
|
||||
</select>
|
||||
|
||||
<script>
|
||||
require(["select2/core"], function (Select2) {
|
||||
var single = new Select2($("#single"));
|
||||
var multiple = new Select2($("#multiple"));
|
||||
var singleMultiple = new Select2($("#single-multiple"), {
|
||||
multiple: true
|
||||
})
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,242 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>QUnit Example</title>
|
||||
<link href="../../dist/css/select2.css" rel="stylesheet"/>
|
||||
|
||||
<script src="../../vendor/almond-0.2.9.js" type="text/javascript"></script>
|
||||
<script src="../../vendor/jquery-2.1.0.js" type="text/javascript"></script>
|
||||
|
||||
<script src="../../dist/js/select2.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<input type="text" style="width:300px" autofocus/><br/>
|
||||
<select style="width:300px" id="source">
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="HI">Hawaii</option>
|
||||
<option value="CA">California</option>
|
||||
<option value="NV">Nevada</option>
|
||||
<option value="OR">Oregon</option>
|
||||
<option value="WA">Washington</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="ID">Idaho</option>
|
||||
<option value="MT">Montana</option>
|
||||
<option value="NE">Nebraska</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
<option value="ND">North Dakota</option>
|
||||
<option value="UT">Utah</option>
|
||||
<option value="WY">Wyoming</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="IL">Illinois</option>
|
||||
<option value="IA">Iowa</option>
|
||||
<option value="KS">Kansas</option>
|
||||
<option value="KY">Kentucky</option>
|
||||
<option value="LA">Louisiana</option>
|
||||
<option value="MN">Minnesota</option>
|
||||
<option value="MS">Mississippi</option>
|
||||
<option value="MO">Missouri</option>
|
||||
<option value="OK">Oklahoma</option>
|
||||
<option value="SD">South Dakota</option>
|
||||
<option value="TX">Texas</option>
|
||||
<option value="TN">Tennessee</option>
|
||||
<option value="WI">Wisconsin</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
<option value="DE">Delaware</option>
|
||||
<option value="FL">Florida</option>
|
||||
<option value="GA">Georgia</option>
|
||||
<option value="IN">Indiana</option>
|
||||
<option value="ME">Maine</option>
|
||||
<option value="MD">Maryland</option>
|
||||
<option value="MA">Massachusetts</option>
|
||||
<option value="MI">Michigan</option>
|
||||
<option value="NH">New Hampshire</option>
|
||||
<option value="NJ">New Jersey</option>
|
||||
<option value="NY">New York</option>
|
||||
<option value="NC">North Carolina</option>
|
||||
<option value="OH">Ohio</option>
|
||||
<option value="PA">Pennsylvania</option>
|
||||
<option value="RI">Rhode Island</option>
|
||||
<option value="SC">South Carolina</option>
|
||||
<option value="VT">Vermont</option>
|
||||
<option value="VA">Virginia</option>
|
||||
<option value="WV">West Virginia</option>
|
||||
</select><br/>
|
||||
<input type="text" style="width:300px" /><br/>
|
||||
<select style="width:300px">
|
||||
<option value="AK">Alaska</option>
|
||||
<option value="HI">Hawaii</option>
|
||||
<option value="CA">California</option>
|
||||
<option value="NV">Nevada</option>
|
||||
<option value="OR">Oregon</option>
|
||||
<option value="WA">Washington</option>
|
||||
<option value="AZ">Arizona</option>
|
||||
<option value="CO">Colorado</option>
|
||||
<option value="ID">Idaho</option>
|
||||
<option value="MT">Montana</option>
|
||||
<option value="NE">Nebraska</option>
|
||||
<option value="NM">New Mexico</option>
|
||||
<option value="ND">North Dakota</option>
|
||||
<option value="UT">Utah</option>
|
||||
<option value="WY">Wyoming</option>
|
||||
<option value="AL">Alabama</option>
|
||||
<option value="AR">Arkansas</option>
|
||||
<option value="IL">Illinois</option>
|
||||
<option value="IA">Iowa</option>
|
||||
<option value="KS">Kansas</option>
|
||||
<option value="KY">Kentucky</option>
|
||||
<option value="LA">Louisiana</option>
|
||||
<option value="MN">Minnesota</option>
|
||||
<option value="MS">Mississippi</option>
|
||||
<option value="MO">Missouri</option>
|
||||
<option value="OK">Oklahoma</option>
|
||||
<option value="SD">South Dakota</option>
|
||||
<option value="TX">Texas</option>
|
||||
<option value="TN">Tennessee</option>
|
||||
<option value="WI">Wisconsin</option>
|
||||
<option value="CT">Connecticut</option>
|
||||
<option value="DE">Delaware</option>
|
||||
<option value="FL">Florida</option>
|
||||
<option value="GA">Georgia</option>
|
||||
<option value="IN">Indiana</option>
|
||||
<option value="ME">Maine</option>
|
||||
<option value="MD">Maryland</option>
|
||||
<option value="MA">Massachusetts</option>
|
||||
<option value="MI">Michigan</option>
|
||||
<option value="NH">New Hampshire</option>
|
||||
<option value="NJ">New Jersey</option>
|
||||
<option value="NY">New York</option>
|
||||
<option value="NC">North Carolina</option>
|
||||
<option value="OH">Ohio</option>
|
||||
<option value="PA">Pennsylvania</option>
|
||||
<option value="RI">Rhode Island</option>
|
||||
<option value="SC">South Carolina</option>
|
||||
<option value="VT">Vermont</option>
|
||||
<option value="VA">Virginia</option>
|
||||
<option value="WV">West Virginia</option>
|
||||
</select>
|
||||
|
||||
<style>
|
||||
.clear {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
box-sizing: border-box;
|
||||
color: #666;
|
||||
cursor: pointer;
|
||||
display: none;
|
||||
font-size: 15px;
|
||||
font-weight: bold;
|
||||
height: 26px;
|
||||
outline: 0;
|
||||
position: absolute;
|
||||
top: 1px;
|
||||
right: 4px;
|
||||
width: 26px;
|
||||
}
|
||||
|
||||
.clear:hover {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.clearable {
|
||||
padding-right: 31px;
|
||||
}
|
||||
|
||||
.clearable .clear {
|
||||
display: inline;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
require(["select2/core", "select2/utils", "select2/selection/single",
|
||||
"select2/dropdown"], function (Select2, Utils, Selection, Dropdown) {
|
||||
function ClearSelection () { }
|
||||
|
||||
ClearSelection.prototype.render = function (decorated) {
|
||||
var $selection = decorated.call(this);
|
||||
|
||||
var $clear = $(
|
||||
'<button class="clear">×</button>'
|
||||
)
|
||||
|
||||
$selection.append($clear);
|
||||
$selection.addClass("clearable");
|
||||
|
||||
this.$clear = $clear;
|
||||
|
||||
return $selection;
|
||||
};
|
||||
|
||||
ClearSelection.prototype.bind = function (decorated, container, $container) {
|
||||
var self = this;
|
||||
|
||||
decorated.call(this, container, $container);
|
||||
|
||||
this.$container = $container;
|
||||
|
||||
this.$clear.on("mousedown", function (evt) {
|
||||
evt.stopPropagation();
|
||||
|
||||
var $first = $container.find("li").first();
|
||||
$first.mouseup();
|
||||
});
|
||||
};
|
||||
|
||||
ClearSelection.prototype.update = function (decorated, data) {
|
||||
decorated.call(this, data);
|
||||
|
||||
if (data.length == 0 || this.$container.find("li").length == 0) {
|
||||
this.$selection.removeClass("clearable");
|
||||
return;
|
||||
}
|
||||
|
||||
var firstOption = this.$container.find("li").first().data("data");
|
||||
var firstData = data[0];
|
||||
|
||||
if (firstOption.id == firstData.id) {
|
||||
this.$selection.removeClass("clearable");
|
||||
} else {
|
||||
this.$selection.addClass("clearable");
|
||||
}
|
||||
};
|
||||
|
||||
function DropdownFooter () { }
|
||||
|
||||
DropdownFooter.prototype.render = function (decorated) {
|
||||
var $dropdown = decorated.call(this);
|
||||
|
||||
$dropdown.append('<div class="footer">My custom footer</div>');
|
||||
|
||||
return $dropdown;
|
||||
}
|
||||
|
||||
function DropdownHeader () { }
|
||||
|
||||
DropdownHeader.prototype.render = function (decorated) {
|
||||
var $dropdown = decorated.call(this);
|
||||
|
||||
$dropdown.prepend('<div class="header">Some custom header</div>');
|
||||
|
||||
return $dropdown;
|
||||
}
|
||||
|
||||
var CustomSelection = Utils.Decorate(Selection, ClearSelection)
|
||||
|
||||
var CustomDropdown = Utils.Decorate(
|
||||
Utils.Decorate(Dropdown, DropdownHeader),
|
||||
DropdownFooter
|
||||
);
|
||||
|
||||
var s2 = new Select2($("#source"), {
|
||||
selectionAdapter: CustomSelection,
|
||||
dropdownAdapter: CustomDropdown
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,138 +0,0 @@
|
||||
|
||||
QUnit.test("decorator", function (assert) {
|
||||
|
||||
var A = clazz(Object, {
|
||||
hello: function () {
|
||||
return "A";
|
||||
}
|
||||
});
|
||||
|
||||
var Decorator = clazz(Object, {
|
||||
hello: function () {
|
||||
return "B" + this.decorated() + "B";
|
||||
}
|
||||
});
|
||||
|
||||
var a = new A();
|
||||
assert.strictEqual(a.hello(), "A");
|
||||
|
||||
|
||||
a.decorateWith(new Decorator());
|
||||
var value = a.hello();
|
||||
assert.strictEqual(value, "BAB");
|
||||
|
||||
});
|
||||
|
||||
QUnit.test("super", function (assert) {
|
||||
|
||||
var A = clazz(Object, {
|
||||
hello: function () {
|
||||
return "A";
|
||||
}
|
||||
});
|
||||
|
||||
var B = clazz(A, {
|
||||
hello: function () {
|
||||
return "B" + this.super() + "B";
|
||||
}
|
||||
});
|
||||
|
||||
var C = clazz(B, {
|
||||
hello: function () {
|
||||
return "C" + this.super() + "C";
|
||||
}
|
||||
});
|
||||
|
||||
var D = clazz(B, {
|
||||
hello: function () {
|
||||
return "D";
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(new C().hello(), "CBABC");
|
||||
assert.strictEqual(new D().hello(), "D");
|
||||
|
||||
});
|
||||
|
||||
QUnit.test("super - constructors", function (assert) {
|
||||
|
||||
var A = clazz(Object, {
|
||||
construct: function () {
|
||||
this.message = "A";
|
||||
}
|
||||
});
|
||||
|
||||
var B = clazz(A, {
|
||||
construct: function () {
|
||||
this.super();
|
||||
this.message = "B" + this.message + "B";
|
||||
}
|
||||
});
|
||||
|
||||
var C = clazz(B, {
|
||||
construct: function () {
|
||||
this.super();
|
||||
this.message = "C" + this.message + "C";
|
||||
}
|
||||
});
|
||||
|
||||
var D = clazz(B, {
|
||||
construct: function () {
|
||||
this.message = "D";
|
||||
}
|
||||
});
|
||||
|
||||
assert.strictEqual(new C().message, "CBABC");
|
||||
assert.strictEqual(new D().message, "D");
|
||||
|
||||
});
|
||||
|
||||
|
||||
QUnit.test("inheritance", function (assert) {
|
||||
|
||||
var counter = 0;
|
||||
|
||||
var A = clazz(Object, {
|
||||
hello: function () {
|
||||
return "A";
|
||||
}
|
||||
});
|
||||
|
||||
var B = clazz(A, {
|
||||
|
||||
});
|
||||
|
||||
var a = new A(), b = new B();
|
||||
assert.ok(a.hello() === "A", "instance of A has hello()");
|
||||
assert.ok(b.hello() === "A", "instance of B has hello()");
|
||||
assert.ok(b instanceof B, "b is instance of B");
|
||||
assert.ok(b instanceof Object, "b is instance of Object");
|
||||
assert.ok(b instanceof A, "b is instance of A");
|
||||
});
|
||||
|
||||
|
||||
QUnit.test("initialization", function (assert) {
|
||||
|
||||
var counter = 0;
|
||||
|
||||
var A = clazz(Object, {
|
||||
construct: function () {
|
||||
counter++;
|
||||
}
|
||||
});
|
||||
|
||||
var B = clazz(A, {
|
||||
|
||||
});
|
||||
|
||||
assert.strictEqual(counter, 0);
|
||||
|
||||
var a = new A();
|
||||
|
||||
assert.strictEqual(counter, 1);
|
||||
|
||||
var b = new B();
|
||||
|
||||
assert.strictEqual(counter, 2);
|
||||
|
||||
});
|
@ -1,105 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>QUnit Example</title>
|
||||
<link rel="stylesheet" href="qunit-1.14.0.css">
|
||||
<script src="jquery-2.1.0.js" type="text/javascript"></script>
|
||||
<script src="jquery.sortable.js" type="text/javascript"></script>
|
||||
<script src="decorators.js"></script>
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
$(function () {
|
||||
|
||||
var Selection = clazz(Object, {
|
||||
construct: function () {
|
||||
this.data = ["value1", "value2"]
|
||||
},
|
||||
render: function () {
|
||||
|
||||
var markup = "<ul>";
|
||||
for (var i = 0; i < this.data.length; i++) {
|
||||
markup += "<li>" + this.renderItem(this.data[i]) + "</li>";
|
||||
}
|
||||
markup += "</ul>";
|
||||
return markup;
|
||||
},
|
||||
renderItem: function (item) {
|
||||
return item;
|
||||
},
|
||||
bind: function (container) {
|
||||
$(container).on("click", "li", function () {
|
||||
alert("clicked: " + $(this).text());
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
var ClearExtension = clazz(Object, {
|
||||
construct: function (opts) {
|
||||
this.opts = opts;
|
||||
},
|
||||
|
||||
renderItem: function (item) {
|
||||
var markup = this.decorated(item);
|
||||
|
||||
if (this.opts.position === "right") {
|
||||
markup += " <a href='#' class='clear'>x</a>";
|
||||
} else {
|
||||
markup = " <a href='#' class='clear'>x</a>" + markup;
|
||||
}
|
||||
return markup;
|
||||
},
|
||||
bind: function (container) {
|
||||
this.decorated(container);
|
||||
container.on("click", "a.clear", function (e) {
|
||||
alert("clear: " + $(this).parents("li").text());
|
||||
e.stopPropagation();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var SortableExtension = clazz(Object, {
|
||||
bind: function (container) {
|
||||
this.decorated(container);
|
||||
$(container).find("ul").sortable().bind('sortupdate', function () {
|
||||
alert("sorted");
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var FooterExtension=clazz(Object, {
|
||||
render: function() {
|
||||
return this.decorated()+"<div>I am a footer</div>";
|
||||
}
|
||||
});
|
||||
|
||||
var selection = new Selection();
|
||||
|
||||
selection
|
||||
.decorateWith(new ClearExtension({position: "right"}))
|
||||
.decorateWith(new SortableExtension())
|
||||
.decorateWith(new FooterExtension());
|
||||
|
||||
var markup = selection.render();
|
||||
$("#container").html(markup);
|
||||
selection.bind($("#container"));
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<div id="container"></div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
@ -1,95 +0,0 @@
|
||||
var clazz = (function () {
|
||||
|
||||
var creatingPrototype = {};
|
||||
|
||||
var methods = function (object) {
|
||||
var methods = {};
|
||||
var proto = object.__proto__;
|
||||
while (proto !== Object.prototype) {
|
||||
for (var methodName in proto) {
|
||||
if (!methods[methodName] && typeof(proto[methodName]) === "function") {
|
||||
methods[methodName] = proto[methodName];
|
||||
}
|
||||
}
|
||||
proto = proto.__proto__;
|
||||
|
||||
}
|
||||
return methods;
|
||||
}
|
||||
|
||||
var decorateWith = function (decorator) {
|
||||
var decoratorMethods = methods(decorator);
|
||||
for (var methodName in decoratorMethods) {
|
||||
var decoratorMethod = decoratorMethods[methodName];
|
||||
if (typeof(decoratorMethod) === "function" && !(methodName === "construct" || methodName.name === "onDelegateAttached" || methodName === "decorateWith")) {
|
||||
this[methodName] = (function (prototype, methodName, method, decorator) {
|
||||
return function () {
|
||||
var delegate = this;
|
||||
try {
|
||||
decorator.decorated = function () {
|
||||
return prototype.apply(delegate, arguments);
|
||||
}
|
||||
return method.apply(decorator, arguments);
|
||||
} finally {
|
||||
delete decorator.decorated;
|
||||
}
|
||||
};
|
||||
})(this[methodName], methodName, decoratorMethod, decorator);
|
||||
this[methodName].displayName = methodName + "#decorator";
|
||||
}
|
||||
}
|
||||
|
||||
if (decorator.onDelegateAttached) {
|
||||
decorator.onDelegateAttached(this);
|
||||
}
|
||||
|
||||
decorator.delegate = this;
|
||||
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
return function (SuperClass, methods) {
|
||||
|
||||
var constructor = function (arg) {
|
||||
if (arg === creatingPrototype) {
|
||||
return;
|
||||
}
|
||||
if (this.construct) {
|
||||
this.construct.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
constructor.prototype = SuperClass !== Object ? new SuperClass(creatingPrototype) : new SuperClass;
|
||||
|
||||
for (var methodName in methods) {
|
||||
|
||||
constructor.prototype[methodName] = (function (prototype, methodName, method) {
|
||||
return function () {
|
||||
var currentSuper = this.super;
|
||||
try {
|
||||
this.super = prototype;
|
||||
return method.apply(this, arguments);
|
||||
} finally {
|
||||
this.super = currentSuper;
|
||||
}
|
||||
};
|
||||
})(constructor.prototype[methodName], methodName, methods[methodName]);
|
||||
|
||||
constructor.prototype[methodName].displayName = methodName;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (!constructor.prototype.decorateWith) {
|
||||
constructor.prototype.decorateWith = decorateWith;
|
||||
}
|
||||
|
||||
|
||||
return constructor;
|
||||
|
||||
}
|
||||
})();
|
||||
|
||||
|
9111
playground/decorators/jquery-2.1.0.js
vendored
9111
playground/decorators/jquery-2.1.0.js
vendored
File diff suppressed because it is too large
Load Diff
@ -1,81 +0,0 @@
|
||||
/*
|
||||
* HTML5 Sortable jQuery Plugin
|
||||
* http://farhadi.ir/projects/html5sortable
|
||||
*
|
||||
* Copyright 2012, Ali Farhadi
|
||||
* Released under the MIT license.
|
||||
*/
|
||||
(function($) {
|
||||
var dragging, placeholders = $();
|
||||
$.fn.sortable = function(options) {
|
||||
var method = String(options);
|
||||
options = $.extend({
|
||||
connectWith: false
|
||||
}, options);
|
||||
return this.each(function() {
|
||||
if (/^enable|disable|destroy$/.test(method)) {
|
||||
var items = $(this).children($(this).data('items')).attr('draggable', method == 'enable');
|
||||
if (method == 'destroy') {
|
||||
items.add(this).removeData('connectWith items')
|
||||
.off('dragstart.h5s dragend.h5s selectstart.h5s dragover.h5s dragenter.h5s drop.h5s');
|
||||
}
|
||||
return;
|
||||
}
|
||||
var isHandle, index, items = $(this).children(options.items);
|
||||
var placeholder = $('<' + (/^ul|ol$/i.test(this.tagName) ? 'li' : 'div') + ' class="sortable-placeholder">');
|
||||
items.find(options.handle).mousedown(function() {
|
||||
isHandle = true;
|
||||
}).mouseup(function() {
|
||||
isHandle = false;
|
||||
});
|
||||
$(this).data('items', options.items)
|
||||
placeholders = placeholders.add(placeholder);
|
||||
if (options.connectWith) {
|
||||
$(options.connectWith).add(this).data('connectWith', options.connectWith);
|
||||
}
|
||||
items.attr('draggable', 'true').on('dragstart.h5s', function(e) {
|
||||
if (options.handle && !isHandle) {
|
||||
return false;
|
||||
}
|
||||
isHandle = false;
|
||||
var dt = e.originalEvent.dataTransfer;
|
||||
dt.effectAllowed = 'move';
|
||||
dt.setData('Text', 'dummy');
|
||||
index = (dragging = $(this)).addClass('sortable-dragging').index();
|
||||
}).on('dragend.h5s', function() {
|
||||
dragging.removeClass('sortable-dragging').show();
|
||||
placeholders.detach();
|
||||
if (index != dragging.index()) {
|
||||
items.parent().trigger('sortupdate', {item: dragging});
|
||||
}
|
||||
dragging = null;
|
||||
}).not('a[href], img').on('selectstart.h5s', function() {
|
||||
this.dragDrop && this.dragDrop();
|
||||
return false;
|
||||
}).end().add([this, placeholder]).on('dragover.h5s dragenter.h5s drop.h5s', function(e) {
|
||||
if (!items.is(dragging) && options.connectWith !== $(dragging).parent().data('connectWith')) {
|
||||
return true;
|
||||
}
|
||||
if (e.type == 'drop') {
|
||||
e.stopPropagation();
|
||||
placeholders.filter(':visible').after(dragging);
|
||||
return false;
|
||||
}
|
||||
e.preventDefault();
|
||||
e.originalEvent.dataTransfer.dropEffect = 'move';
|
||||
if (items.is(this)) {
|
||||
if (options.forcePlaceholderSize) {
|
||||
placeholder.height(dragging.outerHeight());
|
||||
}
|
||||
dragging.hide();
|
||||
$(this)[placeholder.index() < $(this).index() ? 'after' : 'before'](placeholder);
|
||||
placeholders.not(placeholder).detach();
|
||||
} else if (!placeholders.is(this) && !$(this).children(options.items).length) {
|
||||
placeholders.detach();
|
||||
$(this).append(placeholder);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
});
|
||||
};
|
||||
})(jQuery);
|
@ -1,237 +0,0 @@
|
||||
/*!
|
||||
* QUnit 1.14.0
|
||||
* http://qunitjs.com/
|
||||
*
|
||||
* Copyright 2013 jQuery Foundation and other contributors
|
||||
* Released under the MIT license
|
||||
* http://jquery.org/license
|
||||
*
|
||||
* Date: 2014-01-31T16:40Z
|
||||
*/
|
||||
|
||||
/** Font Family and Sizes */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult {
|
||||
font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; }
|
||||
#qunit-tests { font-size: smaller; }
|
||||
|
||||
|
||||
/** Resets */
|
||||
|
||||
#qunit-tests, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult, #qunit-modulefilter {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
/** Header */
|
||||
|
||||
#qunit-header {
|
||||
padding: 0.5em 0 0.5em 1em;
|
||||
|
||||
color: #8699A4;
|
||||
background-color: #0D3349;
|
||||
|
||||
font-size: 1.5em;
|
||||
line-height: 1em;
|
||||
font-weight: 400;
|
||||
|
||||
border-radius: 5px 5px 0 0;
|
||||
}
|
||||
|
||||
#qunit-header a {
|
||||
text-decoration: none;
|
||||
color: #C2CCD1;
|
||||
}
|
||||
|
||||
#qunit-header a:hover,
|
||||
#qunit-header a:focus {
|
||||
color: #FFF;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar label {
|
||||
display: inline-block;
|
||||
padding: 0 0.5em 0 0.1em;
|
||||
}
|
||||
|
||||
#qunit-banner {
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
#qunit-testrunner-toolbar {
|
||||
padding: 0.5em 0 0.5em 2em;
|
||||
color: #5E740B;
|
||||
background-color: #EEE;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#qunit-userAgent {
|
||||
padding: 0.5em 0 0.5em 2.5em;
|
||||
background-color: #2B81AF;
|
||||
color: #FFF;
|
||||
text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px;
|
||||
}
|
||||
|
||||
#qunit-modulefilter-container {
|
||||
float: right;
|
||||
}
|
||||
|
||||
/** Tests: Pass/Fail */
|
||||
|
||||
#qunit-tests {
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests li {
|
||||
padding: 0.4em 0.5em 0.4em 2.5em;
|
||||
border-bottom: 1px solid #FFF;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
#qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests li strong {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#qunit-tests li a {
|
||||
padding: 0.5em;
|
||||
color: #C2CCD1;
|
||||
text-decoration: none;
|
||||
}
|
||||
#qunit-tests li a:hover,
|
||||
#qunit-tests li a:focus {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
#qunit-tests li .runtime {
|
||||
float: right;
|
||||
font-size: smaller;
|
||||
}
|
||||
|
||||
.qunit-assert-list {
|
||||
margin-top: 0.5em;
|
||||
padding: 0.5em;
|
||||
|
||||
background-color: #FFF;
|
||||
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.qunit-collapsed {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#qunit-tests table {
|
||||
border-collapse: collapse;
|
||||
margin-top: 0.2em;
|
||||
}
|
||||
|
||||
#qunit-tests th {
|
||||
text-align: right;
|
||||
vertical-align: top;
|
||||
padding: 0 0.5em 0 0;
|
||||
}
|
||||
|
||||
#qunit-tests td {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
#qunit-tests pre {
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
|
||||
#qunit-tests del {
|
||||
background-color: #E0F2BE;
|
||||
color: #374E0C;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#qunit-tests ins {
|
||||
background-color: #FFCACA;
|
||||
color: #500;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/*** Test Counts */
|
||||
|
||||
#qunit-tests b.counts { color: #000; }
|
||||
#qunit-tests b.passed { color: #5E740B; }
|
||||
#qunit-tests b.failed { color: #710909; }
|
||||
|
||||
#qunit-tests li li {
|
||||
padding: 5px;
|
||||
background-color: #FFF;
|
||||
border-bottom: none;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
/*** Passing Styles */
|
||||
|
||||
#qunit-tests li li.pass {
|
||||
color: #3C510C;
|
||||
background-color: #FFF;
|
||||
border-left: 10px solid #C6E746;
|
||||
}
|
||||
|
||||
#qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; }
|
||||
#qunit-tests .pass .test-name { color: #366097; }
|
||||
|
||||
#qunit-tests .pass .test-actual,
|
||||
#qunit-tests .pass .test-expected { color: #999; }
|
||||
|
||||
#qunit-banner.qunit-pass { background-color: #C6E746; }
|
||||
|
||||
/*** Failing Styles */
|
||||
|
||||
#qunit-tests li li.fail {
|
||||
color: #710909;
|
||||
background-color: #FFF;
|
||||
border-left: 10px solid #EE5757;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
#qunit-tests > li:last-child {
|
||||
border-radius: 0 0 5px 5px;
|
||||
}
|
||||
|
||||
#qunit-tests .fail { color: #000; background-color: #EE5757; }
|
||||
#qunit-tests .fail .test-name,
|
||||
#qunit-tests .fail .module-name { color: #000; }
|
||||
|
||||
#qunit-tests .fail .test-actual { color: #EE5757; }
|
||||
#qunit-tests .fail .test-expected { color: #008000; }
|
||||
|
||||
#qunit-banner.qunit-fail { background-color: #EE5757; }
|
||||
|
||||
|
||||
/** Result */
|
||||
|
||||
#qunit-testresult {
|
||||
padding: 0.5em 0.5em 0.5em 2.5em;
|
||||
|
||||
color: #2B81AF;
|
||||
background-color: #D2E0E6;
|
||||
|
||||
border-bottom: 1px solid #FFF;
|
||||
}
|
||||
#qunit-testresult .module-name {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
/** Fixture */
|
||||
|
||||
#qunit-fixture {
|
||||
position: absolute;
|
||||
top: -10000px;
|
||||
left: -10000px;
|
||||
width: 1000px;
|
||||
height: 1000px;
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -1,25 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="qunit-1.14.0.css">
|
||||
<script src="jquery-2.1.0.js" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<script>
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
<script src="qunit-1.14.0.js"></script>
|
||||
<script src="decorators.js"></script>
|
||||
<script src="decorator_tests.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
9111
playground/mobile/jquery-2.1.0.js
vendored
9111
playground/mobile/jquery-2.1.0.js
vendored
File diff suppressed because it is too large
Load Diff
@ -1,157 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
|
||||
.dropdown {
|
||||
background-color: green;
|
||||
border: 3px solid red;
|
||||
position: fixed;
|
||||
padding: 10px;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
.search input {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.results {
|
||||
overflow: scroll;
|
||||
border: 1px solid blue;
|
||||
}
|
||||
|
||||
.results ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.results li {
|
||||
border: 1px solid red;
|
||||
height: 10vh;
|
||||
height: 40px;
|
||||
margin: 3px;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<script src="jquery-2.1.0.js"></script>
|
||||
<script>
|
||||
$(function () {
|
||||
|
||||
function adjust() {
|
||||
var height = $(".dropdown").height();
|
||||
var searchHeight = $(".search").height();
|
||||
var needed = height - searchHeight;
|
||||
console.log(height, searchHeight, needed);
|
||||
$(".results").css({maxHeight: needed});
|
||||
}
|
||||
|
||||
|
||||
$(".dropdown")
|
||||
.on("scroll", function (e) {
|
||||
e.preventDefault();
|
||||
return false;
|
||||
});
|
||||
|
||||
$(".search input").on("blur", function() {
|
||||
$(".dropdown").hide();
|
||||
})
|
||||
|
||||
|
||||
//window.setInterval(adjust, 100);
|
||||
|
||||
$("#trigger").on("focus", function(e) {
|
||||
$(".dropdown").show();
|
||||
$(".search input").focus();
|
||||
$("head").append('<meta name = "viewport" content = "user-scalable=no, width=device-width, initial-scale=1.0, maximium-scale=1.0, minimum-scale=1.0"/>');
|
||||
adjust();
|
||||
});
|
||||
|
||||
$("#resize").on("click", adjust);
|
||||
|
||||
var a = 0;
|
||||
$(window).on("resize", function () {
|
||||
adjust();
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<form>
|
||||
<p>
|
||||
<input type="text"/>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text"/>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text" id="trigger"/>
|
||||
</p>
|
||||
<p>
|
||||
<input type="text"/>
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<div class="dropdown" style="display:none">
|
||||
|
||||
<div class="result-list">
|
||||
<div class="search">
|
||||
<a href="#">reload</a><span id="message"></span><a href="#" id="resize">resize</a>
|
||||
<input type="text"/>
|
||||
</div>
|
||||
<div class="results">
|
||||
<ul>
|
||||
<li>Result 1</li>
|
||||
<li>Result 2</li>
|
||||
<li>Result 3</li>
|
||||
<li>Result 4</li>
|
||||
<li>Result 5</li>
|
||||
<li>Result 6</li>
|
||||
<li>Result 7</li>
|
||||
<li>Result 8</li>
|
||||
<li>Result 9</li>
|
||||
<li>Result 10</li>
|
||||
<li>Result 11</li>
|
||||
<li>Result 12</li>
|
||||
<li>Result 13</li>
|
||||
<li>Result 14</li>
|
||||
<li>Result 15</li>
|
||||
<li>Result 16</li>
|
||||
<li>Result 17</li>
|
||||
<li>Result 18</li>
|
||||
<li>Result 19</li>
|
||||
<li>Result 20</li>
|
||||
<li>Result 21</li>
|
||||
<li>Result 22</li>
|
||||
<li>Result 23</li>
|
||||
<li>Result 24</li>
|
||||
<li>Result 25</li>
|
||||
<li>Result 26</li>
|
||||
<li>Result 27</li>
|
||||
<li>Result 28</li>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user