~ubuntu-branches/ubuntu/lucid/loggerhead/lucid-security

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): James Westby, Roland Mas, Jelmer Vernooij, James Westby
  • Date: 2009-08-26 13:18:03 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20090826131803-0ce1fhaetci8b0c5
Tags: 1.17-0ubuntu1
[ Roland Mas ]
* Use the YUI library provided by libjs-yui. (Closes: #511286)

[ Jelmer Vernooij ]
* Use my debian.org address in Uploaders field.
* Add ${misc:Depends} to please lintian.
* Suggest recent version of paste, which doesn't expose internal port
  numbers in links. (Closes: #507000)
* Bump standards version to 3.8.1.

[ James Westby ]
* New upstream release.
* Drop get-orig-source rule in favour of debian/watch.
* Add python-pkg-resources and python-paste to Build-Depends,
  python-pkg-resources to Depends and python-simplejson to
  Recommends due to dependency changes.

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', function(Y) {
8
8
 
66
66
        if (text === UNDEFINED && INNER_TEXT in element) {
67
67
            text = element[INNER_TEXT];
68
68
        } 
69
 
        return text || ''; 
 
69
        return text || '';
70
70
    },
71
71
 
72
72
    /**
79
79
     * @return {HTMLElement | null} The first matching child html element.
80
80
     */
81
81
    firstChild: function(element, fn) {
82
 
        return Y.DOM._childBy(element, null, fn); 
 
82
        return Y.DOM._childBy(element, null, fn);
83
83
    },
84
84
 
85
85
    firstChildByTag: function(element, tag, fn) {
86
 
        return Y.DOM._childBy(element, tag, fn); 
 
86
        return Y.DOM._childBy(element, tag, fn);
87
87
    },
88
88
 
89
89
    /**
90
90
     * Finds the lastChild of the given HTMLElement.
91
91
     * @method lastChild
92
92
     * @param {HTMLElement} element The html element.
 
93
     * @param {String} tag The tag to search for.
93
94
     * @param {Function} fn optional An optional boolean test to apply.
94
95
     * The optional function is passed the current HTMLElement being tested as its only argument.
95
96
     * If no function is given, the first found is returned.
96
97
     * @return {HTMLElement | null} The first matching child html element.
97
98
     */
98
99
    lastChild: function(element, fn) {
99
 
        return Y.DOM._childBy(element, null, fn, true); 
 
100
        return Y.DOM._childBy(element, null, fn, true);
100
101
    },
101
102
 
102
103
    lastChildByTag: function(element, tag, fn) {
103
 
        return Y.DOM._childBy(element, tag, fn, true); 
 
104
        return Y.DOM._childBy(element, tag, fn, true);
104
105
    },
105
106
 
106
107
    /**
126
127
                    }
127
128
                }
128
129
 
129
 
                return elements; 
 
130
                return elements;
130
131
            };
131
132
        } else {
132
133
            return function(element, tag, fn) {
142
143
                        };
143
144
                    }
144
145
 
145
 
                    elements = Y.DOM.filterElementsBy(elements, wrapFn); 
 
146
                    elements = Y.DOM.filterElementsBy(elements, wrapFn);
146
147
                }
147
148
                return elements;
148
149
            };
159
160
     * @return {Array} The collection of child elements.
160
161
     */
161
162
    children: function(element, fn) {
162
 
        return Y.DOM.childrenByTag(element, null, fn); 
 
163
        return Y.DOM.childrenByTag(element, null, fn);
163
164
    },
164
165
 
165
166
    /**
172
173
     * @param {Boolean} all optional Whether all node types should be scanned, or just element nodes.
173
174
     * @return {HTMLElement | null} The matching DOM node or null if none found. 
174
175
     */
175
 
    previous: function(element, fn, all) {
 
176
    previous: function(element, fn) {
176
177
        return Y.DOM.elementByAxis(element, PREVIOUS_SIBLING, fn);
177
178
    },
178
179
 
211
212
     * @param {String} axis The axis to search (parentNode, nextSibling, previousSibling).
212
213
     * @param {Function} fn optional An optional boolean test to apply.
213
214
     * @param {Boolean} all optional Whether all node types should be returned, or just element nodes.
214
 
     * The optional function is passed the current DOM node being tested as its only argument.
 
215
     * The optional function is passed the current HTMLElement being tested as its only argument.
215
216
     * If no function is given, the first element is returned.
216
217
     * @return {HTMLElement | null} The matching element or null if none found.
217
218
     */
255
256
     * @param {HTMLElement} root optional An optional root element to start from.
256
257
     * @param {Function} fn optional An optional boolean test to apply.
257
258
     * The optional function is passed the current HTMLElement being tested as its only argument.
258
 
     * If no function is given, the first match is returned.
 
259
     * If no function is given, the first match is returned. 
259
260
     * @return {HTMLElement} The matching element.
260
261
     */
261
262
    firstByTag: function(tag, root, fn) {
284
285
     */
285
286
    filterElementsBy: function(elements, fn, firstOnly) {
286
287
        var ret = (firstOnly) ? null : [];
287
 
        for (var i = 0, el; el = elements[i++];) {
288
 
            if ( el[TAG_NAME] && (!fn || fn(el)) ) {
 
288
        for (var i = 0, len = elements[LENGTH]; i < len; ++i) {
 
289
            if (elements[i][TAG_NAME] && (!fn || fn(elements[i]))) {
289
290
                if (firstOnly) {
290
 
                    ret = el;
 
291
                    ret = elements[i];
291
292
                    break;
292
293
                } else {
293
 
                    ret[ret[LENGTH]] = el;
 
294
                    ret[ret[LENGTH]] = elements[i];
294
295
                }
295
296
            }
296
297
        }
308
309
    contains: function(element, needle) {
309
310
        var ret = false;
310
311
 
311
 
        if (!needle || !needle[NODE_TYPE] || !element || !element[NODE_TYPE]) {
 
312
        if ( !needle || !element || !needle[NODE_TYPE] || !element[NODE_TYPE]) {
312
313
            ret = false;
313
314
        } else if (element[CONTAINS])  {
314
315
            if (Y.UA.opera || needle[NODE_TYPE] === 1) { // IE & SAF contains fail if needle not an ELEMENT_NODE
326
327
    },
327
328
 
328
329
    /**
329
 
     * Returns an HTMLElement for the given string of HTML.
330
 
     * @method create
331
 
     * @param {String} html The string of HTML to convert to a DOM element. 
332
 
     * @param {Document} document An optional document to create the node with.
333
 
     * @return {HTMLElement} The newly created element. 
 
330
     * Determines whether or not the HTMLElement is part of the document.
 
331
     * @method inDoc
 
332
     * @param {HTMLElement} element The containing html element.
 
333
     * @param {HTMLElement} doc optional The document to check.
 
334
     * @return {Boolean} Whether or not the element is attached to the document. 
334
335
     */
 
336
    inDoc: function(element, doc) {
 
337
        doc = doc || Y.config.doc;
 
338
        return Y.DOM.contains(doc.documentElement, element);
 
339
    },
 
340
 
335
341
    create: function(html, doc) {
336
342
        doc = doc || Y.config.doc;
337
343
        var m = re_tag.exec(html);
523
529
        });
524
530
    }
525
531
})();
 
532
 
526
533
/** 
527
534
 * The DOM utility provides a cross-browser abtraction layer
528
535
 * normalizing DOM tasks, and adds extra helper functionality
604
611
    }
605
612
});
606
613
 
 
614
 
607
615
/** 
608
616
 * Add style management functionality to DOM.
609
617
 * @module dom
645
653
     * @param {String} att The style property to set. 
646
654
     * @param {String|Number} val The value. 
647
655
     */
648
 
    setStyle: function(node, att, val) {
649
 
        var style = node[STYLE],
 
656
    setStyle: function(node, att, val, style) {
 
657
        style = node[STYLE],
650
658
            CUSTOM_STYLES = Y.DOM.CUSTOM_STYLES;
651
659
 
652
660
        if (style) {
754
762
 
755
763
}
756
764
 
 
765
 
 
766
 
757
767
/**
758
768
 * Adds position and region management functionality to DOM.
759
769
 * @module dom
762
772
 */
763
773
 
764
774
var OFFSET_TOP = 'offsetTop',
 
775
 
765
776
    DOCUMENT_ELEMENT = 'documentElement',
766
777
    COMPAT_MODE = 'compatMode',
767
778
    OFFSET_LEFT = 'offsetLeft',
784
795
    RE_TABLE = /^t(?:able|d|h)$/i;
785
796
 
786
797
Y.mix(Y.DOM, {
 
798
 
 
799
 
787
800
    /**
788
801
     * Returns the inner height of the viewport (exludes scrollbar). 
789
802
     * @method winHeight
790
 
     * @return {Int} The pixel height of the viewport.
 
803
 
791
804
     */
792
805
    winHeight: function(node) {
793
806
        var h = Y.DOM._getWinSize(node)[HEIGHT];
797
810
    /**
798
811
     * Returns the inner width of the viewport (exludes scrollbar). 
799
812
     * @method winWidth
800
 
     * @return {Int} The pixel width of the viewport.
 
813
 
801
814
     */
802
815
    winWidth: function(node) {
803
816
        var w = Y.DOM._getWinSize(node)[WIDTH];
807
820
    /**
808
821
     * Document height 
809
822
     * @method docHeight
810
 
     * @return {Int} The pixel height of the document.
 
823
 
811
824
     */
812
825
    docHeight:  function(node) {
813
826
        var h = Y.DOM._getDocSize(node)[HEIGHT];
817
830
    /**
818
831
     * Document width 
819
832
     * @method docWidth
820
 
     * @return {Int} The pixel width of the document.
 
833
 
821
834
     */
822
835
    docWidth:  function(node) {
823
836
        var w = Y.DOM._getDocSize(node)[WIDTH];
827
840
    /**
828
841
     * Amount page has been scroll vertically 
829
842
     * @method docScrollX
830
 
     * @return {Int} The scroll amount in pixels.
 
843
 
831
844
     */
832
845
    docScrollX: function(node) {
833
846
        var doc = Y.DOM._getDoc();
837
850
    /**
838
851
     * Amount page has been scroll horizontally 
839
852
     * @method docScrollY
840
 
     * @return {Int} The scroll amount in pixels.
 
853
 
841
854
     */
842
855
    docScrollY:  function(node) {
843
856
        var doc = Y.DOM._getDoc();
855
868
     TODO: test inDocument/display
856
869
     */
857
870
    getXY: function() {
 
871
 
 
872
 
 
873
 
 
874
 
858
875
        if (document[DOCUMENT_ELEMENT][GET_BOUNDING_CLIENT_RECT]) {
859
876
            return function(node) {
860
877
                if (!node) {
887
904
                            if (bTop !== MEDIUM) {
888
905
                                off2 = parseInt(bTop, 10);
889
906
                            }
 
907
 
 
908
 
 
909
 
890
910
                        }
891
911
                        
892
912
                        xy[0] -= off1;
893
913
                        xy[1] -= off2;
 
914
 
894
915
                    }
895
916
 
896
917
                if ((scrollTop || scrollLeft)) {
998
1019
    setXY: function(node, xy, noRetry) {
999
1020
        var pos = Y.DOM.getStyle(node, POSITION),
1000
1021
            setStyle = Y.DOM.setStyle,
 
1022
 
1001
1023
            delta = [ // assuming pixels; if not we will have to retry
1002
1024
                parseInt( Y.DOM[GET_COMPUTED_STYLE](node, LEFT), 10 ),
1003
1025
                parseInt( Y.DOM[GET_COMPUTED_STYLE](node, TOP), 10 )
1010
1032
 
1011
1033
        var currentXY = Y.DOM.getXY(node);
1012
1034
 
 
1035
 
 
1036
 
 
1037
 
1013
1038
        if (currentXY === false) { // has to be part of doc to have xy
 
1039
 
 
1040
 
 
1041
 
 
1042
 
 
1043
 
1014
1044
            return false; 
1015
1045
        }
1016
1046
        
1107
1137
    }
1108
1138
});
1109
1139
 
 
1140
 
 
1141
 
1110
1142
/**
1111
1143
 * Adds position and region management functionality to DOM.
1112
1144
 * @module dom
1116
1148
 
1117
1149
var OFFSET_WIDTH = 'offsetWidth',
1118
1150
    OFFSET_HEIGHT = 'offsetHeight',
 
1151
    TOP = 'top',
 
1152
    RIGHT = 'right',
 
1153
    BOTTOM = 'bottom',
 
1154
    LEFT = 'left',
1119
1155
    TAG_NAME = 'tagName';
1120
1156
 
1121
1157
var getOffsets = function(r1, r2) {
1122
 
 
1123
 
    var t = Math.max(r1.top,    r2.top   ),
1124
 
        r = Math.min(r1.right,  r2.right ),
1125
 
        b = Math.min(r1.bottom, r2.bottom),
1126
 
        l = Math.max(r1.left,   r2.left  );
 
1158
    var t = Math.max(r1[TOP], r2[TOP]),
 
1159
        r = Math.min(r1[RIGHT], r2[RIGHT]),
 
1160
        b = Math.min(r1[BOTTOM], r2[BOTTOM]),
 
1161
        l = Math.max(r1[LEFT], r2[LEFT]),
 
1162
        ret = {};
1127
1163
    
1128
 
    return {
1129
 
        top: t,
1130
 
        bottom: b,
1131
 
        left: l,
1132
 
        right: r
1133
 
    };
 
1164
    ret[TOP] = t;
 
1165
    ret[RIGHT] = r;
 
1166
    ret[BOTTOM] = b;
 
1167
    ret[LEFT] = l;
 
1168
    return ret;
1134
1169
};
1135
1170
 
1136
 
Y.mix(Y.DOM, {
 
1171
var DOM = DOM || Y.DOM;
 
1172
Y.mix(DOM, {
1137
1173
    /**
1138
1174
     * Returns an Object literal containing the following about this element: (top, right, bottom, left)
1139
1175
     * @method region
1141
1177
     @return {Object} Object literal containing the following about this element: (top, right, bottom, left)
1142
1178
     */
1143
1179
    region: function(node) {
1144
 
        var x = Y.DOM.getXY(node),
 
1180
        var x = DOM.getXY(node),
1145
1181
            ret = false;
1146
1182
        
1147
1183
        if (x) {
1169
1205
     @return {Object} Object literal containing the following intersection data: (top, right, bottom, left, area, yoff, xoff, inRegion)
1170
1206
     */
1171
1207
    intersect: function(node, node2, altRegion) {
1172
 
        var r = altRegion || Y.DOM.region(node), region = {};
 
1208
        var r = altRegion || DOM.region(node), region = {};
1173
1209
 
1174
1210
        var n = node2;
1175
1211
        if (n[TAG_NAME]) {
1176
 
            region = Y.DOM.region(n);
 
1212
            region = DOM.region(n);
1177
1213
        } else if (Y.Lang.isObject(node2)) {
1178
1214
            region = node2;
1179
1215
        } else {
1182
1218
        
1183
1219
        var off = getOffsets(region, r);
1184
1220
        return {
1185
 
            top: off.top,
1186
 
            right: off.right,
1187
 
            bottom: off.bottom,
1188
 
            left: off.left,
1189
 
            area: ((off.bottom - off.top) * (off.right - off.left)),
1190
 
            yoff: ((off.bottom - off.top)),
1191
 
            xoff: (off.right - off.left),
1192
 
            inRegion: Y.DOM.inRegion(node, node2, false, altRegion)
 
1221
            top: off[TOP],
 
1222
            right: off[RIGHT],
 
1223
            bottom: off[BOTTOM],
 
1224
            left: off[LEFT],
 
1225
            area: ((off[BOTTOM] - off[TOP]) * (off[RIGHT] - off[LEFT])),
 
1226
            yoff: ((off[BOTTOM] - off[TOP])),
 
1227
            xoff: (off[RIGHT] - off[LEFT]),
 
1228
            inRegion: DOM.inRegion(node, node2, false, altRegion)
1193
1229
        };
1194
1230
        
1195
1231
    },
1203
1239
     */
1204
1240
    inRegion: function(node, node2, all, altRegion) {
1205
1241
        var region = {},
1206
 
            r = altRegion || Y.DOM.region(node);
 
1242
            r = altRegion || DOM.region(node);
1207
1243
 
1208
1244
        var n = node2;
1209
1245
        if (n[TAG_NAME]) {
1210
 
            region = Y.DOM.region(n);
 
1246
            region = DOM.region(n);
1211
1247
        } else if (Y.Lang.isObject(node2)) {
1212
1248
            region = node2;
1213
1249
        } else {
1215
1251
        }
1216
1252
            
1217
1253
        if (all) {
1218
 
            return ( r.left   >= region.left   &&
1219
 
                r.right  <= region.right  && 
1220
 
                r.top    >= region.top    && 
1221
 
                r.bottom <= region.bottom    );
 
1254
            return (
 
1255
                r[LEFT]   >= region[LEFT]   &&
 
1256
                r[RIGHT]  <= region[RIGHT]  && 
 
1257
                r[TOP]    >= region[TOP]    && 
 
1258
                r[BOTTOM] <= region[BOTTOM]  );
1222
1259
        } else {
1223
1260
            var off = getOffsets(region, r);
1224
 
            if (off.bottom >= off.top && off.right >= off.left) {
 
1261
            if (off[BOTTOM] >= off[TOP] && off[RIGHT] >= off[LEFT]) {
1225
1262
                return true;
1226
1263
            } else {
1227
1264
                return false;
1239
1276
     * @return {Boolean} True if in region, false if not.
1240
1277
     */
1241
1278
    inViewportRegion: function(node, all, altRegion) {
1242
 
        return Y.DOM.inRegion(node, Y.DOM.viewportRegion(node), all, altRegion);
 
1279
        return DOM.inRegion(node, DOM.viewportRegion(node), all, altRegion);
1243
1280
            
1244
1281
    },
1245
1282
 
1250
1287
     */
1251
1288
    viewportRegion: function(node) {
1252
1289
        node = node || Y.config.doc.documentElement;
1253
 
        var r = {
1254
 
            top: Y.DOM.docScrollY(node),
1255
 
            right: Y.DOM.winWidth(node) + Y.DOM.docScrollX(node),
1256
 
            bottom: (Y.DOM.docScrollY(node) + Y.DOM.winHeight(node)),
1257
 
            left: Y.DOM.docScrollX(node)
1258
 
        };
 
1290
        var r = {};
 
1291
        r[TOP] = DOM.docScrollY(node);
 
1292
        r[RIGHT] = DOM.winWidth(node) + DOM.docScrollX(node);
 
1293
        r[BOTTOM] = (DOM.docScrollY(node) + DOM.winHeight(node));
 
1294
        r[LEFT] = DOM.docScrollX(node);
1259
1295
 
1260
1296
        return r;
1261
1297
    }
1262
1298
});
 
1299
 
1263
1300
/**
1264
1301
 * Add style management functionality to DOM.
1265
1302
 * @module dom
1323
1360
 
1324
1361
        if (property === OPACITY) {
1325
1362
            value = Y.DOM.CUSTOM_STYLES[OPACITY].get(el);        
1326
 
        } else if (!current || current.indexOf(PX) > -1) { // no need to convert
 
1363
        } else if (!current || (current.indexOf && current.indexOf(PX) > -1)) { // no need to convert
1327
1364
            value = current;
1328
1365
        } else if (Y.DOM.IE.COMPUTED[property]) { // use compute function
1329
1366
            value = Y.DOM.IE.COMPUTED[property](el, property);
1474
1511
Y.DOM.IE.COMPUTED = IEComputed;
1475
1512
Y.DOM.IE.ComputedStyle = ComputedStyle;
1476
1513
 
 
1514
 
1477
1515
/**
1478
1516
 * Provides helper methods for collecting and filtering DOM elements.
1479
1517
 * @module dom
1774
1812
            for (i = 0, len = token[ATTRIBUTES][LENGTH]; i < len; ++i) {
1775
1813
                attribute = node.getAttribute(token[ATTRIBUTES][i][0], 2);
1776
1814
                if (attribute === undefined) {
1777
 
                    attribute = node[token[ATTRIBUTES][i][0]];
1778
 
                    if (attribute === undefined) {
1779
 
                        return false;
1780
 
                    }
 
1815
                    return false;
1781
1816
                }
1782
1817
                if ( ops[token[ATTRIBUTES][i][1]] &&
1783
1818
                        !ops[token[ATTRIBUTES][i][1]](attribute, token[ATTRIBUTES][i][2])) {
2028
2063
 
2029
2064
};
2030
2065
 
2031
 
if (Y.UA.ie) { // rewrite class for IE (others use getAttribute('class')
 
2066
if (Y.UA.ie && Y.UA.ie < 8) { // rewrite class for IE (others use getAttribute('class')
2032
2067
    Selector.attrAliases['class'] = 'className';
2033
2068
    Selector.attrAliases['for'] = 'htmlFor';
2034
2069
}
2036
2071
Y.Selector = Selector;
2037
2072
Y.Selector.patterns = patterns;
2038
2073
 
 
2074
 
2039
2075
/**
2040
2076
 * Add style management functionality to DOM.
2041
2077
 * @module dom
2114
2150
 
2115
2151
 
2116
2152
 
2117
 
}, '3.0.0pr1' ,{skinnable:false});
 
2153
 
 
2154
}, '3.0.0pr2' ,{skinnable:false});