mirror of
https://github.com/Luzifer/share.git
synced 2024-12-29 23:11:18 +00:00
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
// Generated by CoffeeScript 1.12.4
|
|
(function() {
|
|
var MSG_GENERIC_ERR, MSG_NOT_FOUND, MSG_NOT_PERMITTED, embedFileInfo, fileURL, handleEmbed, handleError, handleErrorMessage, hashLoad;
|
|
|
|
fileURL = void 0;
|
|
|
|
MSG_NOT_FOUND = 'File not found';
|
|
|
|
MSG_NOT_PERMITTED = 'Not allowed to access file';
|
|
|
|
MSG_GENERIC_ERR = 'Something went wrong';
|
|
|
|
$(function() {
|
|
$(window).bind('hashchange', hashLoad);
|
|
return hashLoad();
|
|
});
|
|
|
|
hashLoad = function() {
|
|
var file;
|
|
file = window.location.hash.substring(1);
|
|
return embedFileInfo(file);
|
|
};
|
|
|
|
embedFileInfo = function(file) {
|
|
if (file === '') {
|
|
return handleErrorMessage(MSG_NOT_FOUND);
|
|
}
|
|
fileURL = file;
|
|
return $.ajax(file, {
|
|
method: 'HEAD',
|
|
success: handleEmbed,
|
|
error: handleError
|
|
});
|
|
};
|
|
|
|
handleEmbed = function(data, status, xhr) {
|
|
var type;
|
|
type = xhr.getResponseHeader('Content-Type');
|
|
console.log(fileURL);
|
|
$('.show-loading').hide();
|
|
$('.filelink-href').attr('href', fileURL);
|
|
$('.filelink-src').attr('src', fileURL);
|
|
$('.filename').text(fileURL.substring(fileURL.lastIndexOf('/') + 1));
|
|
if (type.match(/^image\//)) {
|
|
$('.show-image').show();
|
|
return;
|
|
}
|
|
if (type.match(/^video\//)) {
|
|
$('.show-video').show();
|
|
return;
|
|
}
|
|
return $('.show-generic').show();
|
|
};
|
|
|
|
handleError = function(xhr, status) {
|
|
var message;
|
|
message = (function() {
|
|
switch (xhr.status) {
|
|
case 404:
|
|
return MSG_NOT_FOUND;
|
|
case 403:
|
|
return MSG_NOT_PERMITTED;
|
|
default:
|
|
return MSG_GENERIC_ERR;
|
|
}
|
|
})();
|
|
return handleErrorMessage(message);
|
|
};
|
|
|
|
handleErrorMessage = function(message) {
|
|
$('.error').text(message);
|
|
$('.show-loading').hide();
|
|
return $('.show-error').show();
|
|
};
|
|
|
|
}).call(this);
|