whins
11/12/2015 - 7:45 AM

browser.js

var pdfDiv = '';
pdfDiv += '<div id="pdf-object" style="background-color:#ffffff;position: relative; top: 0px; left: 0px ;z-index: 0 !important; padding: 25px"><span style="color: rgba(102, 116, 127, 1)">It appears you don\'t have Adobe Reader or PDF support in this web browser.</span> <a id="pdf-url" href="#">Click here to download the PDF</a><span style="color: rgba(102, 116, 127, 1)"> or </span> <a id="pdf-url" href="https://get.adobe.com/reader/">click here to download and install Adobe Reader</a></div>';
$("#document-pdf-container").html(pdfDiv);
$('#pdf-object').show();
$('#pdf-object').css({ display: 'block' });
if (_url) {
	$('#pdf-url').attr('href', _url);
	var pdfObject = new PDFObjectEmbed({
		url: _url,
		id: 'pdf-previewer'
	});
	var success = pdfObject.embed('pdf-object');
	if (!success) {
		var loader = '<div data-bind="visible: ($root.dataOp() == "loading")" class="tile-data-loading"><div class="loading-gif"></div> Loading...</div>';
		var customPDFObject = '<object data="' + _url + '" type="application/pdf"></object>';
		var info = getAcrobatInfo();
		if (info.browser == "chrome") {
		    $('#pdf-object').html(loader);
		} else if (info.browser == "safari" && info.acrobat) {
			$('#pdf-object').html(customPDFObject);
		} else if (info.browser == 'ie' && info.acrobat) {
			$('#pdf-object').html(customPDFObject);
		} else if (info.browser == "firefox") {
			$('#pdf-object').html(customPDFObject);
		};
    }
} else {
    $('#pdf-object').html('<div data-bind="visible: ($root.dataOp() == "loading")" class="tile-data-loading"><div class="loading-gif"></div> Loading...</div>');
}
var getAcrobatInfo = function () {
	var getBrowserName = function () {
		return this.name = this.name || function () {
			var userAgent = navigator ? navigator.userAgent.toLowerCase() : "other";

			if (userAgent.indexOf("chrome") > -1) return "chrome";
			else if (userAgent.indexOf("safari") > -1) return "safari";
			else if (userAgent.indexOf("msie") > -1 || userAgent.indexOf("trident") > -1 || userAgent.indexOf('like gecko') > -1) return "ie";
			else if (userAgent.indexOf("firefox") > -1) return "firefox";
			return userAgent;
		}();
	};

	var getActiveXObject = function (name) {
		try { return new ActiveXObject(name); } catch (e) { }
	};

	var getNavigatorPlugin = function (name) {
		for (key in navigator.plugins) {
			var plugin = navigator.plugins[key];
			if (plugin.name == name) return plugin;
		}
	};

	var getPDFPlugin = function () {
		return this.plugin = this.plugin || function () {
			if (getBrowserName() == 'ie') {
				//
				// load the activeX control
				// AcroPDF.PDF is used by version 7 and later
				// PDF.PdfCtrl is used by version 6 and earlier
				return getActiveXObject('AcroPDF.PDF') || getActiveXObject('PDF.PdfCtrl');
			}
			else {
				return getNavigatorPlugin('Adobe Acrobat') || getNavigatorPlugin('Chrome PDF Viewer') || getNavigatorPlugin('WebKit built-in PDF');
			}
		}();
	};

	var isAcrobatInstalled = function () {
		return !!getPDFPlugin();
	};

	var getAcrobatVersion = function () {
		try {
			var plugin = getPDFPlugin();

			if (getBrowserName() == 'ie') {
				var versions = plugin.GetVersions().split(',');
				var latest = versions[0].split('=');
				return parseFloat(latest[1]);
			}

			if (plugin.version) return parseInt(plugin.version);
			return plugin.name

		}
		catch (e) {
			return null;
		}
	}
	// The returned object
	return {
		browser: getBrowserName(),
		acrobat: isAcrobatInstalled() ? 'installed' : false,
		acrobatVersion: getAcrobatVersion()
	};
};
var hasIE = window.eval && eval("/*@cc_on 1;@*/");
var hasOpera = !!window.opera;
var hasChrome = !!window.chrome;
var hasFireFox = !!window.sidebar;
var hasSafari = !window.external && !hasOpera;