diff options
author | ewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-22 07:00:35 +0000 |
---|---|---|
committer | ewinslow <ewinslow@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2011-02-22 07:00:35 +0000 |
commit | 131b559a6136fc6f6f9b1c9aac54898b9a3aa74c (patch) | |
tree | 79c1a64bdaa28b714a234f8e588f2e176967501c /mod/blog/views/default/js | |
parent | 567de1ec8eed575003d6e4f96f4b3a364854df78 (diff) | |
download | elgg-131b559a6136fc6f6f9b1c9aac54898b9a3aa74c.tar.gz elgg-131b559a6136fc6f6f9b1c9aac54898b9a3aa74c.tar.bz2 |
Cleaned up blog js
git-svn-id: http://code.elgg.org/elgg/trunk@8419 36083f99-b078-4883-b0ff-0f9b5a30f544
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 |