{"size": 2117, "ext": "js", "max_stars_repo_path": "src/js/modules/previewModule.js", "max_stars_repo_name": "PewhProgrammer/CMS-K-System", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/js/modules/previewModule.js", "max_issues_repo_name": "PewhProgrammer/CMS-K-System", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/js/modules/previewModule.js", "max_forks_repo_name": "PewhProgrammer/CMS-K-System", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 30.2428571429, "max_line_length": 111, "alphanum_fraction": 0.4506376949}
/**
 * Created by Thinh-Laptop on 01.06.2017.
 */

(function (jQuery) {
    "use strict";

    jQuery.previewModule = function (el, options) {
        // To avoid scope issues, use 'base' instead of 'this'
        // to reference this class from internal events and functions.
        var base = this;

        /**
         * initialisation
         */
        base.init = function () {
            // merge given options with default options
            jQuery.extend(base.options, options);

            // Access to jQuery and DOM versions of element
            base.el = el;
            base.$el = jQuery(el);
            base.$previewFrame = $("iframe#previewFrame");
            base.$noPreviewFrame = $("#noPreview");

            $("#resourceTable").find("input").change(function () {
                if (this.checked) {
                    var resType = $(this).attr("data-resType");
                    var resData = $(this).attr("data-resData");
                    //console.log(resType);

                    if(resType === 'pdf' || resType === 'image' || resType === 'rss' || resType === 'website'){
                        base.$noPreviewFrame.hide();
                        base.$previewFrame.show();
                        base.$previewFrame.attr("src", resData);

                        if (resType === 'pdf'){
                            base.$previewFrame.removeAttr("sandbox");
                        }
                        else{ //prevents forwarding
                            base.$previewFrame.attr("sandbox", "allow-forms allow-scripts");
                        }

                    }
                    else{
                        base.$previewFrame.hide();
                        base.$noPreviewFrame.show();
                    }

                $("#previewResource").text($(this).val());
                }
            });


        };


        // call init method
        base.init();
    };

    jQuery.fn.previewModule = function (options) {
        return this.each(function () {
            new jQuery.previewModule(this, options);
        });
    };
})(jQuery);


