杰表技术论坛 's Archiver

admin 发表于 2010-3-19 21:50

jatoolsPrinter 的 jquery 插件

var jatools = {
    jobs: []
}
function jatoolsPrinter() {
    if ($('#_jatoolsPrinter').length == 0) $('<OBJECT ID="_jatoolsPrinter" style="display:none" CLASSID="CLSID:B43D3361-D075-4BE2-87FE-057188254255" codebase="jatoolsPrinter.cab#version=5,0,0,0"></OBJECT>').appendTo($('body'));
    this.cached = false;
    this.print = function (cfg, prompt) {
        if (_jatoolsPrinter && typeof(_jatoolsPrinter.print) != 'undefined') {
            _jatoolsPrinter.print(this.normalize(cfg));
        } else {
            this.cache(cfg);
            setTimeout("jatools.jobs[" + cfg.index + "].jatoolsPrinter.print(jatools.jobs[" + cfg.index + "]," + (prompt == true) + ")", 50);
        }
    }
    this.cache = function (cfg) {
        if (!this.cached) {
            this.cached = true;
            jatools.jobs.push(cfg);
            cfg.jatoolsPrinter = this;
            cfg.index = jatools.jobs.length - 1;
        }
    }
    this.normalize = function (cfg) {
        var _pages = [],
            pages = cfg.pages;
        if (pages.length == 0) throw '请正确指定要打印的内容!';
        pages.each(function (e, it) {
            _pages.push(it);
        })
        var result = {
            pages: _pages,
            settings: cfg,
            autoBreakPage: true,
            documents: document,
            copyrights: '杰创软件拥有版权  www.jatools.com'
        };
        return result;
    }
    this.printPreview = function (cfg) {
        if (_jatoolsPrinter && typeof(_jatoolsPrinter.printPreview) != 'undefined') {
            _jatoolsPrinter.printPreview(this.normalize(cfg));
        } else {
            this.cache(cfg);
            setTimeout("jatools.jobs[" + cfg.index + "].jatoolsPrinter.printPreview(jatools.jobs[" + cfg.index + "])", 50);
        }
    }
}

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.