UNPKG

platform-project

Version:

平台项目

36 lines (33 loc) 926 B
function FileDownloader(options) { this.node = options.node; this.url = this.node.attr('data-url'); } FileDownloader.prototype = { constructor: FileDownloader, trigger: function () { if (!this.node || !this.node.length) { return; } this.bindEvent(); }, bindEvent: function () { var _this = this; this.node.on('click', function () { var $dFrame = $('.download-frame'); if ($dFrame.length > 0) { $dFrame.remove(); } var elemIF = $('<iframe class="download-frame hidden" src=' + _this.url + '></iframe>'); $('body').append(elemIF); }) } } $.fn.fileDownloader = function () { if (!$(this).length) { return } $(this).each(function () { new FileDownloader({ node: $(this), }).trigger(); }); } module.exports = FileDownloader;