Skip to content

Commit

Permalink
Adding loadOnce to Ajax delegator.
Browse files Browse the repository at this point in the history
  • Loading branch information
anutron committed May 2, 2013
1 parent 46554f9 commit 781a763
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Docs/Delegators/Delegator.Ajax.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ The above example will load the response from the links HREF (`get/list/item.php
* action - (*string*; optional) - the action to take on the target. Any of the options described below.
* method - (*string*; optional) - the HTML verb to use; defaults to `get`.
* filter - (*string*; optional) - a selector to run against the response whose response will be used to update the DOM instead of the full response.
* loadOnce - (*boolean*; optional) - if `true`, the link will only load content into its target once. Subsequent clicks are ignored (a console warning is displayed).

### Actions

Expand Down
5 changes: 5 additions & 0 deletions Source/Delegators/Delegator.Ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Delegator.register('click', 'Ajax', {
method: 'get'
},
handler: function(event, link, api){
if (api.getAs(Boolean, 'loadOnce') === true && link.retrieve('ajaxLoaded')){
api.warn('already loaded link via ajax. `once` option is true, so exiting quietly.');
return;
}
var target,
action = api.get('action'),
selector = api.get('target');
Expand Down Expand Up @@ -73,5 +77,6 @@ Delegator.register('click', 'Ajax', {
}
})
).send();
link.store('ajaxLoaded', true);
}
});

0 comments on commit 781a763

Please sign in to comment.