2019-05-27 00:56:50 +00:00
< template >
< div >
< div class = "mb-4" >
< p class = "text-center" >
2019-05-27 05:01:25 +00:00
<!-- < a : class = "[tab == 'popular'? 'btn font-weight-bold py-0 btn-success' : 'btn font-weight-bold py-0 btn-outline-success']" href = "#" @click.prevent ="setTab('popular')" > Popular < / a > -- >
2019-05-27 00:56:50 +00:00
< a : class = "[tab == 'new'? 'btn font-weight-bold py-0 btn-success' : 'btn font-weight-bold py-0 btn-outline-success']" href = "#" @click.prevent ="setTab('new')" > New < / a >
2019-05-27 05:01:25 +00:00
<!-- < a : class = "[tab == 'random'? 'btn font-weight-bold py-0 btn-success' : 'btn font-weight-bold py-0 btn-outline-success']" href = "#" @click.prevent ="setTab('random')" > Random < / a > -- >
2019-05-27 00:56:50 +00:00
< a : class = "[tab == 'about'? 'btn font-weight-bold py-0 btn-success' : 'btn font-weight-bold py-0 btn-outline-success']" href = "#" @click.prevent ="setTab('about')" > About < / a >
< / p >
< / div >
< div v-if = "tab != 'about'" class="row loops-container" >
< div class = "col-12 col-md-4 mb-3" v-for = "(loop, index) in loops" >
2019-05-28 05:07:03 +00:00
< div class = "card border border-success" >
2019-05-27 00:56:50 +00:00
< div class = "embed-responsive embed-responsive-1by1" >
2019-06-04 01:48:52 +00:00
< video class = "embed-responsive-item" :src = "videoSrc(loop)" preload = "auto" width = "100%" height = "100%" loop @ click = "toggleVideo(loop, $event)" > < / video >
2019-05-27 00:56:50 +00:00
< / div >
< div class = "card-body" >
2019-06-04 01:48:52 +00:00
< p class = "username font-weight-bolder lead d-flex justify-content-between" > < a :href = "loop.account.url" > { { loop . account . acct } } < / a > < a :href = "loop.url" > { { timestamp ( loop ) } } < / a > < / p >
< p class = "small text-muted text-truncate" v-html = "loop.content ? loop.content : 'Untitled'" > < / p >
2019-05-27 00:56:50 +00:00
< div class = "small text-muted d-flex justify-content-between mb-0" >
< span > { { loop . favourites _count } } Likes < / span >
< span > { { loop . reblogs _count } } Shares < / span >
2019-06-04 01:48:52 +00:00
< span > { { loop . reply _count } } Comments < / span >
2019-05-27 00:56:50 +00:00
< / div >
< / div >
< / div >
< / div >
< / div >
< div v -else class = "col-12" >
< div class = "card" >
< div class = "card-body" >
< p class = "lead text-center mb-0" > Loops are an exciting new way to explore short videos on Pixelfed . < / p >
< / div >
< / div >
< / div >
< / div >
< / template >
< style type = "text/css" >
. loops - container . card {
box - shadow : none ;
}
. loops - container . card . card - img - top {
border - radius : 0 ;
}
. loops - container a {
color : # 343 a40 ;
}
a . hashtag ,
. loops - container . card - body a : hover {
color : # 28 a745 ! important ;
}
< / style >
< script type = "text/javascript" >
Object . defineProperty ( HTMLMediaElement . prototype , 'playing' , {
get : function ( ) {
return ! ! ( this . currentTime > 0 && ! this . paused && ! this . ended && this . readyState > 2 ) ;
}
} )
export default {
data ( ) {
return {
'version' : 1 ,
'loops' : [ ] ,
2019-05-27 05:01:25 +00:00
'tab' : 'new'
2019-05-27 00:56:50 +00:00
}
} ,
mounted ( ) {
axios . get ( '/api/v2/loops' )
. then ( res => {
this . loops = res . data ;
} )
} ,
methods : {
videoSrc ( loop ) {
return loop . media _attachments [ 0 ] . url ;
} ,
setTab ( tab ) {
this . tab = tab ;
} ,
toggleVideo ( loop , $event ) {
let el = $event . target ;
$ ( 'video' ) . each ( function ( ) {
if ( el . src != $ ( this ) [ 0 ] . src ) {
$ ( this ) [ 0 ] . pause ( ) ;
}
} ) ;
if ( ! el . playing ) {
el . play ( ) ;
2019-06-04 01:48:52 +00:00
//this.incrementLoop(loop);
2019-05-27 00:56:50 +00:00
} else {
el . pause ( ) ;
}
} ,
incrementLoop ( loop ) {
2019-06-04 01:48:52 +00:00
// axios.post('/api/v2/loops/watch', {
// id: loop.id
// }).then(res => {
// console.log(res.data);
// });
2019-05-27 00:56:50 +00:00
} ,
timestamp ( loop ) {
let ts = new Date ( loop . created _at ) ;
return ts . toLocaleDateString ( ) ;
}
}
}
< / script >