Sha256: 44261e937f4d9f344dcc847bdbe10c99e406fc25a0c9aefdd4442d4427c1f2b3

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

var BlogPostsInitializer = (function () {

  function initializeAutosave () {
    var formInput = $('.posts__form-autosave')

    if (formInput) {
      var form = $(formInput).parent()
      setInterval(function () {
        if ($(formInput).val('false')) {
          $(formInput).val('true')
          $(form).attr('data-remote', true)
          $.rails.handleRemote($(form))
          $(formInput).val('false')
          $(form).attr('data-remote', false)
        }
      }, 10000)
    }
  }

  function initializeCategoriesAutosave () {
    var form = $('.posts__edit-categories').find('form')
    $(form).find('input').change(function () {
      $(form).submit()
    })
  }

  function initializePublicationDatetimeAutosave () {
    var form = $('.posts__edit-publication-datetime').find('form')
    $(form).find('input').change(function () {
      $(form).submit()
    })
  }

  function initializeStatusSwitchAutosave () {
    var form = $('.posts__edit-status-switch').find('form')
    $(form).find('select').change(function () {
      $(form).submit()
    })
  }

  // Init:

  function init () {
    initializeAutosave()
    initializeCategoriesAutosave()
    initializePublicationDatetimeAutosave()
    initializeStatusSwitchAutosave()
  }

  return {
    init: init
  }

})()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lato_blog-2.1 app/assets/javascripts/lato_blog/initializers/Posts.js