flexpaper_flash_debug.js 11 KB

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