Changeset 4801

Show
Ignore:
Timestamp:
11/14/08 09:36:27 (2 months ago)
Author:
martin_s
Message:

Merged trunk with dev/0.11 branch.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • googlemapmacro/0.11/tracgooglemap/htdocs/tracgooglemap.js

    r4714 r4801  
    5555        // associated init function: 
    5656        $("div.tracgooglemap") 
    57         .attr( 'id', function (index) { 
    58             return 'tracgooglemap-' + index; 
    59         }) 
    6057        .each( function (index) { 
    6158            var initfunc = tracgooglemapfuncs[index]; 
    6259            if (initfunc) { 
    63                 initfunc(this); 
     60                initfunc(this, index); 
    6461            } 
    6562        }); 
     
    7168        var key = $("link.google-key").attr('title'); 
    7269        jQuery.getScript("http://www.google.com/jsapi?key=" + key, function () { 
    73             google.load("maps", "2", {"callback" : gmapiloaded}) 
     70            google.load("maps", "2.x", {"callback" : gmapiloaded}) 
    7471        }); 
    7572    } 
  • googlemapmacro/0.11/tracgooglemap/macro.py

    r4761 r4801  
    99from trac.core import * 
    1010from trac.util.html import escape,Markup 
    11 from trac.wiki.api import parse_args 
     11from tracadvparseargs import parse_args 
    1212from trac.wiki.formatter import extract_link 
    1313from trac.wiki.macros import WikiMacroBase 
     
    2020import re 
    2121 
     22COUNT = '_googlemapmacro_count' 
     23 
    2224_reWHITESPACES = re.compile(r'\s+') 
    2325_reCOMMA       = re.compile(r',\s*') 
     
    4042//<![CDATA[ 
    4143 
    42 TracGoogleMap( function (mapdiv) { 
     44TracGoogleMap( function (mapdiv,index) { 
    4345    var map = new GMap2(mapdiv, { 
    4446    //    size: new GSize(%(width)s, %(height)s), 
     
    6365    } 
    6466    %(markers_str)s 
     67    if ("%(directions)s") { 
     68        dirdiv = document.getElementById("tracgooglemap-directions-" + index); 
     69        gdir = new GDirections(map, dirdiv); 
     70        gdir.load("%(directions)s"); 
     71    } 
    6572}, "%(id)s" ); 
    6673 
     
    6875""" 
    6976 
    70 class GoogleMapMacro(WikiMacroBase): 
    71     """ Provides a macro to insert Google Maps(TM) in Wiki pages 
    72     """ 
     77class GoogleMapMacro (WikiMacroBase): 
     78    """ Provides a macro to insert Google Maps(TM) in Wiki pages.""" 
    7379    implements(IRequestFilter,ITemplateProvider,IRequestFilter,IEnvironmentSetupParticipant) 
    7480 
     
    157163        return address 
    158164 
    159     def _parse_args(self, args, strict=True, sep = ',', quote = '"', kw = True, min = -1, num = -1): 
    160         """ parses a comma separated string were the values can include multiple 
    161         quotes """ 
    162         esc    = 0   # last char was escape char 
    163         quoted = 0   # inside quote 
    164         start  = 0   # start of current field 
    165         pos    = 0   # current position 
    166         largs  = [] 
    167         kwargs = {} 
    168  
    169         def checkkey (arg): 
    170             import re 
    171             arg = arg.replace(r'\,', ',') 
    172             if strict: 
    173                 m = re.match(r'\s*[a-zA-Z_]\w+=', arg) 
    174             else: 
    175                 m = re.match(r'\s*[^=]+=', arg) 
    176             if m: 
    177                 kw = arg[:m.end()-1].strip() 
    178                 if strict: 
    179                     kw = unicode(kw).encode('utf-8') 
    180                 kwargs[kw] = self._strip(arg[m.end():]) 
    181             else: 
    182                 largs.append(self._strip(arg)) 
    183  
    184         if args: 
    185             for char in args: 
    186                 if esc: 
    187                     esc = 0 
    188                 elif char == quote: 
    189                     quoted = not quoted 
    190                 elif char == '\\': 
    191                     esc = 1 
    192                 elif char == sep and not quoted: 
    193                     checkkey( args[start:pos] ) 
    194                     start = pos + 1 
    195                 pos = pos + 1 
    196             checkkey( args[start:] ) 
    197  
    198         if num > 0: 
    199             if   len(largs) > num: 
    200                 largs = largs[0:num] 
    201             elif len(largs) < num: 
    202                 min = num 
    203  
    204         if min > 0 and min > len(largs): 
    205             for i in range(len(largs), min): 
    206                 largs.append(None) 
    207  
    208         if kw: 
    209             return largs, kwargs 
    210         else: 
    211             return largs 
    212  
    213165 
    214166    def _get_coords(self, address): 
     
    246198 
    247199    def expand_macro(self, formatter, name, content): 
    248         largs, kwargs = self._parse_args(content
     200        largs, kwargs = parse_args(content, multi=['marker','to']
    249201        if len(largs) > 0: 
    250202            arg = unicode(largs[0]) 
     203            if _reCOORDS.match(arg): 
     204                if not 'center' in kwargs: 
     205                    kwargs['center'] = arg 
     206            else: 
     207                if not 'address' in kwargs: 
     208                    kwargs['address'] = arg 
     209        if 'from' in kwargs and not 'address' in kwargs and not 'center' in kwargs: 
     210            arg = unicode(kwargs['from']) 
    251211            if _reCOORDS.match(arg): 
    252212                if not 'center' in kwargs: 
     
    399359        # Produce markers 
    400360        markers_str = "" 
     361        if not 'marker' in kwargs: 
     362            kwargs['marker'] = [] 
    401363        if 'markers' in kwargs: 
     364            kwargs['marker'].extend( parse_args( unicode(kwargs['markers']), delim='|', 
     365                                      listonly=True) ) 
     366        if kwargs['marker']: 
    402367            markers = [] 
    403             for marker in self._parse_args(unicode(kwargs['markers']), sep='|', kw=False)
    404                 location, letter, link, title = self._parse_args(marker, 
    405                         sep=';', kw=False, num=4 ) 
     368            for marker in kwargs['marker']
     369                location, letter, link, title = parse_args( marker, 
     370                        delim=';', listonly=True, minlen=4 )[:4] 
    406371                if not title: 
    407372                    title = link 
     
    440405            markers_str = ''.join( markers ) 
    441406 
     407        # Get macro count from request object 
     408        req = formatter.req 
     409        count = getattr (req, COUNT, 0) 
     410        id = 'tracgooglemap-%s' % count 
     411        setattr (req, COUNT, count + 1) 
     412 
     413        # Canvas for this map 
     414        mapdiv = tag.div ( 
     415                    "Google Map is loading ... (JavaScript enabled?)", 
     416                    id=id, 
     417                    style = "width: %s; height: %s;" % (width,height), 
     418                    class_ = "tracgooglemap" 
     419                ) 
     420 
     421        if 'from' in kwargs and 'to' in kwargs: 
     422            directions = "from: %s to: %s" % (kwargs['from'],' to: '.join(list(kwargs['to']))) 
     423            mapnmore = tag.table( 
     424                            tag.tr( 
     425                                tag.td( 
     426                                    tag.div( "",  
     427                                        class_ = 'tracgooglemap-directions', 
     428                                        id     = 'tracgooglemap-directions-%s' % count 
     429                                    ), 
     430                                    style="vertical-align:top;", 
     431                                ), 
     432                                tag.td( 
     433                                    mapdiv, 
     434                                    style="vertical-align:top;", 
     435                                ) 
     436                            ), 
     437                          class_ = 'tracgooglemaps' 
     438                       ) 
     439 
     440        else: 
     441            directions = "" 
     442            mapnmore = mapdiv 
     443 
    442444        # put everything in a tidy div 
    443445        html = tag.div( 
     
    449451                        'type':type, 'width':width, 'height':height, 
    450452                        'types_str':types_str, 'controls_str':controls_str, 
    451                         'markers_str':markers_str 
     453                        'markers_str':markers_str, 'directions':directions, 
    452454                        }, 
    453455                        type = "text/javascript"), 
    454                     # Canvas for this map 
    455                     tag.div ( 
    456                         "Google Map is loading ... (JavaScript enabled?)", 
    457                         #id=id, 
    458                         style = "width: %s; height: %s;" % (width,height), 
    459                         class_ = "tracgooglemap" 
    460                         ) 
     456                    mapnmore 
    461457                    ], 
    462458                class_ = "tracgooglemap-parent"