Commits

rjollos  committed 610ad70

Refs #9764: Replace virtual script with a script and use `add_script_data` to pass data to the script.

  • Participants
  • Parent commits 8b2ac01

Comments (0)

Files changed (4)

File 0.12/quiet/htdocs/quiet.js

         }
     });
 }
+
+var query = function(action){
+    jQuery.ajax({
+        'type': "GET",
+        'url': get_url()+'/'+quiet['toggle']+'/'+action,
+        'success': function(data){refresh(jQuery('#'+quiet['toggle']),data);},
+        'error': function(r){alert("ERROR:\n\n"+r.responseText);}
+    });
+}
+
+var listeners = function(action){
+    jQuery.ajax({
+        'type': "GET",
+        'url': get_url()+'/'+quiet['listen'],
+        'success': function(data){listen(data);},
+        'error': function(r){alert("ERROR:\n\n"+r.responseText);}
+    });
+}
+
+var get_url = function(){
+    return jQuery('link[rel="search"]').attr('href').replace(/\/search/, '');
+}
+
+jQuery(document).ready(function(){
+    // set the visuals
+    query('status');
+    
+    // toggle on link click
+    jQuery('#'+quiet['toggle']).click(function(e){
+        e.preventDefault();
+        query('toggle');
+        return false;
+    });
+    
+    // setup event listeners
+    listeners();
+});

File 0.12/quiet/templates/quiet.html

-<script type="text/javascript" xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:xi="http://www.w3.org/2001/XInclude"
-      xmlns:py="http://genshi.edgewall.org/" py:strip="">
-
-var query = function(action){
-    jQuery.ajax({
-        'type': "GET",
-        'url': get_url()+'/${toggle}/'+action,
-        'success': function(data){refresh(jQuery('#${toggle}'),data);},
-        'error': function(r){alert("ERROR:\n\n"+r.responseText);}
-    });
-}
-
-var listeners = function(action){
-    jQuery.ajax({
-        'type': "GET",
-        'url': get_url()+'/${listen}',
-        'success': function(data){listen(data);},
-        'error': function(r){alert("ERROR:\n\n"+r.responseText);}
-    });
-}
-
-var get_url = function(){
-    return jQuery('link[rel="search"]').attr('href').replace(/\/search/, '');
-}
-
-
-jQuery(document).ready(function(){
-    // set the visuals
-    query('status');
-    
-    // toggle on link click
-    jQuery('#${toggle}').click(function(e){
-        e.preventDefault();
-        query('toggle');
-        return false;
-    });
-    
-    // setup event listeners
-    listeners();
-});
-
-</script>

File 0.12/quiet/web_ui.py

 from trac.core import *
 from genshi.builder import tag
-from trac.web.chrome import add_script, add_stylesheet, add_ctxtnav
+from trac.web.chrome import add_script, add_script_data, add_stylesheet, add_ctxtnav
 from trac.web.chrome import ITemplateProvider
 from trac.web.main import IRequestFilter, IRequestHandler
 from trac.perm import IPermissionRequestor
 
 
 class QuietModule(Component,QuietBase):
-    implements(IRequestHandler, IRequestFilter,
-               ITemplateProvider, IPermissionRequestor)
+    implements(IRequestFilter, ITemplateProvider, IPermissionRequestor)
         
     # IPermissionRequestor methods  
     def get_permission_actions(self):
 
     def get_templates_dirs(self):
         from pkg_resources import resource_filename
-        return [resource_filename(__name__, 'templates')]
+        return []
 
     # IRequestFilter methods
     def pre_process_request(self, req, handler):
             href = req.href(MODE,'toggle')
             a = tag.a(self._get_label(req), href=href, id=MODE)
             add_ctxtnav(req, a)
-            add_script(req, '/quiet/quiet.html')
             add_script(req, 'quiet/quiet.js')
             add_stylesheet(req, 'quiet/quiet.css')
+            add_script_data(req, {'quiet': {'toggle': MODE,
+                                            'listen': LISTEN}})
         return template, data, content_type
-    
-    # IRequestHandler methods
-    def match_request(self, req):
-        return req.path_info.startswith('/quiet/')
-    
-    def process_request(self, req):
-        req.perm.require('QUIET_MODE')
-        return 'quiet.html', {'toggle':MODE,'listen':LISTEN}, 'text/javascript'
-
 
 class QuietAjaxModule(Component,QuietBase):
     implements(IRequestHandler)

File 0.12/setup.py

     author="Rob Guttman", author_email="guttman@alum.mit.edu",
     license='GPL', url='http://trac-hacks.org/wiki/TracQuietPlugin',
     packages = ['quiet'],
-    package_data = {'quiet':['templates/*.html','htdocs/*.js',
-                             'htdocs/*.css','htdocs/*.png']},
+    package_data = {'quiet':['htdocs/*.js','htdocs/*.css','htdocs/*.png']},
     entry_points = {'trac.plugins':['quiet.web_ui = quiet.web_ui']}
 )