var docviewer; function getdocviewer(){ if(docviewer) return docviewer; else docviewer = window.flexpaperviewer_instance.getapi(); return docviewer; } /** * * flexpaper constructor (name of swf, name of placeholder, config) * */ window.flexpaperviewer = window.$f = function() { var config = arguments[2].config; window.flexpaperviewer_instance = flashembed(arguments[1], { src: arguments[0]+".swf", version: [10, 0], expressinstall: "js/expressinstall.swf" }, { swffile : config.swffile, scale : config.scale, zoomtransition : config.zoomtransition, zoomtime : config.zoomtime, zoominterval : config.zoominterval, fitpageonload : config.fitpageonload, fitwidthonload : config.fitwidthonload, printenabled : config.printenabled, fullscreenasmaxwindow : config.fullscreenasmaxwindow, progressiveloading : config.progressiveloading, minzoomsize : config.minzoomsize, maxzoomsize : config.maxzoomsize, searchmatchall : config.searchmatchall, searchserviceurl : config.searchserviceurl, startatpage : config.startatpage, initviewmode : config.initviewmode, bitmapbasedrendering : config.bitmapbasedrendering, viewmodetoolsvisible : config.viewmodetoolsvisible, zoomtoolsvisible : config.zoomtoolsvisible, navtoolsvisible : config.navtoolsvisible, cursortoolsvisible : config.cursortoolsvisible, searchtoolsvisible : config.searchtoolsvisible, localechain : config.localechain, key : config.key }); }; /** * handles the event of external links getting clicked in the document. * * @example onexternallinkclicked("http://www.google.com") * * @param string link */ function onexternallinkclicked(link){ $("#txt_eventlog").val('onexternallinkclicked:' + link + '\n' + $("#txt_eventlog").val()); } /** * recieves progress information about the document being loaded * * @example onprogress( 100,10000 ); * * @param int loaded * @param int total */ function onprogress(loadedbytes,totalbytes){ $("#txt_progress").val('onprogress:' + loadedbytes + '/' + totalbytes + '\n'); } /** * handles the event of a document is in progress of loading * */ function ondocumentloading(){ $("#txt_eventlog").val('ondocumentloading' + '\n' + $("#txt_eventlog").val()); } /** * handles the event of a document is in progress of loading * */ function onpageloading(pagenumber){ $("#txt_eventlog").val('onpageloading:' + pagenumber + '\n' + $("#txt_eventlog").val()); } /** * receives messages about the current page being changed * * @example oncurrentpagechanged( 10 ); * * @param int pagenum */ function oncurrentpagechanged(pagenum){ $("#txt_eventlog").val('oncurrentpagechanged:' + pagenum + '\n' + $("#txt_eventlog").val()); } /** * receives messages about the document being loaded * * @example ondocumentloaded( 20 ); * * @param int totalpages */ function ondocumentloaded(totalpages){ $("#txt_eventlog").val('ondocumentloaded:' + totalpages + '\n' + $("#txt_eventlog").val()); } /** * receives messages about the page loaded * * @example onpageloaded( 1 ); * * @param int pagenumber */ function onpageloaded(pagenumber){ $("#txt_eventlog").val('onpageloaded:' + pagenumber + '\n' + $("#txt_eventlog").val()); } /** * receives messages about the page loaded * * @example onerrorloadingpage( 1 ); * * @param int pagenumber */ function onerrorloadingpage(pagenumber){ $("#txt_eventlog").val('onerrorloadingpage:' + pagenumber + '\n' + $("#txt_eventlog").val()); } /** * receives error messages when a document is not loading properly * * @example ondocumentloadederror( "network error" ); * * @param string errormessage */ function ondocumentloadederror(errmessage){ $("#txt_eventlog").val('ondocumentloadederror:' + errmessage + '\n' + $("#txt_eventlog").val()); } /** * receives error messages when a document has finished printed * * @example ondocumentprinted(); * */ function ondocumentprinted(){ $("#txt_eventlog").val('ondocumentprinted\n' + $("#txt_eventlog").val()); } /** * * flexpaper embedding functionality. based on flashembed * */ (function() { var ie = document.all, url = 'http://www.adobe.com/go/getflashplayer', jquery = typeof jquery == 'function', re = /(\d+)[^\d]+(\d+)[^\d]*(\d*)/, global_opts = { // very common opts width: '100%', height: '100%', id: "_" + ("" + math.random()).slice(9), // flashembed defaults allowfullscreen: true, allowscriptaccess: 'always', quality: 'high', // flashembed specific options version: [3, 0], onfail: null, expressinstall: null, w3c: false, cachebusting: false }; // version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/) if (window.attachevent) { window.attachevent("onbeforeunload", function() { __flash_unloadhandler = function() {}; __flash_savedunloadhandler = function() {}; }); } // simple extend function extend(to, from) { if (from) { for (var key in from) { if (from.hasownproperty(key)) { to[key] = from[key]; } } } return to; } // used by asstring method function map(arr, func) { var newarr = []; for (var i in arr) { if (arr.hasownproperty(i)) { newarr[i] = func(arr[i]); } } return newarr; } window.flashembed = function(root, opts, conf) { // root must be found / loaded if (typeof root == 'string') { root = document.getelementbyid(root.replace("#", "")); } // not found if (!root) { return; } root.onclick = function(){return false;} if (typeof opts == 'string') { opts = {src: opts}; } return new flash(root, extend(extend({}, global_opts), opts), conf); }; // flashembed "static" api var f = extend(window.flashembed, { conf: global_opts, getversion: function() { var fo, ver; try { ver = navigator.plugins["shockwave flash"].description.slice(16); } catch(e) { try { fo = new activexobject("shockwaveflash.shockwaveflash.7"); ver = fo && fo.getvariable("$version"); } catch(err) { try { fo = new activexobject("shockwaveflash.shockwaveflash.6"); ver = fo && fo.getvariable("$version"); } catch(err2) { } } } ver = re.exec(ver); return ver ? [ver[1], ver[3]] : [0, 0]; }, asstring: function(obj) { if (obj === null || obj === undefined) { return null; } var type = typeof obj; if (type == 'object' && obj.push) { type = 'array'; } switch (type){ case 'string': obj = obj.replace(new regexp('(["\\\\])', 'g'), '\\$1'); // flash does not handle %- characters well. transforms "50%" to "50pct" (a dirty hack, i admit) obj = obj.replace(/^\s?(\d+\.?\d+)%/, "$1pct"); return '"' +obj+ '"'; case 'array': return '['+ map(obj, function(el) { return f.asstring(el); }).join(',') +']'; case 'function': return '"function()"'; case 'object': var str = []; for (var prop in obj) { if (obj.hasownproperty(prop)) { str.push('"'+prop+'":'+ f.asstring(obj[prop])); } } return '{'+str.join(',')+'}'; } // replace ' --> " and remove spaces return string(obj).replace(/\s/g, " ").replace(/\'/g, "\""); }, gethtml: function(opts, conf) { opts = extend({}, opts); /******* object tag and it's attributes *******/ var html = ''; } // not allowed params opts.width = opts.height = opts.id = opts.w3c = opts.src = null; opts.onfail = opts.version = opts.expressinstall = null; for (var key in opts) { if (opts[key]) { html += ''; } } /******* flashvars *******/ var vars = ""; if (conf) { for (var k in conf) { if (conf[k]) { var val = conf[k]; vars += k +'='+ (/function|object/.test(typeof val) ? f.asstring(val) : val) + '&'; } } vars = vars.slice(0, -1); html += ''; } html += ""; return html; }, issupported: function(ver) { return version[0] > ver[0] || version[0] == ver[0] && version[1] >= ver[1]; } }); var version = f.getversion(); function flash(root, opts, conf) { // version is ok if (f.issupported(opts.version)) { root.innerhtml = f.gethtml(opts, conf); // express install } else if (opts.expressinstall && f.issupported([6, 65])) { root.innerhtml = f.gethtml(extend(opts, {src: opts.expressinstall}), { mmredirecturl: location.href, mmplayertype: 'plugin', mmdoctitle: document.title }); } else { // fail #2.1 custom content inside container if (!root.innerhtml.replace(/\s/g, '')) { /* root.innerhtml = "

flash version " + opts.version + " or greater is required

" + "

" + (version[0] > 0 ? "your version is " + version : "you have no flash plugin installed") + "

" + (root.tagname == 'a' ? "

click here to download latest version

" : "

download latest version from here

"); */ var pagehost = ((document.location.protocol == "https:") ? "https://" : "http://"); root.innerhtml = "get adobe flash player"; if (root.tagname == 'a') { root.onclick = function() { location.href = url; }; } } // onfail if (opts.onfail) { var ret = opts.onfail.call(this); if (typeof ret == 'string') { root.innerhtml = ret; } } } // http://flowplayer.org/forum/8/18186#post-18593 if (ie) { window[opts.id] = document.getelementbyid(opts.id); } // api methods for callback extend(this, { getroot: function() { return root; }, getoptions: function() { return opts; }, getconf: function() { return conf; }, getapi: function() { return root.firstchild; } }); } // setup jquery support if (jquery) { // tools version number jquery.tools = jquery.tools || {version: '1.2.5'}; jquery.tools.flashembed = { conf: global_opts }; jquery.fn.flashembed = function(opts, conf) { return this.each(function() { $(this).data("flashembed", flashembed(this, opts, conf)); }); }; } })();