0% found this document useful (0 votes)
5 views6 pages

Pagina Player

The document contains JavaScript code for a Wix website that manages user interactions with an audio player, including view counts, likes, and volume controls. It features functions for updating view counts, copying URLs, displaying and hiding elements, and managing likes through user authentication. Additionally, it formats display values for views and duration, and handles user interface animations for a better user experience.

Uploaded by

iSound
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Pagina Player

The document contains JavaScript code for a Wix website that manages user interactions with an audio player, including view counts, likes, and volume controls. It features functions for updating view counts, copying URLs, displaying and hiding elements, and managing likes through user authentication. Additionally, it formats display values for views and duration, and handles user interface animations for a better user experience.

Uploaded by

iSound
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

import wixData from 'wix-data';

import wixWindow from 'wix-window';


import wixUsers from 'wix-users';

import wixLocation from 'wix-location';

const viewsEvent = function () {

$w("#dynamicDataset").onReady(() => {
const itemObj = $w("#dynamicDataset").getCurrentItem();
let totalViews = itemObj.views + 1;
$w("#dynamicDataset").setFieldValue("views", totalViews)
$w('#dynamicDataset').save();

$w("#txtViews").text =
formatView(String($w("#dynamicDataset").getCurrentItem().views))
});

$w.onReady(function () {

let currentYear = new Date().getFullYear();

$w("#txtCopyright").text = `Copyright © ${currentYear} BOOM by iSound`;

let ulrSite = wixLocation.url

$w('#button41').label = ulrSite;

$w("#btnCopiar").onClick(() => {
let textUrl = $w("#button41").label;

wixWindow.copyToClipboard(textUrl)
.then(() => {
$w("#btnCopiar").disable();
$w("#btnCopiar").label = 'Copied!';

resetButton()
})
})

setTimeout(viewsEvent, 100);

});

function formatView(view) {
if (view > 999 && view < 1000000) {
return `${(view/1000).toFixed(0)}K`;
} else if (view > 1000000) {
return `${(view / 1000000).toFixed(0)}M`;
} else if (view > 1000000000) {
return `${(view / 1000000000).toFixed(0)}B`;
} else if (view < 900) {
return view;
}
}

function resetButton() {
if ($w("#btnCopiar").disable()) {
setTimeout(function () {
$w("#btnCopiar").enable();
$w("#btnCopiar").label = 'Copy';

}, 1000);
}
}

//Compartilhar//
export function btnShared_click(event) {
$w("#boxShared").show();
}

export function boxShared_mouseIn(event) {


$w("#boxShared").show();
}

export function boxShared_mouseOut(event) {


let fadeOptions = {
"duration": 1000,
"delay": 1000
};

$w("#boxShared").hide("fade", fadeOptions);
}

//Volume////
export function btnVolume_click(event) {
$w("#boxVolume").show();
}

export function boxVolume_mouseIn(event) {


$w("#boxVolume").show();
}

export function boxVolume_mouseOut(event) {


let fadeOptions = {
"duration": 1000,
"delay": 1000
};

$w("#boxVolume").hide("fade", fadeOptions);
}

export function sliderVolume_change(event) {


$w("#audioPlayer1").volume = $w("#sliderVolume").value;
}

function formatammss(s) {
function duas_casas(numero) {
if (numero <= 9) {
numero = "0" + numero;
}
return numero;
}
let minuto = duas_casas(Math.round((s % 3600) / 60));
let segundo = duas_casas((s % 3600) % 60);
let formatado = minuto + ":" + segundo;

return formatado;
}

//Barra de Progresso//
export async function audioPlayer1_progress(event) {
let duration = $w("#audioPlayer1").duration
$w("#progressBar1").targetValue = duration;

let time = await formatammss(Number(duration))

$w('#txtDuration').text = time

let currentTime = $w("#audioPlayer1").currentTime // 137

$w("#progressBar1").value = currentTime;
}

//Função aparecer e sumir duração//


export function audioPlayer1_play(event) {
let fadeOptions = {
"duration": 1000,
"delay": 1000
};

$w("#txtDuration1").show("fade", fadeOptions);

let fade = {
"duration": 1000,
"delay": 1000
};

$w("#txtDuration").show("fade", fade);

}
export function audioPlayer1_ended(event) {
let fadeOptions = {
"duration": 1000,
"delay": 1000
};

$w("#txtDuration1").hide("fade", fadeOptions);

let fade = {
"duration": 1000,
"delay": 1000
};

$w("#txtDuration").hide("fade", fade);
}

export function dynamicDataset_ready() {


likeData1()
}

let centerBounce = {
"duration": 500,
"direction": "center",
"intensity": "medium",
};

function likeData1() {
let likes_array = [];
$w('#dynamicDataset').onReady(() => {
let itemData = $w('#dynamicDataset').getCurrentItem()
let likes = itemData.likes;
if (likes) {
console.log(likes);
let parsed_likes = JSON.parse(likes);
$w("#likes1").text = parsed_likes.length.toLocaleString();
} else {
$w("#likes1").text = (0).toLocaleString();
}
if (itemData.likes) {
if (itemData.likes.includes(wixUsers.currentUser.id)) {
$w("#emptyHeart1").hide();
$w("#fullHeart1").show();
}
}
$w("#emptyHeart1").onClick((event) => {
if (wixUsers.currentUser.loggedIn) {
let $item = $w.at(event.context);
// let data_item = itemData;
toggleHeart($item, itemData)
} else {

}
});

$w("#fullHeart1").onClick((event) => {
let $item = $w.at(event.context);
// let data_item =
toggleHeart($item, itemData);
});
})
async function toggleHeart(item, itemData) {

let emptyHeart = $w("#emptyHeart1");


let fullHeart = $w("#fullHeart1");
let likes = $w("#likes1");
// toggle the fold at the index
if (fullHeart.hidden) {
fullHeart.show('bounce', centerBounce);
emptyHeart.hide()
// await fullHeart.disable();
await saveHeart(itemData);
// fullHeart.enable();
likes.text = (Number(likes.text) + 1).toLocaleString();
} else {
fullHeart.hide();
emptyHeart.show('bounce', centerBounce);
// await emptyHeart.disable();
await deleteHeart(itemData);
// fullHeart.enable();
likes.text = (Number(likes.text) - 1).toLocaleString();
}

}
async function saveHeart(itemData) {
if (!itemData.likes) {
likes_array.push({
"_id": wixUsers.currentUser.id
})
console.log(likes_array);
itemData.likes = await JSON.stringify(likes_array);
wixData.update("beats", itemData)
.then((results) => {});
} else {
likes_array = JSON.parse(itemData.likes);
likes_array.push({
"_id": wixUsers.currentUser.id
})
console.log(likes_array);
itemData.likes = await JSON.stringify(likes_array);
wixData.update("beats", itemData)
.then((results) => {});
}
}
async function deleteHeart(itemData) {
console.log("Delete Heart");
if (itemData.likes) {
let parsed_likes = JSON.parse(itemData.likes);
let deleted_likes = parsed_likes.filter(function (obj) {
return obj._id !== wixUsers.currentUser.id;

});
console.log(deleted_likes);
itemData.likes = await JSON.stringify(deleted_likes);
wixData.update("beats", itemData)
.then((results) => {
// console.log()
});
}
}
}

//Sumir box volume e shared

You might also like