Skip to content

Commit edd8d34

Browse files
zubeydecivelekzzacharo
authored andcommitted
feature: add share link with timestamp
1 parent fd187b2 commit edd8d34

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

cds/modules/records/static/templates/cds_records/video/share.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,46 @@
1+
<!-- Share link -->
2+
<div class="cds-detail-sharelink mb-20 d-flex align-items-center">
3+
4+
<!-- Share URL + Copy -->
5+
<div class="input-group" style="flex:1;">
6+
<input id="copyShare"
7+
type="text"
8+
class="form-control"
9+
ng-model="share.link"
10+
readonly
11+
aria-label="Shareable link" />
12+
13+
<span class="input-group-btn">
14+
<button ngclipboard
15+
class="btn btn-default"
16+
data-clipboard-target="#copyShare"
17+
type="button">
18+
<i class="fa fa-copy"></i>
19+
</button>
20+
</span>
21+
</div>
22+
23+
<!-- Start at -->
24+
<div class="sharelink-start">
25+
<label class="start-checkbox">
26+
<input type="checkbox"
27+
ng-model="share.withStart"
28+
ng-change="updateShareLink()">
29+
Start at:
30+
</label>
31+
32+
<input type="text"
33+
class="start-time"
34+
placeholder="0:00"
35+
ng-disabled="!share.withStart"
36+
ng-model="share.startInput"
37+
ng-change="updateShareLink()"
38+
ng-pattern="/^[0-9:]*$/">
39+
</div>
40+
41+
</div>
42+
<!-- /Share link -->
43+
144
<!-- Social -->
245
<div class="cds-detail-video-social-media mb-20">
346
<h4>Social media</h4>

cds/modules/theme/assets/bootstrap3/js/cds_records/cdsRecord.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,51 @@ function cdsRecordController($scope, $sce, $http, $timeout, $filter) {
468468
return cleanTitle;
469469
};
470470

471+
$scope.share = {
472+
link: window.location.href.split("?")[0],
473+
startInput: "0:00",
474+
withStart: false,
475+
};
476+
477+
function parseHMS(txt) {
478+
if (txt == null) return NaN;
479+
txt = String(txt).trim();
480+
if (!txt) return NaN;
481+
if (!/^\d{1,2}(?::\d{1,2}){0,2}$/.test(txt)) return NaN;
482+
483+
var parts = txt.split(":").map(Number);
484+
if (parts.length === 1) return parts[0]; // ss
485+
if (parts.length === 2) return parts[0] * 60 + parts[1]; // mm:ss
486+
return parts[0] * 3600 + parts[1] * 60 + parts[2]; // hh:mm:ss
487+
}
488+
489+
$scope.updateShareLink = function () {
490+
var url = window.location.href.split("?")[0];
491+
if ($scope.share.withStart) {
492+
var secs = parseHMS($scope.share.startInput);
493+
if (!isNaN(secs) && secs > 0) {
494+
url += (url.indexOf("?") === -1 ? "?" : "&") + "t=" + Math.floor(secs);
495+
}
496+
}
497+
$scope.share.link = url;
498+
};
499+
500+
$scope.copyShareLink = function () {
501+
if (navigator.clipboard && window.isSecureContext) {
502+
navigator.clipboard.writeText($scope.share.link);
503+
} else {
504+
var tmp = document.createElement("textarea");
505+
tmp.value = $scope.share.link;
506+
document.body.appendChild(tmp);
507+
tmp.select();
508+
try {
509+
document.execCommand("copy");
510+
} catch (e) {}
511+
document.body.removeChild(tmp);
512+
}
513+
};
514+
515+
471516
/**
472517
* Trust iframe url
473518
* @memberof cdsRecordController

cds/modules/theme/assets/bootstrap3/scss/cds/cds.scss

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,4 +1404,44 @@ div[cds-search-results] {
14041404
.in-this-video-panel {
14051405
max-height: calc(100vh - 120px);
14061406
}
1407+
}
1408+
1409+
1410+
.cds-detail-sharelink {
1411+
display: flex;
1412+
align-items: center;
1413+
flex-wrap: wrap;
1414+
}
1415+
.cds-detail-sharelink .input-group {
1416+
flex: 1 1 420px;
1417+
margin-right: 10px;
1418+
}
1419+
.sharelink-start {
1420+
display: flex;
1421+
align-items: center;
1422+
font-size: 14px;
1423+
}
1424+
.sharelink-start .start-checkbox {
1425+
display: flex;
1426+
align-items: center;
1427+
cursor: pointer;
1428+
font-weight: 500;
1429+
}
1430+
.sharelink-start .start-checkbox input[type="checkbox"] {
1431+
width: 18px;
1432+
height: 18px;
1433+
margin-right: 6px;
1434+
transform: scale(1.25);
1435+
}
1436+
.start-time {
1437+
width: 64px;
1438+
border: none;
1439+
color: #ccc;
1440+
background: transparent;
1441+
text-align: center;
1442+
outline: none;
1443+
}
1444+
.sharelink-start:has(input[type="checkbox"]:checked) .start-time {
1445+
border-bottom: 1px solid #888;
1446+
color: #333333;
14071447
}

0 commit comments

Comments
 (0)