naja

Modern AJAX library for Nette Framework

MIT License

Downloads
22.1K
Stars
109
Committers
7

Bot releases are hidden (Show)

naja - 2.2.0

Published by jiripudil almost 3 years ago

New features

  • ✨ SnippetCache has been extracted into a separate component and the feature now has its own documentation page.

    • The historyUiCache option has been deprecated in favour of the new snippetCache option.
    • The HistoryHandler.uiCache flag has been deprecated in favour of the snippetCache option. You can configure it via naja.initialize(defaultOptions).
    • The data-naja-history-no-cache attribute has been deprecated in favour of data-naja-snippet-cache="off".
    • An alternative snippet cache storage has been added, utilizing SessionStorage which might offer a larger data quota than history entries. If your snippets are too large for history state, you might try this storage using the snippetCache: 'session' option.
    • The SnippetCache component exposes three events, store, fetch and restore, that allow you to tweak the caching behaviour or bypass it altogether.
  • ✨ HistoryHandler exposes two new events, buildState and restoreState. These allow you to hook into the History API integration, and the SnippetCache is built on top of them.

  • ✨ ScriptLoader is now able to deduplicate loaded scripts by a unique identifier (suggested in #336). You can add a data-naja-script-id attribute to the <script> element inside a snippet. ScriptLoader will only load each identified script once, even if it repeatedly appears in multiple snippet responses.

Minor changes and bugfixes

  • 🐞 Naja no longer adds submitter to form data if it has an empty name (#333).
  • 🐞 Naja is able to correctly serialize top-level arrays in data into (#315).
  • πŸ”§ naja.initialize() is no longer required to be called after the DOM is loaded, Naja makes sure of that internally where necessary.
  • πŸ”§ Naja now sends a proper Accept: application/json header (#314).
  • πŸ“– Documentation has been extended with more explanatory sections and code examples (#211).
naja - 2.0.0-alpha.2

Published by jiripudil over 4 years ago

naja - 1.8.3

Published by jiripudil over 4 years ago

  • Made support for submitting forms via GET even more reliable.
naja - 1.8.2

Published by jiripudil over 4 years ago

  • Fixed submitting forms via GET (#63).
naja - 1.8.1

Published by jiripudil over 4 years ago

  • Reverted a commit that got into 1.8.0 as a result of a brain fart.
naja - 1.8.0

Published by jiripudil over 4 years ago

  • SnippetHandler events now have the fromCache flag. The beforeUpdate and afterUpdate events now carry the information about whether the snippet is being updated from cache after user navigation (i.e. going back in history), or as a result of an AJAX request to the server.
  • RedirectHandler detects local redirects via UIHandler.allowedOrigins. Until now, redirects leading to the same origin were done via another AJAX request (unless forced otherwise). This detection now takes into account the configured allowed origins, which means that redirects to any of the allowed origins is processed asynchronously by default.
  • RedirectHandler dispatches the redirect event prior to redirection. This event allows you to override the soft vs. hard redirection settings, or even entirely prevent the redirection from happening.
naja - 2.0.0-alpha1

Published by naja-publisher almost 5 years ago

naja - 1.7.0

Published by jiripudil almost 5 years ago

  • Deprecate reading options from response payload (#44). After some thought, I consider passing options such as replaceHistory or forceRedirect to Naja via the response payload to be a cul-de-sac; server should not be able to affect the client-side processing of the request in such direct way. Therefore, Naja now emits a deprecation warning if it encounters such options in the payload, and will stop supporting them in 2.0.

  • RedirectHandler: pass original options to the new "redirection" request (#45). If the target redirection URL is local (i.e. relative, or absolute pointing to the same origin), RedirectHandler sends another AJAX request instead of redirecting. Since redirect sequences are usually perceived as a single request, Naja now mimics such flow by passing the options of the original request to the redirected request, so that the intended behaviour of the request is preserved.

naja - 1.6.0

Published by jiripudil over 5 years ago

  • Refactor UIHandler and FormsHandler to only rebind updated snippets (#19). This is a simple internal refactoring which could lead to a better performance. As a side effect, the UIHandler now exposes the bindUI() method which you can use to manually bind the AJAX handler to DOM nodes that are created dynamically via a different mechanism than Nette snippets.

  • Accept defaultOptions in naja.initialize() (#24). The naja.initialize() method now accepts defaultOptions, adding a second way to configure them in addition to modyfing naja.defaultOptions directly. The default options passed to the initialize method are also provided to the init event listeners.

  • HistoryHandler: implement disabling UI cache (#17). This is an advanced feature that entirely disables the UI state cache; this helps prevent errors caused by big snippets that exceed the maximum storage quota. During navigation through the browser history, requests are actually sent again rather than artificially replayed from the history entry state. Be sure that you know what you're doing before using this feature.

  • Optimized SnippetHandler prepend/append (#20). Thanks @vitkutny!

naja - 1.5.1

Published by jiripudil over 6 years ago

  • Fixed: HistoryHandler now respects naja.defaultOptions.history and does not override it to true when data-naja-history attribute is not set on the element. (Thanks @brosland for investigation!)
naja - 1.5.0

Published by jiripudil over 6 years ago

  • FormsHandler now optionally accepts a reference to nette-forms (#15). This is handy if you import the nette-forms script manually. If you provide the reference, FormsHandler will use it instead of relying on global window.Nette.
naja - 1.4.0

Published by jiripudil over 6 years ago

  • Added UIHandler.clickElement() and UIHandler.submitForm() helper methods (#12) that allow you to dispatch UI-bound events manually. This is especially useful if you need to submit a form programmatically (e.g. on change of select box), because form.submit() does not trigger the form's submit event.
    • ⚠️ The helper methods trigger the interaction event with originalEvent set to undefined. This potentially breaks BC if you choose to use the newly introduced methods!
  • Simplified initial pop detection (#10). It doesn't appear to be a problem anymore, but in browsers where it still is a problem (some ancient Chromes and Safaris), this solution should work too while being elegantly simple. As a side effect, this should also prevent popstate behaviour in HistoryHandler being triggered on hashchange.
    • ⚠️ This also removes a few attributes from HistoryHandler that are no longer necessary: initialUrl, initialState, and popped. They were part of the internal API and were never documented, thus I don't consider their removal to be a BC break.
naja - 1.3.2

Published by jiripudil over 6 years ago

  • Fixed incorrect data-naja-snippet-prepend and data-naja-snippet-append attributes detection in SnippetHandler
naja - 1.3.1

Published by jiripudil over 6 years ago

  • Fixed incorrect data-naja-history-nocache attribute detection in HistoryHandler (#8, thanks @dakur)
naja - 1.3.0

Published by jiripudil almost 7 years ago

  • You can provide default options for your extensions or even Naja's core components via naja.defaultOptions.
  • The options object is now passed to the success, error, and complete event handlers. Components and extensions can now use the options object to pass metadata along with the request instead of having to keep track of them internally, which should prevent potential concurrency issues.
  • RedirectHandler reads the forceRedirect flag not only from response payload but also from options.
naja - 1.2.0

Published by jiripudil almost 7 years ago

  • SnippetHandler now exposes events that are dispatched prior to and after every snippet update.
  • I got rid of an unnecessary layer of inheritance in a small internal refactoring.
naja - 1.1.0

Published by jiripudil almost 7 years ago

  • Initialization of core services was refactored to allow for further changes.
  • The Promise returned by naja.makeRequest() is resolved with the parsed response body, or rejected with the thrown error. This allows you to chain custom behavior after the response is processed by Naja when calling makeRequest() manually.
  • Aborted requests are handled in a specific abort event. They no longer trigger error handling, as the reasons for aborting the request usually do not indicate an erroneous state.
  • The bound selector (.ajax) is now customizable via naja.uiHandler.selector.
  • To prevent people from shooting themselves in the foot, UIHandler now checks that the link target matches a set of allowed origins, and does not dispatch the asynchronous request if it does not match. You can configure the allowed origins by pushing them to naja.uiHandler.allowedOrigins.
  • Browser history manipulation can be disabled for specific requests by adding history: false to the request options, or data-naja-history="off" to the .ajax element.
  • Also, you can now decide on the front-end side whether you want to push a new state, or replace the current one, by adding history: 'replace' to the options or data-naja-history="replace" to the element.
  • Tests now run in real browsers via SauceLabs, so that there's a better guarantee that IE 10+ is actually supported. πŸŽ‰
Package Rankings
Top 3.5% on Npmjs.org
Badges
Extracted from project README
Build Status Code Coverage latest version license minified size minzipped size monthly downloads downloads total
Related Projects