Skip to content

Commit d375e63

Browse files
Bumped version to 2.3.8
1 parent 6ab74a5 commit d375e63

4 files changed

Lines changed: 66 additions & 36 deletions

File tree

dist/cash.esm.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -902,12 +902,15 @@ fn.serialize = function () {
902902
fn.val = function (value) {
903903
if (value === undefined) return this[0] && getValue(this[0]);
904904
return this.each(function (i, ele) {
905-
if (selectMultipleRe.test(ele.type) && isArray(value)) {
905+
var isMultiple = selectMultipleRe.test(ele.type),
906+
eleValue = value === null ? isMultiple ? [] : '' : value;
907+
908+
if (isMultiple && isArray(eleValue)) {
906909
each(ele.options, function (option) {
907-
option.selected = value.indexOf(option.value) >= 0;
910+
option.selected = eleValue.indexOf(option.value) >= 0;
908911
});
909912
} else {
910-
ele.value = value;
913+
ele.value = eleValue;
911914
}
912915
});
913916
}; // @optional ./serialize.js
@@ -937,22 +940,33 @@ fn.detach = function () {
937940
// @require manipulation/detach.js
938941

939942

940-
var fragment;
941-
942-
function initFragment() {
943-
if (fragment) return;
944-
fragment = doc.implementation.createHTMLDocument('');
945-
var base = fragment.createElement('base');
946-
base.href = doc.location.href;
947-
fragment.head.appendChild(base);
943+
var fragmentRe = /^\s*<(\w+)[^>]*>/,
944+
singleTagRe = /^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/;
945+
var containers;
946+
947+
function initContainers() {
948+
if (containers) return;
949+
var table = doc.createElement('table'),
950+
tr = doc.createElement('tr');
951+
containers = {
952+
'*': doc.createElement('div'),
953+
tr: doc.createElement('tbody'),
954+
td: tr,
955+
th: tr,
956+
thead: table,
957+
tbody: table,
958+
tfoot: table
959+
};
948960
}
949961

950962
function parseHTML(html) {
951-
//FIXME: `<tr></tr>` can't be parsed with this
952-
initFragment();
953-
if (!isString(html)) html = '';
954-
fragment.body.innerHTML = html;
955-
return $(fragment.body.childNodes).detach().get();
963+
initContainers();
964+
if (!isString(html)) return [];
965+
if (singleTagRe.test(html)) return [doc.createElement(RegExp.$1)];
966+
var fragment = fragmentRe.test(html) && RegExp.$1,
967+
container = containers[fragment] || containers['*'];
968+
container.innerHTML = html;
969+
return $(container.childNodes).detach().get();
956970
}
957971

958972
cash.parseHTML = parseHTML; // @optional ./camel_case.js
@@ -995,6 +1009,7 @@ function insertElement(ele, child, prepend) {
9951009

9961010

9971011
function insertContent(parent, child, prepend) {
1012+
if (child === undefined) return;
9981013
var isStr = isString(child);
9991014

10001015
if (!isStr && child.length) {

dist/cash.js

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -913,12 +913,15 @@ fn.serialize = function () {
913913
fn.val = function (value) {
914914
if (value === undefined) return this[0] && getValue(this[0]);
915915
return this.each(function (i, ele) {
916-
if (selectMultipleRe.test(ele.type) && isArray(value)) {
916+
var isMultiple = selectMultipleRe.test(ele.type),
917+
eleValue = value === null ? isMultiple ? [] : '' : value;
918+
919+
if (isMultiple && isArray(eleValue)) {
917920
each(ele.options, function (option) {
918-
option.selected = value.indexOf(option.value) >= 0;
921+
option.selected = eleValue.indexOf(option.value) >= 0;
919922
});
920923
} else {
921-
ele.value = value;
924+
ele.value = eleValue;
922925
}
923926
});
924927
}; // @optional ./serialize.js
@@ -948,22 +951,33 @@ fn.detach = function () {
948951
// @require manipulation/detach.js
949952

950953

951-
var fragment;
952-
953-
function initFragment() {
954-
if (fragment) return;
955-
fragment = doc.implementation.createHTMLDocument('');
956-
var base = fragment.createElement('base');
957-
base.href = doc.location.href;
958-
fragment.head.appendChild(base);
954+
var fragmentRe = /^\s*<(\w+)[^>]*>/,
955+
singleTagRe = /^\s*<(\w+)\s*\/?>(?:<\/\1>)?\s*$/;
956+
var containers;
957+
958+
function initContainers() {
959+
if (containers) return;
960+
var table = doc.createElement('table'),
961+
tr = doc.createElement('tr');
962+
containers = {
963+
'*': doc.createElement('div'),
964+
tr: doc.createElement('tbody'),
965+
td: tr,
966+
th: tr,
967+
thead: table,
968+
tbody: table,
969+
tfoot: table
970+
};
959971
}
960972

961973
function parseHTML(html) {
962-
//FIXME: `<tr></tr>` can't be parsed with this
963-
initFragment();
964-
if (!isString(html)) html = '';
965-
fragment.body.innerHTML = html;
966-
return $(fragment.body.childNodes).detach().get();
974+
initContainers();
975+
if (!isString(html)) return [];
976+
if (singleTagRe.test(html)) return [doc.createElement(RegExp.$1)];
977+
var fragment = fragmentRe.test(html) && RegExp.$1,
978+
container = containers[fragment] || containers['*'];
979+
container.innerHTML = html;
980+
return $(container.childNodes).detach().get();
967981
}
968982

969983
cash.parseHTML = parseHTML; // @optional ./camel_case.js
@@ -1006,6 +1020,7 @@ function insertElement(ele, child, prepend) {
10061020

10071021

10081022
function insertContent(parent, child, prepend) {
1023+
if (child === undefined) return;
10091024
var isStr = isString(child);
10101025

10111026
if (!isStr && child.length) {

dist/cash.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "cash-dom",
33
"description": "An absurdly small jQuery alternative for modern browsers.",
4-
"version": "2.3.7",
4+
"version": "2.3.8",
55
"license": "MIT",
66
"main": "./dist/cash.js",
77
"module": "./dist/cash.esm.js",

0 commit comments

Comments
 (0)