blogging 102: gadgets!

 Now comes the fun part of making a blog: the gadgets! Gadgets are the pictures or interactive elements on the side of your blog. They help make a blog feel like your own! 


To add gadgets of your own, you're going to go to the layout section of your blog editing page. It should look something like this. When you click the add a gadget option, you'll get a long dropdown menu. The one's we'll focus on are the HTML option. When you click on this, it will open a box with a title option and a text option. If you want your gadget to have any text above the interactive element, this is where you put it. The bottom box is for your HTML code. You can paste or write your code in here as well as make any edits to customize your gadget to your page

HTML code can be pretty confusing, so let's look at an example from my blog with my CD player widget. 

Click here to expand/collapse the CD Player HTML

 <style>
/* MP3 Player - Scoped Styles (Only affects .player) */
.player * {
    box-sizing: border-box;
}

.player {
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

/* All styles are scoped under .player */
.player .window,
.player .title-bar {
    font-family: "Pixelated MS Sans Serif", Arial;
    -webkit-font-smoothing: none;
    font-size: 11px;
}

.player .window {
    box-shadow: inset -1px -1px #0a0a0a,
        inset 1px 1px #dfdfdf, inset -2px -2px #808080,
        inset 2px 2px #ffffff;
    background: #c0c0c0;
    padding: 3px;
    width: 260px;
}

.player .title-bar {
    padding: 3px 2px 3px 3px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to right, #613574 0%, #C0C0C0 100%);
}

.player .title-bar-text {
    font-weight: bold;
    color: white;
    letter-spacing: 0;
    margin-right: 24px;
    font-size: 11px;
}

.player .title-bar-controls {
    display: flex;
}

.player .title-bar-controls button {
    padding: 0;
    display: block;
    min-width: 16px;
    min-height: 14px;
    background: silver;
    border: none;
    border-radius: 0;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff, inset -2px -2px grey, inset 2px 2px #dfdfdf;
    font-size: 11px;
    color: transparent;
    text-shadow: none;
}

.player .title-bar-controls button:active {
    box-shadow: inset -1px -1px #fff, inset 1px 1px #0a0a0a, inset -2px -2px #dfdfdf, inset 2px 2px grey;
}

.player .title-bar-controls button[aria-label="Minimize"] {
    background-image: url("https://raw.githubusercontent.com/jdan/98.css/main/icon/minimize.svg");
    background-position: bottom 3px left 4px;
    background-repeat: no-repeat;
}

.player .title-bar-controls button[aria-label="Maximize"] {
    background-image: url("https://raw.githubusercontent.com/jdan/98.css/4a2282dd9170cabf730fb5803d1153d86b2e94e3/icon/maximize.svg");
    background-position: top 2px left 3px;
    background-repeat: no-repeat;
}

.player .title-bar-controls button[aria-label="Close"] {
    background-image: url("https://raw.githubusercontent.com/jdan/98.css/main/icon/close.svg");
    background-position: top 3px left 4px;
    background-repeat: no-repeat;
    margin-left: 2px;
}

.player .window-body {
    margin: 0px;
    height: 98px;
}

.player .flex {
    display: flex;
}

.player #imagestyle {
    background: silver;
    border: 2px solid silver;
    width: 95px;
    height: 95px;
    box-shadow: inset -1px -1px #fff, inset 1px 1px grey, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
}

.player .ic {
    width: 90px;
    position: relative;
    bottom: 1px;
    right: 1px;
    overflow: hidden;
    padding: 2px;
    border: 2px solid transparent;
}

.player .titlebaricon {
    height: 14px;
    width: 14px;
}

.player #musicplayer {
    border: 2px solid silver;
    border-width: 2px 0px 0px 0px;
    width: 160px;
}

.player .songtitlewindow {
    background-color: #fff;
    box-shadow: inset -1px -1px #fff, inset 1px 1px grey, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
}

.player .songtitlearrow {
    background-size: 100%;
    background-repeat: no-repeat;
    background-image: url(https://files.catbox.moe/f5e8np.png);
    height: 21px;
    width: 21px;
    position: relative;
    top: 2px;
    left: -2px;
    border: 0px solid transparent;
}

.player .songtitle {
    padding: 5px;
    border-bottom: 0px;
    display: block;
    font-family: "Pixelated MS Sans Serif", Arial;
    font-size: 11px;
    color: #000;
}

.player .controls {
    font-size: 18px !important;
    text-align: center;
    width: 100%;
    position: relative;
    bottom: 10px;
}

.player .controls td {
    padding: 8px 5px 0px 5px;
}

.player .controls button {
    min-width: 40px;
    background: silver;
    border: none;
    border-radius: 0;
    box-shadow: inset -1px -1px #0a0a0a, inset 1px 1px #fff, inset -2px -2px grey, inset 2px 2px #dfdfdf;
    padding: 4px 8px;
    font-size: 11px;
    color: #000;
    cursor: pointer;
}

.player .controls button:active {
    box-shadow: inset -1px -1px #fff, inset 1px 1px #0a0a0a, inset -2px -2px #dfdfdf, inset 2px 2px grey;
}

.player .controlimg {
    height: 15px;
    width: 15px;
    display: block;
}

.player .seeking {
    background-color: #c0c0c0;
    display: flex;
    justify-content: space-evenly;
    padding: 14px;
    align-items: center;
}

.player .current-time,
.player .total-duration {
    font-family: "Pixelated MS Sans Serif", Arial;
    font-size: 11px;
    color: #000;
}

.player input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    background: transparent;
    margin: 0 5px;
}

.player input[type="range"]:focus {
    outline: none;
}

.player input[type="range"]::-webkit-slider-runnable-track {
    width: 100%;
    height: 2px;
    box-sizing: border-box;
    background: black;
    border-right: 1px solid grey;
    border-bottom: 1px solid grey;
    box-shadow: 1px 0 0 white, 1px 1px 0 white, 0 1px 0 white, -1px 0 0 darkgrey,
        -1px -1px 0 darkgrey, 0 -1px 0 darkgrey, -1px 1px 0 white, 1px -1px darkgrey;
}

.player input[type="range"]::-moz-range-track {
    width: 100%;
    height: 2px;
    box-sizing: border-box;
    background: black;
    border-right: 1px solid grey;
    border-bottom: 1px solid grey;
    box-shadow: 1px 0 0 white, 1px 1px 0 white, 0 1px 0 white, -1px 0 0 darkgrey,
        -1px -1px 0 darkgrey, 0 -1px 0 darkgrey, -1px 1px 0 white, 1px -1px darkgrey;
}

.player input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 21px;
    width: 11px;
    background: url("https://raw.githubusercontent.com/jdan/98.css/main/icon/indicator-horizontal.svg");
    transform: translateY(-8px);
    box-shadow: none;
    border: none;
}

.player input[type="range"]::-moz-range-thumb {
    height: 21px;
    width: 11px;
    border: 0;
    border-radius: 0;
    background: url("https://raw.githubusercontent.com/jdan/98.css/main/icon/indicator-horizontal.svg");
    transform: translateY(2px);
}

@font-face {
    font-family: "Pixelated MS Sans Serif";
    src: url("https://files.catbox.moe/1za99g.woff") format("woff");
    src: url("https://files.catbox.moe/8fwbkl.woff2") format("woff2");
    font-weight: normal;
    font-style: normal;
}

@font-face {
    font-family: "Pixelated MS Sans Serif";
    src: url("https://files.catbox.moe/z7csle.woff") format("woff");
    src: url("https://files.catbox.moe/moqhx6.woff2") format("woff2");
    font-weight: bold;
    font-style: normal;
}
</style>

<div class="player">
    <div class="window">
        <div class="title-bar">
            <div class="title-bar-text"><sub><img class="titlebaricon" src="https://files.catbox.moe/tg55zp.png" alt="cd player icon" /></sub> CD player</div>
            <div class="title-bar-controls">
                <button aria-label="Minimize"></button>
                <button aria-label="Maximize"></button>
                <button aria-label="Close"></button>
            </div>
        </div>
        <div class="window-body">
            <div class="flex">
                <div id="imagestyle"><img class="ic" src="https://i.pinimg.com/736x/de/0f/cd/de0fcd818924383d4d6964fa282a386a.jpg" /></div>
                <div id="musicplayer">
                    <div class="songtitlewindow">
                        <div class="flex"><marquee scrollamount="4" class="songtitle"></marquee><div class="songtitlearrow"></div></div>
                    </div>

                    <div class="seeking">
                        <div class="current-time">00:00</div>
                        <input type="range" min="1" max="100" value="0" class="seek_slider" />
                        <div class="total-duration">0:00</div>
                    </div>

                    <table class="controls">
                        <tr>
                            <td><button class="prev-track"><img src="https://files.catbox.moe/hhoh1h.png" class="controlimg" /></button></td>
                            <td><button class="playpause-track"><img src="https://files.catbox.moe/w93riq.png" class="controlimg" /></button></td>
                            <td><button class="next-track"><img src="https://files.catbox.moe/p4q9gf.png" class="controlimg" /></button></td>
                        </tr>
                    </table>

                    <audio id="music" src=""></audio>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    (function() {
        // initiate variables
        let track_name = document.querySelector(".player .songtitle");
        let playpause_btn = document.querySelector(".player .playpause-track");
        let next_btn = document.querySelector(".player .next-track");
        let prev_btn = document.querySelector(".player .prev-track");
        let seek_slider = document.querySelector(".player .seek_slider");
        let curr_time = document.querySelector(".player .current-time");
        let total_duration = document.querySelector(".player .total-duration");

        let track_index = 0;
        let isPlaying = false;
        let updateTimer;
        let curr_track = document.getElementById("music");

        // YOUR SONGS HERE
        let track_list = [{
            name: "The Bitch Is Back - Elton John",
            path: "https://files.catbox.moe/51ihi8.mp3"
        }, {
            name: "Black Sheep - Metric",
            path: "https://files.catbox.moe/29gs6t.mp3"
        }, {
            name: "My Life - Billy Joel",
            path: "https://files.catbox.moe/udxi9c.mp3"
        }, {
            name: "One Way Or Another - Blondie",
            path: "https://files.catbox.moe/pipce1.mp3"
        }, {
            name: "I Love Rock 'N Roll - Joan Jett and the Blackhearts",
            path: "https://files.catbox.moe/ozwr2w.mp3"
        }];

        function loadTrack(index) {
            clearInterval(updateTimer);
            resetValues();
            curr_track.src = track_list[index].path;
            curr_track.load();
            track_name.textContent = "playing " + (index + 1) + " of " + track_list.length + ": " + track_list[index].name;
            updateTimer = setInterval(seekUpdate, 1000);
            curr_track.addEventListener("ended", nextTrack);
        }

        function resetValues() {
            curr_time.textContent = "0:00";
            total_duration.textContent = "0:00";
            seek_slider.value = 0;
        }

        function playpauseTrack() {
            if (!isPlaying) playTrack();
            else pauseTrack();
        }

        function playTrack() {
            curr_track.play();
            isPlaying = true;
            playpause_btn.innerHTML = '<img src="https://files.catbox.moe/njer0s.png" class="controlimg" />';
        }

        function pauseTrack() {
            curr_track.pause();
            isPlaying = false;
            playpause_btn.innerHTML = '<img src="https://files.catbox.moe/w93riq.png" class="controlimg" />';
        }

        function nextTrack() {
            track_index = (track_index < track_list.length - 1) ? track_index + 1 : 0;
            loadTrack(track_index);
            playTrack();
        }

        function prevTrack() {
            track_index = (track_index > 0) ? track_index - 1 : track_list.length - 1;
            loadTrack(track_index);
            playTrack();
        }

        function seekTo() {
            let seekto = curr_track.duration * (seek_slider.value / 100);
            curr_track.currentTime = seekto;
        }

        function seekUpdate() {
            if (!isNaN(curr_track.duration)) {
                let seekPosition = curr_track.currentTime * (100 / curr_track.duration);
                seek_slider.value = seekPosition;

                let currentMinutes = Math.floor(curr_track.currentTime / 60);
                let currentSeconds = Math.floor(curr_track.currentTime - currentMinutes * 60);
                let durationMinutes = Math.floor(curr_track.duration / 60);
                let durationSeconds = Math.floor(curr_track.duration - durationMinutes * 60);

                if (currentSeconds < 10) currentSeconds = "0" + currentSeconds;
                if (durationSeconds < 10) durationSeconds = "0" + durationSeconds;

                curr_time.textContent = currentMinutes + ":" + currentSeconds;
                total_duration.textContent = durationMinutes + ":" + durationSeconds;
            }
        }

        // Event listeners
        playpause_btn.addEventListener("click", playpauseTrack);
        next_btn.addEventListener("click", nextTrack);
        prev_btn.addEventListener("click", prevTrack);
        seek_slider.addEventListener("change", seekTo);

        loadTrack(track_index);
    })();
</script>

This is the code you'll paste into the HTML box, but once it's in there you'll want to make it your own! It seems long and intimidating, but ctrl+f is going to be your best friend. But first, a crash course in HTML by a girl who knows next to nothing about coding: 

This sort of thing with a name next to one of these { is going to be defining what an element is. The section labeled padding dictates how far from center the element is, so mess with these numbers to adjust where it sits within the allotted space for a widget. We know this widget is aligned to the center because of the align-items section. The important part for customization is the background section, which tells the element what color to be. In this case, it's telling it to be a gradient from one color to a completely different one. All elements are going to be defined in this way. Let's take a look at another one. 

This element has sections telling it how big it should be in the height and width sections. Messing with these can help you change the size, but be aware it will also change where it is centered in the available area. The other thing to note about this element is the image. When putting an image into HTML code you have to use the image address. Most of my images are from Pinterest, and to get the image address from there you just double click. 

To customize the widget, I ctrl+F for the hex codes and change them to the ones that match my bog to zip around. This part usually requires some double checking in your blog, so you'll have to take some time to mess around. You have to make sure all sections with colors are changed to match your blog.

To customize the songs in the CD player widget, you're going to want to crtl+f for YOUR SONGS HERE. Below, there will be a section that looks like this. 


A website called Catbox will turn mp3 files into a url you can put in here. If you want to add more songs, make sure you use the appropriate format by copy-pasting an entire section between the {} and replacing the song title and url. 

Most gadgets just use this HTML section, but some will require additional CSS coding to format the elements. CSS coding goes in the CSS dropdown in the advanced menu of the theme editor. CSS coding is a bit different, but when making changes look for the same basic things: pixel measurements for size or alignment and hex codes to change the color. 

Hopefully this answers some questions about the gadget feature! If you have any questions, let me know in the comments!

No comments:

Post a Comment