|
1 |
|
2 //Bookmark add dialog |
|
3 |
|
4 function addBookmarkDialog() |
|
5 { |
|
6 this.write = writeAddBookmarkDialog; |
|
7 |
|
8 // do setup |
|
9 this.write(); |
|
10 } |
|
11 |
|
12 // "Private" methods |
|
13 function writeAddBookmarkDialog() |
|
14 { |
|
15 var html = |
|
16 '<div id="BookmarkDialogOverlay"></div>'+ |
|
17 '<div id="BookmarkDialogContainer">'+ |
|
18 '<form name = "bookmarkAddDialog" id="bookmarkAddForm" class="bookmarkAddFormPortriat">'+ |
|
19 '<table cellpadding="3" cellspacing="3" class="dialogBox"> '+ |
|
20 ' <tr><td colspan="2"> '+ |
|
21 ' <input name = "TitleTextBox" type ="text" class="textInputUI" id = "titleTextBoxId" OnFocus="selectElementOnFocus(this);" onblur="titleFieldLostFocus();" maxlength="256" />'+ |
|
22 '</td></tr>'+ |
|
23 '<tr><td colspan="2"> '+ |
|
24 ' <input name = "UrlTextBox" type ="text" id = "urlTextBoxId" OnFocus="selectElementOnFocus(this);" onblur="urlFieldLostFocus();" class="textInputUI" maxlength="256" /> '+ |
|
25 '</td></tr>'+ |
|
26 '<tr>'+ |
|
27 '<td> '+ |
|
28 '<input name="Ok" type="button" value="Done" class="doneButton" onmouseup="addBookmark();"/> '+ |
|
29 '</td>'+ |
|
30 '<td>'+ |
|
31 '<input name="Cancel" type="button" value="Cancel" class="cancelButton" onmouseup="bookmarkDialogIdHide();"/>'+ |
|
32 '</td> '+ |
|
33 '</tr> '+ |
|
34 '</table>'+ |
|
35 '</form>'+ |
|
36 '</div>'; |
|
37 document.write(html); |
|
38 } |
|
39 |
|
40 |
|
41 function bookmarkDialogIdHide(){ |
|
42 document.getElementById("BookmarkDialogOverlay").style.display = 'none'; |
|
43 document.getElementById("BookmarkDialogContainer").style.display = 'none'; |
|
44 document.getElementById("bookmarkAddForm").style.display = 'none'; |
|
45 window.snippets.BookmarkDialogId.hide(); |
|
46 } |
|
47 |
|
48 |
|
49 function launchBookmarkAddDialog() |
|
50 { |
|
51 try{ |
|
52 var bmtitle = document.bookmarkAddDialog.TitleTextBox.value = window.pageController.currentDocTitle; |
|
53 var bmurl = document.bookmarkAddDialog.UrlTextBox.value = window.pageController.currentDocUrl; |
|
54 |
|
55 if(bmtitle == "") |
|
56 document.bookmarkAddDialog.TitleTextBox.value = "Title"; |
|
57 |
|
58 if(bmurl == "") |
|
59 document.bookmarkAddDialog.UrlTextBox.value = "Url"; |
|
60 |
|
61 window.chrome.aspectChanged.connect(_updateBookmarkDialogGoemetry); |
|
62 |
|
63 document.getElementById("BookmarkDialogOverlay").style.display = 'block'; |
|
64 document.getElementById("BookmarkDialogContainer").style.display = 'block'; |
|
65 document.getElementById("bookmarkAddForm").style.display = 'block'; |
|
66 |
|
67 var dialog = document.getElementById("bookmarkAddForm");; |
|
68 |
|
69 if (window.chrome.displayMode == "portrait") |
|
70 dialog.className = "bookmarkAddFormPortriat" |
|
71 else //landscape |
|
72 dialog.className = "bookmarkAddFormLandScape" |
|
73 |
|
74 window.snippets.BookmarkDialogId.repaint(); |
|
75 window.snippets.BookmarkDialogId.show(false); |
|
76 window.snippets.BookmarkDialogId.zValue = 15; |
|
77 }catch(e){ alert(e); } |
|
78 |
|
79 } |
|
80 |
|
81 function addBookmark () |
|
82 { |
|
83 //get title and url from the dailog |
|
84 var bmtitle = document.bookmarkAddDialog.TitleTextBox.value; |
|
85 var bmurl= document.bookmarkAddDialog.UrlTextBox.value; |
|
86 |
|
87 |
|
88 //hide bookmraks dialog |
|
89 document.getElementById("BookmarkDialogOverlay").style.display = 'none'; |
|
90 document.getElementById("BookmarkDialogContainer").style.display = 'none'; |
|
91 document.getElementById("bookmarkAddForm").style.display = 'none'; |
|
92 window.snippets.BookmarkDialogId.hide(); |
|
93 |
|
94 //add a bookmark to the bookmark database |
|
95 var errCode = window.bookmarksManager.addBookmark(bmurl,bmtitle); |
|
96 if(errCode == -2) { |
|
97 alert("Bookmark Already Present"); |
|
98 return; |
|
99 } |
|
100 else if(errCode == -3){ |
|
101 alert("Bookmark Url Is Empty"); |
|
102 return; |
|
103 } |
|
104 else if(errCode != -0){ |
|
105 alert("General Error"); |
|
106 return; |
|
107 } |
|
108 |
|
109 try { |
|
110 window.views.WebView.reload(); |
|
111 } catch(E) { alert(E); } |
|
112 |
|
113 } |
|
114 |
|
115 function selectElementOnFocus(el) |
|
116 { |
|
117 el.scrollRight = el.length+1; |
|
118 el.select(); |
|
119 } |
|
120 |
|
121 function titleFieldLostFocus() |
|
122 { |
|
123 var bmtitle = document.bookmarkAddDialog.TitleTextBox.value; |
|
124 if(bmtitle == "") |
|
125 document.bookmarkAddDialog.TitleTextBox.value = "Title"; |
|
126 } |
|
127 |
|
128 function urlFieldLostFocus() |
|
129 { |
|
130 var bmurl= document.bookmarkAddDialog.UrlTextBox.value; |
|
131 if(bmurl == "") |
|
132 document.bookmarkAddDialog.UrlTextBox.value = "Url"; |
|
133 } |
|
134 |
|
135 function _updateBookmarkDialogGoemetry(displayMode) |
|
136 { |
|
137 var dialog = document.getElementById("bookmarkAddForm");; |
|
138 |
|
139 if (window.chrome.displayMode == "portrait") |
|
140 dialog.className = "bookmarkAddFormPortriat" |
|
141 else //landscape |
|
142 dialog.className = "bookmarkAddFormLandScape" |
|
143 } |