Quantcast
Channel: MyBB Community Forums - Tutorials
Viewing all articles
Browse latest Browse all 690

Open image link and youtube link in modal

$
0
0
1 - create new file in extra.js using Notepad++

1.1 - Put code below in extra.js
Code:
$(document).ready(function() {
    $("a[href*='.jpg'], a[href*='.gif'], a[href*='.png']").each(function(e) {
        $(this).attr('data-link', $(this).attr('href'));
    });
    $("a[href*='.jpg'], a[href*='.gif'], a[href*='.png']").click(function(e) {
        e.preventDefault();
        src_elem = $(this).attr('data-link');
        src_val = $(this).text();
        $('<div id="image_mod" style="display: none; width: initial;"><table><tr><th>'+ src_val +'</th></tr><tr><td><img src="'+ src_elem +'"/></td></tr></table></div>').appendTo('body');
        $(this).attr({'href':'#image_mod', 'rel':'modal:open'});
    });

    $("a[href*='youtu.be'], a[href*='youtube']").each(function(e) {
        var url = $(this).attr('href'),
        regExp = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=)([^#\&\?]*).*/,
        match = url.match(regExp);
        if (match&&match[2].length==11){
            url = match[2];
        }
        else {
            url = url.replace(/^[^v]+v.(.{11}).*/,"$1");
        }
        $(this).attr('data-yt', url);
    });
    $("a[href*='youtu.be'], a[href*='youtube']").click(function(e) {
        e.preventDefault();
        src_elem = $(this).attr('data-yt');
        $('<div id="yt_mod" style="display: none; width: initial;"><iframe width="560" height="315" src="//www.youtube.com/embed/'+ src_elem +'?html5=1&autoplay=1" frameborder="0" allowfullscreen ></iframe></div>').appendTo('body');
        $(this).attr({'href':'#yt_mod', 'rel':'modal:open'});
    });
});

2 - In headerinclude template

2.1 - find
Code:
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/jquery.plugins.min.js?ver=1800"></script>

2.2 - add below
Code:
<script type="text/javascript" src="{$mybb->asset_url}/jscripts/extra.js"></script>

it´s all

Demo in my forum: https://forum.minnasuki.com/thread-403-post-325350.html#pid325350
click in
Code:
https://www.youtube.com/watch?v=9Fiwc79_N9c and https://i.imgur.com/xhLyWcm.jpg
to see result.

Viewing all articles
Browse latest Browse all 690

Trending Articles