Skip to content

Commit 6145c31

Browse files
committed
add many events for plugins
1 parent d17ba97 commit 6145c31

File tree

4 files changed

+283
-171
lines changed

4 files changed

+283
-171
lines changed

Gruntfile.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ module.exports = function(grunt) {
5858
grunt.fail.warn('Lang '+ arg_lang +' unknown');
5959
}
6060
}
61-
62-
grunt.log.writeln('Merged files: ['+ files_to_load.join(', ') +']');
6361

6462

6563
grunt.initConfig({
@@ -176,10 +174,7 @@ module.exports = function(grunt) {
176174
jshint: {
177175
lib: {
178176
files: {
179-
src: [
180-
'src/query-builder.js',
181-
'src/query-builder-sql-support.js'
182-
]
177+
src: ['src/query-builder.js'].concat(files_to_load)
183178
}
184179
}
185180
},
@@ -210,6 +205,39 @@ module.exports = function(grunt) {
210205
grunt.file.write(path, modules.join('\n\n'));
211206
grunt.log.writeln('Built "' + path + '".');
212207
});
208+
209+
// list the triggers and changes in core code
210+
grunt.registerTask('describe_triggers', '', function() {
211+
var triggers = {};
212+
213+
core = grunt.file.read('src/query-builder.js').split('\n').forEach(function(line, i) {
214+
var matches = /(?:this|that)\.(trigger|change)\('(\w+)'[^)]*\);/.exec(line);
215+
if (matches !== null) {
216+
triggers[matches[2]] = triggers[matches[2]] || {
217+
name: matches[2],
218+
type: matches[1],
219+
usages: []
220+
};
221+
222+
triggers[matches[2]].usages.push([i, matches[0].slice(0,-1)]);
223+
}
224+
});
225+
226+
grunt.log.writeln('\nTriggers in QueryBuilder ' + grunt.template.process('<%= pkg.version %>') + ' :\n');
227+
228+
for (var t in triggers) {
229+
grunt.log.write((triggers[t].name)['cyan']);
230+
grunt.log.writeln(' (' + triggers[t].type + ')');
231+
232+
triggers[t].usages.forEach(function(line) {
233+
grunt.log.write('+-- ');
234+
grunt.log.write((':' + line[0])['red']);
235+
grunt.log.writeln(' ' + line[1]);
236+
});
237+
238+
grunt.log.write('\n');
239+
}
240+
});
213241

214242
grunt.loadNpmTasks('grunt-contrib-uglify');
215243
grunt.loadNpmTasks('grunt-contrib-copy');

src/plugins/bt-selectpicker.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*!
2+
* jQuery QueryBuilder Bootstrap Selectpicker
3+
* Copyright 2014-2015 Damien "Mistic" Sorel (http://www.strangeplanet.fr)
4+
* Licensed under MIT (http://opensource.org/licenses/MIT)
5+
*/
6+
7+
(function($){
8+
"use strict";
9+
10+
$.fn.queryBuilder.define('bt-selectpicker', function(options) {
11+
if (!$.fn.selectpicker || !$.fn.selectpicker.Constructor) {
12+
$.error('Bootstrap Select is required to use "bt-selectpicker" plugin. Get it here: http://silviomoreto.github.io/bootstrap-select');
13+
}
14+
15+
options = $.extend({
16+
container: 'body',
17+
style: 'btn-inverse btn-xs',
18+
width: 'auto',
19+
showIcon: false
20+
}, options || {});
21+
22+
// init selectpicker on filters
23+
this.on('afterAddRule', function($rule) {
24+
$rule.find('.rule-filter-container select').selectpicker(options);
25+
});
26+
27+
// init selectpicker on operators
28+
this.on('afterCreateRuleOperators', function($rule) {
29+
$rule.find('.rule-operator-container select').selectpicker(options);
30+
});
31+
});
32+
33+
}(jQuery));

src/plugins/bt-tooltip-errors.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,21 @@
88
"use strict";
99

1010
$.fn.queryBuilder.define('bt-tooltip-errors', function(options) {
11+
if (!$.fn.tooltip || !$.fn.tooltip.Constructor || !$.fn.tooltip.Constructor.prototype.fixTitle) {
12+
$.error('Bootstrap Tooltip is required to use "bt-tooltip-errors" plugin. Get it here: http://getbootstrap.com');
13+
}
14+
1115
options = $.extend({
1216
placement: 'right'
1317
}, options || {});
1418

1519
// add BT Tooltip data
16-
this.on('rule-template', function(h) {
20+
this.on('ruleTemplate', function(h) {
1721
return h.replace('class="error-container"', 'class="error-container" data-toggle="tooltip"');
1822
});
1923

2024
// init/refresh tooltip when title changes
21-
this.on('rule-error', function($target, error) {
25+
this.on('validationError', function($target) {
2226
$target.find('.error-container').eq(0)
2327
.tooltip(options)
2428
.tooltip('hide')

0 commit comments

Comments
 (0)