前端js如何查找具体代码

前台页面显示的一个上传功能的div

<div id="rn_FileAttachmentUpload_36" class="rn_FileAttachmentUpload rn_Input">
    <div id="rn_FileAttachmentUpload_36_LabelContainer">
        <label for="rn_FileAttachmentUpload_36_FileInput" id="rn_FileAttachmentUpload_36_Label">Attach a photo of the item                </label>
    </div>
    <input name="file" id="rn_FileAttachmentUpload_36_FileInput" type="file" aria-labelledby="rn_FileAttachmentUpload_36_Label">
        <img id="rn_FileAttachmentUpload_36_LoadingIcon" class="rn_Hidden" alt="Loading" src="images/indicator.gif">
        <span id="rn_FileAttachmentUpload_36_StatusMessage" aria-label="Status"></span>
    <span id="rn_FileAttachmentUpload_36_ErrorMessage"></span>
</div>

我想找到上传的代码分析一下,请问如何去确定呢?

我用f12-sources-Ctrl+Shift+F全局查找FileAttachmentUpload,定位到一个js,里面包含上传代码

RightNow.Widgets.FileAttachmentUpload = RightNow.Field.extend({
    overrides: {
        constructor: function() {
            this.parent();
            this.input = this.Y.one(this.baseSelector + "_FileInput");
            if (!this.input)
                return;
            this._eo = new RightNow.Event.EventObject(this);
            this._attachmentCount = this.data.js.attachmentCount || 0;
            this._attachments = [];
            this._statusMessage = this.Y.one(this.baseSelector + "_StatusMessage");
            this._ErrorMessage = this.Y.one(this.baseSelector + "_ErrorMessage");
            this._parentFormElement = this.input.ancestor('form');
            if (this._parentFormElement) {
                this._origEncType = this._parentFormElement.get('enctype');
                this.input.on("change", this._onFileAdded, this);
                this.input.on("keypress", this._onKeyPress, this);
                this.input.on("paste", function() {
                    return false;
                });
                RightNow.Form.find(this.input.get('id'), this.instanceID).on("submit", this._onValidateUpdate, this);
                this.on("constraintChange:min_required_attachments", this.updateMinAttachments, this);
            } else {
                RightNow.UI.addDevelopmentHeaderError("FileAttachmentUpload must be placed within a form with a unique ID.");
            }
            this.data.attrs.max_attachments = (this.data.attrs.max_attachments === 0) ? Number.MAX_VALUE : this.data.attrs.max_attachments;
            if (this._attachmentCount === this.data.attrs.max_attachments)
                this.input.set("disabled", true);
        },
        getValue: function() {
            return this._attachments;
        }
    },
    swapLabel: function(container, minAttachments, label, template) {
        this.Y.augment(this, RightNow.RequiredLabel);
        var templateObject = {
            label: label,
            instanceID: this.instanceID,
            fieldName: this._fieldName,
            minAttachments: minAttachments
        };
        container.setHTML('');
        container.append(new EJS({
            text: template
        }).render(templateObject));
    },
    updateMinAttachments: function(evt, constraint) {
        var minAttachments = constraint[0].constraint;
        if (minAttachments > this.data.attrs.max_attachments || minAttachments === this.data.attrs.min_required_attachments)
            return;
        this.toggleErrorIndicator(false);
        if (this.data.attrs.min_required_attachments > 0 && this.lastErrorLocation) {
            this.Y.one('#' + this.lastErrorLocation).all("[data-field='" + this._fieldName + "']").remove();
        }
        if (this.data.attrs.label_input) {
            this.swapLabel(this.Y.one(this.baseSelector + '_LabelContainer'), minAttachments, this.data.attrs.label_input, this.getStatic().templates.label);
        }
        this.data.attrs.min_required_attachments = minAttachments;
    },
    _onKeyPress: function(event) {
        var keyPressed = event.keyCode;
        if (keyPressed && (keyPressed !== RightNow.UI.KeyMap.ENTER && keyPressed !== RightNow.UI.KeyMap.TAB) || (keyPressed === RightNow.UI.KeyMap.ENTER && this.Y.UA.ie)) {
            event.halt();
        }
    },
    _onFileAdded: function(e) {
        var value = e.target.get('value');
        if (this._uploading || value === "" || !this._validateFileExtension(value))
            return;
        this._sendUploadRequest();
    },
    _validateFileExtension: function(fileName) {
        if (!this.data.attrs.valid_file_extensions)
            return true;
        this._validExtensions || (this._validExtensions = this.data.attrs.valid_file_extensions.toLowerCase().replace(' ', '').split(','));
        var index = fileName.lastIndexOf('.')
          , fileExtension = (index !== -1 && index !== (fileName.length - 1)) ? fileName.substring(index + 1).toLowerCase() : null
          , extensionIsValid = fileExtension && this.Y.Array.indexOf(this._validExtensions, fileExtension) > -1;
        if (extensionIsValid) {
            this.toggleErrorIndicator(false);
            return true;
        }
        this.toggleErrorIndicator(true);
        this._setStatusMessage(RightNow.Text.sprintf(this.data.attrs.label_invalid_extension, '.' + this._validExtensions.join(", .")), false, true, "alert", null);
        return false;
    },
    _setStatusMessage: function(message, screenReaderClass, errorClass, role, tabIndex) {
        this._statusMessage.set('innerHTML', message);
        if (screenReaderClass && !this._statusMessage.hasClass("rn_ScreenReaderOnly")) {
            this._statusMessage.addClass("rn_ScreenReaderOnly");
        } else if (!screenReaderClass && this._statusMessage.hasClass("rn_ScreenReaderOnly")) {
            this._statusMessage.removeClass("rn_ScreenReaderOnly");
        }
        if (errorClass && !this._statusMessage.hasClass("rn_ErrorMessage")) {
            this._statusMessage.addClass("rn_ErrorMessage");
        } else if (!errorClass && this._statusMessage.hasClass("rn_ErrorMessage")) {
            this._statusMessage.removeClass("rn_ErrorMessage");
        }
        role ? this._statusMessage.setAttribute("role", role) : this._statusMessage.removeAttribute("role");
        tabIndex ? this._statusMessage.setAttribute("tabIndex", tabIndex) : this._statusMessage.removeAttribute("tabIndex");
    },
    _sendUploadRequest: function() {
        this._eo.data.filename = this.input.get('value');
        var postData = {
            name: this.data.js.id,
            path: this.data.js.path,
            count: this._attachmentCount,
            ext: this.data.attrs.valid_file_extensions,
            max_attach_hash: this.data.js.max_attach_hash,
            max_attachments: this.data.attrs.max_attachments,
            constraints: this.data.js.constraints
        };

这个上传函数需要传入path,
但是这个页面里的this.data.js.path是怎么赋值的呢? 在前台的上传div和这个js中间是不是还调用的其他的文件?

阅读 1.8k
1 个回答

你在代码全局搜一下this.data看看?应该能看到初始化的地方

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题