This commit is contained in:
Marcin Kurczewski 2014-02-01 10:10:09 +01:00
parent ac1997d4d0
commit d170e3b526
6 changed files with 36 additions and 2 deletions

View file

@ -2,6 +2,12 @@ $(function()
{ {
function onDomUpdate() function onDomUpdate()
{ {
$('form.edit-comment textarea, form.add-comment textarea')
.bind('change keyup', function(e)
{
enableExitConfirmation();
});
$('form.edit-comment, form.add-comment').submit(function(e) $('form.edit-comment, form.add-comment').submit(function(e)
{ {
e.preventDefault(); e.preventDefault();
@ -41,6 +47,8 @@ $(function()
} }
else else
{ {
disableExitConfirmation();
formDom.find('.preview').hide(); formDom.find('.preview').hide();
var cb = function() var cb = function()
{ {

View file

@ -272,3 +272,18 @@ $(function()
Mousetrap.bind('d', function() { var url = $('.paginator:visible .next:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup'); Mousetrap.bind('d', function() { var url = $('.paginator:visible .next:not(.disabled) a').attr('href'); if (typeof url !== 'undefined') window.location.href = url; }, 'keyup');
Mousetrap.bind('p', function() { $('.post a').eq(0).focus(); return false; }, 'keyup'); Mousetrap.bind('p', function() { $('.post a').eq(0).focus(); return false; }, 'keyup');
}); });
function enableExitConfirmation()
{
$(window).bind('beforeunload', function(e)
{
return true;
});
}
function disableExitConfirmation()
{
$(window).unbind('beforeunload');
}

View file

@ -136,6 +136,7 @@ $(function()
function uploadFinished() function uploadFinished()
{ {
disableExitConfirmation();
window.location.href = $('#upload-step2').attr('data-redirect-url'); window.location.href = $('#upload-step2').attr('data-redirect-url');
} }
@ -224,6 +225,7 @@ $(function()
{ {
for (var i = 0; i < inputs.length; i ++) for (var i = 0; i < inputs.length; i ++)
{ {
enableExitConfirmation();
var input = inputs[i]; var input = inputs[i];
var postDom = $('#post-template').clone(true); var postDom = $('#post-template').clone(true);
postDom.find('form').submit(false); postDom.find('form').submit(false);

View file

@ -12,6 +12,7 @@ $(function()
aDom.addClass('inactive'); aDom.addClass('inactive');
var formDom = $('form.edit-post'); var formDom = $('form.edit-post');
formDom.data('original-data', formDom.serialize());
if (formDom.find('.tagit').length == 0) if (formDom.find('.tagit').length == 0)
{ {
$.getJSON('/tags?json', {filter: 'order:popularity,desc'}, function(data) $.getJSON('/tags?json', {filter: 'order:popularity,desc'}, function(data)
@ -23,7 +24,13 @@ $(function()
tagItOptions.availableTags = tags; tagItOptions.availableTags = tags;
tagItOptions.placeholderText = $('.tags input').attr('placeholder'); tagItOptions.placeholderText = $('.tags input').attr('placeholder');
$('.tags input').tagit(tagItOptions); $('.tags input').tagit(tagItOptions);
formDom.find('input[type=text]:visible:eq(0)').focus(); formDom.find('input[type=text]:visible:eq(0)').focus();
formDom.find('textarea, input').bind('change keyup', function()
{
if (formDom.serialize() != formDom.data('original-data'))
enableExitConfirmation();
});
}); });
} }
else else
@ -89,6 +96,8 @@ $(function()
{ {
if (data['success']) if (data['success'])
{ {
disableExitConfirmation();
$.get(window.location.href, function(data) $.get(window.location.href, function(data)
{ {
$('#sidebar').replaceWith($(data).find('#sidebar')); $('#sidebar').replaceWith($(data).find('#sidebar'));

View file

@ -180,8 +180,8 @@ class PostController
*/ */
public function uploadAction() public function uploadAction()
{ {
$this->context->stylesheets []= 'upload.css'; $this->context->stylesheets []= 'post-upload.css';
$this->context->scripts []= 'upload.js'; $this->context->scripts []= 'post-upload.js';
$this->context->subTitle = 'upload'; $this->context->subTitle = 'upload';
PrivilegesHelper::confirmWithException(Privilege::UploadPost); PrivilegesHelper::confirmWithException(Privilege::UploadPost);
if ($this->config->registration->needEmailForUploading) if ($this->config->registration->needEmailForUploading)