kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0
http://demos.krajee.com/markdown
Other
89 stars 41 forks source link

initEditor is overriding globally scoped name #68

Closed davidnewcomb closed 6 years ago

davidnewcomb commented 6 years ago

From kv-markdown.js:

function initEditor(params) {
    var input = params.source,
        editor = params.editor,
        preview = params.preview,
        target = params.target,
        maximize = params.maximize,
        container = params.container,
        modal = editor.slice(1) + '-modal',
        export1 = params.export1,
        export2 = params.export2,
        defHeight = params.height,
        $iframe = $('#' + params.iframeId),
        $form = $iframe.contents().find('form'),
        fullscreen = input.slice(1) + '-fullscreen';
    filename = params.filename;  //// <--------

    $(input).focus(function () {
        $(editor).addClass('active');
    });

filename is not defined inside your file, and the area where it is used is in the global space. So by setting this variable here you are potentially overwriting someone else' variable. It is difficult to say what the effect is. It could be nothing or everything!

I think you want:

        $form = $iframe.contents().find('form'),
        fullscreen = input.slice(1) + '-fullscreen',  /// <---
        filename = params.filename;  //// <--------

    $(input).focus(function () {
        $(editor).addClass('active');
    });