Skip to content

Instantly share code, notes, and snippets.

@sergzach
Created December 2, 2012 21:35
Show Gist options
  • Save sergzach/4191171 to your computer and use it in GitHub Desktop.
Save sergzach/4191171 to your computer and use it in GitHub Desktop.
codemirror.
var editor;
$(function(){
editor = CodeMirror.fromTextArea(document.getElementById("id_body"), {
lineNumbers: true,
indentUnit: 4,
tabMode: "shift",
matchBrackets: true
});
$('#preview').click(function() {
editor.save();
var current = new Date();
var month = current.getMonth() + 1;
var day = current.getDate();
var year = current.getFullYear();
var hour = current.getHours();
var minute = current.getMinutes();
var second = current.getSeconds();
var array = [day,month,year,hour,minute,second];
var time = array.join(""); // array to string without commas
var chars= "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 6;
var random = '';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
random += chars.substring(rnum,rnum+1);
}
random += time;
var title = $('#id_title').val();
var body = $('#id_body').val();
var id = random;
var ajaxOptions = {
type:'post',
url : '/admin/post/save_preview/',
data : {
'title' : title,
'body' : body,
'id' : id
},
success: function(){
window.open("/blog/post/preview/"+id);
},
error: function(){
alert('Bir hata oluştu. Lütfen tekrar deneyiniz.');
}
};
$.ajax(ajaxOptions);
});
$('#submit').click(function() {
if (!$('#id_title').val())
{
$('#warning').fadeIn(200).delay(3000);
$('#warning').fadeOut(200);
return false;
}
else {
ajaxStart: $('#loading_gif').fadeIn(200);
var auto_save_id = $('#auto_save_id').val();
var title = $('#id_title').val();
var body = $('#id_body').val();
if ($('#id_isdraft').prop('checked')){
var isdraft="True";
}else{
var isdraft="False";
}
var ajaxOptions = {
type: 'post',
url: '/admin/post/save/',
data: {
'title': title,
'body': body,
'isdraft': isdraft,
'auto_save_id': auto_save_id
},
success: function(data){
$('#loading_gif').fadeOut(200);
$('#success').fadeIn(200).delay(3000);
$('#auto_save_id').val(data.pid);
},
complete: function(){
$('#success').fadeOut(200);
},
error: function(){
alert("Bir hata oluştu. Lütfen tekrar deneyiniz.");
}
};
$.ajax(ajaxOptions);
return false;
}
});
call_func = setInterval(auto_save,'20000');
});
function auto_save(){
if (!$('#id_title').val())
{
$('#warning').fadeIn(200).delay(3000);
$('#warning').fadeOut(200);
return false;
}
else {
var title = $('#id_title').val();
var body = $('#id_body').val();
if ($('#id_isdraft').prop('checked')){
var isdraft="True";
}else
{
var isdraft="False";
}
var auto_save_id = $('#auto_save_id').val();
var ajaxOptions = {
type : 'post',
url : '/admin/post/save/',
data : {
'title' : title,
'body' : body,
'isdraft' : isdraft,
'auto_save_id' : auto_save_id
},
success: function(data){
$('#loading_gif').fadeOut(200);
$('#success').fadeIn(200).delay(3000);
$('#auto_save_id').val(data.pid);
},
complete: function(){
$('#success').fadeOut(200);
},
error: function(){
alert("Bir hata oluştu. Lütfen tekrar deneyiniz.");
}
};
$.ajax(ajaxOptions);
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment