Created
July 31, 2014 18:13
-
-
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
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
// ... | |
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