bullseye/app/assets/javascripts/bullseye.js.erb

61 lines
1.4 KiB
Plaintext
Raw Permalink Normal View History

this.Bullseye = {
2012-08-30 15:23:50 +00:00
target: function(controller, actions, callback) {
this.targets[controller] = (this.targets[controller] || {});
2012-08-30 15:23:50 +00:00
var actions_i;
for (actions_i = 0; actions_i < actions.length; ++actions_i) {
this.targets[controller][actions[actions_i]] = callback;
}
},
targets: {},
exec: function() {
var controller, action;
switch (arguments.length) {
case 2:
controller = arguments[0];
action = arguments[1];
break;
case 1:
choices = arguments[0];
choice_loop:
for (controller_i = 0; controller_i < choices.length; ++controller_i) {
controller = choices[controller_i];
if (this.targets[controller]) {
for (action_i = 0; action_i < choices.length; ++action_i) {
action = choices[action_i];
if (this.targets[controller][action]) {
break choice_loop;
}
}
}
}
break;
}
2012-09-22 01:05:27 +00:00
controller = controller.replace('/', '-');
if (this.targets[controller] && this.targets[controller][action]) {
this.targets[controller][action].apply(this.context);
}
}
};
Bullseye.context = this;
$(function() {
Bullseye.exec(
<% if Bullseye.config.fuzzy_search %>
<%= Bullseye.config.fuzzy_search %>
<% else %>
<%= Bullseye.config.js_controller_search %>,
<%= Bullseye.config.js_action_search %>
<% end %>
);
});