-
Notifications
You must be signed in to change notification settings - Fork 0
/
doc.js
66 lines (52 loc) · 1.68 KB
/
doc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/browser/blob/master/LICENSE
*/
// doc
// object for document and document fragment targets
// import
import { Arr, Ele, Num } from '../index.js';
// export
export default {
// is
// retourne vrai si la valeur est un document, un fragment de document ou un template
is: function(value)
{
return (this.isCurrent(value) || this.isFragment(value) || this.isTemplate(value));
},
// is
// retourne vrai si la valeur est le document courant
isCurrent: function(value)
{
return value === document;
},
// isFragment
// retourne vrai si la valeur est un fragment de document
isFragment: function(value)
{
return value instanceof DocumentFragment;
},
// getDimension
// retourne la dimension du document, c'est à dire la dimension des premiers enfants du document
getDimension: function(value)
{
this.typecheck(value);
const r = { width: 0, height: 0 };
if(this.isCurrent(value))
{
r.width = Num.round(document.documentElement.scrollWidth);
r.height = Num.round(document.documentElement.scrollHeight);
}
else
{
const children = this.children(value);
Arr.each(children,function(ele) {
const dimension = Ele.getDimension(ele);
r.width += dimension.width;
r.height += dimension.height;
});
}
return r;
}
}