@whitesev/domutils 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.amd.js CHANGED
@@ -830,8 +830,11 @@ define((function () { 'use strict';
830
830
  **/
831
831
  listenKeyboard(target, eventName = "keypress", callback, options) {
832
832
  let keyboardEventCallBack = function (event) {
833
+ /** 键名 */
833
834
  let keyName = event.key || event.code;
835
+ /** 键值 */
834
836
  let keyValue = event.charCode || event.keyCode || event.which;
837
+ /** 组合键列表 */
835
838
  let otherCodeList = [];
836
839
  if (event.ctrlKey) {
837
840
  otherCodeList.push("ctrl");
@@ -846,7 +849,7 @@ define((function () { 'use strict';
846
849
  otherCodeList.push("shift");
847
850
  }
848
851
  if (typeof callback === "function") {
849
- callback(keyName, keyValue.toString(), otherCodeList, event);
852
+ callback(keyName, keyValue, otherCodeList, event);
850
853
  }
851
854
  };
852
855
  this.on(target, eventName, keyboardEventCallBack, options);
@@ -863,7 +866,7 @@ define((function () { 'use strict';
863
866
  super(option);
864
867
  }
865
868
  /** 版本号 */
866
- version = "2024.8.30";
869
+ version = "2024.9.23";
867
870
  attr(element, attrName, attrValue) {
868
871
  let DOMUtilsContext = this;
869
872
  if (typeof element === "string") {
@@ -1281,7 +1284,13 @@ define((function () { 'use strict';
1281
1284
  element.insertAdjacentHTML("afterbegin", content);
1282
1285
  }
1283
1286
  else {
1284
- element.insertBefore(content, element.firstChild);
1287
+ let $firstChild = element.firstChild;
1288
+ if ($firstChild == null) {
1289
+ element.prepend(content);
1290
+ }
1291
+ else {
1292
+ element.insertBefore(content, element.firstChild);
1293
+ }
1285
1294
  }
1286
1295
  }
1287
1296
  /**
@@ -1305,7 +1314,15 @@ define((function () { 'use strict';
1305
1314
  element.insertAdjacentHTML("afterend", content);
1306
1315
  }
1307
1316
  else {
1308
- element.parentElement.insertBefore(content, element.nextSibling);
1317
+ let $parent = element.parentElement;
1318
+ let $nextSlibling = element.nextSibling;
1319
+ if (!$parent || $nextSlibling) {
1320
+ // 任意一个不行
1321
+ element.after(content);
1322
+ }
1323
+ else {
1324
+ element.parentElement.insertBefore(content, element.nextSibling);
1325
+ }
1309
1326
  }
1310
1327
  }
1311
1328
  /**
@@ -1329,7 +1346,13 @@ define((function () { 'use strict';
1329
1346
  element.insertAdjacentHTML("beforebegin", content);
1330
1347
  }
1331
1348
  else {
1332
- element.parentElement.insertBefore(content, element);
1349
+ let $parent = element.parentElement;
1350
+ if (!$parent) {
1351
+ element.before(content);
1352
+ }
1353
+ else {
1354
+ $parent.insertBefore(content, element);
1355
+ }
1333
1356
  }
1334
1357
  }
1335
1358
  /**