{"_id":"nette.ajax.js","_rev":"6-adfb08d7522339493603345d55059945","name":"nette.ajax.js","description":"Flexible utility script for AJAX in Nette Framework. Supports snippets, redirects etc. http://addons.nette.org/cs/nette-ajax-js","dist-tags":{"latest":"2.3.0"},"versions":{"2.1.0":{"name":"nette.ajax.js","version":"2.1.0","description":"Flexible utility script for AJAX in Nette Framework. Supports snippets, redirects etc. http://addons.nette.org/cs/nette-ajax-js","main":"nette.ajax.js","repository":{"type":"git","url":"git+https://github.com/vojtech-dobes/nette.ajax.js.git"},"keywords":["nette","ajax","jquery"],"author":{"name":"Vojtech Dobes"},"license":"MIT","bugs":{"url":"https://github.com/vojtech-dobes/nette.ajax.js/issues"},"homepage":"https://github.com/vojtech-dobes/nette.ajax.js#readme","gitHead":"ed761cf3b93722f409f0f8c779669db9b8ca410b","_id":"nette.ajax.js@2.1.0","scripts":{},"_shasum":"1c469eb7dd2d979fb2b1b8117092695a76ae314f","_from":".","_npmVersion":"4.0.5","_nodeVersion":"7.3.0","_npmUser":{"name":"trejjam","email":"jan.trejbal@gmail.com"},"dist":{"shasum":"1c469eb7dd2d979fb2b1b8117092695a76ae314f","tarball":"https://registry.npmjs.org/nette.ajax.js/-/nette.ajax.js-2.1.0.tgz","integrity":"sha512-xAkjLNWRizQ4IapQvBKSWZDT4YcIjqZUij+AUuFTF9k9w9ykkby4vbHaEI6oU3VW9uztEn6HhqUi/cP2yapdPw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIGoCtb1WoBVTXyyxYDSH4HksX18YOMpxmhZAa/1Igr4eAiASMDD5UFysZzIWF0bB5xF1ogR/iY+g4S0DiZIXDPRvrA=="}]},"maintainers":[{"name":"trejjam","email":"jan.trejbal@gmail.com"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/nette.ajax.js-2.1.0.tgz_1482954992333_0.48104226938448846"}},"2.3.0":{"name":"nette.ajax.js","version":"2.3.0","description":"Flexible utility script for AJAX in Nette Framework. Supports snippets, redirects etc. http://addons.nette.org/cs/nette-ajax-js","main":"nette.ajax.js","repository":{"type":"git","url":"git+https://github.com/vojtech-dobes/nette.ajax.js.git"},"keywords":["nette","ajax","jquery"],"author":{"name":"Vojtech Dobes"},"license":"MIT","bugs":{"url":"https://github.com/vojtech-dobes/nette.ajax.js/issues"},"homepage":"https://github.com/vojtech-dobes/nette.ajax.js#readme","gitHead":"299903f97158084b06fcbaeb2a2db87b38eac68b","_id":"nette.ajax.js@2.3.0","scripts":{},"_shasum":"426752cb2a00988570ed70aa2bdc58d072cc0354","_from":".","_npmVersion":"4.2.0","_nodeVersion":"7.10.1","_npmUser":{"name":"trejjam","email":"jan.trejbal@gmail.com"},"dist":{"shasum":"426752cb2a00988570ed70aa2bdc58d072cc0354","tarball":"https://registry.npmjs.org/nette.ajax.js/-/nette.ajax.js-2.3.0.tgz","integrity":"sha512-yuWyy+Fkk3bgrNBLu+TyhKquws9GgmJNDQ9rUWZ3NE2Y0OznzG6V+TWF841JD3/VMIU3SXCclceos7oRlpxfbw==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICkIfnDZEeX7R72bOg7iz0LKm3LPTa4j9kUyLQCFV0eaAiEAjGQv9PejgtkrDt8lRH1btsbVT/v0441NbHePmmBV/hw="}]},"maintainers":[{"name":"trejjam","email":"jan.trejbal@gmail.com"},{"name":"vojtechdobes","email":"me@vojtechdobes.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/nette.ajax.js-2.3.0.tgz_1501670620527_0.953711093403399"}}},"readme":"## For Nette Framework\n\nFlexible utility script for AJAX. Supports snippets, redirects etc.\n\n#### License\n\nMIT\n\n#### Dependencies\n\njQuery 1.7\n\n## Installation\n\n1. Copy `nette.ajax.js` to your directory with Javascript files (you can use [Bower](http://bower.io/) for this).\n2. Link the file in your templates (usually in `app/@layout.latte`, after jQuery!).\n3. Put somewhere the initialization routine:\n\n```js\n$(function () {\n\t$.nette.init();\n});\n```\n\n## Usage\n\nBy defaults all links and forms with CSS class `ajax` will be instantly ajaxified. Behavior can be altered in configuration of `init` extension. Object returned by call `var init = $.nette.ext('init');` has these props:\n\n<table>\n\t<tr>\n\t\t<th>name</th>\n\t\t<th>default value</th>\n\t\t<th>description</th>\n\t</tr>\n\t<tr>\n\t\t<td><code>linkSelector</code></td>\n\t\t<td><code>a.ajax</code></td>\n\t\t<td>CSS selector for links</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>formSelector</code></td>\n\t\t<td><code>form.ajax</code></td>\n\t\t<td>CSS selector for forms</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>buttonSelector</code></td>\n\t\t<td><code>input.ajax[type=\"submit\"], input.ajax[type=\"image\"]</code></td>\n\t\t<td>CSS selector for form elements responsible for submit</td>\n\t</tr>\n</table>\n\nAjaxification is bound to `click` (`submit`) event in `nette` namespace. Ajaxification of specific link can be canceled with code like this (while other callbacks will remain):\n\n```js\n$('a.no-ajax').off('click.nette');\n```\n\nOr even simpler:\n\n```js\n$('a.no-ajax').netteAjaxOff();\n```\n\n## Extensions\n\nAjaxification envelopes standard `$.ajax()` call and extends it with several events, that can be hooked with custom callbacks. Set of associated callbacks is called **extension**. Snippets processing, ability to cancel running request by *Escape*... all this functionality is implemented in form of extensions. Registration of extension looks like this:\n\n```js\n$.nette.ext('name', {\n    event1: function () {\n    },\n    event2: ...\n}, {\n    // ... shared context (this) of all callbacks\n});\n```\n\nFirst argument is name. It's optional.\n\nSecond argument should be hash of callbacks with keys corresponding to names of events. These events are available:\n\n<table>\n\t<tr>\n\t\t<th>name</th>\n\t\t<th>arguments</th>\n\t\t<th>description</th>\n\t</tr>\n\t<tr>\n\t\t<td><code>init</code></td>\n\t\t<td></td>\n\t\t<td>Called just once during <code>$.nette.init();</code> call.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>load</code></td>\n\t\t<td><code>requestHandler</code></td>\n\t\t<td>Should contain ajaxification. <code>requestHandler</code> can be bound to UI events to initiate AJAX request.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>before</code></td>\n\t\t<td><code>jqXHR</code>, <code>settings</code></td>\n\t\t<td>Called immediatelly before AJAX request execution. If FALSE is returned, request won't start.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>start</code></td>\n\t\t<td><code>jqXHR</code>, <code>settings</code></td>\n\t\t<td>Called immediatelly after start of AJAX request.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>success</code></td>\n\t\t<td><code>payload</code>, <code>status</code>, <code>jqXHR</code>, <code>settings</code></td>\n\t\t<td>Called after successful completion of AJAX request. Equivalent to <code>$.ajax( ... ).done( ...</code>.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>complete</code></td>\n\t\t<td><code>jqXHR</code>, <code>status</code>, <code>settings</code></td>\n\t\t<td>Called after every AJAX request completion. Equivalent to <code>$.ajax( ... ).always( ...</code>.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>error</code></td>\n\t\t<td><code>jqXHR</code>, <code>status</code>, <code>error</code>, <code>settings</code></td>\n\t\t<td>Called in case of failure of AJAX request. Equivalent to <code>$.ajax( ... ).fail( ...</code>.</td>\n\t</tr>\n</table>\n\nExtension can be disabled:\n\n```js\n$.nette.ext('name', null);\n```\n\nExtension can be configured. Its context can be acquired by:\n\n```js\nvar context = $.nette.ext('name');\n```\n\n## Default extensions\n\n<table>\n\t<tr>\n\t\t<th>name</th>\n\t\t<th>description</th>\n\t</tr>\n\t<tr>\n\t\t<td><code>validation</code></td>\n\t\t<td>Limits the ajaxification to clicks/submits without <em>Ctrl</em>, <em>Alt</em> or <em>Shift</em> key, local links and valid form submits.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>forms</code></td>\n\t\t<td>Adds support for submitting forms with all data, name of clicked button and coordinates of click in <code>[type=image]</code> inputs.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>snippets</code></td>\n\t\t<td>Updates DOM by <code>snippets</code> array in response (default Nette handling of Latte snippets).</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>redirect</code></td>\n\t\t<td>Executes redirect to different URL (when <code>$this->redirect()</code> is called in presener). Can be replaced by <code>history</code> extension.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>unique</code></td>\n\t\t<td>Keeps only request running at the same moment.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>abort</code></td>\n\t\t<td>Allows user to abort running request by pressing <em>Escape</em>.</td>\n\t</tr>\n\t<tr>\n\t\t<td><code>init</code></td>\n\t\t<td>Default ajaxification.</td>\n\t</tr>\n</table>\n\n## Useful tricks\n\nAll these special features expect all default extensions to be on.\n\n### `data-ajax-off`\n\nLink or any other ajaxified element can have custom data attribute `data-ajax-off`. It contains names of extensions, that should be deactivated for Ajax request fired on element.\n\n```html\n<a n:href=\"do!\" class=\"ajax\" data-ajax-off=\"snippets\">\n```\n\nYou can also use it in `$.nette.ajax()`. Like this:\n\n```js\n$.nette.ajax({\n\turl: ...,\n\toff: ['snippets']\n});\n```\n\n### `data-ajax-pass` (in `validation` extension)\n\nAjaxification of element ensures, that `e.preventDefault()` will be called. This attribute can prevent it, if you need more callbacks to be fired.\n\n### `data-ajax-append` (in `snippets` extension)\n\nNew content of snippet with this attribute won't replace the old content, but it will rather be appended to it.\n\n### `data-ajax-prepend` (in `snippets` extension)\n\nNew content of snippet with this attribute won't replace the old content, but it will rather be prepended to it.\n\n### `data-ajax-validate` (in `validation` extension)\n\nClick on link or submittion of form is validated on various conditions. You can switch any of them:\n\n```html\n<a n:href=\"do!\" class=\"ajax\" data-ajax-validate='{\"keys\":false}'>\n```\n\nAnd as in case of `data-ajax-off`, you can pass it right into `$.nette.ajax()`.\n\n```js\n$.nette.ajax({\n\turl: ...,\n\tvalidate: {\n\t\tkeys: false\n\t}\n});\n```\n\nThis means that clicking link with Ctrl will not open new tab, but will ajaxify request.\n\n### Dependency on other extension\n\nIn event callbacks, you can call `this.ext()` to get context of other extension. If you add `true` as second argument, script will fail if that extension won't be available.\n\n```js\n$.nette.ext({\n\tsuccess: function (payload) {\n\t\tvar snippets = this.ext('snippets', true);\n\t\t...\n\t}\n});\n```\n","maintainers":[{"name":"trejjam","email":"jan.trejbal@gmail.com"},{"name":"vojtechdobes","email":"me@vojtechdobes.com"}],"time":{"modified":"2022-06-21T01:12:29.968Z","created":"2016-12-28T19:56:34.556Z","2.1.0":"2016-12-28T19:56:34.556Z","2.3.0":"2017-08-02T10:43:41.493Z"},"homepage":"https://github.com/vojtech-dobes/nette.ajax.js#readme","keywords":["nette","ajax","jquery"],"repository":{"type":"git","url":"git+https://github.com/vojtech-dobes/nette.ajax.js.git"},"author":{"name":"Vojtech Dobes"},"bugs":{"url":"https://github.com/vojtech-dobes/nette.ajax.js/issues"},"license":"MIT","readmeFilename":"readme.md","users":{"trejjam":true}}