/* * Utility functions and constants for the Page Saver Toolkit. * * Copyright (c) 2007-2009 Pearl Crescent, LLC. All Rights Reserved. * * Version 1.2. * * Permission is granted to use this file and its contents in your * own applications. */ /* * Call PageSaverInitialize() once to initialize the Page Saver Toolkit. * Returns a Boolean true value if successful. */ function PageSaverInitialize() { var psEvent = document.createEvent("Event"); if (psEvent) { psEvent.initEvent("PageSaverInitAPI", true, true); window.dispatchEvent(psEvent); } return ("PageSaverCaptureImage" in window); } /* * The main Page Saver Toolkit function is PageSaverCaptureImage, which * is available after a successful call to PageSaverInitialize(). This * function initiates a page capture operation which takes place in the * background (asynchronously). It should be called like this: * * PageSaverCaptureImage(captureWindow, capturePortion, destination, * destPathOrURI, options, completionFuncName); * * where: * captureWindow is the window whose contents should be captured. Pass null * to capture the contents of the current window. * * capturePortion is one of the capture portion values defined below. * * destination is one of the destination values defined below. * * destPathOrURI specifies the destination file or server location. * The destPathOrURI parameter may contain a file pathname, * an ftp:// URL, an http:// URL, or an https:// URL. When * specifying a file pathname, use care to avoid overwriting * an existing file by mistake. When specifying a URL, include * the password in the URL if it has not been saved in the * Firefox Password Manager. * * To save the captured image in the default file location, * pass null for destPathOrURI and pass * kPageSaverDestinationLocalFile for the destination * parameter. * * To save the captured image to the server that is configured * in the Page Saver options, pass null for destPathOrURI and * pass kPageSaverDestinationServer for the destination * parameter. * * options is a string that contains a comma-separated list of options: * closeWhenDone - close the window after capture is complete. * exitWhenDone - exit Firefox after capture is complete. * noInteraction - do not interact with the user, play sounds, etc. * top= - omit from the captured image the first pixelval * pixels along the top of page. * left= - omit from the captured image the first pixelval * pixels along the left side of the page. * bottom= - crop the captured image along the bottom at * pixelval pixels. If pixelval is a negative * number, crop at pixelval pixels from the bottom. * right= - crop the captured image along the right side at * pixelval pixels. If pixelval is a negative * number, crop at pixelval pixels from the right. * element= - the id of an element which is to be captured. * scale= - reduce or limit the size of the captured image. * If scaleval ends with a % character, the image * is scaled to the specified percentage. * If scaleval is a simple integer, the largest * dimension of the resulting image will be no * larger than scaleval pixels. * format= - specify format of saved image. The content-type * may include options, e.g., image/jpeg@quality=90. * * * completionFunc is a string that, if it is not null, specifies the name * of a function that is called when the image capture * operation has finished. The function should be defined * like: * function OnCaptureComplete(aResultCode, aMsg) * { * ... * } * The aResultCode parameter is an integer result code; it * will be one of the result code values defined below. * The aMsg parameter is a string that, if it is not null, * provides more information about an error that occurred. */ /* * Capture portion values. */ const kPageSaverPortionVisible = 0; // Capture the visible part of a page. const kPageSaverPortionEntire = 1; // Capture an entire page. const kPageSaverPortionSelected = 2; // Capture a selected region of a page. /* * Destination values. */ const kPageSaverDestinationDefault = -2; // Use the default destination set // in the Page Saver Pro options. const kPageSaverDestinationClipboard = -1; // The system clipboard. const kPageSaverDestinationLocalFile = 0; // A local file. const kPageSaverDestinationServer = 1; // A remote file (FTP of HTTP PUT). /* * Result code values. Success is indicated by kPageSaverResultCodeSuccess. */ const kPageSaverResultCodeSuccess = 0; const kPageSaverResultCodeCancelled = 1; const kPageSaverResultCodeNoInteractionAllowed = 2; const kPageSaverResultCodeInvalidArg = 3; const kPageSaverResultCodeNoCanvas = 4; const kPageSaverResultCodeCanvasDrawingError = 5; const kPageSaverResultCodeCanvasStreamError = 6; const kPageSaverResultCodeInvalidFilePath = 7; const kPageSaverResultCodeFileOutputError = 8; const kPageSaverResultCodeUploadError = 9; const kPageSaverResultCodeClipboardError = 10; const kPageSaverResultCodeElementNotFound = 11; const kPageSaverResultCodeRequestError = 12;