function createGiftElement(giftDescription, giftLink, giftReceived, giftTitle, giftKey, giftWhere, giftBuyer, giftUid,
                             giftDate){
    console.log("Creating " + giftUid);
    try{
      document.getElementById("TestGift").remove();
    } catch (err) {}

    giftCounter++;

    var liItem = document.createElement("LI");
    liItem.id = "gift" + giftUid;
    liItem.className = "gift";
    if(giftReceived == 1) {
      liItem.className += " checked";
      //console.log("Checked, created");
    }
    liItem.onclick = function (){
      var spanGift = document.getElementsByClassName("close")[0];
      var buyBtn = document.getElementById('giftBuy');
      var dontBuyBtn = document.getElementById('giftDontBuy');
      var descField = document.getElementById('giftDescription');
      var boughtField = document.getElementById('giftBought');
      var titleField = document.getElementById('giftTitle');
      var whereField = document.getElementById('giftWhere');
      var linkField = document.getElementById('giftLink');

      noteTitleField = document.getElementById('notificationTitle');
      noteInfoField = document.getElementById('notificationInfo');

      if (giftLink != ""){
        linkField.innerHTML = "Click me to go to the webpage!";
        linkField.onclick = function() {
          var newGiftLink = "http://";
          if(giftLink.includes("https://")){
            giftLink = giftLink.slice(8, giftLink.length);
          } else if (giftLink.includes("http://")){
            giftLink = giftLink.slice(7, giftLink.length);
          }
          newGiftLink += giftLink;
          window.open(newGiftLink, "_blank");
        };
      } else {
        linkField.innerHTML = "There was no link provided";
        linkField.onclick = function() {
        };
      }
      if(giftDescription != "") {
        descField.innerHTML = "Description: " + giftDescription;
      } else {
        descField.innerHTML = "There was no description provided";
      }
      titleField.innerHTML = giftTitle;
      if(giftWhere != "") {
        whereField.innerHTML = "This can be found at: " + giftWhere;
      } else {
        whereField.innerHTML = "There was no location provided";
      }
      if(giftReceived == 1){
        if(giftBuyer == "" || giftBuyer == null || giftBuyer == undefined){
          boughtField.innerHTML = "This gift has been bought";
        } else {
          boughtField.innerHTML = "This gift was bought by " + giftBuyer;
        }
      } else {
        boughtField.innerHTML = "This gift has not been bought yet";
      }
      if(giftDate != undefined) {
        if (giftDate != "") {
          giftCreationDate.innerHTML = "Created on: " + giftDate;
        } else {
          giftCreationDate.innerHTML = "Creation date not available";
        }
      } else {
        giftCreationDate.innerHTML = "Creation date not available";
      }
      buyBtn.onclick = function(){
        if (giftReceived == 0) {
          firebase.database().ref("users/" + user.uid + "/giftList/" + giftKey).update({
            received: 1,
            buyer: currentUser.userName
          });
        } else {
          alert("This gift has already been marked as bought!");
        }
      };
      dontBuyBtn.onclick = function(){
        if (giftReceived == 1) {
          if (giftBuyer == currentUser.userName || giftBuyer == "") {
            firebase.database().ref("users/" + user.uid + "/giftList/" + giftKey).update({
              received: 0,
              buyer: ""
            });
          } else {
            alert("Only the buyer, " + giftBuyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " +
              "if this has been done in error.");
          }
        } else {
          alert("This gift has already been marked as \"Un-Bought\"!");
        }
      };

      //show modal
      modal.style.display = "block";
      currentModalOpen = giftUid;
      console.log("Modal Open: " + currentModalOpen);

      //close on close
      spanGift.onclick = function() {
        currentModalOpen = "";
        console.log("Closed modal");
        modal.style.display = "none";
      };

      //close on click
      window.onclick = function(event) {
        if (event.target == modal) {
          currentModalOpen = "";
          console.log("Closed modal");
          modal.style.display = "none";
        }
      };
    };
    var textNode = document.createTextNode(giftTitle);
    liItem.appendChild(textNode);

    giftList.insertBefore(liItem, document.getElementById("giftListContainer").childNodes[0]);
    clearInterval(offlineTimer);
  }
//with the proper gift's details and buttons.
with the proper gift's details and buttons.
with the proper gift ' s details and buttons .
function createGiftElement(giftDescription, giftLink, giftReceived, giftTitle, giftKey, giftWhere, giftBuyer, giftUid,
                             giftDate){
    console.log("Creating " + giftUid);
    try{
      document.getElementById("TestGift").remove();
    } catch (err) {}
    giftCounter++;
    var liItem = document.createElement("LI");
    liItem.id = "gift" + giftUid;
    liItem.className = "gift";
    if(giftReceived == 1) {
      liItem.className += " checked";
    }
    liItem.onclick = function (){
      var spanGift = document.getElementsByClassName("close")[0];
      var buyBtn = document.getElementById('giftBuy');
      var dontBuyBtn = document.getElementById('giftDontBuy');
      var descField = document.getElementById('giftDescription');
      var boughtField = document.getElementById('giftBought');
      var titleField = document.getElementById('giftTitle');
      var whereField = document.getElementById('giftWhere');
      var linkField = document.getElementById('giftLink');
      noteTitleField = document.getElementById('notificationTitle');
      noteInfoField = document.getElementById('notificationInfo');
      if (giftLink != ""){
        linkField.innerHTML = "Click me to go to the webpage!";
        linkField.onclick = function() {
          var newGiftLink = "http://";
          if(giftLink.includes("https://")){
            giftLink = giftLink.slice(8, giftLink.length);
          } else if (giftLink.includes("http://")){
            giftLink = giftLink.slice(7, giftLink.length);
          }
          newGiftLink += giftLink;
          window.open(newGiftLink, "_blank");
        };
      } else {
        linkField.innerHTML = "There was no link provided";
        linkField.onclick = function() {
        };
      }
      if(giftDescription != "") {
        descField.innerHTML = "Description: " + giftDescription;
      } else {
        descField.innerHTML = "There was no description provided";
      }
      titleField.innerHTML = giftTitle;
      if(giftWhere != "") {
        whereField.innerHTML = "This can be found at: " + giftWhere;
      } else {
        whereField.innerHTML = "There was no location provided";
      }
      if(giftReceived == 1){
        if(giftBuyer == "" || giftBuyer == null || giftBuyer == undefined){
          boughtField.innerHTML = "This gift has been bought";
        } else {
          boughtField.innerHTML = "This gift was bought by " + giftBuyer;
        }
      } else {
        boughtField.innerHTML = "This gift has not been bought yet";
      }
      if(giftDate != undefined) {
        if (giftDate != "") {
          giftCreationDate.innerHTML = "Created on: " + giftDate;
        } else {
          giftCreationDate.innerHTML = "Creation date not available";
        }
      } else {
        giftCreationDate.innerHTML = "Creation date not available";
      }
      buyBtn.onclick = function(){
        if (giftReceived == 0) {
          firebase.database().ref("users/" + user.uid + "/giftList/" + giftKey).update({
            received: 1,
            buyer: currentUser.userName
          });
        } else {
          alert("This gift has already been marked as bought!");
        }
      };
      dontBuyBtn.onclick = function(){
        if (giftReceived == 1) {
          if (giftBuyer == currentUser.userName || giftBuyer == "") {
            firebase.database().ref("users/" + user.uid + "/giftList/" + giftKey).update({
              received: 0,
              buyer: ""
            });
          } else {
            alert("Only the buyer, " + giftBuyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " +
              "if this has been done in error.");
          }
        } else {
          alert("This gift has already been marked as \"Un-Bought\"!");
        }
      };
      modal.style.display = "block";
      currentModalOpen = giftUid;
      console.log("Modal Open: " + currentModalOpen);
      spanGift.onclick = function() {
        currentModalOpen = "";
        console.log("Closed modal");
        modal.style.display = "none";
      };
      window.onclick = function(event) {
        if (event.target == modal) {
          currentModalOpen = "";
          console.log("Closed modal");
          modal.style.display = "none";
        }
      };
    };
    var textNode = document.createTextNode(giftTitle);
    liItem.appendChild(textNode);
    giftList.insertBefore(liItem, document.getElementById("giftListContainer").childNodes[0]);
    clearInterval(offlineTimer);
  }
function createGiftElement ( giftDescription , giftLink , giftReceived , giftTitle , giftKey , giftWhere , giftBuyer , giftUid , giftDate ) { console . log ( "Creating " + giftUid ) ; try { document . getElementById ( "TestGift" ) . remove ( ) ; } catch ( err ) { } giftCounter ++ ; var liItem = document . createElement ( "LI" ) ; liItem . id = "gift" + giftUid ; liItem . className = "gift" ; if ( giftReceived == 1 ) { liItem . className += " checked" ; } liItem . onclick = function ( ) { var spanGift = document . getElementsByClassName ( "close" ) [ 0 ] ; var buyBtn = document . getElementById ( 'giftBuy' ) ; var dontBuyBtn = document . getElementById ( 'giftDontBuy' ) ; var descField = document . getElementById ( 'giftDescription' ) ; var boughtField = document . getElementById ( 'giftBought' ) ; var titleField = document . getElementById ( 'giftTitle' ) ; var whereField = document . getElementById ( 'giftWhere' ) ; var linkField = document . getElementById ( 'giftLink' ) ; noteTitleField = document . getElementById ( 'notificationTitle' ) ; noteInfoField = document . getElementById ( 'notificationInfo' ) ; if ( giftLink != "" ) { linkField . innerHTML = "Click me to go to the webpage!" ; linkField . onclick = function ( ) { var newGiftLink = "http://" ; if ( giftLink . includes ( "https://" ) ) { giftLink = giftLink . slice ( 8 , giftLink . length ) ; } else if ( giftLink . includes ( "http://" ) ) { giftLink = giftLink . slice ( 7 , giftLink . length ) ; } newGiftLink += giftLink ; window . open ( newGiftLink , "_blank" ) ; } ; } else { linkField . innerHTML = "There was no link provided" ; linkField . onclick = function ( ) { } ; } if ( giftDescription != "" ) { descField . innerHTML = "Description: " + giftDescription ; } else { descField . innerHTML = "There was no description provided" ; } titleField . innerHTML = giftTitle ; if ( giftWhere != "" ) { whereField . innerHTML = "This can be found at: " + giftWhere ; } else { whereField . innerHTML = "There was no location provided" ; } if ( giftReceived == 1 ) { if ( giftBuyer == "" || giftBuyer == null || giftBuyer == undefined ) { boughtField . innerHTML = "This gift has been bought" ; } else { boughtField . innerHTML = "This gift was bought by " + giftBuyer ; } } else { boughtField . innerHTML = "This gift has not been bought yet" ; } if ( giftDate != undefined ) { if ( giftDate != "" ) { giftCreationDate . innerHTML = "Created on: " + giftDate ; } else { giftCreationDate . innerHTML = "Creation date not available" ; } } else { giftCreationDate . innerHTML = "Creation date not available" ; } buyBtn . onclick = function ( ) { if ( giftReceived == 0 ) { firebase . database ( ) . ref ( "users/" + user . uid + "/giftList/" + giftKey ) . update ( { received : 1 , buyer : currentUser . userName } ) ; } else { alert ( "This gift has already been marked as bought!" ) ; } } ; dontBuyBtn . onclick = function ( ) { if ( giftReceived == 1 ) { if ( giftBuyer == currentUser . userName || giftBuyer == "" ) { firebase . database ( ) . ref ( "users/" + user . uid + "/giftList/" + giftKey ) . update ( { received : 0 , buyer : "" } ) ; } else { alert ( "Only the buyer, " + giftBuyer + ", can \"Un-Buy\" this gift. Please contact them to undo this action " + "if this has been done in error." ) ; } } else { alert ( "This gift has already been marked as \"Un-Bought\"!" ) ; } } ; modal . style . display = "block" ; currentModalOpen = giftUid ; console . log ( "Modal Open: " + currentModalOpen ) ; spanGift . onclick = function ( ) { currentModalOpen = "" ; console . log ( "Closed modal" ) ; modal . style . display = "none" ; } ; window . onclick = function ( event ) { if ( event . target == modal ) { currentModalOpen = "" ; console . log ( "Closed modal" ) ; modal . style . display = "none" ; } } ; } ; var textNode = document . createTextNode ( giftTitle ) ; liItem . appendChild ( textNode ) ; giftList . insertBefore ( liItem , document . getElementById ( "giftListContainer" ) . childNodes [ 0 ] ) ; clearInterval ( offlineTimer ) ; }
with the proper gift's details and buttons.
with the proper gift ' s details and buttons .
//console.log("Checked, created"); //show modal //close on close //close on click