조국현

Merge branch 'feature/shareKakaoFaceBook' into develop

1 +Kakao.init('fill your own key');
2 +const APP_ID = 'fill your own ID';
3 +const APP_KEY = 'fill your own key';
1 var caloriesLimit=9999; 4 var caloriesLimit=9999;
2 function getCheckboxValue(event) { 5 function getCheckboxValue(event) {
3 if(event.target.checked) { 6 if(event.target.checked) {
...@@ -7,11 +10,9 @@ function getCheckboxValue(event) { ...@@ -7,11 +10,9 @@ function getCheckboxValue(event) {
7 } 10 }
8 11
9 } 12 }
10 -
11 const searchForm = document.querySelector('form'); 13 const searchForm = document.querySelector('form');
12 const searchResultDiv = document.querySelector('.search-result') 14 const searchResultDiv = document.querySelector('.search-result')
13 -const APP_ID = 'fill your own ID'; 15 +
14 -const APP_KEY = 'fill your own key';
15 searchForm.addEventListener('submit', function(event){ 16 searchForm.addEventListener('submit', function(event){
16 if(document.getElementById('name').value.length === 0){ 17 if(document.getElementById('name').value.length === 0){
17 alert('한글자 이상 입력해주세요'); 18 alert('한글자 이상 입력해주세요');
...@@ -27,19 +28,33 @@ searchForm.addEventListener('submit', function(event){ ...@@ -27,19 +28,33 @@ searchForm.addEventListener('submit', function(event){
27 fetchAPI(); 28 fetchAPI();
28 } 29 }
29 }); 30 });
30 -function shareRecipe(sns,urlInfo) { 31 +function shareRecipe(sns,urlInfo,foodImage,foodLabel) {
31 - console.log(urlInfo); 32 + var documentUrl = document.URL;
32 - var thisUrl = document.URL; 33 + var snsWrite = "친구에게 요리 레시피 추천! 같이 요리 해먹자~"+urlInfo;
33 - var snsWrite = "요리 레시피 공유하기"+urlInfo;
34 if( sns == 'facebook' ) { 34 if( sns == 'facebook' ) {
35 - var url = "http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(thisUrl); 35 + var url = "http://www.facebook.com/sharer/sharer.php?u="+encodeURIComponent(urlInfo);
36 window.open(url, "", "width=600, height=4060"); 36 window.open(url, "", "width=600, height=4060");
37 } 37 }
38 else if( sns == 'twitter' ) { 38 else if( sns == 'twitter' ) {
39 - var url = "http://twitter.com/share?url="+encodeURIComponent(thisUrl)+"&text="+encodeURIComponent(snsWrite); 39 + var url = "http://twitter.com/share?url="+encodeURIComponent(documentUrl)+"&text="+encodeURIComponent(snsWrite);
40 window.open(url, "tweetPop", "width=600, height=400,scrollbars=yes"); 40 window.open(url, "tweetPop", "width=600, height=400,scrollbars=yes");
41 + }else if(sns=='kakaotalk'){
42 + Kakao.Link.createDefaultButton({
43 + container:'#buttonkakao',
44 + objectType:'feed',
45 + content:{
46 + title:"친구에게 요리 레시피 추천!",
47 + description:foodLabel+" 같이 요리 해먹자~",
48 + imageUrl:foodImage,
49 + link:{
50 + mobileWebUrl:urlInfo,
51 + webUrl:urlInfo
52 + },
53 + },
54 + });
41 } 55 }
42 } 56 }
57 +
43 async function fetchAPI(){ 58 async function fetchAPI(){
44 const recipeURL = `https://api.edamam.com/search?q=${searchQuery}&app_id=${APP_ID}&app_key=${APP_KEY}`; 59 const recipeURL = `https://api.edamam.com/search?q=${searchQuery}&app_id=${APP_ID}&app_key=${APP_KEY}`;
45 const response = await fetch(recipeURL); 60 const response = await fetch(recipeURL);
...@@ -60,9 +75,6 @@ function boxinfo(results){ ...@@ -60,9 +75,6 @@ function boxinfo(results){
60 else{ 75 else{
61 boxsinfo += 76 boxsinfo +=
62 ` 77 `
63 - <style>
64 -
65 - </style>
66 78
67 <div class="item"> 79 <div class="item">
68 <img src="${result.recipe.image}" alt=""> 80 <img src="${result.recipe.image}" alt="">
...@@ -73,10 +85,13 @@ function boxinfo(results){ ...@@ -73,10 +85,13 @@ function boxinfo(results){
73 <a href="https://www.youtube.com/results?search_query=${result.recipe.label}+home+recipe" target="_blank">View Videos</a> 85 <a href="https://www.youtube.com/results?search_query=${result.recipe.label}+home+recipe" target="_blank">View Videos</a>
74 <ul class="sns"> 86 <ul class="sns">
75 <li class="facebook"> 87 <li class="facebook">
76 - <a href="#n" onclick="shareRecipe('facebook','${result.recipe.url}'');return false;" class="facebook" target="_self" title="페이스북 공유"><span class="skip">페이스북</span></a> 88 + <a href="#n" onclick="shareRecipe('facebook','${result.recipe.url}');return false;" class="facebook" target="_self" title="페이스북 공유"><span class="skip">페이스북</span></a>
77 </li> 89 </li>
78 <li class="twitter"> 90 <li class="twitter">
79 - <a href="#n" onclick="shareRecipe('twitter','${result.recipe.url}');return false;" class="twitter" target="_self" title="트위터 공유"><span class="skip">트위터</span></a> 91 + <a href="" onclick="shareRecipe('twitter','${result.recipe.url}');return false;" class="twitter" target="_self" title="트위터 공유"><span class="skip">트위터</span></a>
92 + </li>
93 + <li class="kakaotalk">
94 + <a href="javascript:shareRecipe('kakaotalk','${result.recipe.url}','${result.recipe.image}','${result.recipe.label}')" id="buttonkakao" onclick="shareRecipe('kakaotalk','${result.recipe.url}','${result.recipe.image}','${result.recipe.label}');return false;" class="kakaotalk" target="_self" title="카카오톡 새창열림"><span class="skip">카카오톡</span></a>
80 </li> 95 </li>
81 </ul> 96 </ul>
82 97
......