arvgta / ajaxify

Ajaxify - An Ajax Plugin
https://4nf.org/
275 stars 124 forks source link

Standalone hash in URL - refinement #103

Closed arvgta closed 7 years ago

arvgta commented 8 years ago

EDIT: Researched the web and it looks like a change in the hash part only does not cause a page refresh - also applying to a standalone hash

Therefore closing again


Hi Nicolas,

as we don't know the exact code yet for this special case, I have opened an issue instead of a pull request.

I understand, that the special case of a standalone hash was not being treated to your satisfaction. There are probably lots of CMS that work with standalone hashes, so this issue is important for a great deal of users...

Have read what you specified in #102 and do agree principally, but would like to tweak the exisiting logic for handling URLs with hashes with as litte as possible changes.

I see two possiblities (both within the _click() handler):

1) Tweak the existing_hashChange() to be less / more selective (that would be the most elegant solution, if it does the job)

or

2) Make a special branch / condition for handling standalone hashes, maybe introducing another option to enable / disable the new logic?

...finally, the solution must also leave the handling of hashes the same for internal links to different root URLs.

Also, returning true means, that the default click() kicks in and the event bubbles up, breaking the execution of Ajaxify, right? I would like to avoid that, if possible...

Here's the current code of the _click() handler:

 click: function(e, mode) { //...handler for normal clicks
      var link = $.rq("v", e);  // validate internal URL
      if(!link || _exoticKey(e)) return; // Ignore everything but normal click

      //solution 2) could be inserted here, maybe returning true
      //e.g. if(link.href.substr(-1) ==='#') return true;

      if(_hashChange(link)) { // only hash has changed
          $.scroll(link.href);
          if(link.href.substr(-1) !=='#') currentURL = link.href; // in case of solution 2) condition could be dropped
          $.hApi("="); 
          return false;
      }

      _stopBubbling(e);
      if($.rq("=")) $.hApi("=");
      if(refresh || !$.rq("=")) _request(); // Continue with _request()
  }
arvgta commented 7 years ago

Am re-opening this, because I would like to know if this current logic is acceptable (I am very unsure about this issue):

 if(link.href.substr(-1) ==='#') return true; // If standalone hash, enable default behaviour and return ??

Pronto, which I use as a backbone, does it this way, too. However, there may be a better way to handle this path of execution?


Questions:

1) Does the current logic cause discontinuation of Ajaxify's execution? 2) If so, how can Ajaxify be "kept alive" instead, emulating the behaviour that the user desired?