!import
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 * Michael Lowe <michael.lowe@bigfoot.com>
26 * Blake Ross <blaker@netscape.com>
27 * Neil Rashbrook <neil@parkwaycc.co.uk>
28 *
29 * Alternatively, the contents of this file may be used under the terms of
30 * either of the GNU General Public License Version 2 or later (the "GPL"),
31 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
32 * in which case the provisions of the GPL or the LGPL are applicable instead
33 * of those above. If you wish to allow use of your version of this file only
34 * under the terms of either the GPL or the LGPL, and not to allow others to
35 * use your version of this file under the terms of the MPL, indicate your
36 * decision by deleting the provisions above and replace them with the notice
37 * and other provisions required by the GPL or the LGPL. If you do not delete
38 * the provisions above, a recipient may use your version of this file under
39 * the terms of any one of the MPL, the GPL or the LGPL.
40 *
41 * ***** END LICENSE BLOCK ***** */
42
43 var browser;
44 var dialog = {};
45 var pref = null;
46 try {
47 pref = Components.classes["@mozilla.org/preferences-service;1"]
48 .getService(Components.interfaces.nsIPrefBranch);
49 } catch (ex) {
50 // not critical, remain silent
51 }
52
onLoad
53 function onLoad()
54 {
55 dialog.input = document.getElementById("dialog.input");
56 dialog.attach = document.documentElement.getButton("accept");
57 dialog.bundle = document.getElementById("attachWebPageBundle");
58
59 // change OK button text to 'attach'
60 dialog.attach.label = dialog.bundle.getString("attachButtonLabel");
61
62 if (pref) {
63 try {
64 dialog.input.value =
65 pref.getComplexValue("mailnews.attach_web_page.last_url",
66 Components.interfaces.nsISupportsString).data;
67 }
68 catch(ex) {
69 }
70 }
71
72 doEnabling();
73 }
74
doEnabling
75 function doEnabling()
76 {
77 dialog.attach.disabled = !dialog.input.value;
78 }
79
attach
80 function attach()
81 {
82 var attachment = Components.classes["@mozilla.org/messengercompose/attachment;1"]
83 .createInstance(Components.interfaces.nsIMsgAttachment);
84 attachment.url = dialog.input.value;
85 window.arguments[0].attachment = attachment;
86 if (pref) {
87 var str = Components.classes["@mozilla.org/supports-string;1"]
88 .createInstance(Components.interfaces.nsISupportsString);
89 str.data = dialog.input.value;
90 pref.setComplexValue("mailnews.attach_web_page.last_url",
91 Components.interfaces.nsISupportsString, str);
92 }
93 return true;
94 }
95
onChooseFile
96 function onChooseFile()
97 {
98 try {
99 var fp = Components.classes["@mozilla.org/filepicker;1"]
100 .createInstance(Components.interfaces.nsIFilePicker);
101 fp.init(window, dialog.bundle.getString("chooseFileDialogTitle"), fp.modeOpen);
102 fp.appendFilters(fp.filterHTML | fp.filterText |
103 fp.filterAll | fp.filterImages | fp.filterXML);
104 if (fp.show() == fp.returnOK && fp.fileURL.spec && fp.fileURL.spec.length > 0)
105 dialog.input.value = fp.fileURL.spec;
106 }
107 catch(ex) {
108 }
109 doEnabling();
110 }
111
useUBHistoryItem
112 function useUBHistoryItem(aMenuItem)
113 {
114 var urlbar = document.getElementById("dialog.input");
115 urlbar.value = aMenuItem.getAttribute("label");
116 urlbar.select();
117 doEnabling();
118 }