flexpaper_flash.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. window.$FlexPaper = window["$FlexPaper"] = function(){
  2. if (window['flexpaper'])
  3. return window['flexpaper'];
  4. else
  5. window['flexpaper'] = window.FlexPaperViewer_Instance.getApi();
  6. return window['flexpaper'];
  7. };
  8. /**
  9. *
  10. * FlexPaper constructor (name of swf, name of placeholder, config)
  11. *
  12. */
  13. window.FlexPaperViewer = window.$f = function() {
  14. var config = arguments[2].config;
  15. window.FlexPaperViewer_Instance = flashembed(arguments[1], {
  16. src: arguments[0]+".swf",
  17. version: [10, 0],
  18. expressInstall: "js/expressinstall.swf"
  19. },{
  20. SwfFile : config.SwfFile,
  21. Scale : config.Scale,
  22. ZoomTransition : config.ZoomTransition,
  23. ZoomTime : config.ZoomTime,
  24. ZoomInterval : config.ZoomInterval,
  25. FitPageOnLoad : config.FitPageOnLoad,
  26. FitWidthOnLoad : config.FitWidthOnLoad,
  27. FullScreenAsMaxWindow : config.FullScreenAsMaxWindow,
  28. ProgressiveLoading : config.ProgressiveLoading,
  29. MinZoomSize : config.MinZoomSize,
  30. MaxZoomSize : config.MaxZoomSize,
  31. SearchMatchAll : config.SearchMatchAll,
  32. SearchServiceUrl : config.SearchServiceUrl,
  33. InitViewMode : config.InitViewMode,
  34. BitmapBasedRendering : config.BitmapBasedRendering,
  35. StartAtPage : config.StartAtPage,
  36. PrintPaperAsBitmap : config.PrintPaperAsBitmap,
  37. AutoAdjustPrintSize : config.AutoAdjustPrintSize,
  38. ViewModeToolsVisible : config.ViewModeToolsVisible,
  39. ZoomToolsVisible : config.ZoomToolsVisible,
  40. NavToolsVisible : config.NavToolsVisible,
  41. CursorToolsVisible : config.CursorToolsVisible,
  42. SearchToolsVisible : config.SearchToolsVisible,
  43. RenderingOrder : config.RenderingOrder,
  44. localeChain : config.localeChain,
  45. key : config.key
  46. });
  47. };
  48. /**
  49. * Handles the event of external links getting clicked in the document.
  50. *
  51. * @example onExternalLinkClicked("http://www.google.com")
  52. *
  53. * @param String link
  54. */
  55. function onExternalLinkClicked(link){
  56. // alert("link " + link + " clicked" );
  57. window.location.href = link;
  58. }
  59. /**
  60. * Recieves progress information about the document being loaded
  61. *
  62. * @example onProgress( 100,10000 );
  63. *
  64. * @param int loaded
  65. * @param int total
  66. */
  67. function onProgress(loadedBytes,totalBytes){
  68. }
  69. /**
  70. * Handles the event of a document is in progress of loading
  71. *
  72. */
  73. function onDocumentLoading(){
  74. }
  75. /**
  76. * Receives messages about the current page being changed
  77. *
  78. * @example onCurrentPageChanged( 10 );
  79. *
  80. * @param int pagenum
  81. */
  82. function onCurrentPageChanged(pagenum){
  83. }
  84. /**
  85. * Receives messages about the document being loaded
  86. *
  87. * @example onDocumentLoaded( 20 );
  88. *
  89. * @param int totalPages
  90. */
  91. function onDocumentLoaded(totalPages){
  92. }
  93. /**
  94. * Handles the event of a document is in progress of loading
  95. *
  96. */
  97. function onPageLoading(pageNumber){
  98. }
  99. /**
  100. * Receives messages about the page loaded
  101. *
  102. * @example onPageLoaded( 1 );
  103. *
  104. * @param int pageNumber
  105. */
  106. function onPageLoaded(pageNumber){
  107. }
  108. /**
  109. * Receives error messages when a document is not loading properly
  110. *
  111. * @example onDocumentLoadedError( "Network error" );
  112. *
  113. * @param String errorMessage
  114. */
  115. function onDocumentLoadedError(errMessage){
  116. }
  117. /**
  118. * Receives error messages when a document has finished printed
  119. *
  120. * @example onDocumentPrinted();
  121. *
  122. */
  123. function onDocumentPrinted(){
  124. }
  125. /**
  126. *
  127. * FlexPaper embedding functionality. Based on FlashEmbed
  128. *
  129. */
  130. (function() {
  131. var IE = document.all,
  132. URL = 'http://www.adobe.com/go/getflashplayer',
  133. JQUERY = typeof jQuery == 'function',
  134. RE = /(\d+)[^\d]+(\d+)[^\d]*(\d*)/,
  135. GLOBAL_OPTS = {
  136. // very common opts
  137. width: '100%',
  138. height: '100%',
  139. id: "_" + ("" + Math.random()).slice(9),
  140. // flashembed defaults
  141. allowfullscreen: true,
  142. allowscriptaccess: 'always',
  143. quality: 'high',
  144. // flashembed specific options
  145. version: [3, 0],
  146. onFail: null,
  147. expressInstall: null,
  148. w3c: false,
  149. cachebusting: false
  150. };
  151. if(IE){GLOBAL_OPTS.cachebusting=true;}
  152. // version 9 bugfix: (http://blog.deconcept.com/2006/07/28/swfobject-143-released/)
  153. if (window.attachEvent) {
  154. window.attachEvent("onbeforeunload", function() {
  155. __flash_unloadHandler = function() {};
  156. __flash_savedUnloadHandler = function() {};
  157. });
  158. }
  159. // simple extend
  160. function extend(to, from) {
  161. if (from) {
  162. for (var key in from) {
  163. if (from.hasOwnProperty(key)) {
  164. to[key] = from[key];
  165. }
  166. }
  167. }
  168. return to;
  169. }
  170. // used by asString method
  171. function map(arr, func) {
  172. var newArr = [];
  173. for (var i in arr) {
  174. if (arr.hasOwnProperty(i)) {
  175. newArr[i] = func(arr[i]);
  176. }
  177. }
  178. return newArr;
  179. }
  180. window.flashembed = function(root, opts, conf) {
  181. // root must be found / loaded
  182. if (typeof root == 'string') {
  183. root = document.getElementById(root.replace("#", ""));
  184. }
  185. // not found
  186. if (!root) { return; }
  187. root.onclick = function(){return false;}
  188. if (typeof opts == 'string') {
  189. opts = {src: opts};
  190. }
  191. return new Flash(root, extend(extend({}, GLOBAL_OPTS), opts), conf);
  192. };
  193. // flashembed "static" API
  194. var f = extend(window.flashembed, {
  195. conf: GLOBAL_OPTS,
  196. getVersion: function() {
  197. var fo, ver;
  198. try {
  199. ver = navigator.plugins["Shockwave Flash"].description.slice(16);
  200. } catch(e) {
  201. try {
  202. fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
  203. ver = fo && fo.GetVariable("$version");
  204. } catch(err) {
  205. try {
  206. fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
  207. ver = fo && fo.GetVariable("$version");
  208. } catch(err2) { }
  209. }
  210. }
  211. ver = RE.exec(ver);
  212. return ver ? [ver[1], ver[3]] : [0, 0];
  213. },
  214. asString: function(obj) {
  215. if (obj === null || obj === undefined) { return null; }
  216. var type = typeof obj;
  217. if (type == 'object' && obj.push) { type = 'array'; }
  218. switch (type){
  219. case 'string':
  220. obj = obj.replace(new RegExp('(["\\\\])', 'g'), '\\$1');
  221. // flash does not handle %- characters well. transforms "50%" to "50pct" (a dirty hack, I admit)
  222. obj = obj.replace(/^\s?(\d+\.?\d+)%/, "$1pct");
  223. return '"' +obj+ '"';
  224. case 'array':
  225. return '['+ map(obj, function(el) {
  226. return f.asString(el);
  227. }).join(',') +']';
  228. case 'function':
  229. return '"function()"';
  230. case 'object':
  231. var str = [];
  232. for (var prop in obj) {
  233. if (obj.hasOwnProperty(prop)) {
  234. str.push('"'+prop+'":'+ f.asString(obj[prop]));
  235. }
  236. }
  237. return '{'+str.join(',')+'}';
  238. }
  239. // replace ' --> " and remove spaces
  240. return String(obj).replace(/\s/g, " ").replace(/\'/g, "\"");
  241. },
  242. getHTML: function(opts, conf) {
  243. opts = extend({}, opts);
  244. /******* OBJECT tag and it's attributes *******/
  245. var html = '<object width="' + opts.width +
  246. '" height="' + opts.height +
  247. '" id="' + opts.id +
  248. '" name="' + opts.id + '"';
  249. if (opts.cachebusting) {
  250. opts.src += ((opts.src.indexOf("?") != -1 ? "&" : "?") + Math.random());
  251. }
  252. if (opts.w3c || !IE) {
  253. html += ' data="' +opts.src+ '" type="application/x-shockwave-flash"';
  254. } else {
  255. html += ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';
  256. }
  257. html += '>';
  258. /******* nested PARAM tags *******/
  259. if (opts.w3c || IE) {
  260. html += '<param name="movie" value="' +opts.src+ '" />';
  261. }
  262. // not allowed params
  263. opts.width = opts.height = opts.id = opts.w3c = opts.src = null;
  264. opts.onFail = opts.version = opts.expressInstall = null;
  265. for (var key in opts) {
  266. if (opts[key]) {
  267. html += '<param name="'+ key +'" value="'+ opts[key] +'" />';
  268. }
  269. }
  270. /******* FLASHVARS *******/
  271. var vars = "";
  272. if (conf) {
  273. for (var k in conf) {
  274. if (conf[k]) {
  275. var val = conf[k];
  276. vars += k +'='+ (/function|object/.test(typeof val) ? f.asString(val) : val) + '&';
  277. }
  278. }
  279. vars = vars.slice(0, -1);
  280. html += '<param name="flashvars" value=\'' + vars + '\' />';
  281. }
  282. html += "</object>";
  283. return html;
  284. },
  285. isSupported: function(ver) {
  286. return VERSION[0] > ver[0] || VERSION[0] == ver[0] && VERSION[1] >= ver[1];
  287. }
  288. });
  289. var VERSION = f.getVersion();
  290. function Flash(root, opts, conf) {
  291. // version is ok
  292. if (f.isSupported(opts.version)) {
  293. root.innerHTML = f.getHTML(opts, conf);
  294. // express install
  295. } else if (opts.expressInstall && f.isSupported([6, 65])) {
  296. root.innerHTML = f.getHTML(extend(opts, {src: opts.expressInstall}), {
  297. MMredirectURL: location.href,
  298. MMplayerType: 'PlugIn',
  299. MMdoctitle: document.title
  300. });
  301. } else {
  302. // fail #2.1 custom content inside container
  303. if (!root.innerHTML.replace(/\s/g, '')) {
  304. /* root.innerHTML =
  305. "<h2>Flash version " + opts.version + " or greater is required</h2>" +
  306. "<h3>" +
  307. (VERSION[0] > 0 ? "Your version is " + VERSION : "You have no flash plugin installed") +
  308. "</h3>" +
  309. (root.tagName == 'A' ? "<p>Click here to download latest version</p>" :
  310. "<p>Download latest version from <a href='" + URL + "'>here</a></p>");
  311. */
  312. var pageHost = ((document.location.protocol == "https:") ? "https://" : "http://");
  313. root.innerHTML = "<a href='http://www.adobe.com/go/getflashplayer'><img src='"
  314. + pageHost + "www.adobe.com/images/shared/download_buttons/get_flash_player.gif' alt='Get Adobe Flash player' /></a>";
  315. if (root.tagName == 'A') {
  316. root.onclick = function() {
  317. location.href = URL;
  318. };
  319. }
  320. }
  321. // onFail
  322. if (opts.onFail) {
  323. var ret = opts.onFail.call(this);
  324. if (typeof ret == 'string') { root.innerHTML = ret; }
  325. }
  326. }
  327. // http://flowplayer.org/forum/8/18186#post-18593
  328. if (IE) {
  329. window[opts.id] = document.getElementById(opts.id);
  330. }
  331. // API methods for callback
  332. extend(this, {
  333. getRoot: function() {
  334. return root;
  335. },
  336. getOptions: function() {
  337. return opts;
  338. },
  339. getConf: function() {
  340. return conf;
  341. },
  342. getApi: function() {
  343. return root.firstChild;
  344. }
  345. });
  346. }
  347. // setup jquery support
  348. if (JQUERY) {
  349. // tools version number
  350. jQuery.tools = jQuery.tools || {version: '1.2.5'};
  351. jQuery.tools.flashembed = {
  352. conf: GLOBAL_OPTS
  353. };
  354. jQuery.fn.flashembed = function(opts, conf) {
  355. return this.each(function() {
  356. $(this).data("flashembed", flashembed(this, opts, conf));
  357. });
  358. };
  359. }
  360. })();