Created
September 25, 2014 02:10
-
-
Save onesup/26e14abe999747964f74 to your computer and use it in GitHub Desktop.
페북 로긴 권한 참고용.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function user_signed_in(){ | |
}; | |
$(document).ready(function(){ | |
$('#message_button').click(function(e) { | |
e.preventDefault(); | |
$.ajax({ | |
type: 'get', | |
url: '/event_finish.json', | |
success: function (data) { | |
if(data.result == "finish"){ | |
alert("아쉽네요!\n다음엔 조금더 서둘러주세요~"); | |
}else{ | |
$.getJSON('/user_signed_in').done(function(json) { | |
if(json.result == true){ | |
message_input_popup(); | |
}else{ | |
fb_login(); | |
} | |
}); | |
} | |
} | |
}); | |
}); | |
$("#facebook_share_link").click(function(e){ | |
e.preventDefault(); | |
$.ajax({ | |
type: 'get', | |
url: '/event_finish.json', | |
success: function (data) { | |
if(data.result == "finish"){ | |
alert("아쉽네요!\n다음엔 조금더 서둘러주세요~"); | |
}else{ | |
fb_share(); | |
} | |
} | |
}); | |
}); | |
$("#close_finish").click(function(e) { | |
e.preventDefault(); | |
window.location.assign("/pc/index") | |
}); | |
$("#show_present_button").click(function(e) { | |
e.preventDefault(); | |
$("#show_present").bPopup({ | |
follow: [false, false], //x, y | |
positionStyle: 'fixed', | |
closeClass: 'close', | |
modalColor: 'black' | |
}); | |
}); | |
$("#button_personal_policy").click(function(e) { | |
e.preventDefault(); | |
$("#personal_policy").bPopup({ | |
follow: [false, false], //x, y | |
positionStyle: 'fixed', | |
closeClass: 'close', | |
modalColor: 'black', | |
position: ['auto', 1500], //x, y | |
}); | |
}); | |
$(".image_paging").click(function(e) { | |
e.preventDefault(); | |
$(".image_paging").removeClass('icon_active'); | |
$(this).addClass('icon_active'); | |
}); | |
$("#new_comment").bind("ajax:before", function(e, data, status, xhr){ | |
e.preventDefault(); | |
spinner = new_comment_spinner(); | |
}).bind("ajax:success", function(evt,data,status,xhr){ | |
spinner.stop(); | |
response = JSON.parse(xhr.responseText); | |
if(response.status==="success"){ | |
fb_tracking(); | |
$("#popup_finish").bPopup({ | |
follow: [false, false], //x, y | |
positionStyle: 'fixed', | |
closeClass: 'close', | |
modalColor: 'black', | |
position: ['auto', 150], //x, y | |
}); | |
}else { | |
} | |
}).bind('ajax:error',function(evt,xhr,status,error){ | |
var $form = $(this),errors,errorText; | |
errors = $.parseJSON(xhr.responseText); | |
validation(errors); | |
}); | |
}); | |
function message_input_popup(){ | |
$("#popup_input").bPopup({ | |
follow: [false, false], //x, y | |
positionStyle: 'fixed', | |
closeClass: 'close', | |
modalColor: 'black', | |
position: ['auto', 160] //x, y | |
}); | |
}; | |
function fb_login_spinner(){ | |
var opts = { | |
lines: 13, // The number of lines to draw | |
length: 20, // The length of each line | |
width: 10, // The line thickness | |
radius: 5, // The radius of the inner circle | |
corners: 1, // Corner roundness (0..1)spin.js | |
rotate: 0, // The rotation offset | |
direction: 1, // 1: clockwise, -1: counterclockwise | |
color: '#fff', // #rgb or #rrggbb or array of colors | |
speed: 1, // Rounds per second | |
trail: 60, // Afterglow percentage | |
shadow: false, // Whether to render a shadow | |
hwaccel: false, // Whether to use hardware acceleration | |
className: 'spinner', // The CSS class to assign to the spinner | |
zIndex: 2e9, // The z-index (defaults to 2000000000) | |
left: 235-35, | |
top: 35-35 | |
}; | |
var target = document.getElementById('message_button'); | |
var spinner = new Spinner(opts).spin(target); | |
return spinner; | |
}; | |
function fb_login(){ | |
var spinner = fb_login_spinner(); | |
FB.login(function(response) { | |
if (response.authResponse) { | |
var url = '/auth/facebook/callback'; | |
$.ajax({ | |
type: "GET", | |
url: url, | |
success: function (data) { | |
spinner.stop(); | |
if(data.success == true) | |
message_input_popup(); | |
else{ | |
alert("페이스북 로그인이 필요합니다."); | |
} | |
} | |
}); | |
}else{ | |
alert("페이스북 로그인이 필요합니다."); | |
} | |
}, { scope: 'email, user_photos, user_birthday, publish_actions, publish_stream' }); | |
}; | |
function validation(errors){ | |
$(".star").empty(); | |
// $('input[data-name ='+error+']').parent().find('span').remove(); | |
$('textarea[data-name="post_message"]').addClass("presence-error") | |
$('textarea[data-name="post_message"]').after("<p class='star post_message'>*</p>"); | |
} | |
function share() { | |
var text = "이브자리 가족의 달 캠페인"; | |
var share_content = { | |
method: "feed", | |
name: "감사한 마음이 이불이 됩니다", | |
link: "<%= Rails.application.secrets.url %>?s=fb_share", | |
picture: '<%= Rails.application.secrets.url + asset_url("sns/fb_90x90.jpg") %>', | |
caption: "부모님께 전하는 메세지를 남겨주세요. 사연을 남겨주시는 분께 추첨을 통해 매일 한 분에게 이브자리 침구를 부모님께 보내드립니다.", | |
description: text | |
}; | |
FB.ui(share_content, function(response) { | |
if(response && response.post_id) { | |
track_viral_action(viral_url, "facebook"); | |
alert("공유되었습니다."); | |
} | |
else { | |
alert("다시 공유해주세요!"); | |
} | |
}); | |
} | |
function fb_share(){ | |
$.getJSON('/user_signed_in').done(function(json) { | |
if(json.result == true){ | |
var user_id = json.user_id; | |
$.ajax({ | |
type: "POST", | |
url: "/viral_actions.json", | |
data: { | |
'viral_action[platform]': "Facebook", | |
'viral_action[device]': "pc", | |
'viral_action[user_id]': user_id | |
}, | |
success: function (data) { | |
share(); | |
} | |
}); | |
}else{ | |
FB.login(function(response) { | |
if(response.authResponse) { | |
$.ajax({ | |
type: "POST", | |
url: "/viral_actions.json", | |
data: { | |
'viral_action[platform]': "Facebook", | |
'viral_action[device]': "pc", | |
'viral_action[user_id]': user_id | |
}, | |
success: function (data) { | |
share(); | |
} | |
}); | |
share(); | |
}else{ | |
alert("페이스북 로그인이 필요합니다."); | |
} | |
},{ | |
scope: 'email, user_photos, user_birthday, publish_actions, publish_stream' | |
}); | |
} | |
}); | |
} | |
function fb_tracking(){ | |
var fb_param = {}; | |
fb_param.pixel_id = '6014588119981'; | |
fb_param.value = '0.00'; | |
fb_param.currency = 'USD'; | |
(function(){ | |
var fpw = document.createElement('script'); | |
fpw.async = true; | |
fpw.src = '//connect.facebook.net/ko_KR/fp.js'; | |
var ref = document.getElementsByTagName('script')[0]; | |
ref.parentNode.insertBefore(fpw, ref); | |
})(); | |
} | |
function new_comment_spinner(){ | |
div_width_center = $("#data_submit_div").width() / 2; | |
div_heifht_center = $("#data_submit_div").height() / 2; | |
var opts = { | |
lines: 13, // The number of lines to draw | |
length: 20, // The length of each line | |
width: 10, // The line thickness | |
radius: 5, // The radius of the inner circle | |
corners: 1, // Corner roundness (0..1)spin.js | |
rotate: 0, // The rotation offset | |
direction: 1, // 1: clockwise, -1: counterclockwise | |
color: '#fff', // #rgb or #rrggbb or array of colors | |
speed: 1, // Rounds per second | |
trail: 60, // Afterglow percentage | |
shadow: false, // Whether to render a shadow | |
hwaccel: false, // Whether to use hardware acceleration | |
className: 'spinner', // The CSS class to assign to the spinner | |
zIndex: 2e9, // The z-index (defaults to 2000000000) | |
left: div_width_center-35, | |
top: div_heifht_center-35 | |
}; | |
var target = document.getElementById('data_submit_div'); | |
var spinner = new Spinner(opts).spin(target); | |
return spinner; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment