add twitter sharing to game over screen
This commit is contained in:
@@ -2,6 +2,7 @@ function HTMLActuator() {
|
||||
this.tileContainer = document.getElementsByClassName("tile-container")[0];
|
||||
this.scoreContainer = document.getElementsByClassName("score-container")[0];
|
||||
this.messageContainer = document.getElementsByClassName("game-message")[0];
|
||||
this.sharingContainer = document.getElementsByClassName("score-sharing")[0];
|
||||
|
||||
this.score = 0;
|
||||
}
|
||||
@@ -28,6 +29,7 @@ HTMLActuator.prototype.actuate = function (grid, metadata) {
|
||||
};
|
||||
|
||||
HTMLActuator.prototype.restart = function () {
|
||||
if (ga) ga("send", "event", "game", "restart");
|
||||
this.clearMessage();
|
||||
};
|
||||
|
||||
@@ -98,8 +100,26 @@ HTMLActuator.prototype.message = function (won) {
|
||||
|
||||
this.messageContainer.classList.add(type);
|
||||
this.messageContainer.getElementsByTagName("p")[0].textContent = message;
|
||||
|
||||
this.clearContainer(this.sharingContainer);
|
||||
this.sharingContainer.appendChild(this.scoreTweetButton());
|
||||
twttr.widgets.load();
|
||||
};
|
||||
|
||||
HTMLActuator.prototype.clearMessage = function () {
|
||||
this.messageContainer.classList.remove("game-won", "game-over");
|
||||
};
|
||||
|
||||
HTMLActuator.prototype.scoreTweetButton = function () {
|
||||
var tweet = document.createElement("a");
|
||||
tweet.classList.add("twitter-share-button");
|
||||
tweet.setAttribute("href", "https://twitter.com/share");
|
||||
tweet.setAttribute("data-via", "gabrielecirulli");
|
||||
tweet.textContent = "Tweet";
|
||||
|
||||
var text = "I scored " + this.score + " points at 2048, a game where you " +
|
||||
"join numbers to score high!";
|
||||
tweet.setAttribute("data-text", text);
|
||||
|
||||
return tweet;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user