lc2-selector
Advanced tools
Comparing version 0.0.1 to 1.0.0
@@ -5,73 +5,76 @@ /*jslint vars: true, plusplus: true */ | ||
'use strict'; | ||
var $ = Sizzle; | ||
if (typeof $ === 'undefined') { | ||
throw new Error('[lc2-sizzle]: Sizzle is not found!'); | ||
} | ||
function lc2Selector($) { | ||
if (typeof Sizzle === 'undefined') { | ||
throw new Error('[lc2-sizzle]: Sizzle is not found!'); | ||
} | ||
function sizzleIframe(iSA, rootContext) { | ||
// iSA: iframeSelectorArray. | ||
function sizzleIframe(iSA, rootContext) { | ||
// iSA: iframeSelectorArray. | ||
var parentArray, result = [], | ||
deepth = 0, | ||
lastSelector = iSA.pop(), | ||
maxDeepth = iSA.length, | ||
iframeContext = []; | ||
var parentArray, result = [], | ||
deepth = 0, | ||
lastSelector = iSA.pop(), | ||
maxDeepth = iSA.length, | ||
iframeContext = []; | ||
function queryIframe(context) { | ||
$(iSA[deepth], context).forEach(function (element) { | ||
if (element.tagName === 'IFRAME') { | ||
iframeContext.push(element.contentWindow.document); | ||
} | ||
}); | ||
} | ||
function queryIframe(context) { | ||
$(iSA[deepth], context).forEach(function (element) { | ||
if (element.tagName === 'IFRAME') { | ||
iframeContext.push(element.contentWindow.document); | ||
} | ||
}); | ||
} | ||
// init query by rootContext. | ||
queryIframe(rootContext); | ||
deepth += 1; | ||
// travel. | ||
while (deepth < maxDeepth && iframeContext.length) { | ||
parentArray = iframeContext; | ||
iframeContext = []; | ||
parentArray.forEach(queryIframe); | ||
// init query by rootContext. | ||
queryIframe(rootContext); | ||
deepth += 1; | ||
} | ||
// travel. | ||
while (deepth < maxDeepth && iframeContext.length) { | ||
parentArray = iframeContext; | ||
iframeContext = []; | ||
parentArray.forEach(queryIframe); | ||
// Query all Element by last deepth context array. | ||
if (deepth === maxDeepth) { | ||
iframeContext.forEach(function (parentContext) { | ||
result = result.concat($(lastSelector, parentContext)); | ||
}); | ||
deepth += 1; | ||
} | ||
// Query all Element by last deepth context array. | ||
if (deepth === maxDeepth) { | ||
iframeContext.forEach(function (parentContext) { | ||
result = result.concat($(lastSelector, parentContext)); | ||
}); | ||
} | ||
return result; | ||
} | ||
return result; | ||
} | ||
function LC2Sizzle(selector, context) { | ||
/** | ||
* sGroup[ [sIframeContext_1], [sIframeContext_2],... ] | ||
*/ | ||
var resultArray = [], | ||
group = selector.split(','); | ||
function LC2Sizzle(selector, context) { | ||
/** | ||
* sGroup[ [sIframeContext_1], [sIframeContext_2],... ] | ||
*/ | ||
var resultArray = [], | ||
group = selector.split(','); | ||
group.forEach(function (selector) { | ||
var gR, iframeContext = selector.split('<'); | ||
group.forEach(function (selector) { | ||
var gR, iframeContext = selector.split('<'); | ||
if (iframeContext.length < 1) { return; } | ||
if (iframeContext.length < 1) { return; } | ||
if (iframeContext.length === 1) { | ||
gR = $(iframeContext[0]); | ||
} else { | ||
gR = sizzleIframe(iframeContext, context); | ||
} | ||
if (iframeContext.length === 1) { | ||
gR = $(iframeContext[0]); | ||
} else { | ||
gR = sizzleIframe(iframeContext, context); | ||
} | ||
gR.forEach(function (element) { | ||
if (resultArray.indexOf(element) === -1) { | ||
resultArray.push(element); | ||
} | ||
}); | ||
gR.forEach(function (element) { | ||
if (resultArray.indexOf(element) === -1) { | ||
resultArray.push(element); | ||
} | ||
}); | ||
}); | ||
return resultArray; | ||
return resultArray; | ||
} | ||
} | ||
@@ -81,6 +84,6 @@ | ||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = LC2Sizzle; | ||
module.exports = lc2Selector; | ||
} else { | ||
window.$ = LC2Sizzle; | ||
window.$ = lc2Selector($); | ||
} | ||
}()); |
{ | ||
"name": "lc2-selector", | ||
"version": "0.0.1", | ||
"version": "1.0.0", | ||
"description": "lc2 css selector", | ||
@@ -5,0 +5,0 @@ "main": "lc2-sizzle.js", |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
5091
71
2