jQuery UI button url - jquery-ui

Im using a jQuery UI button and I want to point it to specific url.
How is that possible?
<button>Button</button>
<script>
$(function() {
$( "input[type=submit], button" )
.button()
.click(function( event ) {
event.preventDefault();
});
});
</script>

Html:
<button id="btYourButton">Button</button>
Javascript:
<script>
$(function() {
$( "#btYourButton" ).button().click(function( event ) {
window.location = "http://google.com"
});
});
</script>

Related

Basecamp3 Jquery ui datepicker not opening

function init() {
$('.message-composition__footer')
.prepend('<input type="text" id="datepicker_1" placeholder="Select date" class="input input--pilled event-form__date-input u-hide-focus" readonly>');
let dp = $( "#datepicker_1" );
console.log(dp);
$(dp).datepicker({
showOn: 'both',
onSelect: function (dateText, inst) {
schedule_date = dateText;
$( dp ).val(dateText);
console.log("schedule_date - " + schedule_date);
}
});
};
document.addEventListener('turbolinks:load', () => {
console.log('turbolinks:load');
init();
});
(function($) {
console.log('new-message script loaded');
init();
})(jQuery);
'turbolinks:load' event fires successfully but datepicker does not work.
if I reload the page then it works. I'm stuck here for 2 days now, please help.
Datepicker after reloading page
Datepicker without reloading page (when 'turbolinks:load' event fires)

How to use tilesloaded event for google maps v3

Here I have a code:
<script>
$(function() {
$( "#photo" ).resizable();
$( "#photo" ).draggable({revert: 'invalid'});
$( "#left" ).droppable({
accept: '#photo',
drop: function( event, ui ) {
$( this )
.find( "p" )
.html( "Dropped!" );
}
});
});
</script>
and this code I must run after full loading google maps, so I need to "hook up" tilesloaded event for this code.
http://jsbin.com/ayugun/7/edit
But how to do that?
Here is the code
google.maps.event.addListener(map, 'tilesloaded', function() {
doWhatYouWant();
});

JQuery Mobile Dynamic Button add Click

I have an infowindow in a google map like so,
var content = '<div id="link"><input type="button" value="Report this light" id="reportBtn"/></div>';
i am using jquery mobile to bind a 'click' event when the infowindow pops open on the map but it doens't fire, my code:
$(document).on('pageinit', function() {
$('#reportBtn').on('click', function() {
alert('it works');
});
});
You need to use event delegation. Try
$(document).on('pageinit', function() {
$(document).on('click', '#reportBtn', function() {
alert('it works');
});
});
Instead of document you can use nearest static element that is a parent to <div id="link">.
$('#nearestparent').on('click', '#reportBtn', function() {...});

Jqueryui dialog create conflicts with other scripts

I have such an issue, I am using few script like jquery carousel slider, jquery drop down menu but when I am trying to add jqueryui dialog all others scripts do not work. Here is my code:
Before I add JqueryUi dialog:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type='text/javascript' src='js/jquery.hoverIntent.minified.js'></script>
<script type='text/javascript' src='js/jquery.dcmegamenu.1.3.3.js'></script>
<script type='text/javascript' src='js/jquery.liquidcarousel.pack.js'></script>
<script>
$(document).ready(function(){
//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
//Caption Sliding (Partially Hidden to Visible)
$('.boxgrid.caption').hover(function(){
$(".cover", this).stop().animate({top:'40px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
});
$('.boxgrid2.caption').hover(function(){
$(".cover", this).stop().animate({top:'190px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'240px'},{queue:false,duration:160});
});
$('.boxgrid3.caption').hover(function(){
$(".cover", this).stop().animate({top:'40px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
});
});
</script>
<script>
jQuery(document).ready(function($) {
jQuery('#mega-menu-1').dcMegaMenu();
});
</script>
<script>
function show() {
if(document.getElementById('benefits').style.display=='none') {
document.getElementById('benefits').style.display='block';
}
return false;
}
function hide() {
if(document.getElementById('benefits').style.display=='block') {
document.getElementById('benefits').style.display='none';
}
return false;
}
</script>
<script type="text/javascript">
<!--
$(document).ready(function() {
$('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
});
-->
</script>
Code with JqueryUi dialog:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type='text/javascript' src='js/jquery.hoverIntent.minified.js'></script>
<script type='text/javascript' src='js/jquery.dcmegamenu.1.3.3.js'></script>
<script type='text/javascript' src='js/jquery.liquidcarousel.pack.js'></script>
<!--Dialog start-->
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;
$(function() {
$( "#dialog" ).dialog({
autoOpen: false,
show: "blind",
hide: "fade"
});
$( ".log-in" ).click(function() {
$( "#dialog" ).dialog( "open" );
return false;
});
});
</script>
<!--Dialog end-->
<script>
$(document).ready(function(){
//To switch directions up/down and left/right just place a "-" in front of the top/left attribute
//Caption Sliding (Partially Hidden to Visible)
$('.boxgrid.caption').hover(function(){
$(".cover", this).stop().animate({top:'40px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
});
$('.boxgrid2.caption').hover(function(){
$(".cover", this).stop().animate({top:'190px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'240px'},{queue:false,duration:160});
});
$('.boxgrid3.caption').hover(function(){
$(".cover", this).stop().animate({top:'40px'},{queue:false,duration:160});
}, function() {
$(".cover", this).stop().animate({top:'90px'},{queue:false,duration:160});
});
});
</script>
<script>
jQuery(document).ready(function($) {
jQuery('#mega-menu-1').dcMegaMenu();
});
</script>
<script>
function show() {
if(document.getElementById('benefits').style.display=='none') {
document.getElementById('benefits').style.display='block';
}
return false;
}
function hide() {
if(document.getElementById('benefits').style.display=='block') {
document.getElementById('benefits').style.display='none';
}
return false;
}
</script>
<script type="text/javascript">
<!--
$(document).ready(function() {
$('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
});
-->
</script>
One more very strange thing for me is that when I add JqueryUi dialog script after all script (to the end of this code) it doesn't work at all.
Any ideas why?
I have used noConflict();
add to script $jQ = jQuery.noConflict(); then change all $ -> $jQ
<script>
$jQ = jQuery.noConflict();
$jQ .fx.speeds._default = 1000;
$jQ (function() {
$jQ ( "#dialog" ).dialog({
autoOpen: false,
show: "blind",
hide: "fade"
});
$jQ ( ".log-in" ).click(function() {
$jQ ( "#dialog" ).dialog( "open" );
return false;
});
});
</script>

Trouble disabling jQuery UI tab

The API says you can't disable the active tab which I think is the crux of my problem.
I have six tabs in one UI Tab. One of the tabs is sometimes empty after an ajax call to fill all the tabs with data based on a user's click of a new UI Accordion selection. I use the "zero" tab as the default selected tab whenever the user makes a new selection.
I use the following to code in the php file that loads the sometimes empty tab to disable the tab when it's empty. It works fine unless the user has this tab selected when clicking a new UI Accordion selection. In only that case, the empty tab will remain enabled.
?>
<script type="text/javascript">
$(document).ready(function() {
$( "#tabs" ).tabs( "option", "disabled", false);
});
</script>
<?php
}else{
?>
<script type="text/javascript">
$(document).ready(function() {
$( "#tabs" ).tabs( "option", "disabled", [2]);
});
</script>
Can someone suggest a stragegy?
Here is the script containing the ajax calls:
<script type="text/javascript">
$('.stallion').live('click', function(){
var id = parseInt(this.id); // Get stallion_ID from clicked "a" tag id.
activestallion(id); // Function to indicate clicked Stallion in Stallion Accordion
// Start loading Overview Tab
var request = $.ajax({
url: "stalliondetails.php",
type: "GET",
data: {stallion_ID : id}
});
request.done( function(html){
$("#tabs-1").html(html);
$( "#tabs" ).tabs( "option", "selected", 0 );
$(".activehorse").fadeOut('1000', function(){
document.getElementById("activehorsename").innerHTML
=document.getElementById(id).innerHTML;
$(".activehorse").fadeIn('1000');
});
$("#tabs").tabs( "select" , 0 );
});
// Overview Tab load finished.
//Pedigree Tab load starting.
var request = $.ajax({
url: "pedigreedetails.php",
type: "GET",
data: {stallion_ID : id},
success: function(html){
$("#tabs-2").html(html);
}
});
//Pedigree Tab load finished.
//Progeny Tab load starting.
var request = $.ajax({
url: "progenydetails.php",
type: "GET",
data: {stallion_ID : id},
success: function(html){
$("#tabs-3").html(html);
}
});
//Progeny Tab load finished.
//News Tab load starting.
var request = $.ajax({
url: "newsdetails.php",
type: "GET",
data: {stallion_ID : id},
success: function(html){
$("#tabs-4").html(html);
}
});
//News Tab load finished.
//Race Record Tab load starting.
var request = $.ajax({
url: "racerecorddetails.php",
type: "GET",
data: {stallion_ID : id},
success: function(html){
$("#tabs-5").html(html);
}
});
//Race Record Tab load finished.
//Analysis Tab load starting.
var request = $.ajax({
url: "analysisdetails.php",
type: "GET",
data: {stallion_ID : id},
success: function(html){
$("#tabs-6").html(html);
}
});
//Analysis Tab load finished.
//Update the Seasons Request form to this Stallion.
updateseasons(id);
$( "#tabs" ).tabs( "option", "selected", 0 );
$("button").button() ;
});
</script>
Thanks for any help.
To help others following this thread I wanted to post what ended up fixing this problem.
I was using
$("#tabs").tabs("option", "disabled", [2]);
When I switched to
$("#tabs").tabs("disable", 2);
The problem was corrected.
Thanks for your help Bart and William.
Try
<script type="text/javascript">
$(document).ready(function() {
$( "#tabs" ).tabs( "option", "disabled", 2);
});
</script>
or multi-disable
<script type="text/javascript">
$(document).ready(function() {
$( "#tabs" ).tabs('option','disabled', [1, 2, 3, 4]);
});
</script>
instead of
<script type="text/javascript">
$(document).ready(function() {
$( "#tabs" ).tabs( "option", "disabled", [2]);
});
</script>
to enable tab and move to use
$( "#tabs" ).tabs( "enable" , 1 )
$( "#tabs" ).tabs( "select" , 1 )
*counting starts from 0

Resources