-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoolbar.html
164 lines (164 loc) · 4.74 KB
/
toolbar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
<!DOCTYPE html>
<html>
<head>
<style>
body {
overflow: hidden;
}
#selector {
float: left;
margin-left: 5px;
margin-right: 6px;
}
#selector #menu {
-webkit-appearance: none;
background: inherit;
border: inherit;
border-radius: inherit;
width: 16px;
height: 16px;
padding-left: 16px;
background: url(sort.png) no-repeat;
outline: none;
}
#selector #tag-selected {
vertical-align: bottom;
margin-right: -6px;
}
#selector #selected {
line-height: 16px;
vertical-align: bottom;
font-size: xx-small;
}
.hidden {
display: none !important;
}
a.bookmark {
display: block;
float: left;
color: rgba(0, 0, 0, 0.796875);
margin-top: -1px;
text-decoration: none;
padding-top: 2px;
padding-bottom: 2px;
padding-left: 7px;
padding-right: 7px;
cursor: default;
}
a.bookmark:hover {
color: white;
background-color: rgba(0, 0, 0, 0.2);
-webkit-border-radius: 10px;
text-shadow: rgba(0, 0, 0, 0.398438) 0px 1px 0px;
}
</style>
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript">
function redrawWindow() {
$('.bookmark').removeClass('to-be-hidden')
$('.bookmark').removeClass('hidden');
$('.bookmark').each(function() {
if ($(this).offset().top > 10) {
$(this).addClass('to-be-hidden');
}
});
$('.to-be-hidden').addClass('hidden').removeClass('to-be-hidden');
};
function reloadBookmarks(username, bookmarks) {
var output = '';
for (var i = 0; i < bookmarks.length; i++) {
var bookmark = bookmarks[i];
var label = bookmark.name;
if (label.length > 27) {
var firstPart = label.substr(0, 12);
var secondPart = label.substr(label.length - 12, 12);
label = firstPart + "…" + secondPart;
}
output += '<a class="bookmark" title="' + bookmark.url + '" href="' + bookmark.url + '">' + label + '</a>';
}
$('#bookmarks').html(output);
redrawWindow();
};
function reloadMenu(username, tags, currentTag) {
var menu = $('#menu');
menu.empty();
if (username) {
menu.append('<option value="home">My Delicious</option>');
menu.append('<hr />');
menu.append('<option id="all" value="all">All Bookmarks</option>');
menu.append('<optgroup id="tags" label="All Bookmarks with Tag"></optgroup>');
var tagContainer = menu.find('#tags');
tagContainer.empty();
for (var i = 0; i < tags.length; i++) {
var tag = tags[i];
var toAppend = '<option ';
if (currentTag && tag.tag == currentTag) {
toAppend += 'selected="selected" ';
}
toAppend += 'value="tag:' + tag.tag + '">' + tag.tag + ' (' + tag.count + ')</option>';
tagContainer.append(toAppend);
}
menu.append('<hr />');
if (currentTag) {
$('#selected').html(currentTag);
$('#tag-selected').removeClass('hidden');
$('#selected').removeClass('hidden');
} else {
$('#menu')[0].selectedIndex = 1;
$('#tag-selected').addClass('hidden');
$('#selected').addClass('hidden');
}
$('#selector').removeClass('hidden');
$('#menu').removeAttr('disabled');
} else {
$('#selector').addClass('hidden');
$('#menu').attr('disabled', 'disabled');
}
menu.append('<option value="refresh">Refresh</option>');
};
function refresh(delicious) {
var username = delicious.username;
var bookmarks = delicious.bookmarks;
var currentTag = delicious.currentTag || '';
var tags = delicious.tags;
reloadMenu(username, tags, currentTag);
reloadBookmarks(username, bookmarks);
};
$(function() {
$(window).resize(redrawWindow);
$('#menu').change(function(event) {
if (!event.target.previousIndex) {
event.target.previousIndex = event.target.selectedIndex;
}
var option = event.target.options[event.target.selectedIndex];
if (option.value.substr(0, 4) == 'tag:') {
var tag = option.value.substr(4);
safari.extension.globalPage.contentWindow.Delicious.reloadBookmarksWithTag(tag);
} else if (option.value == 'all') {
safari.extension.globalPage.contentWindow.Delicious.reloadBookmarks();
} else if (option.value == 'refresh') {
refresh(safari.extension.globalPage.contentWindow.Delicious);
event.target.selectedIndex = event.target.previousIndex;
} else if (option.value == 'home') {
var tab = safari.application.activeBrowserWindow.openTab();
tab.url = 'http://delicious.com/home';
event.target.selectedIndex = event.target.previousIndex;
}
event.target.previousIndex = event.target.selectedIndex;
});
refresh(safari.extension.globalPage.contentWindow.Delicious);
});
</script>
<title>Toolbar</title>
</head>
<body>
<div id="selector" class="hidden">
<select name="menu" id="menu" disabled="disabled">
</select>
<img id="tag-selected" src="tag-small.png" class="hidden" />
<span id="selected" class="hidden"></span>
</div>
<div id="bookmarks">
</div>
</body>
</html>