Skip to content

Instantly share code, notes, and snippets.

@Garfeild
Created July 29, 2012 23:10
Show Gist options
  • Save Garfeild/3202459 to your computer and use it in GitHub Desktop.
Save Garfeild/3202459 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Market Share - eHealth strategy</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/style_resources.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css"/>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="js/slide.js" type="text/javascript"></script>
<script src="js/popup.js" type="text/javascript"></script>
<script type="text/javascript">
function loadCartItems(){
$.ajax({
type: "GET",
url: "cart_items.xml",
dataType: "xml",
success: function(xml) {
//reset array if loaded again
contentIdList = new Array();
contentURLList = new Array();
contentIdList_counter = 0;
$(xml).find('site').each(function(){
//add node value to an array
contentIdNode = ['' + $(this).attr('id'), '' + $(this).find('title').text(), '' + $(this).find('mediatype').text()];
//add new array to array parent
contentIdList[contentIdList_counter] = contentIdNode;
//increment counter
// contentIdList_counter = contentIdList_counter + 1;
var id = $(this).attr('id');
var title = $(this).find('title').text();
var url = $(this).find('url').text();
var mediatype = $(this).find('mediatype').text();
contentURLList[contentIdList_counter] = url;
contentIdList_counter = contentIdList_counter + 1;
$('<li class="item"></li>').html('<a class="view" id="link_'+id+'" href="../'+url+'">'+'<img src="images/'+mediatype+'_icon.png"/>'+title+'</a>').appendTo('#xml');
$('<a href="#" class="cartLink" id="cart_'+id+'">').html('<img id="icon_'+id+'" src="images/cart_icon.png"/></a>').appendTo('#xml');
$('#link_'+id).click(function() {
//alert('View: '+id);
});
//cart icon clicked
$('#cart_'+id).click(function() {
img_src = '' + $("#icon_" + id).attr("src");
triggerAddItemToCart(url);
//if on or off
if (img_src.indexOf("cart_icon_on") != -1){
//change img src
turnCartIconOff(id);
// $("a.cartLink").attr( "href", "../remove."+url);
} else {
//change img src
turnCartIconOn(id);
//send PDF to cart
// $("a.cartLink").attr( "href", "../add."+url);
}
});
});
cartItemsLoaded();
}
});
}
function cartItemsLoaded(){
// TO DO: trigger link press for app to intercep
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "ipresent:cartItemsLoaded");
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
function resetCartItems(){
$(document).find('#xml').empty();
loadCartItems();
}
$(document).ready(loadCartItems());
</script>
<script type="text/javascript">
//array full of possible variables
var contentIdList;
var contentURLList;
//array counter
var contentIdList_counter;
// Takes a list of items separated by string, and loops through each to set them on or off in cart
function initializeCartItemsFromString(commadelimitedItems){
var itemsArray = commadelimitedItems.split(","); // separate string into array
// loop through items
for (k=0; k<itemsArray.length; k++){
// Call function to set image on
addItemToCartWithName(itemsArray[k]);
}
return 'OK';
}
function resetSelectedCartItems(){
var itemsArray = commadelimitedItems.split(","); // separate string into array
// loop through items
for (k=0; k<itemsArray.length; k++){
// Call function to set image on
addItemToCartWithName(itemsArray[k]);
}
}
function addItemToCartWithName(id){
//match found boolean
var id_match = false;
var idx = -1;
//loop through parent array
for (var i = 0; i < contentURLList.length; i++)
{
if (contentURLList[i] == id)
{
//postive
turnCartIconOn(contentIdList[i]);
}
}
}
function isContentIdInList(id, list){
}
function triggerAddItemToCart(name){
// TO DO: trigger link press for app to intercep
var iframe = document.createElement("IFRAME");
iframe.setAttribute("src", "ipresent:addItemToCartWithName:"+name);
document.documentElement.appendChild(iframe);
iframe.parentNode.removeChild(iframe);
iframe = null;
}
//change img src by id
function turnCartIconOn(id){
$("#icon_" + id).attr({ src: "images/cart_icon_on.png"});
}
function turnCartIconOff(id){
$("#icon_" + id).attr({ src: "images/cart_icon.png"});
}
</script>
</head>
<body>
<div id="pageContent">
<div class="documents">
<div style="margin: 10px 0 0 0;"><img src="images/topbar.png" width="600px" height="12"/></div>
<h2>Resources</h2>
<ul id="xml">
<!--Generated Dynamically from XML>-->
</ul>
</div>
<!--
<div id="window" style="position:absolute; top:500px; background:#0C0; height:500px; width:100%;">
</div>
-->
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment