Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src='http://code.jquery.com/jquery-latest.js' type='text/javascript'></script>
- <script type='text/javascript'>
- //<![CDATA[
- // تضمين فيديوهات اليوتيوب داخل تعليقات بلوجر وداخل الموضوعات by MS-potilas 2012.
- // See http://abu-iyad.com
- //
- // if oetag=0, just use video urls like:
- // https://www.youtube.com/watch?v=FI_l43NxgcU
- // surrounded by white space (video tag can be used, too)
- // if oetag=1 (for nerdy blogs?), use syntax:
- // [video=https://www.youtube.com/watch?v=FI_l43NxgcU]
- // config:
- var oetag = 0; // see above
- var oetagname = "video"; // [video=zzz], maybe you like "embed" or "youtube" more?
- var oelazy = -1; // -1 detect, 0 = normal, 1 = lazy (needs lazy load hack)
- //
- function oe_loadscript(filename) {
- var scr=document.createElement('script');
- scr.setAttribute("type","text/javascript");
- scr.setAttribute("src",filename);
- document.getElementsByTagName("head")[0].appendChild(scr);
- }
- function oe_jumptohash() { // reposition to anchor
- window.scrollTo(0, $("#"+window.location.hash.replace(/^#/, "")).offset().top);
- }
- var oe_tid;
- var oe_elems = {};
- //
- function oembed_callback(response) {
- var resp = response;
- revurl = resp.url.split("").reverse().join("");
- html = oe_elems[response.callID].html();
- ee = $(resp.html);
- w = parseInt(ee.attr("width"));
- h = parseInt(ee.attr("height"));
- if(oelazy==1) { // convert to lazy load
- src = ee.attr("src");
- src += ((src.indexOf("?")==-1) ? "?" : "&") + "autoplay=1";
- ee.attr("src", src);
- ee.attr("style", "vertical-align:top;");
- htm = $("<div/>").append(ee).html();
- htm = $('<div/>').text(htm).html().replace(/"/g,'"');
- resp.html = '<a href="'+resp.url+'" class="youtube-lazy-link" style="width: '+w+'px; height: '+h+'px; background: #000) center center no-repeat;" onclick="$(this).replaceWith(\''+htm+'\');return false;"><div style="width:'+(w-4)+'px;height:'+(h-4)+'px;" class="youtube-lazy-link-div"></div><div class="youtube-lazy-link-info"></div></a>';
- }
- htmlx = html.replace(new RegExp("\\[" + oetagname + "="+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+"\\]"), " " + resp.url + " ");
- htmlx = htmlx.replace(new RegExp("\\[" + oetagname + "="+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+" \\]"), " " + resp.url + " ");
- htmlx = htmlx.replace(new RegExp('"'+resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+'"', "g"), '"'+revurl+'"'); // trick to preserve href="url"
- htmlx = htmlx.replace(new RegExp(resp.url.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")), '<div style="height:'+h+'px;" class="oembed youtube">'+resp.html+'</div>')
- htmlx = htmlx.replace(new RegExp('"'+revurl.replace("/", "\\/").replace(".", "\\.").replace("?", "\\?")+'"', "g"), '"'+resp.url+'"'); // trick to preserve href="url"
- if(html != htmlx) {
- oe_elems[response.callID].html(htmlx);
- if(window.location.hash.replace(/^#/, "").length > 0) {
- if(oe_tid) window.clearTimeout(oe_tid);
- oe_tid = window.setTimeout("oe_jumptohash()", 1000);
- }
- }
- }
- function oembed_yt(url, width, callID) {
- src = "http://oembed-js.appspot.com/?url=" + encodeURIComponent(url) + "&callback=oembed_callback&callID=" + encodeURIComponent(callID);
- if(width) src = src + "&maxwidth=" + width + "&maxheight=" + width;
- oe_loadscript(src);
- }
- $(document).ready(function() {
- det=$('<div class="youtube-lazy-link-div" />');
- $("body").append(det);
- if(det.css("position")=="absolute") {
- if(oelazy != 0) oelazy=1;
- }
- else oelazy = 0;
- det.remove();
- window.setTimeout(function() {
- var callID=0;
- $(".comment-content,.comment-body,.comment-body-author,.post-body").each(function() {
- html = " " + $(this).html() + " ";
- if(oetag)
- matches = html.match(new RegExp("\\["+oetagname+"=(https?:\\/\\/[^\\s<\\/]*youtu\\.*be[^\\]]+)", "g"));
- else
- matches = html.match(/([>\s^]|\[\w+=)(https?:\/\/[^\s<\/]*youtu\.*be[^\s<\]]+)/g);
- if(matches && matches.length) {
- for(var i=0;i<matches.length;i++) {
- url = matches[i].match(/https?:\/\/[^\s<\/]*youtu\.*be[^\s<\]]+/);
- oe_elems[callID] = $(this);
- oembed_yt(url, $(this).width(), callID++);
- }
- }
- });
- }, 500);
- });
- //]]>
- </script>
- <script src='http://code.jquery.com/jquery-latest.js' type='text/javascript'></script>
- <script type='text/javascript'>
- //<![CDATA[
- // Lazy loading of youtube videos by MS-potilas 2012. Needs jQuery.
- // طريقة الاستخدام نسخ الكود بالأسفل ووضعه مباشرة داخل الموضوع بعد التعديل
- // <a class="youtube-lazy-link" style="width:560px;height:315px;" href="https://www.youtube.com/watch?v=الأى دى الخاص بالفيديو">عنوان الفيديو</a>
- // - يمكنك تغيير ابعاد الفيديو
- // Source: http://www.abu-iyad.com/2014/10/youtube-videos-lazy-load.html
- $(document).ready(function() {
- $("a.youtube-lazy-link").each(function(index) {
- var embedparms = $(this).attr("href").split("/embed/")[1];
- if(!embedparms) embedparms = $(this).attr("href").split("://youtu.be/")[1];
- if(!embedparms) embedparms = $(this).attr("href").split("?v=")[1].replace(/&/,'?');
- var youid = embedparms.split("?")[0].split("#")[0];
- var start = embedparms.match(/[#&]t=(d+)s/);
- if(start) start = start[1];
- else {
- start = embedparms.match(/[#&]t=(d+)m(d+)s/);
- if(start) start = parseInt(start[1])*60+parseInt(start[2]);
- else {
- start = embedparms.match(/[?&]start=(d+)/);
- if(start) start = start[1];
- }
- }
- embedparms = embedparms.split("#")[0];
- if(start && embedparms.indexOf("start=") == -1)
- embedparms += ((embedparms.indexOf("?")==-1) ? "?" : "&") + "start="+start;
- if(embedparms.indexOf("showinfo=0") != -1)
- $(this).html('');
- else
- $(this).html('<div class="youtube-lazy-link-info">' + $(this).html() + '</div>');
- $(this).prepend('<div style="height:'+(parseInt($(this).css("height"))-4)+'px;width:'+(parseInt($(this).css("width"))-4)+'px;" class="youtube-lazy-link-div"></div>');
- $(this).css("background", "#000) center center no-repeat");
- $(this).attr("id", youid+index);
- $(this).attr("href", "http://www.youtube.com/watch?v="+youid+(start ? "#t="+start+"s" : ""));
- var emu = 'http://www.youtube.com/embed/'+embedparms;
- emu += ((emu.indexOf("?")==-1) ? "?" : "&") + "autoplay=1";
- var videoFrame = '<iframe width="'+parseInt($(this).css("width"))+'" height="'+parseInt($(this).css("height"))+'" style="vertical-align:top;" src="'+emu+'" frameborder="0" allowfullscreen></iframe>';
- $(this).attr("onclick", "$('#"+youid+index+"').replaceWith('"+videoFrame+"');return false;");
- });
- })
- //]]>
- </script>
- <style type='text/css'>
- a.youtube-lazy-link {
- vertical-align:top;
- background:#555;
- width:560px; height:315px;
- background-size:cover;
- text-decoration:none;
- color:#DDD;
- text-align:left;
- text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
- display:inline-block;
- }
- a.youtube-lazy-link:hover {
- text-decoration:none;
- color:#FFF;
- }
- .youtube-lazy-link-div {
- border:2px solid #000;
- background: url(http://lh4.googleusercontent.com/-QCeB6REIFlE/TuGUlY3N46I/AAAAAAAAAaI/9-urEUtpKcI/s800/youtube-play-button.png) center center no-repeat;
- position:absolute;
- }
- .youtube-lazy-link-div:hover {
- background: url( http://lh4.googleusercontent.com/-ywkTvQ4VohA/T455cg8_PRI/AAAAAAAAAq4/qfUJoK13InI/s800/youtube-play-button-hover-red.png) center center no-repeat;
- }
- .youtube-lazy-link-info {
- font-size: 110%;
- padding: 2px 6px;
- background: rgb(0, 0, 0);
- background: rgba(0, 0, 0, 0.5);
- }
- </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement