UNPKG

js-pkg

Version:
11 lines (10 loc) 3.77 kB
/*! * filename: ej.print.min.js * version : 15.3.0.33 * Copyright Syncfusion Inc. 2001 - 2017. All rights reserved. * Use of this code is subject to the terms of our license. * A copy of the current license can be obtained at any time by e-mailing * licensing@syncfusion.com. Any infringement will be prosecuted under * applicable laws. */ (function(n){typeof define=="function"&&define.amd?define(["./../common/ej.core.min"],n):n()})(function(){"use strict";var n=this&&this.__extends||function(n,t){function r(){this.constructor=n}for(var i in t)t.hasOwnProperty(i)&&(n[i]=t[i]);n.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)},t=function(t){function i(n,i){return t.call(this),this._rootCSS="e-print",this.PluginName="ejPrint",this.id="null",this.defaults={globalStyles:!0,externalStyles:null,excludeSelector:null,append:null,printInNewWindow:!1,prepend:null,timeOutPeriod:1e3,title:null,height:454,width:1024,docType:"<!doctype html>",beforeStart:null},n&&(n.jquery||(n=$("#"+n)),n.length)?$(n).ejPrint(i).data(this.PluginName):void 0}return n(i,t),i.prototype._init=function(){this.id=this.element[0].id;this._initialize(this.element,undefined)},i.prototype._initialize=function(n,t){var o,f,i,r,u,e;if(this.styles=$(""),this.title=$("title"),this.model.globalStyles&&this._addglobalStyles(this.model.globalStyles),this.model.externalStyles&&this._addStylesToElement(this.model.externalStyles),this.model.title&&this._addTitleToElement(this.model.title),o=$("<html/>"),f=$("<head/>").append(this.title),f.append(this.styles.clone()),i=$("<body/>"),r=$("<div/>"),t){if(typeof n=="string")n=$(n),r.append(n.clone());else if(typeof n=="object")for(u=0;u<n.length;u++)r.append($(n[u]).clone())}else r.append(n.clone());return(this.copy=r,i.append(this.copy),this.model.append&&i.append(this._getjQueryObject(this.model.append)),this.model.prepend&&i.prepend(this._getjQueryObject(this.model.prepend)),this.copy=o.append(f).append(i),this.model.excludeSelector!=null&&this._removeContentFromPrint(this.model.excludeSelector),e=this.copy,this.copy.remove(),t===undefined)?(this._printContent(e,null,!1),!0):e},i.prototype._getjQueryObject=function(n){return $(n).clone().length===0?$("<div />").html(n):$(n).clone()},i.prototype._addglobalStyles=function(){this.model.globalStyles&&(this.styles=$("style, link, meta, title"))},i.prototype._addStylesToElement=function(n){var i,t,r;if(this.model.externalStyles)for(i=$.isArray(n)?n:n.split(","),t=0;t<i.length;t++)r=$("<link rel='stylesheet' href='"+i[t]+"'>"),this.styles=$.merge(this.styles,r)},i.prototype._addTitleToElement=function(){this.model.title&&(this.title.length===0&&(this.title=$("<title />")),this.title.text(this.model.title))},i.prototype._removeContentFromPrint=function(n){var i,t;if(this.model.excludeSelector)for(i=$.isArray(n)?n:n.split(","),t=0;t<i.length;t++)this.copy.find(i[t]).remove()},i.prototype._printContent=function(n,t,i){var e=this,r,u,f;if(i){if(u=[],this.element.attr("id")!==undefined?u.push("#"+this.element.attr("id")):u.push("."+this.element.attr("class").replace(/ /g,".")),n!==undefined)if($.isArray(n))for(f=0;f<n.length;f++)u.push(n[f]);else u.push(n);n=this._initialize(u,!0)}this._trigger("beforeStart",{content:n});t||(r=this.model.printInNewWindow?window.open():window.open(" ","print","height="+this.model.height+",width="+this.model.width+",tabbar=no"));r.document.write(this.model.docType);r.document.write(n[0].outerHTML);r.document.close();r.focus();setTimeout(function(){ej.isNullOrUndefined(r.window)||(r.print(),setTimeout(function(){r.close()},e.model.timeOutPeriod))},this.model.timeOutPeriod)},i.prototype.print=function(n,t){this._printContent(n,t,!0)},i}(ej.WidgetBase);window.ej.widget("ejPrint","ej.Print",new t)});