Instantly share code, notes, and snippets.
Created
May 6, 2016 14:40
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save t0nylombardi/d5a53131cee9c05d293bb88738cce82d 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
/* htdocs/dpsweb/ferguson/js/gallery_social.js | |
$Id: gallery_social.js,v 1.7 2015-04-30 16:19:12 wschutz Exp $ */ | |
/*Global Varibles */ | |
var feature_section = ''; | |
var ig_pic_number = ''; | |
var ig_main_image = ''; | |
var ig_longUrl = ''; | |
var underscore = '_'; | |
var urlAccessToken = "62f6a7c7aee727b0acc6311e173274d17dca7b1b"; | |
//Gets the main image name. | |
function ig_main_image_name() { | |
var URL = $('#main_room_image').attr('src'); | |
var pic_name = URL.substring(URL.lastIndexOf('/') + 1); | |
return pic_name; | |
} | |
//Gets the style name. | |
function ig_style_name() { | |
return $('#main_room_image').attr('data-room-name'); | |
} | |
// gets Room Description | |
function getRoomDesc() { | |
return jQuery(".ig_gallery_left h2:first-child").text(); | |
} | |
//returns the URL string for social Buttons | |
function ig_social_url() { | |
return document.URL; | |
} | |
var urlShorner = { | |
getShortUrl: function(url, callback){ | |
jQuery.getJSON( | |
url, | |
{}, | |
function(response) { | |
if(callback) | |
callback(response); | |
} | |
); | |
} | |
}; | |
function postToFeed() { | |
var fbImg = $('#main_room_image').attr('src'); | |
FB.ui({ | |
method: 'feed', | |
link: ig_social_url(), | |
picture: fbImg, | |
description: getRoomDesc(), | |
caption: 'Love this room, I found it on shop.Ferguson.com!', | |
}); | |
} | |
function sharePin() { | |
ig_longUrl = encodeURIComponent(ig_social_url()); | |
var pinMedia = $('#main_room_image').attr('src'); | |
var page_url = ig_longUrl; | |
var PinterestUrl = "http://pinterest.com/pin/create/button/?url="; | |
var pinterestText = "Love this room, I found it in the Inspiration Gallery at Ferguson.com!"; | |
window.open( PinterestUrl + | |
page_url + '&media=' + | |
pinMedia + '&description=' + | |
pinterestText, 'PinterestUrl', 'width=626,height=436' | |
); | |
var pinURL = PinterestUrl + page_url + | |
'&media=' + pinMedia + | |
'&description=' + pinterestText ; | |
return false; | |
} | |
function shareTweet() { | |
var page_url = ig_social_url(); | |
var bitlyUrl = 'https://api-ssl.bitly.com/v3/shorten?access_token=' | |
var twitterUrl = 'http://twitter.com/share?url='; | |
var twitterText = "Love this product, I found it on shop.Ferguson.com!"; | |
var twitterTag = 'Ferguson_FEI'; | |
if (jQuery.browser.msie && jQuery.browser.version == 8 ) { | |
window.open(twitterUrl+page_url+'&text='+twitterText+'&hashtags='+twitterTag,'', 'width=626,height=436'); | |
} else { | |
urlShorner.getShortUrl( bitlyUrl+urlAccessToken+ '&longUrl=' + page_url, | |
function(response) { | |
var shortUrl = response.data.url; | |
window.open(twitterUrl+shortUrl+'&text='+twitterText+'&hashtags='+twitterTag,'', 'width=626,height=436'); | |
}); | |
} | |
return false; | |
} | |
function shareHouzz() { | |
var page_url = ig_social_url(); | |
var houzzUrl = 'http://www.houzz.com/imageClipperUpload?link='; | |
var houzzPic = $('#main_room_image').attr('src'); | |
var houzzText = "Love this product, I found it on Shop.Ferguson.com!"; | |
var hzid = 9489; | |
window.open( houzzUrl +page_url + | |
'&source=button' + | |
'&hzid=' + hzid + | |
'&imageUrl=' + houzzPic + | |
'&link=' + page_url + | |
'&title=' + houzzText , | |
'houzzUrl', 'width=760,height=436' | |
); | |
return false; | |
} | |
$(document).ready(function() { | |
//Facebook api call | |
$.getScript('http://connect.facebook.net/en_US/sdk.js', function(){ | |
FB.init({ | |
appId: '163522890488588', | |
version: 'v2.2' | |
}); | |
}); | |
$(document).on('click', '[data-role="ig_facebook"]', function(){ | |
postToFeed(); | |
return false; | |
}); | |
$(document).on('click', '[data-role="ig_twitter"]', function(){ | |
shareTweet(); | |
return false; | |
}); | |
$(document).on('click', '[data-role="ig_pinterest"]', function(){ | |
sharePin(); | |
return false; | |
}); | |
//Houzz | |
jQuery(document).on('click', '[data-role="ig_houzz"]', function(){ | |
shareHouzz(); | |
return false; | |
}); | |
//"Email to a Friend" | |
$(document).on('click', '[data-role="ig_email_to_friend"]', function(){ | |
$("#inspirational_email_modal").dialog({ | |
modal:true, | |
width:500, | |
title: "Share This Inspirational Image", | |
dialogClass: 'siteDialog', | |
close: function() { | |
$("#inspirational_email_container").show(); | |
$("#email_success").hide(); | |
}, | |
height:585 | |
}); | |
}); | |
// clicked on the background | |
$(".ui-widget-overlay").on('click', function(){ | |
$("#inspirational_email_container").dialog("close"); | |
}); | |
// clicked on the submit button | |
$("#inspiration_email_submit").on('click', function(){ | |
//if ($("#inspiration_email_form").valid()){ | |
if (true){ | |
$("#ig_email_main_image").val(ig_main_image_name()); | |
$("#ig_email_section").val(ig_social_url()); | |
$("#ig_email_style").val(ig_style_name()); | |
/* | |
expects JSON output of the form: | |
{status: 'OK|ERROR', data:['array','of','errs'| 'success_text'] | |
If status == 'OK', hides 'form_container' and 'error_container' and displays success_container | |
If status == 'ERROR' add the 'errorInvalid' class to all labels for that input and shows error_container | |
*/ | |
//function validatedFormRequest(url,data,form_container,error_container,success_container){ | |
$('#given_addresses').html($('#email').val() + ($('#senderFriends').val() ? ("," + $('#senderFriends').val()) : '' )); | |
validatedFormRequest('/forms/inspiration_gallery',$('#inspiration_email_form').serialize() + "&format=wide",$('#inspirational_email_container'),$('#email_error'),$('#email_success')); | |
} else { | |
$("#errorDivConsult").show(); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment