Advertisement
Guest User

Example usage of jQuery policy

a guest
Nov 14th, 2013
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 0.96 KB | None | 0 0
  1. // adding custom operators
  2. $.policy.addOperator('defined', function(data, check) {
  3.   return typeof data != 'undefined';
  4. });
  5. $.policy.addOperator('longer_than', function(data, check) {
  6.   return data && data.hasOwnProperty('length') && data.length > check;
  7. });
  8.  
  9. // add some policies
  10. $.policy.add('name.longer_than', 10);
  11. $('#our_people').find('.person').policy('in_set'); // our people with names longer than 10 characters
  12. $('#our_people').find('.person').policy('not_in_set'); // our people with names shorter than 10 characters
  13.  
  14. // we can also namespace policies
  15. $.policy.add('price.gteq', 25000, 'price_between_25_50k');
  16. $.policy.add('price.lteq', 50000, 'price_between_25_50k');
  17. $('li.products').policy('in_set', 'price_between_25_50k'); // all products with data-price between
  18.                                                            // 25,000 and 50,000 (inclusive)
  19. $('li.products').policy('not_in_set', 'price_between_25_50k'); // all the rest of the products
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement