<commit_before>'use strict';
var ko = require('knockout');
var $ = require('jquery');

var $osf = require('js/osfHelpers');
var mathrender = require('js/mathrender');
var md = require('js/markdown').full;
var mdQuick = require('js/markdown').quick;
var diffTool = require('js/diffTool');

var THROTTLE = 500;

ko.bindingHandlers.mathjaxify = {
    update: function(element, valueAccessor, allBindingsAccessor, data, context) {
        var vm = context.$data;
        //Need to unwrap the data in order for KO to know it's changed.
        ko.unwrap(valueAccessor());

        if(vm.allowMathjaxification() && vm.allowFullRender()) {
            mathrender.mathjaxify('#' + element.id);
        }
    }
};


function ViewWidget(visible, version, viewText, rendered, contentURL, allowMathjaxification, allowFullRender, editor) {
    var self = this;
    self.version = version;
    self.viewText = viewText; // comes from EditWidget.viewText
    self.rendered = rendered;
    self.visible = visible;
    self.allowMathjaxification = allowMathjaxification;
    self.editor = editor;
    self.allowFullRender = allowFullRender;
    self.renderTimeout = null;
    self.displaySource = ko.observable('');
    self.debouncedAllowFullRender = $osf.debounce(function() {
        self.allowFullRender(true);
    }, THROTTLE);

    self.renderMarkdown = function(rawContent){
        if(self.visible()) {
            if (self.allowFullRender()) {
                return md.render(rawContent);
            } else {
                return mdQuick.render(rawContent);
            }
        } else {
            return '';
        }
    };

    if (typeof self.editor !== 'undefined') {
        self.editor.on('change', function () {
            if(self.version() === 'preview') {
                // Quick render
                self.allowFullRender(false);

                // Full render
                self.debouncedAllowFullRender();
            }
        });
    } else {
        self.allowFullRender(true);
    }
}<commit_msg>Move self.renderMarkdown method to ViewWidget prototype<commit_after>'use strict';
var ko = require('knockout');
var $ = require('jquery');

var $osf = require('js/osfHelpers');
var mathrender = require('js/mathrender');
var md = require('js/markdown').full;
var mdQuick = require('js/markdown').quick;
var diffTool = require('js/diffTool');

var THROTTLE = 500;

ko.bindingHandlers.mathjaxify = {
    update: function(element, valueAccessor, allBindingsAccessor, data, context) {
        var vm = context.$data;
        //Need to unwrap the data in order for KO to know it's changed.
        ko.unwrap(valueAccessor());

        if(vm.allowMathjaxification() && vm.allowFullRender()) {
            mathrender.mathjaxify('#' + element.id);
        }
    }
};


var ViewWidget = function(visible, version, viewText, rendered, contentURL, allowMathjaxification, allowFullRender, editor) {
    var self = this;
    self.version = version;
    self.viewText = viewText; // comes from EditWidget.viewText
    self.rendered = rendered;
    self.visible = visible;
    self.allowMathjaxification = allowMathjaxification;
    self.editor = editor;
    self.allowFullRender = allowFullRender;
    self.renderTimeout = null;
    self.displaySource = ko.observable('');
    self.debouncedAllowFullRender = $osf.debounce(function() {
        self.allowFullRender(true);
    }, THROTTLE);

    if (typeof self.editor !== 'undefined') {
        self.editor.on('change', function () {
            if(self.version() === 'preview') {
                // Quick render
                self.allowFullRender(false);

                // Full render
                self.debouncedAllowFullRender();
            }
        });
    } else {
        self.allowFullRender(true);
    }
};

ViewWidget.prototype.renderMarkdown = function(rawContent) {
    if(self.visible()) {
        if (self.allowFullRender()) {
            return md.render(rawContent);
        } else {
            return mdQuick.render(rawContent);
        }
    } else {
        return '';
    }
};
{'fraction_non_alphanumeric': 0.12962050271069492, 'fraction_numerical': 0.0014785608674223755, 'mean_word_length': 2.5574057843996494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3813682', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1138, 'n_words': 242}