-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.min.js
1 lines (1 loc) · 2.84 KB
/
app.min.js
1
$(function(){var a={firstCat:null,secondCat:null,cats:[{name:"Jim",url:"https://lh3.ggpht.com/nlI91wYNCrjjNy5f-S3CmVehIBM4cprx-JFWOztLk7vFlhYuFR6YnxcT446AvxYg4Ab7M1Fy0twaOCWYcUk=s0#w=640&h=426",count:0,id:"first"},{name:"Bob",url:"https://lh3.ggpht.com/kixazxoJ2ufl3ACj2I85Xsy-Rfog97BM75ZiLaX02KgeYramAEqlEHqPC3rKqdQj4C1VFnXXryadFs1J9A=s0#w=640&h=496",count:0,id:"second"},{name:"Paul",url:"https://lh5.ggpht.com/LfjkdmOKkGLvCt-VuRlWGjAjXqTBrPjRsokTNKBtCh8IFPRetGaXIpTQGE2e7ZCUaG2azKNkz38KkbM_emA=s0#w=640&h=454",count:0,id:"third"},{name:"Anthony",url:"https://www.petfinder.com/wp-content/uploads/2012/11/140272627-grooming-needs-senior-cat-632x475.jpg",count:0,id:"fourth"},{name:"Andrew",url:"https://pbs.twimg.com/profile_images/378800000532546226/dbe5f0727b69487016ffd67a6689e75a.jpeg",count:0,id:"fifth"}]},b={init:function(){c.init()},getCats:function(){return a.cats},setFirstCat:function(b){a.firstCat=b},setSecondCat:function(b){a.secondCat=b},incrementCounterFirst:function(){a.firstCat.count++},incrementCounterSecond:function(){a.secondCat.count++},firstCatCount:function(){return a.firstCat.count},secondCatCount:function(){return a.secondCat.count},firstCatID:function(){return a.firstCat.id},secondCatID:function(){return a.secondCat.id}},c={init:function(){this.catImage=document.getElementById("cat_one"),this.catImageTwo=document.getElementById("cat_two"),this.catName=document.getElementById("cat1Name"),this.catNameTwo=document.getElementById("cat2Name"),this.firstCatClickCount=document.getElementById("catCount"),this.secondCatClickCount=document.getElementById("catCount2"),this.clearCat=document.getElementById("clearCat"),this.render(),this.src=""},render:function(){var d=b.getCats();for(i=0;i<d.length;i++)catClicked=document.getElementById(d[i].id),catClicked.src=d[i].url,catClicked.addEventListener("click",function(a){return function(){""===c.catImage.src||c.catImage.src===c.src?(c.catImage.src=a.url,c.catName.textContent=a.name,b.setFirstCat(a),$("#"+a.id).hide()):""!==c.catImageTwo.src&&c.catImageTwo.src!==c.src||(c.catImageTwo.src=a.url,c.catNameTwo.textContent=a.name,b.setSecondCat(a),$("#"+a.id).hide())}}(d[i]));this.catImage.addEventListener("click",function(){b.incrementCounterFirst(),c.firstCatClickCount.textContent=b.firstCatCount(),console.log(b.firstCatCount())},!1),this.catImageTwo.addEventListener("click",function(){b.incrementCounterSecond(),c.secondCatClickCount.textContent=b.secondCatCount(),console.log(b.secondCatCount())},!1),this.clearCat.addEventListener("click",function(){c.catImage.src="",console.log(c.catImage.src.length),c.src=c.catImage.src,c.catName.textContent="",c.firstCatClickCount.textContent="",null!==a.firstCat&&$("#"+b.firstCatID()).show(),c.catImageTwo.src="",console.log(c.catImageTwo.src),c.catNameTwo.textContent="",c.secondCatClickCount.textContent="",null!==a.secondCat&&$("#"+b.secondCatID()).show()},!1)}};b.init()});