Docked footer that acts like a frame? - javascript

I'm designing a band website and Reverbnation has a cool music player in the footer which allows music to keep playing while changing pages.
I've looked at the code and I can't see any evidence of using frames. Which is the only way I know of achieving something like this. But that way is no longer supported in HTML5 and is also crap for SEO.
There is some JavaScript in the source code of the player, but I don't know enough JavaScript to tell if it's responsible. Something like this would be very useful to the site I'm building.
I would try a Google search but I have no idea what keywords I would use to look for a how to on the subject.
As the code was pretty long I cut and paste it here if anybody is willing to take a look at it.
Here is my code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.4.2/knockout-min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
jQuery(function($) {
if (!$("body").hasClass("new_sofia_navigation")) {
$("body").addClass("new_sofia_navigation")
}
var $search_el = $('#sofia_header_search input[type=text]')
$search_el.quickSearch({
search_path: 'http://search.reverbnation.com/search/quick.json',
use_jsonp: true
});
$("#sofia_header_search").submit(function(e) {
var $form = $(this);
e.preventDefault();
Reverb.Navigate.go_to_page_url($form.attr('action') + '?' + $form.serialize());
});
var repositionSearchContainer = function() {
$("#global_menu_search").find(".expanded_content").alignTo($("#global_menu_search"), "br-tr")
}
$("#menu_notifications, #global_menu_search, #menu_user_actions").bind("expand", function() {
var $menu = $(this).find(".expanded_content"),
$align_target = $("#global_menu_search"),
align_offset = {
top: 0,
left: 0
}
if ($menu.hasAttr("data-align-target")) {
$align_target = $("#" + $menu.attr("data-align-target"))
}
if ($menu.hasAttr("data-align-offset")) {
var offsets = $menu.attr("data-align-offset").split(":")
align_offset.left = parseInt(offsets[0]) || 0
align_offset.top = parseInt(offsets[1]) || 0
}
$(this).find(".expanded_content").alignTo($align_target, "br-tr", align_offset)
})
$search_el.bind("quicksearch_disable", repositionSearchContainer).bind("quicksearch_enable", repositionSearchContainer)
$("#menu_notifications:not(.no_notices)").bind("expand", function() {
$.get("/page_object/reset_new_notice_count/artist_332065")
$(this).addClass("no_notices")
})
$(window).trigger('user:login', {
"type": "Artist",
"feat_ownapp_apple": "0",
"artist_bes": 5722,
"feat_rpk": "P",
"feat_fr_rap": "P",
"feat_ownapp_push": "0",
"feat_mega": "0",
"feat_distro": "0",
"feat_ownapp": "0",
"feat_distro_p": "0",
"feat_distro_e": "0",
"is_admin": false,
"feat_widg": "0",
"feat_mega_max": "0",
"artist_country": "UK",
"genre": "Metal",
"feat_fr": "P",
"feat_bundle": "0",
"feat_ownapp_droid": "0",
"artist_bought": true,
"control_room": "sofia",
"name": "Soul Sanctuary",
"id": 332065,
"feat_sb": "0",
"feat_fr_360": "0",
"current_layout": "v3"
});
});
</script>
</div>
</div>
<script type="text/javascript">
jQuery(function($) {
Reverb.Notification.init('#standard_flash_message');
});
</script>
</div>
<div id="docked_footer">
<style type="text/css">
#sm2-container {
position: absolute;
width: 1px;
height: 1px;
top: 0;
left: 0;
overflow: hidden;
}
</style>
<div id="loading_gif">
<img alt="16x16_black" src="http://gp1.wac.edgecastcdn.net/802892/production_static/images/spinners/16x16_black.gif?1357641892" />
<span>Loading...</span>
</div>
<textarea id="template" style="display:none">
<div class="player_queue_item" >
<a href="javascript:trackEvent('V3 Footer Data','Click','Play Item ');" class="play_state" data-command="play" ></a>
<div class="content_wrap">
<div class="content">
<a href='{link}'><img src='{image}' /></a>
<h3 title="{title}">{title_display}</h3>
{artist_display}</h4>
</div>
</div>
<div class="actions" style="text-align:center">
Download
Share
Favorite
Lyrics
Be a fan
</div>
</div>
</textarea>
<div id="sm2-container"></div>
<div class="footer_content clearfix">
<div class="footer_music_player" id="music_player">
<div class="player_queue collapsed" id="player_queue">
<div class="player_queue_content">
<div class="player_queue_header">
</div>
<div class="player_queue_items card" data-card="queue_items">
<div class="card_actions clearfix">
<span data-role="title"></span>
Clear
Share All
Channels
</div>
<div class="player_queue_list"></div>
</div>
<div class=" card" data-card="queue_discover">
<div class="card_actions">
Show Queue
</div>
<div class="player_queue_discover">
<h1>ReverbNation Channels</h1>
<h3>Select a Music Channel to Get Started</h3>
Global Chart Toppers
Local Chart Toppers
Trending Artists
Alt/Rock/Indie
Electro/Pop/Dance
HipHop/Rap/R&B
Featured Artists
My Favorites
Custom Channel
</div>
</div>
<div class="player_queue_custom_channel card" data-card="queue_custom_channel">
<div class="card_actions">
Show Queue
</div>
<form action="/c/audio_player/music_now" id="custom_channel_form" method="post" onsubmit="new Ajax.Request('/c/audio_player/music_now', {asynchronous:true, evalScripts:true, parameters:Form.serialize(this)}); return false;"> <label for="reverb_radio_genres_player_select">Select Genres:</label>
<input id="reverb_radio_channel" name="reverb_radio[channel]" type="hidden" value="reverb_picks" />
<select data-placeholder="Click to select genre(s)" id="reverb_radio_genres_player_select" multiple="multiple" name="reverb_radio[genres][]">
<option value="alternative">Alternative</option>
<option value="ambient">Ambient</option>
<option value="americana">Americana</option>
<option value="bluegrass">Bluegrass</option>
<option value="blues">Blues</option>
<option value="bollywoodtollywood">Bollywood/Tollywood</option>
<option value="celtic">Celtic</option>
<option value="childrens">Childrens</option>
<option value="christianrock">Christian Rock</option>
<option value="christiangospel">Christian/Gospel</option>
<option value="classical">Classical</option>
<option value="comedy">Comedy</option>
<option value="country">Country</option>
<option value="dj">DJ</option>
<option value="dance">Dance</option>
<option value="dubstep">Dubstep</option>
<option value="electronicdancemusic">Electronic Dance Music</option>
<option value="electronica">Electronica</option>
<option value="experimental">Experimental</option>
<option value="folk">Folk</option>
<option value="funk">Funk</option>
<option value="hiphop">Hip Hop</option>
<option value="holiday">Holiday</option>
<option value="house">House</option>
<option value="indie">Indie</option>
<option value="instrumental">Instrumental</option>
<option value="jam">Jam</option>
<option value="jazz">Jazz</option>
<option value="latin">Latin</option>
<option value="metal">Metal</option>
<option value="other">Other</option>
<option value="pop">Pop</option>
<option value="punk">Punk</option>
<option value="rbsoul">R&B/Soul</option>
<option value="rap">Rap</option>
<option value="reggae">Reggae</option>
<option value="rock">Rock</option>
<option value="rockabilly">Rockabilly</option>
<option value="singersongwriter">Singer Songwriter</option>
<option value="ska">Ska</option>
<option value="spiritual">Spiritual</option>
<option value="spokenword">Spoken Word</option>
<option value="world">World</option>
</select>
<input class="standard_button style_primary size_small" name="commit" type="submit" value="Ok" />
Cancel
</form>
</div>
</div>
</div>
<div class="player_about" id="player_about">
<div class="cards">
<div class="song_info card" data-card="song_info">
<div class="song_actions clearfix">
</div>
<img data-role="image" src="data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==" />
<h3 data-role="title"></h3>
<a href="#" data-role="link">
<h4 data-role="artist"></h4>
</a>
<div class="progress_slider_wrap">
<div class="player_slider progress_slider">
<div class="progress">
<div class="progress_thumb small"></div>
</div>
<div class="time_progress extra_ui" style="word-break: normal !important;">12:123</div>
</div>
</div>
</div>
<div class="discover_music card" data-card="discover_music">
<p>Not listening to anything?</p>
<p>Try one of the ReverbNation Channels</p>
</div>
<div class="feedback card active" data-card="feedback">
</div>
</div>
</div>
<div class="player_song_control" id="player_control">
<div class="buttons">
</div>
<div class="player_slider volume_slider">
<div class="progress">
<div class="progress_thumb big"></div>
</div>
</div>
</div>
</div>
<div class="footer_content_right" id="docked_footer_content_right">
<div id="rabbit_hole_controls" class="footer_content_right_profile rabbit_hole_enabled">
<center>
Wat
Rabbit Hole
Go deeper <br/>
What's This?
</center>
</div>
<div id="rabbit_hole_tooltip" style="display: none"></div>
<script language="Javascript">
Reverb.playerReady(function() {
var $tooltip = $j('#rabbit_hole_tooltip'),
timeout_id;
$tooltip.bind('display-tooltip', function(e, message) {
$tooltip.html(message);
$tooltip.trigger('tooltip-show');
clearTimeout(timeout_id);
timeout_id = setTimeout(function() {
$tooltip.trigger('tooltip-hide');
}, 10000)
});
$tooltip.bind('tooltip-show', function(e) {
$tooltip.stop(true, true, true).
animate({
bottom: "-=10",
opacity: 'show'
});
});
$tooltip.bind('tooltip-hide', function(e) {
$tooltip.stop(true, true, true).
animate({
bottom: "+=10",
opacity: 'hide'
});
});
$tooltip.click(function(e) {
var info = MusicPlayer.getInstance().getCurrentSong()
if (info && info.link) {
Reverb.Navigate.go_to_page_url(info.link)
}
$tooltip.trigger('tooltip-hide');
})
$j('#rabbit-hole-wat').hover(function(e) {
if ($tooltip.html() != "") {
$tooltip.trigger('tooltip-show');
}
}, function(e) {
$tooltip.trigger('tooltip-hide');
});
function recommendationTextFor(hash, current_song) {
var reason = "Playing <em>" + current_song.artist + "</em> because";
switch (hash.type) {
case 'direct':
reason += " they were recommended by <em>" + $j.escapeHTML(hash.name) + "</em>";
break;
case 'show_bill':
reason += " they played a show with <em>" + $j.escapeHTML(hash.name) + "</em>" +
" on " + $j.escapeHTML(hash.latest_show_date) + ' in ' + $j.escapeHTML(hash.latest_show_location);
break;
case 'featured_artist':
reason += " they're a featured artist";
break;
default:
reason += " it's awesome";
break;
}
if (hash.reason != null) {
return $j.escapeHTML(hash.reason) + ". " + reason;
} else {
return reason;
}
}
MusicPlayer.getInstance().bind('playlist_updated', function(e, player) {
if ($j('#rabbit_hole_controls').hasClass('rabbit_hole_enabled')) {
$j('#music_player .player_queue_item:last').addClass('in_rabbit_hole');
}
});
MusicPlayer.getInstance().bind('song_play', function(e, player) {
var current_song = player && player.getCurrentSong();
if (current_song == null) {
// Hopefully means we got the thing cleared
$j('#rabbit_hole_controls').removeClass('rabbit_hole_enabled');
$j('#rabbit_hole_tooltip').html('');
Reverb.RabbitHoleCache = {};
return;
}
if (Reverb.RabbitHoleCache[parseInt(current_song.id, 10)] != null) {
$tooltip.trigger('display-tooltip', recommendationTextFor(Reverb.RabbitHoleCache[parseInt(current_song.id, 10)], current_song))
}
});
})
$j(function($) {
var goToCurrentArtist = function() {
// wee need a little delay to be sure the playlist is actually loaded before making any redirect
// not the ideal solution, but it doesn't require a beautiful reaper
window.setTimeout(function() {
var info = MusicPlayer.getInstance().getCurrentSong()
if (info && info.link) {
Reverb.Navigate.go_to_page_url(info.link)
}
})
}
$('#engage_rabbit_hole').click(function(e) {
var current_po;
if ((CURRENT_PAGE_OBJECT || '').match(/artist_/)) {
current_po = CURRENT_PAGE_OBJECT;
} else {
current_po = ''
}
trackEvent('V3 Footer Data', 'Click', 'Rabbit Hole');
$.ajax('/c/audio_player/rabbit_hole_now/' + current_po, {
type: 'get',
beforeSend: function() {
$j('#rabbit_hole_tooltip').trigger('display-tooltip', 'Loading…');
},
complete: goToCurrentArtist
});
return false;
});
$('#go_deeper').click(function(e) {
e.preventDefault();
var player = MusicPlayer.getInstance();
trackEvent('V3 Footer Data', 'Click', 'Go Deeper');
if (player.playingIndex < player.playlist.length - 1) {
player.sendCommand('next');
goToCurrentArtist()
}
});
$('#what_is_rabbit_hole').click(function(e) {
e.preventDefault();
modal_open('/audio_player/modal/rabbit_hole_modal')
trackEvent('V3 Footer Data', 'Click', 'What Is Rabbit Hole');
});
Reverb.RabbitHoleCache = Reverb.RabbitHoleCache || {};
});
</script>
</div>
</div>
<div id="footer_marketing_wrap">
<div id="footer_marketing" class="standard_footer_marketing standard_typography"></div>
</div>
<script type="text/javascript">
jQuery(function($) {
$("#player_about").qtip()
var $form = $("#custom_channel_form")
$("#music_player select").chosen().change(function() {
window.setTimeout(function() {
$form.center($form.parent())
}, 0)
})
$form.center($form.parent())
Reverb.playerReady(function() {
var load_timeout;
/* - No longer tied to profile page, will use server-side to check session cookie -
var songs_container = $("#profile_songs_container"), current_song_id, load_timeout
songs_container.delegate(".standard_play_button:not(.playing)","click", function(){
current_song_id = $(this).attr("data-song-id")
window.clearTimeout(load_timeout)
})
*/
MusicPlayer.getInstance().bind("playlist_updated", function fn(ev, player) {
var song = player.getCurrentSong();
/* - No longer tied to profile page, will use server-side to check session cookie -
if(songs_container.is(":not(:visible)")){
// detach the event listener, as the user left the original profile page
player.unbind("playlist_updated", fn)
}else if(song){
// if the current sound might not be the one the user is listening to.
// In order to be sure we're tracking the correct data, we have to check that the current song in the playlist is actually the one the user clicked on
if(current_song_id+"" == song.id+""){
current_song_id = false;
*/
window.clearTimeout(load_timeout);
var check_loaded = function() {
if (song && player.currentSound && player.currentSound.getLoaded()) { // the load percentage is > 0
//alert('before incrementing lp_song_plays');
$.get("/artist/increment_lp_song_plays", {
song_id: song.id
});
} else {
load_timeout = window.setTimeout(check_loaded, 100);
}
}
check_loaded();
/* }
}*/
});
});
})
</script>
</div>
</div>

The page you are refering to, is a single page website. They are not changing pages but change the look of the one page with javascript and ajax requests. That's why the player keeps playing.

Related

jQuery document on change for checkboxes and select options doesn't work

I'm having trouble with a (document.ready) on change function. It should get triggered when checkboxes are checked or when option elements from a select field are selected.
Everything works just fine with only checkboxes but once I added the part for select it stopped working like it should. I guess it's just a minor change somewhere but I haven't found the source. If you check the snippet it should become more obvious. I would really appreciate some help. :/
jQuery(document).ready(function() {
/* Location Filter */
var $filterCheckboxes = $('input[type="checkbox"]');
$(document).on('change', 'input[type="checkbox"]', 'select', function() {
var selectedFilters = {};
$filterCheckboxes.filter(':checked').each(function() {
if (!selectedFilters.hasOwnProperty(this.name)) {
selectedFilters[this.name] = [];
}
selectedFilters[this.name].push(this.value);
});
/* THIS PART IS PROBLEMATIC */
$('select option').filter(':selected').each(function() {
if (!selectedFilters.hasOwnProperty(this.name)) {
selectedFilters[this.name] = [];
}
selectedFilters[this.name].push(this.value);
});
/* WITHOUT IT EVERYTHING IS FINE BUT ONLY CHECKBOXES WORK */
var $filteredResults = $('.location-wrap');
$.each(selectedFilters, function(name, filterValues) {
$filteredResults = $filteredResults.filter(function() {
var matched = false,
currentFilterValues = $(this).attr('class').split(' ');
$.each(currentFilterValues, function(_, currentFilterValue) {
if ($.inArray(currentFilterValue, filterValues) != -1) {
matched = true;
return false;
}
});
return matched;
});
});
$('.location-wrap').removeClass('location-show').hide();
$('.location-wrap').removeClass('location-show').filter($filteredResults).addClass('location-show').show();
});
}); // jQuery(document).ready(function()
.content-box .location-show::after {
content: '';
background-color: #000;
height: 1px;
margin: 30px 0;
clear: both;
display: block;
}
.content-box .location-show:last-child::after {
height: 0;
margin: 0;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- FORM -->
<div class="content-box">
<form id="location-options">
<label>
<input type="checkbox" name="location-option" value="ltype-snack-bar" id="ltype-snack-bar"> Snack Bar
</label>
<label>
<input type="checkbox" name="location-option" value="ltype-restaurant" id="ltype-restaurant"> Restaurant
</label>
<label>
<input type="checkbox" name="location-option" value="filter-cat-ice-cream-parlor" id="ltype-ice-cream-parlor"> Ice cream parlor
</label>
<select name="location-category" id="location-category">
<option value="">Category</option>
<option value="filter-cat-a">Category A</option>
<option value="filter-cat-a">Category B</option>
<option value="filter-cat-a">Category C</option>
</select>
</form>
<!-- ELEMENTS READY FOR FILTERING -->
<div class="location-wrap location-show ltype-snack-bar filter-cat-a">
<h3>Snack Bar</h3>
<p>Some address2</p>
<p>Some description</p>
</div>
<div class="location-wrap location-show ltype-restaurant filter-cat-b">
<h3>Restaurant #1</h3>
<p>Some address</p>
<p>Some description</p>
</div>
<div class="location-wrap location-show ltype-ice-cream-parlor filter-cat-b">
<h3>Ice cream parlor</h3>
<p>Some address</p>
<p>Some description</p>
</div>
<div class="location-wrap location-show ltype-restaurant filter-cat-c">
<h3>Restaurant #2</h3>
<p>Some address</p>
<p>Some description</p>
</div>
</div>

Input value not updating on page when changed

I have to do a web page for school that converts temperature between celsius and fahrenheit.
I tried to make it with 2 input boxes that change value based on the value of the other input box, when I write something on one of the input boxes for the first time it works, but then even though on the code the value changes, on the page it doesn't appear.
I am new to javascript and html in general and I don't know what I'm doing wrong.
This is the code:
function cambiagradi(x,y) {
if (document.getElementById(x).value == "Centigradi") {
document.getElementById(y).value = "Fahrenheit";
}
else {
document.getElementById(y).value = "Centigradi";
}
}
function Conversione(from,to,gradi) {
var x = document.getElementById(from).value;
if (document.getElementById(gradi).value == "Centigradi") {
document.getElementById(to).setAttribute("value", (x-32)*5/9);
}
else {
document.getElementById(to).setAttribute("value", (x*9/5)+32);
}
}
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body style="background-color: #008080;">
<h1 style="text-align:center">Convertitore Temperatura</h1>
<div class="container" style="display:flex; justify-content: center">
<div style=" padding: 1%; ">
<p>
<input type="text" id="box1" oninput="Conversione('box1','box2','Gradi2')">
</p>
<p style="margin-left:10%">
<label for="Gradi1">Gradi</label>
<select id="Gradi1" onchange="cambiagradi('Gradi1','Gradi2')">
<option value="Centigradi">Centigradi</option>
<option value="Fahrenheit">Fahrenheit</option>
</select>
</p>
</div>
<div style=" padding: 1%; ">=</div>
<div style=" padding: 1%; ">
<p>
<input type="text" id="box2" oninput="Conversione('box2','box1','Gradi1')">
</p>
<p style="margin-left:10%">
<label for="Gradi2">Gradi</label>
<select id="Gradi2" onchange="cambiagradi('Gradi2','Gradi1')">
<option value="Fahrenheit">Fahrenheit</option>
<option value="Centigradi">Centigradi</option>
</select>
</p>
</div>
</div>
</body>
</html>
Thanks in advance!
You should just set the value of the element and all would work as expected.
The explanation you can find here.
function Conversione(from, to, gradi) {
const x = document.getElementById(from).value;
if (document.getElementById(gradi).value == "Centigradi") {
document.getElementById(to).value = ((x - 32) * 5) / 9;
} else {
document.getElementById(to).value = (x * 9) / 5 + 32;
}
}
Some explanations within the code. Tell me if you need more. It looks more complicated but it avoids inline JavaScript which is good :)
// Define your elements as variables first as you're going to use them multiple times :
const gradi1 = document.getElementById("Gradi1");
const gradi2 = document.getElementById("Gradi2");
const box1 = document.getElementById("box1");
const box2 = document.getElementById("box2");
// Now, always use gradi1, gradi2, box1 and box2 instead of document.getElementById ....
// Then, avoid INLINE JavaScript ! (onchange="")
// We're gonna add 'event listener' to your elements
gradi1.addEventListener("change", function(){
cambiagradi(this); // 'this' means you'll know which element triggered the event when calling the function
}, false);
gradi2.addEventListener("change", function(){
cambiagradi(this);
}, false);
box1.addEventListener("input", function(){
Conversione(this)
}, false);
box2.addEventListener("input", function(){
Conversione(this)
}, false);
// You passed 'this' previously, so its back here with the name you want (ex: ancora_this)
function cambiagradi(ancora_this) {
if (ancora_this.id == "Gradi1") {
if (ancora_this.selectedIndex == 0) { // 'selectedIndex' means selected option position in the dropdown menu (begins at 0)
gradi2.selectedIndex = 1;
} else {
gradi2.selectedIndex = 0;
}
} else {
if (ancora_this.selectedIndex == 1) {
gradi1.selectedIndex = 0;
} else {
gradi1.selectedIndex = 1;
}
}
}
function Conversione(ancora_this) {
var target, conv, unit;
if (ancora_this.id == "box1") {
target = box2;
unit = gradi1;
} else {
target = box1;
unit = gradi2;
}
if (unit.selectedIndex == 0) {
conv = (Number(ancora_this.value) * 9/5) + 32;
} else {
conv = (Number(ancora_this.value) - 32)*5/9;
}
target.value = conv;
}
body {
background-color: #008080
}
h1 {
text-align: center
}
.container {
display: flex;
justify-content: center
}
.container div {
padding: 1%;
}
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Convertitore Temperatura</h1>
<div class="container">
<div>
<p>
<!-- type="number" is better because it only allows numbers -->
<input type="number" id="box1">
</p>
<p style="margin-left:10%">
<label for="Gradi1">Gradi</label>
<select id="Gradi1">
<option value="Centigradi" selected>Centigradi</option>
<option value="Fahrenheit">Fahrenheit</option>
</select>
</p>
</div>
<div>=</div>
<div>
<p>
<input type="number" id="box2">
</p>
<p style="margin-left:10%">
<label for="Gradi2">Gradi</label>
<select id="Gradi2">
<!-- I switched the order to have the same 'index' on both SELECT menus
Also, I added 'selected' to have a default selected unit at start -->
<option value="Centigradi">Centigradi</option>
<option value="Fahrenheit" selected>Fahrenheit</option>
</select>
</p>
</div>
</div>
</body>
</html>

Target two fields when searching

I have this layout:
<input id="search">
<div class="entry">
<div class="title">hello</div>
<div class="description">lorem</div>
</div>
<div class="entry">
<div class="title">ipsum</div>
<div class="description">test</div>
</div>
And I allow users to search the entry divs by the content of the title div:
jQuery(document).ready(function() {
jQuery("#search").on("keyup click input", function () {
var val = jQuery(this).val();
if (val.length) {
jQuery(".entry").hide().filter(function () {
return jQuery('.title',this).text().toLowerCase().indexOf(val.toLowerCase()) != -1;
}).show();
}
else {
jQuery(".entry").show();
}
});
});
Works great. Try jsFiddle.
My question is, how do I make it so the search targets both the content of the title div and the description field?
If you want it to search for both title and description use this.
return jQuery('.title, .description',this)
Then it will look like
jQuery(".entry").hide().filter(function () {
return jQuery('.title, .description',this).text().toLowerCase().indexOf(val.toLowerCase()) != -1;
}).show();
Here is a link so you can test it.
In the filter function, you can add an OR condition that can check the description and filter results on title or description.
jQuery(document).ready(function() {
jQuery("#search").on("keyup click input", function() {
var val = jQuery(this).val();
if (val.length) {
jQuery(".entry").hide().filter(function() {
return jQuery('.title, .description', this).text().toLowerCase().indexOf(val.toLowerCase()) != -1;
}).show();
} else {
jQuery(".entry").show();
}
});
});
.entry {
background: #fff;
margin-bottom: 10px;
width: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="search">
<div class="entry">
<div class="title">hello</div>
<div class="description">lorem</div>
</div>
<div class="entry">
<div class="title">ipsum</div>
<div class="description">test</div>
</div>

setInterval() not working with src linked images in HTML

New coder - 1st question here. I'm doing first free code camp project, but question is about a unrequired flourish I just want to add and learn about, it's not needed for project. I want the album covers I've linked in HTML to change every x seconds. But nothing happens yet. Images just stay static. Thanks
<h2> Discography </h2>
<div class="row">
<div id="album" class="col-lg-8">
<div class="albums" id="album 0"> <span><img src="https://upload.wikimedia.org/wikipedia/en/b/b6/Elliottsmithromancandle.jpeg" alt="1994" class="img-responsive"></span></div>
<div class="albums" id="album 1"> <span><img src="https://upload.wikimedia.org/wikipedia/en/e/e3/Elliott_Smith_%28album%29.jpg" alt="1995" class="img-responsive"></span></div>
<div class="albums" id="album 2"> <span><img src="https://upload.wikimedia.org/wikipedia/en/f/fd/Elliottsmitheitheror55.jpg" alt="1997" class="img-responsive"></span></div>
<div class="albums" id="album 3"> <span><img src="https://upload.wikimedia.org/wikipedia/en/thumb/3/…albumcover.jpg/330px-ElliottsmithXOalbumcover.jpg" alt="1998" class="img-responsive"></span></div>
<div class="albums" id="album 4"> <span><img src="https://upload.wikimedia.org/wikipedia/en/thumb/a/…_cover.jpg/330px-Elliott_smith_figure_8_cover.jpg" alt="2000" class="img-responsive"></span></div>
<div class="albums" id="album 5"> <span><img src="https://upload.wikimedia.org/wikipedia/en/8/8c/Elliott_smith_from_a_basement_on_the_hill_cover.jpg" alt="2004" class="img-responsive"></span></div>
<div class="albums" id="album 6"> <span><img src="https://upload.wikimedia.org/wikipedia/en/4/4e/New_Moon_%28Elliott_Smith_album%29_cover.jpg" alt="2007" class="img-responsive"></span></div>
</div>
and the javascript code
//Change album cover after 5 seconds - continous loop//
var Discography = document.getElementById("album");
var disc = ["album 0", "album 1", "album 2", "album 3", "album 4", "album 5", "album 6"];
var counter = 0;
function changeDisc() {
if (counter >= disc.length) {
counter = 0;
}
Discography.setAttribute =disc[counter];
counter++;
}
var myCounter = setInterval(changeDisc, 6000);
Discography.onClick = function() {
clearInterval(Disography);
Discography.innerHTML = "Counter stopped";
};
You aren't actually setting the attribute. You are actually removing the setAttribute method and replacing it with the url. I think you want this:
function changeDisc() {
if (counter >= disc.length) {
counter = 0;
}
Discography.setAttribute('src', disc[counter]);
counter++;
}
I managed to get your code working. I don't know if this is what you wanted, but I hope it helped you.
Assign Attributes
Discography.setAttribute = disc[counter];
Should be
Discography.setAttribute("src", discs[counter]);
Bind EventHandlers
Discography.onClick = function() {
Should be
Discography.addEventListener("click", function () {
Wrong Element
You tried to assign the src attribute to the <div id="album" class="col-lg-8"> which is a div and it does not have that attribute.
To fix this I added all possible album images to a Array and this will be assigned to a single <img /> to get this working.
Note that I modified some naming conventions, which I do prefer.
My Solution
var discs = [
"https://upload.wikimedia.org/wikipedia/en/b/b6/Elliottsmithromancandle.jpeg",
"https://upload.wikimedia.org/wikipedia/en/e/e3/Elliott_Smith_%28album%29.jpg",
"https://upload.wikimedia.org/wikipedia/en/f/fd/Elliottsmitheitheror55.jpg",
"https://upload.wikimedia.org/wikipedia/en/thumb/3/…albumcover.jpg/330px-ElliottsmithXOalbumcover.jpg",
"https://upload.wikimedia.org/wikipedia/en/thumb/a/…_cover.jpg/330px-Elliott_smith_figure_8_cover.jpg",
"https://upload.wikimedia.org/wikipedia/en/8/8c/Elliott_smith_from_a_basement_on_the_hill_cover.jpg" ,
"https://upload.wikimedia.org/wikipedia/en/4/4e/New_Moon_%28Elliott_Smith_album%29_cover.jpg",
];
var counter = 0;
var discography = document.getElementById("album");
function moveToNextDisc() {
if (counter >= discs.length) {
counter = 0;
}
discography.setAttribute("src", discs[counter]);
counter++;
}
var interval = setInterval(moveToNextDisc, 1000);
discography.addEventListener("click", function () {
clearInterval(interval);
discography.innerHTML = "Counter stopped";
});
<h2>Discography</h2>
<div class="row">
<div class="col-lg-8">
<div class="albums">
<span>
<img id="album" alt="1994" class="img-responsive">
</span>
</div>
</div>
</div>
for learning purpose, you are developing a component that:
changes cover every track change
stops when the user pauses
Javascript should be used for business logic and html/css as a view reflection of the state of the component.
So we need for an Object which has at least three methods:
public play starts the player
public pause pauses the player
private _loop iterates through the tracks
and for a Controller which controls the html view.
function Player(element, interval) {
this.element = element;
this.tracks = element.querySelectorAll('.albums');
this.currentTrack = null;
this.isPlaying = false;
this._timeout = null;
this.interval = Number(interval) || 2000;
}
Player.prototype.pause = function() {
window.clearTimeout(this._timeout);
this.isPlaying = false;
return this;
};
Player.prototype.play = function() {
this.isPlaying = true;
return this._loop();
};
Player.prototype._loop = function() {
var self = this;
self._timeout = window.setTimeout(function() {
var track;
if(self.currentTrack) {
track = self.currentTrack.nextElementSibling;
self.currentTrack.style.opacity = 0;
}
if(!track) {
track = self.tracks[0];
}
track.style.opacity = 1;
self.currentTrack = track;
return self._loop();
}, self.interval);
return this;
}
/** VIEW CTRL **/
function PlayerCtrl() {
var element = document.querySelector('#album');
var player = new Player(element, 3000);
var play = document.querySelector('#Play');
var pause = document.querySelector('#Pause');
play.onclick = function() {
return player.isPlaying || player.play();
};
pause.onclick = function() {
return player.isPlaying && player.pause();
};
player.play();
}
document.addEventListener('DOMContentLoaded', PlayerCtrl);
#album {
width: 300px;
height: 300px;
margin: 10px auto;
overflow: hidden;
background: lightcoral;
position: relative;
border: 3px dotted #333;
}
.albums {
transition: 450ms opacity linear;
opacity: 0;
position: absolute;
top: 0;
left: 0;
}
.albums img { max-width: 100%; }
<button id="Play">Play</button>
<button id="Pause">Pause</button>
<hr />
<h2> Discography </h2>
<div class="row">
<div id="album" class="col-lg-8">
<div class="albums" id="album 0"> <span><img src="https://upload.wikimedia.org/wikipedia/en/b/b6/Elliottsmithromancandle.jpeg" alt="1994" class="img-responsive"></span></div>
<div class="albums" id="album 1"> <span><img src="https://upload.wikimedia.org/wikipedia/en/e/e3/Elliott_Smith_%28album%29.jpg" alt="1995" class="img-responsive"></span></div>
<div class="albums" id="album 2"> <span><img src="https://upload.wikimedia.org/wikipedia/en/f/fd/Elliottsmitheitheror55.jpg" alt="1997" class="img-responsive"></span></div>
<div class="albums" id="album 3"> <span><img src="https://upload.wikimedia.org/wikipedia/en/thumb/3/…albumcover.jpg/330px-ElliottsmithXOalbumcover.jpg" alt="1998" class="img-responsive"></span></div>
<div class="albums" id="album 4"> <span><img src="https://upload.wikimedia.org/wikipedia/en/thumb/a/…_cover.jpg/330px-Elliott_smith_figure_8_cover.jpg" alt="2000" class="img-responsive"></span></div>
<div class="albums" id="album 5"> <span><img src="https://upload.wikimedia.org/wikipedia/en/8/8c/Elliott_smith_from_a_basement_on_the_hill_cover.jpg" alt="2004" class="img-responsive"></span></div>
<div class="albums" id="album 6"> <span><img src="https://upload.wikimedia.org/wikipedia/en/4/4e/New_Moon_%28Elliott_Smith_album%29_cover.jpg" alt="2007" class="img-responsive"></span></div>
</div>

Icon size changes on shift

I want to shift the whole div to left on click of button but I want to fix the size now size changes on shift. I want to click on Sync button and it should move left.
I am using Jquery.
Following is the whole Code
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$('button').click(function () {
$('.error').stop().fadeIn(400).delay(3000).fadeOut(400); //fade out after 3 seconds
});
</script>
<script type="text/javascript">
window.onload=function(){
populatedropdown( "monthdropdown", "yeardropdown")
}
</script>
<script type="text/javascript">
var monthtext=['Month','01','02','03','04','05','06','07','08','09','10','11','12'];
var yeartext=['Year','2015','2014','2013','2012','2011','2010','2009','2008','2007','2006','2005','2004','2003','2002','2001','2000'];
function populatedropdown( monthfield, yearfield){
var today=new Date();
var monthfield=document.getElementById(monthfield);
var yearfield=document.getElementById(yearfield);
for (var m=0; m<=12; m++)
monthfield.options[m]=new Option(monthtext[m], monthtext[m])
// monthfield.options[today.getMonth()]=new Option(monthtext[today.getMonth()], monthtext[today.getMonth()], true, true) ;//select today's month
var thisyear=today.getFullYear();
// yearfield.options[0]= Year;
for (var y=0; y<17; y++){
//yearfield.options[y]=new Option(thisyear, thisyear);
yearfield.options[y]=new Option(yeartext[y], yeartext[y]);
thisyear-=1;
}
// yearfield.options[0]=new Option(today.getFullYear(), today.getFullYear(), true, true); //select today's year
}
</script>
<script type="text/javascript">
$(function () {
$("#drop").change(function () {
selectedText = $(this).find("option:selected").text();
if(selectedText != "RBSK")
{
alert("Test available for RBSK only");
}
msg="";
});
});
$(function () {
$("#monthdropdown").change(function () {
selectedText_month="Month";
selectedText_month = $(this).find("option:selected").text();
if(selectedText_month == "Month")
{
alert("Please Choose Month");
}
console.log("month is--" + selectedText_month);
});
});
$(function () {
$("#yeardropdown").change(function () {
selectedText_year="Year";
selectedText_year = $(this).find("option:selected").text();
if(selectedText_year == "Year")
{
alert("Please Choose Valid Year");
}
console.log("year is--" + selectedText_year);
});
});
console.log("period: "+selectedText_year+selectedText_month);
</script>
<script type="text/javascript">
$(document).ready(function() {
$('#Submit').click(function () {
$('#content').animate({
'marginLeft': "-=600px" //moves left
});
});
$('#Submit').click(function () {
$('#myHeader').animate({
'marginTop': "-=250px" //moves left
});
});
$('#Submit').click(function () {
$('#qwe').animate({
'marginTop': "-=450px" //moves left
});
});
$('#Submit').click(function () {
$('#qwe2').animate({
'marginTop': "-=450px" //moves left
});
});
$('#Submit').click(function () {
$('#qwe1').animate({
'marginTop': "-=950px" //moves left
});
});
$('#Submit').click(function () {
$('#qwe3').animate({
'marginTop': "-=970px" //moves left
});
});
// $('#Submit').click(function () {
// $('#img').show();
//
// $.ajax({
//
//
//
// success: function (result) {
// $('#img').hide();
// }
//
// });
// });
});
</script>
<style>
h2 {
text-align: center;
}
body {
background-color: lightblue;
}
</style>
<!DOCTYPE html>
<html lang="en">
<head>
<body>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<form id="From1" method="post">
<div style="display:table-cell; vertical-align:middle; text-align:center">
<img src="js/xmlimg.png" style="width:180px; height:160px"; align="left">
<img src="js/loading.gif" id="img" style="display:none" align="center"/>
</div>
<div id="content"style="display: block">
<h2 >Welcome</h2>
<br>
<p style="font-size:150%;margin-left:39%" > Sources :
<select id="drop" name="drop">
<option value="0">Select Source</option>
<option value="1">RBSK</option>
<option value="2">MIDRS</option>
<option value="3">ATM </option>
<option value="4">RT </option>
</select>
<p style="font-size:150%;margin-left:40%"; >Period :
<form>
<form action="" name="someform">
<select id="monthdropdown"></select>
<select id="yeardropdown"></select>
<br> <br>
<button type="button" class="btn btn-primary btn-lg" style= " margin-left: 13% " id="Submit" name="Submit" onclick="prepareDataValueSet()">SYNC
</button>
</form>
</form>
</div>
<h4 id="myHeader" style="text-align:right; margin-top:10%; margin-right:20%; color: indianred"></h4>
<h4 id="qwe" style="text-align: right; margin-top:15%; margin-right:10%;color: dodgerblue"></h4>
<h4 id="qwe2" style="text-align: right; margin-top:20%; margin-right:10%;color: dodgerblue"></h4>
<h4 id="qwe1" style="text-align: right; margin-top:55%; margin-right:4%;color: darkgreen"></h4>
<h4 id="qwe3" style="text-align: right; margin-top:55%; margin-right:4%;color: darkgreen"></h4>
</div>
</form>
</body>
</html>

Categories

Resources