2013-10-07 00:44:17 +02:00
|
|
|
$(function()
|
|
|
|
{
|
2013-11-30 16:42:47 +01:00
|
|
|
$('.tabs a').click(function(e)
|
2013-10-25 09:40:33 +02:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
var className = $(this).parents('li').attr('class').replace('selected', '').replace(/^\s+|\s+$/, '');
|
2013-11-30 16:42:47 +01:00
|
|
|
$('.tabs li').removeClass('selected');
|
2013-10-25 09:40:33 +02:00
|
|
|
$(this).parents('li').addClass('selected');
|
2014-02-16 11:44:42 +01:00
|
|
|
$('.tab-content').hide();
|
|
|
|
$('.tab-content.' + className).show();
|
2013-10-25 09:40:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
$('#file-handler').on('dragenter', function(e)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
|
|
|
$(this).addClass('active');
|
2013-10-25 09:40:33 +02:00
|
|
|
}).on('dragleave', function(e)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
|
|
|
$(this).removeClass('active');
|
2013-10-25 09:40:33 +02:00
|
|
|
}).on('dragover', function(e)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
2013-10-25 09:40:33 +02:00
|
|
|
}).on('drop', function(e)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
handleFiles(e.originalEvent.dataTransfer.files);
|
|
|
|
$(this).trigger('dragleave');
|
2013-10-25 09:40:33 +02:00
|
|
|
}).on('click', function(e)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
|
|
|
$(':file').show().focus().trigger('click').hide();
|
|
|
|
});
|
|
|
|
|
|
|
|
$(':file').change(function(e)
|
|
|
|
{
|
|
|
|
handleFiles(this.files);
|
|
|
|
});
|
|
|
|
|
2013-10-25 09:40:33 +02:00
|
|
|
|
|
|
|
|
2014-02-16 15:08:54 +01:00
|
|
|
$('#url-handler-wrapper input').keydown(function(e)
|
2013-10-25 09:40:33 +02:00
|
|
|
{
|
2014-02-16 15:08:54 +01:00
|
|
|
if (e.which == 13)
|
2013-10-25 14:55:18 +02:00
|
|
|
{
|
2014-02-16 15:08:54 +01:00
|
|
|
$('#url-handler-wrapper button').trigger('click');
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$('#url-handler-wrapper button').click(function(e)
|
|
|
|
{
|
|
|
|
var url = $('#url-handler-wrapper input').val();
|
|
|
|
url = url.replace(/^\s+|\s+$/, '');
|
|
|
|
if (url == '')
|
|
|
|
return;
|
|
|
|
$('#url-handler-wrapper input').val('');
|
|
|
|
handleURLs([url]);
|
2013-10-25 09:40:33 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-19 16:16:09 +02:00
|
|
|
$('.post .move-down-trigger, .post .move-up-trigger').on('click', function()
|
|
|
|
{
|
2013-11-23 09:51:57 +01:00
|
|
|
if ($('#the-submit').hasClass('inactive'))
|
|
|
|
return;
|
2013-10-19 16:16:09 +02:00
|
|
|
var dir = $(this).hasClass('move-down-trigger') ? 'd' : 'u';
|
|
|
|
var post = $(this).parents('.post');
|
|
|
|
if (dir == 'u')
|
|
|
|
post.insertBefore(post.prev('.post'));
|
|
|
|
else
|
|
|
|
post.insertAfter(post.next('.post'));
|
|
|
|
});
|
2013-10-07 00:44:17 +02:00
|
|
|
$('.post .remove-trigger').on('click', function()
|
|
|
|
{
|
2013-11-23 09:51:57 +01:00
|
|
|
if ($('#the-submit').hasClass('inactive'))
|
|
|
|
return;
|
2013-10-07 00:44:17 +02:00
|
|
|
$(this).parents('.post').slideUp(function()
|
|
|
|
{
|
|
|
|
$(this).remove();
|
2013-10-25 14:55:18 +02:00
|
|
|
handleInputs([]);
|
2013-10-07 00:44:17 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-10-25 09:40:33 +02:00
|
|
|
|
2013-10-19 16:00:47 +02:00
|
|
|
function sendNextPost()
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
2013-10-09 00:58:49 +02:00
|
|
|
var posts = $('#upload-step2 .post');
|
2013-10-07 00:44:17 +02:00
|
|
|
if (posts.length == 0)
|
|
|
|
{
|
2013-10-19 16:00:47 +02:00
|
|
|
uploadFinished();
|
2013-10-07 00:44:17 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-10-19 16:00:47 +02:00
|
|
|
var postDom = posts.first();
|
|
|
|
var url = postDom.find('form').attr('action') + '?json';
|
2013-10-30 16:51:22 +01:00
|
|
|
var fd = new FormData(postDom.find('form').get(0));
|
|
|
|
|
|
|
|
fd.append('file', postDom.data('file'));
|
|
|
|
fd.append('url', postDom.data('url'));
|
|
|
|
|
2013-10-19 16:00:47 +02:00
|
|
|
|
|
|
|
var ajaxData =
|
2013-10-09 00:58:49 +02:00
|
|
|
{
|
2013-10-19 16:00:47 +02:00
|
|
|
url: url,
|
|
|
|
data: fd,
|
|
|
|
processData: false,
|
|
|
|
contentType: false,
|
|
|
|
dataType: 'json',
|
|
|
|
type: 'POST',
|
|
|
|
success: function(data)
|
2013-10-09 00:58:49 +02:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
postDom.slideUp(function()
|
2013-10-09 00:58:49 +02:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
postDom.remove();
|
|
|
|
sendNextPost();
|
|
|
|
});
|
2013-11-23 09:51:57 +01:00
|
|
|
},
|
2014-05-01 22:29:36 +02:00
|
|
|
error: function(xhr)
|
2013-11-23 09:51:57 +01:00
|
|
|
{
|
2014-05-01 22:29:36 +02:00
|
|
|
postDom
|
|
|
|
.find('.alert')
|
|
|
|
.html(xhr.responseJSON
|
|
|
|
? xhr.responseJSON.messageHtml
|
|
|
|
: 'Fatal error')
|
|
|
|
.slideDown();
|
2013-11-23 09:51:57 +01:00
|
|
|
enableUpload();
|
2013-10-09 00:58:49 +02:00
|
|
|
}
|
2013-10-19 16:00:47 +02:00
|
|
|
};
|
2013-10-07 00:44:17 +02:00
|
|
|
|
2013-10-19 16:00:47 +02:00
|
|
|
$.ajax(ajaxData);
|
|
|
|
}
|
|
|
|
|
|
|
|
function uploadFinished()
|
|
|
|
{
|
2014-02-01 10:10:09 +01:00
|
|
|
disableExitConfirmation();
|
2013-10-19 16:00:47 +02:00
|
|
|
window.location.href = $('#upload-step2').attr('data-redirect-url');
|
|
|
|
}
|
|
|
|
|
|
|
|
function disableUpload()
|
|
|
|
{
|
|
|
|
var theSubmit = $('#the-submit');
|
|
|
|
theSubmit.addClass('inactive');
|
|
|
|
var posts = $('#upload-step2 .post');
|
|
|
|
posts.find(':input').attr('readonly', true);
|
|
|
|
posts.addClass('inactive');
|
|
|
|
}
|
|
|
|
|
|
|
|
function enableUpload()
|
|
|
|
{
|
|
|
|
var theSubmit = $('#the-submit');
|
|
|
|
theSubmit.removeClass('inactive');
|
|
|
|
var posts = $('#upload-step2 .post');
|
|
|
|
posts.removeClass('inactive');
|
|
|
|
posts.find(':input').attr('readonly', false);
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#the-submit').click(function(e)
|
|
|
|
{
|
|
|
|
e.preventDefault();
|
|
|
|
var theSubmit = $(this);
|
2013-11-23 09:51:57 +01:00
|
|
|
if (theSubmit.hasClass('inactive'))
|
|
|
|
return;
|
2013-10-19 16:00:47 +02:00
|
|
|
disableUpload();
|
|
|
|
sendNextPost();
|
2013-10-07 00:44:17 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
function handleFiles(files)
|
2013-10-25 09:40:33 +02:00
|
|
|
{
|
|
|
|
handleInputs(files, function(postDom, file)
|
|
|
|
{
|
2014-05-03 14:20:48 +02:00
|
|
|
postDom.data('url', '');
|
2013-10-25 09:40:33 +02:00
|
|
|
postDom.data('file', file);
|
|
|
|
$('.file-name strong', postDom).text(file.name);
|
|
|
|
|
|
|
|
if (file.type.match('image.*'))
|
|
|
|
{
|
|
|
|
var img = postDom.find('img')
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = (function(theFile, img)
|
|
|
|
{
|
|
|
|
return function(e)
|
|
|
|
{
|
2014-02-20 21:26:46 +01:00
|
|
|
changeThumb(img, e.target.result);
|
2013-10-25 09:40:33 +02:00
|
|
|
};
|
|
|
|
})(file, img);
|
|
|
|
reader.readAsDataURL(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2014-02-20 21:26:46 +01:00
|
|
|
function changeThumb(img, url)
|
|
|
|
{
|
|
|
|
$(img)
|
|
|
|
.css('background-image', 'none')
|
|
|
|
.attr('src', url)
|
|
|
|
.data('custom-thumb', true);
|
|
|
|
}
|
|
|
|
|
2013-10-25 09:40:33 +02:00
|
|
|
function handleURLs(urls)
|
|
|
|
{
|
|
|
|
handleInputs(urls, function(postDom, url)
|
|
|
|
{
|
|
|
|
postDom.data('url', url);
|
2014-05-03 14:20:48 +02:00
|
|
|
postDom.data('file', '');
|
2013-10-25 13:18:03 +02:00
|
|
|
postDom.find('[name=source]').val(url);
|
|
|
|
if (matches = url.match(/watch.*?=([a-zA-Z0-9_-]+)/))
|
|
|
|
{
|
|
|
|
postDom.find('.file-name strong').text(url);
|
|
|
|
$.getJSON('http://gdata.youtube.com/feeds/api/videos/' + matches[1] + '?v=2&alt=jsonc', function(data)
|
|
|
|
{
|
|
|
|
postDom.find('.file-name strong')
|
|
|
|
.text(data.data.title);
|
2014-02-20 21:26:46 +01:00
|
|
|
changeThumb(postDom.find('img'), data.data.thumbnail.hqDefault);
|
2013-10-25 13:18:03 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-20 21:26:46 +01:00
|
|
|
postDom.find('.file-name strong').text(url);
|
|
|
|
changeThumb(postDom.find('img'), url);
|
2013-10-25 13:18:03 +02:00
|
|
|
}
|
2013-10-25 09:40:33 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleInputs(inputs, callback)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
2013-10-25 09:56:55 +02:00
|
|
|
for (var i = 0; i < inputs.length; i ++)
|
2013-10-07 00:44:17 +02:00
|
|
|
{
|
2013-10-25 09:56:55 +02:00
|
|
|
var input = inputs[i];
|
|
|
|
var postDom = $('#post-template').clone(true);
|
|
|
|
postDom.find('form').submit(false);
|
|
|
|
postDom.removeAttr('id');
|
2013-10-25 09:40:33 +02:00
|
|
|
|
2013-10-25 09:56:55 +02:00
|
|
|
$('.posts').append(postDom);
|
2013-10-07 00:44:17 +02:00
|
|
|
|
2013-10-25 09:56:55 +02:00
|
|
|
postDom.show();
|
2014-02-18 21:15:00 +01:00
|
|
|
attachTagIt($('.tags input', postDom));
|
2013-10-09 17:50:07 +02:00
|
|
|
|
2013-10-25 09:56:55 +02:00
|
|
|
callback(postDom, input);
|
|
|
|
}
|
2013-10-25 14:55:18 +02:00
|
|
|
if ($('.posts .post').length == 0)
|
2014-02-20 21:30:30 +01:00
|
|
|
{
|
|
|
|
disableExitConfirmation();
|
2013-10-25 14:55:18 +02:00
|
|
|
$('#upload-step2').fadeOut();
|
2014-02-20 21:30:30 +01:00
|
|
|
}
|
2013-10-25 14:55:18 +02:00
|
|
|
else
|
2014-02-20 21:30:30 +01:00
|
|
|
{
|
|
|
|
enableExitConfirmation();
|
2013-10-25 14:55:18 +02:00
|
|
|
$('#upload-step2').fadeIn();
|
2014-02-20 21:30:30 +01:00
|
|
|
}
|
2013-10-07 00:44:17 +02:00
|
|
|
}
|
2014-02-20 21:26:46 +01:00
|
|
|
|
|
|
|
$('.post img').mouseenter(function(e)
|
|
|
|
{
|
|
|
|
if ($(this).data('custom-thumb') != true)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$('#lightbox')
|
|
|
|
.attr('src', $(this).attr('src'))
|
|
|
|
.show()
|
|
|
|
.position({
|
|
|
|
of: $(this),
|
|
|
|
my: 'center center',
|
|
|
|
at: 'center center',
|
|
|
|
})
|
|
|
|
.show();
|
|
|
|
});
|
|
|
|
$('.post img').mouseleave(function(e)
|
|
|
|
{
|
|
|
|
$('#lightbox').hide();
|
|
|
|
});
|
2013-10-07 00:44:17 +02:00
|
|
|
});
|