Created
June 3, 2014 20:39
-
-
Save parris/c2bc5ceb013793bfe707 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}); | |
}; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(function(require) { | |
'use strict'; | |
var withStickitBase = require('./with_stickit_base_mixin'); | |
this.mixin( | |
withStickitBase, | |
options | |
); | |
this.after('render', function(){ | |
this.stickit(); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits: @parris, @mscheibe, @kevinastone, and @mralex