rosa-build/app/assets/javascripts/extra/preview.js

24 lines
827 B
JavaScript
Raw Normal View History

2012-09-18 11:00:21 +01:00
$(document).ready(function() {
var preview_url = $('#preview_url').val();
$('#md_tabs.nav.nav-tabs').each(function(i) { $(this).find('a:first').tab('show') });
$('#md_tabs a[data-toggle="tab"]').on('shown', function (e) {
if(e.relatedTarget) { var hash = e.relatedTarget.hash; }
else { var hash = e.currentTarget.hash; }
var el = $(hash+'_input');
var el_dup = $(hash+'_input_dup');
var preview = $(e.target.hash+' > .formatted.cm-s-default');
if(el.val() != el_dup.val() || preview.val() === '') {
el_dup.val(el.val());
$.ajax({
type: 'POST',
url: preview_url,
data: el_dup.serialize(),
success: function(data){
2012-09-21 11:31:55 +01:00
preview.html(data).find('code').each(function (code) { CodeMirrorRun(this); })
2012-09-25 10:47:12 +01:00
}
});
2012-09-18 11:00:21 +01:00
};
});
});