JavaScript for WordPress Forums Vanilla JavaScript vanillapress 1.6.17 on firefox

This topic contains 3 replies, has 2 voices, and was last updated by  Zac Gordon 2 years, 6 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27222

    Alexandra
    Participant

    Hi for js i like to work on firefox as i found the code inspector console better
    and i noticed that when i click update it has a different behaviour than in chrome, the page reloads, so it seems that the preventdefault in the function editor.updateContent doesn’t work the same under firefox…
    and because of that of course the update is not saved

    second thing, when we check if localStorage exists, why creating a new function to check it, i find much more simple to do that

    if(!model.getLocalStore()) {
        model.updateLocalStore(data);
      }

    What do you think ?

    #27240

    Zac Gordon
    Keymaster

    Hi! Great question!

    Firefox handles events a bit different and you can simply do this:

    
    function( event ) {
      event.preventDefault;
    }
    

    That approach you took would probably be fine! Could you point me to exactly where you’re seeing this so I can respond in more depth?

    Thanks!

    Great questions!!!

    #27267

    Alexandra
    Participant

    it’s in chapter 1.6.17 Load Content from Local Store , in the model

    there is this function

    /**
     * Checks if local store already exists
     *
     * @return {Boolean} Boolean value for if local store already exists
     */
    model.checkLocalStore = function() {
    
      var store = model.getLocalStore();
    
      if ( null === store ) {
        return false;
      } else {
        return true;
      }
    
    }

    and then it’s used in the init

    model.init = function() {
    
      if( false === model.checkLocalStore() ) {
          model.updateLocalStore( data );
      }
    }

    But as this function is not used in other places i found that doing it like this

    model.init = function() {
    
      if( false === model.checkLocalStore() ) {
        model.updateLocalStore( data );
      }
    
    }

    much more simpler

    For the preventDefault on firefox, can you show me how the function would be, and how to make it work on all browser
    i am trying things but it doesn’t work

    I have tried return false;
    searching on google http://stackoverflow.com/questions/1367195/preventdefault-wont-work-on-firefox

    but it doesn’t work

    this is the actual function

    /**
     * Updates local storage for post or page
     *
     */
    editor.updateContent = function() {
    
      event.preventDefault();
    
      model.updateContent( editor.currentContent );
    
    };
    #27493

    Zac Gordon
    Keymaster

    This should work:

    
    editor.updateContent = function( event ) {
    
      event.preventDefault();
      model.updateContent( editor.currentContent );
    
    };
    

    Some folks like to do this:

    
    editor.updateContent = function( e ) {
    
      e.preventDefault();
      model.updateContent( editor.currentContent );
    
    };
    

    I will go back when I have some time and update some of the early event stuff to talk more about cross browser support and reasons for this.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.