1var ytp = new function() { 2 3 /* Default Configuration Settings */ 4 this.config = new function() { 5 6 /* Path to YTP-Directory */ 7 this.ytp_path = "/ytp"; 8 9 /* API-Key */ 10 this.api_key = false; 11 12 /* AJAX */ 13 this.ajax = false; 14 15 /* Statistics */ 16 this.statistics = false; 17 18 /* Add Player to all embedded Youtube-Iframes */ 19 this.iframes = false; 20 21 /* Player-Type */ 22 this.mode = { 23 flat: { 24 intro: true, 25 play: true, 26 pause: true, 27 time: true, 28 timeline: true, 29 volume: true, 30 loop: false, 31 share: true, 32 comments: true, 33 related: false, 34 search: false, 35 youtube_popup: false, 36 youtube_popout: false, 37 speed: false, 38 info: false, 39 playlist_shuffle: false 40 }, 41 ultimate: { 42 intro: true, 43 play: true, 44 pause: true, 45 time: true, 46 timeline: true, 47 volume: true, 48 loop: true, 49 share: true, 50 comments: true, 51 related: true, 52 search: true, 53 youtube_popup: true, 54 youtube_popout: true, 55 speed: true, 56 info: true, 57 playlist_shuffle: true 58 } 59 }; 60 61 /* Layout */ 62 this.layout = "default"; 63 64 /* Skin */ 65 this.skin = "default"; 66 67 /* Intro */ 68 this.intro = true; 69 70 /* Play */ 71 this.play = true; 72 73 /* Autoplay */ 74 this.autoplay = false; 75 76 /* Pause */ 77 this.pause = true; 78 79 /* Time */ 80 this.time = true; 81 82 /* Timeline */ 83 this.timeline = true; 84 85 /* Volume */ 86 this.volume = true; 87 88 /* Loop */ 89 this.loop = false; 90 91 /* Share */ 92 this.share = false; 93 94 /* Share on Website */ 95 this.share_website = false; 96 97 /* Comments */ 98 this.comments = false; 99 100 /* More Comments */ 101 this.comments_more = false; 102 103 /* Related Videos */ 104 this.related = false; 105 106 /* Load more related Videos */ 107 this.related_more = false; 108 109 /* 2x Playrate */ 110 this.speed = false; 111 112 /* Youtube-Popup */ 113 this.youtube_popup = false; 114 115 /* Youtube-Popout */ 116 this.youtube_popout = false; 117 118 /* Youtube-Logo */ 119 this.youtube_logo = true; 120 121 /* Playlist */ 122 this.playlist_list = true; 123 124 /* Playlist Videos */ 125 this.playlist_videos = true; 126 127 /* Playlist: Next Video */ 128 this.playlist_next = true; 129 130 /* Playlist: Previous Video */ 131 this.playlist_previous = true; 132 133 /* Playlist: Shuffle */ 134 this.playlist_shuffle = true; 135 136 /* Playlist: More Videos */ 137 this.playlist_more = true; 138 139 /* Info */ 140 this.info = false; 141 142 /* Language */ 143 this.language = false; 144 145 /* Advertisement */ 146 this.advertisement = false; 147 148 /* ID of Ad-Content (global) */ 149 this.ad_id = false; 150 151 /* ID of Ad-Intro-Content */ 152 this.ad_intro_id = false; 153 154 /* ID of Ad-Pause-Content */ 155 this.ad_pause_id = false; 156 157 /* ID of Ad-End-Content */ 158 this.ad_end_id = false; 159 160 /* ID of Ad-Bottom-Content */ 161 this.ad_bottom_id = false; 162 163 /* File-Path to Ad-Content (global) */ 164 this.ad_file = false; 165 166 /* File-Path to Ad-Intro-Content */ 167 this.ad_intro_file = false; 168 169 /* File-Path to Ad-Pause-Content */ 170 this.ad_pause_file = false; 171 172 /* File-Path to Ad-End-Content */ 173 this.ad_end_file = false; 174 175 /* File-Path to Ad-Bottom-Content */ 176 this.ad_bottom_file = false; 177 178 /* Area(s) where Ad is displayed */ 179 this.ad_area = false; 180 181 /* Ad Intro Timer */ 182 this.ad_intro_timer = 20; 183 184 /* Ad End Timer */ 185 this.ad_end_timer = 5; 186 187 /* Ad Pause Timer */ 188 this.ad_pause_timer = 0; 189 190 /* Play Time */ 191 this.play_time = 10; 192 193 /* Text */ 194 this.text = { 195 play: "Play", 196 pause: "Pause", 197 volume: "Volume", 198 loop: "Loop", 199 share: "Share", 200 share_facebook: "Facebook", 201 share_twitter: "Twitter", 202 share_linkedin: "LinkedIn", 203 share_tumblr: "Tumblr", 204 share_google: "Google", 205 share_email: "Email", 206 share_reddit: "Reddit", 207 share_whatsapp: "WhatsApp", 208 comments: "Comments", 209 comments_more: "More Comments", 210 related: "Related Videos", 211 related_more: "More Videos", 212 speed: "Play faster", 213 youtube: "Watch on YouTube", 214 popup: "Pop-Out", 215 search: "Search", 216 search_more: "More Videos", 217 info: "Info", 218 fullscreen: "Fullscreen", 219 smallscreen: "Back to normal", 220 next: "Next Video", 221 previous: "Previous Video", 222 list: "Toggle Playlist", 223 shuffle: "Shuffle Playlist", 224 playlist_more: "More Videos", 225 close: "Close", 226 ad_close: "Close Ad", 227 ad_close_seconds: "Seconds", 228 ad_close_wait_seconds: "Wait", 229 statistic_views: "Views", 230 statistic_likes: "Likes", 231 statistic_dislikes: "Dislikes", 232 statistic_comments: "Comments", 233 info_channel: "Channel" 234 }; 235
236 /* Search */ 237 this.search = false; 238 239 /* Search: More Videos */ 240 this.search_more = false; 241 242 /* Fullscreen */ 243 this.fullscreen = true; 244 245 /* Hide Controls (when Video is playing) */ 246 this.hide = true; 247 248 /* Youtube Player Config */ 249 this.youtube_controls = 0; 250 this.youtube_fs = 0; 251 this.youtube_autohide = 1; 252 this.youtube_related = 0; 253 this.youtube_showinfo = 0; 254 this.youtube_modestbranding = 1; 255 256 /* Config for Player-Element */ 257 this.element = function(element) { 258 259 /* Player-Element */ 260 window["ytp-element"] = {}; 261 262 $.each(ytp.config,function(key,value) { 263 window["ytp-element"][key] = (typeof($(element).data(key))!==typeof(ytp_undefined)) ? $(element).data(key) : window["ytp"]["config"][key]; 264 }); 265 266 /* Text */ 267 window["ytp-element"]["text"] = ytp.config.text; 268 if(window["ytp-element"]["language"]!==ytp.config.language) { 269 if(ytp.config.ajax==true) { 270 $.each(ytp_config.text,function(index,value) { 271 if(index==window["ytp-element"]["language"]) { 272 window["ytp-element"]["text"] = value; 273 } 274 }); 275 } else { 276 // Language can't be loaded if there is no AJAX-Connection 277 } 278 } 279 280 return window["ytp-element"]; 281 282 } 283 284 } 285 286 /* Default Events Settings */ 287 this.events = new function() { 288 289 /* When Player is loaded */ 290 this.onReady = false; 291 292 /* When Play-Button is triggered */ 293 this.onPlay = false; 294 295 /* When Pause-Button is triggered */ 296 this.onPause = false; 297 298 /* When Video ends */ 299 this.onEnd = false; 300 301 /* Events for Player-Element */ 302 this.element = function(element) { 303 304 /* onReady */ 305 var onReady = (typeof($(element).data("onready"))!==typeof(ytp_undefined)) ? $(element).data("onready") : ytp.events.onReady; 306 307 /* onPlay */ 308 var onPlay = (typeof($(element).data("onplay"))!==typeof(ytp_undefined)) ? $(element).data("onplay") : ytp.events.onPlay; 309 310 /* onPause */ 311 var onPause = (typeof($(element).data("onpause"))!==typeof(ytp_undefined)) ? $(element).data("onpause") : ytp.events.onPause; 312 313 /* onEnd */ 314 var onEnd = (typeof($(element).data("onend"))!==typeof(ytp_undefined)) ? $(element).data("onend") : ytp.events.onEnd; 315 316 return { 317 onReady: onReady, 318 onPlay: onPlay, 319 onPause: onPause, 320 onEnd: onEnd 321 } 322 } 323 324 } 325 326 /* Initial Setup */ 327 this.init = function(attributes) { 328 329 attributes = (typeof(attributes)!==typeof(ytp_undefined)) ? attributes : false; 330 331 window["ytp_initiated"] = true; 332 333 window["ytp_attributes"] = attributes; 334 335 /* Look for Config */ 336 if(typeof(window["ytp_attributes"].config)!==typeof(ytp_undefined)) { 337 338 /* Look for Mode */ 339 if(typeof(window["ytp_attributes"].config.mode)!==typeof(ytp_undefined)) { 340 341 /* Setup Attributes */ 342 $.each(window["ytp"]["config"]["mode"][window["ytp_attributes"].config.mode],function(key,value) { 343 window["ytp_attributes"]["config"][key] = value; 344 }); 345 346 } 347 348 /* Check for Attributes */ 349 $.each(ytp.config,function(key,value) { 350 if(typeof(window["ytp_attributes"]["config"][key])!==typeof(ytp_undefined)) window["ytp"]["config"][key] = window["ytp_attributes"]["config"][key]; 351 }); 352 353 } 354 355 /* Include Styles and Scripts */ 356 $("<link />",{ 357 rel: "stylesheet", 358 type: "text/css", 359 href: ytp.config.ytp_path+"/assets/css/ytp.css" 360 }).appendTo("head"); 361 362 $.getScript(ytp.config.ytp_path+"/assets/js/vendor/jquery.jscrollpane.min.js"); 363 $.getScript(ytp.config.ytp_path+"/assets/js/vendor/jquery.mousewheel.js"); 364 365 366 /* Look for Events */ 367 if(typeof(window["ytp_attributes"].events)!==typeof(ytp_undefined)) { 368 369 /* onReady */ 370 if(typeof(window["ytp_attributes"].events.onReady)!==typeof(ytp_undefined)) ytp.events.onReady = window["ytp_attributes"].events.onReady; 371 372 /* onPlay */ 373 if(typeof(window["ytp_attributes"].events.onPlay)!==typeof(ytp_undefined)) ytp.events.onPlay = window["ytp_attributes"].events.onPlay; 374 375 /* onPause */ 376 if(typeof(window["ytp_attributes"].events.onPause)!==typeof(ytp_undefined)) ytp.events.onPause = window["ytp_attributes"].events.onPause; 377 378 /* onEnd */ 379 if(typeof(window["ytp_attributes"].events.onEnd)!==typeof(ytp_undefined)) ytp.events.onEnd = window["ytp_attributes"].events.onEnd; 380 381 } 382 383 /* Check for AJAX-Connection */ 384 if(ytp.config.ajax==true) { 385 $.ajax({ 386 method: "POST", 387 url: ytp.config.ytp_path+"/php/ajax.php", 388 data: { method: "config" } 389 }) 390 .done(function(response) { 391 /* HTML-Error-Page */ 392 if(response[0]=="<") { 393 /* AJAX Connection did not work */ 394 ytp.config.ajax = false;
395 } 396 /* Response */ 397 else { 398 ytp_config = JSON.parse(response); 399 if(typeof(ytp_config.ajax[0])===typeof(ytp_undefined)) { 400 /* AJAX Connection did not work */ 401 ytp.config.ajax = false; 402 } else { 403 if(ytp_config.ajax[0]==false) { 404 ytp.config.ajax = false; 405 } 406 /* Default Language */ 407 if(ytp.config.language==false) { 408 ytp.config.language = "en"; 409 } 410 /* Config Settings */ 411 ytp.config.language = (ytp_config.language[0]=="true") ? true : false; 412 ytp.config.advertisement = (ytp_config.advertisement[0]=="true") ? true : false; 413 ytp.config.statistics = (ytp_config.statistics[0]=="true") ? true : false; 414 /* Setup Text Config */ 415 $.each(ytp_config.text,function(index,value) { 416 if(index==ytp.config.language) { 417 ytp.config.text = value; 418 } 419 }); 420 } 421 } 422 /* Setup Youtube API */ 423 ytp.youtube_api(); 424 }) 425 .fail(function() { 426 /* AJAX Connection did not work */ 427 ytp.config.ajax = false; 428 /* Setup Youtube API */ 429 ytp.youtube_api(); 430 }); 431 } else { 432 /* Setup Youtube API */ 433 ytp.youtube_api(); 434 } 435 436 /* On Window Resize */ 437 $(window).resize(function() { 438 $.each($(".ytp"),function() { 439 ytp.resize(this); 440 }); 441 }); 442 443 delete window["ytp_attributes"]; 444 445 } 446 447 /* Resize Player */ 448 this.resize = function(player) { 449 450 /* Remove Playlist if to small */ 451 if($(player).innerWidth()<400) { 452 if($(player).find(".ytp-list").hasClass("ytp-active")) { 453 if(!$(player).hasClass("ytp-layout-full")) { 454 $(player).find(".ytp-list").trigger("click"); 455 } 456 } 457 $(player).addClass("ytp-small-version"); 458 } else { 459 $(player).removeClass("ytp-small-version"); 460 } 461 462 /* Set Timeline */ 463 $(player).find(".ytp-timeline").css("bottom",$(player).find(".ytp-controls").innerHeight()+"px").removeClass("ytp-no-opacity"); 464 465 /* Play-Button */ 466 $(player).find(".ytp-play-button").css("margin-top","-"+$(player).find(".ytp-controls").innerHeight()+"px"); 467 468 /* Set Share */ 469 $(player).find(".ytp-share-wrap").css("bottom",($(player).find(".ytp-controls").innerHeight()+15)+"px"); 470 471 /* Set Wraps (Comments, Search, ...) */ 472 var wraps = new Array("info","search","related","comments"); 473 $.each(wraps,function() { 474 $(player).find(".ytp-"+this+"-wrap").css("bottom",($(player).find(".ytp-controls").innerHeight())+"px"); 475 }); 476 477 /* Reset Scrollbar */ 478 if(typeof(window["ytp_pane_"+$(player).data("element")])!=typeof(ytp_undefined)) { 479 window["ytp_pane_"+$(player).data("element")].reinitialise(); 480 } 481 482 /* Set Logo */ 483 $(player).find(".ytp-youtube-logo").css("bottom",($(player).find(".ytp-controls").innerHeight()+15)+"px").removeClass("ytp-no-opacity"); 484 485 } 486 487 /* Setup Youtube API */ 488 this.youtube_api = function() { 489 var tag = document.createElement('script'); 490 tag.src = "https://www.youtube.com/iframe_api"; 491 var firstScriptTag = document.getElementsByTagName('script')[0]; 492 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 493 } 494 495 /* Look for YTP-Elements */ 496 this.ready = function() { 497 498 /* Check for embedded Iframes */ 499 if(ytp.config.iframes==true) { 500 501 /* Loop through Iframes */ 502 $("iframe").each(function() { 503 504 /* Check for Youtube-Embed-Frame */ 505 if(this.src.indexOf("//www.youtube.com/embed")>-1) { 506 507 /* Generate Player ID */ 508 var element_id = ytp.idGenerator(); 509 510 /* Generate Player Element */ 511 $("<div />", { 512 class: "ytp-wrap-iframe-embed", 513 id: "wrap_iframe_"+element_id 514 }).css({ 515 "width": $(this).width(), 516 //"height": $(this).height() 517 }).insertBefore($(this)); 518 519 $("<div />", { 520 id: "iframe_"+element_id, 521 class: "ytp" 522 }).css({ 523 "width": $(this).width(), 524 //"height": $(this).height() 525 }).appendTo($("#wrap_iframe_"+element_id)); 526 527 /* Set Data-Attributes */ 528 $.each($(this).data(),function(index,value) { 529 $("#iframe_"+element_id).data(index,value); 530 }); 531 532 /* Check for List */ 533 if(this.src.indexOf("/p")>-1||this.src.indexOf("list=")>-1) { 534 /* Add Loader */ 535 ytp.loader($("#iframe_"+element_id)); 536 /* Looking for List ID */ 537 if(this.src.indexOf("/p")>-1) { 538 var list_id_array = this.src.split("/"); 539 var list_id = list_id_array[list_id_array.length-1]; 540 list_id_array = list_id.split("?"); 541 list_id = list_id_array[list_id_array.length-1]; 542 } else { 543 var list_id_array = this.src.split("list="); 544 list_id_array = list_id_array[1].split("&"); 545 var list_id = list_id_array[0]; 546 } 547 /* Loading Playlist */ 548 $("#iframe_"+element_id).addClass("ytp-playlist-loading"); 549 if(ytp.config.ajax==true) { 550 $.ajax({ 551 method: "POST", 552 url: ytp.config.ytp_path+"/php/ajax.php", 553 data: { id: list_id, method: "feed", page: 1, type: "playlist" } 554 }) 555 .done(function(json) { 556 var videos = JSON.parse(json); 557 ytp.playlist.videos(videos,element_id); 558 }); 559 } else { 560 /* Check for API-Key */ 561 if(ytp.config.api_key!=false) { 562 var feed_url = ytp.feed.load("playlist",list_id); 563 var yt = $.getJSON(feed_url, function(videos) { 564 ytp.playlist.videos(videos,element_id); 565 }); 566 yt.fail(function(data) { 567 ytp.feed.fail(data); 568 }); 569 } 570 /* Not able to load Playlist */ 571 else { 572 573 } 574 } 575 /* Add List ID */ 576 $("#iframe_"+element_id).data("list",list_id); 577 } else { 578 var video_id_array = this.src.split("/"); 579 var video_id = video_id_array[video_id_array.length-1]; 580 video_id_array = video_id.split("?"); 581 video_id = video_id_array[video_id_array.length-1]; 582 $("#iframe_"+element_id).data("video",(video_id)); 583 } 584 585 $(this).remove(); 586 587 } 588 589 }); 590 591 } 592 593 $(".ytp").each(function() { 594 595 ytp.load(this); 596 597 }); 598 599 } 600 601 /* Generate Video Element */ 602 this.new = function(element,attributes) { 603 attributes = (typeof(attributes)!==typeof(ytp_undefined)) ? attributes : false;
604 /* Generate Element */ 605 $("<div />", { 606 class: "ytp" 607 }).appendTo($(element)); 608 /* Add all Attributes from Element */ 609 $.each($(element).data(),function(key,value) { 610 $(element).find(".ytp").data(key,value); 611 }); 612 /* Add all Attributes from Parameter */ 613 $.each(attributes,function(key,value) { 614 $(element).find(".ytp").data(key,value); 615 }); 616 /* Load Video */ 617 ytp.load($(element).find(".ytp")); 618 } 619 620 /* Setup Video Element */ 621 this.load = function(element) { 622 623 /* Check if already loaded */ 624 if(!$(element).hasClass("ytp-loaded")) { 625 626 /* Add "ytp-loaded" ClassName */ 627 $(element).addClass("ytp-loaded"); 628 629 /* Check for Playlist */ 630 if(typeof($(element).data("playlist"))!==typeof(ytp_undefined)) { 631 632 /* Get or generate ID for the Player Element */ 633 var element_id = ($(element).attr("id")) ? $(element).attr("id") : ytp.idGenerator(); 634 $(element).attr("id","iframe_"+element_id); 635 636 $(element).addClass("ytp-playlist-loading"); 637 638 if(ytp.config.ajax==true) { 639 /* Get Playlist via AJAX */ 640 $.ajax({ 641 method: "POST", 642 url: ytp.config.ytp_path+"/php/ajax.php", 643 data: { id: $(element).data("playlist"), page: 1, method: "feed", type: "playlist" } 644 }) 645 .done(function(json) { 646 var videos = JSON.parse(json); 647 ytp.playlist.videos(videos,element_id); 648 }); 649 } else { 650 /* Check for API-Key */ 651 if(ytp.config.api_key!=false) { 652 var feed_url = ytp.feed.load("playlist",$(element).data("playlist")); 653 var yt = $.getJSON(feed_url, function(videos) { 654 ytp.playlist.videos(videos,element_id); 655 }); 656 yt.fail(function(data) { 657 ytp.feed.fail(data); 658 }); 659 } 660 /* Not able to load Playlist */ 661 else { 662 663 } 664 } 665 666 /* Add List ID */ 667 $(element).data("list",($(element).data("playlist"))); 668 } 669 670 /* Check for Playlist - Defined by Video IDs */ 671 if(typeof($(element).data("playlist-videos"))!==typeof(ytp_undefined)) { 672 673 /* Get or generate ID for the Player Element */ 674 var element_id = ($(element).attr("id")) ? $(element).attr("id") : ytp.idGenerator(); 675 $(element).attr("id","iframe_"+element_id); 676 677 $(element).addClass("ytp-playlist-loading"); 678 679 if(ytp.config.ajax==true) { 680 /* Get Playlist via AJAX */ 681 $.ajax({ 682 method: "POST", 683 url: ytp.config.ytp_path+"/php/ajax.php", 684 data: { id: $(element).data("playlist-videos"), page: 1, method: "feed", type: "video" } 685 }) 686 .done(function(json) { 687 var videos = JSON.parse(json); 688 ytp.playlist.videos(videos,element_id); 689 }); 690 } else { 691 /* Check for API-Key */ 692 if(ytp.config.api_key!=false) { 693 var feed_url = ytp.feed.load("video",$(element).data("playlist-videos")); 694 var yt = $.getJSON(feed_url, function(videos) { 695 ytp.playlist.videos(videos,element_id);; 696 }); 697 yt.fail(function(data) { 698 ytp.feed.fail(data); 699 }); 700 } 701 /* Not able to load Playlist */ 702 else { 703 704 } 705 } 706 707 /* Add List ID */ 708 $(element).data("list",($(element).data("playlist-videos"))); 709 } 710 711 /* Check for Mode */ 712 if(typeof($(element).data("mode"))!==typeof(ytp_undefined)) { 713 /* Setup Attributes */ 714 $.each(window["ytp"]["config"]["mode"][$(element).data("mode")],function(key,value) { 715 $(element).data(key,value); 716 }); 717 } 718 719 /* Start Video Player */ 720 ytp.video(element); 721 722 } 723 724 } 725 726 this.video = function(element) { 727 728 /* Player Element */ 729 var player = $(element); 730 731 /* Check for Playlist */ 732 if(player.hasClass("ytp-playlist-loading")) { 733 return window.setTimeout(function() { 734 ytp.video(element); 735 },20); 736 } 737 738 /* Get Player Config */ 739 var config = ytp.config.element(element); 740 741 /* Get Player Events */ 742 var events = ytp.events.element(element); 743 744 /* Get or generate ID for the Player Element */ 745 var element_id = (player.attr("id")) ? player.attr("id") : ytp.idGenerator(); 746 player.attr("id","ytp_"+element_id); 747 748 /* Remove inner HTML of Player Element */ 749 player.html(""); 750 751 /* Add Loader */ 752 ytp.loader(player); 753 754 /* Check for Video ID */ 755 if(typeof(player.data("video"))!==typeof(ytp_undefined)) { 756 var video_id = player.data("video"); 757 } 758 /* Check for Video URL */ 759 else if(typeof(player.data("video-url"))!==typeof(ytp_undefined)) { 760 var video_id = ((player.data("video-url").split("="))[1].split("&"))[0]; 761 } 762
763 /* Save Players Width to a Variable */ 764 window["width_"+element_id] = player.width(); 765 766 /* Set ID and Data for Player Element */ 767 player.data("element",element_id); 768 player.data("video",video_id); 769 770 /* Set Player Layout */ 771 $(element).addClass("ytp-layout-"+config.layout); 772 773 /* Set Player Skin */ 774 $(element).addClass("ytp-skin-"+config.skin); 775 776 /* Player Wrapper */ 777 $("<div />", { 778 class: "ytp-iframe-wrap" 779 }).appendTo($(element)); 780 781 /* Player Element */ 782 $("<div />", { 783 id: element_id, 784 }).appendTo($(element).find(".ytp-iframe-wrap")); 785 786 /* Intro */ 787 if(config.intro==true) { 788 $("<div />", { 789 class: "ytp-intro ytp-active", 790 }).css("background-image","url('https://img.youtube.com/vi/"+video_id+"/hqdefault.jpg')").on("click",function() { 791 $(element).find(".ytp-play-button").trigger("click"); 792 }).appendTo($(element)); 793 } 794 795 /* Youtube-Logo */ 796 if(config.youtube_logo==true) { 797 $("<a />", { 798 class: "ytp-youtube-logo ytp-no-opacity ytp-icon", 799 target: "_blank", 800 title: config.text.youtube, 801 href: "https://www.youtube.com/watch?v="+video_id 802 }).appendTo($(element)); 803 } 804 805 /* Play-Button */ 806 $("<div />", { 807 class: "ytp-play-button ytp-active ytp-icon", 808 title: config.text.play 809 }).on("click",function() { 810 ytp.controls.play(this,true); 811 }).appendTo($(element)); 812 813 /* Stop-Button */ 814 $("<div />", { 815 class: "ytp-stop", 816 title: config.text.pause 817 }).on("click",function() { 818 ytp.controls.pause(this,true); 819 }).appendTo($(element)); 820 821 /* Timeline */ 822 if(config.timeline==true) { 823 $("<div />", { 824 class: "ytp-timeline ytp-no-opacity", 825 }).append( 826 $("<div />", { 827 class: "ytp-line-loaded", 828 }) 829 ).append( 830 $("<div />", { 831 class: "ytp-line-active", 832 }) 833 ).append( 834 $("<div />", { 835 class: "ytp-line-jump", 836 }) 837 ).appendTo($(element)); 838 } 839 840 /* Playlist Videos */ 841 if(typeof(window["ytp_videos_"+element_id])!==typeof(ytp_undefined)) { 842 /* Controls */ 843 $("<div />", { 844 class: "ytp-scroll ytp-playlist", 845 }).append($("<div />", { 846 class: "ytp-scroll-pane", 847 })).appendTo($(element)); 848 var video_counter = 0; 849 $.each(window["ytp_videos_"+element_id].items,function() { 850 var videoId = (typeof(this.snippet.resourceId)!==typeof(ytp_undefined)) ? this.snippet.resourceId.videoId : this.id; 851 /* Default Thumbnail */ 852 var thumbnail = (typeof(this.snippet.thumbnails)!==typeof(ytp_undefined)) ? this.snippet.thumbnails.high.url : "#"; 853 /* High Quality Image */ 854 // var thumbnail = "https://img.youtube.com/vi/"+videoId+"/maxresdefault.jpg"; 855 $("<div />", { 856 class: "ytp-video" 857 }) 858 .css("background-image","url('"+thumbnail+"')") 859 .on("click",function() { 860 ytp.playlist.video(element_id,$(this).data("video")); 861 }) 862 .data("video",videoId) 863 .append( 864 $("<div />", { 865 class: "ytp-title" 866 }) 867 .html(this.snippet.title) 868 ) 869 .append( 870 $("<div />", { 871 class: "ytp-description" 872 }) 873 .html(this.snippet.description) 874 ) 875 .appendTo($("#ytp_"+element_id+" .ytp-playlist").find(".ytp-scroll-pane")); 876 if(video_counter==0) { 877 $("#ytp_"+element_id+" .ytp-playlist").find(".ytp-video").addClass("ytp-active"); 878 } 879 video_counter++; 880 }); 881 var config = ytp.config.element($("#ytp_"+element_id)); 882 if(config.playlist_more==true) { 883 if(typeof(window["ytp_videos_"+element_id].nextPageToken)!==typeof(ytp_undefined)) { 884 $("<div />", { 885 class: "ytp-button" 886 }) 887 .on("click",function() { 888 ytp.playlist.load(element_id,window["ytp_videos_"+element_id].nextPageToken); 889 }) 890 .html(config.text.playlist_more) 891 .appendTo($("#ytp_"+element_id+" .ytp-playlist .ytp-scroll-pane")); 892 } 893 } 894 player.addClass("ytp-has-playlist"); 895 if(config.playlist_videos==true) { 896 player.addClass("ytp-playlist-visible"); 897 player.find(".ytp-playlist").addClass("ytp-visible"); 898 } 899 /* Horizontal Scrollbar (Playlist) */ 900 if(config.layout=="full") { 901 $("#ytp_"+element_id+" .ytp-playlist .ytp-scroll-pane").css("width",video_counter*$("#ytp_"+element_id+" .ytp-playlist").find(".ytp-video").innerWidth()); 902 } 903 /* Scrollbar */ 904 var pane = $("#ytp_"+element_id+" .ytp-playlist"); 905 pane.jScrollPane(); 906 window["ytp_pane_"+element_id] = pane.data("jsp"); 907 } 908 909 /* Controls */ 910 $("<div />", { 911 class: "ytp-controls", 912 }).appendTo($(element)); 913 914 /* Play-Button */ 915 if(config.play==true) { 916 $("<div />", { 917 class: "ytp-play ytp-active ytp-icon", 918 title: config.text.play 919 }).on("click",function() { 920 ytp.controls.play(this,true); 921 }).appendTo($(element).find(".ytp-controls")); 922 } 923 924 /* Pause-Button */ 925 if(config.pause==true) { 926 $("<div />", { 927 class: "ytp-pause ytp-icon", 928 title: config.text.pause 929 }).on("click",function() { 930 ytp.controls.pause(this,true); 931 }).appendTo($(element).find(".ytp-controls")); 932 } 933 934 /* Time */ 935 if(config.time==true) { 936 $("<div />", { 937 class: "ytp-time", 938 }).appendTo($(element).find(".ytp-controls")); 939 $("<div />", { 940 class: "ytp-time-max", 941 }).appendTo($(element).find(".ytp-controls")); 942 } 943 944 /* Sound */ 945 if(config.volume==true) { 946 947 /* Sound-Button */ 948 $("<div />", { 949 class: "ytp-sound ytp-icon", 950 title: config.text.volume 951 }).on("click",function() { 952 if($(this).hasClass("ytp-volume-0")) { 953 ytp.sound.change(element_id,$(element).find(".ytp-volume-backup").val()); 954 } else { 955 ytp.sound.change(element_id,0); 956 } 957 }).appendTo($(element).find(".ytp-controls")); 958 959 /* Sound-Change */ 960 $("<div />", { 961 class: "ytp-sound-change", 962 }).append( 963 $("<div />", { 964 class: "ytp-sound-now", 965 }) 966 ).appendTo($(element).find(".ytp-controls")); 967 968 /* Possible Spacer for smaller Screens */ 969 $("<div />", { 970 class: "ytp-spacer" 971 }).appendTo($(element).find(".ytp-controls")); 972 973 } 974 975 /* Playlist-Buttons */ 976 if(typeof(window["ytp_videos_"+element_id])!==typeof(ytp_undefined)) { 977 978 /* Back-Button */ 979 if(config.playlist_previous==true) { 980 $("<div />", { 981 class: "ytp-back ytp-icon", 982 title: config.text.previous 983 }).on("click",function() { 984 ytp.playlist.back(element_id); 985 }).appendTo($(element).find(".ytp-controls")); 986 } 987 988 /* List-Button */ 989 if(config.playlist_list==true&&config.playlist_videos==true) { 990 $("<div />", { 991 class: "ytp-list ytp-active ytp-icon", 992 title: config.text.list 993 }).on("click",function() { 994 if($(this).hasClass("ytp-active")) { 995 $(element).removeClass("ytp-playlist-visible"); 996 $(this).removeClass("ytp-active"); 997 } else { 998 $(element).addClass("ytp-playlist-visible"); 999 $(this).addClass("ytp-active"); 1000 } 1001 }).appendTo($(element).find(".ytp-controls")); 1002 } 1003 1004 /* Next-Button */ 1005 if(config.playlist_next==true) { 1006 $("<div />", { 1007 class: "ytp-next ytp-icon", 1008 title: config.text.next 1009 }).on("click",function() { 1010 ytp.playlist.next(element_id); 1011 }).appendTo($(element).find(".ytp-controls")); 1012 } 1013 1014 /* Shuffle-Button */ 1015 if(config.playlist_shuffle==true) { 1016 $("<div />", { 1017 class: "ytp-shuffle ytp-icon", 1018 title: config.text.shuffle 1019 }).on("click",function() { 1020 if($(element).hasClass("ytp-shuffle")) { 1021 $(element).removeClass("ytp-shuffle"); 1022 $(this).removeClass("ytp-active"); 1023 } else { 1024 $(element).addClass("ytp-shuffle"); 1025 $(this).addClass("ytp-active"); 1026 } 1027 }).appendTo($(element).find(".ytp-controls")); 1028 } 1029 1030 } 1031 1032 /* Loop */ 1033 if(config.loop==true) { 1034 $("<div />", { 1035 class: "ytp-loop ytp-icon", 1036 title: config.text.loop 1037 }).on("click",function() { 1038 if($(element).hasClass("ytp-loop")) { 1039 $(element).removeClass("ytp-loop"); 1040 $(this).removeClass("ytp-active"); 1041 } else { 1042 $(element).addClass("ytp-loop"); 1043 $(this).addClass("ytp-active"); 1044 } 1045 }).appendTo($(element).find(".ytp-controls")); 1046 } 1047 1048 /* Share-Button */ 1049 if(config.share==true) { 1050 1051 $("<div />", { 1052 class: "ytp-share ytp-icon", 1053 title: config.text.share 1054 }).on("click",function() { 1055 if($(element).find(".ytp-share-wrap").hasClass("ytp-active")) { 1056 $(element).find(".ytp-share-wrap").removeClass("ytp-active"); 1057 $(element).find(".ytp-share").removeClass("ytp-active"); 1058 } else { 1059 $(element).find(".ytp-share-wrap").addClass("ytp-active"); 1060 $(element).find(".ytp-share").addClass("ytp-active"); 1061 } 1062 }).appendTo($(element).find(".ytp-controls")); 1063 1064 $("<div />", { 1065 class: "ytp-share-wrap" 1066 }).appendTo($(element)); 1067 1068 /* Share: Facebook */ 1069 $("<a />", { 1070 class: "ytp-facebook ytp-icon", 1071 title: config.text.share_facebook, 1072 target: "_blank" 1073 }).on("click",function() { 1074 ytp.share(this,element,"facebook"); 1075 }).appendTo($(element).find(".ytp-share-wrap")); 1076 1077 /* Share: Twitter */ 1078 $("<a />", { 1079 class: "ytp-twitter ytp-icon", 1080 title: config.text.share_twitter, 1081 target: "_blank" 1082 }).on("click",function() { 1083 ytp.share(this,element,"twitter"); 1084 }).appendTo($(element).find(".ytp-share-wrap")); 1085 1086 /* Share: Google */ 1087 $("<a />", { 1088 class: "ytp-google ytp-icon", 1089 title: config.text.share_google, 1090 target: "_blank" 1091 }).on("click",function() { 1092 ytp.share(this,element,"google"); 1093 }).appendTo($(element).find(".ytp-share-wrap")); 1094 1095 /* Share: Tumblr */ 1096 $("<a />", { 1097 class: "ytp-tumblr ytp-icon", 1098 title: config.text.share_tumblr, 1099 target: "_blank" 1100 }).on("click",function() { 1101 ytp.share(this,element,"tumblr"); 1102 }).appendTo($(element).find(".ytp-share-wrap")); 1103 1104 /* Share: Email */ 1105 $("<a />", { 1106 class: "ytp-email ytp-icon", 1107 title: config.text.share_email 1108 }).on("click",function() { 1109 ytp.share(this,element,"email"); 1110 }).appendTo($(element).find(".ytp-share-wrap")); 1111 1112 /* Share: WhatsApp */ 1113 if(ytp.isMobile()===true) { 1114 $("<a />", { 1115 class: "ytp-whatsapp ytp-icon", 1116 title: config.text.share_whatsapp 1117 }).on("click",function() { 1118 ytp.share(this,element,"whatsapp"); 1119 }).appendTo($(element).find(".ytp-share-wrap")); 1120 } 1121 1122 /* Share: LinkedIn */ 1123 $("<a />", { 1124 class: "ytp-linkedin ytp-icon", 1125 title: config.text.share_linkedin, 1126 target: "_blank" 1127 }).on("click",function() { 1128 ytp.share(this,element,"linkedin"); 1129 }).appendTo($(element).find(".ytp-share-wrap")); 1130 1131 /* Share: Reddit */ 1132 $("<a />", { 1133 class: "ytp-reddit ytp-icon", 1134 title: config.text.share_reddit, 1135 target: "_blank" 1136 }).on("click",function() { 1137 ytp.share(this,element,"reddit"); 1138 }).appendTo($(element).find(".ytp-share-wrap")); 1139 1140 } 1141 1142 /* Comments */ 1143 if(config.comments==true&&(config.ajax==true||config.api_key!=false)) { 1144 /* Comments-Button */ 1145 $("<div />", { 1146 class: "ytp-comments ytp-icon", 1147 title: config.text.comments 1148 }).on("click",function() { 1149 /* Load Comments */ 1150 if($("#ytp_"+element_id+" .ytp-comments-wrap .ytp-scroll-pane").length==0) { 1151 /* Set highest z-Index for this Element */ 1152 $("#ytp_"+element_id+" .ytp-z-index").removeClass("ytp-z-index"); 1153 $("#ytp_"+element_id+" .ytp-comments-wrap").addClass("ytp-z-index"); 1154 /* Load Comments */ 1155 ytp.comments.load(element_id,1); 1156 } else { 1157 /* Check for State */ 1158 if($("#ytp_"+element_id+" .ytp-comments-wrap").hasClass("ytp-visible")) { 1159 $("#ytp_"+element_id+" .ytp-comments-wrap").removeClass("ytp-visible"); 1160 $("#ytp_"+element_id+" .ytp-comments").removeClass("ytp-visible"); 1161 } else { 1162 /* Set highest z-Index for this Element */ 1163 $("#ytp_"+element_id+" .ytp-z-index").removeClass("ytp-z-index"); 1164 $("#ytp_"+element_id+" .ytp-comments-wrap").addClass("ytp-z-index"); 1165 /* Show Element */ 1166 $("#ytp_"+element_id+" .ytp-comments-wrap").addClass("ytp-visible"); 1167 $("#ytp_"+element_id+" .ytp-comments").addClass("ytp-visible"); 1168 } 1169 } 1170 }).appendTo($(element).find(".ytp-controls")); 1171 /* Comments Window */ 1172 $("<div />", { 1173 class: "ytp-comments-wrap ytp-scroll", 1174 }).append( 1175 $("<div />", { 1176 class: "ytp-close ytp-icon", 1177 title: config.text.close 1178 }).on("click",function() { 1179 $("#ytp_"+element_id+" .ytp-controls .ytp-comments").trigger("click"); 1180 }) 1181 ).appendTo($(element)); 1182 } 1183 1184 /* Related-Videos */ 1185 if(config.related==true&&(config.ajax==true||config.api_key!=false)) { 1186 /* Related-Videos Button */ 1187 $("<div />", { 1188 class: "ytp-related ytp-icon", 1189 title: config.text.related 1190 }).on("click",function() { 1191 /* Load Related Videos */ 1192 if($("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane").length==0) { 1193 /* Set highest z-Index for this Element */ 1194 $("#ytp_"+element_id+" .ytp-z-index").removeClass("ytp-z-index"); 1195 $("#ytp_"+element_id+" .ytp-related-wrap").addClass("ytp-z-index"); 1196 /* Load Videos */ 1197 ytp.related.load(element_id,1); 1198 } else { 1199 /* Check for State */ 1200 if($("#ytp_"+element_id+" .ytp-related-wrap").hasClass("ytp-visible")) { 1201 $("#ytp_"+element_id+" .ytp-related-wrap").removeClass("ytp-visible"); 1202 $("#ytp_"+element_id+" .ytp-related").removeClass("ytp-visible"); 1203 } else { 1204 /* Set highest z-Index for this Element */ 1205 $("#ytp_"+element_id+" .ytp-z-index").removeClass("ytp-z-index"); 1206 $("#ytp_"+element_id+" .ytp-related-wrap").addClass("ytp-z-index"); 1207 /* Show Element */ 1208 $("#ytp_"+element_id+" .ytp-related-wrap").addClass("ytp-visible"); 1209 $("#ytp_"+element_id+" .ytp-related").addClass("ytp-visible"); 1210 } 1211 } 1212 }).appendTo($(element).find(".ytp-controls")); 1213 /* Related Videos Window */ 1214 $("<div />", { 1215 class: "ytp-related-wrap ytp-scroll", 1216 }).append( 1217 $("<div />", { 1218 class: "ytp-close ytp-icon", 1219 title: config.text.close 1220 }).on("click",function() { 1221 $("#ytp_"+element_id+" .ytp-controls .ytp-related").trigger("click"); 1222 }) 1223 ).appendTo($(element)); 1224 } 1225 1226 /* 2x Speed */ 1227 if(config.speed==true) { 1228 $("<div />", { 1229 class: "ytp-speed ytp-icon", 1230 title: config.text.speed 1231 }).on("click",function() { 1232 ytp.controls.speed(element,element_id); 1233 }).appendTo($(element).find(".ytp-controls")); 1234 } 1235 1236 /* Youtube-Button */ 1237 if(config.youtube_popup==true) { 1238 $("<a />", { 1239 class: "ytp-youtube ytp-icon", 1240 target: "_blank", 1241 title: config.text.popup 1242 }).on("click",function() { 1243 //window["player_"+element_id].pauseVideo(); 1244 $(this).attr("href","https://www.youtube.com/watch?v="+$(element).data("video")); 1245 }).appendTo($(element).find(".ytp-controls")); 1246 } 1247 1248 /* Popout-Button */ 1249 if(config.youtube_popout==true) { 1250 $("<div />", { 1251 class: "ytp-popup ytp-icon", 1252 title: config.text.popout 1253 }).on("click",function() { 1254 ytp.popup(element_id); 1255 }).appendTo($(element).find(".ytp-controls")); 1256 } 1257 1258 /* Search */ 1259 if(config.search==true&&(config.ajax==true||config.api_key!=false)) { 1260 1261 /* Search-Button */ 1262 $("<div />", { 1263 class: "ytp-search ytp-icon", 1264 title: config.text.search 1265 }).on("click",function() { 1266 if($(this).hasClass("ytp-active")) { 1267 $(this).removeClass("ytp-active"); 1268 $(element).find(".ytp-search-wrap").removeClass("ytp-visible"); 1269 } else { 1270 /* Set highest z-Index for this Element */ 1271 $(element).find(".ytp-z-index").removeClass("ytp-z-index"); 1272 $(element).find(".ytp-search-wrap").addClass("ytp-z-index"); 1273 /* Show Element */ 1274 $(this).addClass("ytp-active"); 1275 $(element).find(".ytp-search-wrap").addClass("ytp-visible"); 1276 var input = $(element).find(".ytp-search-wrap").find("input"); 1277 input.focus(); 1278 } 1279 }).appendTo($(element).find(".ytp-controls")); 1280 1281 /* Search-Wrap */ 1282 $("<div />", { 1283 class: "ytp-search-wrap ytp-scroll", 1284 })
1285 .append( 1286 $("<div />", { 1287 class: "ytp-close ytp-icon", 1288 title: config.text.close 1289 }).on("click",function() { 1290 $("#ytp_"+element_id+" .ytp-controls .ytp-search").trigger("click"); 1291 }) 1292 ) 1293 .append($("<input />", { 1294 class: "q", 1295 }).on("keyup",function(e) { 1296 if(typeof(window["timeout_search_"+element_id])!==typeof(ytp_undefined)) { 1297 window.clearTimeout(window["timeout_search_"+element_id]); 1298 delete window["timeout_search_"+element_id]; 1299 } 1300 if(e.keyCode==13) { 1301 ytp.search.load(element_id,1); 1302 } else if(this.value.length>2) { 1303 window["timeout_search_"+element_id] = window.setTimeout("ytp.search.load('"+element_id+"',1);",3000); 1304 } 1305 })).appendTo($(element)); 1306 1307 } 1308 1309 /* Info-Button */ 1310 if(config.info==true) { 1311 $("<div />", { 1312 class: "ytp-info ytp-icon", 1313 title: config.text.info 1314 }).on("click",function() { 1315 ytp.info.load(element_id); 1316 }).appendTo($(element).find(".ytp-controls")); 1317 $("<div />", { 1318 class: "ytp-info-wrap ytp-scroll", 1319 }) 1320 .append( 1321 $("<div />", { 1322 class: "ytp-close ytp-icon", 1323 title: config.text.close 1324 }).on("click",function() { 1325 $("#ytp_"+element_id+" .ytp-controls .ytp-info").trigger("click"); 1326 }) 1327 ).appendTo($(element)); 1328 } 1329 1330 /* Fullscreen-Button */ 1331 if(config.fullscreen==true) { 1332 $("<div />", { 1333 class: "ytp-fullscreen ytp-icon", 1334 title: config.text.fullscreen 1335 }).on("click",function() { 1336 ytp.fullscreen(element_id); 1337 }).appendTo($(element).find(".ytp-controls")); 1338 } 1339 1340 /* Advertisement */ 1341 if(config.advertisement==true) { 1342 var ad_area = (config.ad_area==false) ? "intro" : config.ad_area; 1343 var ad_areas = ad_area.split(","); 1344 $.each(ad_areas,function() { 1345 var ad_not_found = false; 1346 /* End Autoplay if Ad is for Intro */ 1347 if(this=="intro") { 1348 config.autoplay = false; 1349 } 1350 /* Check for Ad-Timer */ 1351 var ad_timer = 0; 1352 /* Ad Content */ 1353 var ad_content = false;
1354 var ad_file = false; 1355 if(config.ad_id!=false) { 1356 ad_content = $("#"+config.ad_id).html(); 1357 } else if(config.ad_file!=false) { 1358 ad_file = ytp.ad.file(config.ad_file); 1359 ad_content = true; 1360 } 1361 if(this=="intro") { 1362 ad_timer = config.ad_intro_timer; 1363 if(config.ad_intro_id!=false) { 1364 ad_content = $("#"+config.ad_intro_id).html(); 1365 } else if(config.ad_intro_file!=false) { 1366 ad_file = ytp.ad.file(config.ad_intro_file); 1367 ad_content = true; 1368 } 1369 } else if(this=="pause") { 1370 ad_timer = config.ad_pause_timer; 1371 if(config.ad_pause_id!=false) { 1372 ad_content = $("#"+config.ad_pause_id).html(); 1373 } else if(config.ad_pause_file!=false) { 1374 ad_file = ytp.ad.file(config.ad_pause_file); 1375 ad_content = true; 1376 } 1377 } else if(this=="end") { 1378 ad_timer = config.ad_end_timer; 1379 if(config.ad_end_id!=false) { 1380 ad_content = $("#"+config.ad_end_id).html(); 1381 } else if(config.ad_end_file!=false) { 1382 ad_file = ytp.ad.file(config.ad_end_file); 1383 ad_content = true; 1384 } 1385 } else { 1386 if(config.ad_bottom_id!=false) { 1387 ad_content = $("#"+config.ad_bottom_id).html(); 1388 } else if(config.ad_bottom_file!=false) { 1389 ad_file = ytp.ad.file(config.ad_bottom_file); 1390 ad_content = true; 1391 } 1392 } 1393 if(ad_content!==false) { 1394 var close_class = "ytp-ad-close"; 1395 if(ad_timer>0) { 1396 close_class+= " ytp-close-timer"; 1397 } 1398 var ad_id = ytp.idGenerator(); 1399 $("<div />", { 1400 id: "ytp-ad-"+ad_id, 1401 class: "ytp-advertisement ytp-ad-"+this 1402 }).append( 1403 $("<div />", { 1404 class: close_class+" ytp-close ytp-icon", 1405 title: config.text.ad_close 1406 }).on("click",function() { 1407 ytp.ad.close($(this).parent(),config,element_id); 1408 }) 1409 ).append( 1410 $("<div />", { 1411 class: close_class+" ytp-ad-close-bottom" 1412 }) 1413 .html(config.text.ad_close) 1414 .append( 1415 $("<div />", { 1416 class: "ytp-ad-timer" 1417 }) 1418 .html(config.text.ad_close_wait_seconds+" <span>"+ad_timer+"</span> "+config.text.ad_close_seconds) 1419 ) 1420 .data("timer",ad_timer) 1421 .on("click",function() { 1422 ytp.ad.close($(this).parent(),config,element_id); 1423 }) 1424 ).append( 1425 $("<div />", { 1426 class: "ytp-ad-content" 1427 }) 1428 ).appendTo($(element)); 1429 if(ad_content===true) { 1430 $("#ytp-ad-"+ad_id).find(".ytp-ad-content").append(ad_file); 1431 } else { 1432 $("#ytp-ad-"+ad_id).find(".ytp-ad-content").html(ad_content); 1433 } 1434 } 1435 }); 1436 } 1437 1438 /* Time-Counter */ 1439 if(config.ajax==true&&config.statistics==true) { 1440 $("<input />", { 1441 class: "ytp-time-counter ytp-hidden", 1442 type: "hidden", 1443 value: 0 1444 }).appendTo($(element)); 1445 $("<input />", { 1446 class: "ytp-last-time ytp-hidden", 1447 type: "hidden", 1448 value: 0 1449 }).appendTo($(element)); 1450 } 1451 1452 /* Volume-Backup */ 1453 $("<input />", { 1454 class: "ytp-volume-backup ytp-hidden", 1455 type: "hidden" 1456 }).appendTo($(element)); 1457 1458 /* Hide Controls */ 1459 if(config.hide==true) { 1460 1461 /* Hide Controls on Mouse leave */ 1462 player.on("mouseleave",function(){ 1463 /* Time: Initial Timeout (longer) */ 1464 var timeoutTime = 3000; 1465 /* Time: Next Timeout(s) */ 1466 if(typeof(window["timeout_hided_"+element_id])!==typeof(ytp_undefined)) { 1467 timeoutTime = 500; 1468 } 1469 /* If Video is playing hide Controls */ 1470 if(typeof(window["player_"+element_id].getPlayerState)=="function") { 1471 if(window["player_"+element_id].getPlayerState()==1) { 1472 window["timeout_"+element_id] = window.setTimeout("ytp.controls.hide('"+element_id+"');",timeoutTime); 1473 } 1474 } 1475 }); 1476 1477 /* Hide Controls on Mouse Moving stopped */ 1478 /** 1479 Removed for now, because you have to overlay the Player and this means you cant close Ads and so on... 1480 (the mousemove-event cant be fired inside the iframe) 1481 **/ 1482 /* 1483 player.on("mousemove",function(){ 1484 // Show Controls if hidden 1485 if(typeof(window["timeout_hide_"+element_id])!==typeof(ytp_undefined)) { 1486 ytp.controls.show(element_id); 1487 } 1488 // Delete Timeout when Mouse moves 1489 if(typeof(window["timeout_move_"+element_id])!==typeof(ytp_undefined)) { 1490 window.clearTimeout(window["timeout_move_"+element_id]); 1491 delete window["timeout_move_"+element_id]; 1492 } 1493 // If Video is playing hide Controls 1494 if(typeof(window["player_"+element_id].getPlayerState)=="function") { 1495 if(window["player_"+element_id].getPlayerState()==1) { 1496 window["timeout_move_"+element_id] = window.setTimeout("ytp.controls.hide('"+element_id+"');",2500); 1497 } 1498 } 1499 }); 1500 */ 1501 1502 /* Show Controls on Mouse enter */ 1503 player.on("mouseenter",function(){ 1504 if(typeof(window["timeout_"+element_id])!==typeof(ytp_undefined)) { 1505 window.clearTimeout(window["timeout_"+element_id]); 1506 delete window["timeout_"+element_id]; 1507 } 1508 if(typeof(window["timeout_hide_"+element_id])!==typeof(ytp_undefined)) { 1509 ytp.controls.show(element_id); 1510 } 1511 }); 1512 1513 } 1514 1515 /* Calculate Player Height */
1516 var height = Math.ceil(window["width_"+element_id]/1.3589); 1517 if(player.prop("style").height!="") { 1518 var height = player.css("height").replace("px",""); 1519 } 1520 //player.css("height",height+"px"); 1521 1522 /* Save Height Ratio */ 1523 window["ratio_"+element_id] = window["width_"+element_id]/height; 1524 1525 /* Check for Control-Bar */ 1526 if(config.youtube_controls===true) { 1527 player.addClass("ytp-youtube-controls"); 1528 } 1529 1530 /* Check for Youtube-Related */ 1531 if(config.youtube_related===true) { 1532 player.addClass("ytp-youtube-related"); 1533 } 1534 1535 /* Setup Youtube Frame */ 1536 window["player_"+element_id] = new YT.Player(element_id, { 1537 //height: height, 1538 width: window["width_"+element_id], 1539 videoId: video_id, 1540 events: { 1541 "onReady": function() { 1542 /* Generate Timeline */ 1543 ytp.timeline(element_id); 1544 /* Timeline Interval */ 1545 window["time_interval_"+element_id] = window.setInterval("ytp.timeInterval('"+element_id+"');",1000); 1546 /* Sound configuration */ 1547 ytp.sound.init(element_id); 1548 $(element).find(".ytp-volume-backup").val(window["player_"+element_id].getVolume()); 1549 /* Events */ 1550 if(window[events.onReady]!==false) { 1551 if(typeof(window[events.onReady])=="function") { 1552 window[events.onReady](window["player_"+element_id],element); 1553 } 1554 } 1555 /* Remove Loader */ 1556 $(element).find(".ytp-loader").remove(); 1557 /* Load Element Config */ 1558 var config = ytp.config.element($(element)); 1559 /* Autoplay */ 1560 if(config.autoplay==true) { 1561 window["player_"+element_id].playVideo(); 1562 /* Statistics */ 1563 if(config.ajax==true&&config.statistics==true) { 1564 ytp.statistics(element_id,"video","views",1); 1565 } 1566 } 1567 /* Statistics */ 1568 if(config.ajax==true&&config.statistics==true) { 1569 ytp.statistics(element_id,"video","loaded",1); 1570 } 1571 }, 1572 'onError': function(event) { 1573 ytp.onPlayerError(event,element_id); 1574 }, 1575 'onStateChange': function(event) { 1576 ytp.onPlayerStateChange($("#ytp_"+element_id),event); 1577 } 1578 }, 1579 playerVars: { 1580 'controls': config.youtube_controls, 1581 'fs' : config.youtube_fs, 1582 'autohide' : config.youtube_autohide, 1583 'related': config.youtube_related, 1584 'rel': config.youtube_related, 1585 'showinfo': config.youtube_showinfo, 1586 'modestbranding': config.youtube_modestbranding 1587 } 1588 }); 1589 } 1590 1591 /* Statistics */ 1592 this.statistics = function(element_id,type,statistic,value) { 1593 $.ajax({ 1594 method: "POST", 1595 url: ytp.config.ytp_path+"/php/ajax.php", 1596 data: { id: $("#ytp_"+element_id).data("video"), method: "statistics", statistic: statistic, type: type, value: value } 1597 }); 1598 } 1599 1600 /* Playlist Functions */ 1601 this.playlist = new function() { 1602 1603 /* Load Video */ 1604 this.video = function(element_id,video_id) { 1605 1606 /* Load Element-Config */ 1607 var config = ytp.config.element($("#ytp_"+element_id)); 1608 /* Show Loader */ 1609 ytp.loader($("#ytp_"+element_id)); 1610 /* Set Video Id */ 1611 $("#ytp_"+element_id).data("video",video_id); 1612 /* Load Video */ 1613 window["player_"+element_id].loadVideoById(video_id); 1614 /* Reset Time */ 1615 $("#ytp_"+element_id).find(".ytp-time").html(""); 1616 /* Reset Time */ 1617 $("#ytp_"+element_id).find(".ytp-time-max").html("-"); 1618 /* Reset Comments */ 1619 $("#ytp_"+element_id).find(".ytp-comments-wrap .ytp-scroll-pane").remove(); 1620 /* Reset Related */ 1621 $("#ytp_"+element_id).find(".ytp-related-wrap .ytp-scroll-pane").remove(); 1622 /* Set Video as active in Playlist */ 1623 var list_count = 0; 1624 $.each($("#ytp_"+element_id).find(".ytp-playlist").find(".ytp-video"),function() { 1625 $(this).removeClass("ytp-active"); 1626 if($(this).data("video")==video_id) { 1627 $(this).addClass("ytp-active"); 1628 var position = $(this).height()*list_count; 1629 if(config.layout=="full") { 1630 position = $(this).width()*list_count; 1631 window["ytp_pane_"+element_id].scrollTo(position,0); 1632 } else { 1633 window["ytp_pane_"+element_id].scrollTo(0,position); 1634 } 1635 1636 } 1637 list_count++; 1638 }); 1639 1640 /* Statistics */ 1641 if(config.ajax==true&&config.statistics==true) { 1642 /* +1 Loaded */ 1643 ytp.statistics(element_id,"video","loaded",1); 1644 /* +1 Views */ 1645 window.setTimeout('ytp.statistics("'+element_id+'","video","views",1);',1000); 1646 } 1647 } 1648 1649 /* Previous Video */ 1650 this.back = function(element_id) { 1651 var video_id = $("#ytp_"+element_id).data("video"); 1652 var search = true; 1653 var previous_video = $("#ytp_"+element_id).find(".ytp-playlist").find(".ytp-video"); 1654 previous_video = $(previous_video).data("video"); 1655 $.each($("#ytp_"+element_id).find(".ytp-playlist").find(".ytp-video"),function() { 1656 if(search===true) { 1657 if($(this).data("video")==video_id) { 1658 search = false;
1659 } 1660 if(search===true) { 1661 previous_video = $(this).data("video"); 1662 } 1663 } 1664 }); 1665 /* Load Video */ 1666 ytp.playlist.video(element_id,previous_video); 1667 } 1668 1669 /* Next Video */ 1670 this.next = function(element_id) { 1671 var video_id = $("#ytp_"+element_id).data("video"); 1672 var search = false; 1673 var next_video = $("#ytp_"+element_id).find(".ytp-playlist").find(".ytp-video"); 1674 next_video = $(next_video).data("video"); 1675 $.each($("#ytp_"+element_id).find(".ytp-playlist").find(".ytp-video"),function() { 1676 if(search===true) { 1677 next_video = $(this).data("video"); 1678 search = false; 1679 } 1680 if($(this).data("video")==video_id) { 1681 search = true; 1682 } 1683 }); 1684 /* Load Video */ 1685 ytp.playlist.video(element_id,next_video); 1686 } 1687 1688 /* Load more Videos */ 1689 this.load = function(element_id,page) { 1690 ytp.loader($("#ytp_"+element_id+" .ytp-playlist")); 1691 $("#ytp_"+element_id+" .ytp-playlist .ytp-button").remove(); 1692 if(ytp.config.ajax==true) { 1693 /* Load Videos via AJAX */ 1694 $.ajax({ 1695 method: "POST", 1696 url: ytp.config.ytp_path+"/php/ajax.php", 1697 data: { id: $("#ytp_"+element_id).data("list"), method: "feed", page: page, type: "playlist" } 1698 }) 1699 .done(function( json ) { 1700 var videos = JSON.parse(json); 1701 ytp.playlist.addVideos(element_id,videos); 1702 }); 1703 } else if(ytp.config.api_key!=false) { 1704 /* Check for API-Key */ 1705 var feed_url = ytp.feed.load("playlist",$("#ytp_"+element_id).data("list"),page); 1706 var yt = $.getJSON(feed_url, function(videos) { 1707 ytp.playlist.addVideos(element_id,videos); 1708 }); 1709 yt.fail(function(data) { 1710 ytp.feed.fail(data); 1711 }); 1712 } 1713 } 1714 1715 /* Add more Videos */ 1716 this.addVideos = function(element_id,videos) { 1717 $.each(videos.items,function() { 1718 var videoId = (typeof(this.snippet.resourceId)!==typeof(ytp_undefined)) ? this.snippet.resourceId.videoId : this.id; 1719 /* Default Thumbnail */ 1720 var thumbnail = (typeof(this.snippet.thumbnails)!==typeof(ytp_undefined)) ? this.snippet.thumbnails.high.url : "#"; 1721 /* High Quality Image */ 1722 // var thumbnail = "https://img.youtube.com/vi/"+this.snippet.resourceId.videoId+"/maxresdefault.jpg"; 1723 $("<div />", { 1724 class: "ytp-video" 1725 }) 1726 .css("background-image","url('"+thumbnail+"')") 1727 .on("click",function() { 1728 ytp.playlist.video(element_id,$(this).data("video")); 1729 }) 1730 .data("video",videoId) 1731 .append( 1732 $("<div />", { 1733 class: "ytp-title" 1734 }) 1735 .html(this.snippet.title) 1736 ) 1737 .append( 1738 $("<div />", { 1739 class: "ytp-description" 1740 }) 1741 .html(this.snippet.description) 1742 ) 1743 .appendTo($("#ytp_"+element_id+" .ytp-playlist").find(".ytp-scroll-pane")); 1744 }); 1745 var config = ytp.config.element($("#ytp_"+element_id)); 1746 if(config.playlist_more==true) { 1747 if(typeof(videos.nextPageToken)!==typeof(ytp_undefined)) { 1748 $("<div />", { 1749 class: "ytp-button" 1750 }) 1751 .on("click",function() { 1752 ytp.playlist.load(element_id,videos.nextPageToken); 1753 }) 1754 .html(config.text.playlist_more) 1755 .appendTo($("#ytp_"+element_id+" .ytp-playlist .ytp-scroll-pane")); 1756 } 1757 } 1758 /* Horizontal Scrollbar (Playlist) */ 1759 if(config.layout=="full") { 1760 $("#ytp_"+element_id+" .ytp-playlist .ytp-scroll-pane").css("width",$("#ytp_"+element_id+" .ytp-playlist").find(".ytp-video").length*$("#ytp_"+element_id+" .ytp-playlist").find(".ytp-video").innerWidth()); 1761 } 1762 /* Scrollbar */ 1763 var pane = $("#ytp_"+element_id+" .ytp-playlist"); 1764 pane.jScrollPane(); 1765 window["ytp_pane_"+element_id] = pane.data("jsp"); 1766 1767 1768 $("#ytp_"+element_id+" .ytp-playlist .ytp-loader").remove(); 1769 } 1770 1771 /* Get Playlist Videos */ 1772 this.videos = function(videos,element_id) { 1773 window["ytp_videos_iframe_"+element_id] = videos; 1774 var videoId = (typeof(videos.items[0].snippet.resourceId)!==typeof(ytp_undefined)) ? videos.items[0].snippet.resourceId.videoId : videos.items[0].id; 1775 $("#iframe_"+element_id).data("video",videoId).removeClass("ytp-playlist-loading"); 1776 } 1777 1778 } 1779 1780 /* Generate Player Timeline */ 1781 this.timeline = function(element_id) { 1782 1783 /* Get Video Duration */ 1784 var duration = window["player_"+element_id].getDuration(); 1785 1786 /* If Video Duration is defined */ 1787 if(duration>1) { 1788 1789 /* Get Player Width */ 1790 var time_step = duration/window["width_"+element_id]; 1791 1792 /* Empty Timeline */ 1793 $("#ytp_"+element_id).find(".ytp-timeline .ytp-line-jump").html(""); 1794 1795 /* Loop for Width of Player */ 1796 for(i=0;i<window["width_"+element_id];i++) { 1797 1798 var time = Math.floor(time_step*i); 1799 1800 /* Generate Time String */ 1801 if(time>59) { 1802 var min = Math.floor((time/60)); 1803 var sec = time - (min*60); 1804 if((sec/10)<1) { 1805 sec = "0"+sec.toString(); 1806 } 1807 var time_string = min+":"+sec; 1808 } else { 1809 if((time/10)<1) { 1810 time = "0"+time.toString(); 1811 } 1812 var time_string = "0:"+time; 1813 } 1814 1815 /* Generate Timeline Element */ 1816 $("<div />", { 1817 class: "ytp-jump", 1818 title: time_string 1819 }).data("time",time).on("click",function() { 1820 window["player_"+element_id].seekTo($(this).data("time"),true); 1821 }).appendTo($("#ytp_"+element_id).find(".ytp-timeline .ytp-line-jump")); 1822 1823 } 1824 1825 /* Set Positions */ 1826 ytp.resize($("#ytp_"+element_id)); 1827 1828 1829 } else { 1830 1831 /* Try again until Video is loaded */ 1832 window.setTimeout("ytp.timeline("+element_id+")",100); 1833 1834 } 1835 } 1836 1837 /* Load Feeds via API */ 1838 this.feed = new function() { 1839 1840 this.load = function(type,id,token) { 1841 1842 token = (typeof(token)!==typeof(ytp_undefined)) ? token : false;
1843 /* Get Page Token if set */ 1844 var page = ""; 1845 if(token!=false) { 1846 page = (token!=1) ? "&pageToken="+token : ""; 1847 } 1848 1849 /* Get Feed URL */ 1850 var url = 'https://www.googleapis.com/youtube/v3/'; 1851 switch(type) { 1852 case "related": 1853 url+= 'search?relatedToVideoId='+id+page+'&part=snippet&type=video&maxResults=50'; 1854 break; 1855 case "comments": 1856 url+= 'commentThreads?videoId='+id+page+'&part=snippet&type=video&maxResults=100'; 1857 break; 1858 case "playlist": 1859 url+= 'playlistItems?playlistId='+id+page+'&part=snippet&type=video&maxResults=50'; 1860 break; 1861 case "search": 1862 url+= 'search?q='+encodeURI(id)+page+'&part=snippet&type=video&maxResults=50'; 1863 break; 1864 case "video": 1865 url+= 'videos?id='+encodeURI(id)+'&part=snippet&type=video'; 1866 break; 1867 case "info": 1868 url+= 'videos?id='+encodeURI(id)+'&part=statistics,snippet&type=video'; 1869 break; 1870 default: 1871 return false; 1872 break; 1873 } 1874 1875 return url+'&key='+ytp.config.api_key; 1876 1877 } 1878 1879 this.fail = function(data) { 1880 var error = 'An error occured while retrieving the playlist.'; 1881 if(typeof(data.responseText) !== typeof(undefined)) { 1882 var message = $.parseJSON(data.responseText); 1883 if(message.error.code == '404') { 1884 error = 'The playlist was not found.'; 1885 }else if(message.error.code == '403') { 1886 error = message.error.message; 1887 }else if(message.error.code == '400') { 1888 error = 'The API key you have entered is invalid.'; 1889 }else { 1890 error = 'An error occured while retrieving the playlist.<br /><em>'+message.error.message+'</em>'; 1891 } 1892 } 1893 console.log(error); 1894 } 1895 1896 } 1897 1898 /* Loading Screen */ 1899 this.loader = function(parent) { 1900 $("<div />", { 1901 class: "ytp-loader", 1902 }).appendTo($(parent)); 1903 for(var i=1;i<9;i++) { 1904 $("<div />", { 1905 class: "ytp-loader-loader ytp-loader-"+i, 1906 }).appendTo($(parent).find(".ytp-loader")); 1907 } 1908 } 1909 1910 /* Control Functions */ 1911 this.controls = new function() { 1912 1913 /* Show Controls */ 1914 this.show = function(element_id) { 1915 $("#ytp_"+element_id).removeClass("ytp-hide-controls"); 1916 delete window["timeout_hide_"+element_id]; 1917 } 1918 1919 /* Hide Controls */ 1920 this.hide = function(element_id) { 1921 $("#ytp_"+element_id).addClass("ytp-hide-controls"); 1922 window["timeout_hide_"+element_id] = true; 1923 window["timeout_hided_"+element_id] = true; 1924 } 1925 1926 /* Play Video */ 1927 this.play = function(element,play) { 1928 var parent = ($(element).parent().data("element")) ? $(element).parent() : $(element).parent().parent(); 1929 if(parent.find(".ytp-ad-intro").length>0) { 1930 if(window["player_"+parent.data("element")].getPlayerState()==5) { 1931 parent.find(".ytp-ad-intro").addClass("ytp-visible"); 1932 ytp.ad.timer(parent.find(".ytp-ad-intro")); 1933 if(parent.find(".ytp-ad-intro").find("video").length>0) { 1934 ytp.ad.play(parent.find(".ytp-ad-intro")); 1935 } 1936 return false; 1937 } 1938 } 1939 if(parent.find(".ytp-ad-bottom").length>0) { 1940 if(window["player_"+parent.data("element")].getPlayerState()==5) { 1941 window.setTimeout(function() { 1942 parent.find(".ytp-ad-bottom").addClass("ytp-visible"); 1943 },3000); 1944 } 1945 } 1946 parent.find(".ytp-intro").removeClass("ytp-active"); 1947 parent.find(".ytp-stop").addClass("ytp-active"); 1948 parent.find(".ytp-play-button").removeClass("ytp-active"); 1949 parent.find(".ytp-controls .ytp-play").removeClass("ytp-active"); 1950 parent.find(".ytp-controls .ytp-pause").addClass("ytp-active"); 1951 $(element).removeClass("ytp-active"); 1952 if(play===true) { 1953 if(window["player_"+parent.data("element")].getPlayerState()==5) { 1954 var config = ytp.config.element($("#"+parent.attr("id"))); 1955 /* Statistics */ 1956 if(config.ajax==true&&config.statistics==true) { 1957 ytp.statistics(parent.attr("id").replace("ytp_",""),"video","views",1); 1958 } 1959 } 1960 window["player_"+parent.data("element")].playVideo(); 1961 } 1962 } 1963 1964 /* Pause Video */ 1965 this.pause = function(element,pause) { 1966 var parent = ($(element).parent().data("element")) ? $(element).parent() : $(element).parent().parent(); 1967 if(parent.find(".ytp-ad-pause").length>0) { 1968 var no_pause_ad = false;
1969 if(parent.find(".ytp-ad-end").length>0) { 1970 if(parent.find(".ytp-ad-end").hasClass("ytp-visible")) { 1971 no_pause_ad = true; 1972 } 1973 } 1974 if(no_pause_ad===false) { 1975 parent.find(".ytp-ad-pause").addClass("ytp-visible"); 1976 ytp.ad.timer(parent.find(".ytp-ad-pause")); 1977 if(parent.find(".ytp-ad-pause").find("video").length>0) { 1978 ytp.ad.play(parent.find(".ytp-ad-pause")); 1979 } 1980 } 1981 } 1982 parent.find(".ytp-stop").removeClass("ytp-active"); 1983 parent.find(".ytp-play-button").addClass("ytp-active"); 1984 parent.find(".ytp-controls .ytp-pause").removeClass("ytp-active"); 1985 parent.find(".ytp-controls .ytp-play").addClass("ytp-active"); 1986 $(element).removeClass("ytp-active"); 1987 if(pause===true) { 1988 window["player_"+parent.data("element")].pauseVideo(); 1989 } 1990 } 1991 1992 /* 2x Speed */ 1993 this.speed = function(element,element_id) { 1994 1995 /* Clear Time Interval */ 1996 window.clearInterval(window["time_interval_"+element_id]); 1997 1998 /* 2x Speed */ 1999 var intervalTime = 500; 2000 var playbackRate = 2; 2001 $(element).find(".ytp-speed").addClass("ytp-double"); 2002 2003 /* 1x Speed */ 2004 if(window["player_"+$(element).data("element")].getPlaybackRate()==2) { 2005 intervalTime = 1000; 2006 playbackRate = 1; 2007 $(element).find(".ytp-speed").removeClass("ytp-double"); 2008 } 2009 2010 /* Set Playback Rate */ 2011 window["player_"+$(element).data("element")].setPlaybackRate(playbackRate); 2012 2013 /* Set Interval */ 2014 window["time_interval_"+element_id] = window.setInterval("ytp.timeInterval('"+element_id+"');",intervalTime); 2015 2016 /* Check for new Time */ 2017 ytp.timeInterval(element_id); 2018 2019 } 2020 2021 } 2022 2023 /* Advertisement */ 2024 this.ad = new function() { 2025 2026 /* Ad-Timer */ 2027 this.timer = function(element) { 2028 if(($(element).find(".ytp-ad-close-bottom").data("timer")*1)>0) { 2029 $(element).find(".ytp-ad-close-bottom .ytp-ad-timer").addClass("ytp-visible"); 2030 window["ad_interval_"+$(element).attr("id")] = window.setInterval(function() { 2031 var seconds = ($(element).find(".ytp-ad-close-bottom").data("timer")*1)-1; 2032 if(seconds==0) { 2033 $(element).find(".ytp-ad-close-bottom .ytp-ad-timer").removeClass("ytp-visible"); 2034 window.clearInterval(window["ad_interval_"+$(element).attr("id")]); 2035 } 2036 $(element).find(".ytp-ad-close-bottom").data("timer",seconds); 2037 $(element).find(".ytp-ad-close-bottom .ytp-ad-timer span").html(seconds); 2038 },1000); 2039 } 2040 } 2041 2042 /* Video or Iframe */ 2043 this.file = function(file) { 2044 if(file.indexOf(".mp4")>-1) { 2045 return $('<video />', { 2046 src: file, 2047 type: 'video/mp4' 2048 }); 2049 } else if(file.indexOf(".webm")>-1) { 2050 return $('<video />', { 2051 src: file, 2052 type: 'video/webm' 2053 }); 2054 } else { 2055 return $('<iframe />', { 2056 src: file 2057 }); 2058 } 2059 } 2060 2061 /* Play Video */ 2062 this.play = function(element) { 2063 element.find("video").get(0).play(); 2064 if(element.find(".ytp-ad-close-bottom").length>0) { 2065 var duration = Math.ceil(element.find("video").get(0).duration); 2066 if(element.find(".ytp-ad-close-bottom").data("timer")*1>duration) { 2067 element.find(".ytp-ad-close-bottom").data("timer",duration); 2068 element.find(".ytp-ad-close-bottom").find("span").html(duration); 2069 } 2070 } 2071 } 2072 2073 /* Close Ad */ 2074 this.close = function(element,config,element_id) { 2075 if(element.find(".ytp-ad-close-bottom").data("timer")*1>0) { 2076 var close_button = element.find(".ytp-ad-close-bottom"); 2077 close_button.addClass("ytp-ad-warning"); 2078 window.setTimeout(function() { 2079 close_button.removeClass("ytp-ad-warning"); 2080 },1000); 2081 } else { 2082 if(element.hasClass("ytp-ad-intro")) { 2083 if(element.parent().find(".ytp-ad-bottom").length>0) { 2084 var ad_bottom = element.parent().find(".ytp-ad-bottom"); 2085 window.setTimeout(function() { 2086 ad_bottom.addClass("ytp-visible"); 2087 },3000); 2088 } 2089 element.remove(); 2090 /* Statistics */ 2091 if(config.ajax==true&&config.statistics==true) { 2092 ytp.statistics(element_id,"video","views",1); 2093 } 2094 window["player_"+element_id].playVideo(); 2095 } else { 2096 element.removeClass("ytp-visible"); 2097 element.find(".ytp-ad-close-bottom").data("timer",config.ad_pause_timer); 2098 element.find(".ytp-ad-timer").find("span").html(config.ad_pause_timer); 2099 if(element.find("video").length>0) { 2100 element.find("video").get(0).pause(); 2101 } 2102 } 2103 } 2104 } 2105 2106 } 2107 2108 /* Share to social Networks */ 2109 this.share = function(button,element,network) { 2110 var config = ytp.config.element(element); 2111 var share_url = "https://youtube.com/watch/?v="+$(element).data("video"); 2112 if(config.ajax==true) { 2113 if(config.share_website==true) { 2114 var url = window.location.href; 2115 var url_arr = url.split("/"); 2116 share_url = url_arr[0]+"//"+url_arr[2]+(config.ytp_path+"/share/?v="+$(element).data("video")); 2117 } 2118 } 2119 var share = true; 2120 switch(network) { 2121 case "facebook": 2122 share_url = "https://www.facebook.com/sharer/sharer.php?u="+encodeURI(share_url); 2123 break; 2124 case "twitter": 2125 share_url = "https://twitter.com/home?status="+encodeURI(share_url); 2126 break; 2127 case "linkedin": 2128 share_url = "https://www.linkedin.com/shareArticle?mini=true&url="+encodeURI(share_url); 2129 break; 2130 case "tumblr": 2131 share_url = "http://tumblr.com/widgets/share/tool?canonicalUrl="+encodeURI(share_url); 2132 break; 2133 case "google": 2134 share_url = "https://plus.google.com/share?url="+encodeURI(share_url); 2135 break; 2136 case "email": 2137 share_url = "mailto:[email protected]?subject="+config.text.share_email_subject+"&body="+encodeURI(share_url); 2138 break; 2139 case "reddit": 2140 share_url = "http://www.reddit.com/submit?url="+encodeURI(share_url); 2141 break; 2142 case "whatsapp": 2143 share_url = "whatsapp://send?text="+encodeURI(share_url); 2144 break; 2145 } 2146 if(share===true) { 2147 button.href = share_url; 2148 } 2149 } 2150 2151 /* On Player state changed */ 2152 this.onPlayerStateChange = function(element,event) { 2153 var stop = false;
2154 var element_id = $(element).data("element"); 2155 var events = ytp.events.element(element); 2156 switch(event.data) { 2157 /* Video ended */ 2158 case 0: 2159 if($(element).find(".ytp-ad-end").length>0) { 2160 $(element).find(".ytp-ad-end").addClass("ytp-visible"); 2161 ytp.ad.timer($(element).find(".ytp-ad-end")); 2162 if($(element).find(".ytp-ad-end").find("video").length>0) { 2163 ytp.ad.play($(element).find(".ytp-ad-end")); 2164 } 2165 ytp.controls.pause($(element).find(".ytp-stop"),true); 2166 ytp.related.load($(element).data("element"),1); 2167 return false; 2168 } 2169 if(events.onEnd!==false) { 2170 if(typeof(window[events.onEnd])=="function") { 2171 window[events.onEnd](window["player_"+element_id],element); 2172 } 2173 } 2174 /* If there is a Loop */ 2175 if($("#ytp_"+element_id).hasClass("ytp-loop")) { 2176 /* Load Video */ 2177 ytp.controls.play($(element).find(".ytp-play"),true); 2178 } 2179 /* If there is a Playlist */ 2180 else if($("#ytp_"+element_id).hasClass("ytp-has-playlist")) { 2181 /* If shuffle is active */ 2182 if($("#ytp_"+element_id).hasClass("ytp-shuffle")) { 2183 var videoId = (typeof(videos.items[0].snippet.resourceId)!==typeof(ytp_undefined)) ? videos.items[0].snippet.resourceId.videoId : videos.items[0].id; 2184 var next_video = (typeof(window["ytp_videos_"+element_id].items[Math.floor(Math.random()*window["ytp_videos_"+element_id].items.length)].snippet.resourceId.videoId)!==typeof(ytp_undefined)) ? window["ytp_videos_"+element_id].items[Math.floor(Math.random()*window["ytp_videos_"+element_id].items.length)].snippet.resourceId.videoId : window["ytp_videos_"+element_id].items[Math.floor(Math.random()*window["ytp_videos_"+element_id].items.length)].id; 2185 ytp.playlist.video(element_id,next_video); 2186 } 2187 /* Next Video */ 2188 else { 2189 ytp.playlist.next(element_id); 2190 } 2191 } else { 2192 ytp.controls.pause($(element).find(".ytp-stop"),true); 2193 ytp.related.load($(element).data("element"),1); 2194 } 2195 window["ytp_player_state_"+element_id] = event.data; 2196 break; 2197 case 1: 2198 if(typeof(window["ytp_player_state_"+element_id])!==typeof(ytp_undefined)) { 2199 if(window["ytp_player_state_"+element_id]==1) { 2200 stop = true; 2201 } 2202 } 2203 if(stop===false) { 2204 if(events.onPlay!==false) { 2205 if(typeof(window[events.onPlay])=="function") { 2206 window[events.onPlay](window["player_"+element_id],element); 2207 } 2208 } 2209 } 2210 window["ytp_player_state_"+element_id] = event.data; 2211 //ytp.controls.play($(element).find(".play")[0],false); 2212 break; 2213 case 2: 2214 if(typeof(window["ytp_player_state_"+element_id])!==typeof(ytp_undefined)) { 2215 if(window["ytp_player_state_"+element_id]==2) { 2216 stop = true; 2217 } 2218 } 2219 if(stop===false) { 2220 if(events.onPause!==false) { 2221 if(typeof(window[events.onPause])=="function") { 2222 window[events.onPause](window["player_"+element_id],element); 2223 } 2224 } 2225 } 2226 window["ytp_player_state_"+element_id] = event.data; 2227 //ytp.controls.play($(element).find(".stop")[0],false); 2228 } 2229 } 2230 2231 /* If Errors are located */ 2232 this.onPlayerError = function(event,element_id) { 2233 $("#ytp_"+element_id+" .ytp-loader").remove(); 2234 $("#ytp_"+element_id).find(".ytp-time-max").html(""); 2235 switch(event.data) { 2236 case 2: 2237 // Parameters arent correct 2238 console.log("Invalid Youtube-Player-Parameter"); 2239 break; 2240 case 5: 2241 // HTML5-Player-Error 2242 console.log("HTML5 Player-Error"); 2243 break; 2244 case 100: 2245 // Video was not found (deleted or set to private) 2246 console.log("This Video was not found"); 2247 break; 2248 case 101: 2249 // The Video-Owner does not accept embedding of this Video 2250 console.log("No embedding allowed for this Video"); 2251 break; 2252 case 150: 2253 // The Video was deleted 2254 console.log("Video was deleted"); 2255 break; 2256 } 2257 } 2258 2259 /* Sound functions */ 2260 this.sound = new function() { 2261 2262 /* Generate Sound config */ 2263 this.init = function(element_id) { 2264 2265 /* For Volume 0 to 100 */ 2266 for(i=0;i<101;i++) { 2267 2268 /* Generate Sound-Volume element */ 2269 $("<div />", { 2270 class: "ytp-jump", 2271 title: i 2272 }).data("volume",i).css({ 2273 left: i+"px" 2274 }).on("click",function() { 2275 ytp.sound.change(element_id,$(this).data("volume")); 2276 }).appendTo($("#ytp_"+element_id).find(".ytp-sound-change")); 2277 2278 } 2279 2280 /* Set defined Sound-Volume */ 2281 $("#ytp_"+element_id).find(".ytp-sound-now").css("width",window["player_"+element_id].getVolume()+"px"); 2282 2283 /* Set Icon */ 2284 ytp.sound.icon(element_id,false); 2285 2286 } 2287 2288 /* Set Icon */ 2289 this.icon = function(element_id,volume) { 2290 var volume = (volume===false) ? window["player_"+element_id].getVolume() : volume; 2291 var element = $("#ytp_"+element_id+" .ytp-sound"); 2292 element.removeClass("ytp-volume-0"); 2293 element.removeClass("ytp-volume-1"); 2294 element.removeClass("ytp-volume-2"); 2295 if(volume==0) { 2296 element.addClass("ytp-volume-0"); 2297 } else if(volume<30) { 2298 element.addClass("ytp-volume-1"); 2299 } else if(volume<70) { 2300 element.addClass("ytp-volume-2"); 2301 } 2302 } 2303
2304 /* Change Volume */ 2305 this.change = function(element_id,volume) { 2306 2307 /* Set Volume */ 2308 window["player_"+element_id].setVolume(volume); 2309 $("#ytp_"+element_id).find(".ytp-sound-now").css("width",volume+"px"); 2310 2311 /* Set Backup */ 2312 if(volume!=0) { 2313 $("#ytp_"+element_id).find(".ytp-volume-backup").val(volume); 2314 } 2315 2316 /* Set Icon */ 2317 ytp.sound.icon(element_id,volume); 2318 2319 } 2320 2321 } 2322 2323 /* Fires every Second (every 500ms for double Time) */ 2324 this.timeInterval = function(element_id) { 2325 2326 /* If Player is ready */ 2327 if(typeof(window["player_"+element_id].getCurrentTime())!==typeof(ytp_undefined)) { 2328 2329 /* If video was loaded */ 2330 if(window["player_"+element_id].getDuration()>0) { 2331 2332 /* Player Bytes loaded */ 2333 $("#ytp_"+element_id).find(".ytp-line-loaded").css("width",(window["player_"+element_id].getVideoLoadedFraction()*100)+"%"); 2334 2335 /* Player Config */ 2336 var config = ytp.config.element($("#ytp_"+element_id)); 2337 2338 /* Current Time */ 2339 var currentTime = Math.ceil(window["player_"+element_id].getCurrentTime()); 2340 2341 /* Check for Time Change */ 2342 if(config.ajax==true&&config.statistics==true) { 2343 if(currentTime!=$("#ytp_"+element_id).find(".ytp-last-time").val()) { 2344 var time_watched = ($("#ytp_"+element_id).find(".ytp-time-counter").val()*1)+1; 2345 if(time_watched>=config.play_time*1) { 2346 ytp.statistics(element_id,"video","play_time",time_watched); 2347 time_watched = 0; 2348 } 2349 $("#ytp_"+element_id).find(".ytp-time-counter").val(time_watched); 2350 } 2351 $("#ytp_"+element_id).find(".ytp-last-time").val(currentTime); 2352 } 2353 2354 /* Video Duration */ 2355 var duration = window["player_"+element_id].getDuration(); 2356 2357 /* Video Width */ 2358 var width = window["width_"+element_id]/duration; 2359 2360 /* Set Width of active Timeline */ 2361 $("#ytp_"+element_id).find(".ytp-line-active").css("width",(currentTime*width)+"px"); 2362 2363 /* If current Time is more than one Minute */ 2364 if(currentTime>59) { 2365 2366 /* Minutes */ 2367 var minutes = Math.floor((currentTime/60)); 2368 2369 /* Seconds */ 2370 var seconds = currentTime - (minutes*60); 2371 if((seconds/10)<1) { 2372 seconds = "0"+seconds.toString(); 2373 } 2374 2375 /* Current Time String */ 2376 currentTime = minutes+":"+seconds; 2377 2378 } else { 2379 2380 /* If Video just startet (< 10 seconds) */ 2381 if((currentTime/10)<1) { 2382 currentTime = "0"+currentTime.toString(); 2383 } 2384 2385 /* Current Time String */ 2386 currentTime = "0:"+currentTime; 2387 2388 } 2389 2390 /* Change Time */ 2391 $("#ytp_"+element_id).find(".ytp-time").html(currentTime); 2392 2393 /* Check maximum Time */ 2394 if( 2395 $("#ytp_"+element_id).find(".ytp-time-max").html()==""|| 2396 $("#ytp_"+element_id).find(".ytp-time-max").html()=="0"|| 2397 $("#ytp_"+element_id).find(".ytp-time-max").html()=="-" 2398 ) { 2399 2400 /* Maximum Time */ 2401 var maxTime = Math.ceil(window["player_"+element_id].getDuration()); 2402 2403 /* If max Time is more than one Minute */ 2404 if(maxTime>59) { 2405 2406 /* Minutes */ 2407 var minutes = Math.floor((maxTime/60)); 2408 2409 /* Seconds */ 2410 var seconds = maxTime - (minutes*60); 2411 if((seconds/10)<1) { 2412 seconds = "0"+seconds.toString(); 2413 } 2414 2415 /* Max Time String */ 2416 maxTime = minutes+":"+seconds; 2417 2418 } else { 2419 2420 /* Max Time String */ 2421 maxTime = "0:"+maxTime; 2422 2423 } 2424 2425 /* If a new Video was loaded into Video-Player */ 2426 if($("#ytp_"+element_id).find(".ytp-time-max").html()=="-") { 2427 2428 /* Create new Timeline */ 2429 ytp.timeline(element_id); 2430 2431 /* Remove Loader */ 2432 $("#ytp_"+element_id+" .ytp-loader").remove(); 2433 2434 } 2435 2436 /* Set maximum Time */ 2437 $("#ytp_"+element_id).find(".ytp-time-max").html(maxTime); 2438 } 2439 2440 /* If Video was paused via Youtube-Iframe */ 2441 if(window["player_"+element_id].getPlayerState()==2&&$("#ytp_"+element_id).find(".ytp-pause").hasClass("ytp-active")) { 2442 ytp.controls.pause($("#ytp_"+element_id).find(".ytp-pause"),true); 2443 } 2444 2445 /* If Video was started via Youtube-Iframe */ 2446 else if(window["player_"+element_id].getPlayerState()==1&&$("#ytp_"+element_id).find(".ytp-play").hasClass("ytp-active")) { 2447 ytp.controls.play($("#ytp_"+element_id).find(".ytp-play"),true); 2448 } 2449 2450 } 2451 } 2452 } 2453 2454 this.comments = new function() { 2455 2456 this.load = function(element_id,page) { 2457 2458 /* Load Config */ 2459 var config = ytp.config.element($("#ytp_"+element_id)); 2460 2461 if((config.ajax==true||config.api_key!=false)&&config.comments==true) { 2462 2463 $("#ytp_"+element_id+" .ytp-comments-wrap").addClass("ytp-visible"); 2464 $("#ytp_"+element_id+" .ytp-comments").addClass("ytp-visible"); 2465 if(page!=1) { 2466 $("#ytp_"+element_id+" .ytp-comments-wrap .ytp-button").remove(); 2467 } else { 2468 if($("#ytp_"+element_id+" .ytp-comments-wrap .ytp-scroll-pane").length>0) { 2469 return false;
2470 } 2471 } 2472 ytp.loader($("#ytp_"+element_id+" .ytp-comments-wrap")); 2473 2474 if(config.ajax==true) { 2475 $.ajax({ 2476 method: "POST", 2477 url: ytp.config.ytp_path+"/php/ajax.php", 2478 data: { id: $("#ytp_"+element_id).data("video"), page: page, method: "feed", type: "comments" } 2479 }) 2480 .done(function( json ) { 2481 console.log(json); 2482 var comments = JSON.parse(json); 2483 ytp.comments.show(element_id,comments,page); 2484 }); 2485 } 2486 /* Check for API-Key */ 2487 else if(config.api_key!=false) { 2488 var feed_url = ytp.feed.load("comments",$("#ytp_"+element_id).data("video"),page); 2489 var yt = $.getJSON(feed_url, function(comments) { 2490 ytp.comments.show(element_id,comments,page); 2491 }); 2492 yt.fail(function(data) { 2493 ytp.feed.fail(data); 2494 }); 2495 } 2496 } 2497 2498 } 2499 2500 this.show = function(element_id,comments,page) { 2501 /* Load Config */ 2502 var config = ytp.config.element($("#ytp_"+element_id)); 2503 if(page==1) { 2504 $("<div />", { 2505 class: "ytp-scroll-pane" 2506 }).appendTo($("#ytp_"+element_id+" .ytp-comments-wrap")); 2507 var element = $("#ytp_"+element_id+" .ytp-comments-wrap .ytp-scroll-pane"); 2508 } else { 2509 var element = $("#ytp_"+element_id+" .ytp-comments-wrap .ytp-scroll-pane .jspPane"); 2510 } 2511 $.each(comments.items,function() { 2512 $("<div />", { 2513 class: "ytp-comment" 2514 }) 2515 .append( 2516 $("<a />", { 2517 class: "ytp-author", 2518 target: "_blank", 2519 href: this.snippet.topLevelComment.snippet.authorChannelUrl 2520 }) 2521 .html(this.snippet.topLevelComment.snippet.authorDisplayName) 2522 ) 2523 .append( 2524 $("<div />", { 2525 class: "ytp-text" 2526 }) 2527 .html(this.snippet.topLevelComment.snippet.textDisplay) 2528 ) 2529 .appendTo(element); 2530 }); 2531 $.each($("#ytp_"+element_id+" .ytp-comments-wrap .ytp-text a"),function() { 2532 if(!$(this).hasClass("ytp-comment-changed")) { 2533 $(this).attr("target","_blank"); 2534 if(this.href.indexOf("&t=")>-1) { 2535 $(this).on("click",function(e) { 2536 e.preventDefault(); 2537 var url_array = this.href.split("&t="); 2538 var url_sub_array = url_array[1].split("h"); 2539 if(typeof(url_sub_array[1])!==typeof(ytp_undefined)) { 2540 var time_array = url_sub_array[1].split("m"); 2541 if(typeof(time_array[1])!==typeof(ytp_undefined)) { 2542 var time_sub_array = time_array[1].split("&"); 2543 var seconds = time_sub_array[0].replace("s",""); 2544 var time = (url_sub_array[0]*60*60)+(time_array[0].replace("m","")*60+seconds*1); 2545 } else { 2546 var time_sub_array = time_array[0].split("&"); 2547 var time = (url_sub_array[0]*60*60)+time_sub_array[0].replace("s",""); 2548 } 2549 } else { 2550 var time_array = url_array[1].split("m"); 2551 if(typeof(time_array[1])!==typeof(ytp_undefined)) { 2552 var time_sub_array = time_array[1].split("&"); 2553 var seconds = time_sub_array[0].replace("s",""); 2554 var time = (time_array[0]*60+seconds*1); 2555 } else { 2556 var time_sub_array = time_array[0].split("&"); 2557 var time = time_sub_array[0].replace("s",""); 2558 } 2559 } 2560 window["player_"+element_id].seekTo(time,true); 2561 window["player_"+element_id].playVideo(); 2562 $("#ytp_"+element_id+" .ytp-comments-wrap").removeClass("ytp-visible"); 2563 $("#ytp_"+element_id+" .ytp-comments").removeClass("ytp-visible"); 2564 }); 2565 } else if(this.href.indexOf("?search_query=")>-1) { 2566 if(config.search==true) { 2567 $(this).on("click",function(e) { 2568 e.preventDefault(); 2569 var url_array = this.href.split("?search_query="); 2570 var url_sub_array = url_array[1].split("&"); 2571 var query = url_sub_array[0].replace("%23",""); 2572 $("#ytp_"+element_id+" .ytp-comments-wrap").removeClass("ytp-visible"); 2573 $("#ytp_"+element_id+" .ytp-comments").removeClass("ytp-visible"); 2574 $("#ytp_"+element_id+" .ytp-controls .ytp-search").trigger("click"); 2575 window.setTimeout(function() { 2576 $("#ytp_"+element_id+" .ytp-search-wrap input").val(query); 2577 ytp.search.load(element_id,1); 2578 },100); 2579 }); 2580 } 2581 } 2582 $(this).addClass("ytp-comment-changed"); 2583 } 2584 }); 2585 if(config.comments_more==true) { 2586 if(typeof(comments.nextPageToken)!==typeof(ytp_undefined)) { 2587 $("<div />", { 2588 class: "ytp-button" 2589 }) 2590 .on("click",function() { 2591 ytp.comments.load(element_id,comments.nextPageToken); 2592 }) 2593 .html(config.text.comments_more) 2594 .appendTo(element); 2595 } 2596 } 2597 $("#ytp_"+element_id+" .ytp-comments-wrap .ytp-loader").remove(); 2598 $("#ytp_"+element_id+" .ytp-comments-wrap .ytp-scroll-pane").jScrollPane({autoReinitialise: true, contentWidth: '0p
2598x'}); 2599 2600 /* Statistics */ 2601 if(config.statistics==true) { 2602 ytp.statistics(element_id,"video","comments",1); 2603 } 2604 } 2605 2606 } 2607 2608 this.related = new function() { 2609 2610 this.load = function(element_id,page) { 2611 2612 /* Load Config */ 2613 var config = ytp.config.element($("#ytp_"+element_id)); 2614 2615 if((config.ajax==true||config.api_key!=false)&&config.related==true) { 2616 2617 if($("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane").length==0) { 2618 $("#ytp_"+element_id+" .ytp-related").addClass("ytp-visible"); 2619 $("#ytp_"+element_id+" .ytp-related-wrap").addClass("ytp-visible"); 2620 } 2621 if(page!=1) { 2622 $("#ytp_"+element_id+" .ytp-related-wrap .ytp-button").remove(); 2623 } else { 2624 if($("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane").length>0) { 2625 return false; 2626 } 2627 } 2628 ytp.loader($("#ytp_"+element_id+" .ytp-related-wrap")); 2629 2630 if(config.ajax==true) { 2631 $.ajax({ 2632 method: "POST", 2633 url: ytp.config.ytp_path+"/php/ajax.php", 2634 data: { id: $("#ytp_"+element_id).data("video"), page: page, method: "feed", type: "related" } 2635 }) 2636 .done(function( json ) { 2637 var videos = JSON.parse(json); 2638 ytp.related.show(element_id,videos,page); 2639 }); 2640 } 2641 /* Check for API-Key */ 2642 else if(config.api_key!=false) { 2643 var feed_url = ytp.feed.load("related",$("#ytp_"+element_id).data("video"),page); 2644 var yt = $.getJSON(feed_url, function(videos) { 2645 ytp.related.show(element_id,videos,page); 2646 }); 2647 yt.fail(function(data) { 2648 ytp.feed.fail(data); 2649 }); 2650 } 2651 2652 } 2653 2654 } 2655 2656 this.show = function(element_id,videos,page) { 2657 /* Load Config */ 2658 var config = ytp.config.element($("#ytp_"+element_id)); 2659 var element = $("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane .jspPane"); 2660 if(page==1) { 2661 $("<div />", { 2662 class: "ytp-scroll-pane" 2663 }).appendTo($("#ytp_"+element_id+" .ytp-related-wrap")); 2664 element = $("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane"); 2665 } 2666 $.each(videos.items,function() { 2667 /* Default Thumbnail */ 2668 var thumbnail = (typeof(this.snippet.thumbnails)!==typeof(ytp_undefined)) ? this.snippet.thumbnails.high.url : "#"; 2669 /* High Quality Image */ 2670 // var thumbnail = "https://img.youtube.com/vi/"+this.id.videoId+"/maxresdefault.jpg"; 2671 $("<div />", { 2672 class: "ytp-video" 2673 }) 2674 .css("background-image","url('"+thumbnail+"')") 2675 .on("click",function() { 2676 $("#ytp_"+element_id).data("video",$(this).data("video")); 2677 if($("#ytp_"+element_id).hasClass("ytp-has-playlist")) { 2678 $("#ytp_"+element_id).removeClass("ytp-has-playlist"); 2679 $("#ytp_"+element_id).removeClass("ytp-playlist-visible"); 2680 } 2681 ytp.video($("#ytp_"+element_id),this); 2682 }) 2683 .data("video",this.id.videoId) 2684 .append( 2685 $("<div />", { 2686 class: "ytp-title" 2687 }) 2688 .html(this.snippet.title) 2689 ) 2690 .append( 2691 $("<div />", { 2692 class: "ytp-description" 2693 }) 2694 .html(this.snippet.description) 2695 ) 2696 .appendTo(element); 2697 }); 2698 if(config.related_more==true) { 2699 if(typeof(videos.nextPageToken)!==typeof(ytp_undefined)) { 2700 $("<div />", { 2701 class: "ytp-button" 2702 }) 2703 .on("click",function() { 2704 ytp.related.load(element_id,videos.nextPageToken); 2705 }) 2706 .html(config.text.related_more) 2707 .appendTo(element); 2708 } 2709 } 2710 $("#ytp_"+element_id+" .ytp-related-wrap .ytp-loader").remove(); 2711 $("#ytp_"+element_id+" .ytp-related-wrap .ytp-scroll-pane").jScrollPane({autoReinitialise: true, contentWidth: '0px'}); 2712 2713 /* Statistics */ 2714 if(config.statistics==true) { 2715 ytp.statistics(element_id,"video","related",1); 2716 } 2717 } 2718 2719 } 2720 2721 this.search = new function() { 2722 2723 this.load = function(element_id,page) { 2724 2725 /* Load Config */ 2726 var config = ytp.config.element($("#ytp_"+element_id)); 2727 2728 if((config.ajax==true||config.api_key!=false)&&config.search==true) { 2729 2730 if(!$("#ytp_"+element_id+" .ytp-search-wrap").hasClass("ytp-active-search")) { 2731 $("#ytp_"+element_id+" .ytp-search-wrap").addClass("ytp-active-search"); 2732 } else { 2733 if(page==1) { 2734 $("#ytp_"+element_id+" .ytp-search-wrap .ytp-scroll-pane").remove(); 2735 } else { 2736 $("#ytp_"+element_id+" .ytp-search-wrap .ytp-button").remove(); 2737 } 2738 } 2739 ytp.loader($("#ytp_"+element_id+" .ytp-search-wrap")); 2740 2741 if(config.ajax==true) { 2742 $.ajax({ 2743 method: "POST", 2744 url: ytp.config.ytp_path+"/php/ajax.php", 2745 data: { id: $("#ytp_"+element_id+" .ytp-search-wrap input").val(), page: page, method: "feed", type: "search" } 2746 }) 2747 .done(function( json ) { 2748 var videos = JSON.parse(json); 2749 ytp.search.show(element_id,videos,page); 2750 }); 2751 } 2752 /* Check for API-Key */ 2753 else if(config.api_key!=false) { 2754 var feed_url = ytp.feed.load("search",$("#ytp_"+element_id+" .ytp-search-wrap input").val(),page); 2755 var yt = $.getJSON(feed_url, function(videos) { 2756 ytp.search.show(element_id,videos,page); 2757 }); 2758 yt.fail(function(data) { 2759 ytp.feed.fail(data); 2760 }); 2761 } 2762 2763 } 2764 2765 this.show = function(element_id,results,page) { 2766 2767 /* Load Config */ 2768 var config = ytp.config.element($("#ytp_"+element_id)); 2769 2770 if(page==1) { 2771 $("<div />", { 2772 class: "ytp-scroll-pane" 2773 }).appendTo($("#ytp_"+element_id+" .ytp-search-wrap")); 2774 var element = $("#ytp_"+element_id+" .ytp-search-wrap .ytp-scroll-pane"); 2775 } else { 2776 var element = $("#ytp_"+element_id+" .ytp-search-wrap .ytp-scroll-pane .jspPane"); 2777 } 2778 $.each(results.items,function() {
2779 /* Default Thumbnail */ 2780 var thumbnail = (typeof(this.snippet.thumbnails)!==typeof(ytp_undefined)) ? this.snippet.thumbnails.high.url : "#"; 2781 /* High Quality Image */ 2782 // var thumbnail = "https://img.youtube.com/vi/"+this.id.videoId+"/maxresdefault.jpg"; 2783 $("<div />", { 2784 class: "ytp-video" 2785 }) 2786 .css("background-image","url('"+thumbnail+"')") 2787 .on("click",function() { 2788 $("#ytp_"+element_id).data("video",$(this).data("video")); 2789 if($("#ytp_"+element_id).hasClass("ytp-has-playlist")) { 2790 $("#ytp_"+element_id).removeClass("ytp-has-playlist"); 2791 $("#ytp_"+element_id).removeClass("ytp-playlist-visible"); 2792 } 2793 ytp.video($("#ytp_"+element_id),this); 2794 }) 2795 .data("video",this.id.videoId) 2796 .append( 2797 $("<div />", { 2798 class: "ytp-title" 2799 }) 2800 .html(this.snippet.title) 2801 ) 2802 .append( 2803 $("<div />", { 2804 class: "ytp-description" 2805 }) 2806 .html(this.snippet.description) 2807 ) 2808 .appendTo(element); 2809 }); 2810 if(config.search_more==true) { 2811 if(typeof(results.nextPageToken)!==typeof(ytp_undefined)) { 2812 $("<div />", { 2813 class: "ytp-button" 2814 }) 2815 .on("click",function() { 2816 ytp.search.load(element_id,results.nextPageToken); 2817 }) 2818 .html(config.text.search_more) 2819 .appendTo(element); 2820 } 2821 } 2822 $("#ytp_"+element_id+" .ytp-search-wrap .ytp-scroll-pane").jScrollPane({autoReinitialise: true, contentWidth: '0px'}); 2823 $("#ytp_"+element_id+" .ytp-search-wrap .ytp-loader").remove(); 2824 2825 /* Statistics */ 2826 if(config.statistics==true) { 2827 ytp.statistics(element_id,"video","search",1); 2828 } 2829 } 2830 2831 } 2832 2833 } 2834 2835 2836 this.info = new function() { 2837 2838 this.load = function(element_id) { 2839 2840 /* Load Config */ 2841 var config = ytp.config.element($("#ytp_"+element_id)); 2842 2843 if($("#ytp_"+element_id+" .ytp-info-wrap").hasClass("ytp-visible")) { 2844 2845 $("#ytp_"+element_id+" .ytp-info-wrap").removeClass("ytp-visible"); 2846 $("#ytp_"+element_id+" .ytp-info").removeClass("ytp-active"); 2847 2848 } else { 2849 2850 /* Set highest z-Index for this Element */ 2851 $("#ytp_"+element_id+" .ytp-z-index").removeClass("ytp-z-index"); 2852 $("#ytp_"+element_id+" .ytp-info-wrap").addClass("ytp-z-index"); 2853 2854 $("#ytp_"+element_id+" .ytp-info-wrap").addClass("ytp-visible"); 2855 $("#ytp_"+element_id+" .ytp-info").addClass("ytp-active"); 2856 2857 if($("#ytp_"+element_id+" .ytp-info-wrap .ytp-scroll-pane").length==0) { 2858 2859 if((config.ajax==true||config.api_key!=false)&&config.info==true) { 2860 2861 ytp.loader($("#ytp_"+element_id+" .ytp-info-wrap")); 2862 2863 if(config.ajax==true) { 2864 $.ajax({ 2865 method: "POST", 2866 url: ytp.config.ytp_path+"/php/ajax.php", 2867 data: { id: $("#ytp_"+element_id).data("video"), page: 1, method: "feed", type: "info" } 2868 }) 2869 .done(function( json ) { 2870 var results = JSON.parse(json); 2871 ytp.info.show(element_id,results); 2872 }); 2873 } else if(config.api_key!=false) { 2874 var feed_url = ytp.feed.load("info",$("#ytp_"+element_id).data("video")); 2875 var yt = $.getJSON(feed_url, function(results) { 2876 ytp.info.show(element_id,results); 2877 }); 2878 yt.fail(function(data) { 2879 ytp.feed.fail(data); 2880 }); 2881 } 2882 2883 } 2884 } 2885 } 2886 2887 } 2888 2889 this.show = function(element_id,results) { 2890 2891 /* Load Config */ 2892 var config = ytp.config.element($("#ytp_"+element_id)); 2893 2894 $("<div />", { 2895 class: "ytp-scroll-pane" 2896 }).append( 2897 $("<div />", { 2898 class: "ytp-info-title" 2899 }).html(results.items[0].snippet.title) 2900 ).append( 2901 $("<div />", { 2902 class: "ytp-info-title-locale" 2903 }).html(results.items[0].snippet.localized.title) 2904 ).append( 2905 $("<div />", { 2906 class: "ytp-info-description" 2907 }).html(results.items[0].snippet.description) 2908 ).append( 2909 $("<div />", { 2910 class: "ytp-info-description-locale" 2911 }).html(results.items[0].snippet.localized.description) 2912 ).append( 2913 $("<a />", { 2914 class: "ytp-info-channel", 2915 href: "https://youtube.com/c/"+results.items[0].snippet.channelId, 2916 target: "_blank" 2917 }).html(config.text.info_channel+": "+results.items[0].snippet.channelTitle) 2918 ).append( 2919 $("<ul />", { 2920 class: "ytp-info-tags" 2921 }) 2922 ).append( 2923 $("<ul />", { 2924 class: "ytp-info-stats" 2925 }) 2926 .append($("<li />", { 2927 class: "ytp-info-views" 2928 }).html(results.items[0].statistics.viewCount+" "+config.text.statistic_views)) 2929 .append($("<li />", { 2930 class: "ytp-info-likes" 2931 }).html(results.items[0].statistics.likeCount+" "+config.text.statistic_likes)) 2932 .append($("<li />", { 2933 class: "ytp-info-dislikes" 2934 }).html(results.items[0].statistics.dislikeCount+" "+config.text.statistic_dislikes)) 2935 .append($("<li />", { 2936 class: "ytp-info-comments" 2937 }).html(results.items[0].statistics.commentCount+" "+config.text.statistic_comments)) 2938 ).appendTo($("#ytp_"+element_id+" .ytp-info-wrap")); 2939 2940 if(results.items[0].snippet.localized.title==results.items[0].snippet.title) { 2941 $("#ytp_"+element_id+" .ytp-info-title-locale").remove(); 2942 } 2943 2944 if(results.items[0].snippet.localized.description==results.items[0].snippet.description) { 2945 $("#ytp_"+element_id+" .ytp-info-description-locale").remove(); 2946 } 2947 2948 $.each(results.items[0].snippet.tags,function() { 2949 var tag = this; 2950 $("<li />") 2951 .html(tag) 2952 .on("click",function() { 2953 if(config.search==true) { 2954 $("#ytp_"+element_id+" .ytp-info-wrap").removeClass("ytp-visible"); 2955 $("#ytp_"+element_id+" .ytp-info").removeClass("ytp-active"); 2956 $("#ytp_"+element_id+" .ytp-controls .ytp-search").trigger("click"); 2957 window.setTimeout(function() { 2958 $("#ytp_"+element_id+" .ytp-search-wrap input").val(tag); 2959 ytp.search.load(element_id,1); 2960 },100); 2961 } 2962 }) 2963 .appendTo($("#ytp_"+element_id+" .ytp-info-wrap .ytp-info-tags")); 2964 }); 2965 2966 $("#ytp_"+element_id+" .ytp-info-wrap .ytp-scroll-pane").jScrollPane({autoReinitialise: true, contentWidth: '0p
2966x'}); 2967 $("#ytp_"+element_id+" .ytp-info-wrap .ytp-loader").remove(); 2968 2969 /* Statistics */ 2970 if(config.statistics==true) { 2971 ytp.statistics(element_id,"video","info",1); 2972 } 2973 } 2974 2975 } 2976 2977 this.fullscreen = function(element_id) { 2978 if($("#ytp_"+element_id).hasClass("ytp-fullscreen")) { 2979 ytp.fullscreen_exit(element_id); 2980 /* Cancel Fullscreen Mode */ 2981 if(document.exitFullscreen) { 2982 document.exitFullscreen(); 2983 } else if(document.msExitFullscreen) { 2984 document.msExitFullscreen(); 2985 } else if(document.mozCancelFullScreen) { 2986 document.mozCancelFullScreen(); 2987 } else if(document.webkitCancelFullScreen) { 2988 document.webkitCancelFullScreen(); 2989 } 2990 } else { 2991 window["width_backup_"+element_id] = window["width_"+element_id]; 2992 window["width_"+element_id] = $(window).width(); 2993 $("#ytp_"+element_id).addClass("ytp-fullscreen"); 2994 $(document.body).addClass("ytp-fullscreen").data("ytp-element",element_id); 2995 /* Request Fullscreen Mode */ 2996 if(document.documentElement.requestFullscreen) { 2997 document.documentElement.requestFullscreen(); 2998 } else if(document.documentElement.mozRequestFullScreen) { 2999 document.documentElement.mozRequestFullScreen(); 3000 } else if(document.documentElement.msRequestFullscreen) { 3001 document.documentElement.msRequestFullscreen(); 3002 } else if(document.documentElement.webkitRequestFullscreen) { 3003 document.documentElement.webkitRequestFullscreen(); 3004 } 3005 /* Change Timeline */ 3006 ytp.timeline(element_id); 3007 ytp.timeInterval(element_id); 3008 window.setTimeout(function() { 3009 /* Add Listener for Exit */ 3010 if(typeof(window["fullscreen_"+element_id])===typeof(ytp_undefined)) { 3011 window["fullscreen_"+element_id] = true; 3012 document.addEventListener('webkitfullscreenchange', ytp.fullscreen_exit, false); 3013 document.addEventListener('mozfullscreenchange', ytp.fullscreen_exit, false); 3014 document.addEventListener('fullscreenchange', ytp.fullscreen_exit, false); 3015 document.addEventListener('MSFullscreenChange', ytp.fullscreen_exit, false); 3016 } 3017 }, 1000); 3018 } 3019 ytp.resize($("#ytp_"+element_id)); 3020 } 3021 3022 this.fullscreen_exit = function() { 3023 var element_id = $(document.body).data("ytp-element"); 3024 document.removeEventListener("webkitfullscreenchange",ytp.fullscreen_exit); 3025 document.removeEventListener("mozfullscreenchange",ytp.fullscreen_exit); 3026 document.removeEventListener("fullscreenchange",ytp.fullscreen_exit); 3027 document.removeEventListener("MSFullscreenChange",ytp.fullscreen_exit); 3028 window["width_"+element_id] = window["width_backup_"+element_id]; 3029 $("#ytp_"+element_id).removeClass("ytp-fullscreen"); 3030 $(document.body).removeClass("ytp-fullscreen"); 3031 ytp.timeline(element_id); 3032 ytp.timeInterval(element_id); 3033 ytp.resize($("#ytp_"+element_id)); 3034 delete window["fullscreen_"+element_id]; 3035 } 3036 3037 this.popup = function(element_id) { 3038 window.open("http://www.youtube.com/embed/"+$("#ytp_"+element_id).data("video")+"/?autoplay=1","youtube_Popup","width="+$(window).width()/2+",height="+$(window).height()/2+",left="+$(window).width()/4+",top="+$(window).height()/4); 3039 } 3040 3041 this.idGenerator = function() { 3042 var S4 = function() { 3043 return (((1+Math.random())*0x10000)|0).toString(16).substring(1); 3044 }; 3045 return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()); 3046 } 3047 3048 this.isMobile = function() { 3049 if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) { 3050 return true; 3051 } else { 3052 return false; 3053 } 3054 } 3055 3056} 3057 3058/* jQuery Function */ 3059$.fn.ytp = function (attributes) { 3060 3061 attributes = (typeof(attributes)!==typeof(ytp_undefined)) ? attributes : false; 3062 3063 /* Check if YoTuP is initiated already */ 3064 if(typeof(window["ytp_initiated"])===typeof(ytp_undefined)) { 3065 ytp.init(attributes); 3066 } 3067 3068 /* Run through all Elements */ 3069 if(typeof(YT)!==typeof(ytp_undefined)) { 3070 if(typeof(YT.Player)!==typeof(ytp_undefined)) { 3071 $.each(this,function() { 3072 3073 /* Set Attributes */ 3074 3075 var element = this; 3076 3077 window["ytp_attributes"] = attributes; 3078 3079 /* Look for Config */ 3080 if(typeof(window["ytp_attributes"].config)!==typeof(ytp_undefined)) { 3081 3082 /* Look for Mode */ 3083 if(typeof(window["ytp_attributes"].config.mode)!==typeof(ytp_undefined)) { 3084 3085 /* Setup Attributes */ 3086 $.each(window["ytp"]["config"]["mode"][window["ytp_attributes"].config.mode],function(key,value) { 3087 window["ytp_attributes"]["config"][key] = value; 3088 }); 3089 3090 } 3091 3092 /* Check for Attributes */ 3093 $.each(ytp.config,function(key,value) { 3094 if(typeof(window["ytp_attributes"]["config"][key])!==typeof(ytp_undefined)) $(element).data(key,window["ytp_attributes"]["config"][key]); 3095 }); 3096 3097 } 3098 3099 /* Look for Events */ 3100 if(typeof(window["ytp_attributes"].events)!==typeof(ytp_undefined)) { 3101 3102 /* onReady */ 3103 if(typeof(window["ytp_attributes"].events.onReady)!==typeof(ytp_undefined)) $(element).data("onready",window["ytp_attributes"].events.onReady); 3104 3105 /* onPlay */ 3106 if(typeof(window["ytp_attributes"].events.onPlay)!==typeof(ytp_undefined)) $(element).data("onplay",window["ytp_attributes"].events.onPlay); 3107 3108 /* onPause */ 3109 if(typeof(window["ytp_attributes"].events.onPause)!==typeof(ytp_undefined)) $(element).data("onpause",window["ytp_attributes"].events.onPause); 3110 3111 /* onEnd */ 3112 if(typeof(window["ytp_attributes"].events.onEnd)!==typeof(ytp_undefined)) $(element).data("onend",window["ytp_attributes"].events.onEnd); 3113 3114 } 3115 3116 delete window["ytp_attributes"]; 3117 3118 /* Check for ClassName "ytp" */ 3119 if(!$(this).hasClass("ytp")) { 3120 $(this).addClass("ytp"); 3121 } 3122 /* Load Player */ 3123 ytp.load(this); 3124 }); 3125 } else { 3126 jQueryElements = this; 3127 window.setTimeout(function() { 3128 $(jQueryElements).ytp(attributes); 3129 },200); 3130 } 3131 } else { 3132 jQueryElements = this; 3133 window.setTimeout(function() { 3134 $(jQueryElements).ytp(attributes); 3135 },200); 3136 } 3137 3138}; 3139 3140/* Callback for the Youtube-Iframe-API */ 3141function onYouTubeIframeAPIReady() { 3142 3143 /* Tell YTP that we a ready */ 3144 ytp.ready(); 3145 3146}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.