Skip to content

Instantly share code, notes, and snippets.

@jordanhudgens
Created May 11, 2015 17:23
Show Gist options
  • Save jordanhudgens/c71656f3372942096e26 to your computer and use it in GitHub Desktop.
Save jordanhudgens/c71656f3372942096e26 to your computer and use it in GitHub Desktop.
getParameterByName = (name) ->
name = name.replace(/[\[]/, '\\[').replace(/[\]]/, '\\]')
regex = new RegExp('[\\?&]' + name + '=([^&#]*)')
results = regex.exec(location.search)
if results == null then '' else decodeURIComponent(results[1].replace(/\+/g, ' '))
# ---
# generated by js2coffee 2.0.3
autoSaveBookChapter = ->
for instance of CKEDITOR.instances
CKEDITOR.instances[instance].updateElement()
$.ajax
type: 'POST'
url: '/book_chapters/autosave/' + getParameterByName('chapter_id')
data: $('.edit_book_chapter').serialize()
dataType: 'script'
success: (data) ->
$(".draft-alert").fadeToggle 1000
return
autoSaveJournalPost = ->
for instance of CKEDITOR.instances
CKEDITOR.instances[instance].updateElement()
$.ajax
type: 'POST'
url: '/journal_posts/autosave/' + getParameterByName('journal_post_id')
data: $('.edit_journal_post').serialize()
dataType: 'script'
success: (data) ->
$(".draft-alert").fadeToggle 1000
return
$ ->
if $('.edit_journal_post').length
setInterval autoSaveJournalPost, 10000
if $('.edit_book_chapter').length
setInterval autoSaveBookChapter, 10000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment