@peter-debugging-2/peter-minimal-jquery 1.0.0 → 2.0.0

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/README.md CHANGED
@@ -8,4 +8,11 @@ Just include this package link as a script tag, this should be delivered via *js
8
8
  - scripts npm to build & bundle with mode
9
9
  - add .npmignore to prevent node_modules being push to npm
10
10
  - change package name in package.json including username, also mind the version
11
- - use ```npm pushblish --access public``` to publish
11
+ - use ```npm pushblish --access public``` to publish
12
+
13
+
14
+ ## New features in version 2.0.0
15
+ - widget factory to standardize ways to create widget and setup life cycle
16
+ - widget inheritance and extense
17
+ - friendly interface via widget bridge
18
+ - set arbitrary data associated with element via Data
package/dist/main.js CHANGED
@@ -2,6 +2,53 @@
2
2
  /******/ "use strict";
3
3
  /******/ var __webpack_modules__ = ({
4
4
 
5
+ /***/ "./src/data.js"
6
+ /*!*********************!*\
7
+ !*** ./src/data.js ***!
8
+ \*********************/
9
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
10
+
11
+ __webpack_require__.r(__webpack_exports__);
12
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
13
+ /* harmony export */ Data: () => (/* binding */ Data),
14
+ /* harmony export */ dataUser: () => (/* binding */ dataUser)
15
+ /* harmony export */ });
16
+ function Data() {
17
+ this.store = new WeakMap();
18
+ }
19
+
20
+ Data.prototype = {
21
+ set(element, key, value) {
22
+ if (!this.store.has(element))
23
+ this.store.set(element, {});
24
+ this.store.get(element)[key] = value;
25
+ },
26
+ get(element, key) {
27
+ if (!this.store.has(element)) return undefined;
28
+ if (key === undefined) return this.store.get(element);
29
+ return this.store.get(element)[key];
30
+ },
31
+ hasData(element) {
32
+ return this.store.get(element);
33
+ },
34
+ remove(element, key) {
35
+ if (!this.store.has(element)) return;
36
+ if (key === undefined)
37
+ this.store.delete(element);
38
+ else
39
+ delete this.store.get(element)[key];
40
+ },
41
+ access(element, key, value) {
42
+ if (value === undefined) return this.get(element, key);
43
+ this.set(element, key, value);
44
+ return value;
45
+ }
46
+ }
47
+
48
+ const dataUser = new Data();
49
+
50
+ /***/ },
51
+
5
52
  /***/ "./src/utils.js"
6
53
  /*!**********************!*\
7
54
  !*** ./src/utils.js ***!
@@ -15,23 +62,24 @@ __webpack_require__.r(__webpack_exports__);
15
62
  /* harmony export */ });
16
63
  function deepExtend() {
17
64
  let target = arguments[0] || {};
18
- let otherArgs = Array.prototype.slice.apply(arguments, 1); //other options to override
65
+ let otherArgs = Array.prototype.slice.apply(arguments, [1]); //other options to override
19
66
  for (const obj of otherArgs) {
20
67
  if (!obj) continue;
21
68
  for (const [key, value] of Object.entries(obj)) {
22
69
  switch (Object.prototype.toString.call(value)) {
23
70
  case '[object Object]':
24
71
  target[key] = target[key] || {};
25
- target[key] = jQuery.fn.extend(target[key], value);
72
+ target[key] = deepExtend(target[key], value);
26
73
  break;
27
74
  case '[object Array]': //review case array
28
- target[key] = jQuery.fn.extend(new Array(value.length), value);
75
+ target[key] = deepExtend(new Array(value.length), value);
29
76
  break;
30
77
  default:
31
78
  target[key] = value;
32
79
  }
33
80
  }
34
81
  }
82
+ return target;
35
83
  }
36
84
 
37
85
  function shallowExtend(target, ...sources) {
@@ -41,8 +89,50 @@ function shallowExtend(target, ...sources) {
41
89
  target[key] = value;
42
90
  }
43
91
  }
92
+ return target;
44
93
  }
45
94
 
95
+ /***/ },
96
+
97
+ /***/ "./src/widget.js"
98
+ /*!***********************!*\
99
+ !*** ./src/widget.js ***!
100
+ \***********************/
101
+ (__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) {
102
+
103
+ __webpack_require__.r(__webpack_exports__);
104
+ /* harmony export */ __webpack_require__.d(__webpack_exports__, {
105
+ /* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__)
106
+ /* harmony export */ });
107
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./src/utils.js");
108
+
109
+ let Widget = function() {};
110
+ Widget.prototype = {
111
+ options: {
112
+ classes: {},
113
+ disabled: false,
114
+ },
115
+
116
+ _createWidget: function(options, element) {
117
+ this.options = (0,_utils_js__WEBPACK_IMPORTED_MODULE_0__.deepExtend)({}, this.options, options);
118
+ this._create();
119
+ this._init();
120
+ },
121
+ _create: function() {},
122
+ _init: function() {},
123
+ _destroy: function() {},
124
+ _setOption: function(key, value) {
125
+ this.options[key] = value;
126
+ return this;
127
+ },
128
+ _setOptions: function(options) {
129
+ for (const key in options )
130
+ this._setOption( key, options[key] );
131
+ return this;
132
+ }
133
+ }
134
+ /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (Widget);
135
+
46
136
  /***/ }
47
137
 
48
138
  /******/ });
@@ -115,6 +205,9 @@ var __webpack_exports__ = {};
115
205
  \*********************/
116
206
  __webpack_require__.r(__webpack_exports__);
117
207
  /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./utils.js */ "./src/utils.js");
208
+ /* harmony import */ var _data_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./data.js */ "./src/data.js");
209
+ /* harmony import */ var _widget_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./widget.js */ "./src/widget.js");
210
+
118
211
 
119
212
 
120
213
 
@@ -253,6 +346,18 @@ __webpack_require__.r(__webpack_exports__);
253
346
  const element = this;
254
347
  element.classList.toggle(className);
255
348
  });
349
+ },
350
+ data: function(name, value) {
351
+ const jQueryObj = this;
352
+ const element = jQueryObj[0];
353
+ if (name === undefined) return _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.get(element);
354
+ if (value === undefined) return _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.access(element, name);
355
+ else {
356
+ return jQuery.each(jQueryObj, function() {
357
+ const element = this;
358
+ _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.access(element, name, value);
359
+ });
360
+ }
256
361
  }
257
362
  }
258
363
  jQuery.shallowExtend = _utils_js__WEBPACK_IMPORTED_MODULE_0__.shallowExtend;
@@ -267,7 +372,125 @@ __webpack_require__.r(__webpack_exports__);
267
372
  if (callback.call(target[key], key, target[key]) === false) break;
268
373
  }
269
374
  return target; //jQuery chainable
375
+ };
376
+ //TODO: jQuery.extends({ something: ...}) will extend the jQuery itself, so we can import jQuery, and add functionality in different module, more scalable
377
+ jQuery.hasData = function(element) {
378
+ return _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.hasData(element);
379
+ };
380
+ jQuery.data = function(element, name, value) {
381
+ return _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.access(element, name, value);
382
+ };
383
+ jQuery.removeData = function(element, name) {
384
+ _data_js__WEBPACK_IMPORTED_MODULE_1__.dataUser.remove(element, name);
385
+ };
386
+ /** This method is ensure we have widgetName => we will have $(element).widgetFullName() getter, setter */
387
+ jQuery.widgetBridge = function(name, constructorFn) {
388
+ let fullName = constructorFn.prototype.widgetFullName || name;
389
+ jQuery.fn[name] = function(options) {
390
+ let isMethodCall = typeof options === "string";
391
+ const jQueryObj = this;
392
+ const args = Array.prototype.slice.call(arguments, 1);
393
+ let returnValue = jQueryObj;
394
+ if (!isMethodCall) { //is init
395
+ jQuery.each(jQueryObj, function() {
396
+ const element = this;
397
+ const instance = jQuery.data(element, fullName);
398
+ if (!instance)
399
+ jQuery.data(this, fullName, new constructorFn(options, element));
400
+ else {
401
+ instance._setOptions(options);
402
+ if (instance._init) instance._init();
403
+ }
404
+ });
405
+ }
406
+ else { //is method call
407
+ if (!jQueryObj.length && options === 'instance') return undefined;
408
+ jQuery.each(jQueryObj, function() {
409
+ let instance = jQuery.data(this, fullName);
410
+ if (!instance) throw Error("not initialized");
411
+ if (options === 'instance') {
412
+ returnValue = instance;
413
+ return false; //exits jQuery.each
414
+ }
415
+ if (typeof instance[options] == 'function') {
416
+ returnValue = instance[options].apply(instance, args);
417
+ return false;
418
+ }
419
+ });
420
+ }
421
+ return returnValue;
422
+ }
270
423
  }
424
+ /**
425
+ * Minimal flow (mental model) $.widget():
426
+ build constructor -> set prototype chain -> wrap overridden methods -> expose $.fn.plugin
427
+ */
428
+ jQuery.widget = function(inputName, base, prototype) {
429
+ const [namespace, name] = inputName.split(".");
430
+ const fullName = `${namespace}-${name}`;
431
+ if (prototype === undefined) {
432
+ prototype = base;
433
+ base = _widget_js__WEBPACK_IMPORTED_MODULE_2__["default"];
434
+ }
435
+
436
+ jQuery[namespace] = jQuery[namespace] || {};
437
+ let constructor = jQuery[namespace][name] = function(options, element) {
438
+ //!this: Called without new
439
+ //!this._createWidget: Prototype isn’t set yet, or calling for simple inheritance
440
+ if (!this || !this._createWidget)
441
+ return new constructor( options, element );
442
+ if (arguments.length)
443
+ this._createWidget( options, element );
444
+ }
445
+
446
+ let basePrototype = new base();
447
+ //not mutate the base 's options from prototype (shared), in case options of base is from prototype
448
+ //obj.options === Base.prototype.options // ✅ true (obj not have options, but get this from its prototype)
449
+ basePrototype.options = jQuery.deepExtend({}, basePrototype.options);
450
+
451
+ let proxiedPrototype = {};
452
+ jQuery.each(prototype, function(property, value) {
453
+ if (typeof value !== "function") {
454
+ proxiedPrototype[property] = value;
455
+ return;
456
+ }
457
+ proxiedPrototype[property] = (function() {
458
+ function _super() {
459
+ return base.prototype[property].apply(this, arguments);
460
+ }
461
+
462
+ function _superApply(args) {
463
+ return base.prototype[property].apply(this, args);
464
+ }
465
+
466
+ return function() {
467
+ //this keyword in this context is the widget instance
468
+ //save these for later restore
469
+ let __super = this._super;
470
+ let __superApply = this._superApply;
471
+
472
+ this._super = _super;
473
+ this._superApply = _superApply;
474
+
475
+ const returnValue = value.apply(this, arguments); //value is a function
476
+ this._super = __super;
477
+ this._superApply = __superApply;
478
+ return returnValue;
479
+ }
480
+ })()
481
+ });
482
+
483
+ constructor.prototype = jQuery.deepExtend(basePrototype, proxiedPrototype, {
484
+ constructor: constructor,
485
+ namespace: namespace,
486
+ widgetName: name,
487
+ widgetFullName: fullName
488
+ });
489
+
490
+ jQuery.widgetBridge( name, constructor );
491
+ return constructor;
492
+ }
493
+
271
494
 
272
495
  //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....
273
496
  // jQuery.fn = jQuery.prototype = {
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"main.js","mappings":";;;;;;;;;;;;;;;AAAO;AACP;AACA,+DAA+D;AAC/D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;UC5BA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WC5BA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;ACNA;AACuD;AACvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gEAAgE;AAChE;AACA,6BAA6B;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8DAA8D;AAC9D;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,mCAAmC;AACnC;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT;AACA;AACA,yCAAyC;AACzC;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,2CAA2C;AAC3C;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA,2BAA2B,oDAAa;AACxC,wBAAwB,iDAAU;AAClC;AACA;AACA,4BAA4B,mBAAmB;AAC/C,6EAA6E;AAC7E;AACA;AACA;AACA;AACA;AACA,uBAAuB;AACvB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,wBAAwB,qBAAqB","sources":["webpack://minimal-jquery/./src/utils.js","webpack://minimal-jquery/webpack/bootstrap","webpack://minimal-jquery/webpack/runtime/define property getters","webpack://minimal-jquery/webpack/runtime/hasOwnProperty shorthand","webpack://minimal-jquery/webpack/runtime/make namespace object","webpack://minimal-jquery/./src/core.js"],"sourcesContent":["export function deepExtend() {\r\n let target = arguments[0] || {};\r\n let otherArgs = Array.prototype.slice.apply(arguments, 1); //other options to override\r\n for (const obj of otherArgs) {\r\n if (!obj) continue;\r\n for (const [key, value] of Object.entries(obj)) {\r\n switch (Object.prototype.toString.call(value)) {\r\n case '[object Object]':\r\n target[key] = target[key] || {};\r\n target[key] = jQuery.fn.extend(target[key], value);\r\n break;\r\n case '[object Array]': //review case array\r\n target[key] = jQuery.fn.extend(new Array(value.length), value);\r\n break;\r\n default:\r\n target[key] = value;\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport function shallowExtend(target, ...sources) {\r\n for (const src of sources) {\r\n if (!src) continue;\r\n for (const [key, value] of Object.entries(src)) {\r\n target[key] = value;\r\n }\r\n }\r\n}","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\r\nimport { shallowExtend, deepExtend } from \"./utils.js\";\r\n\r\n(function(global) {\r\n function jQueryObject(selector) {\r\n if (selector.nodeType) {\r\n this.length = 1;\r\n this[0] = selector;\r\n }\r\n else if (typeof selector == 'string') {\r\n let nodeList = document.querySelectorAll(selector); //an array of nodelist => change it to jquery object\r\n let index = 0;\r\n this.length = 0; //Data in constructor, methods in prototype ✅\r\n for (let node of nodeList) {\r\n this[index] = node;\r\n index += 1;\r\n this.length += 1;\r\n }\r\n }\r\n else \r\n return;\r\n //new jQueryObject implicitly return this\r\n }\r\n\r\n let jQuery = (selector) => new jQueryObject(selector);\r\n jQueryObject.prototype = jQuery.fn = jQuery.prototype = { //alias to prototype\r\n ready: function(callback) {\r\n let jQueryObj = this;\r\n const isReady = Array.prototype.some.call(jQueryObj, function(element) {\r\n return element.readyState != null && element.readyState != \"loading\";\r\n });\r\n if (isReady) {\r\n callback();\r\n }\r\n else {\r\n jQueryObj.on('DOMContentLoaded', callback);\r\n }\r\n },\r\n each: function(callback) { //suger syntax, now callback exec for each match element of jQuery instance and chainable\r\n return jQuery.each(this, callback);\r\n },\r\n on: function(event, callback) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.addEventListener(event, function(e) {\r\n callback.call(element, e)\r\n });\r\n })\r\n },\r\n text: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) { //setter\r\n const text = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.textContent = text;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].textContent;\r\n }\r\n },\r\n val: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) {\r\n const value = arguments[0];//if call arguments inside jQuery.each then it is different\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.value = value;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].value;\r\n }\r\n },\r\n css: function() {\r\n let cssCamelcaseProperty = function(cssProperty) {\r\n return cssProperty.replace(/-([a-z])/g, (fullMatch, captureCharacter) => {\r\n return captureCharacter.toUpperCase();\r\n });\r\n };\r\n const jQueryObj = this;\r\n if (arguments.length == 2) {\r\n let cssPropertyName = arguments[0];\r\n let value = arguments[1];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'object') {\r\n const cssProperties = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n for (const [cssPropertyName, value] of Object.entries(cssProperties)) {\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n }\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'string') {\r\n const cssPropertyName = arguments[0];\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n let result = getComputedStyle(jQueryObj[0])[camelProperty];\r\n return jQueryObj[0].style[camelProperty];\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n let result = jQueryObj[0].style;\r\n return result;\r\n }\r\n },\r\n hasClass: function(className) {\r\n const jQueryObj = this;\r\n const result = Array.prototype.some.call(jQueryObj, (element) => element.classList.contains(className));\r\n return result;\r\n },\r\n addClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.add(className);\r\n });\r\n },\r\n removeClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.remove(className);\r\n });\r\n },\r\n toggleClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.toggle(className);\r\n });\r\n }\r\n }\r\n jQuery.shallowExtend = shallowExtend;\r\n jQuery.deepExtend = deepExtend;\r\n jQuery.each = function(target, callback) {\r\n if (target.length > 0) {\r\n for (let i = 0; i < target.length; i++)\r\n if (callback.call(target[i], i, target[i]) === false) break; //TODO: not sure why return false will break\r\n }\r\n else {\r\n for (let key in target)\r\n if (callback.call(target[key], key, target[key]) === false) break;\r\n }\r\n return target; //jQuery chainable\r\n }\r\n\r\n //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....\r\n // jQuery.fn = jQuery.prototype = {\r\n // shallowExtend: shallowExtend,\r\n // deepExtend: deepExtend,\r\n // }\r\n\r\n global.jQuery = global.$ = jQuery;\r\n})(window)\r\n//IIFE to ensure, all var in this file not polute window global object, only jQuery & $\r\n//or could use export { jQuery, jQuery as $ }, then import these 2 from the core.js (module)\r\n"],"names":[],"ignoreList":[],"sourceRoot":""}
1
+ {"version":3,"file":"main.js","mappings":";;;;;;;;;;;;;;;AAAO;AACP;AACA;AACA;AACA;AACA;AACA;AACA,sCAAsC;AACtC;AACA,KAAK;AACL;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA;AACO,4B;;;;;;;;;;;;;;;AChCA;AACP;AACA,iEAAiE;AACjE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO;AACP;AACA;AACA;AACA;AACA;AACA;AACA;AACA,C;;;;;;;;;;;;;;;AC9BwC;AACxC;AACA;AACA;AACA,mBAAmB;AACnB;AACA,KAAK;AACL;AACA;AACA,uBAAuB,qDAAU,GAAG;AACpC;AACA;AACA,KAAK;AACL,0BAA0B;AAC1B,qBAAqB;AACrB,2BAA2B;AAC3B;AACA;AACA;AACA,KAAK;AACL;AACA;AACA;AACA;AACA;AACA;AACA,iEAAe,MAAM,E;;;;;;UC1BrB;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WC5BA;WACA;WACA;WACA;WACA,yCAAyC,wCAAwC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;WCAA;WACA;WACA;WACA,uDAAuD,iBAAiB;WACxE;WACA,gDAAgD,aAAa;WAC7D,E;;;;;;;;;;;;;;ACNA;AACuD;AAClB;AACJ;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,gEAAgE;AAChE;AACA,6BAA6B;AAC7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,8DAA8D;AAC9D;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT,mCAAmC;AACnC;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT;AACA;AACA,yCAAyC;AACzC;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA,2CAA2C;AAC3C;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA,2CAA2C,8CAAQ;AACnD,4CAA4C,8CAAQ;AACpD;AACA;AACA;AACA,oBAAoB,8CAAQ;AAC5B,iBAAiB;AACjB;AACA;AACA;AACA,2BAA2B,oDAAa;AACxC,wBAAwB,iDAAU;AAClC;AACA;AACA,4BAA4B,mBAAmB;AAC/C,6EAA6E;AAC7E;AACA;AACA;AACA;AACA;AACA,uBAAuB;AACvB;AACA,6BAA6B,eAAe;AAC5C;AACA,eAAe,8CAAQ;AACvB;AACA;AACA,eAAe,8CAAQ;AACvB;AACA;AACA,QAAQ,8CAAQ;AAChB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iCAAiC;AACjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA,mBAAmB;AACnB;AACA;AACA;AACA;AACA;AACA;AACA,sCAAsC;AACtC;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,4BAA4B,UAAU,GAAG,KAAK;AAC9C;AACA;AACA,mBAAmB,kDAAM;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,oDAAoD;AACpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sEAAsE;AACtE;AACA;AACA;AACA;AACA,aAAa;AACb,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,CAAC;AACD;AACA,wBAAwB,qBAAqB","sources":["webpack://@peter-debugging-2/peter-minimal-jquery/./src/data.js","webpack://@peter-debugging-2/peter-minimal-jquery/./src/utils.js","webpack://@peter-debugging-2/peter-minimal-jquery/./src/widget.js","webpack://@peter-debugging-2/peter-minimal-jquery/webpack/bootstrap","webpack://@peter-debugging-2/peter-minimal-jquery/webpack/runtime/define property getters","webpack://@peter-debugging-2/peter-minimal-jquery/webpack/runtime/hasOwnProperty shorthand","webpack://@peter-debugging-2/peter-minimal-jquery/webpack/runtime/make namespace object","webpack://@peter-debugging-2/peter-minimal-jquery/./src/core.js"],"sourcesContent":["export function Data() {\r\n this.store = new WeakMap();\r\n}\r\n\r\nData.prototype = {\r\n set(element, key, value) {\r\n if (!this.store.has(element))\r\n this.store.set(element, {});\r\n this.store.get(element)[key] = value;\r\n },\r\n get(element, key) {\r\n if (!this.store.has(element)) return undefined;\r\n if (key === undefined) return this.store.get(element);\r\n return this.store.get(element)[key];\r\n },\r\n hasData(element) {\r\n return this.store.get(element);\r\n },\r\n remove(element, key) {\r\n if (!this.store.has(element)) return;\r\n if (key === undefined) \r\n this.store.delete(element);\r\n else \r\n delete this.store.get(element)[key];\r\n },\r\n access(element, key, value) {\r\n if (value === undefined) return this.get(element, key);\r\n this.set(element, key, value);\r\n return value;\r\n } \r\n}\r\n\r\nexport const dataUser = new Data();","export function deepExtend() {\r\n let target = arguments[0] || {};\r\n let otherArgs = Array.prototype.slice.apply(arguments, [1]); //other options to override\r\n for (const obj of otherArgs) {\r\n if (!obj) continue;\r\n for (const [key, value] of Object.entries(obj)) {\r\n switch (Object.prototype.toString.call(value)) {\r\n case '[object Object]':\r\n target[key] = target[key] || {};\r\n target[key] = deepExtend(target[key], value);\r\n break;\r\n case '[object Array]': //review case array\r\n target[key] = deepExtend(new Array(value.length), value);\r\n break;\r\n default:\r\n target[key] = value;\r\n }\r\n }\r\n }\r\n return target;\r\n}\r\n\r\nexport function shallowExtend(target, ...sources) {\r\n for (const src of sources) {\r\n if (!src) continue;\r\n for (const [key, value] of Object.entries(src)) {\r\n target[key] = value;\r\n }\r\n }\r\n return target;\r\n}","import { deepExtend } from \"./utils.js\";\r\nlet Widget = function() {};\r\nWidget.prototype = {\r\n options: {\r\n classes: {},\r\n disabled: false,\r\n },\r\n\r\n _createWidget: function(options, element) {\r\n this.options = deepExtend({}, this.options, options);\r\n this._create();\r\n this._init();\r\n },\r\n _create: function() {},\r\n\t_init: function() {},\r\n _destroy: function() {},\r\n _setOption: function(key, value) {\r\n this.options[key] = value;\r\n return this;\r\n },\r\n _setOptions: function(options) {\r\n for (const key in options )\r\n\t\t\tthis._setOption( key, options[key] );\r\n return this;\r\n }\r\n}\r\nexport default Widget;","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Check if module exists (development only)\n\tif (__webpack_modules__[moduleId] === undefined) {\n\t\tvar e = new Error(\"Cannot find module '\" + moduleId + \"'\");\n\t\te.code = 'MODULE_NOT_FOUND';\n\t\tthrow e;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","\r\nimport { shallowExtend, deepExtend } from \"./utils.js\";\r\nimport { dataUser } from \"./data.js\";\r\nimport Widget from \"./widget.js\";\r\n(function(global) {\r\n function jQueryObject(selector) {\r\n if (selector.nodeType) {\r\n this.length = 1;\r\n this[0] = selector;\r\n }\r\n else if (typeof selector == 'string') {\r\n let nodeList = document.querySelectorAll(selector); //an array of nodelist => change it to jquery object\r\n let index = 0;\r\n this.length = 0; //Data in constructor, methods in prototype ✅\r\n for (let node of nodeList) {\r\n this[index] = node;\r\n index += 1;\r\n this.length += 1;\r\n }\r\n }\r\n else \r\n return;\r\n //new jQueryObject implicitly return this\r\n }\r\n\r\n let jQuery = (selector) => new jQueryObject(selector);\r\n jQueryObject.prototype = jQuery.fn = jQuery.prototype = { //alias to prototype\r\n ready: function(callback) {\r\n let jQueryObj = this;\r\n const isReady = Array.prototype.some.call(jQueryObj, function(element) {\r\n return element.readyState != null && element.readyState != \"loading\";\r\n });\r\n if (isReady) {\r\n callback();\r\n }\r\n else {\r\n jQueryObj.on('DOMContentLoaded', callback);\r\n }\r\n },\r\n each: function(callback) { //suger syntax, now callback exec for each match element of jQuery instance and chainable\r\n return jQuery.each(this, callback);\r\n },\r\n on: function(event, callback) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.addEventListener(event, function(e) {\r\n callback.call(element, e)\r\n });\r\n })\r\n },\r\n text: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) { //setter\r\n const text = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.textContent = text;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].textContent;\r\n }\r\n },\r\n val: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) {\r\n const value = arguments[0];//if call arguments inside jQuery.each then it is different\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.value = value;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].value;\r\n }\r\n },\r\n css: function() {\r\n let cssCamelcaseProperty = function(cssProperty) {\r\n return cssProperty.replace(/-([a-z])/g, (fullMatch, captureCharacter) => {\r\n return captureCharacter.toUpperCase();\r\n });\r\n };\r\n const jQueryObj = this;\r\n if (arguments.length == 2) {\r\n let cssPropertyName = arguments[0];\r\n let value = arguments[1];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'object') {\r\n const cssProperties = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n for (const [cssPropertyName, value] of Object.entries(cssProperties)) {\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n }\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'string') {\r\n const cssPropertyName = arguments[0];\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n let result = getComputedStyle(jQueryObj[0])[camelProperty];\r\n return jQueryObj[0].style[camelProperty];\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n let result = jQueryObj[0].style;\r\n return result;\r\n }\r\n },\r\n hasClass: function(className) {\r\n const jQueryObj = this;\r\n const result = Array.prototype.some.call(jQueryObj, (element) => element.classList.contains(className));\r\n return result;\r\n },\r\n addClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.add(className);\r\n });\r\n },\r\n removeClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.remove(className);\r\n });\r\n },\r\n toggleClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.toggle(className);\r\n });\r\n },\r\n data: function(name, value) {\r\n const jQueryObj = this;\r\n const element = jQueryObj[0];\r\n if (name === undefined) return dataUser.get(element);\r\n if (value === undefined) return dataUser.access(element, name);\r\n else {\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n dataUser.access(element, name, value);\r\n });\r\n }\r\n }\r\n }\r\n jQuery.shallowExtend = shallowExtend;\r\n jQuery.deepExtend = deepExtend;\r\n jQuery.each = function(target, callback) {\r\n if (target.length > 0) {\r\n for (let i = 0; i < target.length; i++)\r\n if (callback.call(target[i], i, target[i]) === false) break; //TODO: not sure why return false will break\r\n }\r\n else {\r\n for (let key in target)\r\n if (callback.call(target[key], key, target[key]) === false) break;\r\n }\r\n return target; //jQuery chainable\r\n };\r\n //TODO: jQuery.extends({ something: ...}) will extend the jQuery itself, so we can import jQuery, and add functionality in different module, more scalable\r\n jQuery.hasData = function(element) {\r\n return dataUser.hasData(element);\r\n };\r\n jQuery.data = function(element, name, value) {\r\n return dataUser.access(element, name, value);\r\n };\r\n jQuery.removeData = function(element, name) {\r\n dataUser.remove(element, name);\r\n };\r\n /** This method is ensure we have widgetName => we will have $(element).widgetFullName() getter, setter */\r\n jQuery.widgetBridge = function(name, constructorFn) { \r\n let fullName = constructorFn.prototype.widgetFullName || name;\r\n jQuery.fn[name] = function(options) {\r\n let isMethodCall = typeof options === \"string\";\r\n const jQueryObj = this;\r\n const args = Array.prototype.slice.call(arguments, 1);\r\n let returnValue = jQueryObj;\r\n if (!isMethodCall) { //is init \r\n jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const instance = jQuery.data(element, fullName);\r\n if (!instance)\r\n jQuery.data(this, fullName, new constructorFn(options, element));\r\n else {\r\n instance._setOptions(options);\r\n if (instance._init) instance._init();\r\n }\r\n });\r\n }\r\n else { //is method call\r\n if (!jQueryObj.length && options === 'instance') return undefined;\r\n jQuery.each(jQueryObj, function() {\r\n let instance = jQuery.data(this, fullName);\r\n if (!instance) throw Error(\"not initialized\");\r\n if (options === 'instance') {\r\n returnValue = instance;\r\n return false; //exits jQuery.each\r\n }\r\n if (typeof instance[options] == 'function') {\r\n returnValue = instance[options].apply(instance, args);\r\n return false;\r\n }\r\n });\r\n } \r\n return returnValue;\r\n }\r\n }\r\n /**\r\n * Minimal flow (mental model) $.widget():\r\n build constructor -> set prototype chain -> wrap overridden methods -> expose $.fn.plugin\r\n */\r\n jQuery.widget = function(inputName, base, prototype) {\r\n const [namespace, name] = inputName.split(\".\");\r\n const fullName = `${namespace}-${name}`;\r\n if (prototype === undefined) {\r\n prototype = base;\r\n base = Widget;\r\n }\r\n\r\n jQuery[namespace] = jQuery[namespace] || {};\r\n let constructor = jQuery[namespace][name] = function(options, element) {\r\n //!this: Called without new\r\n //!this._createWidget: Prototype isn’t set yet, or calling for simple inheritance\r\n if (!this || !this._createWidget)\r\n return new constructor( options, element );\r\n if (arguments.length)\r\n this._createWidget( options, element );\r\n }\r\n\r\n let basePrototype = new base();\r\n //not mutate the base 's options from prototype (shared), in case options of base is from prototype\r\n //obj.options === Base.prototype.options // ✅ true (obj not have options, but get this from its prototype)\r\n basePrototype.options = jQuery.deepExtend({}, basePrototype.options);\r\n\r\n let proxiedPrototype = {};\r\n jQuery.each(prototype, function(property, value) {\r\n if (typeof value !== \"function\") {\r\n proxiedPrototype[property] = value;\r\n return;\r\n }\r\n proxiedPrototype[property] = (function() {\r\n function _super() {\r\n return base.prototype[property].apply(this, arguments);\r\n }\r\n\r\n function _superApply(args) {\r\n return base.prototype[property].apply(this, args);\r\n }\r\n\r\n return function() {\r\n //this keyword in this context is the widget instance\r\n //save these for later restore\r\n let __super = this._super;\r\n let __superApply = this._superApply;\r\n\r\n this._super = _super;\r\n this._superApply = _superApply;\r\n\r\n const returnValue = value.apply(this, arguments); //value is a function\r\n this._super = __super;\r\n this._superApply = __superApply;\r\n return returnValue;\r\n }\r\n })()\r\n });\r\n\r\n constructor.prototype = jQuery.deepExtend(basePrototype, proxiedPrototype, {\r\n constructor: constructor,\r\n namespace: namespace,\r\n widgetName: name,\r\n widgetFullName: fullName\r\n });\r\n\r\n jQuery.widgetBridge( name, constructor );\r\n return constructor;\r\n }\r\n\r\n\r\n //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....\r\n // jQuery.fn = jQuery.prototype = {\r\n // shallowExtend: shallowExtend,\r\n // deepExtend: deepExtend,\r\n // }\r\n\r\n global.jQuery = global.$ = jQuery;\r\n})(window)\r\n//IIFE to ensure, all var in this file not polute window global object, only jQuery & $\r\n//or could use export { jQuery, jQuery as $ }, then import these 2 from the core.js (module)\r\n"],"names":[],"ignoreList":[],"sourceRoot":""}
package/dist/main.min.js CHANGED
@@ -1,2 +1,3 @@
1
- (()=>{"use strict";function t(){let t=arguments[0]||{},e=Array.prototype.slice.apply(arguments,1);for(const n of e)if(n)for(const[e,o]of Object.entries(n))switch(Object.prototype.toString.call(o)){case"[object Object]":t[e]=t[e]||{},t[e]=jQuery.fn.extend(t[e],o);break;case"[object Array]":t[e]=jQuery.fn.extend(new Array(o.length),o);break;default:t[e]=o}}function e(t,...e){for(const n of e)if(n)for(const[e,o]of Object.entries(n))t[e]=o}!function(n){function o(t){if(t.nodeType)this.length=1,this[0]=t;else{if("string"!=typeof t)return;{let e=document.querySelectorAll(t),n=0;this.length=0;for(let t of e)this[n]=t,n+=1,this.length+=1}}}let s=t=>new o(t);o.prototype=s.fn=s.prototype={ready:function(t){Array.prototype.some.call(this,function(t){return null!=t.readyState&&"loading"!=t.readyState})?t():this.on("DOMContentLoaded",t)},each:function(t){return s.each(this,t)},on:function(t,e){return s.each(this,function(){const n=this;n.addEventListener(t,function(t){e.call(n,t)})})},text:function(){const t=this;if(1==arguments.length){const e=arguments[0];return s.each(t,function(){this.textContent=e})}if(!arguments||0==arguments?.length)return t[0].textContent},val:function(){const t=this;if(1==arguments.length){const e=arguments[0];return s.each(t,function(){this.value=e})}if(!arguments||0==arguments?.length)return t[0].value},css:function(){let t=function(t){return t.replace(/-([a-z])/g,(t,e)=>e.toUpperCase())};const e=this;if(2==arguments.length){let n=arguments[0],o=arguments[1];return s.each(e,function(){const e=t(n);this.style[e]=o})}if(1==arguments.length&&"object"==typeof arguments[0]){const n=arguments[0];return s.each(e,function(){const e=this;for(const[o,s]of Object.entries(n)){const n=t(o);e.style[n]=s}})}if(1==arguments.length&&"string"==typeof arguments[0]){const n=t(arguments[0]);return getComputedStyle(e[0])[n],e[0].style[n]}if(!arguments||0==arguments?.length)return e[0].style},hasClass:function(t){return Array.prototype.some.call(this,e=>e.classList.contains(t))},addClass:function(t){return s.each(this,function(){this.classList.add(t)})},removeClass:function(t){return s.each(this,function(){this.classList.remove(t)})},toggleClass:function(t){return s.each(this,function(){this.classList.toggle(t)})}},s.shallowExtend=e,s.deepExtend=t,s.each=function(t,e){if(t.length>0)for(let n=0;n<t.length&&!1!==e.call(t[n],n,t[n]);n++);else for(let n in t)if(!1===e.call(t[n],n,t[n]))break;return t},n.jQuery=n.$=s}(window)})();
1
+ /*! For license information please see main.min.js.LICENSE.txt */
2
+ (()=>{"use strict";function t(){let e=arguments[0]||{},n=Array.prototype.slice.apply(arguments,[1]);for(const i of n)if(i)for(const[n,s]of Object.entries(i))switch(Object.prototype.toString.call(s)){case"[object Object]":e[n]=e[n]||{},e[n]=t(e[n],s);break;case"[object Array]":e[n]=t(new Array(s.length),s);break;default:e[n]=s}return e}function e(t,...e){for(const n of e)if(n)for(const[e,i]of Object.entries(n))t[e]=i;return t}function n(){this.store=new WeakMap}n.prototype={set(t,e,n){this.store.has(t)||this.store.set(t,{}),this.store.get(t)[e]=n},get(t,e){if(this.store.has(t))return void 0===e?this.store.get(t):this.store.get(t)[e]},hasData(t){return this.store.get(t)},remove(t,e){this.store.has(t)&&(void 0===e?this.store.delete(t):delete this.store.get(t)[e])},access(t,e,n){return void 0===n?this.get(t,e):(this.set(t,e,n),n)}};const i=new n;let s=function(){};s.prototype={options:{classes:{},disabled:!1},_createWidget:function(e,n){this.options=t({},this.options,e),this._create(),this._init()},_create:function(){},_init:function(){},_destroy:function(){},_setOption:function(t,e){return this.options[t]=e,this},_setOptions:function(t){for(const e in t)this._setOption(e,t[e]);return this}};const o=s;!function(n){function s(t){if(t.nodeType)this.length=1,this[0]=t;else{if("string"!=typeof t)return;{let e=document.querySelectorAll(t),n=0;this.length=0;for(let t of e)this[n]=t,n+=1,this.length+=1}}}let r=t=>new s(t);s.prototype=r.fn=r.prototype={ready:function(t){Array.prototype.some.call(this,function(t){return null!=t.readyState&&"loading"!=t.readyState})?t():this.on("DOMContentLoaded",t)},each:function(t){return r.each(this,t)},on:function(t,e){return r.each(this,function(){const n=this;n.addEventListener(t,function(t){e.call(n,t)})})},text:function(){const t=this;if(1==arguments.length){const e=arguments[0];return r.each(t,function(){this.textContent=e})}if(!arguments||0==arguments?.length)return t[0].textContent},val:function(){const t=this;if(1==arguments.length){const e=arguments[0];return r.each(t,function(){this.value=e})}if(!arguments||0==arguments?.length)return t[0].value},css:function(){let t=function(t){return t.replace(/-([a-z])/g,(t,e)=>e.toUpperCase())};const e=this;if(2==arguments.length){let n=arguments[0],i=arguments[1];return r.each(e,function(){const e=t(n);this.style[e]=i})}if(1==arguments.length&&"object"==typeof arguments[0]){const n=arguments[0];return r.each(e,function(){const e=this;for(const[i,s]of Object.entries(n)){const n=t(i);e.style[n]=s}})}if(1==arguments.length&&"string"==typeof arguments[0]){const n=t(arguments[0]);return getComputedStyle(e[0])[n],e[0].style[n]}if(!arguments||0==arguments?.length)return e[0].style},hasClass:function(t){return Array.prototype.some.call(this,e=>e.classList.contains(t))},addClass:function(t){return r.each(this,function(){this.classList.add(t)})},removeClass:function(t){return r.each(this,function(){this.classList.remove(t)})},toggleClass:function(t){return r.each(this,function(){this.classList.toggle(t)})},data:function(t,e){const n=this[0];return void 0===t?i.get(n):void 0===e?i.access(n,t):r.each(this,function(){i.access(this,t,e)})}},r.shallowExtend=e,r.deepExtend=t,r.each=function(t,e){if(t.length>0)for(let n=0;n<t.length&&!1!==e.call(t[n],n,t[n]);n++);else for(let n in t)if(!1===e.call(t[n],n,t[n]))break;return t},r.hasData=function(t){return i.hasData(t)},r.data=function(t,e,n){return i.access(t,e,n)},r.removeData=function(t,e){i.remove(t,e)},r.widgetBridge=function(t,e){let n=e.prototype.widgetFullName||t;r.fn[t]=function(t){let i="string"==typeof t;const s=this,o=Array.prototype.slice.call(arguments,1);let c=s;if(i){if(!s.length&&"instance"===t)return;r.each(s,function(){let e=r.data(this,n);if(!e)throw Error("not initialized");return"instance"===t?(c=e,!1):"function"==typeof e[t]?(c=e[t].apply(e,o),!1):void 0})}else r.each(s,function(){const i=r.data(this,n);i?(i._setOptions(t),i._init&&i._init()):r.data(this,n,new e(t,this))});return c}},r.widget=function(t,e,n){const[i,s]=t.split("."),c=`${i}-${s}`;void 0===n&&(n=e,e=o);let a=(r[i]=r[i]||{})[s]=function(t,e){if(!this||!this._createWidget)return new a(t,e);arguments.length&&this._createWidget(t,e)},u=new e;u.options=r.deepExtend({},u.options);let h={};return r.each(n,function(t,n){h[t]="function"==typeof n?function(){function i(){return e.prototype[t].apply(this,arguments)}function s(n){return e.prototype[t].apply(this,n)}return function(){let t=this._super,e=this._superApply;this._super=i,this._superApply=s;const o=n.apply(this,arguments);return this._super=t,this._superApply=e,o}}():n}),a.prototype=r.deepExtend(u,h,{constructor:a,namespace:i,widgetName:s,widgetFullName:c}),r.widgetBridge(s,a),a},n.jQuery=n.$=r}(window)})();
2
3
  //# sourceMappingURL=main.min.js.map
@@ -0,0 +1,3 @@
1
+ //!this._createWidget: Prototype isn’t set yet, or calling for simple inheritance
2
+
3
+ //!this: Called without new
@@ -1 +1 @@
1
- {"version":3,"file":"main.min.js","mappings":"mBAAO,SAASA,IACZ,IAAIC,EAASC,UAAU,IAAM,CAAC,EAC1BC,EAAYC,MAAMC,UAAUC,MAAMC,MAAML,UAAW,GACvD,IAAK,MAAMM,KAAOL,EACd,GAAKK,EACL,IAAK,MAAOC,EAAKC,KAAUC,OAAOC,QAAQJ,GACtC,OAAQG,OAAON,UAAUQ,SAASC,KAAKJ,IACnC,IAAK,kBACDT,EAAOQ,GAAOR,EAAOQ,IAAQ,CAAC,EAC9BR,EAAOQ,GAAOM,OAAOC,GAAGC,OAAOhB,EAAOQ,GAAMC,GAC5C,MACJ,IAAK,iBACDT,EAAOQ,GAAOM,OAAOC,GAAGC,OAAO,IAAIb,MAAMM,EAAMQ,QAASR,GACxD,MACJ,QACIT,EAAOQ,GAAOC,EAIlC,CAEO,SAASS,EAAclB,KAAWmB,GACrC,IAAK,MAAMC,KAAOD,EACd,GAAKC,EACL,IAAK,MAAOZ,EAAKC,KAAUC,OAAOC,QAAQS,GACtCpB,EAAOQ,GAAOC,CAG1B,ECzBA,SAAUY,GACN,SAASC,EAAaC,GAClB,GAAIA,EAASC,SACTC,KAAKR,OAAS,EACdQ,KAAK,GAAKF,MAET,IAAuB,iBAA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SAASrC,EAAQgC,GAC3B,GAAIhC,EAAOiB,OAAS,EAChB,IAAK,IAAIkD,EAAI,EAAGA,EAAInE,EAAOiB,SACwB,IAA3Ce,EAASnB,KAAKb,EAAOmE,GAAIA,EAAGnE,EAAOmE,IADRA,UAInC,IAAK,IAAI3D,KAAOR,EACZ,IAAqD,IAAjDgC,EAASnB,KAAKb,EAAOQ,GAAMA,EAAKR,EAAOQ,IAAiB,MAEpE,OAAOR,CACX,EAQAqB,EAAOP,OAASO,EAAO+C,EAAItD,CAC9B,CA9JD,CA8JGuD,O","sources":["webpack://minimal-jquery/./src/utils.js","webpack://minimal-jquery/./src/core.js"],"sourcesContent":["export function deepExtend() {\r\n let target = arguments[0] || {};\r\n let otherArgs = Array.prototype.slice.apply(arguments, 1); //other options to override\r\n for (const obj of otherArgs) {\r\n if (!obj) continue;\r\n for (const [key, value] of Object.entries(obj)) {\r\n switch (Object.prototype.toString.call(value)) {\r\n case '[object Object]':\r\n target[key] = target[key] || {};\r\n target[key] = jQuery.fn.extend(target[key], value);\r\n break;\r\n case '[object Array]': //review case array\r\n target[key] = jQuery.fn.extend(new Array(value.length), value);\r\n break;\r\n default:\r\n target[key] = value;\r\n }\r\n }\r\n }\r\n}\r\n\r\nexport function shallowExtend(target, ...sources) {\r\n for (const src of sources) {\r\n if (!src) continue;\r\n for (const [key, value] of Object.entries(src)) {\r\n target[key] = value;\r\n }\r\n }\r\n}","\r\nimport { shallowExtend, deepExtend } from \"./utils.js\";\r\n\r\n(function(global) {\r\n function jQueryObject(selector) {\r\n if (selector.nodeType) {\r\n this.length = 1;\r\n this[0] = selector;\r\n }\r\n else if (typeof selector == 'string') {\r\n let nodeList = document.querySelectorAll(selector); //an array of nodelist => change it to jquery object\r\n let index = 0;\r\n this.length = 0; //Data in constructor, methods in prototype ✅\r\n for (let node of nodeList) {\r\n this[index] = node;\r\n index += 1;\r\n this.length += 1;\r\n }\r\n }\r\n else \r\n return;\r\n //new jQueryObject implicitly return this\r\n }\r\n\r\n let jQuery = (selector) => new jQueryObject(selector);\r\n jQueryObject.prototype = jQuery.fn = jQuery.prototype = { //alias to prototype\r\n ready: function(callback) {\r\n let jQueryObj = this;\r\n const isReady = Array.prototype.some.call(jQueryObj, function(element) {\r\n return element.readyState != null && element.readyState != \"loading\";\r\n });\r\n if (isReady) {\r\n callback();\r\n }\r\n else {\r\n jQueryObj.on('DOMContentLoaded', callback);\r\n }\r\n },\r\n each: function(callback) { //suger syntax, now callback exec for each match element of jQuery instance and chainable\r\n return jQuery.each(this, callback);\r\n },\r\n on: function(event, callback) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.addEventListener(event, function(e) {\r\n callback.call(element, e)\r\n });\r\n })\r\n },\r\n text: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) { //setter\r\n const text = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.textContent = text;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].textContent;\r\n }\r\n },\r\n val: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) {\r\n const value = arguments[0];//if call arguments inside jQuery.each then it is different\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.value = value;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].value;\r\n }\r\n },\r\n css: function() {\r\n let cssCamelcaseProperty = function(cssProperty) {\r\n return cssProperty.replace(/-([a-z])/g, (fullMatch, captureCharacter) => {\r\n return captureCharacter.toUpperCase();\r\n });\r\n };\r\n const jQueryObj = this;\r\n if (arguments.length == 2) {\r\n let cssPropertyName = arguments[0];\r\n let value = arguments[1];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'object') {\r\n const cssProperties = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n for (const [cssPropertyName, value] of Object.entries(cssProperties)) {\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n }\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'string') {\r\n const cssPropertyName = arguments[0];\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n let result = getComputedStyle(jQueryObj[0])[camelProperty];\r\n return jQueryObj[0].style[camelProperty];\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n let result = jQueryObj[0].style;\r\n return result;\r\n }\r\n },\r\n hasClass: function(className) {\r\n const jQueryObj = this;\r\n const result = Array.prototype.some.call(jQueryObj, (element) => element.classList.contains(className));\r\n return result;\r\n },\r\n addClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.add(className);\r\n });\r\n },\r\n removeClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.remove(className);\r\n });\r\n },\r\n toggleClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.toggle(className);\r\n });\r\n }\r\n }\r\n jQuery.shallowExtend = shallowExtend;\r\n jQuery.deepExtend = deepExtend;\r\n jQuery.each = function(target, callback) {\r\n if (target.length > 0) {\r\n for (let i = 0; i < target.length; i++)\r\n if (callback.call(target[i], i, target[i]) === false) break; //TODO: not sure why return false will break\r\n }\r\n else {\r\n for (let key in target)\r\n if (callback.call(target[key], key, target[key]) === false) break;\r\n }\r\n return target; //jQuery chainable\r\n }\r\n\r\n //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....\r\n // jQuery.fn = jQuery.prototype = {\r\n // shallowExtend: shallowExtend,\r\n // deepExtend: deepExtend,\r\n // }\r\n\r\n global.jQuery = global.$ = jQuery;\r\n})(window)\r\n//IIFE to ensure, all var in this file not polute window global object, only jQuery & $\r\n//or could use export { jQuery, jQuery as $ }, then import these 2 from the core.js (module)\r\n"],"names":["deepExtend","target","arguments","otherArgs","Array","prototype","slice","apply","obj","key","value","Object","entries","toString","call","jQuery","fn","extend","length","shallowExtend","sources","src","global","jQueryObject","selector","nodeType","this","nodeList","document","querySelectorAll","index","node","ready","callback","some","element","readyState","on","each","event","addEventListener","e","text","jQueryObj","textContent","val","css","cssCamelcaseProperty","cssProperty","replace","fullMatch","captureCharacter","toUpperCase","cssPropertyName","camelProperty","style","cssProperties","getComputedStyle","hasClass","className","classList","contains","addClass","add","removeClass","remove","toggleClass","toggle","i","$","window"],"ignoreList":[],"sourceRoot":""}
1
+ {"version":3,"file":"main.min.js","mappings":";mBAAO,SAASA,IACZ,IAAIC,EAASC,UAAU,IAAM,CAAC,EAC1BC,EAAYC,MAAMC,UAAUC,MAAMC,MAAML,UAAW,CAAC,IACxD,IAAK,MAAMM,KAAOL,EACd,GAAKK,EACL,IAAK,MAAOC,EAAKC,KAAUC,OAAOC,QAAQJ,GACtC,OAAQG,OAAON,UAAUQ,SAASC,KAAKJ,IACnC,IAAK,kBACDT,EAAOQ,GAAOR,EAAOQ,IAAQ,CAAC,EAC9BR,EAAOQ,GAAOT,EAAWC,EAAOQ,GAAMC,GACtC,MACJ,IAAK,iBACDT,EAAOQ,GAAOT,EAAW,IAAII,MAAMM,EAAMK,QAASL,GAClD,MACJ,QACIT,EAAOQ,GAAOC,EAI9B,OAAOT,CACX,CAEO,SAASe,EAAcf,KAAWgB,GACrC,IAAK,MAAMC,KAAOD,EACd,GAAKC,EACL,IAAK,MAAOT,EAAKC,KAAUC,OAAOC,QAAQM,GACtCjB,EAAOQ,GAAOC,EAGtB,OAAOT,CACX,CC9BO,SAASkB,IACZC,KAAKC,MAAQ,IAAIC,OACrB,CAEAH,EAAKd,UAAY,CACb,GAAAkB,CAAIC,EAASf,EAAKC,GACTU,KAAKC,MA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C,GAEAgG,EAAYrG,UAAY+C,EAAOpD,WAAW2G,EAAeC,EAAkB,CACvEF,YAAaA,EACbF,UAAWA,EACXU,WAAYzB,EACZM,eAAgBD,IAGpB1C,EAAOwC,aAAcH,EAAMiB,GACpBA,CACX,EASA/D,EAAOS,OAAST,EAAOwE,EAAI/D,CAC9B,CAhSD,CAgSGgE,O","sources":["webpack://@peter-debugging-2/peter-minimal-jquery/./src/utils.js","webpack://@peter-debugging-2/peter-minimal-jquery/./src/data.js","webpack://@peter-debugging-2/peter-minimal-jquery/./src/widget.js","webpack://@peter-debugging-2/peter-minimal-jquery/./src/core.js"],"sourcesContent":["export function deepExtend() {\r\n let target = arguments[0] || {};\r\n let otherArgs = Array.prototype.slice.apply(arguments, [1]); //other options to override\r\n for (const obj of otherArgs) {\r\n if (!obj) continue;\r\n for (const [key, value] of Object.entries(obj)) {\r\n switch (Object.prototype.toString.call(value)) {\r\n case '[object Object]':\r\n target[key] = target[key] || {};\r\n target[key] = deepExtend(target[key], value);\r\n break;\r\n case '[object Array]': //review case array\r\n target[key] = deepExtend(new Array(value.length), value);\r\n break;\r\n default:\r\n target[key] = value;\r\n }\r\n }\r\n }\r\n return target;\r\n}\r\n\r\nexport function shallowExtend(target, ...sources) {\r\n for (const src of sources) {\r\n if (!src) continue;\r\n for (const [key, value] of Object.entries(src)) {\r\n target[key] = value;\r\n }\r\n }\r\n return target;\r\n}","export function Data() {\r\n this.store = new WeakMap();\r\n}\r\n\r\nData.prototype = {\r\n set(element, key, value) {\r\n if (!this.store.has(element))\r\n this.store.set(element, {});\r\n this.store.get(element)[key] = value;\r\n },\r\n get(element, key) {\r\n if (!this.store.has(element)) return undefined;\r\n if (key === undefined) return this.store.get(element);\r\n return this.store.get(element)[key];\r\n },\r\n hasData(element) {\r\n return this.store.get(element);\r\n },\r\n remove(element, key) {\r\n if (!this.store.has(element)) return;\r\n if (key === undefined) \r\n this.store.delete(element);\r\n else \r\n delete this.store.get(element)[key];\r\n },\r\n access(element, key, value) {\r\n if (value === undefined) return this.get(element, key);\r\n this.set(element, key, value);\r\n return value;\r\n } \r\n}\r\n\r\nexport const dataUser = new Data();","import { deepExtend } from \"./utils.js\";\r\nlet Widget = function() {};\r\nWidget.prototype = {\r\n options: {\r\n classes: {},\r\n disabled: false,\r\n },\r\n\r\n _createWidget: function(options, element) {\r\n this.options = deepExtend({}, this.options, options);\r\n this._create();\r\n this._init();\r\n },\r\n _create: function() {},\r\n\t_init: function() {},\r\n _destroy: function() {},\r\n _setOption: function(key, value) {\r\n this.options[key] = value;\r\n return this;\r\n },\r\n _setOptions: function(options) {\r\n for (const key in options )\r\n\t\t\tthis._setOption( key, options[key] );\r\n return this;\r\n }\r\n}\r\nexport default Widget;","\r\nimport { shallowExtend, deepExtend } from \"./utils.js\";\r\nimport { dataUser } from \"./data.js\";\r\nimport Widget from \"./widget.js\";\r\n(function(global) {\r\n function jQueryObject(selector) {\r\n if (selector.nodeType) {\r\n this.length = 1;\r\n this[0] = selector;\r\n }\r\n else if (typeof selector == 'string') {\r\n let nodeList = document.querySelectorAll(selector); //an array of nodelist => change it to jquery object\r\n let index = 0;\r\n this.length = 0; //Data in constructor, methods in prototype ✅\r\n for (let node of nodeList) {\r\n this[index] = node;\r\n index += 1;\r\n this.length += 1;\r\n }\r\n }\r\n else \r\n return;\r\n //new jQueryObject implicitly return this\r\n }\r\n\r\n let jQuery = (selector) => new jQueryObject(selector);\r\n jQueryObject.prototype = jQuery.fn = jQuery.prototype = { //alias to prototype\r\n ready: function(callback) {\r\n let jQueryObj = this;\r\n const isReady = Array.prototype.some.call(jQueryObj, function(element) {\r\n return element.readyState != null && element.readyState != \"loading\";\r\n });\r\n if (isReady) {\r\n callback();\r\n }\r\n else {\r\n jQueryObj.on('DOMContentLoaded', callback);\r\n }\r\n },\r\n each: function(callback) { //suger syntax, now callback exec for each match element of jQuery instance and chainable\r\n return jQuery.each(this, callback);\r\n },\r\n on: function(event, callback) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.addEventListener(event, function(e) {\r\n callback.call(element, e)\r\n });\r\n })\r\n },\r\n text: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) { //setter\r\n const text = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.textContent = text;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].textContent;\r\n }\r\n },\r\n val: function() {\r\n const jQueryObj = this;\r\n if (arguments.length == 1) {\r\n const value = arguments[0];//if call arguments inside jQuery.each then it is different\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.value = value;\r\n })\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n return jQueryObj[0].value;\r\n }\r\n },\r\n css: function() {\r\n let cssCamelcaseProperty = function(cssProperty) {\r\n return cssProperty.replace(/-([a-z])/g, (fullMatch, captureCharacter) => {\r\n return captureCharacter.toUpperCase();\r\n });\r\n };\r\n const jQueryObj = this;\r\n if (arguments.length == 2) {\r\n let cssPropertyName = arguments[0];\r\n let value = arguments[1];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'object') {\r\n const cssProperties = arguments[0];\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n for (const [cssPropertyName, value] of Object.entries(cssProperties)) {\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n element.style[camelProperty] = value;\r\n }\r\n });\r\n }\r\n else if (arguments.length == 1 && typeof arguments[0] == 'string') {\r\n const cssPropertyName = arguments[0];\r\n const camelProperty = cssCamelcaseProperty(cssPropertyName);\r\n let result = getComputedStyle(jQueryObj[0])[camelProperty];\r\n return jQueryObj[0].style[camelProperty];\r\n }\r\n else if (!arguments || arguments?.length == 0) {\r\n let result = jQueryObj[0].style;\r\n return result;\r\n }\r\n },\r\n hasClass: function(className) {\r\n const jQueryObj = this;\r\n const result = Array.prototype.some.call(jQueryObj, (element) => element.classList.contains(className));\r\n return result;\r\n },\r\n addClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.add(className);\r\n });\r\n },\r\n removeClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.remove(className);\r\n });\r\n },\r\n toggleClass: function(className) {\r\n const jQueryObj = this;\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n element.classList.toggle(className);\r\n });\r\n },\r\n data: function(name, value) {\r\n const jQueryObj = this;\r\n const element = jQueryObj[0];\r\n if (name === undefined) return dataUser.get(element);\r\n if (value === undefined) return dataUser.access(element, name);\r\n else {\r\n return jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n dataUser.access(element, name, value);\r\n });\r\n }\r\n }\r\n }\r\n jQuery.shallowExtend = shallowExtend;\r\n jQuery.deepExtend = deepExtend;\r\n jQuery.each = function(target, callback) {\r\n if (target.length > 0) {\r\n for (let i = 0; i < target.length; i++)\r\n if (callback.call(target[i], i, target[i]) === false) break; //TODO: not sure why return false will break\r\n }\r\n else {\r\n for (let key in target)\r\n if (callback.call(target[key], key, target[key]) === false) break;\r\n }\r\n return target; //jQuery chainable\r\n };\r\n //TODO: jQuery.extends({ something: ...}) will extend the jQuery itself, so we can import jQuery, and add functionality in different module, more scalable\r\n jQuery.hasData = function(element) {\r\n return dataUser.hasData(element);\r\n };\r\n jQuery.data = function(element, name, value) {\r\n return dataUser.access(element, name, value);\r\n };\r\n jQuery.removeData = function(element, name) {\r\n dataUser.remove(element, name);\r\n };\r\n /** This method is ensure we have widgetName => we will have $(element).widgetFullName() getter, setter */\r\n jQuery.widgetBridge = function(name, constructorFn) { \r\n let fullName = constructorFn.prototype.widgetFullName || name;\r\n jQuery.fn[name] = function(options) {\r\n let isMethodCall = typeof options === \"string\";\r\n const jQueryObj = this;\r\n const args = Array.prototype.slice.call(arguments, 1);\r\n let returnValue = jQueryObj;\r\n if (!isMethodCall) { //is init \r\n jQuery.each(jQueryObj, function() {\r\n const element = this;\r\n const instance = jQuery.data(element, fullName);\r\n if (!instance)\r\n jQuery.data(this, fullName, new constructorFn(options, element));\r\n else {\r\n instance._setOptions(options);\r\n if (instance._init) instance._init();\r\n }\r\n });\r\n }\r\n else { //is method call\r\n if (!jQueryObj.length && options === 'instance') return undefined;\r\n jQuery.each(jQueryObj, function() {\r\n let instance = jQuery.data(this, fullName);\r\n if (!instance) throw Error(\"not initialized\");\r\n if (options === 'instance') {\r\n returnValue = instance;\r\n return false; //exits jQuery.each\r\n }\r\n if (typeof instance[options] == 'function') {\r\n returnValue = instance[options].apply(instance, args);\r\n return false;\r\n }\r\n });\r\n } \r\n return returnValue;\r\n }\r\n }\r\n /**\r\n * Minimal flow (mental model) $.widget():\r\n build constructor -> set prototype chain -> wrap overridden methods -> expose $.fn.plugin\r\n */\r\n jQuery.widget = function(inputName, base, prototype) {\r\n const [namespace, name] = inputName.split(\".\");\r\n const fullName = `${namespace}-${name}`;\r\n if (prototype === undefined) {\r\n prototype = base;\r\n base = Widget;\r\n }\r\n\r\n jQuery[namespace] = jQuery[namespace] || {};\r\n let constructor = jQuery[namespace][name] = function(options, element) {\r\n //!this: Called without new\r\n //!this._createWidget: Prototype isn’t set yet, or calling for simple inheritance\r\n if (!this || !this._createWidget)\r\n return new constructor( options, element );\r\n if (arguments.length)\r\n this._createWidget( options, element );\r\n }\r\n\r\n let basePrototype = new base();\r\n //not mutate the base 's options from prototype (shared), in case options of base is from prototype\r\n //obj.options === Base.prototype.options // ✅ true (obj not have options, but get this from its prototype)\r\n basePrototype.options = jQuery.deepExtend({}, basePrototype.options);\r\n\r\n let proxiedPrototype = {};\r\n jQuery.each(prototype, function(property, value) {\r\n if (typeof value !== \"function\") {\r\n proxiedPrototype[property] = value;\r\n return;\r\n }\r\n proxiedPrototype[property] = (function() {\r\n function _super() {\r\n return base.prototype[property].apply(this, arguments);\r\n }\r\n\r\n function _superApply(args) {\r\n return base.prototype[property].apply(this, args);\r\n }\r\n\r\n return function() {\r\n //this keyword in this context is the widget instance\r\n //save these for later restore\r\n let __super = this._super;\r\n let __superApply = this._superApply;\r\n\r\n this._super = _super;\r\n this._superApply = _superApply;\r\n\r\n const returnValue = value.apply(this, arguments); //value is a function\r\n this._super = __super;\r\n this._superApply = __superApply;\r\n return returnValue;\r\n }\r\n })()\r\n });\r\n\r\n constructor.prototype = jQuery.deepExtend(basePrototype, proxiedPrototype, {\r\n constructor: constructor,\r\n namespace: namespace,\r\n widgetName: name,\r\n widgetFullName: fullName\r\n });\r\n\r\n jQuery.widgetBridge( name, constructor );\r\n return constructor;\r\n }\r\n\r\n\r\n //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....\r\n // jQuery.fn = jQuery.prototype = {\r\n // shallowExtend: shallowExtend,\r\n // deepExtend: deepExtend,\r\n // }\r\n\r\n global.jQuery = global.$ = jQuery;\r\n})(window)\r\n//IIFE to ensure, all var in this file not polute window global object, only jQuery & $\r\n//or could use export { jQuery, jQuery as $ }, then import these 2 from the core.js (module)\r\n"],"names":["deepExtend","target","arguments","otherArgs","Array","prototype","slice","apply","obj","key","value","Object","entries","toString","call","length","shallowExtend","sources","src","Data","this","store","WeakMap","set","element","has","get","undefined","hasData","remove","delete","access","dataUser","Widget","options","classes","disabled","_createWidget","_create","_init","_destroy","_setOption","_setOptions","global","jQueryObject","selector","nodeType","nodeList","document","querySelectorAll","index","node","jQuery","fn","ready","callback","some","readyState","on","each","event","addEventListener","e","text","jQueryObj","textContent","val","css","cssCamelcaseProperty","cssProperty","replace","fullMatch","captureCharacter","toUpperCase","cssPropertyName","camelProperty","style","cssProperties","getComputedStyle","hasClass","className","classList","contains","addClass","add","removeClass","toggleClass","toggle","data","name","i","removeData","widgetBridge","constructorFn","fullName","widgetFullName","isMethodCall","args","returnValue","instance","Error","widget","inputName","base","namespace","split","constructor","basePrototype","proxiedPrototype","property","_super","_superApply","__super","__superApply","widgetName","$","window"],"ignoreList":[],"sourceRoot":""}
package/index.html CHANGED
@@ -11,6 +11,7 @@
11
11
  <div class="myDiv"></div>
12
12
  <!-- <script src="./src/core.js" type="module"></script> -->
13
13
  <script src="./dist/main.js"></script>
14
+ <!-- <script src="https://cdn.jsdelivr.net/npm/@peter-debugging-2/peter-minimal-jquery@1.0.0/dist/main.js"></script> -->
14
15
  <!-- <script type="module"> -->
15
16
  <script>
16
17
  jQuery(document).ready(function() {
@@ -33,12 +34,21 @@
33
34
  })
34
35
  .val("Just a value")
35
36
  .css({"color": "yellow", "display": "block"})
36
- .toggleClass("myInput");
37
+ .toggleClass("myInput")
38
+ .data("peterData", {"hello": "world", "me": 1});
37
39
  jQuery(".myDiv").text("Hello world");
40
+ console.log(jQuery("input").data());
38
41
  console.log(jQuery("input").css("color"));
39
42
  console.log(jQuery("input").css());
40
43
  console.log(jQuery("input").hasClass("myInput"));
41
-
44
+
45
+ jQuery.widget("custom.simpleWidget", {
46
+ _create: function() {
47
+ console.log("This is me");
48
+ }
49
+ });
50
+ jQuery("input").simpleWidget();
51
+ jQuery("input").simpleWidget({"me": 2});
42
52
  </script>
43
53
  </body>
44
54
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@peter-debugging-2/peter-minimal-jquery",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "A usable simplified jquery like package",
5
5
  "main": "./src/core.js",
6
6
  "type": "module",
package/src/core.js CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  import { shallowExtend, deepExtend } from "./utils.js";
3
-
3
+ import { dataUser } from "./data.js";
4
+ import Widget from "./widget.js";
4
5
  (function(global) {
5
6
  function jQueryObject(selector) {
6
7
  if (selector.nodeType) {
@@ -136,6 +137,18 @@ import { shallowExtend, deepExtend } from "./utils.js";
136
137
  const element = this;
137
138
  element.classList.toggle(className);
138
139
  });
140
+ },
141
+ data: function(name, value) {
142
+ const jQueryObj = this;
143
+ const element = jQueryObj[0];
144
+ if (name === undefined) return dataUser.get(element);
145
+ if (value === undefined) return dataUser.access(element, name);
146
+ else {
147
+ return jQuery.each(jQueryObj, function() {
148
+ const element = this;
149
+ dataUser.access(element, name, value);
150
+ });
151
+ }
139
152
  }
140
153
  }
141
154
  jQuery.shallowExtend = shallowExtend;
@@ -150,7 +163,125 @@ import { shallowExtend, deepExtend } from "./utils.js";
150
163
  if (callback.call(target[key], key, target[key]) === false) break;
151
164
  }
152
165
  return target; //jQuery chainable
166
+ };
167
+ //TODO: jQuery.extends({ something: ...}) will extend the jQuery itself, so we can import jQuery, and add functionality in different module, more scalable
168
+ jQuery.hasData = function(element) {
169
+ return dataUser.hasData(element);
170
+ };
171
+ jQuery.data = function(element, name, value) {
172
+ return dataUser.access(element, name, value);
173
+ };
174
+ jQuery.removeData = function(element, name) {
175
+ dataUser.remove(element, name);
176
+ };
177
+ /** This method is ensure we have widgetName => we will have $(element).widgetFullName() getter, setter */
178
+ jQuery.widgetBridge = function(name, constructorFn) {
179
+ let fullName = constructorFn.prototype.widgetFullName || name;
180
+ jQuery.fn[name] = function(options) {
181
+ let isMethodCall = typeof options === "string";
182
+ const jQueryObj = this;
183
+ const args = Array.prototype.slice.call(arguments, 1);
184
+ let returnValue = jQueryObj;
185
+ if (!isMethodCall) { //is init
186
+ jQuery.each(jQueryObj, function() {
187
+ const element = this;
188
+ const instance = jQuery.data(element, fullName);
189
+ if (!instance)
190
+ jQuery.data(this, fullName, new constructorFn(options, element));
191
+ else {
192
+ instance._setOptions(options);
193
+ if (instance._init) instance._init();
194
+ }
195
+ });
196
+ }
197
+ else { //is method call
198
+ if (!jQueryObj.length && options === 'instance') return undefined;
199
+ jQuery.each(jQueryObj, function() {
200
+ let instance = jQuery.data(this, fullName);
201
+ if (!instance) throw Error("not initialized");
202
+ if (options === 'instance') {
203
+ returnValue = instance;
204
+ return false; //exits jQuery.each
205
+ }
206
+ if (typeof instance[options] == 'function') {
207
+ returnValue = instance[options].apply(instance, args);
208
+ return false;
209
+ }
210
+ });
211
+ }
212
+ return returnValue;
213
+ }
153
214
  }
215
+ /**
216
+ * Minimal flow (mental model) $.widget():
217
+ build constructor -> set prototype chain -> wrap overridden methods -> expose $.fn.plugin
218
+ */
219
+ jQuery.widget = function(inputName, base, prototype) {
220
+ const [namespace, name] = inputName.split(".");
221
+ const fullName = `${namespace}-${name}`;
222
+ if (prototype === undefined) {
223
+ prototype = base;
224
+ base = Widget;
225
+ }
226
+
227
+ jQuery[namespace] = jQuery[namespace] || {};
228
+ let constructor = jQuery[namespace][name] = function(options, element) {
229
+ //!this: Called without new
230
+ //!this._createWidget: Prototype isn’t set yet, or calling for simple inheritance
231
+ if (!this || !this._createWidget)
232
+ return new constructor( options, element );
233
+ if (arguments.length)
234
+ this._createWidget( options, element );
235
+ }
236
+
237
+ let basePrototype = new base();
238
+ //not mutate the base 's options from prototype (shared), in case options of base is from prototype
239
+ //obj.options === Base.prototype.options // ✅ true (obj not have options, but get this from its prototype)
240
+ basePrototype.options = jQuery.deepExtend({}, basePrototype.options);
241
+
242
+ let proxiedPrototype = {};
243
+ jQuery.each(prototype, function(property, value) {
244
+ if (typeof value !== "function") {
245
+ proxiedPrototype[property] = value;
246
+ return;
247
+ }
248
+ proxiedPrototype[property] = (function() {
249
+ function _super() {
250
+ return base.prototype[property].apply(this, arguments);
251
+ }
252
+
253
+ function _superApply(args) {
254
+ return base.prototype[property].apply(this, args);
255
+ }
256
+
257
+ return function() {
258
+ //this keyword in this context is the widget instance
259
+ //save these for later restore
260
+ let __super = this._super;
261
+ let __superApply = this._superApply;
262
+
263
+ this._super = _super;
264
+ this._superApply = _superApply;
265
+
266
+ const returnValue = value.apply(this, arguments); //value is a function
267
+ this._super = __super;
268
+ this._superApply = __superApply;
269
+ return returnValue;
270
+ }
271
+ })()
272
+ });
273
+
274
+ constructor.prototype = jQuery.deepExtend(basePrototype, proxiedPrototype, {
275
+ constructor: constructor,
276
+ namespace: namespace,
277
+ widgetName: name,
278
+ widgetFullName: fullName
279
+ });
280
+
281
+ jQuery.widgetBridge( name, constructor );
282
+ return constructor;
283
+ }
284
+
154
285
 
155
286
  //NOTE: if Query.fn = jQuery.prototype is after jQueryObject.prototype = jQuery.fn, then prototype of instance not have these methods: shallowExtend, ....
156
287
  // jQuery.fn = jQuery.prototype = {
package/src/data.js ADDED
@@ -0,0 +1,33 @@
1
+ export function Data() {
2
+ this.store = new WeakMap();
3
+ }
4
+
5
+ Data.prototype = {
6
+ set(element, key, value) {
7
+ if (!this.store.has(element))
8
+ this.store.set(element, {});
9
+ this.store.get(element)[key] = value;
10
+ },
11
+ get(element, key) {
12
+ if (!this.store.has(element)) return undefined;
13
+ if (key === undefined) return this.store.get(element);
14
+ return this.store.get(element)[key];
15
+ },
16
+ hasData(element) {
17
+ return this.store.get(element);
18
+ },
19
+ remove(element, key) {
20
+ if (!this.store.has(element)) return;
21
+ if (key === undefined)
22
+ this.store.delete(element);
23
+ else
24
+ delete this.store.get(element)[key];
25
+ },
26
+ access(element, key, value) {
27
+ if (value === undefined) return this.get(element, key);
28
+ this.set(element, key, value);
29
+ return value;
30
+ }
31
+ }
32
+
33
+ export const dataUser = new Data();
package/src/utils.js CHANGED
@@ -1,22 +1,23 @@
1
1
  export function deepExtend() {
2
2
  let target = arguments[0] || {};
3
- let otherArgs = Array.prototype.slice.apply(arguments, 1); //other options to override
3
+ let otherArgs = Array.prototype.slice.apply(arguments, [1]); //other options to override
4
4
  for (const obj of otherArgs) {
5
5
  if (!obj) continue;
6
6
  for (const [key, value] of Object.entries(obj)) {
7
7
  switch (Object.prototype.toString.call(value)) {
8
8
  case '[object Object]':
9
9
  target[key] = target[key] || {};
10
- target[key] = jQuery.fn.extend(target[key], value);
10
+ target[key] = deepExtend(target[key], value);
11
11
  break;
12
12
  case '[object Array]': //review case array
13
- target[key] = jQuery.fn.extend(new Array(value.length), value);
13
+ target[key] = deepExtend(new Array(value.length), value);
14
14
  break;
15
15
  default:
16
16
  target[key] = value;
17
17
  }
18
18
  }
19
19
  }
20
+ return target;
20
21
  }
21
22
 
22
23
  export function shallowExtend(target, ...sources) {
@@ -26,4 +27,5 @@ export function shallowExtend(target, ...sources) {
26
27
  target[key] = value;
27
28
  }
28
29
  }
30
+ return target;
29
31
  }
package/src/widget.js ADDED
@@ -0,0 +1,27 @@
1
+ import { deepExtend } from "./utils.js";
2
+ let Widget = function() {};
3
+ Widget.prototype = {
4
+ options: {
5
+ classes: {},
6
+ disabled: false,
7
+ },
8
+
9
+ _createWidget: function(options, element) {
10
+ this.options = deepExtend({}, this.options, options);
11
+ this._create();
12
+ this._init();
13
+ },
14
+ _create: function() {},
15
+ _init: function() {},
16
+ _destroy: function() {},
17
+ _setOption: function(key, value) {
18
+ this.options[key] = value;
19
+ return this;
20
+ },
21
+ _setOptions: function(options) {
22
+ for (const key in options )
23
+ this._setOption( key, options[key] );
24
+ return this;
25
+ }
26
+ }
27
+ export default Widget;