1 if (!window.RichFaces) { 2 window.RichFaces = {}; 3 } 4 5 (function($, rf) { 6 7 rf.ui = rf.ui || {}; 8 9 var evaluate = function(selector) { 10 var result = selector; 11 try { 12 result = eval(selector); 13 } catch (e) { 14 //do nothing 15 } 16 return result; 17 }; 18 19 var evaluateJQuery = function(element, selector) { 20 var result = element || evaluate(selector); 21 if (!(result instanceof $)) { 22 result = $(result || ""); 23 } 24 25 return result; 26 }; 27 28 var createEventHandlerFunction = function(opts) { 29 return function() { 30 var selector = evaluateJQuery(null, opts.selector); 31 selector[opts.attachType || "bind"](opts.event, null, new Function("event", opts.query)); 32 }; 33 }; 34 35 var createDirectQueryFunction = function(opts) { 36 var queryFunction = new Function("options", "arguments[1]." + opts.query); 37 38 return function() { 39 var element; 40 var options; 41 42 if (arguments.length == 1) { 43 if (!opts.selector) { 44 //if selector is not present take selector as default 45 element = arguments[0]; 46 }else{ 47 //if selector is allready presen from rich jQuery component take options as default. 48 options = arguments[0]; 49 } 50 51 } else { 52 //function(element, options) { ...query()... } 53 element = arguments[0]; 54 options = arguments[1]; 55 } 56 57 var selector = evaluateJQuery(element, opts.selector); 58 queryFunction.call(this, options, selector); 59 }; 60 }; 61 62 var createQueryFunction = function(options) { 63 if (options.event) { 64 return createEventHandlerFunction(options); 65 } else { 66 return createDirectQueryFunction(options); 67 } 68 }; 69 70 var query = function(options) { 71 if (options.timing == 'immediate') { 72 createQueryFunction(options).call(this); 73 } else { 74 $(document).ready(createQueryFunction(options)); 75 } 76 }; 77 78 rf.ui.jQueryComponent = { 79 80 createFunction: createQueryFunction, 81 82 query: query 83 84 }; 85 86 }(RichFaces.jQuery, RichFaces)); 87