2012-05-16 08:42:43 +00:00
|
|
|
<%#= encoding: utf-8 %>
|
|
|
|
$(function() {
|
|
|
|
var content_holder, content;
|
2012-05-17 13:31:29 +00:00
|
|
|
var selector = 'a[contenteditable="true"]';
|
2012-05-16 08:42:43 +00:00
|
|
|
// prevent clicks inside editable area to fire
|
|
|
|
// a click event on the body
|
|
|
|
// and therefor saving our content before we even edit it
|
2012-05-17 13:31:29 +00:00
|
|
|
|
|
|
|
$(".nav-tabs").find(".icons-pencil").click(function(){
|
|
|
|
$(this).css({
|
|
|
|
"display" : "none"
|
|
|
|
})
|
|
|
|
$(this).next().attr("contenteditable",true).addClass("edit");
|
|
|
|
// $(selector).click(function(e) {
|
|
|
|
// e.stopPropagation();
|
|
|
|
// });
|
2012-05-16 08:42:43 +00:00
|
|
|
|
|
|
|
// initialize the "save" function
|
|
|
|
$(selector).focus(function(e) {
|
|
|
|
content_holder = $(this);
|
2012-05-17 13:31:29 +00:00
|
|
|
content = content_holder.html();
|
2012-05-16 08:42:43 +00:00
|
|
|
// one click outside the editable area saves the content
|
2012-05-17 13:31:29 +00:00
|
|
|
$(selector).keypress( function(e) {
|
2012-05-16 08:42:43 +00:00
|
|
|
// but not if the content didn't change
|
2012-05-17 13:31:29 +00:00
|
|
|
//alert('out!!');
|
|
|
|
if(e.keyCode == 13){
|
|
|
|
$(".nav-tabs>li>a").removeClass("edit");
|
|
|
|
$(this).prev(".icons-pencil").css({
|
|
|
|
"display" : "block"
|
|
|
|
})
|
|
|
|
e.preventDefault();
|
|
|
|
// if ($(e.target).is(selector) || content == content_holder.html()) {
|
|
|
|
// return;
|
|
|
|
// }
|
2012-05-16 08:42:43 +00:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
url: content_holder.data('edit-url'),
|
|
|
|
type: 'POST',
|
|
|
|
dataType: 'json',
|
|
|
|
data: { body: content_holder.html() },
|
|
|
|
success: function(json) {
|
2012-05-17 13:31:29 +00:00
|
|
|
$(selector).attr("contenteditable",false)
|
2012-09-12 11:12:50 +00:00
|
|
|
alert("<%= I18n.t('update.success_') %>");
|
2012-05-16 08:42:43 +00:00
|
|
|
//content_holder.effect('highlight', {'color': '#0f0'}, 3000);
|
|
|
|
},
|
|
|
|
error: function() {
|
2012-09-12 11:12:50 +00:00
|
|
|
alert("<%= I18n.t('update.fail') %>");
|
2012-05-16 08:42:43 +00:00
|
|
|
//content_holder.effect('highlight', {'color': '#f00'}, 3000);
|
|
|
|
content_holder.html(content);
|
|
|
|
}
|
|
|
|
});
|
2012-05-17 13:31:29 +00:00
|
|
|
}
|
2012-05-16 08:42:43 +00:00
|
|
|
});
|
|
|
|
});
|
2012-05-17 13:31:29 +00:00
|
|
|
});
|
2012-05-16 08:42:43 +00:00
|
|
|
});
|