Popup window with information on mouse over hyperlink - php

I want to display contact info with the link to contact us page on mouse over hyperlink just like stackoverflow (mouse over user name) and gmail (click over user name). The below is what the latest updated code looks like.
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/start/jquery-ui.css" />
<script>
$('#open').mouseenter(function() {
$('#dialog_content').dialog('open');
});
$('#dialog_content').mouseleave(function() {
$('#dialog_content').dialog('close');
});
var posX = $('#open').offset().left;
var posY = $('#open').offset().top;
console.log(posX,posY);
$('#dialog_content').dialog({
autoOpen: false,
open: function() {
closedialog = 1;
$(document).bind('click', overlayclickclose);
},
focus: function() {
closedialog = 0;
},
close: function() {
$(document).unbind('click');
},
buttons: {
/*
Ok: function() {
$(this).dialog('close');
}
*/
},
show: {
effect: 'fade',
duration: 800
},
hide: {
effect: 'fade',
duration: 800
},
position: [posX,posY+25],
resizable: false
});
</script>
<style>
.ui-dialog-titlebar {display:none;}
#other_content {width:200px; height:200px;background-color:grey;}
#dialog_content{display:none;}
</style>
<div id="dialog_content">bla bla bla</div>
<div id="open">CONTACT US</div>
The error that i get
Uncaught TypeError: Cannot read property 'left' of undefined

Check this option:
jsfiddle.net/3mxGM/4/
It creates a jQuery modal window with the info inside the div with id dialog_content. You might want dynamic content inside that div from your database or something. Anyway this should work for what you want.
html:
<div id="dialog_content">
Here you can write the info to show up in the modal window.<br /><br />
If you know what AJAX is, could be a good idea to use it to query your database and get the info from there.</div>
Open dialog
jQuery:
$(document).ready(function(){
$('#open').mouseenter(function() {
$('#dialog_content').dialog('open');
});
$('#dialog_content').mouseleave(function() {
$('#dialog_content').dialog('close');
});
var posX = $('#open').offset().left;
var posY = $('#open').offset().top;
$('#dialog_content').dialog({
autoOpen: false,
focus: function() {
closedialog = 0;
},
close: function() {
$(document).unbind('click');
},
buttons: {
/*
Ok: function() {
$(this).dialog('close');
}
*/
},
show: {
effect: 'fade',
duration: 800
},
hide: {
effect: 'fade',
duration: 800
},
position: [posX,posY+25],
resizable: false
});
});
css:
.ui-dialog-titlebar {display:none;}

If you're looking for a much more code-simple popup tooltip, I am enjoying a customized version of this:
http://devseo.co.uk/examples/pure-css-tooltips/#
If this is too fancy for you it was just some css3 transitions on top of this more basic version, explained well here:
http://sixrevisions.com/css/css-only-tooltips/

Related

using the $.post with php&jquery

Ok, Im trying to make a draggable CMS system, now Im stuck on the next problem.
When Im done dragging my 'div' I want to save my new left and top (x and y) variables in my MySQL database using PhP.
I get my left and top variables by the next line of codes:
$(function() {
$( "#3" ).draggable({
stop: function () {
$.post("upload.php", {
left: this.getBoundingClientRect().left,
top: this.getBoundingClientRect().top
})
},
containment: "#containment-wrapper",
scroll: false
});
my upload.php is:
<?
mysql_query("UPDATE nvt SET left='". $_POST['left'] ."'")or die(mysql_error());
mysql_query("UPDATE nvt SET top='". $_POST['top'] ."'")or die(mysql_error());
header("Location: inlogged");
?>
When I'm done dragging my div there is just no reaction?
I think you are missing }); at the end. The code should be :
$(function() {
$( "#3" ).draggable({
stop: function ( event, ui ) {
$.post("upload.php", {
left: parseInt( ui.offset.left ),
top: parseInt( ui.offset.top )
})
},
containment: "#containment-wrapper",
scroll: false
});
}); //see the change

jquery: passing parameter to modal

I have the following in a table, repeated for each row:
<a <?php echo 'id="'.$id.'"'; ?> class="custom-dialog-btn btn btn-small">
<i class="icon-trash"></i>
</a>
where id is different for each line, because it is taken from a table in database where it is the primary key.
Then, I used th following jQuery code:
$(".custom-dialog-btn").bind("click", function (event) {
$("#mws-jui-dialog").dialog("option", {
modal: false
}).dialog("open");
event.preventDefault();
});
$("#mws-jui-dialog").dialog({
autoOpen: false,
title: "Alert",
modal: true,
width: "640",
buttons: [{
text: "NO",
id: "cancel_button",
click: function () {
$(this).dialog("close");
}
},
{
text: "OK",
id: "confirm_button",
click: function () {
myremovefuntion(id); // I need the id
}}
]
});
that refers to the dialog:
<div id="mws-jui-dialog">
<div class="mws-dialog-inner">
<h2>Are you sure you want to delete?</h2>
</div>
</div>
How can I pass the id to the modal?
You can append a data attribute to your dialog div as follows;
$('a').click(function (e) {
e.preventDefault();
$("#your_dialog").data('mycustomdata', $(this).prop('id')).dialog('open');
});
And retreive it like this
$("#your_dialog").dialog({
autoOpen: false,
resizable: false,
height:200,
modal: true,
buttons: {
Cancel: function() {
$(this).dialog('close');
},
'Delete': function() {
$(this).dialog('close');
var mydata = $(this).data('mycustomdata'); // = gives you the id of anchor element
// some delete logic
}
}
});
While Emin's answer certainly works, I wonder if this fabuolus jQuery UI library perhaps has a dialogue flavour analogue to JavaScript's native confirm() method? Or perhaps a possibility to pass in callback functions? This would remove the need from the dialogue code containing business logic.
Use the following code to get the id:
var id = $(this).prop("id");
And you will get the id of that which element you have clicked.

using the form action in jquery to go to php

How can I use the action in html form so I can send all the data form my form
I tried $("#formupload").attr('action') seems not working
Here is my code:
$(".clickupload").click(function () {
$("#dialog-form").dialog("open");
});
$("#dialog-form").dialog({
autoOpen: false,
closeOnEscape: true,
title: "Upload Picture",
width: 400,
height: 300,
modal: true,
buttons: {
Cancel: function () {
$(this).dialog("close");
},
Upload: function () {
$(document).ready(function () {
$("#formupload").attr('action');
});
}
}
});
<div id="dialog-form">
<form id="formupload" action="ProfileImages/FileUpload.php" method="POST" enctype="multipart/form-data">
<input type="file" name="uploadProfilePicture"/>
</form>
</div>
You mean eventually $("#formupload").sumbit();? What you're doing is reading the attribute and then doing nothing with it?
Try simply $("#formupload").submit()
What bweobi said, and eventually put all the jQuery initialisation stuff on document ready to make sure the document is all initialised before you add event handlers to its elements :
(function($) { // Allows you to create variables locally so
// there are no conflict with other stuffs.
$(document).ready(function() {
// You can name jQuery variables with a dollar so you can easily make
// the difference betwen jQuery and non-jquery objects.
$dialogForm = $('#dialog-form'); // Half queries, double speed.
$(".clickupload").click(function () {
$dialogForm.dialog("open");
});
$dialogForm..dialog({
autoOpen: false,
closeOnEscape: true,
title: "Upload Picture",
width: 400,
height: 300,
modal: true,
buttons: {
Cancel: function () {
$(this).dialog("close");
},
Upload: function () {
$("#formupload").submit();
}
}
});
});
})(jQuery); // Alows you not to use $ in global scope in case
// you use multiple libraries that use the $.

jquery styling content in dynamic element

I am using the jquery plugin flexslider to display some images and captions. I am using the code below to take captions out of the flexslider content and place into an outside element.
The captions are styled using spans but when they are placed into the new element called ".captions" they are not styled and all text is running together.
How can I apply styling and formatting to the text in the ".captions" div?
<script type="text/javascript" charset="utf-8">
$(window).load(function() {
$captions = $('.captions');
$('.flexslider').flexslider({
animation: "fade",
controlNav: "thumbnails",
directionNav: true,
slideshow: false,
useCSS: true,
touch: true,
start: function() {
$activecaption = $('.flex-active-slide .flex-caption');
$captions.html($activecaption.text());
},
after: function() {
$activecaption = $('.flex-active-slide .flex-caption');
$captions.html($activecaption.text());
}
});
});
</script>
For example I am echoing out this:
echo "<span class='artwork-title'>$page->title</span>,<span class='artwork-year'> $artwork->date</span><span class='artwork-year'>$artwork->dimensions</span>";
and my jquery seems to be getting rid of the span tags.
After rereading the question, it seems like you need the active caption in the .captions element. All you have to do is switch .text() to .html() and all of the elements should come with it.
$(window).load(function() {
$captions = $('.captions');
$('.flexslider').flexslider({
animation: "fade",
controlNav: "thumbnails",
directionNav: true,
slideshow: false,
useCSS: true,
touch: true,
start: function() {
$activecaption = $('.flex-active-slide .flex-caption');
$captions.html($activecaption.html());
},
after: function() {
$activecaption = $('.flex-active-slide .flex-caption');
$captions.html($activecaption.html());
}
});
});
Reference: http://www.woothemes.com/flexslider/
You can apply a css class with the .addClass
<style>
.capStyle
{
color: red;
}
</style>
$(".captions").addClass("capStyle");

Can't open more than once jquery dialog

i have a jquery dialog, which in i have:
$(document).ready(function() {
if( window.location.href.indexOf( '#product' ) != -1 ) {
var productID = window.location.href.split('-');
showDialog(productID[1]);
}
});
function showDialog(productID)
{
$( "#dialog-modal_"+productID ).html( "<iframe src='index.php?act=showProduct&id="+productID+"' width='100%' height='100%' frameborder='0' scrolling='no'></iframe>" );
$( "#dialog-modal_"+productID ).dialog({
width: 790,
height: 590,
modal: true,
open: function(event, ui)
{
}
});
}
it works fine when i open it, but if i close that window and try to re-open it - it does not responding.
thanks!!
Below is a sample of how jQuery UI Dialog code should appear. Remember, you need a way to open the dialog. So create a function that calls showDialog on that modal again. A button, or link would work.
jQuery UI Code
function showDialog(productID)
{
var container = $('#dialog-modal_'+productID).html('<blah blah>');
container.dialog({
autoOpen: false,
modal: true,
width: 790,
height: 590
});
container
.dialog('option', 'title', 'Your Title')
.dialog('option', 'buttons', {
Close: function() {
$(this).dialog('close');
}
})
.dialog('open');
//do open event work here
}
DOM for a Open Button
Open My Modal
jQuery for Open Button
$('a#open').click(function(e) {
e.preventDefault();
showDialog(<your id>);
});

Categories