From dd4f328a299d09e3aded026c5422aa1b59051571 Mon Sep 17 00:00:00 2001 From: Angelina Konstantinova Date: Tue, 27 Mar 2018 10:34:47 +0300 Subject: [PATCH] Attach: extend api --- common.blocks/attach/attach.js | 12 ++++++++++-- common.blocks/attach/attach.spec.js | 5 +++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/common.blocks/attach/attach.js b/common.blocks/attach/attach.js index 2781de348..f359d0afb 100644 --- a/common.blocks/attach/attach.js +++ b/common.blocks/attach/attach.js @@ -31,6 +31,14 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{ return this._clear(data); }, + /** + * Returns file element + * @returns {attach__file} + */ + getFileElem : function() { + return this.findChildElem('file'); + }, + _clear : function(data) { var control = this._elem('control').domElem, name = control.attr('name'), @@ -47,7 +55,7 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{ (tabIndex? ' tabindex="' + tabIndex + '"' : '') + '/>'); - bemDom.destruct(this.findChildElem('file').domElem); + bemDom.destruct(this.getFileElem().domElem); this.domElem.append(this._elem('no-file').domElem); // use append because only detached before @@ -75,7 +83,7 @@ provide(bemDom.declBlock(this.name, Control, /** @lends attach.prototype */{ _updateFileElem : function() { var fileName = extractFileNameFromPath(this.getVal()); - this.findChildElem('file') && bemDom.destruct(this._elem('file').domElem); + this.getFileElem() && bemDom.destruct(this._elem('file').domElem); bemDom.append( this.domElem, diff --git a/common.blocks/attach/attach.spec.js b/common.blocks/attach/attach.spec.js index 2f33141d8..3d583faa2 100644 --- a/common.blocks/attach/attach.spec.js +++ b/common.blocks/attach/attach.spec.js @@ -37,6 +37,11 @@ describe('attach', function() { setFile('\\usr\\local\\file.png'); attach._elem('text').domElem.text().should.be.equal('file.png'); }); + + it('should have file element', function() { + setFile('file.png'); + Boolean(attach.getFileElem()).should.be.true; + }); }); describe('clear', function() {