flexpaper_flash.js 10 KB

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