*/
function hideDoneScreen(){
document.getElementById('btnBookmark').parentNode.parentNode.style.display = "none";
document.getElementById('btnShareAgain').style.display='none';
}
/*
* Callback of Share again link (top-right link) on done screen
* It switches widget to Home home screen
*/
function doneShareAgainClick(){
turnPage("main");
}
/**
* To show done screen
* - Shows the share anywhere (monitor) image
* - Shows Bookmarklet button
* - Show/hide content of done screen according to the Browser
*/
function showDoneScreen(){
turnPage("done");
var img_url_initial="https://ws.sharethis.com/images/reskin2014/";
var defaultClass='', defaultSrc='', imageVersion = '_noText';
if(!currentLang){
imageVersion = '';
}
if(stlib.browser.getIEVersion()){ //IE
defaultClass = 'stBtnExplorer';
defaultSrc = img_url_initial+'share_success.png';
}else if(stlib.browser.isChrome()){ //Chrome
defaultClass = 'stBtnChrome';
defaultSrc = img_url_initial+'share_success.png';
}else if(stlib.browser.isSafari()){ //Safari
defaultClass = 'stBtnSafari';
defaultSrc = img_url_initial+'share_success.png';
}else if(stlib.browser.isOpera()){ // Opera
defaultClass = 'stBtnOpera';
defaultSrc = img_url_initial+'share_success.png';
}else{ //Default case will show effects of FireFox browser
defaultClass='stBtnFirefox';
defaultSrc = img_url_initial+'share_success.png';
}
// Applies Monitor image according to Browser
var imgDoneScreenMonitor = document.getElementById('imgDoneScreenMonitor');
imgDoneScreenMonitor.src = defaultSrc;
// Shows the bookmarklet button according to Browser
var btnBookmark = document.getElementById('btnBookmark');
btnBookmark.className = defaultClass;
btnBookmark.parentNode.parentNode.style.display = "block";
// Bind functionality for link click event
btnBookmark.parentNode.onclick=function(){
//addServiceLinks(); // Updates the services list
moveServices(0); // Resets the service list preferences
doneShareAgainClick(); // Turn widget screen to Home screen
stlib.gaLogger.gaLog("DoneScreen","ShareAgain");
};
// Shows Share Again link on top-right corner of widget
document.getElementById('btnShareAgain').style.display='block';
// Bind functionality for Share Again link click event
document.getElementById('btnShareAgain').onclick=function(){
//addServiceLinks(); // Updates the services list
moveServices(0); // Resets the service list preferences
doneShareAgainClick(); // Turn widget screen to Home screen
stlib.gaLogger.gaLog("DoneScreen","ShareAgain");
};
}
function showHome(){
turnPage("main");
}
/********************Posters**********/
var poster={};
//creates poster screen based on service
function createPoster(service){
if(widget.title==null){ widget.title=widget.URL;}
// console.log("createPoster");
document.getElementById('poster_inputBox').value = "";
document.getElementById('poster_inputBox').onfocus = function(){hideError();};
var headerText = lang.strings['msg_post_to'];
if(service=="twitter"){ // Todo: Investigate when this code is called
updateServiceCount(service, 'Tweet');
stlib.gaLogger.gaLog("Twitter","poster_clicked");
widget.poster="twitter";
document.getElementById('poster_textArea').style.display="block";
document.getElementById('poster_textArea').value="";
createShar();
document.getElementById('comment_box').style.display="block";
document.getElementById('poster_input_div').style.display="none";
document.getElementById('poster_textArea').onkeypress=poster.updateCounter;
document.getElementById('poster_message_counter').style.display="block";
headerText += " Twitter";
turnPage("poster");
}else if(service=="wordpress"){ // Opens WordPress screen of widget
updateServiceCount(service, 'Wordpress');
widget.poster="wordpress";
stlib.gaLogger.gaLog("Wordpress","poster_clicked");
document.getElementById('poster_textArea').style.display="none";
document.getElementById('comment_box').style.display="none";
document.getElementById('poster_input_div').style.display="block";
document.getElementById('poster_message_counter').style.display="none";
document.getElementById('poster_message_counter').style.display="none";
headerText = lang.strings['msg_post_wordpress'];
turnPage("poster");
}
turnTitle("other", headerText); // Updates the widget header as per the service
}
//poster.hide=function(){}
poster.cancel=function(service){
turnPage("main");
widget.poster=null;
};
poster.getCount=function(){
var element=document.getElementById('poster_textArea');
var text=element.value;
if(text.length>=117){
return false;
}else{
return 117-text.length;
}
};
poster.updateCounter=function(e){
try{var KeyID = (window.event) ? event.keyCode : e.keyCode;}catch(err){KeyID=0;}
var val=poster.getCount();
var ctr=element=document.getElementById('counter');
if(val===false){
ctr.innerHTML=0;
if(KeyID!==0){
return true;
}else{
return false;
}
}else{
if(val<11){
ctr.style.color="red";
}else{
ctr.style.color="#666666";
}
ctr.innerHTML=val;
}
};
poster.post=function(service){
stlib.data.resetShareData();
stlib.data.set("source", "share4xPoster","shareInfo");
stlib.data.set("buttonType", "large","shareInfo");
stlib.data.set("title", widget.title,"shareInfo");
stlib.data.set("url", widget.URL, "shareInfo");
//SA-77: introduce new st_short_url parameter
stlib.data.set("short_url", widget.short_url, "shareInfo");
stlib.data.set("sharURL", widget.sharURL, "shareInfo");
stlib.data.set("status", document.getElementById('poster_textArea').value, "shareInfo");
if(widget.poster=="wordpress"){
// console.log("post to wordpress");
if(document.getElementById('poster_inputBox').value.length<1){
showError(lang.strings['msg_valid_blog']);
return false;
}else{
if(widget.service==null){
widget.service = 'legacy';
}
var wpurl=document.getElementById('poster_inputBox').value;
wpurl = wpurl.replace(/^https?:\/\//,'');
stlib.data.set("destination", "wordpress", "shareInfo");
stlib.data.set("wpurl", wpurl, "shareInfo");
stlib.data.set("service", widget.service, "shareInfo");
stlib.sharer.share(null, widget.servicePopup);
widget.poster=null;
showDoneScreen();
return true;
}
}
return true;
};
/***************SHAR URL******************/
function createShar(){
var url=widget.URL;
if(url==widget.lastURL && widget.shorten == false){
var temp=( (widget.title!=null) ? widget.title+' - ' : "" )+widget.sharURL;
document.getElementById('poster_textArea').value=temp;
poster.updateCounter();
//Fix for FB:12537
}else if(((url!=="" && url!==" " && url!==null && widget.lastURL!=url) || widget.sharCreated == false) && widget.shorten == true){
widget.sharCreated = false; //Fix for FB:12537
widget.sharURL=url;//Fix for FB:12537
document.getElementById('poster_textArea').value = lang.strings['msg_loading'];
widget.lastURL=url;
var data=["return=json","cb=createShar_onSuccess","service=createSharURL","url="+encodeURIComponent(url),"sessionID="+widget.sessionID,"fpc="+widget.fpc];
data=data.join('&');
jsonp.makeRequest("https://ws.sharethis.com/api/getApi.php?"+data);
}
}
function createShar_onSuccess(response){
if((typeof response) != "undefined" && response.status=="SUCCESS"){
widget.sharURL=response.data.sharURL;
widget.sharCreated = true;
}
//console.log(widget.title);
var temp=( (widget.title!=null) ? widget.title+' - ' : "" )+widget.sharURL;
document.getElementById('poster_textArea').value=temp;
poster.updateCounter();
}
/***************I18N******************/
if(typeof(lang)=="undefined"){
var lang={};
lang.strings=new Object;
lang.strings['msg_loading'] = 'Loading';
lang.strings['msg_posting_t'] = 'Posting to Twitter';
lang.strings['msg_text'] = 'Text to a Friend:';
lang.strings['msg_sendign_inProgress'] = 'Sharing Message';
lang.strings['msg_get_button'] = 'Get the add-on now!';
lang.strings['msg_put_sharethis'] = 'Easily share your favorite finds online with a click of a button';
lang.strings['msg_valid_blog'] = 'Sorry, there was something wrong with that URL, please try again.';
lang.strings['msg_post_wordpress'] = 'Post to Wordpress';
lang.strings['msg_email_to'] = 'To:';
lang.strings['msg_email_from'] = 'From:';
lang.strings['msg_email_send'] = 'Send';
lang.strings['msg_email_cancel'] = 'Cancel';
lang.strings['msg_email_preview'] = 'Preview';
lang.strings['msg_email_close_preview'] = 'Close Preview';
lang.strings['msg_email_char_limit'] = '2000 characters left';
lang.strings['email_message'] = 'Message:';
lang.strings['msg_email_privacy'] = 'Privacy Policy';
lang.strings['msg_email_load_cont'] = 'Loading Contacts...';
lang.strings['msg_import_serv'] = 'Import Contacts From';
lang.strings['msg_email_captcha_info'] = 'Please type the words below:';
lang.strings['msg_valid_email_add'] = 'Please enter a valid email address.';
lang.strings['msg_valid_email_add_from'] = 'Please enter a valid email address in the "From" field.';
lang.strings['msg_valid_recipients'] = 'Please enter a valid recipient';
lang.strings['msg_captcha'] = 'Please enter the Captcha response.';
lang.strings['msg_view_all']="View All";
lang.strings['msg_hide_all']="Hide All";
lang.strings['msg_share_success_fs']="Your message was successfully shared! Log-in with FastShare to share with just one click next time.";
lang.strings['msg_fast_share']='Enable FastShare';
lang.strings['msg_related_shares']="Popular Shares:";
lang.strings['msg_post_to']="Post to";
lang.strings['msg_message']="Message:";
lang.strings['msg_submit']="Submit";
lang.strings['msg_friends']="What are your friends sharing?";
lang.strings['msg_my_acct']="My Account";
lang.strings['msg_signin']="Sign In";
lang.strings['msg_signout']="Sign Out";
lang.strings['msg_notyou']="Not You?";
lang.strings['msg_get_sharethis']="Get ShareThis";
lang.strings['msg_free_plugin']="FREE Plug-In!";
lang.strings['msg_recents']="Recents:";
lang.strings['msg_greeting']="Hi";
lang.strings['msg_share_anywhere']="Share from Anywhere";
// Todo: Remove above strings which are overritten
lang.strings['msg_close']="Close";
lang.strings['msg_email'] = "Select your Email";
lang.strings['msg_add_bookmark']="Share Again";
lang.strings['msg_add_extension']="Share Again";
lang.strings['msg_share_success']="Successfully Shared!";
lang.strings['msg_share_again']="Share again";
lang.strings['msg_track']="Opt out";
lang.strings['msg_powered']="Powered by";
lang.strings['msg_search_services'] = "Search for services";
lang.strings["msg_email_cancel"]="Cancel";
lang.strings["msg_post_wordpress"]="Post to Wordpress";
lang.strings['msg_submit']="Submit";
lang.strings["msg_valid_blog"]="Sorry, there was something wrong with that URL, please try again.";
lang.strings["msg_email_send"]="Send";
lang.strings['msg_share']="Share this with friends!";
lang.strings['msg_back']="Back";
lang.strings['msg_blog_url']="Blog URL";
lang.strings['msg_popup_blocker']="Please disable your popup-blocker!";
}
/*
* Reset top offset of services list
*/
function moveServices(row, search) {
if (row == 0) {
var element=document.getElementById('chicklet_search_field');
if(element!=null && typeof(search)=="undefined" && !search){
element.value=lang.strings['msg_search_services'];
}
}
document.getElementById("all_chicklets").scrollTop = (row*46);
}
/**
* @function showEmailPage: Responsible for opening the Email screen
* @returns {Boolean}
*/
function showEmailPage() {
if(!widget.isServiceClicked){ //Close link, if page's email button was clicked
document.getElementById('btnBack').style.display = "none"; //Hide Back link
document.getElementById('btnClose').style.display = "block"; // Show Close link
document.getElementById('btnClose').onclick=function(){ //Register Close link click handler
closeEmailWidget();
stlib.gaLogger.gaLog("New Email share page - 4x","Close clicked");
};
}else{//Back link, if minor service email button was clicked
document.getElementById('btnClose').style.display = "none"; // Hide Close link
document.getElementById('btnBack').style.display = "block"; // Show Back link
document.getElementById('btnBack').onclick=function(){ //Register Back link click handler
moveServices(0); // Resets the service list preferences
emailGoBackClick(); //Opens Home screen
stlib.gaLogger.gaLog("New Email share page - 4x","Go Back clicked");
};
}
document.getElementById('email_main').onclick=function(e){ //Register Email service click handler
e = e || window.event;
var svcEmailClicked = e.target || e.srcElement;
return emailShareExternal(svcEmailClicked);
};
widget.isServiceClicked = false; // flag to identify which (within widget or pub page) email button clicked
stlib.gaLogger.gaLog("New Email share page - 4x","Opened");
return false;
}
/*
* Sends message to buttons.js to close the widget
*/
function closeEmailWidget(){
if(typeof(window.postMessage)!=="undefined"){
parent.postMessage("ShareThis|close|Email", document.referrer);
}
}
/*
* To hide top-right links (Back and Close links) as these are out of emailPage
*/
function hideEmailPage(){
document.getElementById('btnBack').style.display = "none";
document.getElementById('btnClose').style.display = "none";
}
function urlEncodeCharacter(c)
{
return '%' + c.charCodeAt(0).toString(16);
}
function urlEncode( s )
{
return escape(s);
}
/*
* Function: getExternalEmailBody
* Parameters:
* 1. serviceType: Which email service button is clicked
* - Possible values:
* 1.1 'gmail' - Gamil button is clicked
* 1.2 'yahoo' - Yahoo button is clicked
* 1.3 'outlook' - Outlook button is clicked
* 1.4 'mailto' - Native email button is clicked
* 2. sharURLValue: Shortened URL
* - Possible values:
* 2.1 '' - If URL is not shortened, due to some reason
* 2.2 Shortened URL
* 3. trimData: Flag to trim data in case of very long data to share
* - Possible values:
* 3.1 null - If data trimming is not required (Limited data being shared)
* 3.2 1 - If data is too long for GET request but can be managed if description is removed from it
* 3.3 2 - If data is too long for GET request and can not be managed by removing description only,
* then comment is also removed from sharing data
*
*/
function getExternalEmailBody(serviceType, sharURLValue, trimData)
{
// If trimData == 1: Remove Description from message
var emailData={
type:widget.type,
recipients:"",
url: widget.URL,
title:(widget.title),
thumbnail:widget.thumb,
embed:widget.content,
description:widget.summary,
sharURL:(sharURLValue != '')?sharURLValue:widget.URL
};
var st_signature = 'This message was sent using ShareThis (https://www.sharethis.com)';
var newLineSpacer = '\r\n\r\n';
if(serviceType == "mailto"){
newLineSpacer = urlEncode(newLineSpacer);
if(emailData.description){
emailData.description = emailData.description.replace(/%/g, urlEncodeCharacter );
}
}
//var YahooEmailMessage = emailData.sharURL+'.'+newLineSpacer+st_signature;
var emailMessage = emailData.sharURL;
if(emailData.description && trimData != 1 && trimData != 2){
emailMessage += newLineSpacer+emailData.description;
}
emailMessage += newLineSpacer+st_signature;
var YahooEmailMessage = emailMessage; // assign the same Gmail emailMessage to Yahoo as well
var emailTo = (emailData.recipients)?emailData.recipients:"";
var emailSubject = (emailData.title)?emailData.title:"Message Subject";
var emailBody = (emailMessage)?(emailMessage):"Message Body";
YahooEmailMessage = (YahooEmailMessage)?(YahooEmailMessage):"Message Body";
var emailServices = {};
emailServices['gmail'] = {
href: "https://mail.google.com/mail/?view=cm",
su: encodeURIComponent(emailSubject),
to: emailTo,
body: encodeURIComponent(emailBody)
};
emailServices['yahoo'] = {
href: "//compose.mail.yahoo.com/?",
//href: "//mail.yahoo.com/neo/launch?action=compose",
//href: "//us.mg1.mail.yahoo.com/dc/launch?sysreq=ignore&action=compose&login=1",
Subject: encodeURIComponent(emailSubject.replace(/%/g, urlEncodeCharacter ).replace(/&/g, urlEncodeCharacter ).replace(/#/g, urlEncodeCharacter).replace(/'/g,urlEncodeCharacter).replace( /"/g, urlEncodeCharacter ).replace(/>/g, urlEncodeCharacter).replace(/'))
};
emailServices['outlook'] = {
href: "//mail.live.com/default.aspx?rru=compose",
subject: encodeURIComponent(emailSubject),
to: emailTo,
body: encodeURIComponent(emailBody.replace(/\r\n/g,'
').replace(/\(/g, '[').replace(/\)/g, ']'))
};
emailServices['mailto'] = {
href: "mailto:"+emailTo+"?",
Subject: emailSubject.replace(/%/g, urlEncodeCharacter ).replace(/&/g, urlEncodeCharacter ).replace(/#/g, urlEncodeCharacter).replace(/'/g,urlEncodeCharacter).replace( /"/g, urlEncodeCharacter ).replace(/>/g, urlEncodeCharacter).replace(//g, urlEncodeCharacter).replace(/
'+winEmailTitle+''+
'
'+
'
'+
''+winEmailTitle+''+
'It will be just a second..'+
'
'+
'
'+
'
'+
'';
winEmail.document.write(winEmailLightbox);
exEmailSharPoller = setInterval( function(){
sharURLValue = widget.sharURL;
if(sharURLValue != ''){
clearExEmailSharPoller([exEmailSharPoller, removeExEmailSharPoller]);
shareExternalEmail(winEmail, serviceType, sharURLValue);
}
}, 100);
removeExEmailSharPoller=setTimeout(function(){
clearExEmailSharPoller([exEmailSharPoller, removeExEmailSharPoller]);
shareExternalEmail(winEmail, serviceType, '');
},5000);
}else{
/*
* Show widget error message.
*
* if window open is called in context of direct user interaction, Popup-blocker should not block it.
* Added as a last resort in case of non-standard popup-blocker
*
*/
showError(lang.strings['msg_popup_blocker']);
}
}
// Go back to Home screen from email screen
function emailGoBackClick(){
turnPage('main');
}
/*
* Show error message on top of widget
*/
function showError(errorMessage)
{
var currentElement = document.getElementById('errorMsg');
currentElement.innerHTML = errorMessage;
currentElement.style.display = "block";
document.getElementById('errorBottom').style.display = "block";
}
/*
* Hides error message
*/
function hideError()
{
var currentElement = document.getElementById('errorMsg');
currentElement.innerHTML = "";
currentElement.style.display = "none";
document.getElementById('errorBottom').style.display = "none";
}
if (typeof(stlib.global.hash) == "string" && stlib.global.hash.substring(0,5) == "popup") {
var cleanHash = "#" + stlib.global.hash;
_$d_();
_$d1("Popup initiated");
_$d1(cleanHash);
fragmentPump.checkFragment(cleanHash);
_$d1("Done Checking Frag");
}