Attachment 'NewWindow2.py'

Download

   1 """
   2     MoinMoin - NewWindow Macro
   3 
   4     Copyright (c) 2000-2001 by Changjune Kim <juneaftn@orgio.net>
   5     All rights reserved, see COPYING for details.
   6 
   7     [[NewWindow("url"[, "linkname"])]]
   8         Pops up a new window when clicked on
   9 
  10     $Id: NewWindow.py,v 0.8 2001/05/16 04:07:13 
  11     
  12     Modified 2004-07-07 by Roger D. Haase
  13     While this format is deprecated in HTML 4.01:
  14     
  15         <a href="http://www.mysite.com" target="_blank">My Site</a> 
  16 
  17     The same functionality can be implemented in Javascript:
  18     
  19         <a href="http://www.mysite.com" target="_blank"
  20            onclick="window.open(this.href); return false;"
  21            onkeypress="window.open(this.href); return false;">
  22            <img src="/wikidata/moin-popup.gif" border="0" width="15" height="9" alt="[New window]">
  23            My Site
  24            </a> 
  25 
  26 """
  27 
  28 # Imports
  29 import cgi, re
  30 #~ from MoinMoin import config
  31 
  32 _args_re_pattern = r'(?P<hq1>[\'"])(?P<url>[^\'"]+)((?P<spacer>[\'"],\s*)(?P<hquote>[\'"])(?P<htext>.+?)(?P=hquote))?'
  33 
  34 def execute(macro, text, args_re=re.compile(_args_re_pattern)):
  35     if not text:
  36         return ('<p><strong class="error">URL Needed!</strong></p>')
  37 
  38     # parse and check arguments
  39     args = args_re.match(text)
  40     if not args:
  41         return '<p><strong class="error">Invalid NewWindow arguments "%s"!</strong></p>' % (text,)
  42 
  43     url = args.group('url')
  44     htext= args.group('htext')
  45     if not htext:
  46         htext=url
  47     #~ result='<a href="%s" target="_blank">'%cgi.escape(url,1)
  48     #~ result+='<img src="%s/img/moin-www.gif" width="11" height="11" border="0" hspace="4" alt="[new window]">%s</a>'\
  49            #~ %(config.url_prefix, htext)
  50     result='<a href="%s" target="_blank"'%cgi.escape(url,1)
  51     result+='''onclick="window.open(this.href); return false;"
  52            onkeypress="window.open(this.href); return false;">
  53            <img src="/wikidata/moin-popup.gif" border="0" width="15" height="9" alt="[New window]">
  54            %s
  55            </a> ''' % (htext)
  56     return result

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-11-30 16:28:18, 2.0 KB) [[attachment:NewWindow2.py]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.