Skip to content

Commit

Permalink
Merge pull request #315 from helen-dikareva/issue314
Browse files Browse the repository at this point in the history
Add some accessory methods to styleUtils and export some service methods for testcafe (close #314)
  • Loading branch information
churkin committed Dec 4, 2015
2 parents f529f1f + 2326fec commit 3ce5900
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 9 deletions.
20 changes: 13 additions & 7 deletions src/client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ import CodeInstrumentation from './sandbox/code-instrumentation';
import EventEmitter from './utils/event-emitter';
import settings from './settings';
import transport from './transport';
import * as JSON from './json';
import * as browserUtils from './utils/browser';
import * as domUtils from './utils/dom';
import * as eventUtils from './utils/event';
import * as typeUtils from './utils/types';
import * as JSON from './json';
import * as positionUtils from './utils/position';
import * as styleUtils from './utils/style';
import { getProxyUrl } from './utils/url';
import isJQueryObj from './utils/is-jquery-object';
import extend from './utils/extend';
import trim from '../utils/string-trim';
/*eslint-enable no-native-reassign*/

class Hammerhead {
Expand Down Expand Up @@ -63,12 +66,15 @@ class Hammerhead {
};

this.utils = {
browser: browserUtils,
dom: domUtils,
event: eventUtils,
position: positionUtils,
style: styleUtils,
types: typeUtils
browser: browserUtils,
dom: domUtils,
event: eventUtils,
position: positionUtils,
style: styleUtils,
types: typeUtils,
isJQueryObj: isJQueryObj,
extend: extend,
trim: trim
};
}

Expand Down
56 changes: 54 additions & 2 deletions src/client/utils/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,45 @@ export function getElementScroll (el) {
};
}

export function getWidth (el) {
if (!el)
return null;

if (domUtils.isWindow(el))
return el.document.documentElement.clientWidth;

if (el.nodeType === 9) {
var doc = el.documentElement;
var clientProp = 'clientWidth';
var scrollProp = 'scrollWidth';
var offsetProp = 'offsetWidth';

if (doc[clientProp] >= doc[scrollProp])
return doc[clientProp];

return Math.max(
el.body[scrollProp], doc[scrollProp],
el.body[offsetProp], doc[offsetProp]
);
}

var value = el.offsetWidth;

value -= getIntValue(get(el, 'paddingLeft'));
value -= getIntValue(get(el, 'paddingRight'));
value -= getIntValue(get(el, 'borderLeftWidth'));
value -= getIntValue(get(el, 'borderRightWidth'));

return value;
}

export function getHeight (el) {
if (!el)
return null;

if (domUtils.isWindow(el))
return el.document.documentElement.clientHeight;

if (el.nodeType === 9) {
var doc = el.documentElement;
var clientProp = 'clientHeight';
Expand All @@ -111,7 +146,6 @@ export function getHeight (el) {
);
}


var value = el.offsetHeight;

value -= getIntValue(get(el, 'paddingTop'));
Expand Down Expand Up @@ -140,6 +174,24 @@ export function getInnerWidth (el) {
return value;
}

export function getInnerHeight (el) {
if (!el)
return null;

if (domUtils.isWindow(el))
return el.document.documentElement.clientHeight;

if (domUtils.isDocument(el))
return el.documentElement.clientHeight;

var value = el.offsetHeight;

value -= getIntValue(get(el, 'borderTopWidth'));
value -= getIntValue(get(el, 'borderBottomWidth'));

return value;
}

export function getOptionHeight (select) {
var realSizeValue = getSelectElementSize(select);
var selectPadding = getElementPadding(select);
Expand Down Expand Up @@ -225,7 +277,7 @@ export function setScrollTop (el, value) {
return;

if (domUtils.isWindow(el) || domUtils.isDocument(el)) {
var win = domUtils.findDocument(el).defaultView;
var win = domUtils.findDocument(el).defaultView;
var scrollLeft = getScrollLeft(el);

win.scrollTo(scrollLeft, value);
Expand Down

0 comments on commit 3ce5900

Please sign in to comment.