Help with pregreplace and uniqid for jquery dialog boxes
First of all, do not be overwhelmed by the long code, I just put it for reference...I have a function that runs preg_replace on each comment users post and puts matches in a jquery dialog box with a matching open-link. For example, if there is a paragraph with two matches, they will be put inside two divs, and a jquery dialog function will be echoed twice; one for each div.
While this works for one match, if there are multiple matches, it does not. I am not sure how to distribute unique ids at a point in time for each of the divs and matching dialog open-scripts. Keep in mind, I removed the preg replace function since it kind of complicates the problem. If anyone has any ideas, they will be greatly appreciated.<?php
$id=uniqid();
$id2=uniqid();
echo "<div id=\"$id2\">
</div>";
?>
$.ui.dialog.defaults.bgiframe = true;
$(function() {
$("<?php echo"#$id2"; ?>").dialog({hide: 'clip', modal: true
,width: 600,height: 350,position: 'center',
show: 'clip',stack: true,title: 'title', minHeight: 25,
minWidth: 100, autoOpen: false});
$('<?php echo"#$id"; ?>').click(function() {
$('<?php echo"#$id2"; ?>').dialog('open');
})
.hover(
function(){
$(this).addClass("ui-state-hover");
},
f开发者_StackOverflow社区unction(){
$(this).removeClass("ui-state-hover");
}
).mousedown(function(){
$(this).addClass("ui-state-active");
})
.mouseup(function(){
$(this).removeClass("ui-state-active");
});
});
Have you tried something like and only displaying the function once.
<?php
echo "<div class="dialog"></div>";
?>
$(document).onload(function() {
$.ui.dialog.defaults.bgiframe = true;
$(function() {
$(".dialog").dialog({ /* ... */
EDIT (again)
Some Text
<a href="" class="open">Open Dialog 1<span class="box">Dialog Content 1</span></a> -
<a href="" class="open">Open Dialog 2<span class="box">Dialog Content 2</span></a> -
<a href="" class="open">Open Dialog 3<span class="box">Dialog Content 3</span></a>
ABC 123
$(".dialog").dialog({
hide: "clip",
modal: false,
width: 600,
height: 350,
position: "center",
show: "clip",
stack: true,
title: "title",
minHeight: 25,
minWidth: 100,
autoOpen: false,
bgiframe: true
});
$("a.open").click(function() {
$(".box").eq($(this).index()).dialog("open");
return false;
});
Tested and works. The problem was that when JQuery replaces the dialog it does not so in the same position. Checking which index the click is from will match up to the dialog box you are trying to opening.
Is it possible to preg replace unique variables into a string?
精彩评论