-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlodash.dom-traverse.min.js
1 lines (1 loc) · 3.2 KB
/
lodash.dom-traverse.min.js
1
!function(){"use strict";function a(a){return _.chain(this).map(a).compact().value()}function b(b){return this._update(a.call(this,b))}function c(a){return(_.indexOf(this.parentNode.children,this)-(a?1:0))%2}function d(a,b){return(b-a)%2}function e(a){return this._update(_.chain(this).map(function(b){for(var c,d=[];(c=_.$(b)[a]())&&(b=c[0]);)d.push(c);return d}).flatten().value())}function f(a){return function(){return a.call(this)}}function g(a){return i(a)?_.chain(a.split(";")).map(function(a){return a=a.split(":"),{prop:i(a[0]),value:i(a[1])}}).indexBy("prop").mapValues("value").value():{}}function h(a){return _.chain(a).pairs().invoke("join",":").value().join(";")}function i(a){return a.replace(/^\s+|\s+$/,"")}function j(a,b){return new j.prototype.Init(a,b)}function k(a,b){return this.length=0,"string"==typeof a?(b=b||document,_.each(b.querySelectorAll(a),_.bind(this._push,this))):this._push(a),this}var l=function(){return document.body.previousElementSibling?function(a){return b.call(this,function(b){return b[a+"ElementSibling"]})}:function(a){return b.call(this,function(b){do b=b[a+"Sibling"];while(b&&1!==b.nodeType);return b})}}(),m=_.partial(l,"next"),n=_.partial(l,"previous"),o=_.partial(e,"next"),p=_.partial(e,"prev"),q=function(){return window.getComputedStyle?function(a,b){return b=b.replace(/([A-Z])/g,"-$1").toLowerCase(),getComputedStyle(a,null).getPropertyValue(b)}:function(a,b){b=b.replace(/\-(\w)/g,function(a,b){return b.toUpperCase()});var c=a.currentStyle[b];return/^\d+(em|pt|%|ex)?$/i.test(c)?function(b){var c=a.style.left,d=a.runtimeStyle.left;return a.runtimeStyle.left=a.currentStyle.left,a.style.left=b||0,b=a.style.pixelLeft+"px",a.style.left=c,a.runtimeStyle.left=d,b}(c):c}}();j.prototype={constructor:j,_push:function(a){a&&[].push.call(this,a)},_clean:function(){if([].splice.call(this,0,this.length),"0"in this)for(var a in this)this.hasOwnProperty(a)&&delete this[a]},_update:function(a){return this._clean(),_.each(a,_.bind(this._push,this)),this},Init:k,find:function(a){return this._update(_.chain(this).map(function(b){return _.chain(a).$(b).toArray().value()}).flatten().value())},filter:function(a){return this._update(_.filter(this,function(b,c){return _.isString(a)?_.$(b).is(a):_.bind(a,b)(c)}))},siblings:function(){var a=_.chain(this).map(function(a){return _.reject(a.parentNode.children,function(b){return b===a})}).flatten().uniq().value();return this._update(a)},next:f(m),prev:f(n),nextAll:f(o),prevAll:f(p),text:function(a){var c="textContent"in this[0]?"textContent":"innerText";return b.call(this,function(b){return a?(b[c]=a,b):b[c]})},is:function(a){var b=this[0],c=b.matches||b.matchesSelector||b.msMatchesMatchesSelector||b.mozMatchesMatchesSelector||b.webkitMatchesSelector||b.oMatchesSelector;return _.every(this,function(b){return c?c.call(b,a):~_.chain(a).$(b.parentNode).indexOf(b).value()})},closest:function(a){return b.call(this,function(b){for(var c;(c=b.parentNode)&&!_.$(c).is(a);)b=c;return c})},css:function(a){return _.isString(a)?q(this[0],a):(_.each(this,function(b){b.style.cssText=h(_.merge(g(b.style.cssText.replace(/;$/,"")),a))}),this)}},k.prototype=j.prototype,j.even=_.partial(c,0),j.odd=_.partial(c,1),j.simpleEven=_.partial(d,0),j.simpleOdd=_.partial(d,1),_.mixin({$:j})}();