Changeset 1157

Show
Ignore:
Timestamp:
10/09/06 07:31:57 (2 years ago)
Author:
therve@gmail.com
Message:

Change some namespaces

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • mochikit/branches/selector/MochiKit/Selector.js

    r1156 r1157  
    11if (typeof(dojo) != 'undefined') { 
    22    dojo.provide('MochiKit.Selector'); 
    3 
    4  
    5 if (typeof(MochiKit) == 'undefined') { 
    6     MochiKit = {}; 
     3    dojo.require('MochiKit.Base'); 
     4    dojo.require('MochiKit.DOM'); 
     5    dojo.require('MochiKit.Iter'); 
     6
     7 
     8if (typeof(JSAN) != 'undefined') { 
     9    JSAN.use("MochiKit.Base", []); 
     10    JSAN.use("MochiKit.DOM", []); 
     11    JSAN.use("MochiKit.Iter", []); 
     12
     13 
     14try { 
     15    if (typeof(MochiKit.Base) === 'undefined' || 
     16        typeof(MochiKit.DOM) === 'undefined' || 
     17        typeof(MochiKit.Iter) === 'undefined') { 
     18        throw ""; 
     19    } 
     20} catch (e) { 
     21    throw "MochiKit.Selector depends on MochiKit.Base, MochiKit.DOM and MochiKit.Iter!"; 
    722} 
    823 
     
    4055        } 
    4156 
    42         var params = this.params, expr = this.expression, match, modifier, clause, rest; 
     57        var params = this.params; 
     58        var expr = this.expression; 
     59        var match, modifier, clause, rest; 
    4360        while (match = expr.match(/^(.*)\[([a-z0-9_:-]+?)(?:([~\|!^$*]?=)(?:"([^"]*)"|([^\]\s]*)))?\]$/i)) { 
    4461            params.attributes = params.attributes || []; 
     
    5269 
    5370        while (match = expr.match(/^([^a-z0-9_-])?([a-z0-9_-]+(?:\([^)]*\))?)(.*)/i)) { 
    54             modifier = match[1], clause = match[2], rest = match[3]; 
     71            modifier = match[1]; 
     72            clause = match[2]; 
     73            rest = match[3]; 
    5574            switch (modifier) { 
    56                 case '#':  
     75                case '#': 
    5776                    params.id = clause; 
    5877                    break; 
    59                 case '.':  
     78                case '.': 
    6079                    params.classNames.push(clause); 
    6180                    break; 
     
    84103 
    85104        function childElements(element) { 
    86             return "filter(function (node){ return node.nodeType == 1; }, " + element + ".childNodes)"; 
     105            return "MochiKit.Base.filter(function (node) { return node.nodeType == 1; }, " + element + ".childNodes)"; 
    87106        } 
    88107 
     
    98117        if ((clause = params.classNames).length > 0) { 
    99118            for (var i = 0; i < clause.length; i++) { 
    100                 conditions.push('hasElementClass(element, ' + repr(clause[i]) + ')'); 
     119                conditions.push('MochiKit.DOM.hasElementClass(element, ' + repr(clause[i]) + ')'); 
    101120            } 
    102121        } 
     
    149168                        break; 
    150169                    case 'only-of-type': 
    151                         conditions.push('filter(function (node) { return node.tagName == element.tagName; }, ' + childElements('element.parentNode') + ').length == 1'); 
     170                        conditions.push('MochiKit.Base.filter(function (node) { return node.tagName == element.tagName; }, ' + childElements('element.parentNode') + ').length == 1'); 
    152171                        break; 
    153172                    case 'empty': 
     
    171190        } 
    172191        if (clause = params.attributes) { 
    173             map(function (attribute) { 
    174                 var value = 'getNodeAttribute(element, ' + repr(attribute.name) + ')'; 
     192            MochiKit.Base.map(function (attribute) { 
     193                var value = 'MochiKit.DOM.getNodeAttribute(element, ' + repr(attribute.name) + ')'; 
    175194                var splitValueBy = function (delimiter) { 
    176195                    return value + ' && ' + value + '.split(' + repr(delimiter) + ')'; 
     
    182201                        break; 
    183202                    case '~=': 
    184                         conditions.push('findValue(' + splitValueBy(' ') + ', ' + repr(attribute.value) + ') > -1'); 
     203                        conditions.push('MochiKit.Base.findValue(' + splitValueBy(' ') + ', ' + repr(attribute.value) + ') > -1'); 
    185204                        break; 
    186205                    case '^=': 
     
    220239 
    221240    nthChild: function (element, a, b, reverse, sametag){ 
    222         var siblings = filter(function (node) { 
     241        var siblings = MochiKit.Base.filter(function (node) { 
    223242            return node.nodeType == 1; 
    224             }, element.parentNode.childNodes); 
     243        }, element.parentNode.childNodes); 
    225244        if (sametag) { 
    226             siblings = filter(function (node) { 
     245            siblings = MochiKit.Base.filter(function (node) { 
    227246                return node.tagName == element.tagName; 
    228247            }, siblings); 
     
    255274            } else if (axis == "~") { 
    256275                while (element.previousSibling) { 
    257                     if (element.previousSibling == scope) return true; 
     276                    if (element.previousSibling == scope) { 
     277                        return true; 
     278                    } 
    258279                    element = element.previousSibling; 
    259280                } 
     
    286307                throw "> combinator not allowed without preceeding expression"; 
    287308            } 
    288             scope = filter(function (node) { 
     309            scope = MochiKit.Base.filter(function (node) { 
    289310                return node.nodeType == 1; 
    290311            }, scope.childNodes); 
     
    298319                throw "~ combinator not allowed without preceeding expression"; 
    299320            } 
    300             var newscope = new Array()
     321            var newscope = []
    301322            while (nextSiblingElement(scope)) { 
    302323                scope = nextSiblingElement(scope); 
     
    329350 
    330351    findChildElements: function (element, expressions) { 
    331         return flattenArray(map(function (expression) { 
     352        return MochiKit.Base.flattenArray(MochiKit.Base.map(function (expression) { 
    332353            var nextScope = ""; 
    333             return reduce(function (results, expr) { 
     354            return MochiKit.Iter.reduce(function (results, expr) { 
    334355                if (match = expr.match(/^[>+~]$/)) { 
    335356                    nextScope = match[0]; 
     
    337358                } else { 
    338359                    var selector = new MochiKit.Selector.Selector(expr); 
    339                     var elements = reduce(function (elements, result) { 
    340                         return extend(elements, selector.findElements(result || element, nextScope)); 
     360                    var elements = MochiKit.Iter.reduce(function (elements, result) { 
     361                        return MochiKit.Base.extend(elements, selector.findElements(result || element, nextScope)); 
    341362                    }, results, []); 
    342363                    nextScope = "";