/**
█▒▓▒░ the flexpaper project
this file is part of flexpaper.
flexpaper is free software: you can redistribute it and/or modify
it under the terms of the gnu general public license as published by
the free software foundation, version 3 of the license.
flexpaper is distributed in the hope that it will be useful,
but without any warranty; without even the implied warranty of
merchantability or fitness for a particular purpose. see the
gnu general public license for more details.
you should have received a copy of the gnu general public license
along with flexpaper. if not, see .
for more information on flexpaper please see the flexpaper project
home page: http://flexpaper.devaldi.com
*/
/**
*
* flexpaper helper function for retrieving a active flexpaper instance
*
*/
window.$flexpaper = window.getdocviewer = window["$flexpaper"] = function(id){
var instance = (id==="undefined")?"":id;
return window["flexpaperviewer_instance"+instance].getapi();
};
/**
*
* flexpaper embedding (name of placeholder, config)
*
*/
window.flexpaperviewerembedding = window.$f = function(id, args) {
var config = args.config;
var _swffile,_pdffile,_imgfiles,_jsonfile = "",_jsdirectory="",_cssdirectory="",_localedirectory="";_wmode = (config.wmode!=null||config.wmmode!=null?config.wmmode||config.wmode:"window");
var _udoc = ((config.doc !=null)?unescape(config.doc):null);
var instance = "flexpaperviewer_instance"+((id==="undefined")?"":id);
var _jsondatatype = (config.jsondatatype!=null)?config.jsondatatype:"json";
if (_udoc != null) {
_swffile = translateurlbyformat(_udoc,"swf");
_pdffile = translateurlbyformat(_udoc,"pdf");
_jsonfile = translateurlbyformat(_udoc,_jsondatatype);
_imgfiles = translateurlbyformat(_udoc,"png");
}
_swffile = (config.swffile!=null?config.swffile:_swffile);
_swffile = (config.swffile!=null?config.swffile:_swffile);
_pdffile = (config.pdffile!=null?config.pdffile:_pdffile);
_imgfiles = (config.imgfiles!=null?config.imgfiles:_imgfiles);
_imgfiles = (config.pageimagepattern!=null?config.pageimagepattern:_imgfiles);
_jsonfile = (config.jsonfile!=null?config.jsonfile:_jsonfile);
_jsdirectory = (config.jsdirectory!=null?config.jsdirectory:"js/");
_cssdirectory = (config.cssdirectory!=null?config.cssdirectory:"css/");
_localedirectory = (config.localedirectory!=null?config.localedirectory:"locale/");
if(_swffile!=null && _swffile.indexof("{" )==0 && _swffile.indexof("[*," ) > 0 && _swffile.indexof("]" ) > 0){_swffile = escape(_swffile);} // split file fix
window[instance] = flashembed(id, {
src : _jsdirectory+"../flexpaperviewer.swf",
version : [10, 0],
expressinstall : "js/expressinstall.swf",
wmode : _wmode
},{
elementid : id,
swffile : _swffile,
pdffile : _pdffile,
imgfiles : _imgfiles,
jsonfile : _jsonfile,
usecustomjsonformat : config.usecustomjsonformat,
jsonpagedataformat : config.jsonpagedataformat,
jsondatatype : _jsondatatype,
scale : (config.scale!=null)?config.scale:0.8,
zoomtransition : (config.zoomtransition!=null)?config.zoomtransition:'easeout',
zoomtime : (config.zoomtime!=null)?config.zoomtime:0.5,
zoominterval : (config.zoominterval)?config.zoominterval:0.2,
fitpageonload : (config.fitpageonload!=null)?config.fitpageonload:false,
fitwidthonload : (config.fitwidthonload!=null)?config.fitwidthonload:false,
fullscreenasmaxwindow : (config.fullscreenasmaxwindow!=null)?config.fullscreenasmaxwindow:false,
progressiveloading : (config.progressiveloading!=null)?config.progressiveloading:false,
minzoomsize : (config.minzoomsize!=null)?config.minzoomsize:0.2,
maxzoomsize : (config.maxzoomsize!=null)?config.maxzoomsize:5,
searchmatchall : (config.searchmatchall!=null)?config.searchmatchall:false,
searchserviceurl : config.searchserviceurl,
initviewmode : config.initviewmode,
bitmapbasedrendering : (config.bitmapbasedrendering!=null)?config.bitmapbasedrendering:false,
startatpage : config.startatpage,
printpaperasbitmap : (config.printpaperasbitmap!=null)?config.printpaperasbitmap:false,
autoadjustprintsize : (config.autoadjustprintsize!=null)?config.autoadjustprintsize:false,
enablecornerdragging : ((config.enablecornerdragging!=null)?config.enablecornerdragging:true), // flexpaper zine parameter
backgroundcolor : config.backgroundcolor, // flexpaper zine parameter
panelcolor : config.panelcolor, // flexpaper zine parameter
backgroundalpha : config.backgroundalpha, // flexpaper zine parameter
uiconfig : config.uiconfig, // flexpaper zine parameter
viewmodetoolsvisible : ((config.viewmodetoolsvisible!=null)?config.viewmodetoolsvisible:true),
zoomtoolsvisible : ((config.zoomtoolsvisible!=null)?config.zoomtoolsvisible:true),
navtoolsvisible : ((config.navtoolsvisible!=null)?config.navtoolsvisible:true),
cursortoolsvisible : ((config.searchtoolsvisible!=null)?config.cursortoolsvisible:true),
searchtoolsvisible : ((config.searchtoolsvisible!=null)?config.searchtoolsvisible:true),
stickytools : config.stickytools,
toolbar : config.toolbar,
docsizequeryservice : config.docsizequeryservice,
renderingorder : config.renderingorder,
localechain : (config.localechain!=null)?config.localechain:"en_us",
jsdirectory : _jsdirectory,
cssdirectory : _cssdirectory,
localedirectory : _localedirectory,
key : config.key
});
};
function translateurlbydocument(url,document){
return (url!=null && url.indexof('{doc}') > 0 ? url.replace("{doc}", document):null);
}
function translateurlbyformat(url,format){
if(url.indexof("{") == 0 && format != "swf"){ // loading in split file mode
url = url.substring(1,url.lastindexof(","));
url = url.replace("[*,0]","{page}")
}
return (url!=null && url.indexof('{format}') > 0 ? url.replace("{format}", format):null);
}
/**
*
* 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*)/,
mobile = (function(){try {return 'ontouchstart' in document.documentelement;} catch (e) {return false;} })(),
global_opts = {
// very common opts
width: '100%',
height: '100%',
id: "_" + ("" + math.random()).slice(9),
// flashembed defaults
allowfullscreen: true,
allowscriptaccess: 'always',
quality: 'high',
allowfullscreeninteractive : true,
// flashembed specific options
version: [10, 0],
onfail: null,
expressinstall: null,
w3c: false,
cachebusting: false
};
window.istouchscreen = mobile;
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 flash to dispatch a event properly
window.dispatchjqueryevent = function (elementid,eventname,args){
jquery('#'+elementid).trigger(eventname,args);
}
// 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);
opts.id = opts.id + (" " + math.random()).slice(9);
/******* object tag and it's attributes *******/
var 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) {
var useragent = navigator.useragent.tolowercase();
var browser = {
version: (useragent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
safari: /webkit/.test(useragent),
opera: /opera/.test(useragent),
msie: /msie/.test(useragent) && !/opera/.test(useragent),
mozilla: /mozilla/.test(useragent) && !/(compatible|webkit)/.test(useragent),
chrome: /chrome/.test(useragent)
};
// default to a rendering mode if its not set
if(!conf.renderingorder && conf.swffile != null){conf.renderingorder = "flash";}
if(conf.renderingorder.indexof('html5')==0){
if(confirm('flexpaper gpl version does not support html5 rendering. do you want to navigate to our download page for more details?')){location.href='http://flexpaper.devaldi.com/download.jsp?ref=flexpaper'}
return;
}
if(conf.renderingorder.indexof('html')==0){
if(confirm('flexpaper gpl version does not support html4 rendering. do you want to navigate to our download page for more details?')){location.href='http://flexpaper.devaldi.com/download.jsp?ref=flexpaper'}
return;
}
// 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 { //use html viewer or die
// fail #2.1 custom content inside container
if (!root.innerhtml.replace(/\s/g, '')) {
var pagehost = ((document.location.protocol == "https:") ? "https://" : "http://");
root.innerhtml =
"
your browser is not compatible with flexpaper
" +
"upgrade to a newer browser or download adobe flash player 10 or higher.
" +
"click on the icon below to download the latest version of adobe flash" +
"";
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) {
jquery.fn.flashembed = function(opts, conf) {
return this.each(function() {
jquery(this).data("flashembed", flashembed(this, opts, conf));
});
};
jquery.fn.flexpaperviewer = function(args){
this.element = new flexpaperviewerembedding(this.attr('id'),args);
};
}else{
throw new error("jquery missing!");
}
})();