PrimefacesQuery.js
/**
* @author redcrow
* create 20/05/2014
* code http://na5cent.blogspot.com/2014/05/primefaces-query-widgetvar-by-css.html
*/
PrimefacesQuery = (function(global) {
function forEachProperty(object, callback, ctx) {
for (var prop in object) {
if (object.hasOwnProperty(prop)) {
callback.call(ctx, object[prop], prop, object);
}
}
}
function getWidgetVar(classSelector) {
var list = [];
forEachProperty(global, function(value) {
is(value, classSelector) && list.push(value);
});
return list;
}
function is(object, classSelector) {
try{
return object && object.jq
&& object.jq.attr
&& object.jq.attr('class')
&& object.jq.attr('class').indexOf(classSelector) !== -1;
}catch(e){ //protect security policy for accessing some object, can't access by external script
return false;
}
}
return {
/**
* @param {String} classSelector - css class selector (of widgetVar) such as 'ui-dialog'
* @returns {Array} array of widgetVar objects
*/
queryWidgetVar: function(classSelector) {
return getWidgetVar(classSelector);
}
};
})(window);
Example to use//multiple widget dialogs
var widgetVarDialogs = PrimefacesQuery.queryWidgetVar('ui-dialog');
//
ไม่มีความคิดเห็น:
แสดงความคิดเห็น