Skip to content

在外部调用editor.menus.img.bindEvent里的$inputFlie(FileInput) #8

@BOBGrile

Description

@BOBGrile

阅读您的代码对JS的封装及函数的调用又深入一些了解,做了一些改写使之能支持外部调用到图片上传的功能,实现如下,但也遇到一些问题,觉得自己还需要学习;
首先是增加内容,具体如下:

  1. 给editor.menus.img对象增加“img_InputFileId”属性,存储InputFile的ID;
  2. editor.menus.img.bindEvent中,给$inputFlie.on('change', function (e) {}中的鼠标定位的标签对象,“$focusElem”增加一个判断;代码如下:
    if(typeof($focusElem) === "undefined"){ log("如是外部调用Img,则图片定位于文字最后"); $focusElem = $(".wangEditor-mobile-txt").children().last(); }
    3.外部触发图片上传Input:$('#' + editor.menus.img.img_InputFileId).trigger('click');

其次介Old Plan:
给editor.menus.img对象增加“img_InputFile”属性,直接存储$('#' + inputFileId);对象;运行有问题,知道自己犯了一个概念性错误,但错在哪里,还请帮助指正一下。

最后,还请推荐一本关于JS封装、设计模式方面的书籍。目前也正在学习您的云网易课程。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions