Skip to content

Commit 9aa1855

Browse files
committed
Stop hitting server on every pageload for bookmarks
1 parent b8e6086 commit 9aa1855

File tree

3 files changed

+4
-116
lines changed

3 files changed

+4
-116
lines changed

readthedocs/core/static-src/core/js/doc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,6 @@ Build.prototype.is_sphinx_builder = function () {
3131
Build.prototype.show_promo = function () {
3232
return (this.config['api_host'] != 'https://readthedocs.com'
3333
&& this.is_sphinx_builder()
34-
&& this.is_rtd_theme());
34+
&& this.is_rtd_theme()
35+
);
3536
};

readthedocs/core/static-src/core/js/readthedocs-doc-embed.js

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -101,63 +101,6 @@ $(document).ready(function () {
101101
}
102102
}
103103
});
104-
105-
// Bookmark Handling
106-
data = {
107-
project: READTHEDOCS_DATA['project'],
108-
version: READTHEDOCS_DATA['version'],
109-
page: READTHEDOCS_DATA['page'],
110-
url: document.location.origin + document.location.pathname
111-
};
112-
113-
// ask the server if a bookmark exists for this page so we can show the proper icon
114-
$.ajax({
115-
type: 'POST',
116-
url: API_HOST + "/bookmarks/exists/",
117-
crossDomain: true,
118-
xhrFields: {
119-
withCredentials: true,
120-
},
121-
data: JSON.stringify(data),
122-
success: function (data) {
123-
$(".bookmark-active").show();
124-
},
125-
error: function(data) {
126-
$(".bookmark-inactive").show();
127-
},
128-
dataType: 'json'
129-
});
130-
131-
$(".bookmark-icon").on('click', function (event) {
132-
var bookmarked = $('.bookmark-active').is(':visible');
133-
$('div.bookmark-active').toggle();
134-
$('div.bookmark-inactive').toggle();
135-
136-
if (bookmarked) {
137-
$.ajax({
138-
type: "POST",
139-
crossDomain: true,
140-
xhrFields: {
141-
withCredentials: true,
142-
},
143-
url: API_HOST + "/bookmarks/remove/",
144-
data: JSON.stringify(data),
145-
});
146-
//$(".bookmark-added-msg").hide();
147-
} else {
148-
$.ajax({
149-
type: "POST",
150-
crossDomain: true,
151-
xhrFields: {
152-
withCredentials: true,
153-
},
154-
url: API_HOST + "/bookmarks/add/",
155-
data: JSON.stringify(data),
156-
});
157-
//$(".bookmark-added-msg").html("<p><a href='/bookmarks'>Bookmark</a> added</p>");
158-
//$(".bookmark-added-msg").show();
159-
}
160-
});
161104
},
162105
error: function () {
163106
console.log('Error loading Read the Docs footer');

readthedocs/core/static/core/js/readthedocs-doc-embed.js

Lines changed: 2 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Build.prototype.is_sphinx_builder = function () {
3232
Build.prototype.show_promo = function () {
3333
return (this.config['api_host'] != 'https://readthedocs.com'
3434
&& this.is_sphinx_builder()
35-
&& this.is_rtd_theme());
35+
&& this.is_rtd_theme()
36+
);
3637
};
3738

3839
},{}],2:[function(require,module,exports){
@@ -139,63 +140,6 @@ $(document).ready(function () {
139140
}
140141
}
141142
});
142-
143-
// Bookmark Handling
144-
data = {
145-
project: READTHEDOCS_DATA['project'],
146-
version: READTHEDOCS_DATA['version'],
147-
page: READTHEDOCS_DATA['page'],
148-
url: document.location.origin + document.location.pathname
149-
};
150-
151-
// ask the server if a bookmark exists for this page so we can show the proper icon
152-
$.ajax({
153-
type: 'POST',
154-
url: API_HOST + "/bookmarks/exists/",
155-
crossDomain: true,
156-
xhrFields: {
157-
withCredentials: true,
158-
},
159-
data: JSON.stringify(data),
160-
success: function (data) {
161-
$(".bookmark-active").show();
162-
},
163-
error: function(data) {
164-
$(".bookmark-inactive").show();
165-
},
166-
dataType: 'json'
167-
});
168-
169-
$(".bookmark-icon").on('click', function (event) {
170-
var bookmarked = $('.bookmark-active').is(':visible');
171-
$('div.bookmark-active').toggle();
172-
$('div.bookmark-inactive').toggle();
173-
174-
if (bookmarked) {
175-
$.ajax({
176-
type: "POST",
177-
crossDomain: true,
178-
xhrFields: {
179-
withCredentials: true,
180-
},
181-
url: API_HOST + "/bookmarks/remove/",
182-
data: JSON.stringify(data),
183-
});
184-
//$(".bookmark-added-msg").hide();
185-
} else {
186-
$.ajax({
187-
type: "POST",
188-
crossDomain: true,
189-
xhrFields: {
190-
withCredentials: true,
191-
},
192-
url: API_HOST + "/bookmarks/add/",
193-
data: JSON.stringify(data),
194-
});
195-
//$(".bookmark-added-msg").html("<p><a href='/bookmarks'>Bookmark</a> added</p>");
196-
//$(".bookmark-added-msg").show();
197-
}
198-
});
199143
},
200144
error: function () {
201145
console.log('Error loading Read the Docs footer');

0 commit comments

Comments
 (0)