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

  • Home
  • SEARCH
  • 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 9189427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:14:04+00:00 2026-06-17T20:14:04+00:00

I am trying to create a javascript plugin that allows you to hook into

  • 0

I am trying to create a javascript plugin that allows you to hook into the save operation. I want some logic wrapped around the logic though:

  1. Show a spinner
  2. Execute save hook-in
  3. Execute save logic
  4. Remove Spinner

here is an example of my code:

function save(){
    var settings = getSettings();

    showSpinner();

    // Hook-in call
    if(settings.onSave)
        settings.onSave();

    saveState();

    removeSpinner();
}

showSpinner() just hides save/cancel buttons and shows a spinner in its place.

hideSpinner() does the opposite.

saveState() saves the data from input fields to their data attributes.

settings.onSave() can be whatever code is passed in to the config by a user of the plugin.

When I run the process the spinner never shows up even though the hook-in I have defined takes ~1.5 seconds to return. If I pause the code in the debugger, the spinner does have a chance to show and it does disappear after the operation is complete.

What is the best approach to resolve this? I am not at all familiar with asynchronous design patterns within javascript. I know there is a single thread that the javascript can run on but I don’t know why the save operation is getting in the way of showing the spinner.

  • 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-17T20:14:05+00:00Added an answer on June 17, 2026 at 8:14 pm

    Your browser won’t update the interface until Javascript gives back control to the browser, meaning you need to return from function before the browser will show the spinner. Use setTimeout to give control back to the browser briefly.

    function save(){
    
        showSpinner();
    
        setTimeout(function(){
            var settings = getSettings();
    
            // Hook-in call
            if(settings.onSave)
                settings.onSave();
    
            saveState();
    
            removeSpinner();
        }, 0 );
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem trying to create a Javascript function that checks all the
I'm trying to create a custom javascript class that inherits from google.maps.Map (V3 API).
I am trying to create a simple Javascript text editor that only makes paragraph
I'm trying to create a Captcha in JavaScript but I ran into issues. I
i am just trying to create a link which execute some JavaScript in stead
Trying to create a backbone plugin that inherits from Backbone.Model but overrides the sync
I am trying to create a Jquery plugin that maintains chainability and has public
I am trying to create a form using only JavaScript. I mean create a
I'm trying to create a public gist via javascript. I'm not using any authentication
I'm trying to create a simple extensible class in javascript but when setting property

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.