Jump to content

Passing data-value= to js and using it.


ztimer

Recommended Posts

Hi.

 

I'm in the need of some help. Cant figure out what is wrong with the code. Getting undefined all the time.

The idea is to pass current playing video and user data to javascript using data-value="valuehere" and then let javascript to send the data to db with the current time and so on.

 

I had a working solution but wanted to use videojs player and now im stuck.

The code before was:

	(function(a){
		a(".history").on("click",function(){

			var b=a(this).data("mp4");
			var store_type=a(this).data("store_type");
			var store_title=a(this).data("store_title");
			var store_tmdbid=a(this).data("store_tmdbid");
			var subtitle=a(this).data("subtitle");
			var resume=a(this).data("resume");
			var user_id=a(this).data("user_id");
			var playpath=a(this).data("mp4")+a(this).data("resume");

			a(".yt-modal-box").append('<div class="modal fade" id="yt-modal"><div class="modal-dialog"><div class="modal-body flex-video widescreen"></div></div></div>');
			a("#yt-modal").modal();
			a("#yt-modal").find(".modal-body").html('<button type="button" class="modal-close" data-dismiss="modal" aria-hidden="true"></button><div id="video_container"><video width="100%" controls autoplay id="video"><source src="'+playpath+'" type="video/mp4"><track kind="subtitles" src="files/Movies/Subtitles/'+subtitle+'" srclang="et" />Your browser does not support the video tag.</video></div>');
			a(document).on("hide.bs.modal",function(){ clearInterval(refreshId); a(".modal-body").html("")})

			function updater(){
				$.post("modules/api/unfinished/update.php",{
					unban: "none",
					user_id: user_id,
					filename: b,
					store_type: store_type,
					store_title: store_title,
					store_tmdbid: store_tmdbid,
					lenght:	video.duration,
					position: video.currentTime,
				})
				.done(function(data){
			    if(data == 1){

						$.post("assets/api/unfinished/update.php",{
							unban: "unban", user_id: user_id, filename: b, lenght:	video.duration, position: video.currentTime,
						})

						function redirect(){
						   window.location = 'logout.php'
						}

						setTimeout(redirect, 2000);

			    }
			  });
			}

			var refreshId = setInterval(updater, 5000);

		})
	})(jQuery);

Now i have something like this:

 

<video id="example_video_1" class="video-js vjs-default-skin vjs-big-play-centered history" controls preload="auto" width="100%" height="389" data-resume="123" data-setup="{}" >
var myValue;

(function(a){
			
 a(".history").ready(function(){
  myValue=a(this).data("resume");
 })

 videojs("example_video_1").ready(function(){
			
  var myPlayer = this;
		  
  myPlayer.on("play", function(){
   alert(window.myValue);  // I would like to use the myValue under this.
  });
		  
  //myPlayer.play();
	
 });
	
})(jQuery);

If you have something then please help out. Thanks.

Link to comment
https://forums.phpfreaks.com/topic/290287-passing-data-value-to-js-and-using-it/
Share on other sites

Seems i have found a solution for my problem. Just for others to see if they have similar issue.

(function(){

	var X23ds2a = document.getElementById('video_info');

	videojs("video").ready(function(){

		var myPlayer = this;
	
		myPlayer.on("play", function(){

			var user_id = X23ds2a.getAttribute('data-user_id');
			alert("Text: " + user_id + " .");

		});

	});

})(jQuery);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.