kartik-v / yii2-markdown

Advanced Markdown editing and conversion utilities for Yii Framework 2.0

Home Page:http://demos.krajee.com/markdown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

initEditor is overriding globally scoped name

davidnewcomb opened this issue · comments

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');
    });