Aurigma File Downloader 7.0.5
Helper Script Reference (iuembed.js)
The iuembed.js helper script is a special JavaScript that is used to embed File Downloader to the HTML page. This topic describes how to use this script.
In this topic:
-
Using Helper Script
- Linking iuembed.js to the Page
- Adding File Downloader to a Web Page
- Initializing File Downloader Parameters
- Configuring an Alternate Text for the Control
- Adding Event Handlers
- Getting a Reference to File Downloader by ID
- Working with Properties Dynamically
- Calling Methods
- Page Load and Initialization Events
- Helper Script Members
You may wonder why to use a separate JavaScript file instead of using standard HTML means of inserting ActiveX controls? The main reason is that this approach lets you avoid the problem caused by the Internet Explorer security update 912945. This update causes all ActiveX controls inserted via the OBJECT tag to be "activated" by the user (with a mouse click or by pressing a key). This noticeably reduces usability. However, iuembed.js implements a workaround that allows avoiding this.
This script is used in the following way:
- Link the iuembed.js file to your HTML page.
- Create an instance of FileDownloaderWriter object.
- Initialize parameters of FileDownloader control.
- Add event handlers if necessary.
- Call the writeHtml method in the necessary part of your HTML code that will embed the FileDownloader instance into the page.
- After the FileDownloader control is embedded, you can get an instance of this control, edit its properties, and call its methods dynamically.
You can find iuembed.js in the root folder of the File Downloader SDK installation folder.
Using Helper Script
Linking iuembed.js to the Page
To be able to use iuembed.js, it is necessary to link it to your page. You can do it in the same way as you do with other JavaScript files, that is by using the SCRIPT tag with the src attribute set to the URL of iuembed.js.
In other words, you should insert the following string into the beginning of the HTML page (before any other JavaScript code):
JavaScript
<script type="text/javascript" src="iuembed.js"></script>
Adding File Downloader to a Web Page
To embed File Downloader into a Web page, you need to do at least the following:
- Create a new FileDownloaderWriter class instance.
- Call the writeHtml method of this object to generate code which will embed File Downloader and write it into the page. Alternatively you can use the getHtml method to get this code as a string.
Here is a short example of adding File Downloader to a Web page:
JavaScript
<script type="text/javascript">
var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
fd.writeHtml();
</script>
The FileDownloaderWriter constructor has three arguments: an ID of the control, a width, and a height. You can change these values later using appropriate properties.
Full list of FileDownloaderWriter members can be found at the end of this topic.
Initializing File Downloader Parameters
To initialize parameters of File Downloader you should use the addParam method of the FileDownloaderWriter class instance before calling writeHtml.
The addParam method takes two arguments: a name of the property and its value.
The following example should make it clear:
JavaScript
<script type="text/javascript">
var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
fd.addParam("FileList", "http://localhost/filedownloader/filelist.txt");
fd.writeHtml();
</script>
Configuring an Alternate Text for the Control
It takes a while to download and install File Downloader. After download completes, the browser requires the user to click a button on the security dialog. Furthermore, if File Downloader is installed on Windows XP with Service Pack 2, the user should also click an information bar before the security dialog appears.
It may be quite confusing for the user. They may misunderstand installation instructions and reject installation when security dialog pops up.
In this case, displaying installation instructions is a good idea. iuembed.js exposes a number of properties that enable this.
The instructionsEnabled property specifies whether to display instructions or not. Set it to true to make instructions appear. The instructionsCommon property specifies an HTML code for those instructions which are common for all client platforms. The instructionsWinXPSP2 and instructionsNotWinXPSP2 values are appended to the common instructions depending on the client platform (Windows XP with Service Pack 2 or other platforms respectively).
This code snippet demonstrates how to use these properties:
JavaScript
fd.instructionsEnabled=true; fd.instructionsCommon="File Downloader ActiveX control is necessary to " + "download files quickly and easily. You will be able to select required " + "files in a user-friendly interface and simply click the \"Download\" " + "button. Installation will take up to few minutes, please be patient. To " + "install File Downloader, "; fd.instructionsNotWinXPSP2="please reload the page and click the \"Yes\" " + "button when you see the control installation dialog." fd.instructionsWinXPSP2="please click the Information Bar. After page reloads " + "click \"Yes\" when you see the control installation dialog.";
Adding Event Handlers
File Downloader provides a number of useful events which you can handle. To add event listeners do the following:
- Create a JavaScript function that has the same list of arguments as the event.
- Use the addEventListener method of the FileDownloaderWriter object. This method has two arguments: the name of the event and the name of the function created on the first step.
This example demonstrates how this should look like:
JavaScript
<script type="text/javascript">
function onError(Code, Description, HttpCode, Page, Url, Index){
//Your code
}
var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
fd.addEventListener("Error", "onError");
</script>
See the full list of all FileDownloader events in the FileDownloader Events reference section.
Getting a Reference to File Downloader by ID
The iuembed.js script contains a special function - getFileDownloader. It takes a single argument - the ID of the control, which you want to reference (for example, specified when creating an instance of FileDownloaderWriter), and returns a reference to the control.
Here is an example of obtaining a referenece:
JavaScript
var downloader = getFileDownloader("FileDownloader1");
Working with Properties Dynamically
Sometimes you need to modify File Downloader properties after initialization. The typical situation is when you need to change the file list in response to some user actions.
To do that, you should get a reference to the FileDownloader control as described above and modify the value of a required property.
The syntax of runtime property modification is the following:
object.setPropertyName(value), where PropertyName is a name of the property as specified in the FileDownloader Properties reference.
To read a property value, use object.getPropertyName instead.
The code snippet below shows how to work with properties after initialization:
JavaScript
var downloader = getFileDownloader("FileDownloader1");
downloader.setFileList(downloader.getFileList());
Calling Methods
To call methods of FileDownloader, use the same approach as you use for properties: get a reference to the FileDownloader instance and call methods:
object.MethodName(argument1, argument2, ...), where MethodName is a name of the method as specified in the FileDownloader Methods reference.
Here is a code example:
JavaScript
var downloader = getFileDownloader("FileDownloader1");
downloader.DownloadFileList();
Page Load and Initialization Events
Quite often it is necessary to work with the File Downloader control when you are sure that the page has been fully loaded and the control itself has been completely created and initialized.
That is why iuembed.js exposes a special event, which is raised when the page is loaded, and the control is completely ready to be used. This event handler can be assigned to the fullPageLoadListenerName property of FileDownloaderWriter as follows:
JavaScript
<script language="javascript">
function onFullPageLoad(){
// ... Add necessary code ...
}
var fd = new FileDownloaderWriter("FileDownloader", 122, 44);
fd.fullPageLoadListenerName = "onFullPageLoad";
// ... Configure File Downloader ...
fd.writeHtml();
</script>
Helper Script Members
Classes
iuembed.js exposes only one class, FileDownloaderWriter, which corresponds to the only class of File Downloader, FileDownloader.
Methods
| Name | Arguments | Description |
|---|---|---|
|
|
|
Adds a parameter with the specified name and value. The settings take effect when the writeHtml or getHtml method is run. |
|
|
|
Subscribes the specified JavaScript function to the specified event. |
|
|
N/A |
Verifies whether ActiveX control is installed. If yes, it returns true; otherwise it returns false. |
|
|
N/A |
Generates the HTML code which will embed File Downloader and returns it as a string. It will write all parameters added with the addParam method and append all event handlers specified by the addEventListener method. |
|
|
N/A |
Generates the HTML code, which will embed File Downloader, and writes this code directly into the page. It will write all parameters added with the addParam method and append all event handlers specified by the addEventListener method. |
Properties
| Name | Default value | Description |
|---|---|---|
|
|
FileDownloader7.cab |
The URL that specifies where to download the ActiveX version of File Downloader from. It is an analogue of the codebase attribute of the <object> element. |
|
|
FileDownloader7_x64.cab |
The URL that specifies where to download the 64-bit ActiveX version of File Downloader from. It is an analogue of the codebase attribute of the <object> element. |
|
|
true |
Switch that specifies whether to use the ActiveX version of File Downloader. |
|
|
empty string |
The minimum required version of the ActiveX version of File Downloader. |
|
|
./ |
The URL that specifies the folder where to download the Java version of File Downloader from. |
|
|
FileDownloader7.jar |
Name of the .jar file. |
|
|
true |
Switch that specifies whether to use the Java version of File Downloader. |
|
|
empty string |
The minimum required version of the Java version of File Downloader. |
|
|
N/A (provided in the constructor) |
Height of the control. You should provide an integer number. Syntax like 100% is acceptable. |
|
|
N/A (provided in the constructor) |
ID of the control that is used to get a reference with the help of the getFileDownloader function. |
|
|
true |
Value that specifies whether to display instructionsCommon , instructionsNotWinXPSP2, and instructionsWinXPSP2 when File Downloader fails to be installed. |
|
|
See code snippet above |
Common part of instructions displayed during download failure (regardless of the Windows version). Can contain any HTML code. |
|
|
See code snippet above |
Part of instructions which is displayed if the current Windows is not Windows XP with Service Pack 2. Appended to the instructionsCommon string. Can contain any HTML code. |
|
|
See code snippet above |
Part of instructions which is displayed if the current Windows is Windows XP with Service Pack 2. Appended to the instructionsCommon string. Can contain any HTML code. |
|
|
N/A (provided in the constructor) |
Width of the control. You should provide an integer number. Syntax like 100% is acceptable. |
Standalone Functions
| Name | Arguments | Description |
|---|---|---|
|
|
|
Returns a reference to the control with the specified ID. |
Members for Private-Label Versions
When private-label version is used, you need to customize the following properties (that should not be changed in the standard version):
| Name | Description |
|---|---|
|
|
Name of the .cab file. |
|
|
Name of the x64 .cab file. |
|
|
CLSID of the ActiveX control. |
|
|
PROGID of the ActiveX control. |
|
|
Name of the .jar file. |
|
|
Java applet class name. |
The following code snippet demonstrates how to use these properties:
JavaScript
<script type="text/javascript">
var fd = new FileDownloaderWriter("FileDownloader1", 122, 44);
fd.activeXControlCodeBase = "MyDownloader.cab";
fd.activeXClassId = "B8144F57-C240-4012-A5AE-6E06019EDA5F";
fd.activeXProgId = "MyCompany.MyDownloader";
fd.javaAppletCodeBase = "MyDownloader.jar";
fd.writeHtml();
</script>