Sha256: 57b7c47cd244f103a2b7034a6f2b6b73d19ccdb10a3b1e51044a1f6052f270df

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

jQuery ->

  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.find( ".show_only_in_edit_mode" ).live( "edit", ->
      $( this ).show()
    ).live( "save cancel", ->
      $( this ).hide()
    )

    # And just the opposite for <span class="do_not_show_in_edit_mode"></span>.
    this.find( ".do_not_show_in_edit_mode" ).live( "edit", ->
      $( this ).hide()
    ).live( "save cancel", ->
      $( 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()

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
edit_mode-0.0.6 lib/assets/javascripts/edit_mode/show_only_in_edit_mode.js.coffee