Werte WP-Gemenide,
ich übertrage gerade eine alte Homepage auf Wordpress.
In der ehemaligen Webseite gab es eine Funktion, die das abspielen von Audios im selben Fenster mit onclick ermöglicht hat.
Der Code sah dazu folgendermaßen aus:
<a class="soundlink" href="/audios/L01_G1/L01_001.mp3" onclick="execSoundLink(this, '/audios/L01_G1/L01_001.mp3', false); return false" id="soundLink-0"><img style="width: 25px; height: 25px; border: none;" src="http://forum.wpde.org/images/alwpikto-3.png" alt=""></a>
Das ganze wurde dann mit folgender Funktion abgewickelt:
(function($) { $(function() {
var SoundController = function($_audioPlayer) {
this.$audioPlayer = $_audioPlayer;
this.playerEl = $_audioPlayer[0];
};
SoundController.prototype = {
selectFile : function(file) {
var mp3File = file.replace(/\.\w+$/, ".mp3");
var oggFile = file.replace(/\.\w+$/, ".ogg");
if (this.playerEl.canPlayType("audio/mpeg")) {
this.$audioPlayer.attr("src", mp3File);
} else {
this.$audioPlayer.attr("src", oggFile);
}
},
play : function() {
this.$audioPlayer.addClass('active');
this.playerEl.play();
},
pause : function() {
this.playerEl.pause();
},
stop : function() {
this.playerEl.pause();
this.playerEl.currentTime = 0;
},
getVolume : function() {
return this.playerEl.volume;
},
setVolume : function(vol) {
this.playerEl.volume = vol;
}
};
var $audioPlayer = $('#audio_player > audio');
var $hiddenAudio = $('<audio></audio>').appendTo( $('body') );
var soundController = new SoundController($audioPlayer);
var hiddenSoundController = new SoundController($hiddenAudio);
/** Play a file once. Don't use the visual player. */
soundController.playFileOnce = function(file) {
hiddenSoundController.selectFile(file);
hiddenSoundController.play();
};
window.soundController = soundController;
});
})(jQuery);
Alles anzeigen
Die obenstehende Funktion habe ich als audio.js Datei gespeichert und lade diese im head.
Leider lädt bei click auf das Image immer noch ein neues Fenster mit dem html5 player.
2. Problem, wenn ich im Editor auf visuellen Modus schalte, entfernt er die gesamte onclick Anweisung.
Hierfür habe ich folgenden code in meiner functions.php des Child-Themes eingefügt:
//Allow onclick within postsfunction allow_onclick_content() {
global $allowedposttags, $allowedtags;
$newattribute = "onclick";
$allowedposttags["a"][$newattribute] = true;
$allowedtags["a"][$newattribute] = true; //unnecessary?
}
add_action( 'init', 'allow_onclick_content' );
Alles anzeigen
Leider auch hier ohne den gewünschten Effekt.
Wer kann mir helfen, das Ganze richtig zu stellen.
Vielen Dank im Voraus
MfG
Robert