@gogocat/data-bind 1.12.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.
Files changed (271) hide show
  1. package/.editorconfig +14 -14
  2. package/.vscode/launch.json +12 -12
  3. package/CONFIGURATION.md +294 -0
  4. package/REACTIVE_MODE.md +553 -0
  5. package/README.md +266 -829
  6. package/babel.config.json +30 -0
  7. package/dist/js/_escape.d.ts +14 -0
  8. package/dist/js/_escape.d.ts.map +1 -0
  9. package/dist/js/applyBinding.d.ts +11 -0
  10. package/dist/js/applyBinding.d.ts.map +1 -0
  11. package/dist/js/attrBinding.d.ts +12 -0
  12. package/dist/js/attrBinding.d.ts.map +1 -0
  13. package/dist/js/binder.d.ts +67 -0
  14. package/dist/js/binder.d.ts.map +1 -0
  15. package/dist/js/changeBinding.d.ts +19 -0
  16. package/dist/js/changeBinding.d.ts.map +1 -0
  17. package/dist/js/commentWrapper.d.ts +39 -0
  18. package/dist/js/commentWrapper.d.ts.map +1 -0
  19. package/dist/js/config.d.ts +55 -0
  20. package/dist/js/config.d.ts.map +1 -0
  21. package/dist/js/createBindingOption.d.ts +32 -0
  22. package/dist/js/createBindingOption.d.ts.map +1 -0
  23. package/dist/js/createEventBinding.d.ts +10 -0
  24. package/dist/js/createEventBinding.d.ts.map +1 -0
  25. package/dist/js/cssBinding.d.ts +15 -0
  26. package/dist/js/cssBinding.d.ts.map +1 -0
  27. package/dist/js/dataBind.js +2756 -2530
  28. package/dist/js/dataBind.min.js +8 -1
  29. package/dist/js/dataBind.min.js.map +1 -1
  30. package/dist/js/domWalker.d.ts +9 -0
  31. package/dist/js/domWalker.d.ts.map +1 -0
  32. package/dist/js/forOfBinding.d.ts +12 -0
  33. package/dist/js/forOfBinding.d.ts.map +1 -0
  34. package/dist/js/hoverBinding.d.ts +13 -0
  35. package/dist/js/hoverBinding.d.ts.map +1 -0
  36. package/dist/js/ifBinding.d.ts +12 -0
  37. package/dist/js/ifBinding.d.ts.map +1 -0
  38. package/dist/js/index.d.ts +10 -0
  39. package/dist/js/index.d.ts.map +1 -0
  40. package/dist/js/modelBinding.d.ts +12 -0
  41. package/dist/js/modelBinding.d.ts.map +1 -0
  42. package/dist/js/postProcess.d.ts +3 -0
  43. package/dist/js/postProcess.d.ts.map +1 -0
  44. package/dist/js/pubSub.d.ts +11 -0
  45. package/dist/js/pubSub.d.ts.map +1 -0
  46. package/dist/js/reactiveProxy.d.ts +28 -0
  47. package/dist/js/reactiveProxy.d.ts.map +1 -0
  48. package/dist/js/renderForOfBinding.d.ts +8 -0
  49. package/dist/js/renderForOfBinding.d.ts.map +1 -0
  50. package/dist/js/renderIfBinding.d.ts +22 -0
  51. package/dist/js/renderIfBinding.d.ts.map +1 -0
  52. package/dist/js/renderIteration.d.ts +16 -0
  53. package/dist/js/renderIteration.d.ts.map +1 -0
  54. package/dist/js/renderTemplate.d.ts +14 -0
  55. package/dist/js/renderTemplate.d.ts.map +1 -0
  56. package/dist/js/renderTemplatesBinding.d.ts +19 -0
  57. package/dist/js/renderTemplatesBinding.d.ts.map +1 -0
  58. package/dist/js/showBinding.d.ts +13 -0
  59. package/dist/js/showBinding.d.ts.map +1 -0
  60. package/dist/js/switchBinding.d.ts +13 -0
  61. package/dist/js/switchBinding.d.ts.map +1 -0
  62. package/dist/js/textBinding.d.ts +13 -0
  63. package/dist/js/textBinding.d.ts.map +1 -0
  64. package/dist/js/types/_escape.d.ts +14 -0
  65. package/dist/js/types/_escape.d.ts.map +1 -0
  66. package/dist/js/types/applyBinding.d.ts +11 -0
  67. package/dist/js/types/applyBinding.d.ts.map +1 -0
  68. package/dist/js/types/attrBinding.d.ts +12 -0
  69. package/dist/js/types/attrBinding.d.ts.map +1 -0
  70. package/dist/js/types/binder.d.ts +67 -0
  71. package/dist/js/types/binder.d.ts.map +1 -0
  72. package/dist/js/types/changeBinding.d.ts +19 -0
  73. package/dist/js/types/changeBinding.d.ts.map +1 -0
  74. package/dist/js/types/commentWrapper.d.ts +39 -0
  75. package/dist/js/types/commentWrapper.d.ts.map +1 -0
  76. package/dist/js/types/config.d.ts +55 -0
  77. package/dist/js/types/config.d.ts.map +1 -0
  78. package/dist/js/types/createBindingOption.d.ts +32 -0
  79. package/dist/js/types/createBindingOption.d.ts.map +1 -0
  80. package/dist/js/types/createEventBinding.d.ts +10 -0
  81. package/dist/js/types/createEventBinding.d.ts.map +1 -0
  82. package/dist/js/types/cssBinding.d.ts +15 -0
  83. package/dist/js/types/cssBinding.d.ts.map +1 -0
  84. package/dist/js/types/domWalker.d.ts +9 -0
  85. package/dist/js/types/domWalker.d.ts.map +1 -0
  86. package/dist/js/types/forOfBinding.d.ts +12 -0
  87. package/dist/js/types/forOfBinding.d.ts.map +1 -0
  88. package/dist/js/types/hoverBinding.d.ts +13 -0
  89. package/dist/js/types/hoverBinding.d.ts.map +1 -0
  90. package/dist/js/types/ifBinding.d.ts +12 -0
  91. package/dist/js/types/ifBinding.d.ts.map +1 -0
  92. package/dist/js/types/index.d.ts +10 -0
  93. package/dist/js/types/index.d.ts.map +1 -0
  94. package/dist/js/types/modelBinding.d.ts +12 -0
  95. package/dist/js/types/modelBinding.d.ts.map +1 -0
  96. package/dist/js/types/postProcess.d.ts +3 -0
  97. package/dist/js/types/postProcess.d.ts.map +1 -0
  98. package/dist/js/types/pubSub.d.ts +11 -0
  99. package/dist/js/types/pubSub.d.ts.map +1 -0
  100. package/dist/js/types/reactiveProxy.d.ts +28 -0
  101. package/dist/js/types/reactiveProxy.d.ts.map +1 -0
  102. package/dist/js/types/renderForOfBinding.d.ts +8 -0
  103. package/dist/js/types/renderForOfBinding.d.ts.map +1 -0
  104. package/dist/js/types/renderIfBinding.d.ts +22 -0
  105. package/dist/js/types/renderIfBinding.d.ts.map +1 -0
  106. package/dist/js/types/renderIteration.d.ts +16 -0
  107. package/dist/js/types/renderIteration.d.ts.map +1 -0
  108. package/dist/js/types/renderTemplate.d.ts +14 -0
  109. package/dist/js/types/renderTemplate.d.ts.map +1 -0
  110. package/dist/js/types/renderTemplatesBinding.d.ts +19 -0
  111. package/dist/js/types/renderTemplatesBinding.d.ts.map +1 -0
  112. package/dist/js/types/showBinding.d.ts +13 -0
  113. package/dist/js/types/showBinding.d.ts.map +1 -0
  114. package/dist/js/types/switchBinding.d.ts +13 -0
  115. package/dist/js/types/switchBinding.d.ts.map +1 -0
  116. package/dist/js/types/textBinding.d.ts +13 -0
  117. package/dist/js/types/textBinding.d.ts.map +1 -0
  118. package/dist/js/types/types.d.ts +111 -0
  119. package/dist/js/types/types.d.ts.map +1 -0
  120. package/dist/js/types/util.d.ts +119 -0
  121. package/dist/js/types/util.d.ts.map +1 -0
  122. package/dist/js/types.d.ts +111 -0
  123. package/dist/js/types.d.ts.map +1 -0
  124. package/dist/js/util.d.ts +119 -0
  125. package/dist/js/util.d.ts.map +1 -0
  126. package/eslint.config.js +124 -0
  127. package/examples/DBMONSTER_COMPARISON.md +123 -0
  128. package/examples/afterRenderDemo.html +119 -0
  129. package/examples/bootstrap/css/animate.css +1579 -1579
  130. package/examples/bootstrap/css/bootstrap.min.css +6 -6
  131. package/examples/bootstrap/css/homeservices.css +378 -390
  132. package/examples/bootstrap/css/open-iconic.css +511 -511
  133. package/examples/bootstrap/fonts/open-iconic.svg +543 -543
  134. package/examples/bootstrap/js/compMessageDialog.js +20 -19
  135. package/examples/bootstrap/js/compSearchBar.js +12 -19
  136. package/examples/bootstrap/js/compSearchResults.js +50 -46
  137. package/examples/bootstrap/js/featureAdsResult.json +65 -65
  138. package/examples/bootstrap/js/searchResult.json +57 -57
  139. package/examples/bootstrap.html +343 -332
  140. package/examples/css/baseTodo.css +141 -141
  141. package/examples/css/dbMonsterStyles.css +27 -27
  142. package/examples/css/indexTodo.css +374 -374
  143. package/examples/dbmonsterForOfReactive.html +40 -0
  144. package/examples/dbmonsterReact.html +19 -0
  145. package/examples/forOfBindingSimpleDebug.html +45 -0
  146. package/examples/globalConfig.html +131 -0
  147. package/examples/js/afterRenderDemo.js +190 -0
  148. package/examples/js/appTodo.js +46 -46
  149. package/examples/js/attrBindingDemo.js +2 -2
  150. package/examples/js/dbMonApp.js +24 -26
  151. package/examples/js/dbMonAppReact.jsx +79 -0
  152. package/examples/js/dbMonAppReactive.js +28 -0
  153. package/examples/js/fiberDemo.js +4 -4
  154. package/examples/js/filtersDemo.js +8 -8
  155. package/examples/js/forOfDemo.js +7 -9
  156. package/examples/js/forOfDemoComplex.js +44 -17
  157. package/examples/js/form.js +14 -14
  158. package/examples/js/globalConfig.js +117 -0
  159. package/examples/js/ifBindingDemo.js +16 -16
  160. package/examples/js/reactiveDemo.js +119 -0
  161. package/examples/js/switchBindingDemo.js +8 -8
  162. package/examples/react-dbmonster/dist/bundle.js +43 -0
  163. package/examples/react-dbmonster/package-lock.json +537 -0
  164. package/examples/react-dbmonster/package.json +16 -0
  165. package/examples/react-dbmonster/src/index.jsx +80 -0
  166. package/examples/reactiveDemo.html +127 -0
  167. package/examples/refreshRateTest.html +75 -75
  168. package/index.html +841 -0
  169. package/package.json +31 -34
  170. package/rollup.config.js +79 -36
  171. package/src/{_escape.js → _escape.ts} +19 -17
  172. package/src/{applyBinding.js → applyBinding.ts} +27 -18
  173. package/src/{attrBinding.js → attrBinding.ts} +14 -13
  174. package/src/{binder.js → binder.ts} +289 -181
  175. package/src/changeBinding.ts +93 -0
  176. package/src/{commentWrapper.js → commentWrapper.ts} +33 -30
  177. package/src/config.ts +107 -0
  178. package/src/{createBindingOption.js → createBindingOption.ts} +39 -15
  179. package/src/createEventBinding.ts +88 -0
  180. package/src/{cssBinding.js → cssBinding.ts} +13 -11
  181. package/src/{domWalker.js → domWalker.ts} +44 -30
  182. package/src/{forOfBinding.js → forOfBinding.ts} +4 -3
  183. package/src/hoverBinding.ts +84 -0
  184. package/src/{ifBinding.js → ifBinding.ts} +14 -12
  185. package/src/index.ts +53 -0
  186. package/src/{modelBinding.js → modelBinding.ts} +11 -9
  187. package/src/{postProcess.js → postProcess.ts} +6 -4
  188. package/src/{pubSub.js → pubSub.ts} +24 -21
  189. package/src/reactiveProxy.ts +285 -0
  190. package/src/{renderForOfBinding.js → renderForOfBinding.ts} +54 -32
  191. package/src/{renderIfBinding.js → renderIfBinding.ts} +41 -19
  192. package/src/{renderIteration.js → renderIteration.ts} +24 -8
  193. package/src/renderTemplate.ts +165 -0
  194. package/src/renderTemplatesBinding.ts +73 -0
  195. package/src/{showBinding.js → showBinding.ts} +4 -3
  196. package/src/{switchBinding.js → switchBinding.ts} +18 -15
  197. package/src/{textBinding.js → textBinding.ts} +5 -4
  198. package/src/types.ts +124 -0
  199. package/src/util.ts +810 -0
  200. package/test/css/reporter.css +9 -9
  201. package/test/globals.d.ts +19 -0
  202. package/test/helpers/testHelper.js +46 -11
  203. package/test/mocks/featureAdsResult.json +65 -65
  204. package/test/mocks/searchResult.json +57 -57
  205. package/test/specs/{attrBinding.spec.js → attrBinding.spec.ts} +103 -106
  206. package/test/specs/{binder.spec.js → binder.spec.ts} +29 -27
  207. package/test/specs/blurBinding.spec.ts +60 -0
  208. package/test/specs/chainableUse.spec.ts +125 -0
  209. package/test/specs/clickBinding.spec.ts +194 -0
  210. package/test/specs/{cssBinding.spec.js → cssBinding.spec.ts} +72 -79
  211. package/test/specs/{dataBindBootstrap.spec.js → dataBindBootstrap.spec.ts} +332 -313
  212. package/test/specs/{filter.spec.js → filter.spec.ts} +75 -76
  213. package/test/specs/{forOfBinding.spec.js → forOfBinding.spec.ts} +208 -219
  214. package/test/specs/formBinding.spec.ts +272 -0
  215. package/test/specs/ifBinding.spec.ts +165 -0
  216. package/test/specs/{nestedComponent.spec.js → nestedComponent.spec.ts} +88 -88
  217. package/test/specs/reactiveProxy.spec.ts +465 -0
  218. package/test/specs/{showBinding.spec.js → showBinding.spec.ts} +148 -149
  219. package/test/specs/{switchBinding.spec.js → switchBinding.spec.ts} +172 -173
  220. package/test/specs/templateBinding.spec.ts +273 -0
  221. package/test/specs/{textBinding.spec.js → textBinding.spec.ts} +47 -48
  222. package/test/tsconfig.json +31 -0
  223. package/test-output.txt +200 -0
  224. package/test-reactive.html +224 -0
  225. package/tsconfig.json +28 -0
  226. package/vendors/lodash.custom.js +4577 -4577
  227. package/vendors/lodash.custom.min.js +45 -45
  228. package/vitest.config.js +27 -0
  229. package/.eslintrc.js +0 -1
  230. package/.grunt/grunt-contrib-jasmine/boot.js +0 -161
  231. package/.grunt/grunt-contrib-jasmine/dist/js/dataBind.js +0 -9
  232. package/.grunt/grunt-contrib-jasmine/grunt-template-jasmine-istanbul/reporter.js +0 -23
  233. package/.grunt/grunt-contrib-jasmine/jasmine-html.js +0 -853
  234. package/.grunt/grunt-contrib-jasmine/jasmine.css +0 -271
  235. package/.grunt/grunt-contrib-jasmine/jasmine.js +0 -9761
  236. package/.grunt/grunt-contrib-jasmine/jasmine_favicon.png +0 -0
  237. package/.grunt/grunt-contrib-jasmine/json2.js +0 -489
  238. package/.grunt/grunt-contrib-jasmine/reporter.js +0 -107
  239. package/coverage/coverage.json +0 -1
  240. package/coverage/lcov/lcov-report/base.css +0 -213
  241. package/coverage/lcov/lcov-report/index.html +0 -93
  242. package/coverage/lcov/lcov-report/js/dataBind.js.html +0 -6596
  243. package/coverage/lcov/lcov-report/js/index.html +0 -93
  244. package/coverage/lcov/lcov-report/prettify.css +0 -1
  245. package/coverage/lcov/lcov-report/prettify.js +0 -1
  246. package/coverage/lcov/lcov-report/sort-arrow-sprite.png +0 -0
  247. package/coverage/lcov/lcov-report/sorter.js +0 -158
  248. package/coverage/lcov/lcov.info +0 -1991
  249. package/eslintrc.json +0 -40
  250. package/examples/bootstrap/js/bootstrap.min.js +0 -6
  251. package/examples/bootstrap/js/popper.min.js +0 -5
  252. package/examples/bootstrap/js/searchSuggestion.js +0 -58
  253. package/examples/bootstrap/js/typeahead.jquery.js +0 -1538
  254. package/gruntfile.js +0 -92
  255. package/gulpfile.js +0 -32
  256. package/src/applyBindingExport.js +0 -5
  257. package/src/changeBinding.js +0 -63
  258. package/src/config.js +0 -66
  259. package/src/createEventBinding.js +0 -46
  260. package/src/eventSystem.js +0 -46
  261. package/src/hoverBinding.js +0 -57
  262. package/src/index.js +0 -26
  263. package/src/renderTemplate.js +0 -128
  264. package/src/renderTemplatesBinding.js +0 -44
  265. package/src/util.js +0 -648
  266. package/test/specs/blurBinding.spec.js +0 -57
  267. package/test/specs/formBinding.spec.js +0 -316
  268. package/test/specs/ifBinding.spec.js +0 -169
  269. package/test/specs/templateBinding.spec.js +0 -117
  270. package/vendors/jasmine-jquery.js +0 -841
  271. package/vendors/jquery-3.2.1.min.js +0 -4
@@ -1,10 +1,10 @@
1
1
  // databing message-dialog-component
2
2
 
3
- (function($, window) {
3
+ (function (window) {
4
4
  let compMessageDialog;
5
5
  const el = {
6
- messageModal: '#message-modal',
7
- messageTextArea: '#message',
6
+ messageModal: null,
7
+ messageTextArea: null,
8
8
  };
9
9
  const viewModel = {
10
10
  numSelectedProviders: '',
@@ -13,45 +13,46 @@
13
13
  selectedProviders: '',
14
14
  defaultMessageText: 'Hi,\nCould you please provide a quote for the following work:\n',
15
15
  sendingMessage: false,
16
- onMessageSubmit: function(e, $el, formData) {
16
+ onMessageSubmit(e, formEl, formData) {
17
17
  e.preventDefault();
18
18
  formData.ids = this.adIds;
19
19
  this.sendingMessage = true;
20
20
  this.updateStatus();
21
21
  console.log('post data: ', formData);
22
22
  },
23
- onTriggerSelectedAds: function(selectedAdData) {
23
+ onTriggerSelectedAds(selectedAdData) {
24
24
  this.selectedAdData = selectedAdData;
25
25
  this.numSelectedProviders = selectedAdData.length > 1 ? selectedAdData.length : '';
26
26
  this.selectedProviders = selectedAdData.length > 1 ? 'advertisers ID: ' : 'advertiser ID:';
27
- this.adIds = selectedAdData.map(function(item, index) {
27
+ this.adIds = selectedAdData.map((item, index) => {
28
28
  return item.id;
29
29
  });
30
30
  this.selectedProviders += this.adIds.toString();
31
31
  this.updateStatus();
32
32
  },
33
- updateStatus: function() {
34
- compMessageDialog.render();
33
+ updateStatus() {
34
+ // Reactive mode - automatic render!
35
35
  },
36
36
  };
37
37
 
38
- $(document).ready(function() {
39
- $.each(el, function(k, v) {
40
- el[k] = $(v);
41
- });
38
+ document.addEventListener('DOMContentLoaded', () => {
39
+ el.messageModal = document.getElementById('message-modal');
40
+ el.messageTextArea = document.getElementById('message');
42
41
 
43
- compMessageDialog = dataBind.init($('[data-bind-comp="message-dialog-component"]')[0], viewModel);
44
- compMessageDialog.render().then(function(comp) {
42
+ const messageDialogElement = document.querySelector('[data-bind-comp="message-dialog-component"]');
43
+ compMessageDialog = dataBind.init(messageDialogElement, viewModel);
44
+ compMessageDialog.render().then((comp) => {
45
45
  const self = comp;
46
46
  compMessageDialog.subscribe('TRIGGER-MESSAGE-DIALOG', self.viewModel.onTriggerSelectedAds);
47
47
 
48
- el.messageModal.on('shown.bs.modal', function() {
49
- el.messageTextArea[0].defaultValue = self.viewModel.defaultMessageText;
48
+ // Bootstrap 5 modal events
49
+ el.messageModal.addEventListener('shown.bs.modal', () => {
50
+ el.messageTextArea.defaultValue = self.viewModel.defaultMessageText;
50
51
  el.messageTextArea.focus();
51
52
  });
52
53
 
53
- el.messageModal.on('hidden.bs.modal', function() {
54
- el.messageTextArea[0].defaultValue = self.viewModel.defaultMessageText;
54
+ el.messageModal.addEventListener('hidden.bs.modal', () => {
55
+ el.messageTextArea.defaultValue = self.viewModel.defaultMessageText;
55
56
  self.viewModel.sendingMessage = false;
56
57
  });
57
58
  // for debug only
@@ -60,4 +61,4 @@
60
61
  console.log('compMessageDialog rendered', window.compMessageDialog);
61
62
  });
62
63
  });
63
- })(jQuery, window);
64
+ })(window);
@@ -1,27 +1,19 @@
1
1
  // databing search-bar
2
2
 
3
- (function($, window) {
3
+ (function (window) {
4
4
  let compSearchBar;
5
- const getFormData = function($form) {
6
- const sArray = $form.serializeArray();
7
- const data = {};
8
- sArray.map(function(n) {
9
- data[n['name']] = n['value'];
10
- });
11
5
 
12
- return data;
13
- };
14
6
  const viewModel = {
15
7
  searchWord: '',
16
8
  searchLocation: '',
17
9
  searching: false,
18
- onSearchWordChange: function(e, $el, newValue, oldValue) {
10
+ onSearchWordChange(e, el, newValue, oldValue) {
19
11
  console.log('onSearchWordChange: ', ' newValue: ', newValue, ' oldValue: ', oldValue);
20
12
  },
21
- onSearchLocationChange: function(e, $el, newValue, oldValue) {
13
+ onSearchLocationChange(e, el, newValue, oldValue) {
22
14
  console.log('onSearchWordChange: ', ' newValue: ', newValue, ' oldValue: ', oldValue);
23
15
  },
24
- onSearchSubmit: function(e, $form, formData) {
16
+ onSearchSubmit(e, form, formData) {
25
17
  e.preventDefault();
26
18
 
27
19
  // simple validation
@@ -36,18 +28,19 @@
36
28
  this.updateStatus();
37
29
  console.log('onSearchSubmit: ', formData);
38
30
  },
39
- onSearchCompleted: function() {
31
+ onSearchCompleted() {
40
32
  this.searching = false;
41
33
  this.updateStatus();
42
34
  },
43
- updateStatus: function() {
44
- compSearchBar.render();
35
+ updateStatus() {
36
+ // Reactive mode - automatic render!
45
37
  },
46
38
  };
47
39
 
48
- $(document).ready(function() {
49
- compSearchBar = dataBind.init($('[data-bind-comp="search-bar"]')[0], viewModel);
50
- compSearchBar.render().then(function(comp) {
40
+ document.addEventListener('DOMContentLoaded', () => {
41
+ const searchBarElement = document.querySelector('[data-bind-comp="search-bar"]');
42
+ compSearchBar = dataBind.init(searchBarElement, viewModel);
43
+ compSearchBar.render().then((comp) => {
51
44
  const self = comp;
52
45
  compSearchBar.subscribe('SEARCH-COMPLETED', self.viewModel.onSearchCompleted);
53
46
  // for debug only
@@ -57,4 +50,4 @@
57
50
  console.log('compSearchBar rendered', window.compSearchBar);
58
51
  });
59
52
  });
60
- })(jQuery, window);
53
+ })(window);
@@ -1,16 +1,16 @@
1
1
  // databing compSearchResults
2
2
 
3
- (function($, window) {
3
+ (function (window) {
4
4
  const isGithubPage = window.location.hostname === 'gogocat.github.io';
5
5
  const examplePath = isGithubPage ? 'https://gogocat.github.io/dataBind/examples/' : '/examples/';
6
6
  let compSearchResults;
7
7
  const searchUrl = `${examplePath}/bootstrap/js/searchResult.json`;
8
8
  const featureAdsResultUrl = `${examplePath}/bootstrap/js/featureAdsResult.json`;
9
- const $searchResultColumns = $('#search-result-columns');
10
- const converResultsData = function(data) {
11
- ret = [];
12
- data.forEach(function(item, index) {
13
- const newItem = $.extend({}, item);
9
+ const searchResultColumns = document.getElementById('search-result-columns');
10
+ const converResultsData = function (data) {
11
+ const ret = [];
12
+ data.forEach((item, index) => {
13
+ const newItem = Object.assign({}, item);
14
14
  if (newItem.bookmarked) {
15
15
  newItem.bookmarkedCss = 'active';
16
16
  }
@@ -33,51 +33,52 @@
33
33
  replacedInitResults: false,
34
34
  isNewSearch: false,
35
35
  currentQuery: null,
36
- getSearchResults: function(formData) {
36
+ getSearchResults(formData) {
37
37
  const self = this;
38
38
 
39
39
  this.isNewSearch = JSON.stringify(self.currentQuery) !== JSON.stringify(formData);
40
40
 
41
41
  self.currentQuery = formData;
42
42
 
43
- $.getJSON(searchUrl, self.currentQuery)
44
- .done(function(data) {
43
+ fetch(searchUrl)
44
+ .then(response => response.json())
45
+ .then((data) => {
45
46
  // mock network delay
46
- setTimeout(function() {
47
+ setTimeout(() => {
47
48
  self.loading = false;
48
49
  self.onSearchResult(data);
49
50
  compSearchResults.publish('SEARCH-COMPLETED', data);
50
51
  }, 1000);
51
52
  })
52
- .fail(function(jqXHR, textStatus, errorThrown) {
53
+ .catch((error) => {
53
54
  self.loading = false;
54
55
  compSearchResults.publish('SEARCH-COMPLETED', {
55
- fail: errorThrown,
56
+ fail: error,
56
57
  });
57
- self.logError(jqXHR, textStatus, errorThrown);
58
+ self.logError(error);
58
59
  });
59
60
  },
60
- getMessageCheckBoxAttr: function(data) {
61
+ getMessageCheckBoxAttr(data) {
61
62
  return {
62
63
  id: data.id,
63
64
  name: data.id,
64
65
  };
65
66
  },
66
- getMessageCheckBoxLabelAttr: function(data) {
67
+ getMessageCheckBoxLabelAttr(data) {
67
68
  return {
68
69
  for: data.id,
69
70
  };
70
71
  },
71
- onSearchResult: function(data) {
72
+ onSearchResult(data) {
72
73
  let newResults = [];
73
74
 
74
75
  if (this.isNewSearch) {
75
- $searchResultColumns.empty();
76
+ searchResultColumns.innerHTML = '';
76
77
  this.searchResults.length = 0;
77
78
  }
78
79
  // first search result - remove current results (featured items)
79
80
  if (compSearchResults.isServerRendered && !this.replacedInitResults) {
80
- // $searchResultColumns.empty();
81
+ // searchResultColumns.innerHTML = '';
81
82
  this.searchResultTitle = 'Search results';
82
83
  // this.searchResults.length = 0;
83
84
  this.replacedInitResults = true;
@@ -99,35 +100,35 @@
99
100
 
100
101
  console.log('onSearchResult: ', data);
101
102
  },
102
- logError: function() {
103
- // eslint-disable-next-line prefer-rest-params
103
+ logError() {
104
+
104
105
  console.warn('search result error: ', arguments);
105
106
  },
106
- onMoreResults: function() {
107
+ onMoreResults() {
107
108
  // get same mock result as example only
108
109
  this.loading = true;
109
110
  this.updateStatus();
110
111
  this.getSearchResults();
111
112
  },
112
- onAdBookmarkClick: function(e, $el) {
113
+ onAdBookmarkClick(e, el) {
113
114
  const activeCss = 'active';
114
- const isActivated = $el.classList.contains(activeCss);
115
- const resultIndex = $el.getAttribute('data-index');
115
+ const isActivated = el.classList.contains(activeCss);
116
+ const resultIndex = el.getAttribute('data-index');
116
117
 
117
118
  this.searchResults[resultIndex].bookmarked = !isActivated;
118
119
  this.searchResults[resultIndex].bookmarkedCss = isActivated ? '' : 'active';
119
120
  this.updateStatus();
120
121
  },
121
- onAdMessageCheck: function(e, $el, newValue, oldValue) {
122
- console.log('onAdMessageCheck: ', $el, newValue, oldValue);
122
+ onAdMessageCheck(e, el, newValue, oldValue) {
123
+ console.log('onAdMessageCheck: ', el, newValue, oldValue);
123
124
  this.updateStatus();
124
125
  },
125
- onMessageTriggerClick: function(e, $el) {
126
+ onMessageTriggerClick(e, el) {
126
127
  compSearchResults.publish('TRIGGER-MESSAGE-DIALOG', this.selectedResults);
127
- console.log('onMessageTriggerClick: ', $el);
128
+ console.log('onMessageTriggerClick: ', el);
128
129
  },
129
- updateStatus: function(opt) {
130
- this.selectedResults = this.searchResults.filter(function(result, index) {
130
+ updateStatus(opt) {
131
+ this.selectedResults = this.searchResults.filter((result, index) => {
131
132
  return result.selected;
132
133
  });
133
134
  this.messageTriggerCss = this.selectedResults.length ? 'show' : '';
@@ -136,20 +137,23 @@
136
137
  };
137
138
 
138
139
  // get server rendered featureAdsResults then init compSearchResults
139
- $.getJSON(featureAdsResultUrl).done(function(featureAdsResultData) {
140
- viewModel.searchResults = converResultsData(featureAdsResultData);
140
+ fetch(featureAdsResultUrl)
141
+ .then(response => response.json())
142
+ .then((featureAdsResultData) => {
143
+ viewModel.searchResults = converResultsData(featureAdsResultData);
141
144
 
142
- compSearchResults = dataBind.init($('[data-bind-comp="search-results-component"]')[0], viewModel);
143
- compSearchResults
144
- .render() // overwrite default server rendered option
145
- .then(function(comp) {
146
- const self = comp;
147
- // subscribe events
148
- compSearchResults.subscribe('SEARCH-AD', self.viewModel.getSearchResults);
149
- // for debug only
150
- window.compSearchResultsViewModel = self.viewModel;
151
- window.compSearchResults = compSearchResults;
152
- console.log('compSearchResults rendered', window.compSearchResults);
153
- });
154
- });
155
- })(jQuery, window);
145
+ const searchResultsElement = document.querySelector('[data-bind-comp="search-results-component"]');
146
+ compSearchResults = dataBind.init(searchResultsElement, viewModel);
147
+ compSearchResults
148
+ .render() // overwrite default server rendered option
149
+ .then((comp) => {
150
+ const self = comp;
151
+ // subscribe events
152
+ compSearchResults.subscribe('SEARCH-AD', self.viewModel.getSearchResults);
153
+ // for debug only
154
+ window.compSearchResultsViewModel = self.viewModel;
155
+ window.compSearchResults = compSearchResults;
156
+ console.log('compSearchResults rendered', window.compSearchResults);
157
+ });
158
+ });
159
+ })(window);
@@ -1,66 +1,66 @@
1
- [{
2
- "id": "001",
3
- "title": "Card title that wraps to a new line",
4
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
5
- "image": "bootstrap/images/pic-home.jpg",
6
- "bookmarked": false,
7
- "numLikes": 110
8
- },
9
- {
10
- "id": "002",
11
- "title": "Card title",
12
- "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
13
- "image": "",
14
- "bookmarked": false,
15
- "numLikes": 9
16
- },
17
- {
18
- "id": "003",
19
- "title": "Card title",
20
- "description": "This card has supporting text below as a natural lead-in to additional content.",
21
- "image": "bootstrap/images/pic-deck.jpg",
22
- "bookmarked": false,
23
- "numLikes": 8
24
- },
25
- {
26
- "id": "004",
27
- "title": "Card title",
28
- "description": "This card has supporting text below as a natural lead-in to additional content.",
29
- "image": "bootstrap/images/pic-carpenter.jpg",
30
- "bookmarked": false,
31
- "numLikes": 8,
32
- "highlight": true
33
- },
34
- {
35
- "id": "005",
36
- "title": "Card title",
37
- "description": "This card has supporting text below as a natural lead-in to additional content.",
38
- "image": "",
39
- "bookmarked": false,
40
- "numLikes": 68
41
- },
42
- {
43
- "id": "006",
44
- "title": "Card title that wraps to a new line",
45
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
46
- "image": "bootstrap/images/pic-bathrooms.jpg",
47
- "bookmarked": true,
48
- "numLikes": 99
49
- },
50
- {
51
- "id": "007",
52
- "title": "Card title",
53
- "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
54
- "image": "",
55
- "bookmarked": false,
56
- "numLikes": 9
57
- },
58
- {
59
- "id": "008",
60
- "title": "Card title",
61
- "description": "This card has supporting text below as a natural lead-in to additional content.",
62
- "image": "bootstrap/images/pic-backyard.jpg",
63
- "bookmarked": false,
64
- "numLikes": 24
65
- }
1
+ [{
2
+ "id": "001",
3
+ "title": "Card title that wraps to a new line",
4
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
5
+ "image": "bootstrap/images/pic-home.jpg",
6
+ "bookmarked": false,
7
+ "numLikes": 110
8
+ },
9
+ {
10
+ "id": "002",
11
+ "title": "Card title",
12
+ "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
13
+ "image": "",
14
+ "bookmarked": false,
15
+ "numLikes": 9
16
+ },
17
+ {
18
+ "id": "003",
19
+ "title": "Card title",
20
+ "description": "This card has supporting text below as a natural lead-in to additional content.",
21
+ "image": "bootstrap/images/pic-deck.jpg",
22
+ "bookmarked": false,
23
+ "numLikes": 8
24
+ },
25
+ {
26
+ "id": "004",
27
+ "title": "Card title",
28
+ "description": "This card has supporting text below as a natural lead-in to additional content.",
29
+ "image": "bootstrap/images/pic-carpenter.jpg",
30
+ "bookmarked": false,
31
+ "numLikes": 8,
32
+ "highlight": true
33
+ },
34
+ {
35
+ "id": "005",
36
+ "title": "Card title",
37
+ "description": "This card has supporting text below as a natural lead-in to additional content.",
38
+ "image": "",
39
+ "bookmarked": false,
40
+ "numLikes": 68
41
+ },
42
+ {
43
+ "id": "006",
44
+ "title": "Card title that wraps to a new line",
45
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
46
+ "image": "bootstrap/images/pic-bathrooms.jpg",
47
+ "bookmarked": true,
48
+ "numLikes": 99
49
+ },
50
+ {
51
+ "id": "007",
52
+ "title": "Card title",
53
+ "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
54
+ "image": "",
55
+ "bookmarked": false,
56
+ "numLikes": 9
57
+ },
58
+ {
59
+ "id": "008",
60
+ "title": "Card title",
61
+ "description": "This card has supporting text below as a natural lead-in to additional content.",
62
+ "image": "bootstrap/images/pic-backyard.jpg",
63
+ "bookmarked": false,
64
+ "numLikes": 24
65
+ }
66
66
  ]
@@ -1,58 +1,58 @@
1
- [{
2
- "id": "001",
3
- "title": "Card title that wraps to a new line",
4
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
5
- "image": "bootstrap/images/pic-home.jpg",
6
- "bookmarked": false,
7
- "numLikes": 110
8
- },
9
- {
10
- "id": "456",
11
- "title": "Card title",
12
- "description": "This card has supporting text below as a natural lead-in to additional content.",
13
- "image": "",
14
- "bookmarked": false,
15
- "numLikes": 8
16
- },
17
- {
18
- "id": "789",
19
- "title": "Sample carpemter service",
20
- "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
21
- "image": "bootstrap/images/pic-carpenter.jpg",
22
- "bookmarked": false,
23
- "numLikes": 8,
24
- "highlight": true
25
- },
26
- {
27
- "id": "888",
28
- "title": "Sample timber floor service",
29
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
30
- "image": "bootstrap/images/pic-deck.jpg",
31
- "bookmarked": false,
32
- "numLikes": 8
33
- },
34
- {
35
- "id": "222",
36
- "title": "Sample timber floor service",
37
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
38
- "image": "",
39
- "bookmarked": false,
40
- "numLikes": 8
41
- },
42
- {
43
- "id": "333",
44
- "title": "Sample boothroom service",
45
- "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
46
- "image": "bootstrap/images/pic-bathrooms.jpg",
47
- "bookmarked": true,
48
- "numLikes": 8
49
- },
50
- {
51
- "id": "444",
52
- "title": "Sample gardening service",
53
- "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
54
- "image": "bootstrap/images/pic-backyard.jpg",
55
- "bookmarked": false,
56
- "numLikes": 8
57
- }
1
+ [{
2
+ "id": "001",
3
+ "title": "Card title that wraps to a new line",
4
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
5
+ "image": "bootstrap/images/pic-home.jpg",
6
+ "bookmarked": false,
7
+ "numLikes": 110
8
+ },
9
+ {
10
+ "id": "456",
11
+ "title": "Card title",
12
+ "description": "This card has supporting text below as a natural lead-in to additional content.",
13
+ "image": "",
14
+ "bookmarked": false,
15
+ "numLikes": 8
16
+ },
17
+ {
18
+ "id": "789",
19
+ "title": "Sample carpemter service",
20
+ "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
21
+ "image": "bootstrap/images/pic-carpenter.jpg",
22
+ "bookmarked": false,
23
+ "numLikes": 8,
24
+ "highlight": true
25
+ },
26
+ {
27
+ "id": "888",
28
+ "title": "Sample timber floor service",
29
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
30
+ "image": "bootstrap/images/pic-deck.jpg",
31
+ "bookmarked": false,
32
+ "numLikes": 8
33
+ },
34
+ {
35
+ "id": "222",
36
+ "title": "Sample timber floor service",
37
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
38
+ "image": "",
39
+ "bookmarked": false,
40
+ "numLikes": 8
41
+ },
42
+ {
43
+ "id": "333",
44
+ "title": "Sample boothroom service",
45
+ "description": "This is a wider card with supporting text below as a natural lead-in to additional content. This card has even longer content than the first to show that equal height action.",
46
+ "image": "bootstrap/images/pic-bathrooms.jpg",
47
+ "bookmarked": true,
48
+ "numLikes": 8
49
+ },
50
+ {
51
+ "id": "444",
52
+ "title": "Sample gardening service",
53
+ "description": "This is a longer card with supporting text below as a natural lead-in to additional content. This content is a little bit longer.",
54
+ "image": "bootstrap/images/pic-backyard.jpg",
55
+ "bookmarked": false,
56
+ "numLikes": 8
57
+ }
58
58
  ]