diff options
Diffstat (limited to 'mod/blog/views/default/js')
-rw-r--r-- | mod/blog/views/default/js/blog/save_draft.php | 121 |
1 files changed, 45 insertions, 76 deletions
diff --git a/mod/blog/views/default/js/blog/save_draft.php b/mod/blog/views/default/js/blog/save_draft.php index 7f3c3bb12..990ab357d 100644 --- a/mod/blog/views/default/js/blog/save_draft.php +++ b/mod/blog/views/default/js/blog/save_draft.php @@ -3,97 +3,66 @@ * Save draft through ajax * * @package Blog - * - * @todo JS 1.8: no. Convert to use elgg.blog.* */ ?> -<script type="text/javascript"> - setInterval("blogSaveDraft()", 60000); +elgg.provide('elgg.blog'); - /* - * Attempt to save and update the input with the guid. - */ - function blogSaveDraftCallback(data, textStatus, XHR) { - if (textStatus == 'success' && data.success == true) { - var form = $('form[name=blog_post]'); +/* + * Attempt to save and update the input with the guid. + */ +elgg.blog.saveDraftCallback = function(data, textStatus, XHR) { + if (textStatus == 'success' && data.success == true) { + var form = $('form[name=blog_post]'); - // update the guid input element for new posts that now have a guid - form.find('input[name=guid]').val(data.guid); + // update the guid input element for new posts that now have a guid + form.find('input[name=guid]').val(data.guid); - oldDescription = form.find('textarea[name=description]').val(); + oldDescription = form.find('textarea[name=description]').val(); - var d = new Date(); - var mins = d.getMinutes() + ''; - if (mins.length == 1) { - mins = '0' + mins; - } - $(".blog-save-status-time").html(d.toLocaleDateString() + " @ " + d.getHours() + ":" + mins); - } else { - $(".blog-save-status-time").html("<?php echo elgg_echo('error'); ?>"); + var d = new Date(); + var mins = d.getMinutes() + ''; + if (mins.length == 1) { + mins = '0' + mins; } + $(".blog-save-status-time").html(d.toLocaleDateString() + " @ " + d.getHours() + ":" + mins); + } else { + $(".blog-save-status-time").html(elgg.echo('error')); } +} - function blogSaveDraft() { - if (typeof(tinyMCE) != 'undefined') { - tinyMCE.triggerSave(); - } - - // only save on changed content - var form = $('form[name=blog_post]'); - var description = form.find('textarea[name=description]').val(); - var title = form.find('input[name=title]').val(); - - if (!(description && title) || (description == oldDescription)) { - return false; - } - - var draftURL = "<?php echo elgg_get_site_url(); ?>action/blog/auto_save_revision"; - var postData = form.serializeArray(); - - // force draft status - $(postData).each(function(i, e) { - if (e.name == 'status') { - e.value = 'draft'; - } - }); - - $.post(draftURL, postData, blogSaveDraftCallback, 'json'); +elgg.blog.saveDraft = function() { + if (typeof(tinyMCE) != 'undefined') { + tinyMCE.triggerSave(); } - $(document).ready(function() { - // get a copy of the body to compare for auto save - oldDescription = $('form[name=blog_post]').find('textarea[name=description]').val(); - -/* we don't seems to be using the text counter anymore� - $('#excerpt.excerpt').each(function(){ - var allowed = 200; - - // set the initial value - $('#countervalue').text(allowed); + // only save on changed content + var form = $('form[name=blog_post]'); + var description = form.find('textarea[name=description]').val(); + var title = form.find('input[name=title]').val(); - // bind on key up event - $(this).keyup(function(){ - var counter_value = ((allowed - ($(this).val().length))); + if (!(description && title) || (description == oldDescription)) { + return false; + } - $("#countervalue").removeClass(); + var draftURL = elgg.config.wwwroot + "action/blog/auto_save_revision"; + var postData = form.serializeArray(); - if ((counter_value > 10)) { - $("#countervalue").addClass("positive"); - } - else if ((counter_value <= 10) && (counter_value >= 0)) { - $("#countervalue").addClass("gettingclose"); - } - else if ((counter_value < 0)) { - $("#countervalue").addClass("negative"); - } + // force draft status + $(postData).each(function(i, e) { + if (e.name == 'status') { + e.value = 'draft'; + } + }); - // insert new length - $('#countervalue').text(counter_value); + $.post(draftURL, postData, blogSaveDraftCallback, 'json'); +} - }); - }); -*/ - }); +elgg.blog.init = function() { + // get a copy of the body to compare for auto save + oldDescription = $('form[name=blog_post]').find('textarea[name=description]').val(); + + setInterval(elgg.blog.saveDraft, 60000); +}; -</script> +elgg.register_event_handler('init', 'system', elgg.blog.init);
\ No newline at end of file |