Skip to content
This repository has been archived by the owner on May 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #868 from swarmcity/shareable
Browse files Browse the repository at this point in the history
Bugfixing lion + url
  • Loading branch information
xardass authored Nov 28, 2018
2 parents 86f82b0 + 7c065bd commit d2e07e5
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions src/pages/detail/detail-simpledeal-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="import" href="../../../bower_components/polymer/polymer-element.html">
<link rel="import" href="../../../bower_components/iron-flex-layout/iron-flex-layout.html">
<link rel="import" href="../../../bower_components/iron-image/iron-image.html">
<link rel="import" href="../../../bower_components/iron-ajax/iron-ajax.html">

<!--
Displays and shared styles only
Expand Down Expand Up @@ -202,6 +203,14 @@
visibility: visible;
}

.force-select {
-webkit-user-select: text;
-moz-user-select: text;
-ms-user-select: text;
user-select: text;
cursor: auto !important;
}

@media only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (min-resolution: 240dpi) {
Expand All @@ -213,6 +222,7 @@
}
</style>
<iron-media-query query="(min-width: 600px)" query-matches="{{wide}}"></iron-media-query>
<iron-ajax id="ajax"></iron-ajax>
<div class="container" wide-layout$="{{wide}}">
<div class="closebox">
<div class="close" on-tap="_close" tabindex="1"></div>
Expand Down Expand Up @@ -251,7 +261,7 @@
</div>
<div class="linkbox">
<div class="copied" id="copied">copied</div>
<span on-tap="_copyUrl" class="link">shareable link</span>
<span id="shareplace" on-tap="_copyUrl" class="link">shareable link</span>
<div class="copied" id="copied">copied</div>
</div>
</div>
Expand Down Expand Up @@ -291,6 +301,7 @@
* takes the user to originating page
*/
_close() {
this._resetShare();
this.dispatchEvent(new CustomEvent('close'));
}
/**
Expand Down Expand Up @@ -331,22 +342,32 @@
_isSeeker(item) {
return (item && item.seekerAddress && this.address && item.seekerAddress == this.address);
}

makeRequest (method, url, done) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = function () {
done(null, xhr.response);
};
xhr.onerror = function () {
done(xhr.response);
};
xhr.send();
}

_copyUrl() {
let textArea = document.createElement('textarea');
textArea.value = window.location.href;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy');
document.body.removeChild(textArea);
let copied = this.shadowRoot.querySelector('#copied');
copied.classList.add('showcopied');
copied.animate(
this.anim.moveUp.arr,
this.anim.moveUp.obj
);
setTimeout(() => {
copied.classList.remove('showcopied');
}, 500);
if(this.$.shareplace.innerHTML == 'shareable link') {
var urltoShort = encodeURIComponent(window.location.href);
var shareUrl = this.makeRequest("GET", "https://i.swarm.city/s/" + urltoShort, (err, res) => {
this.$.shareplace.innerHTML = res;
this.$.shareplace.classList.add('force-select');
});
}
}

_resetShare() {
this.$.shareplace.innerHTML ='shareable link';
this.$.shareplace.classList.remove('force-select');
}
}
window.customElements.define(MyDetailSimpledealMain.is, MyDetailSimpledealMain);
Expand Down

0 comments on commit d2e07e5

Please sign in to comment.