Add new in-place editor

This commit is contained in:
Eike Foken
2011-09-14 00:09:50 +02:00
parent 0c0b00f4e3
commit 51f3e022fe
8 changed files with 711 additions and 65 deletions

View File

@@ -97,27 +97,6 @@ var CookieList = function(cookieName) {
};
};
/**
* Saves the changes done by in-place edit.
*
* @param obj
* @param cancel
*/
function saveChanges(obj, cancel) {
var a;
if (!cancel) {
a = $(obj).parent().siblings(0).val();
$.post(SITE_URL + 'ajax/save_project', { content: a }, function(response) {
alert("Die Änderungen wurden gespeichert.");
});
} else {
a = cancel;
}
$(obj).parent().parent().after('<div class="editInPlace">' + a + '</div>').remove();
}
/**
* Alternates the table rows.
*/
@@ -127,21 +106,6 @@ $.fn.alternateRowColors = function() {
return this;
};
/**
* Replaces html line breaks with newlines.
*/
$.fn.br2nl = function() {
return $(this).html().replace(/(<br>)|(<br \/>)|(<p>)|(<\/p>)/g, "");
};
/**
* Similar to PHP's nl2br function.
*/
$.fn.nl2br = function() {
var breakTag = (is_xhtml || typeof is_xhtml === 'undefined') ? '<br />' : '<br>';
return $(this).html().replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1'+ breakTag +'$2');
};
/**
* Do some stuff if document is ready.
*/
@@ -153,7 +117,7 @@ $(document).ready(function() {
$('ul.tabs li:first').addClass('active').show(); // activate first tab
$('.tab_content:first').show(); // show first tab content
// onClick event
// on-click event
$('ul.tabs li').click(function() {
$('ul.tabs li').removeClass('active'); // remove any 'active' class
$(this).addClass('active'); // add 'active' class to selected tab
@@ -251,28 +215,6 @@ $(document).ready(function() {
$(this).find('td.drag_handle').removeClass('drag_handle-show');
});
/*
* In-place editor
*/
$('.editInPlace').click(function() {
var textarea = '<div><textarea rows="6" cols="60">' + $(this).br2nl() + '</textarea><p></p>';
var button = '<p><a class="button save" href="javascript:void(0);">Speichern</a> <a class="button cancel" href="javascript:void(0);">Abbrechen</a></div>';
var revert = $(this).html();
$(this).after(textarea + button).remove();
$('.save').click(function() {
saveChanges(this, false);
});
$('.cancel').click(function() {
saveChanges(this, revert);
});
}).mouseover(function() {
$(this).addClass('editable');
}).mouseout(function() {
$(this).removeClass('editable');
});
/*
* Active project selection
*/