Skip to content

Make Utils.defineModelProperties() accessible for plugins #608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
7 changes: 7 additions & 0 deletions src/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ $.fn.queryBuilder.extend = QueryBuilder.extend;
*/
$.fn.queryBuilder.define = QueryBuilder.define;

/**
* @function
* @memberof external:"jQuery.fn"
* @see Utils.defineModelPropertiesByString
*/
$.fn.queryBuilder.defineModelPropertiesByString = Utils.defineModelPropertiesByString;

/**
* @function
* @memberof external:"jQuery.fn"
Expand Down
17 changes: 17 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,20 @@ Utils.defineModelProperties = function(obj, fields) {
});
});
};

/**
* Defines properties on an Node prototype with getter and setter.<br>
* Update events are emitted in the setter through root Model (if any).<br>
* The object must have a `__` object, non enumerable property to store values.
* @param {string} modelName
* one of Model, Node, Group, Rule
* @param {string[]} fields
*/
Utils.defineModelPropertiesByString = function(modelName, fields) {
// Allowing eval here only because the allowed values are very strict
if (['Model', 'Node', 'Group', 'Rule'].indexOf(modelName) !== -1) {
/*jshint evil:true */
var obj = eval(modelName);
return Utils.defineModelProperties(obj, fields);
}
};