Skip to content

Instantly share code, notes, and snippets.

@mayroncachina
Created February 11, 2014 20:54
Show Gist options
  • Save mayroncachina/8943921 to your computer and use it in GitHub Desktop.
Save mayroncachina/8943921 to your computer and use it in GitHub Desktop.
var canvas = null;
function buttonSocial(div){
if($("#image-"+div).attr("src") == "images/"+div+".png"){
$("#image-"+div).attr("src", "images/"+div+"-ativo.png");
$("#text-"+div).attr("style", "color:#c2240a");
}else{
$("#image-"+div).attr("src", "images/"+div+".png");
$("#text-"+div).attr("style", "color:#FFF");
}
}
// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
var largeImage = document.getElementById('largeImage');
largeImage.style.display = 'block';
largeImage.width = 120;
largeImage.height = 118;
largeImage.src = "data:image/jpeg;base64," + imageData;
canvas = imageData;
console.log(canvas)
closeDiv('#posiciona');
}
// A button will call this function
function capturePhotoEdit() {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
// A button will call this function
function getPhoto(source) {
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL,
sourceType: source });
}
// Called if something bad happens.
function onFail(message) {
//alert('Failed because: ' + message);
}
function compartilhar() {
//Valida se Email esta marcado
if($("#text-mail").attr("style") == "color:#c2240a"){
//envia por email
}
//Valida se Face esta marcado
if($("#text-face").attr("style") == "color:#c2240a"){
var token_face = localStorage.getItem('fb-token');
//verifica se esta logado
console.log("TOKEN FB= " + token_face);
if(token_face != ""){
$(".upload-content").hide();
$(".upload-file").show();
dados = {
facebook_token: token_face,
twitter_token: "",
user_id: localStorage.getItem('id_user'),
description: $(".text-photo").val(),
file_base64: canvas
}
$.ajax({
type: 'POST',
url:'http://you.webbyapp.com/ws/entries/',
async: false,
data: dados,
crossDomain: true,
error: function(xhr, ts, e){
$.mobile.changePage( "social.html", {
transition: "pop",
reverse: false,
changeHash: false
});
console.log(xhr);
console.log("ts: "+ts);
console.log("e:"+e);
},
success: function(data, ts, xhr){
$.mobile.changePage( "social.html", {
transition: "pop",
reverse: false,
changeHash: false
});
},
});
}else{
loginFacebook();
}
}
//Valida se Instagram esta marcado
if($("#text-instagram").attr("style") == "color:#c2240a"){ }
//Valida se Twitter esta marcado
if($("#text-twitter").attr("style") == "color:#c2240a"){
//upload para o twitter
}
console.log('Compartilhar!!!')
}
/**
* Envia a foto para o instagram
*/
function sendInstagram(){
setTimeout(function() {
console.log(largeImage)
Instagram.share("data:image/jpeg;base64," + canvas, function (err) {
if (err) {
console.log("not shared");
} else {
console.log("shared");
}
});
}, 500);
}
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
$(".upload-content").show();
$(".upload-file").hide();
$.mobile.changePage( "social.html", {
transition: "pop",
reverse: false,
changeHash: false
});
}
function fail(error) {
alert("An error has occurred: Code = " = error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
$(".upload-content").show();
$(".upload-file").hide();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment