Commit 2280008a authored by Ivan Tyagov's avatar Ivan Tyagov

Add a udimentary shopping cart suppor using localStorage browser API.

parent 9d3c0361
var RenderJs={
bootstrap: function (root){
// initial load application gadget
RenderJs.load(root);
},
load: function (root) {
// Load gadget layout by traversing DOM
gadget_list = root.find("[gadget]");
// Load chilren
gadget_list.each(function(i,v){RenderJs.loadGadgetFromUrl($(this));});
},
loadGadgetFromUrl: function(gadget) {
// Load gadget's SPECs from URL
url = gadget.attr("gadget")
//console.log(url);
$.ajax({url:url,
success: function (data) {
RenderJs.parse (data);
gadget.append(data);
// a gadget may contain sub gadgets
RenderJs.load(gadget);
//console.log(url+ data);
gadget.find("a").each(
function(){
$(this).click(
function(){
alert("disabled link, do action on *same* page"); return false;})}
)
},
});
},
// XXX: finish below
parse: function (data){
// XXX: Parse an HTML document and get out .js and .css
// XXX: load .css
// XXX: load .jss (see requirejs)
// $.ajax({url:"jquery-ui.js",
// type: "script"});
},
save: function () {
// XXX: Save gadget layoyut by traversing DOM and using some kind of storage
console.log("XXX: save");
},
}
// init all when DOM is ready
$(document).ready(function() {
RenderJs.bootstrap($("#application"));
});
...@@ -75,7 +75,7 @@ ...@@ -75,7 +75,7 @@
<!--<strong class="no">Out of Stock</strong>//--> <!--<strong class="no">Out of Stock</strong>//-->
</li> </li>
<li> <li>
<button type="submit">Add to Cart</button> <button type="submit" onclick="return addToCart();">Add to Cart</button>
</li> </li>
</ol> </ol>
</form> </form>
...@@ -111,6 +111,19 @@ ...@@ -111,6 +111,19 @@
<script type="text/javascript" language="javascript"> <script type="text/javascript" language="javascript">
function addToCart(){
shopping_cart = localStorage.getItem("ivan_new_shopping_cart");
if (shopping_cart==null){
shopping_cart = "";
}
item = $(".product-title").text();
quality = $("#input-amount").attr("value");
shopping_cart = shopping_cart + "<br>Item: " + item + ", Quality: " + quality;
localStorage.setItem("ivan_new_shopping_cart", shopping_cart);
updateShoppingCart();
return false;
}
function updateProduct(url){ function updateProduct(url){
$.ajax({ $.ajax({
url: url, url: url,
......
<div class="secondary"> <div class="secondary">
<div id="shopping-cart"
gadget="portal_gadgets/shopping_cart/gadget.html"
gadget:property="{}"></div>
<ol> <ol>
<li> <li>
......
...@@ -10,7 +10,8 @@ ...@@ -10,7 +10,8 @@
<ol id="cart"> <ol id="cart">
<li class="meta-1"><a href="#">my account</a></li> <li class="meta-1"><a href="#">my account</a></li>
<li class="meta-2"><a href="#"><img src="img/icon-cart.gif" alt="icon-cart" width="17" height="14" /> 22</a></li> <li class="meta-2"><a href="#"><img src="img/icon-cart.gif" alt="icon-cart" width="17" height="14" /> 22</a></li>
<li class="meta-3"><a href="#">view cart &raquo;</a></li> <li class="meta-3"><a href="#" onclick="updateShoppingCart();$('#shopping-cart').toggle(); return false;">view cart &raquo;</a></li>
</ol> </ol>
</div> </div>
</div> </div>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment