Skip to content

Commit

Permalink
get headless phantom finally working
Browse files Browse the repository at this point in the history
  • Loading branch information
ded committed Nov 26, 2012
1 parent f7b7ce6 commit e0b349d
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 104 deletions.
7 changes: 2 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
boosh:
smoosh make ./config/smoosh.json
node_modules/smoosh/bin/smoosh make ./config/smoosh.json
cp src/ender.js mobile/ender.js

install:
npm install smoosh -g

test:
serve . && phantomjs tests/phantom.js
node tests/test-env.js
1 change: 0 additions & 1 deletion config/smoosh.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
, "sub": true
, "white": false
, "indent": 2
, "whitespace": true
, "asi": true
, "laxbreak": true
, "eqeqeq": false
Expand Down
Empty file added hey there
Empty file.
5 changes: 3 additions & 2 deletions mobile/qwery-mobile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @preserve Qwery - A Blazing Fast query selector engine
* https://github.com/ded/qwery
* copyright Dustin Diaz & Jacob Thornton 2012
* copyright Dustin Diaz 2012
* MIT License
*/

Expand Down Expand Up @@ -35,7 +35,8 @@

function uniq(ar) {
var a = [], i, j
label: for (i = 0; i < ar.length; i++) {
label:
for (i = 0; i < ar.length; i++) {
for (j = 0; j < a.length; j++) {
if (a[j] == ar[i]) {
continue label
Expand Down
4 changes: 2 additions & 2 deletions mobile/qwery-mobile.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion mobile/src/mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

function uniq(ar) {
var a = [], i, j
label: for (i = 0; i < ar.length; i++) {
label:
for (i = 0; i < ar.length; i++) {
for (j = 0; j < a.length; j++) {
if (a[j] == ar[i]) {
continue label
Expand Down
7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "qwery"
, "description": "blazing fast CSS3 query selector engine"
, "version": "3.3.11"
, "version": "3.4.0"
, "homepage": "https://github.com/ded/qwery"
, "author": "Dustin Diaz <dustin@dustindiaz.com> (http://dustindiaz.com)"
, "contributors": [
Expand All @@ -19,8 +19,7 @@
, "devDependencies": {
"sink-test": ">= 1.0.1"
, "serve": "*"
}
, "scripts": {
"test": "phantomjs tests/phantom.js"
, "smoosh": "0.4.0"
, "phantomjs": "0.2.3"
}
}
10 changes: 5 additions & 5 deletions pseudos/qwery-pseudos.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* @preserve Qwery - A Blazing Fast query selector engine
* https://github.com/ded/qwery
* copyright Dustin Diaz & Jacob Thornton 2012
* copyright Dustin Diaz 2012
* MIT License
*/

Expand All @@ -27,8 +27,8 @@
}

function checkNthExpr(el, nodes, a, b) {
if (!a) return (nodes[b-1] == el)
for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i-1]) return true
if (!a) return (nodes[b - 1] == el)
for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i - 1]) return true
return false
}

Expand All @@ -54,9 +54,9 @@
}

// *was* going to be in CSS3, didn't quite make it
pseudos.contains = function(el, val) { return text(el).indexOf(val) != -1 }
pseudos.contains = function (el, val) { return text(el).indexOf(val) != -1 }

pseudos.not = function(el, val) { return !q.is(el, val) }
pseudos.not = function (el, val) { return !q.is(el, val) }

pseudos['nth-child'] = function (el, val) {
if (!val || !(p = el.parentNode)) return false
Expand Down
4 changes: 2 additions & 2 deletions pseudos/qwery-pseudos.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions pseudos/src/pseudos.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
}

function checkNthExpr(el, nodes, a, b) {
if (!a) return (nodes[b-1] == el)
for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i-1]) return true
if (!a) return (nodes[b - 1] == el)
for (i = b, l = nodes.length; ((a > 0) ? (i <= l) : (i >= 1)); i += a) if (el == nodes[i - 1]) return true
return false
}

Expand All @@ -47,9 +47,9 @@
}

// *was* going to be in CSS3, didn't quite make it
pseudos.contains = function(el, val) { return text(el).indexOf(val) != -1 }
pseudos.contains = function (el, val) { return text(el).indexOf(val) != -1 }

pseudos.not = function(el, val) { return !q.is(el, val) }
pseudos.not = function (el, val) { return !q.is(el, val) }

pseudos['nth-child'] = function (el, val) {
if (!val || !(p = el.parentNode)) return false
Expand Down
72 changes: 37 additions & 35 deletions qwery.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*!
* @preserve Qwery - A Blazing Fast query selector engine
* https://github.com/ded/qwery
* copyright Dustin Diaz & Jacob Thornton 2012
* copyright Dustin Diaz 2012
* MIT License
*/

(function (name, definition, context) {
(function (name, context, definition) {
if (typeof module != 'undefined' && module.exports) module.exports = definition()
else if (typeof context['define'] == 'function' && context['define']['amd']) define(name, definition)
else if (typeof context['define'] == 'function' && context['define']['amd']) define(definition)
else context[name] = definition()
})('qwery', function () {
})('qwery', this, function () {
var doc = document
, html = doc.documentElement
, byClass = 'getElementsByClassName'
Expand Down Expand Up @@ -38,21 +38,22 @@
, dividers = new RegExp('(' + splitters.source + ')' + splittersMore.source, 'g')
, tokenizr = new RegExp(splitters.source + splittersMore.source)
, chunker = new RegExp(simple.source + '(' + attr.source + ')?' + '(' + pseudo.source + ')?')
, walker = {
' ': function (node) {
return node && node !== html && node.parentNode
}
, '>': function (node, contestant) {
return node && node.parentNode == contestant.parentNode && node.parentNode
}
, '~': function (node) {
return node && node.previousSibling
}
, '+': function (node, contestant, p1, p2) {
if (!node) return false
return (p1 = previous(node)) && (p2 = previous(contestant)) && p1 == p2 && p1
}

var walker = {
' ': function (node) {
return node && node !== html && node.parentNode
}
, '>': function (node, contestant) {
return node && node.parentNode == contestant.parentNode && node.parentNode
}
, '~': function (node) {
return node && node.previousSibling
}
, '+': function (node, contestant, p1, p2) {
if (!node) return false
return (p1 = previous(node)) && (p2 = previous(contestant)) && p1 == p2 && p1
}
}

function cache() {
this.c = {}
Expand Down Expand Up @@ -180,7 +181,7 @@
if (!tokens.length) return r

// filter further according to the rest of the selector (the left side)
each(r, function(e) { if (ancestorMatch(e, tokens, dividedTokens)) ret[ret.length] = e })
each(r, function (e) { if (ancestorMatch(e, tokens, dividedTokens)) ret[ret.length] = e })
return ret
}

Expand Down Expand Up @@ -222,8 +223,9 @@
}

function uniq(ar) {
var a = [], i, j
o: for (i = 0; i < ar.length; ++i) {
var a = [], i, j;
o:
for (i = 0; i < ar.length; ++i) {
for (j = 0; j < a.length; ++j) if (a[j] == ar[i]) continue o
a[a.length] = ar[i]
}
Expand Down Expand Up @@ -270,15 +272,15 @@
// where the root is not document and a relationship selector is first we have to
// do some awkward adjustments to get it to work, even with qSA
function collectSelector(root, collector) {
return function(s) {
return function (s) {
var oid, nid
if (splittable.test(s)) {
if (root[nodeType] !== 9) {
// make sure the el has an id, rewrite the query, set root to doc and run it
if (!(nid = oid = root.getAttribute('id'))) root.setAttribute('id', nid = '__qwerymeupscotty')
s = '[id="' + nid + '"]' + s // avoid byId and allow us to match context element
collector(root.parentNode || root, s, true)
oid || root.removeAttribute('id')
// make sure the el has an id, rewrite the query, set root to doc and run it
if (!(nid = oid = root.getAttribute('id'))) root.setAttribute('id', nid = '__qwerymeupscotty')
s = '[id="' + nid + '"]' + s // avoid byId and allow us to match context element
collector(root.parentNode || root, s, true)
oid || root.removeAttribute('id')
}
return;
}
Expand All @@ -298,16 +300,16 @@
while (element = element.parentNode) if (element === container) return 1
return 0
}
, getAttr = function() {
, getAttr = function () {
// detect buggy IE src/href getAttribute() call
var e = doc.createElement('p')
return ((e.innerHTML = '<a href="#x">x</a>') && e.firstChild.getAttribute('href') != '#x') ?
function(e, a) {
function (e, a) {
return a === 'class' ? e.className : (a === 'href' || a === 'src') ?
e.getAttribute(a, 2) : e.getAttribute(a)
} :
function(e, a) { return e.getAttribute(a) }
}()
function (e, a) { return e.getAttribute(a) }
}()
, hasByClass = !!doc[byClass]
// has native qSA support
, hasQSA = doc.querySelector && doc[qSA]
Expand All @@ -320,13 +322,13 @@
return arrayify(root[qSA](selector))
}
// special case where we need the services of `collectSelector()`
each(ss = selector.split(','), collectSelector(root, function(ctx, s) {
each(ss = selector.split(','), collectSelector(root, function (ctx, s) {
e = ctx[qSA](s)
if (e.length == 1) result[result.length] = e.item(0)
else if (e.length) result = result.concat(arrayify(e))
}))
return ss.length > 1 && result.length > 1 ? uniq(result) : result
} catch(ex) { }
} catch (ex) { }
return selectNonNative(selector, root)
}
// no native selector support
Expand All @@ -342,7 +344,7 @@
return result
}
// more complex selector, get `_qwery()` to do the work for us
each(ss = selector.split(','), collectSelector(root, function(ctx, s, rewrite) {
each(ss = selector.split(','), collectSelector(root, function (ctx, s, rewrite) {
r = _qwery(s, ctx)
for (i = 0, l = r.length; i < l; i++) {
if (ctx[nodeType] === 9 || rewrite || isAncestor(r[i], root)) result[result.length] = r[i]
Expand All @@ -364,4 +366,4 @@
qwery.pseudos = {}

return qwery
}, this);
});
Loading

0 comments on commit e0b349d

Please sign in to comment.