diff options
| author | hukl <contact@smyck.org> | 2009-05-08 09:18:19 +0200 |
|---|---|---|
| committer | hukl <contact@smyck.org> | 2009-05-08 09:18:19 +0200 |
| commit | 6856613c1bebf778a843eaeb4527870c5f1f72e6 (patch) | |
| tree | 4680007da92faab9e541eb7ad0c8e0743691a63a | |
| parent | 7f88d4b70da9b1f1916e3f1e7c0d3913d1e31bc1 (diff) | |
put the whole autosave stuff into admin_interface.js
| -rw-r--r-- | app/views/layouts/admin.html.erb | 45 | ||||
| -rw-r--r-- | app/views/nodes/_autosave.html.erb | 0 | ||||
| -rw-r--r-- | public/javascripts/admin_interface.js | 49 |
3 files changed, 49 insertions, 45 deletions
diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 07363e3..7902cae 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb | |||
| @@ -24,52 +24,9 @@ | |||
| 24 | extended_valid_elements : "aggregate[tags|limit|order_by|order_direction|partial]", | 24 | extended_valid_elements : "aggregate[tags|limit|order_by|order_direction|partial]", |
| 25 | relative_urls : false, | 25 | relative_urls : false, |
| 26 | entity_encoding : "raw", | 26 | entity_encoding : "raw", |
| 27 | oninit : "setup_autosave" | 27 | oninit : "cccms.setup_autosave" |
| 28 | }); | 28 | }); |
| 29 | 29 | ||
| 30 | var setup_autosave = function() { | ||
| 31 | |||
| 32 | var elements = { | ||
| 33 | "title" : $('#page_title'), | ||
| 34 | "abstract" : $('#page_abstract'), | ||
| 35 | "body" : $('#page_body_ifr').contents().find('#tinymce'), | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | var page = { | ||
| 40 | "cached_title_length" : elements.title.val().length, | ||
| 41 | "cached_abstract_length" : elements.abstract.val().length, | ||
| 42 | "cached_body_length" : elements.body.html().length, | ||
| 43 | |||
| 44 | "title_has_changed" : function() { | ||
| 45 | return (elements.title.val().length != this.cached_title_length) | ||
| 46 | }, | ||
| 47 | |||
| 48 | "abstract_has_changed" : function() { | ||
| 49 | return (elements.abstract.val().length != this.cached_abstract_length) | ||
| 50 | }, | ||
| 51 | |||
| 52 | "body_has_changed" : function() { | ||
| 53 | return elements.body.html().length != this.cached_body_length | ||
| 54 | } | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | jQuery.fn.submitWithAjax = function(options) { | ||
| 59 | if (page.title_has_changed() || page.abstract_has_changed() || page.body_has_changed()) { | ||
| 60 | |||
| 61 | page.cached_title_length = elements.title.val().length; | ||
| 62 | page.cached_abstract_length = elements.abstract.val().length; | ||
| 63 | page.cached_body_length = elements.body.html().length; | ||
| 64 | |||
| 65 | $("#flash").append("<img src='/images/ajax-loader.gif' alt='' />"); | ||
| 66 | $.post(this.attr("action"), $(this).serialize(), null, "script"); | ||
| 67 | } | ||
| 68 | }; | ||
| 69 | |||
| 70 | setInterval('$("#edit_node_<%= @node.id %>").submitWithAjax()', 15000); | ||
| 71 | } | ||
| 72 | |||
| 73 | </script> | 30 | </script> |
| 74 | </head> | 31 | </head> |
| 75 | 32 | ||
diff --git a/app/views/nodes/_autosave.html.erb b/app/views/nodes/_autosave.html.erb deleted file mode 100644 index e69de29..0000000 --- a/app/views/nodes/_autosave.html.erb +++ /dev/null | |||
diff --git a/public/javascripts/admin_interface.js b/public/javascripts/admin_interface.js index 2b8a0d2..a1d78c7 100644 --- a/public/javascripts/admin_interface.js +++ b/public/javascripts/admin_interface.js | |||
| @@ -16,4 +16,51 @@ $(document).ready(function () { | |||
| 16 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} | 16 | 'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")} |
| 17 | }) | 17 | }) |
| 18 | 18 | ||
| 19 | }); \ No newline at end of file | 19 | }); |
| 20 | |||
| 21 | |||
| 22 | cccms = { | ||
| 23 | setup_autosave : function() { | ||
| 24 | |||
| 25 | var elements = { | ||
| 26 | "title" : $('#page_title'), | ||
| 27 | "abstract" : $('#page_abstract'), | ||
| 28 | "body" : $('#page_body_ifr').contents().find('#tinymce'), | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | var page = { | ||
| 33 | "cached_title_length" : elements.title.val().length, | ||
| 34 | "cached_abstract_length" : elements.abstract.val().length, | ||
| 35 | "cached_body_length" : elements.body.html().length, | ||
| 36 | |||
| 37 | "title_has_changed" : function() { | ||
| 38 | return (elements.title.val().length != this.cached_title_length) | ||
| 39 | }, | ||
| 40 | |||
| 41 | "abstract_has_changed" : function() { | ||
| 42 | return (elements.abstract.val().length != this.cached_abstract_length) | ||
| 43 | }, | ||
| 44 | |||
| 45 | "body_has_changed" : function() { | ||
| 46 | return elements.body.html().length != this.cached_body_length | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | jQuery.fn.submitWithAjax = function(options) { | ||
| 52 | if (page.title_has_changed() || page.abstract_has_changed() || page.body_has_changed()) { | ||
| 53 | |||
| 54 | page.cached_title_length = elements.title.val().length; | ||
| 55 | page.cached_abstract_length = elements.abstract.val().length; | ||
| 56 | page.cached_body_length = elements.body.html().length; | ||
| 57 | |||
| 58 | $("#flash").append("<img src='/images/ajax-loader.gif' alt='' />"); | ||
| 59 | $.post(this.attr("action"), $(this).serialize(), null, "script"); | ||
| 60 | |||
| 61 | } | ||
| 62 | }; | ||
| 63 | |||
| 64 | setInterval('$("#page_editor > form").submitWithAjax()', 15000); | ||
| 65 | } | ||
| 66 | } \ No newline at end of file | ||
