Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
John McEleney
/
casperjs
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Commit
adb1ad9f
...
adb1ad9f4148d4f699b07e87219aaa321bdfd21d
authored
2013-05-04 16:00:33 -0600
by
hexid
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Add elementVisible(elem) and refactor visible(selector) and getElementsInfo(selector) to use it
1 parent
9707539c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
16 deletions
modules/clientutils.js
modules/clientutils.js
View file @
adb1ad9
...
...
@@ -128,6 +128,24 @@
};
/**
* Checks if a given DOM element is visible in remove page.
*
* @param Object element DOM element
* @return Boolean
*/
this
.
elementVisible
=
function
elementVisible
(
elem
)
{
try
{
var
comp
=
window
.
getComputedStyle
(
elem
,
null
);
return
comp
.
visiblility
!==
'hidden'
&&
comp
.
display
!==
'none'
&&
elem
.
offsetHeight
>
0
&&
elem
.
offsetWidth
>
0
;
}
catch
(
e
)
{
return
false
;
}
}
/**
* Base64 encodes a string, even binary ones. Succeeds where
* window.btoa() fails.
*
...
...
@@ -427,8 +445,8 @@
*/
this
.
getElementsInfo
=
function
getElementsInfo
(
selector
)
{
var
bounds
=
this
.
getElementsBounds
(
selector
);
var
visibility
=
this
.
visible
(
selector
)
;
return
Array
.
prototype
.
map
.
call
(
this
.
findAll
(
selector
),
function
(
element
,
index
)
{
var
eleVisible
=
this
.
elementVisible
;
return
[]
.
map
.
call
(
this
.
findAll
(
selector
),
function
(
element
,
index
)
{
var
attributes
=
{};
[].
forEach
.
call
(
element
.
attributes
,
function
(
attr
)
{
attributes
[
attr
.
name
.
toLowerCase
()]
=
attr
.
value
;
...
...
@@ -443,7 +461,7 @@
y
:
bounds
[
index
].
top
,
width
:
bounds
[
index
].
width
,
height
:
bounds
[
index
].
height
,
visible
:
visibility
visible
:
eleVisible
(
element
)
};
});
};
...
...
@@ -801,24 +819,16 @@
};
/**
* Checks if a
given DOM element
is visible in remote page.
* Checks if a
ny element matching a given selector
is visible in remote page.
*
* @param String selector CSS3 selector
* @return Boolean
*/
this
.
visible
=
function
visible
(
selector
)
{
try
{
var
elems
=
this
.
findAll
(
selector
);
return
Array
.
prototype
.
some
.
call
(
elems
,
function
(
el
)
{
var
comp
=
window
.
getComputedStyle
(
el
,
null
);
return
comp
.
visibility
!==
'hidden'
&&
comp
.
display
!==
'none'
&&
el
.
offsetHeight
>
0
&&
el
.
offsetWidth
>
0
;
});
}
catch
(
e
)
{
return
false
;
}
var
eleVisible
=
this
.
elementVisible
;
return
[].
some
.
call
(
this
.
findAll
(
selector
),
function
(
el
)
{
return
eleVisible
(
el
);
});
};
};
})(
typeof
exports
===
"object"
?
exports
:
window
);
...
...
Please
register
or
sign in
to post a comment