Skip to content

Instantly share code, notes, and snippets.

@parris
Created June 3, 2014 20:39
Show Gist options
  • Save parris/c2bc5ceb013793bfe707 to your computer and use it in GitHub Desktop.
Save parris/c2bc5ceb013793bfe707 to your computer and use it in GitHub Desktop.
define(function(require) {
'use strict';
require('stickit');
return function(options){
// NOTE: this assumes inputs
var bindingDefaults = {
events: ['blur', 'paste', 'change'],
onSet: 'onSet'
};
this.after('initialize', function(){
var bindings = (options && options.bindings) || this.bindings;
if (!bindings) {
throw new Error('Bindings missing');
}
// Take selector: 'field_name' bindings
// and have them use our default binding config
// Leaves selector :{} ones alone
_.each(_.keys(bindings), function(selector){
var binding = bindings[selector];
if (_.isString(binding)) {
binding = _.extend({
observe: binding
}, bindingDefaults);
bindings[selector] = binding;
}
});
this.bindings = bindings;
});
this.setDefaults({
// bindings: options.bindings,
// No-op to be overridden/wrapped
onSet: function(val, options){
return val;
}
});
};
});
define(function(require) {
'use strict';
var withStickitBase = require('./with_stickit_base_mixin');
this.mixin(
withStickitBase,
options
);
this.before('onRender', function(){
this.stickit();
});
this.after('onShow', function(){
this.stickit();
});
});
define(function(require) {
'use strict';
var withStickitBase = require('./with_stickit_base_mixin');
this.mixin(
withStickitBase,
options
);
this.after('render', function(){
this.stickit();
});
});
@parris
Copy link
Author

parris commented Jun 3, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment