Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions doc/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,35 @@ Triggered when a new page is about to be loaded from the server.

The load event object contains the following properties.

| property | type | description |
|-----------|---------------|-------------------------|
| event.url | string | url that will be loaded |
| property | type | description |
|-------------------|--------|--------------------------------------------------------------------------------|
| event.url | string | url that will be loaded |
| event.ajaxOptions | object | options that are passed to [$.ajax method](http://api.jquery.com/jquery.ajax/) |

Using this event it is possible to change the requested url. This can be useful to append an arbitrary parameter to the requested url so the server can handle the request differently. For example to optimize the returned html by stripping everything outside the container element (header, footer, etc.).

```javascript
ias.on('load', function(event) {
event.url = event.url + "?ajax=1";

// alternatively...
event.ajaxOptions.data = { ajax: 1 };
})
```

The ajaxOptions property can also be used for more exotic configurations.

```javascript
ias.on('load', function(event) {
// A more exotic example, timeout and HTTP auth
event.timeout = 7000; //ms
event.username = 'shirley';
event.password = 'temple';
})
```

See http://api.jquery.com/jquery.ajax/ for a complete list of options.

### loaded

| argument | type | description |
Expand Down
12 changes: 9 additions & 3 deletions src/jquery-ias.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,15 @@
delay = delay || this.defaultDelay;

var loadEvent = {
url: url
url: url,
ajaxOptions: {
dataType: 'html'
}
};

self.fire('load', [loadEvent]);

this.jsXhr = $.get(loadEvent.url, null, $.proxy(function(data) {
function xhrDoneCallback(data) {
$itemContainer = $(this.itemsContainerSelector, data).eq(0);
if (0 === $itemContainer.length) {
$itemContainer = $(data).filter(this.itemsContainerSelector).eq(0);
Expand All @@ -211,7 +214,10 @@
callback.call(self, data, items);
}
}
}, self), 'html');
}

this.jsXhr = $.ajax(loadEvent.url, loadEvent.ajaxOptions)
.done($.proxy(xhrDoneCallback, self));

return this.jsXhr;
};
Expand Down