~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/static/javascript/yui/build/dom/dom-screen-debug.js

  • Committer: Martin Albisetti
  • Date: 2008-12-30 19:20:39 UTC
  • Revision ID: argentina@gmail.com-20081230192039-kc2spvli08fo09sx
Upgrade YUI3 to PR2

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
4
http://developer.yahoo.net/yui/license.txt
5
 
version: 3.0.0pr1
 
5
version: 3.0.0pr2
6
6
*/
7
7
YUI.add('dom-screen', function(Y) {
8
8
 
 
9
 
9
10
/**
10
11
 * Adds position and region management functionality to DOM.
11
12
 * @module dom
14
15
 */
15
16
 
16
17
var OFFSET_TOP = 'offsetTop',
 
18
 
17
19
    DOCUMENT_ELEMENT = 'documentElement',
18
20
    COMPAT_MODE = 'compatMode',
19
21
    OFFSET_LEFT = 'offsetLeft',
36
38
    RE_TABLE = /^t(?:able|d|h)$/i;
37
39
 
38
40
Y.mix(Y.DOM, {
 
41
 
 
42
 
39
43
    /**
40
44
     * Returns the inner height of the viewport (exludes scrollbar). 
41
45
     * @method winHeight
42
 
     * @return {Int} The pixel height of the viewport.
 
46
 
43
47
     */
44
48
    winHeight: function(node) {
45
49
        var h = Y.DOM._getWinSize(node)[HEIGHT];
50
54
    /**
51
55
     * Returns the inner width of the viewport (exludes scrollbar). 
52
56
     * @method winWidth
53
 
     * @return {Int} The pixel width of the viewport.
 
57
 
54
58
     */
55
59
    winWidth: function(node) {
56
60
        var w = Y.DOM._getWinSize(node)[WIDTH];
61
65
    /**
62
66
     * Document height 
63
67
     * @method docHeight
64
 
     * @return {Int} The pixel height of the document.
 
68
 
65
69
     */
66
70
    docHeight:  function(node) {
67
71
        var h = Y.DOM._getDocSize(node)[HEIGHT];
72
76
    /**
73
77
     * Document width 
74
78
     * @method docWidth
75
 
     * @return {Int} The pixel width of the document.
 
79
 
76
80
     */
77
81
    docWidth:  function(node) {
78
82
        var w = Y.DOM._getDocSize(node)[WIDTH];
83
87
    /**
84
88
     * Amount page has been scroll vertically 
85
89
     * @method docScrollX
86
 
     * @return {Int} The scroll amount in pixels.
 
90
 
87
91
     */
88
92
    docScrollX: function(node) {
89
93
        var doc = Y.DOM._getDoc();
93
97
    /**
94
98
     * Amount page has been scroll horizontally 
95
99
     * @method docScrollY
96
 
     * @return {Int} The scroll amount in pixels.
 
100
 
97
101
     */
98
102
    docScrollY:  function(node) {
99
103
        var doc = Y.DOM._getDoc();
111
115
     TODO: test inDocument/display
112
116
     */
113
117
    getXY: function() {
 
118
 
 
119
 
 
120
 
 
121
 
114
122
        if (document[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) {
115
123
            return function(node) {
116
124
                if (!node) {
143
151
                            if (bTop !== MEDIUM) {
144
152
                                off2 = parseInt(bTop, 10);
145
153
                            }
 
154
 
 
155
 
 
156
 
146
157
                        }
147
158
                        
148
159
                        xy[0] -= off1;
149
160
                        xy[1] -= off2;
 
161
 
150
162
                    }
151
163
 
152
164
                if ((scrollTop || scrollLeft)) {
254
266
    setXY: function(node, xy, noRetry) {
255
267
        var pos = Y.DOM.getStyle(node, POSITION),
256
268
            setStyle = Y.DOM.setStyle,
 
269
 
257
270
            delta = [ // assuming pixels; if not we will have to retry
258
271
                parseInt( Y.DOM[GET_COMPUTED_STYLE](node, LEFT), 10 ),
259
272
                parseInt( Y.DOM[GET_COMPUTED_STYLE](node, TOP), 10 )
266
279
 
267
280
        var currentXY = Y.DOM.getXY(node);
268
281
 
 
282
 
 
283
 
 
284
 
269
285
        if (currentXY === false) { // has to be part of doc to have xy
 
286
 
 
287
 
 
288
 
 
289
 
 
290
 
270
291
            Y.log('xy failed: node not available', 'error', 'Node');
271
292
            return false; 
272
293
        }
365
386
    }
366
387
});
367
388
 
 
389
 
 
390
 
368
391
/**
369
392
 * Adds position and region management functionality to DOM.
370
393
 * @module dom
374
397
 
375
398
var OFFSET_WIDTH = 'offsetWidth',
376
399
    OFFSET_HEIGHT = 'offsetHeight',
 
400
    TOP = 'top',
 
401
    RIGHT = 'right',
 
402
    BOTTOM = 'bottom',
 
403
    LEFT = 'left',
377
404
    TAG_NAME = 'tagName';
378
405
 
379
406
var getOffsets = function(r1, r2) {
380
 
 
381
 
    var t = Math.max(r1.top,    r2.top   ),
382
 
        r = Math.min(r1.right,  r2.right ),
383
 
        b = Math.min(r1.bottom, r2.bottom),
384
 
        l = Math.max(r1.left,   r2.left  );
 
407
    var t = Math.max(r1[TOP], r2[TOP]),
 
408
        r = Math.min(r1[RIGHT], r2[RIGHT]),
 
409
        b = Math.min(r1[BOTTOM], r2[BOTTOM]),
 
410
        l = Math.max(r1[LEFT], r2[LEFT]),
 
411
        ret = {};
385
412
    
386
 
    return {
387
 
        top: t,
388
 
        bottom: b,
389
 
        left: l,
390
 
        right: r
391
 
    };
 
413
    ret[TOP] = t;
 
414
    ret[RIGHT] = r;
 
415
    ret[BOTTOM] = b;
 
416
    ret[LEFT] = l;
 
417
    return ret;
392
418
};
393
419
 
394
 
Y.mix(Y.DOM, {
 
420
var DOM = DOM || Y.DOM;
 
421
Y.mix(DOM, {
395
422
    /**
396
423
     * Returns an Object literal containing the following about this element: (top, right, bottom, left)
397
424
     * @method region
399
426
     @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
400
427
     */
401
428
    region: function(node) {
402
 
        var x = Y.DOM.getXY(node),
 
429
        var x = DOM.getXY(node),
403
430
            ret = false;
404
431
        
405
432
        if (x) {
427
454
     @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
428
455
     */
429
456
    intersect: function(node, node2, altRegion) {
430
 
        var r = altRegion || Y.DOM.region(node), region = {};
 
457
        var r = altRegion || DOM.region(node), region = {};
431
458
 
432
459
        var n = node2;
433
460
        if (n[TAG_NAME]) {
434
 
            region = Y.DOM.region(n);
 
461
            region = DOM.region(n);
435
462
        } else if (Y.Lang.isObject(node2)) {
436
463
            region = node2;
437
464
        } else {
440
467
        
441
468
        var off = getOffsets(region, r);
442
469
        return {
443
 
            top: off.top,
444
 
            right: off.right,
445
 
            bottom: off.bottom,
446
 
            left: off.left,
447
 
            area: ((off.bottom - off.top) * (off.right - off.left)),
448
 
            yoff: ((off.bottom - off.top)),
449
 
            xoff: (off.right - off.left),
450
 
            inRegion: Y.DOM.inRegion(node, node2, false, altRegion)
 
470
            top: off[TOP],
 
471
            right: off[RIGHT],
 
472
            bottom: off[BOTTOM],
 
473
            left: off[LEFT],
 
474
            area: ((off[BOTTOM] - off[TOP]) * (off[RIGHT] - off[LEFT])),
 
475
            yoff: ((off[BOTTOM] - off[TOP])),
 
476
            xoff: (off[RIGHT] - off[LEFT]),
 
477
            inRegion: DOM.inRegion(node, node2, false, altRegion)
451
478
        };
452
479
        
453
480
    },
461
488
     */
462
489
    inRegion: function(node, node2, all, altRegion) {
463
490
        var region = {},
464
 
            r = altRegion || Y.DOM.region(node);
 
491
            r = altRegion || DOM.region(node);
465
492
 
466
493
        var n = node2;
467
494
        if (n[TAG_NAME]) {
468
 
            region = Y.DOM.region(n);
 
495
            region = DOM.region(n);
469
496
        } else if (Y.Lang.isObject(node2)) {
470
497
            region = node2;
471
498
        } else {
473
500
        }
474
501
            
475
502
        if (all) {
476
 
            return ( r.left   >= region.left   &&
477
 
                r.right  <= region.right  && 
478
 
                r.top    >= region.top    && 
479
 
                r.bottom <= region.bottom    );
 
503
            return (
 
504
                r[LEFT]   >= region[LEFT]   &&
 
505
                r[RIGHT]  <= region[RIGHT]  && 
 
506
                r[TOP]    >= region[TOP]    && 
 
507
                r[BOTTOM] <= region[BOTTOM]  );
480
508
        } else {
481
509
            var off = getOffsets(region, r);
482
 
            if (off.bottom >= off.top && off.right >= off.left) {
 
510
            if (off[BOTTOM] >= off[TOP] && off[RIGHT] >= off[LEFT]) {
483
511
                return true;
484
512
            } else {
485
513
                return false;
497
525
     * @return {Boolean} True if in region, false if not.
498
526
     */
499
527
    inViewportRegion: function(node, all, altRegion) {
500
 
        return Y.DOM.inRegion(node, Y.DOM.viewportRegion(node), all, altRegion);
 
528
        return DOM.inRegion(node, DOM.viewportRegion(node), all, altRegion);
501
529
            
502
530
    },
503
531
 
508
536
     */
509
537
    viewportRegion: function(node) {
510
538
        node = node || Y.config.doc.documentElement;
511
 
        var r = {
512
 
            top: Y.DOM.docScrollY(node),
513
 
            right: Y.DOM.winWidth(node) + Y.DOM.docScrollX(node),
514
 
            bottom: (Y.DOM.docScrollY(node) + Y.DOM.winHeight(node)),
515
 
            left: Y.DOM.docScrollX(node)
516
 
        };
 
539
        var r = {};
 
540
        r[TOP] = DOM.docScrollY(node);
 
541
        r[RIGHT] = DOM.winWidth(node) + DOM.docScrollX(node);
 
542
        r[BOTTOM] = (DOM.docScrollY(node) + DOM.winHeight(node));
 
543
        r[LEFT] = DOM.docScrollX(node);
517
544
 
518
545
        return r;
519
546
    }
520
547
});
521
548
 
522
549
 
523
 
}, '3.0.0pr1' ,{skinnable:false, requires:['dom-base', 'dom-style']});
 
550
 
 
551
}, '3.0.0pr2' ,{skinnable:false, requires:['dom-base', 'dom-style']});