summaryrefslogtreecommitdiff
path: root/yaksh/static/yaksh/js/lesson.js
blob: 6f873b984b0bbf42dd5b3e18193222361cb449a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
$(document).ready(function(){
    var csrftoken = jQuery("[name=csrfmiddlewaretoken]").val();

    function csrfSafeMethod(method) {
        // These HTTP methods do not require CSRF protection
        return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
    }
    $.ajaxSetup({
        beforeSend: function(xhr, settings) {
            if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
                xhr.setRequestHeader("X-CSRFToken", csrftoken);
            }
        }
    });
    $("#preview").click(function(){
        var description = $("#id_description").val();
        var preview_url = window.location.protocol + "//" +
                window.location.host + "/exam/manage/courses/lesson/preview/";
        $.ajax({
            url: preview_url,
            timeout: 15000,
            type: 'POST',
            data: JSON.stringify({'description': description}),
            dataType: 'json',
            contentType: 'application/json; charset=utf-8',
            success: function(msg) {
                preview_text(msg['data']);
            },
            error: function(jqXHR, textStatus) {

            }
        });
    });

    function preview_text(data){
        var preview_div = $("#preview_text_div");
        if (!preview_div.is(":visible")){
            $("#preview_text_div").toggle();
        }
        $("#description_body").empty();
        $("#description_body").append(data);
    }

    $("#embed").click(function() {
        $("#dialog_iframe").toggle();
        $("#dialog_iframe").dialog({
            resizable: false,
            height: '300',
            width: '450'
        });
    });

    $("#submit_info").click(function(){
        var url = $("#url").val();
        if (url == "") {
            if (!$("#error_div").is(":visible")){
                $("#error_div").toggle();
            }
        }
        else{
            if ($("#error_div").is(":visible")){
                $("#error_div").toggle();
            }
            $("#video_frame").attr("src", url);
            $("#html_text").text($("#iframe_div").html().trim());
        }
    });

    $("#copy").click(function(){
        try{
            var text = $("#html_text");
            text.select();
            document.execCommand("Copy");
        } catch (err) {
            alert("Unable to copy. Press Ctrl+C or Cmd+C to copy")    
        }
    });
});