From 9b7f2fefbe8b4f12a61dc9440894763175ed6367 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 20 Apr 2022 23:53:23 +1000 Subject: [PATCH] Chap02 -> Managing templates with jQuery --- ko-cart/index.html | 194 ------------------------ ko-cart/js/viewmodel.js | 24 ++- ko-cart/views/add-to-catalog-modal.html | 76 ++++++++++ ko-cart/views/cart-item.html | 36 +++++ ko-cart/views/cart-widget.html | 4 + ko-cart/views/cart.html | 18 +++ ko-cart/views/catalog.html | 48 ++++++ ko-cart/views/finish-order-modal.html | 24 +++ ko-cart/views/header.html | 18 +++ ko-cart/views/order.html | 36 +++++ 10 files changed, 283 insertions(+), 195 deletions(-) create mode 100644 ko-cart/views/add-to-catalog-modal.html create mode 100644 ko-cart/views/cart-item.html create mode 100644 ko-cart/views/cart-widget.html create mode 100644 ko-cart/views/cart.html create mode 100644 ko-cart/views/catalog.html create mode 100644 ko-cart/views/finish-order-modal.html create mode 100644 ko-cart/views/header.html create mode 100644 ko-cart/views/order.html diff --git a/ko-cart/index.html b/ko-cart/index.html index f4c56b8..181d03d 100644 --- a/ko-cart/index.html +++ b/ko-cart/index.html @@ -21,200 +21,6 @@
- - - - - - - - - diff --git a/ko-cart/js/viewmodel.js b/ko-cart/js/viewmodel.js index 810640c..9a5828d 100644 --- a/ko-cart/js/viewmodel.js +++ b/ko-cart/js/viewmodel.js @@ -134,4 +134,26 @@ var vm = (function () { visibleCart: visibleCart }; })(); -ko.applyBindings(vm); + +var templates = [ + 'header', + 'catalog', + 'cart', + 'cart-item', + 'cart-widget', + 'order', + 'add-to-catalog-modal', + 'finish-order-modal' +]; + +var busy = templates.length; +templates.forEach(function(tpl){ + "use strict"; + $.get('views/' + tpl + '.html').then(function(data) { + $('body').append(data); + busy--; + if (!busy) { + ko.applyBindings(vm); + } + }) +}) \ No newline at end of file diff --git a/ko-cart/views/add-to-catalog-modal.html b/ko-cart/views/add-to-catalog-modal.html new file mode 100644 index 0000000..a8df684 --- /dev/null +++ b/ko-cart/views/add-to-catalog-modal.html @@ -0,0 +1,76 @@ + diff --git a/ko-cart/views/cart-item.html b/ko-cart/views/cart-item.html new file mode 100644 index 0000000..1f3f6d5 --- /dev/null +++ b/ko-cart/views/cart-item.html @@ -0,0 +1,36 @@ + diff --git a/ko-cart/views/cart-widget.html b/ko-cart/views/cart-widget.html new file mode 100644 index 0000000..6e8491f --- /dev/null +++ b/ko-cart/views/cart-widget.html @@ -0,0 +1,4 @@ + diff --git a/ko-cart/views/cart.html b/ko-cart/views/cart.html new file mode 100644 index 0000000..9032529 --- /dev/null +++ b/ko-cart/views/cart.html @@ -0,0 +1,18 @@ + diff --git a/ko-cart/views/catalog.html b/ko-cart/views/catalog.html new file mode 100644 index 0000000..6f4df0e --- /dev/null +++ b/ko-cart/views/catalog.html @@ -0,0 +1,48 @@ + diff --git a/ko-cart/views/finish-order-modal.html b/ko-cart/views/finish-order-modal.html new file mode 100644 index 0000000..33bb66e --- /dev/null +++ b/ko-cart/views/finish-order-modal.html @@ -0,0 +1,24 @@ + diff --git a/ko-cart/views/header.html b/ko-cart/views/header.html new file mode 100644 index 0000000..12a358f --- /dev/null +++ b/ko-cart/views/header.html @@ -0,0 +1,18 @@ + diff --git a/ko-cart/views/order.html b/ko-cart/views/order.html new file mode 100644 index 0000000..c308ce8 --- /dev/null +++ b/ko-cart/views/order.html @@ -0,0 +1,36 @@ +