Это потому, что вы объединяете объект complimenter
вместо его вывода - который вы получаете, вызывая complimenter.get()
.
Еще одна вещь, которую вы хотите подарить и поделиться тем же комплиментом, но каждый get()
возвращает различные комплименты, поэтому вам нужно get
один раз и использовать его для рендеринга HTML-кода div, а также передать его в ссылку href
.
const compliment = complimenter.get();
var link = "https://twitter.com/intent/tweet?hashtags=compliment&related=complimenttime&text=" + compliment;
document.getElementById('tweet').setAttribute("href", link); //assigns url above as href to twitter button
document.getElementById('compliment').innerHTML = "<span class='bold'>" + compliment + "</span>" + "<br />";
Рабочий код:
// idea + dictionary by hnldesign from b3ta
var Complimenter = primish({
a: 'lovely,beautiful,gorgeous,kind,wonderful,nice,perfect'.split(','),
b: 'good-looking,super-duper,awesome'.split(','),
c: 'pal,friend,person,human'.split(','),
d: 'improver,supporter,juggler'.split(','),
combos: ['a,b,c', 'a,b,d', 'b,c', 'b,d'],
constructor: function(element){
element && (this.element = element);
this.combos = this.combos.map(function(c){return c.split(',')});
this.compliment();
},
compliment: function(e){
e && e.preventDefault();
var compliment= this.get();
this.element && (this.element.innerHTML = compliment);
reGenerateLink(compliment);
return compliment;
},
get: function(){
var c = this.combos,
self = this;
return c[Math.random()*c.length>>0].map(function(k){
return self[k][Math.random()*self[k].length>>0]
}).join(' ');
}
});
(function(){
var complimenter = new Complimenter(document.getElementById('compliment'));
document.querySelector('.heading').addEventListener('click', complimenter.compliment.bind(complimenter));
const compliment = complimenter.get();
reGenerateLink(compliment);
//assigns url above as href to twitter button
document.getElementById('compliment').innerHTML = "<span class='bold'>" + compliment + "</span>" + "<br />";
}());
function reGenerateLink(compliment) {
var link = "https://twitter.com/intent/tweet?hashtags=compliment&related=complimenttime&text=" + compliment;
document.getElementById('tweet').setAttribute("href", link);
}
@import url(http://fonts.googleapis.com/css?family=Russo+One);
* {
font-family: arial;
font-weight: bold;
}
body,
html {
height: 100%;
margin: 0;
}
body {
background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0naHR0cDovL3d3dy53My5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IDwvZGVmcz4KICA8cmVjdCB4PSctNSUnIHk9Jy01JScgd2lkdGg9JzExMCUnIGhlaWdodD0nMTEwJScgZmlsbD0nIzAwMDAyMicvPgogIDxyZWN0IHdpZHRoPScxMTAlJyBoZWlnaHQ9JzExMCUnIGZpbGw9J3VybCgjcCknLz4KICA8cmVjdCB4PSctNSUnIHk9Jy01JScgd2lkdGg9JzExMCUnIGhlaWdodD0nMTEwJScgZmlsbD0ndXJsKCNnKScvPgo8L3N2Zz4=');
}
.box {
text-align: center;
width: 600px;
height: 276px;
color: rgba(255, 255, 255, .7);
text-shadow: 1px 1px 5px rgba(0, 0, 0, .7);
}
#compliment {
font-family: "Russo One";
text-transform: uppercase;
font-size: 4em;
}
button.heading {
outline: none;
-moz-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
-webkit-box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
padding: 5px;
border: 1px solid #808080;
background-color: #f5f5f5;
background-image: -moz-linear-gradient(top, #ffffff, #e6e6e6);
background-image: -webkit-gradient(linear, 0 0, 0 100%, from(#ffffff), to(#e6e6e6));
background-image: -webkit-linear-gradient(top, #ffffff, #e6e6e6);
background-image: linear-gradient(to bottom, #ffffff, #e6e6e6);
background-repeat: repeat-x;
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ffffffff', endColorstr='#ffe6e6e6', GradientType=0);
font-size: 14px;
font-family: "Russo One";
text-transform: uppercase;
margin: 15px auto 50px;
}
.ac {
margin: auto;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
}
.twitter-share a,
.twitter-share a:visited {
color: #fff;
}
<script src="https://rawgit.com/DimitarChristoff/primish/master/primish-min.js"></script>
<div class="ac box">
Random compliment generator. <br/>Generate compliments until you get one you like.<br/>
<button class="heading">
generate new compliment
</button>
<div id="compliment"></div>
<div>
<a target="_blank" role="button" class="btn btn-info my-btn" id="tweet"><i class="fa fa-twitter"></i> Tweet this</a>
</div>
</div>
http://jsfiddle.net/moshfeu/n71L9skg/6/