test mutation observer
by bakhshi
HTML
<script src='https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js'></script>
<button id='check'>check</button>
<output id='output'></output>
<div id='container'>container</div>
JavaScript
$(function () {
$("#check").click(function () {
$("#container>div").each(function () {
var self = $(this);
if (self.find('.test').css("text-transform") !== 'uppercase' || self.css('font-style') !== 'italic') { console.log(self.text());self.css('background-color', 'red');}
});
var output = $("#output");
var out = [];
if(Object.keys(toBeAttachedSelectors).length)
out.push('selectors!');
if(nodesToBeProcessed.length)
out.push('nodes to be processed!');
if(Object.keys(toBeAttachedNodes).length)
out.push('tobeattached nodes!');
output.val(out.join(' '));
})
})
function AttachedToDom(toBeAttachedObj, arg0, arg1) {
var timeout = (+arg1 || +arg0 || (60000 * 3)) | 0;
var context = arg0 && typeof arg0 !== 'number' && arg0;
var tobeAttached;
if (toBeAttachedObj.nodeType) tobeAttached = $(toBeAttachedObj);
else if (toBeAttachedObj.jquery) tobeAttached = toBeAttachedObj;
else tobeAttached = toBeAttachedObj;
//un finished work on using mutation observers
var ThereIsMutationObserver = !! MutationObserver;
if (ThereIsMutationObserver) return AttachedToDomByMutationObsever(tobeAttached, timeout, arg1);
}
var MutationObserver = (window).MutationObserver || (window).WebKitMutationObserver || (window).MozMutationObserver;
var attachedToDomDFDKey = "___attachedToDom_dfd";
var attachedToDomKey = "___attachedToDom";
function AttachedToDomByMutationObsever(tobeAttachedSelectorOrJQuery, timeout, context) {
var toBeAttached = (tobeAttachedSelectorOrJQuery.jquery ? tobeAttachedSelectorOrJQuery : $(tobeAttachedSelectorOrJQuery));
//if already waiting for attach...
var oldDFD;
if (oldDFD = toBeAttached.data(attachedToDomDFDKey)) return oldDFD.promise();
var dfd = $.Deferred();
var alreadyAttached = $.inArray($("body")[0], toBeAttached.parents().addBack().get()) >= 0;
if (alreadyAttached)...