Einzelnen Beitrag anzeigen
Alt 12.05.2008, 11:23   #1 (permalink)
Susanne81
PostRank: 1
 
Registriert seit: 27.03.2008
Beiträge: 42
php / js Frage

Hi.
Ist wohl das falsche Board, aber hier kann mir bestimmt jemand helfen.

Es gibt da dieses JS:

Code:
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
if(win.focus){win.focus();}}
function CloseNewWin(){if(win!=null && win.open)win.close()}
Der Code, um ein Popup zu öffnen sieht z.B. so aus:

Code:
<a href="test/test.jpg" onclick="NewWindow(this.href,'image','850','578','yes','center');return false" onfocus="this.blur()"  name="image" alt="image">test</a>
Funktioniert wunderbar.
Nun möchte ich das automatisiert auf alle Links anwenden, die auf ein Bild verweisen. Dazu habe ich mir ein Plugin geschnappt, welches eigentlich nur das rel="lightbox" Attribut hinzufügt und anstelle dessen versucht das
Code:
onclick="NewWindow(this.href,'image','850','578','yes','center');return false" onfocus="this.blur()"
einzusetzen.

so, z.B.

Code:
add_filter('the_content', 'addlightboxrel_replace');
function addlightboxrel_replace ($content)
{   global $post;
	$pattern = "/<a(.*?)href=('|\")([^>]*).(bmp|gif|jpeg|jpg|png)('|\")(.*?)>(.*?)<\/a>/i";
    $replacement = '<a$1href=$2$3.$4$5 onclick="NewWindow(this.href,image,850,578,yes,center);return false" onfocus="this.blur()" name="image" alt="image">$7</a>';
    $content = preg_replace($pattern, $replacement, $content);
    $content = str_replace("%LIGHTID%", $post->ID, $content);
    return $content;
}
Behalte ich die ' ' bei image, 850, usw drin gibt es einen php Error, nehme ich sie raus, so wie oben zu sehen, oder ersetze sie durch " " passiert leider nichts.

Wie mache ich das denn nun, meine Lieben?

Einen sonnigen Tag,
su*
Susanne81 ist offline   Mit Zitat antworten