mutationobserver-shim
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -1,9 +0,10 @@ | ||
// mutationobserver-shim v0.3.1 (github.com/megawac/MutationObserver.js) | ||
// mutationobserver-shim v0.3.2 (github.com/megawac/MutationObserver.js) | ||
// Authors: Graeme Yeates (github.com/megawac) | ||
window.MutationObserver=window.MutationObserver||window.WebKitMutationObserver||function(r){function w(a){this.g=[];this.k=a}function H(a){(function c(){var d=a.takeRecords();d.length&&a.k(d,a);a.f=setTimeout(c,w._period)})()}function t(a){var b={type:null,target:null,addedNodes:[],removedNodes:[],previousSibling:null,nextSibling:null,attributeName:null,attributeNamespace:null,oldValue:null},c;for(c in a)b[c]!==r&&a[c]!==r&&(b[c]=a[c]);return b}function I(a,b){var c=B(a,b);return function(d){var g= | ||
d.length,n;b.a&&c.a&&A(d,a,c.a,b.d);if(b.b||b.e)n=J(d,a,c,b);if(n||d.length!==g)c=B(a,b)}}function A(a,b,c,d){for(var g={},n=b.attributes,h,m,C=n.length;C--;)h=n[C],m=h.name,d&&d[m]===r||(h.value!==c[m]&&a.push(t({type:"attributes",target:b,attributeName:m,oldValue:c[m],attributeNamespace:h.namespaceURI})),g[m]=!0);for(m in c)g[m]||a.push(t({target:b,type:"attributes",attributeName:m,oldValue:c[m]}))}function J(a,b,c,d){function g(b,c,g,h,y){var r=b.length-1;y=-~((r-y)/2);for(var f,k,e;e=b.pop();)f= | ||
g[e.h],k=h[e.i],d.b&&y&&Math.abs(e.h-e.i)>=r&&(a.push(t({type:"childList",target:c,addedNodes:[f],removedNodes:[f],nextSibling:f.nextSibling,previousSibling:f.previousSibling})),y--),d.a&&k.a&&A(a,f,k.a,d.d),d.c&&3===f.nodeType&&f.nodeValue!==k.c&&a.push(t({type:"characterData",target:f})),d.e&&n(f,k)}function n(b,c){for(var x=b.childNodes,p=c.b,y=x.length,w=p?p.length:0,f,k,e,l,u,z=0,v=0,q=0;v<y||q<w;)l=x[v],u=(e=p[q])&&e.j,l===u?(d.a&&e.a&&A(a,l,e.a,d.d),d.c&&e.c!==r&&l.nodeValue!==e.c&&a.push(t({type:"characterData", | ||
target:l})),k&&g(k,b,x,p,z),d.e&&(l.childNodes.length||e.b&&e.b.length)&&n(l,e),v++,q++):(h=!0,f||(f={},k=[]),l&&(f[e=D(l)]||(f[e]=!0,-1===(e=E(p,l,q,"j"))?d.b&&(a.push(t({type:"childList",target:b,addedNodes:[l],nextSibling:l.nextSibling,previousSibling:l.previousSibling})),z++):k.push({h:v,i:e})),v++),u&&u!==x[v]&&(f[e=D(u)]||(f[e]=!0,-1===(e=E(x,u,v))?d.b&&(a.push(t({type:"childList",target:c.j,removedNodes:[u],nextSibling:p[q+1],previousSibling:p[q-1]})),z--):k.push({h:e,i:q})),q++));k&&g(k,b, | ||
x,p,z)}var h;n(b,c);return h}function B(a,b){var c=!0;return function g(a){var h={j:a};!b.c||3!==a.nodeType&&8!==a.nodeType?(b.a&&c&&1===a.nodeType&&(h.a=F(a.attributes,function(a,c){if(!b.d||b.d[c.name])a[c.name]=c.value;return a})),c&&(b.b||b.c||b.a&&b.e)&&(h.b=K(a.childNodes,g)),c=b.e):h.c=a.nodeValue;return h}(a)}function D(a){try{return a.id||(a.mo_id=a.mo_id||G++)}catch(b){try{return a.nodeValue}catch(c){return G++}}}function K(a,b){for(var c=[],d=0;d<a.length;d++)c[d]=b(a[d],d,a);return c} | ||
function F(a,b){for(var c={},d=0;d<a.length;d++)c=b(c,a[d],d,a);return c}function E(a,b,c,d){for(;c<a.length;c++)if((d?a[c][d]:a[c])===b)return c;return-1}w._period=30;w.prototype={observe:function(a,b){for(var c={a:!!(b.attributes||b.attributeFilter||b.attributeOldValue),b:!!b.childList,e:!!b.subtree,c:!(!b.characterData&&!b.characterDataOldValue)},d=this.g,g=0;g<d.length;g++)d[g].m===a&&d.splice(g,1);b.attributeFilter&&(c.d=F(b.attributeFilter,function(a,b){a[b]=!0;return a}));d.push({m:a,l:I(a, | ||
c)});this.f||H(this)},takeRecords:function(){for(var a=[],b=this.g,c=0;c<b.length;c++)b[c].l(a);return a},disconnect:function(){this.g=[];clearTimeout(this.f);this.f=null}};var G=1;return w}(void 0); | ||
window.MutationObserver=window.MutationObserver||function(w){function v(a){this.i=[];this.m=a}function I(a){(function c(){var d=a.takeRecords();d.length&&a.m(d,a);a.h=setTimeout(c,v._period)})()}function p(a){var b={type:null,target:null,addedNodes:[],removedNodes:[],previousSibling:null,nextSibling:null,attributeName:null,attributeNamespace:null,oldValue:null},c;for(c in a)b[c]!==w&&a[c]!==w&&(b[c]=a[c]);return b}function J(a,b){var c=C(a,b);return function(d){var f=d.length,n;b.a&&3===a.nodeType&& | ||
a.nodeValue!==c.a&&d.push(new p({type:"characterData",target:a,oldValue:c.a}));b.b&&c.b&&A(d,a,c.b,b.f);if(b.c||b.g)n=K(d,a,c,b);if(n||d.length!==f)c=C(a,b)}}function L(a,b){return b.value}function M(a,b){return"style"!==b.name?b.value:a.style.cssText}function A(a,b,c,d){for(var f={},n=b.attributes,k,g,x=n.length;x--;)k=n[x],g=k.name,d&&d[g]===w||(D(b,k)!==c[g]&&a.push(p({type:"attributes",target:b,attributeName:g,oldValue:c[g],attributeNamespace:k.namespaceURI})),f[g]=!0);for(g in c)f[g]||a.push(p({target:b, | ||
type:"attributes",attributeName:g,oldValue:c[g]}))}function K(a,b,c,d){function f(b,c,f,k,y){var g=b.length-1;y=-~((g-y)/2);for(var h,l,e;e=b.pop();)h=f[e.j],l=k[e.l],d.c&&y&&Math.abs(e.j-e.l)>=g&&(a.push(p({type:"childList",target:c,addedNodes:[h],removedNodes:[h],nextSibling:h.nextSibling,previousSibling:h.previousSibling})),y--),d.b&&l.b&&A(a,h,l.b,d.f),d.a&&3===h.nodeType&&h.nodeValue!==l.a&&a.push(p({type:"characterData",target:h,oldValue:l.a})),d.g&&n(h,l)}function n(b,c){for(var g=b.childNodes, | ||
q=c.c,x=g.length,v=q?q.length:0,h,l,e,m,t,z=0,u=0,r=0;u<x||r<v;)m=g[u],t=(e=q[r])&&e.node,m===t?(d.b&&e.b&&A(a,m,e.b,d.f),d.a&&e.a!==w&&m.nodeValue!==e.a&&a.push(p({type:"characterData",target:m,oldValue:e.a})),l&&f(l,b,g,q,z),d.g&&(m.childNodes.length||e.c&&e.c.length)&&n(m,e),u++,r++):(k=!0,h||(h={},l=[]),m&&(h[e=E(m)]||(h[e]=!0,-1===(e=F(q,m,r,"node"))?d.c&&(a.push(p({type:"childList",target:b,addedNodes:[m],nextSibling:m.nextSibling,previousSibling:m.previousSibling})),z++):l.push({j:u,l:e})), | ||
u++),t&&t!==g[u]&&(h[e=E(t)]||(h[e]=!0,-1===(e=F(g,t,u))?d.c&&(a.push(p({type:"childList",target:c.node,removedNodes:[t],nextSibling:q[r+1],previousSibling:q[r-1]})),z--):l.push({j:e,l:r})),r++));l&&f(l,b,g,q,z)}var k;n(b,c);return k}function C(a,b){var c=!0;return function f(a){var k={node:a};!b.a||3!==a.nodeType&&8!==a.nodeType?(b.b&&c&&1===a.nodeType&&(k.b=G(a.attributes,function(c,f){if(!b.f||b.f[f.name])c[f.name]=D(a,f);return c})),c&&(b.c||b.a||b.b&&b.g)&&(k.c=N(a.childNodes,f)),c=b.g):k.a= | ||
a.nodeValue;return k}(a)}function E(a){try{return a.id||(a.mo_id=a.mo_id||H++)}catch(b){try{return a.nodeValue}catch(c){return H++}}}function N(a,b){for(var c=[],d=0;d<a.length;d++)c[d]=b(a[d],d,a);return c}function G(a,b){for(var c={},d=0;d<a.length;d++)c=b(c,a[d],d,a);return c}function F(a,b,c,d){for(;c<a.length;c++)if((d?a[c][d]:a[c])===b)return c;return-1}v._period=30;v.prototype={observe:function(a,b){for(var c={b:!!(b.attributes||b.attributeFilter||b.attributeOldValue),c:!!b.childList,g:!!b.subtree, | ||
a:!(!b.characterData&&!b.characterDataOldValue)},d=this.i,f=0;f<d.length;f++)d[f].s===a&&d.splice(f,1);b.attributeFilter&&(c.f=G(b.attributeFilter,function(a,b){a[b]=!0;return a}));d.push({s:a,o:J(a,c)});this.h||I(this)},takeRecords:function(){for(var a=[],b=this.i,c=0;c<b.length;c++)b[c].o(a);return a},disconnect:function(){this.i=[];clearTimeout(this.h);this.h=null}};var B=document.createElement("i");B.style.top=0;var D=(B="null"!=B.attributes.style.value)?L:M,H=1;return v}(void 0); | ||
//# sourceMappingURL=mutationobserver.map |
@@ -5,4 +5,4 @@ ###Compiled files | ||
- Original: 23.2 kB | ||
- Minified: 3.4 kB | ||
- Gzipped: 788 bytes | ||
- Original: 25 kB | ||
- Minified: 3.7 kB | ||
- Gzipped: 1.6 kB |
@@ -15,4 +15,5 @@ /*! | ||
- https://bugzilla.mozilla.org/show_bug.cgi?id=749920 | ||
* Don't use WebKitMutationObserver as Safari (6.0.5-6.1) use a buggy implementation | ||
*/ | ||
window.MutationObserver = window.MutationObserver || window.WebKitMutationObserver || (function(undefined) { | ||
window.MutationObserver = window.MutationObserver || (function(undefined) { | ||
"use strict"; | ||
@@ -80,3 +81,4 @@ /** | ||
// some browsers are strict in their implementation that config.subtree and childList must be set together. We don't care - spec doesn't specify | ||
// some browsers enforce that subtree must be set with childList, attributes or characterData. | ||
// We don't care as spec doesn't specify this rule. | ||
kids: !! config.childList, | ||
@@ -185,2 +187,10 @@ descendents: !! config.subtree, | ||
if (config.charData && $target.nodeType === 3 && $target.nodeValue !== $oldstate.charData) { | ||
mutations.push(new MutationRecord({ | ||
type: "characterData", | ||
target: $target, | ||
oldValue: $oldstate.charData | ||
})); | ||
} | ||
// Alright we check base level changes in attributes... easy | ||
@@ -206,3 +216,37 @@ if (config.attr && $oldstate.attr) { | ||
// Check if the environment has the attribute bug (#4) which cause | ||
// element.attributes.style to always be null. | ||
var hasAttributeBug = document.createElement("i"); | ||
hasAttributeBug.style.top = 0; | ||
hasAttributeBug = hasAttributeBug.attributes.style.value != "null"; | ||
/** | ||
* Gets an attribute value in an environment without attribute bug | ||
* | ||
* @param {Node} el | ||
* @param {Attr} attr | ||
* @return {String} an attribute value | ||
*/ | ||
function getAttributeSimple(el, attr) { | ||
// There is a potential for a warning to occur here if the attribute is a | ||
// custom attribute in IE<9 with a custom .toString() method. This is | ||
// just a warning and doesn't affect execution (see #21) | ||
return attr.value; | ||
} | ||
/** | ||
* Gets an attribute value with special hack for style attribute (see #4) | ||
* | ||
* @param {Node} el | ||
* @param {Attr} attr | ||
* @return {String} an attribute value | ||
*/ | ||
function getAttributeWithStyleHack(el, attr) { | ||
// As with getAttributeSimple there is a potential warning for custom attribtues in IE7. | ||
return attr.name !== "style" ? attr.value : el.style.cssText; | ||
} | ||
var getAttributeValue = hasAttributeBug ? getAttributeSimple : getAttributeWithStyleHack; | ||
/** | ||
* fast helper to check to see if attributes object of an element has changed | ||
@@ -226,3 +270,3 @@ * doesnt handle the textnode case | ||
if (!filter || has(filter, name)) { | ||
if (attr.value !== $oldstate[name]) { | ||
if (getAttributeValue($target, attr) !== $oldstate[name]) { | ||
// The pushing is redundant but gzips very nicely | ||
@@ -306,3 +350,4 @@ mutations.push(MutationRecord({ | ||
type: "characterData", | ||
target: $cur | ||
target: $cur, | ||
oldValue: oldstruct.charData | ||
})); | ||
@@ -359,3 +404,4 @@ } | ||
type: "characterData", | ||
target: $cur | ||
target: $cur, | ||
oldValue: oldstruct.charData | ||
})); | ||
@@ -473,3 +519,3 @@ } | ||
if (!config.afilter || config.afilter[attr.name]) { | ||
memo[attr.name] = attr.value; | ||
memo[attr.name] = getAttributeValue($target, attr); | ||
} | ||
@@ -476,0 +522,0 @@ return memo; |
@@ -5,3 +5,3 @@ { | ||
"description": "MutationObserver shim for ES3 environments", | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"keywords": [ | ||
@@ -44,3 +44,3 @@ "DOM", | ||
"grunt-contrib-qunit": "~0.5.0", | ||
"grunt-file-info": "1.0.4", | ||
"grunt-file-info": "~1.0.14", | ||
"grunt-saucelabs": "~4.1.2", | ||
@@ -47,0 +47,0 @@ "grunt-tagrelease": "~0.3.1", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Unidentified License
License(Experimental) Something that seems like a license was found, but its contents could not be matched with a known license.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
583
30586
1
80
8