From 0834a5a6f3acb15ecd611d7b028b523aa59b2c2b Mon Sep 17 00:00:00 2001 From: "Misho M. Petkovic" Date: Fri, 4 Jul 2014 16:05:24 +0200 Subject: [PATCH] Score sharing script Adding thih code score will be shared on twitter. --- js/html_actuator.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/js/html_actuator.js b/js/html_actuator.js index d840068..9561632 100644 --- a/js/html_actuator.js +++ b/js/html_actuator.js @@ -130,6 +130,7 @@ HTMLActuator.prototype.message = function (won) { this.messageContainer.classList.add(type); this.messageContainer.getElementsByTagName("p")[0].textContent = message; + this.messageContainer.appendChild(this.showSocialButtons()); }; HTMLActuator.prototype.clearMessage = function () { @@ -137,3 +138,38 @@ HTMLActuator.prototype.clearMessage = function () { this.messageContainer.classList.remove("game-won"); this.messageContainer.classList.remove("game-over"); }; + +HTMLActuator.prototype.showSocialButtons = function () { + var text = "I scored " + this.score + " points at 243, a game where you join nubers to score high! @mishopet" + var html = + '
' + + '' + + '
' + + '
'; + document.getElementById( 'viewport' ).insertAdjacentHTML( 'beforeEnd', html ); + + var script = document.createElement( 'script' ); + script.async = true; + script.src = document.location.protocol + '//connect.facebook.net/en_US/all.js#xfbml=1&appId=239765196226361'; + document.getElementById( 'fb-root' ).appendChild( script ); + + script = document.createElement( 'script' ); + script.async = true; + script.src = document.location.protocol + '//platform.twitter.com/widgets.js'; + document.getElementById( 'social-buttons' ).appendChild( script ); + + script = document.createElement( 'script' ); + script.async = true; + script.src = document.location.protocol + '//apis.google.com/js/plusone.js'; + document.getElementById( 'social-buttons' ).appendChild( script ); + + window.setTimeout( function () { + + document.getElementById( 'social-buttons' ).removeAttribute( 'class' ); + + }, 1000 ); + return html +};