<commit_before>/*
 * Wiki content previews - ajaxified.
 */

(function($) {

"use strict";

function AjaxPreview(el, options) {
    /* Args:
     * el - The button/link DOM element that triggers the preview
     * options - dict of options
     *      previewUrl - url to POST the content and get a preview
     *      contentElement - DOM element or selector that input content
     *      previewElement - DOM element or selector to insert the preview
     *      changeHash - Change document.location.hash to the id of
     *                   previewElemnt (default: true)
     */
    AjaxPreview.prototype.init.call(this, el, options);
}

AjaxPreview.prototype = {
    init: function(el, options) {
        var self = this,
            $btn = $(el),
            o = options || {},
            previewUrl = o.previewUrl || $btn.data('preview-url'),
            $preview = (o.previewElement && $(o.previewElement)) ||
                       $('#' + $btn.data('preview-container-id')),
            $content = (o.contentElement && $(o.contentElement)) ||
                       $('#' + $btn.data('preview-content-id')),
            csrftoken = $btn.closest('form')
                            .find('input[name=csrfmiddlewaretoken]').val(),
            changeHash = o.changeHash === undefined ? true : o.changeHash;

        $btn.click(function(e) {
            e.preventDefault();
            $btn.attr('disabled', 'disabled');
            $(self).trigger('get-preview');
        });

        // Trying to make this event driven for easier testability.
        $(self).bind('get-preview', function(e) {
            $.ajax({
                url: previewUrl,
                type: 'POST',
                data: {
                    content: $content.val(),
                    csrfmiddlewaretoken: csrftoken
                },
                dataType: 'html',
                success: function(html) {
                    $(self).trigger('show-preview', [true, html]);
                },
                error: function() {
                    var msg = gettext('There was an error generating the preview.');
                    $(self).trigger('show-preview', [false, msg]);
                }
            });
        });

        $(self).bind('show-preview', function(e, success, html) {
            $preview.html(html);
            if (changeHash) {
                document.location.hash = $preview.attr('id');
            }
            $btn.removeAttr('disabled');
            $(self).trigger('done', [success]);
        });
    }<commit_msg>[Bug 701078] Fix lazyloading images in preview<commit_after>/*
 * Wiki content previews - ajaxified.
 */

(function($) {

"use strict";

function AjaxPreview(el, options) {
    /* Args:
     * el - The button/link DOM element that triggers the preview
     * options - dict of options
     *      previewUrl - url to POST the content and get a preview
     *      contentElement - DOM element or selector that input content
     *      previewElement - DOM element or selector to insert the preview
     *      changeHash - Change document.location.hash to the id of
     *                   previewElemnt (default: true)
     */
    AjaxPreview.prototype.init.call(this, el, options);
}

AjaxPreview.prototype = {
    init: function(el, options) {
        var self = this,
            $btn = $(el),
            o = options || {},
            previewUrl = o.previewUrl || $btn.data('preview-url'),
            $preview = (o.previewElement && $(o.previewElement)) ||
                       $('#' + $btn.data('preview-container-id')),
            $content = (o.contentElement && $(o.contentElement)) ||
                       $('#' + $btn.data('preview-content-id')),
            csrftoken = $btn.closest('form')
                            .find('input[name=csrfmiddlewaretoken]').val(),
            changeHash = o.changeHash === undefined ? true : o.changeHash;

        $btn.click(function(e) {
            e.preventDefault();
            $btn.attr('disabled', 'disabled');
            $(self).trigger('get-preview');
        });

        // Trying to make this event driven for easier testability.
        $(self).bind('get-preview', function(e) {
            $.ajax({
                url: previewUrl,
                type: 'POST',
                data: {
                    content: $content.val(),
                    csrfmiddlewaretoken: csrftoken
                },
                dataType: 'html',
                success: function(html) {
                    $(self).trigger('show-preview', [true, html]);
                },
                error: function() {
                    var msg = gettext('There was an error generating the preview.');
                    $(self).trigger('show-preview', [false, msg]);
                }
            });
        });

        $(self).bind('show-preview', function(e, success, html) {
            $preview.html(html);
            if (changeHash) {
                document.location.hash = $preview.attr('id');
            }
            $btn.removeAttr('disabled');
            $('img.lazy').lazyload();
            $(self).trigger('done', [success]);
        });
    }
{'fraction_non_alphanumeric': 0.14011999225856397, 'fraction_numerical': 0.0011612154054577125, 'mean_word_length': 1.5943775100401607, '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': '7284586', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1321, 'n_words': 315}