Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9322631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:08:28+00:00 2026-06-19T04:08:28+00:00

I have a web app with Rails. I use jQuery for manipulating text selections.

  • 0

I have a web app with Rails. I use jQuery for manipulating text selections.

I have implemented two modi:

Reading mode:
User can only read text. Highlights and modifications are hidden.

Review mode:
User can edit and modify the text.

For the reading mode I want to prevent all functions for text modifications to get triggered.

For now I have a variable inReviewMode. Its boolean and I trigger the value when the user clicks on a button. In the code I realize the switch like:

(CoffeeScript notation)

jQuery ->
  $(document).on 'contextmenu', 'article#content', (e) ->
    if inReviewMode
      e.preventDefault()
      # and so on... 

  $(document).on 'click', 'article#content', (e) ->
    if inReviewMode
      # something to do

Is there a better approach like wrapping the if statement around all functions and then implementing the “reading mode functions” in the else block?

I hope you understand my question.
Thanks for helping!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-19T04:08:29+00:00Added an answer on June 19, 2026 at 4:08 am

    I think there are a few things that could clean this up:

    1. Use stopImmediatePropagation to cancel notifications to sibling event handlers.
    2. Use one event handler for all of the “edit” events you’d like to cancel.

    In other words, something like this:

    $ ->
        isReviewMode = false;
    
        $('#review-yes').change () ->
            isReviewMode = this.checked;
    
        $(document).on 'click contextmenu', '#content', (e) ->
            if isReviewMode
                e.preventDefault()
                e.stopImmediatePropagation()
    
        $(document).on 'click', '#content', (e) ->
            alert 'edit mode!'
    

    Example: http://jsfiddle.net/6zAN7/8/

    As you can see from the example, both click and contextmenu don’t occur in review mode.

    You could extend the idea and provide a constant variable EditModeEvents that contains all of the events that you want to cancel in edit mode:

    $ ->
        isReviewMode = false;
        EditModeEvents = ['click', 'contextmenu'];
    
        $('#review-yes').change () ->
            isReviewMode = this.checked;
    
        $(document).on EditModeEvents.join(' '), '#content', (e) ->
            if isReviewMode
                e.preventDefault()
                e.stopImmediatePropagation()
    
        $(document).on 'click', '#content', (e) ->
                alert 'edit mode!'
    

    This way, the code is a bit clearer on what it’s accomplishing and all you’ll have to do to add new events is add the event name to EditModeEvents.

    This strategy assumes that all you want to do in review mode for each event is stop the event from occurring. If you need to do different things depending on the event, then this won’t work as well–but you can do something similar with separate event handlers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a web app running on Rails, using Devise and OmniAuth for user
I have a web app with a clean RESTful JSON API, based on Rails
I have another web app, that uses the liferay user database. But before a
I have a Rails project that is basically a simple web app for a
I've got a little time-tracking web app (implemented in Rails 3.2.8 & MySQL). The
i've developed small web app for personal use with Ruby on Rails. Now when
I have a rails app that makes web api call , the rails app
I have a Rails web app that is used to gather data from an
I have a web frontend based on a Ruby On Rails app that inserts
In my Rails app I have some plain old JS: function reorder(divid,url) { jQuery(divid).sortable({

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.