Autoplay Audio when modal jquery dialog box opens? - jquery-ui

I've set up a html where: when you click on a journal button, you open a jquery modal dialog box with more information and the journal. All well and good. But I want audio to play when the dialog box is opened.
So far I have 11 dialog boxes and 11 separate audios for each respective one, but when the audio is set to 'autoplay' all the audios on the page start playing as soon as the page is loaded at once.
How can I make it so that the audio for each respective journal button only starts playing when the dialog box opening button is clicked?
Here's my code for one of the dialog boxes:
<div id="dialog-4" title="The brushwood platform"><p><span style=""><em>Kevin and Izzy worked on excavating the brushwood platform.</em></span></p>
<table width="688" height="390" align="center" class="dialog_form">
<tr>
<td width="320" height="189"><figure><img src="images/megaphone.png" width="250" height="320" border="0" alt="Illustration of Izzy and Kevin filler"/><figcaption>Illustration of Kevin and Izzy</figcaption></figure></td>
<th width="13"> </th>
<td width="631"><p>This is an area that had been created by laying down brushwood and then covering with worked timbers.</p></td>
</tr>
<tr>
<td height="142" style="text-align: center"><audio id="audio4" title="Spoken Journal" preload="auto" controls autoplay loop >
<source src="../Kizzy (brushwood, reed peat).mp3" type="audio/mpeg">
Your browser does not support the audio element. </audio>
</td>
<td> </td>
<td><p>The platform is on the lake edge and was likely used for stability on the boggy ground. Evidence of flint knapping has been found in and around the platform.</p></td>
</tr>
<tr>
<th height="251"><figure><img src="images/imgp2925-copy.jpg" width="300" height="190" alt="Brushwood"/><figcaption>Part of the brushwood platform excavated in 2015 at Star Carr.</figcaption></figure></th>
<th> </th>
</tr>
</div>
<button id="opener-4"></button>
</article>
var __adobewebfontsappname__="dreamweaver"
$(function() {
$( "#dialog-4" ).dialog({
autoOpen: false,
modal: true,
resizable: false,
draggable: false,
width: 950,
height: 600,
buttons: {
OK: function() {$(this).dialog("close");}
},
});
$( "#opener-4" ).click(function() {
$( "#dialog-4" ).dialog( "open" );
});
});

Related

Close all other jQueryUI tooltips when a new tooltip is opened

How can I close all other jQueryUI tooltips when a user opens a new tooltip. I want to avoid littering the UI with open tooltips.
I did not want to clutter up what I thought was a straightforward question but my tooltips are customized to only show when a user has clicked on a help icon or field name as in the example below. In addition as in the example, the help triggers are not in the [label] tag associated to that input and so the tooltip can't count on the field focus. I suspect that is the issue.
function loadCSS(filename) {
var file = document.createElement("link");
file.setAttribute("rel", "stylesheet");
file.setAttribute("type", "text/css");
file.setAttribute("href", filename);
document.head.appendChild(file);
}
loadCSS("https://code.jquery.com/ui/1.12.1/themes/start/jquery-ui.css");
// Disable HOVER tooltips for input elements since they are just annoying.
$("input[title]").tooltip({
disabled: true,
content: function() {
// Allows the tooltip text to be treated as raw HTML.
return $(this).prop('title');
},
close: function(event, ui) {
// Disable the Tooltip once closed to ensure it can only open via click.
$(this).tooltip('disable');
}
});
/* Manually Open the Tooltips */
$(".ui-field-help").click(function(e) {
var forId = e.target.getAttribute('for');
if (forId) {
var $forEl = $("#" + forId);
if ($forEl.length)
$forEl.tooltip('enable').tooltip('open');
}
});
.ui-field-help {
text-decoration: underline;
}
input {
width: 100%
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js" integrity="sha256-VazP97ZCwtekAsvgPBSUwPFKdrwD3unUfSGVYrahUqU=" crossorigin="anonymous"></script>
<table width=100%>
<tr>
<td for="A000" class="ui-field-help">First</td>
<td><input type="Text" id="A000" title="title #A000"></td>
</tr>
<tr>
<td for="B000" class="ui-field-help">Second</td>
<td><input type="Text" id="B000" title="title #B000"></td>
</tr>
<tr>
<td for="C000" class="ui-field-help">Third</td>
<td><input type="Text" id="C000" title="title #C000"></td>
</tr>
<tr>
<td for="D000" class="ui-field-help">Fourth</td>
<td><input type="Text" id="D000" title="title #D000"></td>
</tr>
<tr>
<td for="E000" class="ui-field-help">Fifth</td>
<td><input type="Text" id="E000" title="title #E000"></td>
</tr>
</table>
What I was asking for was unnecessary. If used correctly jQueryUI tooltips will automatically close themselves based on the focus/hover events.
If the tooltip is opened without triggering these events then there won't be any way for it to automatically close itself.
I had intentionally opened the tooltips via a click on a separate help icon. That click did not trigger the focus. By fixing my code to move the icon into the LABEL (for=) tied to the INPUT, it resulted in the INPUT receiving the focus which then gave the jQueryUI tooltip widget what it needed to manage the visibility.

jquery ui button creating trouble

<table class='dates'>
<form method='post' action='' name='admin' id='form_admin'>
<tr>
<td>Start Time Of Election</td>
<td>: <input type="text" id="stime" name='elect' placeholder='hh:mm' readonly="true"/></td>
</tr>
<tr>
<td>End Time Of Election</td>
<td>: <input type="text" id="etime" name='elect' placeholder='hh:mm' readonly="true" disabled='true'/></td>
</tr>
<tr>
<td align='right'>
<input id='enable' type='submit' name='date' value='Update' disabled='true'/>
</td>
<td align='right'>
<input type='submit' name='cancel' value='Cancel'/>
</td>
</tr>
</form>
</table>
<script type="text/javascript">
$(function(){
$('#stime').timepicker({
hourMin: 8,
hourMax: 10,
onSelect: function(){
$('#etime').prop('disabled', false);
$('#etime').timepicker({
hourMin: 16,
hourMax: 18,
onSelect: function(){
$('#enable').prop('disabled', false);
}
});
}
});
});
</script>
my code works fine with jQuery UI, datepicker and time picker and my update button gets enabled up on selecting end time. but when i use jQuery UI button to give a nice look to my buttons, with this code
$(function() {
$( "input[type=submit], button" )
.button()
.click(function( event ) {
});
});
though i get the styles but my update button never gets enabled.
Try with
$("#enable").button( "enable" );
See the jQuery doc here

Elements above JQuery accordion losing padding

I have a jquery dialog that contains a jquery accordion among other things. When I click the accordion headings to expand the different sections, the elements above the accordion lose their padding for the duration of the animation. The result is that these elements shift to the left for the duration of the animation. Below are the HTML/JS snippets in question.
Any thoughts?
HTML:
<div id="bodyDiv">
<!-- Dialog -->
<div id="patientPopup" title="Patient:" class="ui-widget">
<table style="width: 100%">
<tr>
<td class="AppointmentImage">
<img src="images/John-Petrucci-tn.jpg" alt="Patient Photo">
</td>
<td>
<b>Name:</b> Smith, Sally <b>DOB:</b> 02/15/1984 <br />
<b>SSN:</b> 999-99-9999 <b>Address:</b> 123 Main St Nashville, TN 37204
</td>
</tr>
<tr>
<td colspan="2" style="width: 100%">
<!--Accordion-->
<div id="patientSummary">
<h3>Encounters</h3>
<div>
<table class="PatientSummary">
<tr>
<th>12/03/2011</th>
<td>
Office visit - this is text for the office visit. some notes perhaps.
</td>
</tr>
<tr>
<th>10/16/2011</th>
<td>
GYN visit - this is text to fill some space.
</td>
</tr>
</table>
</div>
<h3>Alerts</h3>
<div>
<ul>
<li>Diabetic</li>
<li>Due for FluShot</li>
</ul>
</div>
<h3>Labs/Radiology</h3>
<div>
<table style="vertical-align: text-top;">
<tr>
<th>Date</th>
<th>Lab</th>
<th>Result</th>
</tr>
<tr>
<td>12/03/2011</td>
<td>Blood Panel</td>
<td>N</td>
</tr>
<tr>
<td>12/03/2011</td>
<td>Pregnancy Test</td>
<td>Y</td>
</tr>
<tr>
<td>12/03/2011</td>
<td>Blood Panel</td>
<td>N</td>
</tr>
<tr>
<td>12/03/2011</td>
<td>Pregnancy Test</td>
<td>Y</td>
</tr>
<tr>
<td>12/03/2011</td>
<td>Blood Panel</td>
<td>N</td>
</tr>
<tr>
<td>12/03/2011</td>
<td>Pregnancy Test</td>
<td>Y</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</div>
<button id="showPatient">Show Patient</button>
</div>
JavaScript:
$("#patientPopup").dialog({
autoOpen: false,
modal: true,
height: 530,
width: 600,
draggable: false,
resizable: false,
open: function () {
$("#patientSummary").accordion({
fillSpace: true,
autoHeight: true
});
}
});
$("#showPatient").button().click(
function () {
$("#patientPopup").dialog("open");
}
);
Any help would be appreciated. Thanks!
The solution was quite simple. I ended up putting the image and text in a completely separate table than the accordion.
Never determined exactly why the top elements were losing their padding though...

The link produced by a custom formatter only shows its text when moused over

I am using jqgrid grails plugin.
Column model for the column is:
{name:'id', index:'id', editable:true, align:'center', formatter:jobListLinkFormatter}
Custom formatter is:
function jobListLinkFormatter(cellvalue, options, rowObject){
var url = "${createLink(action:'jobListJSON')}" +"/"+cellvalue;
var link ="my link";
return link;
};
The link is produced correctly, however the text 'my link' only shows when moused over. What is the cause of this problem?
Add generate html: The text for the link only shows when mouse over on the row and 'ui-state-hover' is applied
<table id="configGrid" class="jqTable ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_configGrid" style="width: 1178px; ">
<tbody>
<tr class="jqgfirstrow" role="row" style="height:auto">
<td role="gridcell" style="height:0px;width:1178px;"></td>
</tr>
<tr id="4" role="row" class="ui-widget-content jqgrow ui-row-ltr">
<td role="gridcell" style="text-align:center;" title="my link" aria-describedby="configGrid_id">
my link
</td>
</tr>
</tbody>
</table>
try adding in your link
function jobListLinkFormatter(cellvalue, options, rowObject){
var url = "${createLink(action:'jobListJSON')}" +"/"+cellvalue;
var link ="<a href='" + url + "'"+" style='font-color:red' >my link</a>";
return link;
};
or class="ui-state-error-text"
if this will work that means that you have problems with css so in firebug inspect your link and see what styles are applied to this link and your font color is the same as background or font size is tiny or something like that.

jQuery UI datepicker causes screen to scroll to the top after selecting a date

I have a couple of jQuery datepickers inside a jQuery dialog. Whenever users select a date from the datepicker the screen scrolls to the top. This only happens in IE8 not the Firefox 3.6 or Chrome 5. Since the majority of users will user IE this is going to be very annoying. Can anyone give me a clue as to why this is happening?
Here is a snippet of the HTML for the dialog:
<div id="AppointmentDialog" style="display: none; font-size: 12px;">
<table>
<tr class="lesson notAvailable allDay">
<td>
Start
</td>
<td>
<input id="txtStartDate" type="text" readonly="readonly" style="width: 90px" class="lesson notAvailable allDay" />
<input id="txtStartTime" type="text" style="width: 50px" class="lesson notAvailable" />
<input id="hidStartTime" type="hidden" value="" />
</td>
</tr>
<tr class="notAvailable allDay">
<td>
End
</td>
<td>
<input id="txtEndDate" type="text" readonly="readonly" style="width: 90px" class="notAvailable allDay" />
<input id="txtEndTime" type="text" style="width: 50px" class="notAvailable" />
<input id="hidEndTime" type="hidden" value="" />
</td>
</tr>
</table>
</div>
Snippet of Javascript to initialise the dialog and datepickers:
$(document).ready(function() {
initDialogs();
});
function initDialogs() {
// Configure the New Appointment dialog
$("#AppointmentDialog").dialog({
autoOpen: false,
resizable: false,
width: 320,
modal: true,
title: 'Appointment',
buttons: {
"Close": function() { $(this).dialog("close"); },
"Save": function() {
// Function call
}
}
});
$.mask.definitions['h'] = '[012]';
$.mask.definitions['m'] = '[012345]';
$("#txtStartTime").mask("h9:m9");
$("#txtEndTime").mask("h9:m9");
// Init date pickers
$("#txtStartDate").datepicker({ dateFormat: 'dd-mm-yy' });
$("#txtEndDate").datepicker({ dateFormat: 'dd-mm-yy' });
};
EDIT
I'm using jQuery 1.4.2 and UI 1.8.2
I've looked into it again. The bug has been reported with a workaround.
I'm using a minified version of jQuery UI so the code looks like this:
(B?" ui-priority-secondary":"")+'" href="#">'+q.getDate()+"</a>")+"</td>"
(B?" ui-priority-secondary":"")+'" href="javascript:;">'+q.getDate()+"</a>")+"</td>"
I had this exact problem, but the real issue turned out to be duplicate ids on the page. Once I removed the duplicate id the problem went away completely.
I wasn't allowed to touch js libraries, I added this line under onSelect handler.
$('#ui-datepicker-div table td a').attr('href', 'javascript:;');
so my code looked like
$('#txtDate').datepicker({
// other properties
onSelect: function (selectedDate) {
$('#ui-datepicker-div table td a').attr('href', 'javascript:;');
// other code
}
});
You need to override the "$" placeholder with "jQuery" if the text contain "#"

Resources