Last active
December 14, 2015 08:09
-
-
Save lushchick/5056143 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var origBind = rivets.binders['each-*'].bind, | |
col = { attr: 'data-col', idx: 0 }, | |
dataKey = 'rivetsEachData'; | |
/** | |
* Patch bind method to auto-refresh re-bound data | |
* | |
* @todo: remove it when this is fixed in Rivets: | |
* https://github.com/mikeric/rivets/issues/118 | |
* | |
* @param el | |
* @param collection | |
* @return {Object} | |
*/ | |
rivets.binders['each-*'].bind = function(el, collection) { | |
var $el = $(el), data = {}, | |
attrName = ['data', rivets.config.prefix, this.type].join('-').replace('--', '-'); | |
data[attrName] = $el.attr(attrName); | |
$el.data(dataKey, data); | |
if ($el.attr(col.attr) === undefined) { | |
$el.attr(col.attr, col.idx++); | |
} | |
return origBind.apply(this, Array.prototype.slice.call(arguments)); | |
}; | |
/** | |
* Patch unbind method to clear previously bound data and turn DOM | |
* into the original state (with all data- attributes) | |
* | |
* @todo: remove it when this is fixed in Rivets | |
* https://github.com/mikeric/rivets/issues/118 | |
* | |
* @param el | |
* @param collection | |
*/ | |
rivets.binders['each-*'].unbind = function(el, collection) { | |
var $el = $(el), | |
attr = $el.attr(col.attr); | |
$el.attr($el.data(dataKey)); | |
$('[' + col.attr + ']', this.marker.parentNode) | |
.filter(function() { | |
return $(this).attr(col.attr) === attr; | |
}) | |
.first().before(el).end().remove(); | |
$(this.marker).remove(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You may put it somewhere before you initialize adapters using rivets.configure (say, after you include rivets.js into your page)