Skip to content

Commit 5c95d5c

Browse files
committed
Sync with upstream repository
1 parent af1c72a commit 5c95d5c

4 files changed

Lines changed: 212 additions & 209 deletions

File tree

assets/javascripts/documentation.js

Lines changed: 0 additions & 209 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,6 @@ $(function() {
7474
return false
7575
})
7676

77-
$('.help-search .search-box').focus(function(){
78-
$(this).css('background-position','0px -25px')
79-
})
80-
81-
$('.help-search .search-box').focusout(function(){
82-
if($(this).val() == ''){
83-
$(this).css('background-position','0px 0px')
84-
}
85-
})
86-
8777
// Grab API status
8878
$.getJSON('https://status.github.com/api/status.json?callback=?', function(data) {
8979
if(data) {
@@ -96,210 +86,11 @@ $(function() {
9686
}
9787
});
9888

99-
// #### Search ####
100-
var searchIndex,
101-
searchHits;
102-
103-
// Load the JSON containing all pages
104-
// Has it been loaded before (and stored with localstorage)?
105-
if (localStorage['searchIndex']) {
106-
searchIndex = JSON.parse(localStorage['searchIndex']);
107-
108-
if (localStorageHasExpired())
109-
loadSearchIndex();
110-
} else {
111-
loadSearchIndex();
112-
}
113-
114-
function loadSearchIndex() {
115-
$.getJSON('/assets/search-index.json', function(data) {
116-
searchIndex = data["pages"];
117-
localStorage['searchIndex'] = JSON.stringify(searchIndex);
118-
localStorage['updated'] = new Date().getTime();
119-
});
120-
}
121-
122-
function localStorageHasExpired() {
123-
// Expires in one day (86400000 ms)
124-
if (new Date().getTime() - parseInt(localStorage['updated'],10) > 86400000) {
125-
return true;
126-
}
127-
128-
return false;
129-
}
130-
131-
// Expand and activate search if the page loaded with a value set for the search field
132-
if ($("#searchfield").val().length > 0) {
133-
$("#search-container").addClass("active");
134-
searchForString($("#searchfield").val());
135-
}
136-
137-
// On input change, update the search results
138-
$("#searchfield").on("input", function(e) {
139-
$(this).val().length > 0 ? $("#search-container").addClass("active") : $("#search-container").removeClass("active");
140-
141-
searchForString($(this).val());
142-
});
143-
144-
// Global keyboard shortcuts
145-
$("body").keyup(function(e) {
146-
if (e.keyCode == 83) {
147-
// S key
148-
if ($("#searchfield").is(":focus"))
149-
return;
150-
151-
e.preventDefault();
152-
$("#searchfield").focus();
153-
}
154-
});
155-
156-
// Keyboard support for the search field
157-
$("#searchfield").keyup(function(e) {
158-
if (e.keyCode == 27) {
159-
// ESC
160-
e.preventDefault();
161-
$("#searchfield").val().length > 0 ? cancelSearch() : $("#searchfield").blur();
162-
} else if (e.keyCode == 13) {
163-
// Return/enter
164-
e.preventDefault();
165-
goToSelectedSearchResult();
166-
} else if (e.keyCode == 8 || e.keyCode == 46) {
167-
// Update search if backspace/delete was pressed
168-
// IE9 doesn't trigger the input event on backspace/delete,
169-
// but they do trigger keyUp
170-
$(this).val().length > 0 ? $("#search-container").addClass("active") : $("#search-container").removeClass("active");
171-
172-
searchForString($(this).val());
173-
}
174-
}).keydown(function(e) {
175-
if (e.keyCode == 38) {
176-
// Arrow up
177-
e.preventDefault();
178-
moveSearchSelectionUp();
179-
} else if (e.keyCode == 40) {
180-
// Arrow down
181-
e.preventDefault();
182-
moveSearchSelectionDown();
183-
} else if (e.keyCode == 27) {
184-
// Prevent default on ESC key
185-
// IE inputs come with some native behaviors that will
186-
// prevent the DOM from updating correctly unless prevented
187-
e.preventDefault();
188-
}
189-
});
190-
191-
// Make clicking the label focus the input label
192-
// for browsers (IE) that doesn't support pointer-events: none
193-
$("#search-container .search-placeholder").click(function(e) {
194-
$("#searchfield").focus();
195-
});
196-
197-
$(".cancel-search").click(function(e) {
198-
cancelSearch();
199-
});
200-
201-
function cancelSearch() {
202-
$("#searchfield").val("");
203-
$("#search-container").removeClass("active");
204-
}
205-
206-
function searchForString(searchString) {
207-
searchHits = [];
208-
searchString = searchString.toLowerCase();
209-
210-
// Search for string in all pages
211-
for (var i = 0; i < searchIndex.length; i++) {
212-
var page = searchIndex[i];
213-
214-
// Add the page to the array of hits if there's a match
215-
if (page.title.toLowerCase().indexOf(searchString) !== -1) {
216-
searchHits.push(page);
217-
}
218-
}
219-
220-
renderResultsForSearch(searchString);
221-
}
222-
223-
// Update the UI representation of the search hits
224-
function renderResultsForSearch(searchString){
225-
$("#search-results").empty();
226-
227-
// Check if there are any results. If not, show placeholder and exit
228-
if (searchHits.length < 1) {
229-
$('<li class="placeholder">No results for <em></em></li>').appendTo("#search-results").find("em").text(searchString);
230-
return;
231-
}
232-
233-
// Render results (max 8)
234-
for (var i = 0; i < Math.min(searchHits.length, 8); i++) {
235-
var page = searchHits[i];
236-
237-
$('<li class="result"><a href="' + page.url + '"><em>' + page.title + '</em><small>' + page.section + '</small></a></li>').appendTo("#search-results");
238-
}
239-
240-
// Select the first alternative
241-
$("#search-results li:first-child").addClass("selected");
242-
}
243-
244-
// Move the selected list item when hovering
245-
$("#search-results").on("mouseenter", "li", function(e) {
246-
$(this).parent().find(".selected").removeClass("selected").end().end()
247-
.addClass("selected");
248-
});
249-
250-
function moveSearchSelectionUp() {
251-
$prev = $("#search-results .selected").prev();
252-
if ($prev.length < 1)
253-
return;
254-
255-
$("#search-results .selected").removeClass("selected");
256-
$prev.addClass("selected");
257-
}
258-
259-
function moveSearchSelectionDown() {
260-
$next = $("#search-results .selected").next();
261-
if ($next.length < 1)
262-
return;
263-
264-
$("#search-results .selected").removeClass("selected");
265-
$next.addClass("selected");
266-
}
267-
268-
function goToSelectedSearchResult() {
269-
var href = $("#search-results .selected a").attr("href");
270-
if (href)
271-
window.location.href = href;
272-
}
273-
27489
// Earth animation
27590
if ($('.dev-program').length) {
27691
setTimeout(function() {
27792
$('.earth').fadeOut();
27893
$('.earth-short-loop').show();
27994
}, 19 * 1000); // Let first loop run through 19 seconds
28095
}
281-
282-
// copy Help's image show/hide functionality in OLs
283-
var dismissFullImage;
284-
285-
$('ol img').each(function(index, elem) {
286-
return $(elem).parent().prepend(elem);
287-
});
288-
289-
$(document).on('click', 'ol img', function(event) {
290-
var $fullImg, $img;
291-
dismissFullImage();
292-
$img = $(event.currentTarget).clone();
293-
$fullImg = $('<div class="js-full-image full-image"><span class="octicon octicon-remove-close"></span></div>').prepend($img);
294-
$(this).closest('li').append($fullImg);
295-
return $(document).on('click', '.js-full-image', function() {
296-
dismissFullImage();
297-
return false;
298-
});
299-
});
300-
301-
dismissFullImage = function() {
302-
$(document).off('click', '.js-full-image', dismissFullImage);
303-
return $('.js-full-image').remove();
304-
};
30596
});

assets/javascripts/images.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
$(function() {
2+
// copy Help's image show/hide functionality in OLs
3+
var dismissFullImage;
4+
5+
$('ol img').each(function(index, elem) {
6+
return $(elem).parent().prepend(elem);
7+
});
8+
9+
$(document).on('click', 'ol img', function(event) {
10+
var $fullImg, $img;
11+
dismissFullImage();
12+
$img = $(event.currentTarget).clone();
13+
$fullImg = $('<div class="js-full-image full-image"><span class="octicon octicon-remove-close"></span></div>').prepend($img);
14+
$(this).closest('li').append($fullImg);
15+
return $(document).on('click', '.js-full-image', function() {
16+
dismissFullImage();
17+
return false;
18+
});
19+
});
20+
21+
dismissFullImage = function() {
22+
$(document).off('click', '.js-full-image', dismissFullImage);
23+
return $('.js-full-image').remove();
24+
};
25+
});

0 commit comments

Comments
 (0)