JavaScript for WordPress › Forums › Vanilla JavaScript › vanillapress 1.6.17 on firefox
- This topic has 3 replies, 2 voices, and was last updated 7 years, 4 months ago by Zac Gordon.
-
AuthorPosts
-
May 10, 2017 at 10:16 am #27222AlexandraParticipant
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 savedsecond 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 ?
May 10, 2017 at 5:12 pm #27240Zac GordonKeymasterHi! 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!!!
May 11, 2017 at 6:06 am #27267AlexandraParticipantit’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 workI have tried return false;
searching on google http://stackoverflow.com/questions/1367195/preventdefault-wont-work-on-firefoxbut 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 ); };
May 15, 2017 at 1:50 am #27493Zac GordonKeymasterThis 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.
-
AuthorPosts
- You must be logged in to reply to this topic.