Jump to content

Passing data-value= to js and using it.


ztimer
Go to solution Solved by 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
Share on other sites

  • Solution

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);
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.