0
|
1 var tiny = null;
|
|
2
|
|
3 /**
|
|
4 * Create a TinyUrl from the current url
|
|
5 */
|
|
6 function tinyurl_create_load(){
|
|
7 window.removeEventListener("load", tinyurl_create_load, true);
|
|
8
|
|
9 if(window.arguments.length > 0 && tiny == null){
|
|
10 tiny = window.arguments[0];
|
|
11
|
|
12 document.getElementById("cancel-btn").focus();
|
|
13
|
|
14 var loaded = {
|
|
15 done : function(oTiny){
|
|
16 try{
|
|
17 // Set values
|
|
18 document.getElementById("tinyurl-label").appendChild(document.createTextNode(oTiny.tiny));
|
|
19 document.getElementById("loading-steps").selectedIndex = 1;
|
|
20 document.getElementById("cancel-btn").setAttribute("default", false);
|
|
21 document.getElementById("close1-btn").setAttribute("default", true);
|
|
22 document.getElementById("close1-btn").focus();
|
|
23
|
|
24 // Copy text
|
|
25 var clipboard = Components.classes["@mozilla.org/widget/clipboardhelper;1"].getService(Components.interfaces.nsIClipboardHelper);
|
|
26 clipboard.copyString(oTiny.tiny);
|
|
27
|
|
28 // Auto-hide the window
|
|
29 var oPrefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
|
|
30 if(oPrefs.prefHasUserValue("tinyurl.confirmation.hide") && oPrefs.getBoolPref("tinyurl.confirmation.hide")){
|
|
31 self.close();
|
|
32 }
|
|
33 else{
|
|
34 window.focus();
|
|
35 }
|
|
36 }catch(e){ }
|
|
37 },
|
|
38
|
|
39 error : function(oTiny){
|
|
40 document.getElementById("loading-steps").selectedIndex = 2;
|
|
41 document.getElementById("close2-btn").setAttribute("default", true);
|
|
42 document.getElementById("close2-btn").focus();
|
|
43 }
|
|
44 }
|
|
45
|
|
46 tiny.shrink(loaded);
|
|
47 }
|
|
48 }
|
|
49
|
|
50 /**
|
|
51 * Cancel url shrinking
|
|
52 */
|
|
53 function tinyrl_create_cancel(){
|
|
54 try{
|
|
55 tiny.abort();
|
|
56 }catch(e){ }
|
|
57 self.close();
|
|
58 }
|
|
59
|
|
60 /**
|
|
61 * Open save dialog
|
|
62 */
|
|
63 function tinyurl_create_openSave(){
|
|
64 try{
|
|
65 if(tinyurl_saved_add(tiny.tiny, tiny.original, tiny.title) == true){
|
|
66 self.close();
|
|
67 }
|
|
68 }catch(e){
|
|
69 alert(e);
|
|
70 }
|
|
71 }
|
|
72
|
|
73 /**
|
|
74 * Goto the url
|
|
75 */
|
|
76 function tinyurl_create_goto(){
|
|
77 if(tiny.tiny == null){
|
|
78 alert("An error occurred");
|
|
79 }
|
|
80
|
|
81 if(opener){
|
|
82 opener.gBrowser.selectedTab = opener.gBrowser.addTab(tiny.tiny);
|
|
83 }
|
|
84 else{
|
|
85 window.open(tiny.tiny);
|
|
86 }
|
|
87
|
|
88 self.close();
|
|
89 } |