Skip to content

Instantly share code, notes, and snippets.

@owskio
Created July 31, 2014 18:13
Show Gist options
  • Save owskio/6e08c16368e5ff8baec5 to your computer and use it in GitHub Desktop.
Save owskio/6e08c16368e5ff8baec5 to your computer and use it in GitHub Desktop.
Chaining with both jquery and underscore functions simultaneously without an underscore context object
// ...
unQuery = function (fn) {
//Allows the usual context-style chaining
//but between all libraries.
return compose(flip(apply(fn)),arrayWrap);
},
// ...
$.fn.options = function (list) {
//PURPOSE: This plugin provides a useful
// abstraction for populating <select>
// lists when given an array of choices.
var $select = this,
markup = '<option value="{{v}}">{{v}}</option>',
option = template(markup),
empty = unQuery($.fn.empty),
css = unQuery($.fn.css),
appendTo = proxy($.fn.append);
return chain(
K($select),
empty(),
K(list),
map(function (item) {
return option({
v: item
})
}),
reduce(concat),
appendTo($select),
css('width',function (index,old) {
//For IE 9 only bug...thanks microsoft
//NOTE: 260px is arbitrary.
return old > 260 ? old : 260;
})
)();
};
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment