Sha256: b91ddb65598b8ddea45820af52ac1609eaa27b5d0c39653573fd91b8bb076015

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

ready = ->

  jQuery.fn.apply_show_only_in_edit_mode = ->

    # When edit mode is entered, on all included '.editable' elements the 'edit' event is triggered.
    # When edit mode is left, the events 'save' or 'cancel' are triggered.
    # For <span class="show_only_in_edit_mode"></span> tags, these events are rather simple:
    # Just show or hide these spans!

    this.on( 'edit', '.show_only_in_edit_mode', ->
      $( this ).show()
    )
    this.on( 'save cancel', '.show_only_in_edit_mode', ->
      $( this ).hide()
    )

    # And just the opposite for <span class="do_not_show_in_edit_mode"></span>.
    this.on( 'edit', '.do_not_show_in_edit_mode', ->
      $( this ).hide()
    )
    this.on( 'save cancel', '.do_not_show_in_edit_mode', ->
      $( this ).show()
    )

    # In order to receive these events, the .show_only_in_edit_mode elements have to be .editable as well.
    this.find( ".show_only_in_edit_mode,.do_not_show_in_edit_mode" ).addClass( "editable" )

    return this

  # Apply this to the whole document in the beginning.
  $( document ).apply_show_only_in_edit_mode()

$(document).ready(ready)

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
edit_mode-1.0.5 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee
edit_mode-1.0.4 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee
edit_mode-1.0.3 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee
edit_mode-1.0.2 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee
edit_mode-1.0.1 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee