Skip to content

Instantly share code, notes, and snippets.

@markbrown4
Forked from anonymous/Controls.js
Created April 12, 2011 04:40
Show Gist options
  • Save markbrown4/914937 to your computer and use it in GitHub Desktop.
Save markbrown4/914937 to your computer and use it in GitHub Desktop.
var Controls = {
init: function (container) {
// Matches "control-something"
var typeRegex = /control-([a-z0-9\-]+)(\s|$)/i;
container.select('.init').each(function (el) {
var control_name = typeRegex.exec(el.className)[1].camelize().ucfirst();
try {
this.createnewControl(control_name, el);
}
catch (ex) {
alert('Could not load control ' + control_name + ': ' + ex);
}
}, this);
}
};
Controls.Base = Class.create({
container: null,
defaults: {},
settings: null,
initialize: function (container, settings) {
this.container = container;
this.settings = Util.extend(this.defaults, settings || {});
this.container.Control = this;
}
});
var Page = {
debug: false,
init: function (container) {
container = $(container || document.body);
Controls.init(container);
},
loadPartial: function (container, url, options) {
options = Util.extend({
method: 'get',
onSuccess: function (xhr) {
container.innerHTML = xhr.responseText;
Page.init(container);
},
onFailure: function (xhr) {
container.innerHTML = Util.translate('PARTIAL_PAGE_UPDATE_FAILURE');
}
}, options);
new Ajax.Request(url, options);
}
}
document.observe('dom:loaded', function () {
Page.init();
});
Controls.AwesomeSearch = Class.create(Controls.Base, {
defaults: {
minChars: 3,
delay: 250,
actions: {}
},
initialize: function ($super, container, settings) {
$super(container, settings);
this.searchInput = container.select('.searchInput')[0];
this.searchInput.observe('keydown', this.keydown.bind(this));
},
keydown: function (e) {
// do something
}
});
/* example HTML
* <div class="control-awesome-search init">
* <input class="searchInput">
* </div>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment